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