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