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