RK29SmartPhone:reduce power consumption in sleep
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk29 / board-rk29-phonesdk.c
1 /* arch/arm/mach-rk29/board-rk29-phonesdk.c
2  *
3  * Copyright (C) 2010 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.h>
20 #include <linux/io.h>
21 #include <linux/delay.h>
22 #include <linux/i2c.h>
23 #include <linux/spi/spi.h>
24 #include <linux/mmc/host.h>
25 #include <linux/android_pmem.h>
26 #include <linux/usb/android_composite.h>
27
28 #include <mach/hardware.h>
29 #include <asm/setup.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33 #include <asm/mach/flash.h>
34 #include <asm/hardware/gic.h>
35
36 #include <mach/iomux.h>
37 #include <mach/gpio.h>
38 #include <mach/irqs.h>
39 #include <mach/rk29_iomap.h>
40 #include <mach/board.h>
41 #include <mach/rk29_nand.h>
42 #include <mach/rk29_camera.h>                          /* ddl@rock-chips.com : camera support */
43 #include <media/soc_camera.h>                               /* ddl@rock-chips.com : camera support */
44 #include <mach/vpu_mem.h>
45 #include <mach/sram.h>
46 #include <mach/ddr.h>
47
48 #include <linux/regulator/rk29-pwm-regulator.h>
49 #include <linux/regulator/machine.h>
50 #include <linux/mfd/wm831x/pdata.h>
51 #include <linux/mfd/wm831x/core.h>
52 #include <linux/mfd/wm831x/gpio.h>
53 #include <linux/mfd/wm8994/pdata.h>
54 #include <linux/mfd/wm8994/registers.h>
55
56 #include <linux/mtd/nand.h>
57 #include <linux/mtd/partitions.h>
58 #include <linux/i2c-gpio.h>
59 #include <linux/mpu.h>
60 #include "devices.h"
61
62 #if defined(CONFIG_MTK23D)
63 #include <linux/mtk23d.h>
64 #endif
65
66 #ifdef CONFIG_USE_GPIO_GENERATE_WAVE
67 #include "../../../drivers/testcode/gpio_wave.h"
68 #endif
69
70 #include "../../../drivers/headset_observe/rk_headset.h"
71 /*set touchscreen different type header*/
72 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI)
73 #include "../../../drivers/input/touchscreen/xpt2046_ts.h"
74 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
75 #include "../../../drivers/input/touchscreen/xpt2046_tslib_ts.h"
76 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
77 #include "../../../drivers/input/touchscreen/xpt2046_cbn_ts.h"
78 #endif
79 #include "../../../drivers/misc/gps/rk29_gps.h"
80 #include "../../../drivers/serial/sc8800.h"
81 #ifdef CONFIG_VIDEO_RK29
82 /*---------------- Camera Sensor Macro Define Begin  ------------------------*/
83 /*---------------- Camera Sensor Configuration Macro Begin ------------------------*/
84 #define CONFIG_SENSOR_0 RK29_CAM_SENSOR_OV5642                      /* back camera sensor */
85 #define CONFIG_SENSOR_IIC_ADDR_0            0x78
86 #define CONFIG_SENSOR_IIC_ADAPTER_ID_0    1
87 #define CONFIG_SENSOR_POWER_PIN_0         INVALID_GPIO
88 #define CONFIG_SENSOR_RESET_PIN_0         INVALID_GPIO
89 #define CONFIG_SENSOR_POWERDN_PIN_0       RK29_PIN6_PB7
90 #define CONFIG_SENSOR_FALSH_PIN_0         INVALID_GPIO
91 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
92 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
93 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
94 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
95
96 #define CONFIG_SENSOR_1 RK29_CAM_SENSOR_OV2659                      /* front camera sensor */
97 #define CONFIG_SENSOR_IIC_ADDR_1            0x60
98 #define CONFIG_SENSOR_IIC_ADAPTER_ID_1    1
99 #define CONFIG_SENSOR_POWER_PIN_1         INVALID_GPIO
100 #define CONFIG_SENSOR_RESET_PIN_1         INVALID_GPIO
101 #define CONFIG_SENSOR_POWERDN_PIN_1       RK29_PIN5_PD7
102 #define CONFIG_SENSOR_FALSH_PIN_1         INVALID_GPIO
103 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
104 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
105 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
106 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
107 #endif  //#ifdef CONFIG_VIDEO_RK29
108 /*---------------- Camera Sensor Configuration Macro End------------------------*/
109 #include "../../../drivers/media/video/rk29_camera.c"
110 /*---------------- Camera Sensor Macro Define End  ------------------------*/
111
112
113 /* Set memory size of pmem */
114 #ifdef CONFIG_RK29_MEM_SIZE_M
115 #define SDRAM_SIZE          (CONFIG_RK29_MEM_SIZE_M * SZ_1M)
116 #else
117 #define SDRAM_SIZE          SZ_512M
118 #endif
119 #define PMEM_GPU_SIZE       SZ_64M
120 #define PMEM_UI_SIZE        SZ_32M
121 #define PMEM_VPU_SIZE       SZ_64M
122 #define PMEM_CAM_SIZE       PMEM_CAM_NECESSARY
123 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
124 #define MEM_CAMIPP_SIZE     SZ_4M
125 #else
126 #define MEM_CAMIPP_SIZE     0
127 #endif
128 #define MEM_FB_SIZE         (3*SZ_2M)
129 #ifdef CONFIG_FB_WORK_IPP
130 #define MEM_FBIPP_SIZE      SZ_8M   //1920 x 1080 x 2 x 2  //RGB565 = x2;RGB888 = x4
131 #else
132 #define MEM_FBIPP_SIZE      0
133 #endif
134 #define PMEM_GPU_BASE       ((u32)RK29_SDRAM_PHYS + SDRAM_SIZE - PMEM_GPU_SIZE)
135 #define PMEM_UI_BASE        (PMEM_GPU_BASE - PMEM_UI_SIZE)
136 #define PMEM_VPU_BASE       (PMEM_UI_BASE - PMEM_VPU_SIZE)
137 #define PMEM_CAM_BASE       (PMEM_VPU_BASE - PMEM_CAM_SIZE)
138 #define MEM_CAMIPP_BASE     (PMEM_CAM_BASE - MEM_CAMIPP_SIZE)
139 #define MEM_FB_BASE         (MEM_CAMIPP_BASE - MEM_FB_SIZE)
140 #define MEM_FBIPP_BASE      (MEM_FB_BASE - MEM_FBIPP_SIZE)
141 #define LINUX_SIZE          (MEM_FBIPP_BASE - RK29_SDRAM_PHYS)
142
143 #define PREALLOC_WLAN_SEC_NUM           4
144 #define PREALLOC_WLAN_BUF_NUM           160
145 #define PREALLOC_WLAN_SECTION_HEADER    24
146
147 #define WLAN_SECTION_SIZE_0     (PREALLOC_WLAN_BUF_NUM * 128)
148 #define WLAN_SECTION_SIZE_1     (PREALLOC_WLAN_BUF_NUM * 128)
149 #define WLAN_SECTION_SIZE_2     (PREALLOC_WLAN_BUF_NUM * 512)
150 #define WLAN_SECTION_SIZE_3     (PREALLOC_WLAN_BUF_NUM * 1024)
151
152 #define WLAN_SKB_BUF_NUM        16
153
154 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
155
156 struct wifi_mem_prealloc {
157         void *mem_ptr;
158         unsigned long size;
159 };
160
161 extern struct sys_timer rk29_timer;
162
163 static int rk29_nand_io_init(void)
164 {
165     return 0;
166 }
167
168 struct rk29_nand_platform_data rk29_nand_data = {
169     .width      = 1,     /* data bus width in bytes */
170     .hw_ecc     = 1,     /* hw ecc 0: soft ecc */
171     .num_flash    = 1,
172     .io_init   = rk29_nand_io_init,
173 };
174
175 #ifdef CONFIG_FB_RK29
176 /*****************************************************************************************
177  * lcd  devices
178  * author: zyw@rock-chips.com
179  *****************************************************************************************/
180 //#ifdef  CONFIG_LCD_TD043MGEA1
181 #define LCD_RXD_PIN          RK29_PIN2_PC7
182 #define LCD_TXD_PIN          RK29_PIN2_PC6
183 #define LCD_CLK_PIN          RK29_PIN2_PC4
184 #define LCD_CS_PIN           RK29_PIN2_PC5
185 /*****************************************************************************************
186 * frame buffer  devices
187 * author: zyw@rock-chips.com
188 *****************************************************************************************/
189 #define FB_ID                       0
190 #define FB_DISPLAY_ON_PIN           INVALID_GPIO//RK29_PIN6_PD0
191 #define FB_LCD_STANDBY_PIN          INVALID_GPIO//RK29_PIN6_PD1
192 #define FB_LCD_CABC_EN_PIN          INVALID_GPIO//RK29_PIN6_PD2
193 #define FB_MCU_FMK_PIN              INVALID_GPIO
194
195 #define FB_DISPLAY_ON_VALUE         GPIO_HIGH
196 #define FB_LCD_STANDBY_VALUE        GPIO_HIGH
197
198 //#endif
199 static int rk29_lcd_io_init(void)
200 {
201     int ret = 0;
202     //printk("rk29_lcd_io_init\n");
203     //ret = gpio_request(LCD_RXD_PIN, NULL);
204     ret = gpio_request(LCD_TXD_PIN, NULL);
205         ret = gpio_request(LCD_CLK_PIN, NULL);
206         ret = gpio_request(LCD_CS_PIN, NULL);
207         //rk29_mux_api_set(GPIO2C7_SPI1RXD_NAME,GPIO2H_GPIO2C7);
208         rk29_mux_api_set(GPIO2C6_SPI1TXD_NAME,GPIO2H_GPIO2C6);
209         rk29_mux_api_set(GPIO2C5_SPI1CSN0_NAME,GPIO2H_GPIO2C5);
210         rk29_mux_api_set(GPIO2C4_SPI1CLK_NAME,GPIO2H_GPIO2C4);
211     return ret;
212 }
213
214 static int rk29_lcd_io_deinit(void)
215 {
216     int ret = 0;
217     //printk("rk29_lcd_io_deinit\n");
218     gpio_free(LCD_CS_PIN);
219         gpio_free(LCD_CLK_PIN);
220         gpio_free(LCD_TXD_PIN);
221         //gpio_free(LCD_RXD_PIN);
222         //rk29_mux_api_set(GPIO2C7_SPI1RXD_NAME,GPIO2H_SPI1_RXD);
223         rk29_mux_api_set(GPIO2C6_SPI1TXD_NAME,GPIO2H_SPI1_TXD);
224         rk29_mux_api_set(GPIO2C5_SPI1CSN0_NAME,GPIO2H_SPI1_CSN0);
225         rk29_mux_api_set(GPIO2C4_SPI1CLK_NAME,GPIO2H_SPI1_CLK);
226     return ret;
227 }
228
229 static struct rk29lcd_info rk29_lcd_info = {
230     .txd_pin  = LCD_TXD_PIN,
231     .clk_pin = LCD_CLK_PIN,
232     .cs_pin = LCD_CS_PIN,
233     .io_init   = rk29_lcd_io_init,
234     .io_deinit = rk29_lcd_io_deinit,
235 };
236
237 int rk29_fb_io_enable(void)
238 {
239     if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
240     {
241         gpio_direction_output(FB_DISPLAY_ON_PIN, 0);
242         gpio_set_value(FB_DISPLAY_ON_PIN, FB_DISPLAY_ON_VALUE);              
243     }
244     if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
245     {
246         gpio_direction_output(FB_LCD_STANDBY_PIN, 0);
247         gpio_set_value(FB_LCD_STANDBY_PIN, FB_LCD_STANDBY_VALUE);             
248     }
249     return 0;
250 }
251
252 int rk29_fb_io_disable(void)
253 {
254     if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
255     {
256         gpio_direction_output(FB_DISPLAY_ON_PIN, 0);
257         gpio_set_value(FB_DISPLAY_ON_PIN, !FB_DISPLAY_ON_VALUE);              
258     }
259     if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
260     {
261         gpio_direction_output(FB_LCD_STANDBY_PIN, 0);
262         gpio_set_value(FB_LCD_STANDBY_PIN, !FB_LCD_STANDBY_VALUE);             
263     }
264     return 0;
265 }
266
267 static int rk29_fb_io_init(struct rk29_fb_setting_info *fb_setting)
268 {
269     int ret = 0;
270     if(fb_setting->mcu_fmk_en && (FB_MCU_FMK_PIN != INVALID_GPIO))
271     {
272         ret = gpio_request(FB_MCU_FMK_PIN, NULL);
273         if(ret != 0)
274         {
275             gpio_free(FB_MCU_FMK_PIN);
276             printk(">>>>>> FB_MCU_FMK_PIN gpio_request err \n ");
277         }
278         gpio_direction_input(FB_MCU_FMK_PIN);
279     }
280     if(fb_setting->disp_on_en && (FB_DISPLAY_ON_PIN != INVALID_GPIO))
281     {
282         ret = gpio_request(FB_DISPLAY_ON_PIN, NULL);
283         if(ret != 0)
284         {
285             gpio_free(FB_DISPLAY_ON_PIN);
286             printk(">>>>>> FB_DISPLAY_ON_PIN gpio_request err \n ");
287         }
288     }
289
290     if(fb_setting->disp_on_en && (FB_LCD_STANDBY_PIN != INVALID_GPIO))
291     {
292         ret = gpio_request(FB_LCD_STANDBY_PIN, NULL);
293         if(ret != 0)
294         {
295             gpio_free(FB_LCD_STANDBY_PIN);
296             printk(">>>>>> FB_LCD_STANDBY_PIN gpio_request err \n ");
297         }
298     }
299
300     if(FB_LCD_CABC_EN_PIN != INVALID_GPIO)
301     {
302         ret = gpio_request(FB_LCD_CABC_EN_PIN, NULL);
303         if(ret != 0)
304         {
305             gpio_free(FB_LCD_CABC_EN_PIN);
306             printk(">>>>>> FB_LCD_CABC_EN_PIN gpio_request err \n ");
307         }
308         gpio_direction_output(FB_LCD_CABC_EN_PIN, 0);
309         gpio_set_value(FB_LCD_CABC_EN_PIN, GPIO_LOW);
310     }
311     rk29_fb_io_enable();   //enable it
312
313     return ret;
314 }
315
316 static struct rk29fb_info rk29_fb_info = {
317     .fb_id   = FB_ID,
318     .mcu_fmk_pin = FB_MCU_FMK_PIN,
319     .lcd_info = &rk29_lcd_info,
320     .io_init   = rk29_fb_io_init,
321     .io_enable = rk29_fb_io_enable,
322     .io_disable = rk29_fb_io_disable,
323 };
324
325 /* rk29 fb resource */
326 static struct resource rk29_fb_resource[] = {
327         [0] = {
328         .name  = "lcdc reg",
329                 .start = RK29_LCDC_PHYS,
330                 .end   = RK29_LCDC_PHYS + RK29_LCDC_SIZE - 1,
331                 .flags = IORESOURCE_MEM,
332         },
333         [1] = {
334             .name  = "lcdc irq",
335                 .start = IRQ_LCDC,
336                 .end   = IRQ_LCDC,
337                 .flags = IORESOURCE_IRQ,
338         },
339         [2] = {
340             .name   = "win1 buf",
341         .start  = MEM_FB_BASE,
342         .end    = MEM_FB_BASE + MEM_FB_SIZE - 1,
343         .flags  = IORESOURCE_MEM,
344     },
345     #ifdef CONFIG_FB_WORK_IPP
346     [3] = {
347             .name   = "win1 ipp buf",
348         .start  = MEM_FBIPP_BASE,
349         .end    = MEM_FBIPP_BASE + MEM_FBIPP_SIZE - 1,
350         .flags  = IORESOURCE_MEM,
351     },
352     #endif
353 };
354
355 /*platform_device*/
356 struct platform_device rk29_device_fb = {
357         .name             = "rk29-fb",
358         .id               = 4,
359         .num_resources    = ARRAY_SIZE(rk29_fb_resource),
360         .resource         = rk29_fb_resource,
361         .dev            = {
362                 .platform_data  = &rk29_fb_info,
363         }
364 };
365
366 struct platform_device rk29_device_dma_cpy = {
367         .name             = "dma_memcpy",
368         .id               = 4,
369
370 };
371
372 #endif
373
374 static struct android_pmem_platform_data android_pmem_pdata = {
375         .name           = "pmem",
376         .start          = PMEM_UI_BASE,
377         .size           = PMEM_UI_SIZE,
378         .no_allocator   = 0,
379         .cached         = 1,
380 };
381
382 static struct platform_device android_pmem_device = {
383         .name           = "android_pmem",
384         .id             = 0,
385         .dev            = {
386                 .platform_data = &android_pmem_pdata,
387         },
388 };
389
390
391 static struct vpu_mem_platform_data vpu_mem_pdata = {
392         .name           = "vpu_mem",
393         .start          = PMEM_VPU_BASE,
394         .size           = PMEM_VPU_SIZE,
395         .cached         = 1,
396 };
397
398 static struct platform_device rk29_vpu_mem_device = {
399         .name           = "vpu_mem",
400         .id                 = 2,
401         .dev            = {
402         .platform_data = &vpu_mem_pdata,
403         },
404 };
405
406 static struct platform_device rk29_v4l2_output_devce = {
407         .name           = "rk29_vout",
408 };
409
410 /* HANNSTAR_P1003 touch I2C */
411 #if defined (CONFIG_HANNSTAR_P1003)
412 #define TOUCH_RESET_PIN RK29_PIN6_PC3
413 #define TOUCH_INT_PIN   RK29_PIN4_PD5
414
415 int p1003_init_platform_hw(void)
416 {
417     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
418       gpio_free(TOUCH_RESET_PIN);
419       printk("p1003_init_platform_hw gpio_request error\n");
420       return -EIO;
421     }
422
423     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
424       gpio_free(TOUCH_INT_PIN);
425       printk("p1003_init_platform_hw gpio_request error\n");
426       return -EIO;
427     }
428     gpio_pull_updown(TOUCH_INT_PIN, 1);
429     gpio_direction_output(TOUCH_RESET_PIN, 0);
430     msleep(500);
431     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
432     msleep(500);
433     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
434
435     return 0;
436 }
437
438
439 struct p1003_platform_data p1003_info = {
440   .model= 1003,
441   .init_platform_hw= p1003_init_platform_hw,
442
443 };
444 #endif
445
446
447 #if defined(CONFIG_TOUCHSCREEN_GT801_IIC) 
448 #include "../../../drivers/input/touchscreen/gt801_ts.h"
449 #define GT801_GPIO_INT      RK29_PIN4_PD5
450 #define GT801_GPIO_RESET    RK29_PIN6_PC3
451 static struct gt801_platform_data gt801_info = {
452         .model                  = 801,
453         .swap_xy                = 0,
454         .x_min                  = 0,
455         .x_max                  = 480,
456         .y_min                  = 0,
457         .y_max                  = 800,
458         .gpio_reset     = GT801_GPIO_RESET,
459         .gpio_reset_active_low = 0,
460         .gpio_pendown           = GT801_GPIO_INT,
461     .pendown_iomux_name = GPIO4D5_CPUTRACECTL_NAME,
462     .resetpin_iomux_name = NULL,
463     .pendown_iomux_mode = GPIO4H_GPIO4D5,
464     .resetpin_iomux_mode = 0,
465 };
466 #endif
467
468
469 #if defined(CONFIG_TOUCHSCREEN_GT818_IIC)
470 #include "../../../drivers/input/touchscreen/gt818_ts.h"
471 #define GT818_GPIO_INT      RK29_PIN4_PD5
472 #define GT818_GPIO_RESET    RK29_PIN6_PC3
473 static struct gt818_platform_data gt818_info = {
474         .model                  = 818,
475         .swap_xy                = 0,
476         .x_min                  = 0,
477         .x_max                  = 480,
478         .y_min                  = 0,
479         .y_max                  = 800,
480         .gpio_reset     = GT818_GPIO_RESET,
481         .gpio_reset_active_low = 0,
482         .gpio_pendown           = GT818_GPIO_INT,
483     .pendown_iomux_name = GPIO4D5_CPUTRACECTL_NAME,
484     .resetpin_iomux_name = NULL,
485     .pendown_iomux_mode = GPIO4H_GPIO4D5,
486     .resetpin_iomux_mode = 0,
487 };
488 #endif
489
490 #if defined(CONFIG_TOUCHSCREEN_ILI2102_IIC) 
491 #include "../../../drivers/input/touchscreen/ili2102_ts.h"
492 #define GT801_GPIO_INT      RK29_PIN4_PD5
493 #define GT801_GPIO_RESET    RK29_PIN6_PC3
494 static struct ili2102_platform_data ili2102_info = {
495         .model                  = 2102,
496         .swap_xy                = 0,
497         .x_min                  = 0,
498         .x_max                  = 481,
499         .y_min                  = 0,
500         .y_max                  = 801,
501         .gpio_reset     = GT801_GPIO_RESET,
502         .gpio_reset_active_low = 1,
503         .gpio_pendown           = GT801_GPIO_INT,
504     .pendown_iomux_name = GPIO4D5_CPUTRACECTL_NAME,
505     .resetpin_iomux_name = NULL,
506     .pendown_iomux_mode = GPIO4H_GPIO4D5,
507     .resetpin_iomux_mode = 0,
508 };
509 #endif
510
511 /* EETI_EGALAX touch I2C */
512 #if defined (CONFIG_EETI_EGALAX)
513 #define TOUCH_RESET_PIN RK29_PIN6_PC3
514 #define TOUCH_INT_PIN   RK29_PIN4_PD5
515
516 static int EETI_EGALAX_init_platform_hw(void)
517 {
518     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
519       gpio_free(TOUCH_RESET_PIN);
520       printk("p1003_init_platform_hw gpio_request error\n");
521       return -EIO;
522     }
523
524     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
525       gpio_free(TOUCH_INT_PIN);
526       printk("p1003_init_platform_hw gpio_request error\n");
527       return -EIO;
528     }
529     gpio_pull_updown(TOUCH_INT_PIN, 1);
530     gpio_direction_output(TOUCH_RESET_PIN, 0);
531     msleep(500);
532     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
533     msleep(500);
534     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
535
536     return 0;
537 }
538
539
540 static struct eeti_egalax_platform_data eeti_egalax_info = {
541   .model= 1003,
542   .init_platform_hw= EETI_EGALAX_init_platform_hw,
543
544 };
545 #endif
546
547 /*MMA8452 gsensor*/
548 #if defined (CONFIG_GS_MMA8452)
549 #define MMA8452_INT_PIN   RK29_PIN6_PC4
550
551 static int mma8452_init_platform_hw(void)
552 {
553
554     if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
555       gpio_free(MMA8452_INT_PIN);
556       printk("mma8452_init_platform_hw gpio_request error\n");
557       return -EIO;
558     }
559     gpio_pull_updown(MMA8452_INT_PIN, 1);
560     return 0;
561 }
562
563
564 static struct mma8452_platform_data mma8452_info = {
565   .model= 8452,
566   .swap_xy = 0,
567   .init_platform_hw= mma8452_init_platform_hw,
568
569 };
570 #endif
571
572 #if defined (CONFIG_SENSORS_MPU3050)
573 /*mpu3050*/
574 static struct mpu3050_platform_data mpu3050_data = {
575                 .int_config = 0x10,
576                 //.orientation = { 1, 0, 0,0, -1, 0,0, 0, 1 },
577                 //.orientation = { 0, 1, 0,-1, 0, 0,0, 0, -1 },
578                 .orientation = { 1, 0, 0,0, 1, 0, 0, 0, 1 },
579                 .level_shifter = 0,
580 #if defined (CONFIG_SENSORS_KXTF9)
581                 .accel = {
582                                 .get_slave_descr = kxtf9_get_slave_descr ,
583                                 .adapt_num = 0, // The i2c bus to which the mpu device is
584                                 // connected
585                                 .irq = RK29_PIN6_PC4,
586                                 .bus = EXT_SLAVE_BUS_SECONDARY,  //The secondary I2C of MPU
587                                 .address = 0x0f,
588                                 //.orientation = { 1, 0, 0,0, 1, 0,0, 0, 1 },
589                                 //.orientation = { 0, -1, 0,-1, 0, 0,0, 0, -1 },
590                                 //.orientation = { 0, 1, 0,1, 0, 0,0, 0, -1 },
591                                 .orientation = {1, 0, 0, 0, 1, 0, 0, 0, 1},
592                 },
593 #endif
594 #if defined (CONFIG_SENSORS_AK8975)
595                 .compass = {
596                                 .get_slave_descr = ak8975_get_slave_descr,/*ak5883_get_slave_descr,*/
597                                 .adapt_num = 0, // The i2c bus to which the compass device is. 
598                                 // It can be difference with mpu
599                                 // connected
600                                 .irq = RK29_PIN6_PC5,
601                                 .bus = EXT_SLAVE_BUS_PRIMARY,
602                                 .address = 0x0d,
603                                 //.orientation = { -1, 0, 0,0, -1, 0,0, 0, 1 },
604                                 //.orientation = { 0, -1, 0,-1, 0, 0,0, 0, -1 },
605                                 .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
606                 },
607 #endif
608 };
609 #endif
610
611 #if defined(CONFIG_GPIO_WM831X)
612 struct rk29_gpio_expander_info  wm831x_gpio_settinginfo[] = {
613         {
614                 .gpio_num               =WM831X_P01,// tp3
615                 .pin_type           = GPIO_OUT,
616                 .pin_value                      =GPIO_HIGH,
617          },
618          
619          {
620                 .gpio_num               =WM831X_P02,//tp4
621                 .pin_type           = GPIO_OUT,
622                 .pin_value                      =GPIO_HIGH,
623          },
624          {
625                 .gpio_num               =WM831X_P03,//tp2
626                 .pin_type           = GPIO_OUT,
627                 .pin_value                      =GPIO_HIGH,
628          },
629          {
630                 .gpio_num               =WM831X_P04,//tp1
631                 .pin_type           = GPIO_OUT,
632                 .pin_value                      =GPIO_HIGH,
633          },
634          {
635                 .gpio_num               =WM831X_P05,//tp1
636                 .pin_type           = GPIO_OUT,
637                 .pin_value                      =GPIO_HIGH,
638          },
639          {
640                 .gpio_num               =WM831X_P06,//tp1
641                 .pin_type           = GPIO_OUT,
642                 .pin_value                      =GPIO_HIGH,
643          },
644          {
645                 .gpio_num               =WM831X_P07,//tp1
646                 .pin_type           = GPIO_OUT,
647                 .pin_value                      =GPIO_HIGH,
648          },
649          {
650                 .gpio_num               =WM831X_P08,//tp1
651                 .pin_type           = GPIO_OUT,
652                 .pin_value                      =GPIO_HIGH,
653          },
654          {
655                 .gpio_num               =WM831X_P09,//tp1
656                 .pin_type           = GPIO_OUT,
657                 .pin_value                      =GPIO_HIGH,
658          },
659          {
660                 .gpio_num               =WM831X_P10,//tp1
661                 .pin_type           = GPIO_OUT,
662                 .pin_value                      =GPIO_HIGH,
663          },
664          {
665                 .gpio_num               =WM831X_P11,//tp1
666                 .pin_type           = GPIO_OUT,
667                 .pin_value                      =GPIO_HIGH,
668          },     
669          {
670                 .gpio_num               =WM831X_P12,
671                 .pin_type           = GPIO_OUT,
672                 .pin_value                      =GPIO_HIGH,
673          },
674 };
675
676 #endif
677
678
679
680 #if defined(CONFIG_MFD_WM831X)
681 static struct wm831x *gWm831x;
682 int wm831x_pre_init(struct wm831x *parm)
683 {
684         int ret;
685         printk("%s\n", __FUNCTION__);
686         gWm831x = parm;
687         //ILIM = 900ma
688         ret = wm831x_reg_read(parm, WM831X_POWER_STATE) & 0xffff;
689         wm831x_reg_write(parm, WM831X_POWER_STATE, (ret&0xfff8) | 0x04);        
690 #if 0
691         wm831x_set_bits(parm, WM831X_LDO_ENABLE, (1 << 3), 0);
692         wm831x_set_bits(parm, WM831X_LDO_ENABLE, (1 << 7), 0);
693         printk("%s:disable ldo4 and ldo8 because they are enabled in uboot\n",__FUNCTION__);
694 #endif  
695         return 0;
696 }
697 int wm831x_post_init(struct wm831x *parm)
698 {
699         struct regulator *dcdc;
700         struct regulator *ldo;
701         
702         dcdc = regulator_get(NULL, "dcdc3");            // 1th IO
703         regulator_set_voltage(dcdc,3000000,3000000);
704         regulator_set_suspend_voltage(dcdc, 3000000);
705         regulator_enable(dcdc);                 
706         printk("%s set dcdc3=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc));
707         regulator_put(dcdc);
708         udelay(100);
709         
710         ldo = regulator_get(NULL, "ldo10");     // 1th modem IO
711         regulator_set_voltage(ldo,3000000,3000000);
712         regulator_set_suspend_voltage(ldo,3000000);
713         regulator_enable(ldo);                  
714         printk("%s set ldo10=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
715         regulator_put(ldo);
716         udelay(100);
717         
718         dcdc = regulator_get(NULL, "dcdc2");    // 2th CORE
719         regulator_set_voltage(dcdc,1300000,1300000);
720         regulator_set_suspend_voltage(dcdc,1000000);
721         regulator_enable(dcdc);                         
722         printk("%s set dcdc2=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc));
723         regulator_put(dcdc);
724         udelay(100);
725         
726         dcdc = regulator_get(NULL, "dcdc1");    // 3th ddr
727         regulator_set_voltage(dcdc,1800000,1800000);
728         regulator_set_suspend_voltage(ldo, 1800000);
729         regulator_enable(dcdc);
730         printk("%s set dcdc1=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc));   
731         regulator_put(dcdc);
732         udelay(100);
733         
734         ldo = regulator_get(NULL, "ldo1");              // 3th nand
735         regulator_set_voltage(ldo,1800000,1800000);
736         regulator_set_suspend_voltage(ldo,1800000);
737         regulator_enable(ldo);                  
738         printk("%s set ldo1=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));             
739         regulator_put(ldo);
740         udelay(100);
741         
742         ldo = regulator_get(NULL, "ldo4");              // 4th usb
743         regulator_set_voltage(ldo,2500000,2500000);
744         regulator_set_suspend_voltage(ldo,2500000);
745         regulator_enable(ldo);  
746         printk("%s set ldo4=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
747         regulator_put(ldo);
748         udelay(100);
749         
750         ldo = regulator_get(NULL, "ldo7");              // 5th usb
751         regulator_set_voltage(ldo,3300000,3300000);
752         regulator_set_suspend_voltage(ldo,3300000);
753         regulator_enable(ldo);                  
754         printk("%s set ldo7=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
755         regulator_put(ldo);
756         udelay(100);
757         
758         dcdc = regulator_get(NULL, "dcdc4");    // backlight
759         regulator_set_voltage(dcdc,20000000,20000000);
760         regulator_set_suspend_voltage(dcdc, 20000000);
761         regulator_enable(dcdc); 
762         printk("%s set dcdc4=%dmV end\n", __FUNCTION__, regulator_get_voltage(dcdc));
763         regulator_put(dcdc);
764         udelay(100);
765 #if 1
766         
767         ldo = regulator_get(NULL, "ldo2");              //lcd
768         regulator_set_voltage(ldo,3000000,3000000);
769         regulator_set_suspend_voltage(ldo,3000000);
770         regulator_enable(ldo);                  
771         printk("%s set ldo2=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
772         regulator_put(ldo);
773
774         ldo = regulator_get(NULL, "ldo3");              //sram
775         regulator_disable(ldo);
776 //      regulator_set_voltage(ldo,1800000,1800000);
777 //      regulator_set_suspend_voltage(ldo,1800000);
778 //      regulator_enable(ldo);                  
779 //      printk("%s set ldo3=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
780         regulator_put(ldo);     
781
782         ldo = regulator_get(NULL, "ldo5");              //tf
783         regulator_set_voltage(ldo,3000000,3000000);
784         regulator_set_suspend_voltage(ldo,3000000);
785         regulator_enable(ldo);                  
786         printk("%s set ldo5=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
787         regulator_put(ldo);
788
789         ldo = regulator_get(NULL, "ldo6");              //camera
790         regulator_set_voltage(ldo,1800000,1800000);
791         regulator_set_suspend_voltage(ldo,1800000);
792         regulator_enable(ldo);                  
793         printk("%s set ldo6=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
794         regulator_put(ldo);
795
796         ldo = regulator_get(NULL, "ldo8");              //cmmb
797         regulator_disable(ldo);
798 //      regulator_set_voltage(ldo,1200000,1200000);
799 //      regulator_set_suspend_voltage(ldo,1200000);
800 //      regulator_enable(ldo);                  
801 //      printk("%s set ldo8=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
802         regulator_put(ldo);
803
804         ldo = regulator_get(NULL, "ldo9");              //cmmb
805         regulator_disable(ldo);
806 //      regulator_set_voltage(ldo,3000000,3000000);
807 //      regulator_set_suspend_voltage(ldo,3000000);
808 //      regulator_enable(ldo);                  
809 //      printk("%s set ldo9=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));
810         regulator_put(ldo);
811         
812 #endif
813         
814         ldo = regulator_get(NULL, "ldo11");
815         //regulator_enable(ldo);                        
816         printk("%s set ldo11=%dmV end\n", __FUNCTION__, regulator_get_voltage(ldo));    
817         regulator_put(ldo);     
818         
819                 
820         return 0;
821 }
822
823 extern void wm831x_enter_sleep(void);
824 extern void wm831x_exit_sleep(void);
825
826 void pmu_wm831x_set_suspend_voltage(void)
827 {
828
829 }
830 EXPORT_SYMBOL_GPL(pmu_wm831x_set_suspend_voltage);
831
832 void pmu_wm831x_set_resume_voltage(void)
833 {
834
835 }
836 EXPORT_SYMBOL_GPL(pmu_wm831x_set_resume_voltage);
837
838 int wm831x_last_deinit(struct wm831x *parm)
839 {
840         struct regulator* ldo;
841
842         printk("%s\n", __FUNCTION__);
843
844         ldo = regulator_get(NULL, "ldo1");
845         regulator_disable(ldo);                 
846         regulator_put(ldo);
847         
848         ldo = regulator_get(NULL, "ldo2");
849         regulator_disable(ldo);                 
850         regulator_put(ldo);
851         
852         ldo = regulator_get(NULL, "ldo3");
853         regulator_disable(ldo);                 
854         regulator_put(ldo);
855         
856         ldo = regulator_get(NULL, "ldo4");
857         //regulator_disable(ldo);       
858         regulator_put(ldo);
859
860         ldo = regulator_get(NULL, "ldo5");
861         regulator_disable(ldo);                 
862         regulator_put(ldo);
863
864         ldo = regulator_get(NULL, "ldo6");
865         regulator_disable(ldo);                 
866         regulator_put(ldo);
867
868         ldo = regulator_get(NULL, "ldo7");
869         regulator_disable(ldo);                 
870         regulator_put(ldo);
871
872         ldo = regulator_get(NULL, "ldo8");
873         //regulator_disable(ldo);                       
874         regulator_put(ldo);
875
876         ldo = regulator_get(NULL, "ldo9");
877         regulator_disable(ldo);                 
878         regulator_put(ldo);
879
880         ldo = regulator_get(NULL, "ldo10");
881         regulator_disable(ldo);                                         
882         regulator_put(ldo);
883
884         return 0;
885 }
886
887 struct wm831x_backlight_pdata wm831x_backlight_platdata = {
888         .isink = 1,     /** ISINK to use, 1 or 2 */
889         .max_uA = 19484,    /** Maximum current to allow */
890 };
891
892 struct wm831x_backup_pdata wm831x_backup_platdata = {
893         .charger_enable = 1,
894         .no_constant_voltage = 0,  /** Disable constant voltage charging */
895         .vlim = 3100,   /** Voltage limit in milivolts */
896         .ilim = 300,   /** Current limit in microamps */
897 };
898
899 struct wm831x_battery_pdata wm831x_battery_platdata = {
900         .enable = 1,         /** Enable charging */
901         .fast_enable = 1,    /** Enable fast charging */
902         .off_mask = 1,       /** Mask OFF while charging */
903         .trickle_ilim = 200,   /** Trickle charge current limit, in mA */
904         .vsel = 4200,           /** Target voltage, in mV */
905         .eoc_iterm = 90,      /** End of trickle charge current, in mA */
906         .fast_ilim = 1000,      /** Fast charge current limit, in mA */
907         .timeout = 180,        /** Charge cycle timeout, in minutes */
908         .syslo = 3300,    /* syslo threshold, in mV*/
909         .sysok = 3500,    /* sysko threshold, in mV*/
910 };
911
912 struct wm831x_status_pdata wm831x_status_platdata[WM831X_MAX_STATUS] = {
913         {
914         .default_src = WM831X_STATUS_OTP,
915         .name = "wm831x_status0",
916         .default_trigger = "wm831x_otp",
917         },
918         {
919         .default_src = WM831X_STATUS_POWER,
920         .name = "wm831x_status1",
921         .default_trigger = "wm831x_power",
922         },      
923 };
924
925
926 static struct regulator_consumer_supply dcdc1_consumers[] = {
927         {
928                 .supply = "dcdc1",
929         }
930 };
931 static struct regulator_consumer_supply dcdc2_consumers[] = {
932         {
933                 .supply = "dcdc2",
934         },
935         {
936                 .supply = "vcore",
937         }
938 };
939 static struct regulator_consumer_supply dcdc3_consumers[] = {
940         {
941                 .supply = "dcdc3",
942         }
943 };
944 static struct regulator_consumer_supply dcdc4_consumers[] = {
945         {
946                 .supply = "dcdc4",
947         }
948 };
949 static struct regulator_consumer_supply epe1_consumers[] = {
950         {
951                 .supply = "epe1",
952         }
953 };
954 static struct regulator_consumer_supply epe2_consumers[] = {
955         {
956                 .supply = "epe2",
957         }
958 };
959 static struct regulator_consumer_supply ldo1_consumers[] = {
960         {
961                 .supply = "ldo1",
962         }
963 };
964 static struct regulator_consumer_supply ldo2_consumers[] = {
965         {
966                 .supply = "ldo2",
967         }
968 };
969 static struct regulator_consumer_supply ldo3_consumers[] = {
970         {
971                 .supply = "ldo3",
972         }
973 };
974 static struct regulator_consumer_supply ldo4_consumers[] = {
975         {
976                 .supply = "ldo4",
977         }
978 };
979 static struct regulator_consumer_supply ldo5_consumers[] = {
980         {
981                 .supply = "ldo5",
982         }
983 };
984 static struct regulator_consumer_supply ldo6_consumers[] = {
985         {
986                 .supply = "ldo6",
987         }
988 };
989 static struct regulator_consumer_supply ldo7_consumers[] = {
990         {
991                 .supply = "ldo7",
992         }
993 };
994 static struct regulator_consumer_supply ldo8_consumers[] = {
995         {
996                 .supply = "ldo8",
997         }
998 };
999 static struct regulator_consumer_supply ldo9_consumers[] = {
1000         {
1001                 .supply = "ldo9",
1002         }
1003 };
1004 static struct regulator_consumer_supply ldo10_consumers[] = {
1005         {
1006                 .supply = "ldo10",
1007         }
1008 };
1009 static struct regulator_consumer_supply ldo11_consumers[] = {
1010         {
1011                 .supply = "ldo11",
1012         }
1013 };
1014 static struct regulator_consumer_supply isink1_consumers[] = {
1015         {
1016                 .supply = "isink1",
1017         }
1018 };
1019 static struct regulator_consumer_supply isink2_consumers[] = {
1020         {
1021                 .supply = "isink2",
1022         }
1023 };
1024
1025 struct regulator_init_data wm831x_regulator_init_dcdc[WM831X_MAX_DCDC] = {
1026         {
1027                 .constraints = {
1028                         .name = "DCDC1",
1029                         .min_uV = 600000,
1030                         .max_uV = 1800000,//0.6-1.8V
1031                         .apply_uV = true,               
1032                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1033                 },
1034                 .num_consumer_supplies = ARRAY_SIZE(dcdc1_consumers),
1035                 .consumer_supplies = dcdc1_consumers,
1036         },
1037         {
1038                 .constraints = {
1039                         .name = "DCDC2",
1040                         .min_uV = 600000,
1041                         .max_uV = 1800000,//0.6-1.8V
1042                         .apply_uV = true,               
1043                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1044                 },
1045                 .num_consumer_supplies = ARRAY_SIZE(dcdc2_consumers),
1046                 .consumer_supplies = dcdc2_consumers,
1047         },
1048         {
1049                 .constraints = {
1050                         .name = "DCDC3",
1051                         .min_uV = 850000,
1052                         .max_uV = 3400000,//0.85-3.4V
1053                         .apply_uV = true,               
1054                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1055                 },
1056                 .num_consumer_supplies = ARRAY_SIZE(dcdc3_consumers),
1057                 .consumer_supplies = dcdc3_consumers,
1058         },
1059         {
1060                 .constraints = {
1061                         .name = "DCDC4",
1062                         .min_uV = 00000000,
1063                         .max_uV = 30000000,//30V/40mA
1064                         .apply_uV = true,               
1065                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1066                 },
1067                 .num_consumer_supplies = ARRAY_SIZE(dcdc4_consumers),
1068                 .consumer_supplies = dcdc4_consumers,
1069         },
1070         
1071 };
1072 struct regulator_init_data wm831x_regulator_init_epe[WM831X_MAX_EPE] = {
1073         {
1074                 .constraints = {
1075                         .name = "EPE1",
1076                         .min_uV = 1200000,
1077                         .max_uV = 3000000,
1078                         .apply_uV = true,               
1079                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1080                 },
1081                 .num_consumer_supplies = ARRAY_SIZE(epe1_consumers),
1082                 .consumer_supplies = epe1_consumers,
1083         },
1084         {
1085                 .constraints = {
1086                         .name = "EPE2",
1087                         .min_uV = 1200000,
1088                         .max_uV = 3000000,
1089                         .apply_uV = true,               
1090                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1091                 },
1092                 .num_consumer_supplies = ARRAY_SIZE(epe2_consumers),
1093                 .consumer_supplies = epe2_consumers,
1094         },
1095 };
1096
1097 struct regulator_init_data wm831x_regulator_init_ldo[WM831X_MAX_LDO] = {
1098         {
1099                 .constraints = {
1100                         .name = "LDO1",
1101                         .min_uV = 900000,
1102                         .max_uV = 3300000,
1103                         .apply_uV = true,               
1104                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1105                 },
1106                 .num_consumer_supplies = ARRAY_SIZE(ldo1_consumers),
1107                 .consumer_supplies = ldo1_consumers,
1108         },
1109         {
1110                 .constraints = {
1111                         .name = "LDO2",
1112                         .min_uV = 900000,
1113                         .max_uV = 3300000,
1114                         .apply_uV = true,               
1115                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1116                 },
1117                 .num_consumer_supplies = ARRAY_SIZE(ldo2_consumers),
1118                 .consumer_supplies = ldo2_consumers,
1119         },
1120         {
1121                 .constraints = {
1122                         .name = "LDO3",
1123                         .min_uV = 900000,
1124                         .max_uV = 3300000,
1125                         .apply_uV = true,               
1126                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1127                 },
1128                 .num_consumer_supplies = ARRAY_SIZE(ldo3_consumers),
1129                 .consumer_supplies = ldo3_consumers,
1130         },
1131         {
1132                 .constraints = {
1133                         .name = "LDO4",
1134                         .min_uV = 900000,
1135                         .max_uV = 3300000,
1136                         .apply_uV = true,               
1137                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1138                 },
1139                 .num_consumer_supplies = ARRAY_SIZE(ldo4_consumers),
1140                 .consumer_supplies = ldo4_consumers,
1141         },
1142         {
1143                 .constraints = {
1144                         .name = "LDO5",
1145                         .min_uV = 900000,
1146                         .max_uV = 3300000,
1147                         .apply_uV = true,               
1148                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1149                 },
1150                 .num_consumer_supplies = ARRAY_SIZE(ldo5_consumers),
1151                 .consumer_supplies = ldo5_consumers,
1152         },
1153         {
1154                 .constraints = {
1155                         .name = "LDO6",
1156                         .min_uV = 900000,
1157                         .max_uV = 3300000,
1158                         .apply_uV = true,               
1159                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1160                 },
1161                 .num_consumer_supplies = ARRAY_SIZE(ldo6_consumers),
1162                 .consumer_supplies = ldo6_consumers,
1163         },
1164         {
1165                 .constraints = {
1166                         .name = "LDO7",
1167                         .min_uV = 1000000,
1168                         .max_uV = 3500000,
1169                         .apply_uV = true,               
1170                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1171                 },
1172                 .num_consumer_supplies = ARRAY_SIZE(ldo7_consumers),
1173                 .consumer_supplies = ldo7_consumers,
1174         },
1175         {
1176                 .constraints = {
1177                         .name = "LDO8",
1178                         .min_uV = 1000000,
1179                         .max_uV = 3500000,
1180                         .apply_uV = true,               
1181                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1182                 },
1183                 .num_consumer_supplies = ARRAY_SIZE(ldo8_consumers),
1184                 .consumer_supplies = ldo8_consumers,
1185         },
1186         {
1187                 .constraints = {
1188                         .name = "LDO9",
1189                         .min_uV = 1000000,
1190                         .max_uV = 3500000,
1191                         .apply_uV = true,               
1192                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1193                 },
1194                 .num_consumer_supplies = ARRAY_SIZE(ldo9_consumers),
1195                 .consumer_supplies = ldo9_consumers,
1196         },
1197         {
1198                 .constraints = {
1199                         .name = "LDO10",
1200                         .min_uV = 1000000,
1201                         .max_uV = 3500000,
1202                         .apply_uV = true,               
1203                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1204                 },
1205                 .num_consumer_supplies = ARRAY_SIZE(ldo10_consumers),
1206                 .consumer_supplies = ldo10_consumers,
1207         },
1208         {
1209                 .constraints = {
1210                         .name = "LDO11",
1211                         .min_uV = 1200000,
1212                         .max_uV = 3000000,
1213                         .apply_uV = true,               
1214                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,           
1215                 },
1216                 .num_consumer_supplies = ARRAY_SIZE(ldo11_consumers),
1217                 .consumer_supplies = ldo11_consumers,
1218         },
1219 };
1220
1221 struct regulator_init_data wm831x_regulator_init_isink[WM831X_MAX_ISINK] = {
1222         {
1223                 .constraints = {
1224                         .name = "ISINK1",
1225                         .min_uA = 00000,
1226                         .max_uA = 40000,
1227                         .always_on = true,
1228                         .apply_uV = true,               
1229                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT,           
1230                 },
1231                 .num_consumer_supplies = ARRAY_SIZE(isink1_consumers),
1232                 .consumer_supplies = isink1_consumers,
1233         },
1234         {
1235                 .constraints = {
1236                         .name = "ISINK2",
1237                         .min_uA = 0000000,
1238                         .max_uA = 0000000,
1239                         .apply_uV = false,              
1240                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT,           
1241                 },
1242                 .num_consumer_supplies = ARRAY_SIZE(isink2_consumers),
1243                 .consumer_supplies = isink2_consumers,
1244         },
1245 };
1246
1247 static int wm831x_checkrange(int start,int num,int val)
1248 {   
1249         if((val<(start+num))&&(val>=start))
1250                 return 0;
1251         else 
1252                 return -1;
1253 }
1254
1255 static int wm831x_init_pin_type(struct wm831x *wm831x)
1256 {
1257 #if 1
1258         struct wm831x_pdata *pdata = wm831x->dev->platform_data;
1259         struct rk29_gpio_expander_info *wm831x_gpio_settinginfo;
1260         uint16_t offset = 0;
1261         uint16_t wm831x_settingpin_num = 0;
1262         uint16_t ret = 0;
1263         int i = 0;
1264
1265         if(wm831x)
1266         {
1267                 wm831x_gpio_settinginfo=pdata->settinginfo;
1268                 if(wm831x_gpio_settinginfo)
1269                 {
1270                         wm831x_settingpin_num = pdata->settinginfolen;
1271                         for(i=0;i<wm831x_settingpin_num;i++)
1272                         {
1273                                 if(!wm831x_checkrange(pdata->gpio_base,pdata->gpio_pin_num,wm831x_gpio_settinginfo[i].gpio_num))
1274                                 {
1275                                         offset = wm831x_gpio_settinginfo[i].gpio_num - pdata->gpio_base;
1276
1277                                         if(wm831x_gpio_settinginfo[i].pin_type==GPIO_IN)
1278                                         {
1279                                                 wm831x_set_bits(wm831x,(WM831X_GPIO1_CONTROL+offset), WM831X_GPN_DIR_MASK|WM831X_GPN_TRI_MASK, 1<<WM831X_GPN_DIR_SHIFT|1<<WM831X_GPN_TRI_SHIFT);
1280                                         }
1281                                         else
1282                                         {
1283                                                 wm831x_set_bits(wm831x,(WM831X_GPIO1_CONTROL+offset), WM831X_GPN_DIR_MASK|WM831X_GPN_TRI_MASK, 1<<WM831X_GPN_TRI_SHIFT);
1284                                                 if(wm831x_gpio_settinginfo[i].pin_value==GPIO_HIGH)
1285                                                 {
1286                                                         wm831x_set_bits(wm831x, WM831X_GPIO_LEVEL, (1 << offset),(1 << offset));
1287                                                 }
1288                                                 else
1289                                                 {
1290                                                         wm831x_set_bits(wm831x, WM831X_GPIO_LEVEL, (1 << offset),(0 << offset));
1291                                                 }
1292                                         }
1293                                         
1294                                 }
1295                         }
1296                 }
1297         }
1298
1299         for(i=0;i<pdata->gpio_pin_num;i++)
1300         {
1301                 wm831x_set_bits(wm831x,(WM831X_GPIO1_CONTROL+i), 
1302                         WM831X_GPN_PULL_MASK|WM831X_GPN_POL_MASK|WM831X_GPN_OD_MASK|WM831X_GPN_TRI_MASK, 
1303                         1<<WM831X_GPN_POL_SHIFT|1<<WM831X_GPN_TRI_SHIFT);
1304                 ret =  wm831x_reg_read(wm831x, WM831X_GPIO1_CONTROL+i);
1305                 printk("Gpio%d Pin Configuration = %x\n",i,ret);
1306         }
1307 #endif
1308         return 0;
1309 }
1310
1311 /*
1312  * GPIO Buttons
1313  */
1314 #if defined(CONFIG_KEYBOARD_WM831X_GPIO)
1315 static struct wm831x_gpio_keys_button wm831x_gpio_buttons[] = {
1316 {       
1317         .code           = KEY_MEDIA,
1318         .gpio           = TCA6424_P21,
1319         .active_low     = 1,
1320         .desc           = "media",
1321         .wakeup         = 0,
1322         .debounce_interval = 120,
1323 },
1324 {
1325     .code= KEY_VOLUMEUP,
1326                 .gpio= WM831X_P05,
1327                 .active_low= 1,
1328                 .desc= "volume_up",
1329                 .wakeup= 0,
1330 },
1331 {
1332                 .code= KEY_CAMERA,
1333                 .gpio= WM831X_P06,
1334                 .active_low= 1,
1335                 .desc= "camera",
1336                 .wakeup= 0,
1337 },
1338 {
1339                 .code= KEY_VOLUMEDOWN,
1340                 .gpio= WM831X_P07,
1341                 .active_low= 1,
1342                 .desc= "volume_down",
1343                 .wakeup= 0,
1344 },
1345 {
1346                 .code= KEY_END,
1347                 .gpio= WM831X_P09,
1348                 .active_low= 1,
1349                 .desc= "enter",
1350                 .wakeup= 0,
1351 },
1352 {
1353                 .code= KEY_MENU,
1354                 .gpio= WM831X_P10,
1355                 .active_low= 1,
1356                 .desc= "menu",
1357                 .wakeup= 0,
1358 },
1359 {
1360                 .code= KEY_SEND,
1361                 .gpio= WM831X_P11,
1362                 .active_low= 1,
1363                 .desc= "esc",
1364                 .wakeup= 0,
1365 },
1366 {
1367                 .code= KEY_BACK,
1368                 .gpio= WM831X_P12,
1369                 .active_low= 1,
1370                 .desc= "home",
1371                 .wakeup= 0,                     
1372 },
1373 };
1374
1375 struct wm831x_gpio_keys_pdata wm831x_gpio_keys_platdata = {
1376         .buttons        = wm831x_gpio_buttons,
1377         .nbuttons       = ARRAY_SIZE(wm831x_gpio_buttons),
1378 };
1379
1380 #endif
1381 struct wm831x_pdata wm831x_platdata = {
1382         /** Called before subdevices are set up */
1383         .pre_init= wm831x_pre_init,
1384         /** Called after subdevices are set up */
1385         .post_init = wm831x_post_init,
1386         /** Called before subdevices are power down */
1387         .last_deinit = wm831x_last_deinit,
1388         
1389 #if defined(CONFIG_GPIO_WM831X)
1390         .gpio_base=WM831X_GPIO_EXPANDER_BASE,
1391         .gpio_pin_num=WM831X_TOTOL_GPIO_NUM,
1392         .settinginfo=wm831x_gpio_settinginfo,
1393         .settinginfolen=ARRAY_SIZE(wm831x_gpio_settinginfo),
1394         .pin_type_init = wm831x_init_pin_type,
1395         .irq_base= NR_AIC_IRQS + 7*NUM_GROUP,
1396 #endif
1397
1398         .backlight = &wm831x_backlight_platdata,
1399
1400         .backup = &wm831x_backup_platdata,
1401         
1402         .battery = &wm831x_battery_platdata,
1403         //.wm831x_touch_pdata = NULL,
1404         //.watchdog = NULL,
1405         
1406 #if defined(CONFIG_KEYBOARD_WM831X_GPIO)        
1407         .gpio_keys = &wm831x_gpio_keys_platdata,
1408 #endif
1409
1410         /** LED1 = 0 and so on */
1411         .status = {&wm831x_status_platdata[0], &wm831x_status_platdata[1]},
1412         
1413         /** DCDC1 = 0 and so on */
1414         .dcdc = {&wm831x_regulator_init_dcdc[0], &wm831x_regulator_init_dcdc[1], &wm831x_regulator_init_dcdc[2], &wm831x_regulator_init_dcdc[3]},
1415
1416         /** EPE1 = 0 and so on */
1417         .epe = {&wm831x_regulator_init_epe[0], &wm831x_regulator_init_epe[1]},
1418
1419         /** LDO1 = 0 and so on */
1420         .ldo = {&wm831x_regulator_init_ldo[0], &wm831x_regulator_init_ldo[1], &wm831x_regulator_init_ldo[2], &wm831x_regulator_init_ldo[3],
1421                         &wm831x_regulator_init_ldo[4], &wm831x_regulator_init_ldo[5], &wm831x_regulator_init_ldo[6], &wm831x_regulator_init_ldo[7],
1422                         &wm831x_regulator_init_ldo[8], &wm831x_regulator_init_ldo[9], &wm831x_regulator_init_ldo[10]},
1423
1424         /** ISINK1 = 0 and so on*/
1425         .isink = {&wm831x_regulator_init_isink[0], &wm831x_regulator_init_isink[1]},
1426 };
1427 #endif
1428
1429
1430
1431 #if defined(CONFIG_RK29_GPS)
1432
1433 #define         RK29_GPS_POWER_PIN              RK29_PIN6_PB2
1434 #define         RK29_GPS_RESET_PIN              RK29_PIN6_PC1
1435
1436 int rk29_gps_power_up(void)
1437 {       
1438         printk("%s \n", __FUNCTION__);  
1439
1440     gpio_request(RK29_GPS_POWER_PIN, NULL);    
1441         gpio_direction_output(RK29_GPS_POWER_PIN, GPIO_HIGH);   
1442
1443         return 0;
1444 }
1445
1446 int rk29_gps_power_down(void)
1447 {       
1448         printk("%s \n", __FUNCTION__);  
1449
1450     gpio_request(RK29_GPS_POWER_PIN, NULL);
1451         gpio_direction_output(RK29_GPS_POWER_PIN, GPIO_LOW);            
1452
1453         return 0;
1454 }
1455
1456 int rk29_gps_reset_set(int level)
1457 {
1458         gpio_request(RK29_GPS_RESET_PIN, NULL);
1459         if (level)
1460                 gpio_direction_output(RK29_GPS_RESET_PIN, GPIO_HIGH);
1461         else
1462                 gpio_direction_output(RK29_GPS_RESET_PIN, GPIO_LOW);
1463
1464         return 0;
1465 }
1466
1467 struct rk29_gps_data rk29_gps_info = {  
1468         .power_up = rk29_gps_power_up,  
1469         .power_down = rk29_gps_power_down,      
1470         .reset = rk29_gps_reset_set,
1471         .uart_id = 3,
1472 };
1473
1474 struct platform_device rk29_device_gps = {
1475         .name = "rk29_gps",
1476         .id = -1,               
1477         .dev            = {
1478         .platform_data = &rk29_gps_info,        
1479                 }           
1480         };
1481 #endif
1482
1483 /*****************************************************************************************
1484  * wm8994  codec
1485  * author: qjb@rock-chips.com
1486  *****************************************************************************************/
1487 //#if defined(CONFIG_MFD_WM8994)
1488 #if defined (CONFIG_REGULATOR_WM8994)
1489 static struct regulator_consumer_supply wm8994_ldo1_consumers[] = {
1490         {
1491                 .supply = "DBVDD",
1492         },
1493         {
1494                 .supply = "AVDD1",
1495         },
1496         {
1497                 .supply = "CPVDD",
1498         },
1499         {
1500                 .supply = "SPKVDD1",
1501         }               
1502 };
1503 static struct regulator_consumer_supply wm8994_ldo2_consumers[] = {
1504         {
1505                 .supply = "DCVDD",
1506         },
1507         {
1508                 .supply = "AVDD2",
1509         },
1510         {
1511                 .supply = "SPKVDD2",
1512         }                       
1513 };
1514 struct regulator_init_data regulator_init_data_ldo1 = {
1515         .constraints = {
1516                 .name = "wm8994-ldo1",
1517                 .min_uA = 00000,
1518                 .max_uA = 18000,
1519                 .always_on = true,
1520                 .apply_uV = true,               
1521                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT,           
1522         },
1523         .num_consumer_supplies = ARRAY_SIZE(wm8994_ldo1_consumers),
1524         .consumer_supplies = wm8994_ldo1_consumers,     
1525 };
1526 struct regulator_init_data regulator_init_data_ldo2 = {
1527         .constraints = {
1528                 .name = "wm8994-ldo2",
1529                 .min_uA = 00000,
1530                 .max_uA = 18000,
1531                 .always_on = true,
1532                 .apply_uV = true,               
1533                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_CURRENT,           
1534         },
1535         .num_consumer_supplies = ARRAY_SIZE(wm8994_ldo2_consumers),
1536         .consumer_supplies = wm8994_ldo2_consumers,     
1537 };
1538 #endif 
1539 struct wm8994_drc_cfg wm8994_drc_cfg_pdata = {
1540         .name = "wm8994_DRC",
1541         .regs = {0,0,0,0,0},
1542 };
1543
1544 struct wm8994_retune_mobile_cfg wm8994_retune_mobile_cfg_pdata = {
1545         .name = "wm8994_EQ",
1546         .rate = 0,
1547         .regs = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
1548 }; 
1549
1550 struct wm8994_pdata wm8994_platdata = { 
1551 #if defined (CONFIG_GPIO_WM8994)
1552         .gpio_base = WM8994_GPIO_EXPANDER_BASE,
1553         //Fill value to initialize the GPIO
1554         .gpio_defaults ={},
1555 #endif  
1556         //enable=0 disable ldo
1557 #if defined (CONFIG_REGULATOR_WM8994)   
1558         .ldo = {
1559                 {
1560                         .enable = 0,
1561                         //RK29_PIN5_PA1
1562                         .supply = NULL,
1563                         .init_data = &regulator_init_data_ldo1,
1564                 },
1565                 {
1566                         .enable = 0,
1567                         .supply = NULL,         
1568                         .init_data = &regulator_init_data_ldo2,
1569                 }
1570         },
1571 #endif  
1572         //DRC 0--use default
1573         .num_drc_cfgs = 0,
1574         .drc_cfgs = &wm8994_drc_cfg_pdata,
1575         //EQ   0--use default 
1576         .num_retune_mobile_cfgs = 0,
1577         .retune_mobile_cfgs = &wm8994_retune_mobile_cfg_pdata,
1578         
1579         .lineout1_diff = 1,
1580         .lineout2_diff = 1,
1581         
1582         .lineout1fb = 1,
1583         .lineout2fb = 1,
1584         
1585         .micbias1_lvl = 1,
1586         .micbias2_lvl = 1,
1587         
1588         .jd_scthr = 0,
1589         .jd_thr = 0,
1590
1591         .PA_control_pin = 0,    
1592         .Power_EN_Pin = RK29_PIN5_PA1,
1593
1594         .speaker_incall_vol = 0,
1595         .speaker_incall_mic_vol = -9,
1596         .speaker_normal_vol = 6,
1597         .earpiece_incall_vol = 0,
1598         .headset_incall_vol = 6,
1599         .headset_incall_mic_vol = -6,
1600         .headset_normal_vol = 6,
1601         .BT_incall_vol = 0,
1602         .BT_incall_mic_vol = 0,
1603         .recorder_vol = 50,
1604         
1605 };
1606 //#endif 
1607
1608 #ifdef CONFIG_RK_HEADSET_DET
1609 #define HEADSET_GPIO RK29_PIN4_PD2
1610 struct rk_headset_pdata rk_headset_info = {
1611         .Headset_gpio           = RK29_PIN4_PD2,
1612         .headset_in_type= HEADSET_IN_HIGH,
1613         .Hook_gpio = RK29_PIN4_PD1,//Detection Headset--Must be set
1614 };
1615
1616 struct platform_device rk_device_headset = {
1617                 .name   = "rk_headsetdet",
1618                 .id     = 0,
1619                 .dev    = {
1620                     .platform_data = &rk_headset_info,
1621                 }
1622 };
1623 #endif
1624
1625 #if defined(CONFIG_GS_L3G4200D)
1626
1627 #include <linux/l3g4200d.h>
1628 #define L3G4200D_INT_PIN  RK29_PIN5_PA3
1629
1630 static int l3g4200d_init_platform_hw(void)
1631 {
1632         if (gpio_request(L3G4200D_INT_PIN, NULL) != 0) {
1633                 gpio_free(L3G4200D_INT_PIN);
1634                 printk("%s: request l3g4200d int pin error\n", __func__);
1635                 return -EIO;
1636         }
1637         gpio_pull_updown(L3G4200D_INT_PIN, 1);
1638         return 0;
1639 }
1640
1641 static struct l3g4200d_platform_data l3g4200d_info = {
1642         .fs_range = 1,
1643         
1644         .axis_map_x = 0,
1645         .axis_map_y = 1,
1646         .axis_map_z = 2,
1647
1648         .negate_x = 1,
1649         .negate_y = 1,
1650         .negate_z = 0,
1651
1652         .init = l3g4200d_init_platform_hw,
1653 };
1654
1655 #endif
1656
1657 /*****************************************************************************************
1658  * i2c devices
1659  * author: kfx@rock-chips.com
1660 *****************************************************************************************/
1661 static int rk29_i2c0_io_init(void)
1662 {
1663 #ifdef CONFIG_RK29_I2C0_CONTROLLER
1664         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_I2C0_SCL);
1665         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_I2C0_SDA);
1666 #else
1667         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_GPIO2B7);
1668         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_GPIO2B6);
1669 #endif
1670         return 0;
1671 }
1672
1673 static int rk29_i2c1_io_init(void)
1674 {
1675 #ifdef CONFIG_RK29_I2C1_CONTROLLER
1676         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_I2C1_SCL);
1677         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_I2C1_SDA);
1678 #else
1679         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_GPIO1A7);
1680         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_GPIO1A6);
1681 #endif
1682         return 0;
1683 }
1684 static int rk29_i2c2_io_init(void)
1685 {
1686 #ifdef CONFIG_RK29_I2C2_CONTROLLER
1687         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_I2C2_SCL);
1688         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_I2C2_SDA);
1689 #else
1690         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_GPIO5D4);
1691         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_GPIO5D3);
1692 #endif
1693         return 0;
1694 }
1695
1696 static int rk29_i2c3_io_init(void)
1697 {
1698 #ifdef CONFIG_RK29_I2C3_CONTROLLER
1699         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_I2C3_SCL);
1700         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_I2C3_SDA);
1701 #else
1702         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_GPIO2B5);
1703         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_GPIO2B4);
1704 #endif
1705         return 0;
1706 }
1707 #ifdef CONFIG_RK29_I2C0_CONTROLLER
1708 struct rk29_i2c_platform_data default_i2c0_data = {
1709         .bus_num    = 0,
1710         .flags      = 0,
1711         .slave_addr = 0xff,
1712         .scl_rate  = 400*1000,
1713         .mode           = I2C_MODE_IRQ,
1714         .io_init = rk29_i2c0_io_init,
1715 };
1716 #else
1717 struct i2c_gpio_platform_data default_i2c0_data = {
1718        .sda_pin = RK29_PIN2_PB6,
1719        .scl_pin = RK29_PIN2_PB7,
1720        .udelay = 5, // clk = 500/udelay = 100Khz
1721        .timeout = 100,//msecs_to_jiffies(200),
1722        .bus_num    = 0,
1723        .io_init = rk29_i2c0_io_init,
1724 };
1725 #endif
1726 #ifdef CONFIG_RK29_I2C1_CONTROLLER
1727 struct rk29_i2c_platform_data default_i2c1_data = {
1728         .bus_num    = 1,
1729         .flags      = 0,
1730         .slave_addr = 0xff,
1731         .scl_rate  = 400*1000,
1732         .mode           = I2C_MODE_IRQ,
1733         .io_init = rk29_i2c1_io_init,
1734 };
1735 #else
1736 struct i2c_gpio_platform_data default_i2c1_data = {
1737        .sda_pin = RK29_PIN1_PA6,
1738        .scl_pin = RK29_PIN1_PA7,
1739        .udelay = 5, // clk = 500/udelay = 100Khz
1740        .timeout = 100,//msecs_to_jiffies(200),
1741        .bus_num    = 1,
1742        .io_init = rk29_i2c1_io_init,
1743 };
1744 #endif
1745 #ifdef CONFIG_RK29_I2C2_CONTROLLER
1746 struct rk29_i2c_platform_data default_i2c2_data = {
1747         .bus_num    = 2,
1748         .flags      = 0,
1749         .slave_addr = 0xff,
1750         .scl_rate  = 400*1000,
1751         .mode           = I2C_MODE_IRQ,
1752         .io_init = rk29_i2c2_io_init,
1753 };
1754 #else
1755 struct i2c_gpio_platform_data default_i2c2_data = {
1756        .sda_pin = RK29_PIN5_PD3,
1757        .scl_pin = RK29_PIN5_PD4,
1758        .udelay = 5, // clk = 500/udelay = 100Khz
1759        .timeout = 100,//msecs_to_jiffies(200),
1760        .bus_num    = 2,
1761        .io_init = rk29_i2c2_io_init,
1762 };
1763 #endif
1764 #ifdef CONFIG_RK29_I2C3_CONTROLLER
1765 struct rk29_i2c_platform_data default_i2c3_data = {
1766         .bus_num    = 3,
1767         .flags      = 0,
1768         .slave_addr = 0xff,
1769         .scl_rate  = 400*1000,
1770         .mode           = I2C_MODE_IRQ,
1771         .io_init = rk29_i2c3_io_init,
1772 };
1773 #else
1774 struct i2c_gpio_platform_data default_i2c3_data = {
1775        .sda_pin = RK29_PIN5_PB5,
1776        .scl_pin = RK29_PIN5_PB4,
1777        .udelay = 5, // clk = 500/udelay = 100Khz
1778        .timeout = 100,//msecs_to_jiffies(200),
1779        .bus_num    = 3,
1780        .io_init = rk29_i2c3_io_init,
1781 };
1782 #endif
1783 #ifdef CONFIG_I2C0_RK29
1784 static struct i2c_board_info __initdata board_i2c0_devices[] = {
1785 #if defined (CONFIG_RK1000_CONTROL)
1786         {
1787                 .type                   = "rk1000_control",
1788                 .addr           = 0x40,
1789                 .flags                  = 0,
1790         },
1791 #endif
1792 #if defined (CONFIG_SND_SOC_RK1000)
1793         {
1794                 .type                   = "rk1000_i2c_codec",
1795                 .addr           = 0x60,
1796                 .flags                  = 0,
1797         },
1798 #endif
1799 #if defined (CONFIG_SND_SOC_WM8900)
1800         {
1801                 .type                   = "wm8900",
1802                 .addr           = 0x1A,
1803                 .flags                  = 0,
1804         },
1805 #endif
1806 #if defined (CONFIG_SND_SOC_WM8994)
1807         {
1808                 .type                   = "wm8994",
1809                 .addr           = 0x1a,
1810                 .flags                  = 0,
1811 //      #if defined(CONFIG_MFD_WM8994)  
1812                 .platform_data  = &wm8994_platdata,     
1813 //      #endif  
1814         },
1815 #endif
1816 #if defined (CONFIG_BATTERY_STC3100)
1817         {
1818                 .type                   = "stc3100",
1819                 .addr           = 0x70,
1820                 .flags                  = 0,
1821         },
1822 #endif
1823 #if defined (CONFIG_BATTERY_BQ27510)
1824         {
1825                 .type                   = "bq27510",
1826                 .addr           = 0x55,
1827                 .flags                  = 0,
1828         },
1829 #endif
1830 #if defined (CONFIG_RTC_HYM8563)
1831         {
1832                 .type                   = "rtc_hym8563",
1833                 .addr           = 0x51,
1834                 .flags                  = 0,
1835                 .irq            = RK29_PIN0_PA1,
1836         },
1837 #endif
1838 #if defined (CONFIG_GS_MMA8452)
1839     {
1840       .type           = "gs_mma8452",
1841       .addr           = 0x1c,
1842       .flags          = 0,
1843       .irq            = MMA8452_INT_PIN,
1844       .platform_data  = &mma8452_info,
1845     },
1846 #endif
1847 #if defined (CONFIG_COMPASS_AK8973)
1848         {
1849                 .type                   = "ak8973",
1850                 .addr           = 0x1d,
1851                 .flags                  = 0,
1852                 .irq                    = RK29_PIN6_PC5,
1853         },
1854 #endif
1855 #if defined (CONFIG_COMPASS_AK8975)
1856         {
1857                 .type                   = "ak8975",
1858                 .addr           = 0x0d,
1859                 .flags                  = 0,
1860                 .irq                    = RK29_PIN6_PC5,
1861         },
1862 #endif
1863 #if defined (CONFIG_INPUT_LPSENSOR_ISL29028)
1864         {
1865                 .type           = "isl29028",
1866                 .addr           = 0x44,
1867                 .flags          = 0,
1868                 .irq            = RK29_PIN4_PD3,
1869         },
1870 #endif
1871 #if defined (CONFIG_ANX7150)
1872     {
1873                 .type           = "anx7150",
1874         .addr           = 0x39,             //0x39, 0x3d
1875         .flags          = 0,
1876         .irq            = RK29_PIN2_PA3,
1877     },
1878 #endif
1879 #if defined (CONFIG_GS_L3G4200D)
1880         {
1881                 .type           = "gs_l3g4200d",
1882                 .addr           = 0x69,
1883                 .flags          = 0,
1884                 .irq            = L3G4200D_INT_PIN,
1885                 .platform_data  = &l3g4200d_info,
1886         },
1887 #endif
1888 #if defined (CONFIG_SENSORS_MPU3050) 
1889         {
1890                 .type                   = "mpu3050",
1891                 .addr                   = 0x68,
1892                 .flags                  = 0,
1893                 .irq                    = RK29_PIN4_PC4,
1894                 .platform_data  = &mpu3050_data,
1895         },
1896 #endif
1897 };
1898 #endif
1899
1900 #ifdef CONFIG_I2C1_RK29
1901 static struct i2c_board_info __initdata board_i2c1_devices[] = {
1902 #if defined (CONFIG_RK1000_CONTROL1)
1903         {
1904                 .type                   = "rk1000_control",
1905                 .addr                   = 0x40,
1906                 .flags                  = 0,
1907         },
1908 #endif
1909
1910 };
1911 #endif
1912
1913 #ifdef CONFIG_I2C2_RK29
1914 static struct i2c_board_info __initdata board_i2c2_devices[] = {
1915 #if defined (CONFIG_TOUCHSCREEN_GT801_IIC)
1916 {
1917         .type           = "gt801_ts",
1918         .addr           = 0x55,
1919         .flags          = 0,
1920         .irq            = RK29_PIN4_PD5,
1921         .platform_data = &gt801_info,
1922 },      
1923 #endif
1924
1925 #if defined (CONFIG_TOUCHSCREEN_GT818_IIC)
1926 {
1927         .type           = "gt818_ts",
1928         .addr           = 0x5d,
1929         .flags          = 0,
1930         .irq            = RK29_PIN4_PD5,
1931         .platform_data = &gt818_info,
1932 },
1933 #endif
1934
1935 #if defined (CONFIG_TOUCHSCREEN_ILI2102_IIC)
1936 {
1937         .type           = "ili2102_ts",
1938         .addr           = 0x41,
1939         .flags          = I2C_M_NEED_DELAY,
1940         .udelay      = 600,
1941         .irq            = RK29_PIN4_PD5,
1942         .platform_data = &ili2102_info,
1943 },      
1944 #endif
1945
1946 #if defined (CONFIG_MFD_WM831X_I2C)
1947 {
1948         .type           = "wm8310",
1949         .addr           = 0x34,
1950         .flags          = 0,
1951         .irq            = RK29_PIN4_PD0,
1952         .platform_data = &wm831x_platdata,
1953 },      
1954 #endif
1955 #if defined (CONFIG_HANNSTAR_P1003)
1956     {
1957       .type           = "p1003_touch",
1958       .addr           = 0x04,
1959       .flags          = 0,
1960       .irq            = RK29_PIN0_PA2,
1961       .platform_data  = &p1003_info,
1962     },
1963 #endif
1964 #if defined (CONFIG_EETI_EGALAX)
1965     {
1966       .type           = "egalax_i2c",
1967       .addr           = 0x04,
1968       .flags          = 0,
1969       .irq            = RK29_PIN4_PD5,
1970       .platform_data  = &eeti_egalax_info,
1971     },
1972 #endif
1973 };
1974 #endif
1975
1976 #ifdef CONFIG_I2C3_RK29
1977 static struct i2c_board_info __initdata board_i2c3_devices[] = {
1978 };
1979 #endif
1980
1981 /*****************************************************************************************
1982  * camera  devices
1983  * author: ddl@rock-chips.com
1984  *****************************************************************************************/
1985 #ifdef CONFIG_VIDEO_RK29 
1986 #define CONFIG_SENSOR_POWER_IOCTL_USR      0
1987 #define CONFIG_SENSOR_RESET_IOCTL_USR      0
1988 #define CONFIG_SENSOR_POWERDOWN_IOCTL_USR      0
1989 #define CONFIG_SENSOR_FLASH_IOCTL_USR      0
1990
1991 #if CONFIG_SENSOR_POWER_IOCTL_USR
1992 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
1993 {
1994     #error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
1995 }
1996 #endif
1997
1998 #if CONFIG_SENSOR_RESET_IOCTL_USR
1999 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
2000 {
2001     #error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
2002 }
2003 #endif
2004
2005 #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
2006 static int sensor_powerdown_usr_cb (struct rk29camera_gpio_res *res,int on)
2007 {
2008     #error "CONFIG_SENSOR_POWERDOWN_IOCTL_USR is 1, sensor_powerdown_usr_cb function must be writed!!";
2009 }
2010 #endif
2011
2012 #if CONFIG_SENSOR_FLASH_IOCTL_USR
2013 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
2014 {
2015     #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
2016 }
2017 #endif
2018
2019 static struct rk29camera_platform_ioctl_cb  sensor_ioctl_cb = {
2020     #if CONFIG_SENSOR_POWER_IOCTL_USR
2021     .sensor_power_cb = sensor_power_usr_cb,
2022     #else
2023     .sensor_power_cb = NULL,
2024     #endif
2025
2026     #if CONFIG_SENSOR_RESET_IOCTL_USR
2027     .sensor_reset_cb = sensor_reset_usr_cb,
2028     #else
2029     .sensor_reset_cb = NULL,
2030     #endif
2031
2032     #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
2033     .sensor_powerdown_cb = sensor_powerdown_usr_cb,
2034     #else
2035     .sensor_powerdown_cb = NULL,
2036     #endif
2037
2038     #if CONFIG_SENSOR_FLASH_IOCTL_USR
2039     .sensor_flash_cb = sensor_flash_usr_cb,
2040     #else
2041     .sensor_flash_cb = NULL,
2042     #endif
2043 };
2044 #include "../../../drivers/media/video/rk29_camera.c"
2045 #endif
2046
2047 /*****************************************************************************************
2048  * backlight  devices
2049  * author: nzy@rock-chips.com
2050  *****************************************************************************************/
2051 #ifdef CONFIG_BACKLIGHT_RK29_BL
2052  /*
2053  GPIO1B5_PWM0_NAME,       GPIO1L_PWM0
2054  GPIO5D2_PWM1_UART1SIRIN_NAME,  GPIO5H_PWM1
2055  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME,   GPIO2L_PWM2
2056  GPIO1A5_EMMCPWREN_PWM3_NAME,     GPIO1L_PWM3
2057  */
2058
2059 #define PWM_ID            0
2060 #define PWM_MUX_NAME      GPIO1B5_PWM0_NAME
2061 #define PWM_MUX_MODE      GPIO1L_PWM0
2062 #define PWM_MUX_MODE_GPIO GPIO1L_GPIO1B5
2063 #define PWM_EFFECT_VALUE  1
2064
2065 //#define LCD_DISP_ON_PIN
2066
2067 #ifdef  LCD_DISP_ON_PIN
2068 #define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
2069 #define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
2070
2071 #define BL_EN_PIN         GPIO0L_GPIO0A5
2072 #define BL_EN_VALUE       GPIO_HIGH
2073 #endif
2074 static int rk29_backlight_io_init(void)
2075 {
2076     int ret = 0;
2077
2078     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
2079         #ifdef  LCD_DISP_ON_PIN
2080     rk29_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
2081
2082     ret = gpio_request(BL_EN_PIN, NULL);
2083     if(ret != 0)
2084     {
2085         gpio_free(BL_EN_PIN);
2086     }
2087
2088     gpio_direction_output(BL_EN_PIN, 0);
2089     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
2090         #endif
2091     return ret;
2092 }
2093
2094 static int rk29_backlight_io_deinit(void)
2095 {
2096     int ret = 0;
2097     #ifdef  LCD_DISP_ON_PIN
2098     gpio_free(BL_EN_PIN);
2099     #endif
2100     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
2101     return ret;
2102 }
2103 struct rk29_bl_info rk29_bl_info = {
2104     .pwm_id   = PWM_ID,
2105     .bl_ref   = PWM_EFFECT_VALUE,
2106     .io_init   = rk29_backlight_io_init,
2107     .io_deinit = rk29_backlight_io_deinit,
2108 };
2109 #endif
2110 /*****************************************************************************************
2111 * pwm voltage regulator devices
2112 ******************************************************************************************/
2113 #if defined (CONFIG_RK29_PWM_REGULATOR)
2114
2115 #define REGULATOR_PWM_ID                                        2
2116 #define REGULATOR_PWM_MUX_NAME                  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME
2117 #define REGULATOR_PWM_MUX_MODE                                          GPIO2L_PWM2
2118 #define REGULATOR_PWM_MUX_MODE_GPIO                             GPIO2L_GPIO2A3
2119 #define REGULATOR_PWM_GPIO                              RK29_PIN2_PA3
2120
2121 static struct regulator_consumer_supply pwm_consumers[] = {
2122         {
2123                 .supply = "vcore",
2124         }
2125 };
2126
2127 static struct regulator_init_data rk29_pwm_regulator_data = {
2128         .constraints = {
2129                 .name = "PWM2",
2130                 .min_uV =  950000,
2131                 .max_uV = 1400000,
2132                 .apply_uV = 1,
2133                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
2134         },
2135         .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
2136         .consumer_supplies = pwm_consumers,
2137 };
2138
2139 static struct pwm_platform_data rk29_regulator_pwm_platform_data = {
2140         .pwm_id = REGULATOR_PWM_ID,
2141         .pwm_gpio = REGULATOR_PWM_GPIO,
2142         //.pwm_iomux_name[] = REGULATOR_PWM_MUX_NAME;
2143         .pwm_iomux_name = REGULATOR_PWM_MUX_NAME,
2144         .pwm_iomux_pwm = REGULATOR_PWM_MUX_MODE,
2145         .pwm_iomux_gpio = REGULATOR_PWM_MUX_MODE_GPIO,
2146         .init_data  = &rk29_pwm_regulator_data,
2147 };
2148
2149 static struct platform_device rk29_device_pwm_regulator = {
2150         .name = "pwm-voltage-regulator",
2151         .id   = -1,
2152         .dev  = {
2153                 .platform_data = &rk29_regulator_pwm_platform_data,
2154         },
2155 };
2156
2157 #endif
2158
2159
2160 #if defined(CONFIG_MTK23D)
2161 static int mtk23d_io_init(void)
2162 {
2163         
2164         return 0;
2165 }
2166
2167 static int mtk23d_io_deinit(void)
2168 {
2169         
2170         return 0;
2171 }
2172  
2173 struct rk2818_23d_data rk2818_23d_info = {
2174         .io_init = mtk23d_io_init,
2175   .io_deinit = mtk23d_io_deinit,
2176         .bp_power = RK29_PIN0_PA0,
2177         .bp_power_active_low = 0,
2178         .bp_reset = RK29_PIN0_PA1,
2179         .bp_reset_active_low = 1,
2180         .bp_statue = RK29_PIN0_PA2,//input  high bp sleep;
2181         .ap_statue = RK29_PIN0_PA4,//output high ap sleep;
2182         .ap_bp_wakeup = RK29_PIN0_PA3, //output AP wake up BP used rising edge;
2183         .bp_ap_wakeup = 0,//input BP wake up AP
2184 };
2185 struct platform_device rk2818_device_mtk23d = { 
2186         .name = "mtk23d",       
2187         .id = -1,       
2188         .dev            = {
2189                 .platform_data = &rk2818_23d_info,
2190         }       
2191     };
2192 #endif
2193
2194
2195 /*****************************************************************************************
2196  * SDMMC devices
2197 *****************************************************************************************/
2198 #ifdef CONFIG_SDMMC0_RK29
2199 static int rk29_sdmmc0_cfg_gpio(void)
2200 {
2201         rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
2202         rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
2203         rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
2204         rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
2205         rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
2206         rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
2207         rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
2208         rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5);   ///GPIO5H_SDMMC0_PWR_EN);  ///GPIO5H_GPIO5D5);
2209         gpio_request(RK29_PIN5_PD5,"sdmmc");
2210         gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
2211         mdelay(100);
2212         gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
2213         return 0;
2214 }
2215
2216 #define CONFIG_SDMMC0_USE_DMA
2217 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
2218         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
2219                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
2220                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
2221         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
2222         .io_init = rk29_sdmmc0_cfg_gpio,
2223         .dma_name = "sd_mmc",
2224 #ifdef CONFIG_SDMMC0_USE_DMA
2225         .use_dma  = 1,
2226 #else
2227         .use_dma = 0,
2228 #endif
2229         .detect_irq = RK29_PIN2_PA2, // INVALID_GPIO
2230         .enable_sd_wakeup = 0,
2231 };
2232 #endif
2233 #ifdef CONFIG_SDMMC1_RK29
2234 #define CONFIG_SDMMC1_USE_DMA
2235 static int rk29_sdmmc1_cfg_gpio(void)
2236 {
2237         rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
2238         rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
2239         rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
2240         rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
2241         rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
2242         rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
2243         //rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_SDMMC1_DETECT_N);
2244         return 0;
2245 }
2246
2247 #ifdef CONFIG_WIFI_CONTROL_FUNC
2248 static int rk29sdk_wifi_status(struct device *dev);
2249 static int rk29sdk_wifi_status_register(void (*callback)(int card_presend, void *dev_id), void *dev_id);
2250 #endif
2251
2252 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK29_PIN1_PD6
2253
2254 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
2255         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
2256                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
2257                                            MMC_VDD_32_33|MMC_VDD_33_34),
2258         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
2259                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
2260         .io_init = rk29_sdmmc1_cfg_gpio,
2261         .dma_name = "sdio",
2262 #ifdef CONFIG_SDMMC1_USE_DMA
2263         .use_dma  = 1,
2264 #else
2265         .use_dma = 0,
2266 #endif
2267 #ifdef CONFIG_WIFI_CONTROL_FUNC
2268         .status = rk29sdk_wifi_status,
2269         .register_status_notify = rk29sdk_wifi_status_register,
2270 #endif
2271 #if 0
2272         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
2273 #endif
2274 };
2275 #endif
2276
2277 #ifdef CONFIG_WIFI_CONTROL_FUNC
2278 #define RK29SDK_WIFI_BT_GPIO_POWER_N       RK29_PIN5_PD6
2279 #define RK29SDK_WIFI_GPIO_RESET_N          RK29_PIN6_PC0
2280 #define RK29SDK_BT_GPIO_RESET_N            RK29_PIN6_PC7
2281
2282 static int rk29sdk_wifi_cd = 0;   /* wifi virtual 'card detect' status */
2283 static void (*wifi_status_cb)(int card_present, void *dev_id);
2284 static void *wifi_status_cb_devid;
2285 int rk29sdk_wifi_power_state = 0;
2286 int rk29sdk_bt_power_state = 0;
2287
2288 static int rk29sdk_wifi_status(struct device *dev)
2289 {
2290         return rk29sdk_wifi_cd;
2291 }
2292
2293 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
2294 {
2295         if(wifi_status_cb)
2296                 return -EAGAIN;
2297         wifi_status_cb = callback;
2298         wifi_status_cb_devid = dev_id;
2299         return 0;
2300 }
2301
2302 static int rk29sdk_wifi_bt_gpio_control_init(void)
2303 {
2304     if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
2305            pr_info("%s: request wifi_bt power gpio failed\n", __func__);
2306            return -1;
2307     }
2308
2309     if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
2310            pr_info("%s: request wifi reset gpio failed\n", __func__);
2311            gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
2312            return -1;
2313     }
2314
2315     if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
2316           pr_info("%s: request bt reset gpio failed\n", __func__);
2317           gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
2318           return -1;
2319     }
2320
2321     gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
2322     gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N,    GPIO_LOW);
2323     gpio_direction_output(RK29SDK_BT_GPIO_RESET_N,      GPIO_LOW);
2324
2325     pr_info("%s: init finished\n",__func__);
2326
2327     return 0;
2328 }
2329
2330 static int rk29sdk_wifi_power(int on)
2331 {
2332         pr_info("%s: %d\n", __func__, on);
2333         if (on){
2334                 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
2335                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
2336                 mdelay(100);
2337                 pr_info("wifi turn on power\n");
2338         }else{
2339                 if (!rk29sdk_bt_power_state){
2340                         gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
2341                         mdelay(100);
2342                         pr_info("wifi shut off power\n");
2343                 }else
2344                 {
2345                         pr_info("wifi shouldn't shut off power, bt is using it!\n");
2346                 }
2347                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
2348
2349         }
2350
2351         rk29sdk_wifi_power_state = on;
2352         return 0;
2353 }
2354
2355 static int rk29sdk_wifi_reset_state;
2356 static int rk29sdk_wifi_reset(int on)
2357 {
2358         pr_info("%s: %d\n", __func__, on);
2359         gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
2360         mdelay(100);
2361         rk29sdk_wifi_reset_state = on;
2362         return 0;
2363 }
2364
2365 int rk29sdk_wifi_set_carddetect(int val)
2366 {
2367         pr_info("%s:%d\n", __func__, val);
2368         rk29sdk_wifi_cd = val;
2369         if (wifi_status_cb){
2370                 wifi_status_cb(val, wifi_status_cb_devid);
2371         }else {
2372                 pr_warning("%s, nobody to notify\n", __func__);
2373         }
2374         return 0;
2375 }
2376 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
2377
2378 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
2379         {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
2380         {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
2381         {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
2382         {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
2383 };
2384
2385 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
2386 {
2387         if (section == PREALLOC_WLAN_SEC_NUM)
2388                 return wlan_static_skb;
2389
2390         if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
2391                 return NULL;
2392
2393         if (wifi_mem_array[section].size < size)
2394                 return NULL;
2395
2396         return wifi_mem_array[section].mem_ptr;
2397 }
2398
2399 int __init rk29sdk_init_wifi_mem(void)
2400 {
2401         int i;
2402         int j;
2403
2404         for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
2405                 wlan_static_skb[i] = dev_alloc_skb(
2406                                 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
2407
2408                 if (!wlan_static_skb[i])
2409                         goto err_skb_alloc;
2410         }
2411
2412         for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
2413                 wifi_mem_array[i].mem_ptr =
2414                                 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
2415
2416                 if (!wifi_mem_array[i].mem_ptr)
2417                         goto err_mem_alloc;
2418         }
2419         return 0;
2420
2421  err_mem_alloc:
2422         pr_err("Failed to mem_alloc for WLAN\n");
2423         for (j = 0 ; j < i ; j++)
2424                 kfree(wifi_mem_array[j].mem_ptr);
2425
2426         i = WLAN_SKB_BUF_NUM;
2427
2428  err_skb_alloc:
2429         pr_err("Failed to skb_alloc for WLAN\n");
2430         for (j = 0 ; j < i ; j++)
2431                 dev_kfree_skb(wlan_static_skb[j]);
2432
2433         return -ENOMEM;
2434 }
2435
2436 static struct wifi_platform_data rk29sdk_wifi_control = {
2437         .set_power = rk29sdk_wifi_power,
2438         .set_reset = rk29sdk_wifi_reset,
2439         .set_carddetect = rk29sdk_wifi_set_carddetect,
2440         .mem_prealloc   = rk29sdk_mem_prealloc,
2441 };
2442 static struct platform_device rk29sdk_wifi_device = {
2443         .name = "bcm4329_wlan",
2444         .id = 1,
2445         .dev = {
2446                 .platform_data = &rk29sdk_wifi_control,
2447          },
2448 };
2449 #endif
2450
2451
2452 /* bluetooth rfkill device */
2453 static struct platform_device rk29sdk_rfkill = {
2454         .name = "rk29sdk_rfkill",
2455         .id = -1,
2456 };
2457
2458
2459 #ifdef CONFIG_VIVANTE
2460 static struct resource resources_gpu[] = {
2461     [0] = {
2462                 .name   = "gpu_irq",
2463         .start  = IRQ_GPU,
2464         .end    = IRQ_GPU,
2465         .flags  = IORESOURCE_IRQ,
2466     },
2467     [1] = {
2468                 .name = "gpu_base",
2469         .start  = RK29_GPU_PHYS,
2470         .end    = RK29_GPU_PHYS + RK29_GPU_SIZE,
2471         .flags  = IORESOURCE_MEM,
2472     },
2473     [2] = {
2474                 .name = "gpu_mem",
2475         .start  = PMEM_GPU_BASE,
2476         .end    = PMEM_GPU_BASE + PMEM_GPU_SIZE,
2477         .flags  = IORESOURCE_MEM,
2478     },
2479 };
2480 static struct platform_device rk29_device_gpu = {
2481     .name             = "galcore",
2482     .id               = 0,
2483     .num_resources    = ARRAY_SIZE(resources_gpu),
2484     .resource         = resources_gpu,
2485 };
2486 #endif
2487 #ifdef CONFIG_KEYS_RK29
2488 extern struct rk29_keys_platform_data rk29_keys_pdata;
2489 static struct platform_device rk29_device_keys = {
2490         .name           = "rk29-keypad",
2491         .id             = -1,
2492         .dev            = {
2493                 .platform_data  = &rk29_keys_pdata,
2494         },
2495 };
2496 #endif
2497
2498 #ifdef CONFIG_USE_GPIO_GENERATE_WAVE
2499 static struct gpio_wave_platform_data gpio_wave_pdata = {
2500         .gpio = RK29_PIN0_PA0,
2501         .Htime = 2000,
2502         .Ltime = 300,
2503         .Dvalue = GPIO_HIGH,
2504 };
2505 static struct platform_device gpio_wave_device = {
2506         .name           = "gpio_wave",
2507         .id     = -1,
2508         .dev            = {
2509                 .platform_data  = &gpio_wave_pdata,
2510         },
2511 };
2512 #endif
2513
2514 static void __init rk29_board_iomux_init(void)
2515 {
2516         #ifdef CONFIG_RK29_PWM_REGULATOR
2517         rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
2518         #endif
2519 }
2520
2521 static struct platform_device *devices[] __initdata = {
2522 #ifdef CONFIG_UART1_RK29
2523         &rk29_device_uart1,
2524 #endif
2525 #ifdef CONFIG_UART0_RK29
2526         &rk29_device_uart0,
2527 #endif
2528 #ifdef CONFIG_UART2_RK29
2529         &rk29_device_uart2,
2530 #endif
2531 #ifdef CONFIG_UART3_RK29
2532         &rk29_device_uart3,
2533 #endif
2534
2535 #ifdef CONFIG_RK29_PWM_REGULATOR
2536         &rk29_device_pwm_regulator,
2537 #endif
2538 #ifdef CONFIG_SPIM0_RK29
2539     &rk29xx_device_spi0m,
2540 #endif
2541 #ifdef CONFIG_SPIM1_RK29
2542     &rk29xx_device_spi1m,
2543 #endif
2544 #ifdef CONFIG_ADC_RK29
2545         &rk29_device_adc,
2546 #endif
2547 #ifdef CONFIG_I2C0_RK29
2548         &rk29_device_i2c0,
2549 #endif
2550 #ifdef CONFIG_I2C1_RK29
2551         &rk29_device_i2c1,
2552 #endif
2553 #ifdef CONFIG_I2C2_RK29
2554         &rk29_device_i2c2,
2555 #endif
2556 #ifdef CONFIG_I2C3_RK29
2557         &rk29_device_i2c3,
2558 #endif
2559
2560 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
2561         &rk29_device_iis_2ch,
2562 #endif
2563 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
2564         &rk29_device_iis_8ch,
2565 #endif
2566
2567 #ifdef CONFIG_KEYS_RK29
2568         &rk29_device_keys,
2569 #endif
2570 #ifdef CONFIG_USE_GPIO_GENERATE_WAVE
2571         &gpio_wave_device,
2572 #endif
2573 #ifdef CONFIG_SDMMC0_RK29
2574         &rk29_device_sdmmc0,
2575 #endif
2576 #ifdef CONFIG_SDMMC1_RK29
2577         &rk29_device_sdmmc1,
2578 #endif
2579
2580 #ifdef CONFIG_MTD_NAND_RK29XX
2581         &rk29xx_device_nand,
2582 #endif
2583
2584 #ifdef CONFIG_WIFI_CONTROL_FUNC
2585         &rk29sdk_wifi_device,
2586 #endif
2587
2588 #ifdef CONFIG_BT
2589         &rk29sdk_rfkill,
2590 #endif
2591
2592 #if defined(CONFIG_MTK23D)
2593         &rk2818_device_mtk23d,
2594 #endif
2595
2596 #ifdef CONFIG_MTD_NAND_RK29
2597         &rk29_device_nand,
2598 #endif
2599
2600 #ifdef CONFIG_FB_RK29
2601         &rk29_device_fb,
2602         &rk29_device_dma_cpy,
2603 #endif
2604 #ifdef CONFIG_BACKLIGHT_RK29_BL
2605         &rk29_device_backlight,
2606 #endif
2607 #ifdef CONFIG_RK29_VMAC
2608         &rk29_device_vmac,
2609 #endif
2610 #ifdef CONFIG_VIVANTE
2611         &rk29_device_gpu,
2612 #endif
2613 #ifdef CONFIG_VIDEO_RK29
2614         &rk29_device_camera,      /* ddl@rock-chips.com : camera support  */
2615         #if (CONFIG_SENSOR_IIC_ADDR_0 != 0x00)
2616         &rk29_soc_camera_pdrv_0,
2617         #endif
2618         &rk29_soc_camera_pdrv_1,
2619         &android_pmem_cam_device,
2620 #endif
2621         &android_pmem_device,
2622         &rk29_vpu_mem_device,
2623 #ifdef CONFIG_USB20_OTG
2624         &rk29_device_usb20_otg,
2625 #endif
2626 #ifdef CONFIG_USB20_HOST
2627         &rk29_device_usb20_host,
2628 #endif
2629 #ifdef CONFIG_USB11_HOST
2630         &rk29_device_usb11_host,
2631 #endif
2632 #ifdef CONFIG_USB_ANDROID
2633         &android_usb_device,
2634         &usb_mass_storage_device,
2635 #endif
2636 #ifdef CONFIG_RK29_IPP
2637         &rk29_device_ipp,
2638 #endif
2639 #ifdef CONFIG_VIDEO_RK29XX_VOUT
2640         &rk29_v4l2_output_devce,
2641 #endif
2642 #ifdef CONFIG_RK_HEADSET_DET
2643     &rk_device_headset,
2644 #endif
2645 #ifdef CONFIG_RK29_GPS
2646         &rk29_device_gps,
2647 #endif
2648 };
2649
2650 #ifdef CONFIG_RK29_VMAC
2651 /*****************************************************************************************
2652  * vmac devices
2653  * author: lyx@rock-chips.com
2654  *****************************************************************************************/
2655 static int rk29_vmac_register_set(void)
2656 {
2657         //config rk29 vmac as rmii, 100MHz
2658         u32 value= readl(RK29_GRF_BASE + 0xbc);
2659         value = (value & 0xfff7ff) | (0x400);
2660         writel(value, RK29_GRF_BASE + 0xbc);
2661         return 0;
2662 }
2663
2664 static int rk29_rmii_io_init(void)
2665 {
2666         int err;
2667
2668         //phy power gpio
2669         err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
2670         if (err) {
2671                 gpio_free(RK29_PIN6_PB0);
2672                 printk("-------request RK29_PIN6_PB0 fail--------\n");
2673                 return -1;
2674         }
2675         //phy power down
2676         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2677         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2678
2679         return 0;
2680 }
2681
2682 static int rk29_rmii_io_deinit(void)
2683 {
2684         //phy power down
2685         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2686         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2687         //free
2688         gpio_free(RK29_PIN6_PB0);
2689         return 0;
2690 }
2691
2692 static int rk29_rmii_power_control(int enable)
2693 {
2694         if (enable) {
2695                 //enable phy power
2696                 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
2697                 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
2698         }
2699         else {
2700                 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2701                 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2702         }
2703         return 0;
2704 }
2705
2706 struct rk29_vmac_platform_data rk29_vmac_pdata = {
2707         .vmac_register_set = rk29_vmac_register_set,
2708         .rmii_io_init = rk29_rmii_io_init,
2709         .rmii_io_deinit = rk29_rmii_io_deinit,
2710         .rmii_power_control = rk29_rmii_power_control,
2711 };
2712 #endif
2713
2714 /*****************************************************************************************
2715  * spi devices
2716  * author: cmc@rock-chips.com
2717  *****************************************************************************************/
2718 #define SPI_CHIPSELECT_NUM 2
2719 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
2720     {
2721                 .name = "spi0 cs0",
2722                 .cs_gpio = RK29_PIN2_PC1,
2723                 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
2724                 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
2725         },
2726         {
2727                 .name = "spi0 cs1",
2728                 .cs_gpio = RK29_PIN1_PA4,
2729                 .cs_iomux_name = GPIO1A4_EMMCWRITEPRT_SPI0CS1_NAME,//if no iomux,set it NULL
2730                 .cs_iomux_mode = GPIO1L_SPI0_CSN1,
2731         }
2732 };
2733
2734 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
2735     {
2736                 .name = "spi1 cs0",
2737                 .cs_gpio = RK29_PIN2_PC5,
2738                 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
2739                 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
2740         },
2741         {
2742                 .name = "spi1 cs1",
2743                 .cs_gpio = RK29_PIN1_PA3,
2744                 .cs_iomux_name = GPIO1A3_EMMCDETECTN_SPI1CS1_NAME,//if no iomux,set it NULL
2745                 .cs_iomux_mode = GPIO1L_SPI1_CSN1,
2746         }
2747 };
2748
2749 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
2750 {
2751 #if 1
2752                 int i;
2753                 if (cs_gpios) {
2754                         for (i=0; i<cs_num; i++) {
2755                                 rk29_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
2756                         }
2757                 }
2758 #endif
2759         return 0;
2760 }
2761
2762 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
2763 {
2764         return 0;
2765 }
2766
2767 static int spi_io_fix_leakage_bug(void)
2768 {
2769 #if 0
2770         gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
2771 #endif
2772         return 0;
2773 }
2774
2775 static int spi_io_resume_leakage_bug(void)
2776 {
2777 #if 0
2778         gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
2779 #endif
2780         return 0;
2781 }
2782
2783 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
2784         .num_chipselect = SPI_CHIPSELECT_NUM,
2785         .chipselect_gpios = rk29xx_spi0_cs_gpios,
2786         .io_init = spi_io_init,
2787         .io_deinit = spi_io_deinit,
2788         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
2789         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
2790 };
2791
2792 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
2793         .num_chipselect = SPI_CHIPSELECT_NUM,
2794         .chipselect_gpios = rk29xx_spi1_cs_gpios,
2795         .io_init = spi_io_init,
2796         .io_deinit = spi_io_deinit,
2797         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
2798         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
2799 };
2800
2801 /*****************************************************************************************
2802  * xpt2046 touch panel
2803  * author: hhb@rock-chips.com
2804  *****************************************************************************************/
2805 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
2806 #define XPT2046_GPIO_INT           RK29_PIN4_PD5 //中断???#define DEBOUNCE_REPTIME  3
2807
2808 static struct xpt2046_platform_data xpt2046_info = {
2809         .model                  = 2046,
2810         .keep_vref_on   = 1,
2811         .swap_xy                = 0,
2812         .debounce_max           = 7,
2813         .debounce_rep           = DEBOUNCE_REPTIME,
2814         .debounce_tol           = 20,
2815         .gpio_pendown           = XPT2046_GPIO_INT,
2816         .pendown_iomux_name = GPIO4D5_CPUTRACECTL_NAME, 
2817         .pendown_iomux_mode = GPIO4H_GPIO4D5,   
2818         .touch_virtualkey_length = 60,
2819         .penirq_recheck_delay_usecs = 1,
2820 #if defined(CONFIG_TOUCHSCREEN_480X800)
2821         .x_min                  = 0,
2822         .x_max                  = 480,
2823         .y_min                  = 0,
2824         .y_max                  = 800,
2825         .touch_ad_top = 3940,
2826         .touch_ad_bottom = 310,
2827         .touch_ad_left = 3772,
2828         .touch_ad_right = 340,
2829 #elif defined(CONFIG_TOUCHSCREEN_800X480)
2830         .x_min                  = 0,
2831         .x_max                  = 800,
2832         .y_min                  = 0,
2833         .y_max                  = 480,
2834         .touch_ad_top = 2447,
2835         .touch_ad_bottom = 207,
2836         .touch_ad_left = 5938,
2837         .touch_ad_right = 153,
2838 #elif defined(CONFIG_TOUCHSCREEN_320X480)
2839         .x_min                  = 0,
2840         .x_max                  = 320,
2841         .y_min                  = 0,
2842         .y_max                  = 480,
2843         .touch_ad_top = 3166,
2844         .touch_ad_bottom = 256,
2845         .touch_ad_left = 3658,
2846         .touch_ad_right = 380,
2847 #endif  
2848 };
2849 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
2850 static struct xpt2046_platform_data xpt2046_info = {
2851         .model                  = 2046,
2852         .keep_vref_on   = 1,
2853         .swap_xy                = 0,
2854         .debounce_max           = 7,
2855         .debounce_rep           = DEBOUNCE_REPTIME,
2856         .debounce_tol           = 20,
2857         .gpio_pendown           = XPT2046_GPIO_INT,
2858         .pendown_iomux_name = GPIO4D5_CPUTRACECTL_NAME, 
2859         .pendown_iomux_mode = GPIO4H_GPIO4D5,   
2860         .touch_virtualkey_length = 60,
2861         .penirq_recheck_delay_usecs = 1,
2862         
2863 #if defined(CONFIG_TOUCHSCREEN_480X800)
2864         .x_min                  = 0,
2865         .x_max                  = 480,
2866         .y_min                  = 0,
2867         .y_max                  = 800,
2868         .screen_x = { 70,  410, 70, 410, 240},
2869         .screen_y = { 50, 50,  740, 740, 400},
2870         .uncali_x_default = {  3267,  831, 3139, 715, 1845 },
2871         .uncali_y_default = { 3638,  3664, 564,  591, 2087 },
2872 #elif defined(CONFIG_TOUCHSCREEN_800X480)
2873         .x_min                  = 0,
2874         .x_max                  = 800,
2875         .y_min                  = 0,
2876         .y_max                  = 480,
2877         .screen_x[5] = { 50, 750,  50, 750, 400};
2878         .screen_y[5] = { 40,  40, 440, 440, 240};
2879         .uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };
2880         .uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };
2881 #elif defined(CONFIG_TOUCHSCREEN_320X480)
2882         .x_min                  = 0,
2883         .x_max                  = 320,
2884         .y_min                  = 0,
2885         .y_max                  = 480,
2886         .screen_x[5] = { 50, 270,  50, 270, 160}; 
2887         .screen_y[5] = { 40,  40, 440, 440, 240}; 
2888         .uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };
2889         .uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };
2890 #endif  
2891 };
2892 #endif
2893
2894 #if defined(CONFIG_SERIAL_SC8800)
2895 static struct plat_sc8800 sc8800_plat_data = {
2896         .slav_rts_pin = RK29_PIN4_PD4,
2897         .slav_rdy_pin = RK29_PIN4_PD1,
2898         .master_rts_pin = RK29_PIN4_PD2,
2899         .master_rdy_pin = RK29_PIN4_PD3,
2900         //.poll_time = 100,
2901 };
2902 #endif
2903
2904 static struct spi_board_info board_spi_devices[] = {
2905 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
2906         {
2907                 .modalias       = "xpt2046_ts",
2908                 .chip_select    = 0,// 2,
2909                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
2910                 .bus_num        = 0,
2911                 .irq = XPT2046_GPIO_INT,
2912                 .platform_data = &xpt2046_info,
2913         },
2914 #endif
2915
2916 #if defined(CONFIG_MFD_WM831X_SPI)
2917         {
2918                 .modalias       = "wm8310",
2919                 .chip_select    = 1,
2920                 .max_speed_hz   = 1*1000*1000,
2921                 .bus_num        = 1,
2922                 .irq            = RK29_PIN4_PD0,
2923                 .platform_data = &wm831x_platdata,
2924         },
2925 #endif
2926 #if defined(CONFIG_SERIAL_SC8800)
2927         {
2928                 .modalias  = "sc8800",
2929                 .bus_num = 0,
2930                 .platform_data = &sc8800_plat_data,
2931                 .max_speed_hz  = 12*1000*1000,
2932                 .chip_select   = 0,
2933         },
2934 #endif
2935 };
2936
2937
2938 /**********************************************************************************************
2939  *
2940  * The virtual keys for android "back", "home", "menu", "search", these four keys are touch key
2941  * on the touch screen panel. (added by hhb@rock-chips.com 2011.03.31)
2942  *
2943  ***********************************************************************************************/
2944 static ssize_t rk29xx_virtual_keys_show(struct kobject *kobj,
2945                         struct kobj_attribute *attr, char *buf)
2946 {
2947 #if (defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) && defined(CONFIG_TOUCHSCREEN_480X800)) \
2948         || defined(CONFIG_TOUCHSCREEN_HX8520_IIC) || defined(CONFIG_TOUCHSCREEN_GT801_IIC)
2949         /* center: x: home: 50, menu: 184, back: 315, search 435, y: 830*/
2950     /* centerx;centery;width;height; */
2951         return sprintf(buf,
2952                 __stringify(EV_KEY) ":" __stringify(KEY_BACK)       ":315:815:120:50"     //":50:830:98:50"  //":210:796:98:50"
2953                 ":" __stringify(EV_KEY) ":" __stringify(KEY_MENU)   ":85:815:88:50"   // ":184:830:120:50"  // ":435:796:120:50"
2954                 ":" __stringify(EV_KEY) ":" __stringify(KEY_HOME)   ":184:815:100:50"   //":315:830:100:50"  //":320:796:100:50"
2955                 ":" __stringify(EV_KEY) ":" __stringify(KEY_SEARCH) ":435:815:88:50"   //":50:815:98:50"    //   //":85:796:88:50"
2956                 "\n");
2957 #endif
2958         return 0;
2959 }
2960
2961 static struct kobj_attribute rk29xx_virtual_keys_attr = {
2962         .attr = {
2963 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
2964                 .name = "virtualkeys.xpt2046-touchscreen",
2965 #elif defined(CONFIG_TOUCHSCREEN_HX8520_IIC)
2966         .name = "virtualkeys.hx8520-touchscreen",
2967 #elif defined(CONFIG_TOUCHSCREEN_GT801_IIC)
2968                 .name = "virtualkeys.gt801-touchscreen",
2969 #elif defined(CONFIG_TOUCHSCREEN_ILI2102_IIC)
2970                 .name = "virtualkeys.ili2102-touchscreen",              
2971 #else
2972                 .name = "virtualkeys",
2973 #endif
2974                 .mode = S_IRUGO,
2975         },
2976         .show = &rk29xx_virtual_keys_show,
2977 };
2978
2979 static struct attribute *rk29xx_properties_attrs[] = {
2980         &rk29xx_virtual_keys_attr.attr,
2981         NULL
2982 };
2983
2984 static struct attribute_group rk29xx_properties_attr_group = {
2985         .attrs = rk29xx_properties_attrs,
2986 };
2987 static int rk29xx_virtual_keys_init(void)
2988 {
2989         int ret;
2990         struct kobject *properties_kobj;
2991         printk("rk29xx_virtual_keys_init \n");
2992         properties_kobj = kobject_create_and_add("board_properties", NULL);
2993         if (properties_kobj)
2994                 ret = sysfs_create_group(properties_kobj,
2995                                 &rk29xx_properties_attr_group);
2996         if (!properties_kobj || ret)
2997         {
2998                 pr_err("failed to create board_properties\n");
2999         }
3000         return ret;
3001 }
3002
3003
3004 static void __init rk29_gic_init_irq(void)
3005 {
3006         gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
3007         gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
3008 }
3009
3010 static void __init machine_rk29_init_irq(void)
3011 {
3012         rk29_gic_init_irq();
3013         rk29_gpio_init();
3014 }
3015
3016 #define POWER_ON_PIN RK29_PIN4_PA4
3017
3018 static void rk29_pm_power_restart(void)
3019 {
3020         printk("%s,line=%d\n",__FUNCTION__,__LINE__);
3021         mdelay(2);
3022 #if defined(CONFIG_MFD_WM831X)
3023         wm831x_device_restart(gWm831x);
3024 #endif
3025
3026 }
3027
3028 static void rk29_pm_power_off(void)
3029 {
3030         printk(KERN_ERR "rk29_pm_power_off start...\n");
3031         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
3032 #if defined(CONFIG_MFD_WM831X)
3033         if(wm831x_read_usb(gWm831x))
3034         rk29_pm_power_restart();        //if charging then restart
3035         else
3036         wm831x_device_shutdown(gWm831x);//else shutdown
3037 #endif
3038         while (1);
3039 }
3040
3041 static void __init machine_rk29_board_init(void)
3042 {
3043         rk29_board_iomux_init();
3044
3045         gpio_request(POWER_ON_PIN,"poweronpin");
3046         gpio_set_value(POWER_ON_PIN, GPIO_HIGH);
3047         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
3048         pm_power_off = rk29_pm_power_off;
3049         //arm_pm_restart = rk29_pm_power_restart;
3050
3051         platform_add_devices(devices, ARRAY_SIZE(devices));
3052 #ifdef CONFIG_I2C0_RK29
3053         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
3054                         ARRAY_SIZE(board_i2c0_devices));
3055 #endif
3056 #ifdef CONFIG_I2C1_RK29
3057         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
3058                         ARRAY_SIZE(board_i2c1_devices));
3059 #endif
3060 #ifdef CONFIG_I2C2_RK29
3061         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
3062                         ARRAY_SIZE(board_i2c2_devices));
3063 #endif
3064 #ifdef CONFIG_I2C3_RK29
3065         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
3066                         ARRAY_SIZE(board_i2c3_devices));
3067 #endif
3068
3069         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
3070
3071 #ifdef CONFIG_WIFI_CONTROL_FUNC
3072         rk29sdk_wifi_bt_gpio_control_init();
3073         rk29sdk_init_wifi_mem();
3074 #endif
3075
3076 //      rk29xx_virtual_keys_init();
3077 }
3078
3079 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
3080                                         char **cmdline, struct meminfo *mi)
3081 {
3082         mi->nr_banks = 1;
3083         mi->bank[0].start = RK29_SDRAM_PHYS;
3084         mi->bank[0].node = PHYS_TO_NID(RK29_SDRAM_PHYS);
3085         mi->bank[0].size = LINUX_SIZE;
3086 }
3087
3088 static void __init machine_rk29_mapio(void)
3089 {
3090         rk29_map_common_io();
3091         rk29_setup_early_printk();
3092         rk29_sram_init();
3093         rk29_clock_init2(periph_pll_96mhz, codec_pll_300mhz, false);
3094         rk29_iomux_init();
3095         ddr_init(DDR_TYPE, DDR_FREQ);
3096 }
3097
3098 MACHINE_START(RK29, "RK29board")
3099         /* UART for LL DEBUG */
3100         .phys_io        = RK29_UART1_PHYS,
3101         .io_pg_offst    = ((RK29_UART1_BASE) >> 18) & 0xfffc,
3102         .boot_params    = RK29_SDRAM_PHYS + 0x88000,
3103         .fixup          = machine_rk29_fixup,
3104         .map_io         = machine_rk29_mapio,
3105         .init_irq       = machine_rk29_init_irq,
3106         .init_machine   = machine_rk29_board_init,
3107         .timer          = &rk29_timer,
3108 MACHINE_END