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