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