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