RK29 Mobile SDK:mtk23 modem support
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk29 / board-rk29-phonesdk.c
1 /* arch/arm/mach-rk29/board-rk29-phonesdk.c
2  *
3  * Copyright (C) 2010 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.h>
20 #include <linux/io.h>
21 #include <linux/delay.h>
22 #include <linux/i2c.h>
23 #include <linux/spi/spi.h>
24 #include <linux/mmc/host.h>
25 #include <linux/android_pmem.h>
26 #include <linux/usb/android_composite.h>
27
28 #include <mach/hardware.h>
29 #include <asm/setup.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33 #include <asm/mach/flash.h>
34 #include <asm/hardware/gic.h>
35
36 #include <mach/iomux.h>
37 #include <mach/gpio.h>
38 #include <mach/irqs.h>
39 #include <mach/rk29_iomap.h>
40 #include <mach/board.h>
41 #include <mach/rk29_nand.h>
42 #include <mach/rk29_camera.h>                          /* ddl@rock-chips.com : camera support */
43 #include <media/soc_camera.h>                               /* ddl@rock-chips.com : camera support */
44 #include <mach/vpu_mem.h>
45 #include <mach/sram.h>
46
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
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,2800000,2800000);
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 #endif 
1385
1386 /*****************************************************************************************
1387  * i2c devices
1388  * author: kfx@rock-chips.com
1389 *****************************************************************************************/
1390 static int rk29_i2c0_io_init(void)
1391 {
1392         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_I2C0_SCL);
1393         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_I2C0_SDA);
1394         return 0;
1395 }
1396
1397 static int rk29_i2c1_io_init(void)
1398 {
1399         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_I2C1_SCL);
1400         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_I2C1_SDA);
1401         return 0;
1402 }
1403 static int rk29_i2c2_io_init(void)
1404 {
1405         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_I2C2_SCL);
1406         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_I2C2_SDA);
1407         return 0;
1408 }
1409
1410 static int rk29_i2c3_io_init(void)
1411 {
1412         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_I2C3_SCL);
1413         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_I2C3_SDA);
1414         return 0;
1415 }
1416
1417 struct rk29_i2c_platform_data default_i2c0_data = {
1418         .bus_num    = 0,
1419         .flags      = 0,
1420         .slave_addr = 0xff,
1421         .scl_rate  = 400*1000,
1422         .mode           = I2C_MODE_IRQ,
1423         .io_init = rk29_i2c0_io_init,
1424 };
1425
1426 struct rk29_i2c_platform_data default_i2c1_data = {
1427         .bus_num    = 1,
1428         .flags      = 0,
1429         .slave_addr = 0xff,
1430         .scl_rate  = 400*1000,
1431         .mode           = I2C_MODE_POLL,
1432         .io_init = rk29_i2c1_io_init,
1433 };
1434
1435 struct rk29_i2c_platform_data default_i2c2_data = {
1436         .bus_num    = 2,
1437         .flags      = 0,
1438         .slave_addr = 0xff,
1439         .scl_rate  = 400*1000,
1440         .mode           = I2C_MODE_IRQ,
1441         .io_init = rk29_i2c2_io_init,
1442 };
1443
1444 struct rk29_i2c_platform_data default_i2c3_data = {
1445         .bus_num    = 3,
1446         .flags      = 0,
1447         .slave_addr = 0xff,
1448         .scl_rate  = 400*1000,
1449         .mode           = I2C_MODE_POLL,
1450         .io_init = rk29_i2c3_io_init,
1451 };
1452
1453 #ifdef CONFIG_I2C0_RK29
1454 static struct i2c_board_info __initdata board_i2c0_devices[] = {
1455 #if defined (CONFIG_RK1000_CONTROL)
1456         {
1457                 .type                   = "rk1000_control",
1458                 .addr           = 0x40,
1459                 .flags                  = 0,
1460         },
1461 #endif
1462 #if defined (CONFIG_SND_SOC_RK1000)
1463         {
1464                 .type                   = "rk1000_i2c_codec",
1465                 .addr           = 0x60,
1466                 .flags                  = 0,
1467         },
1468 #endif
1469 #if defined (CONFIG_SND_SOC_WM8900)
1470         {
1471                 .type                   = "wm8900",
1472                 .addr           = 0x1A,
1473                 .flags                  = 0,
1474         },
1475 #endif
1476 #if defined (CONFIG_SND_SOC_WM8994)
1477         {
1478                 .type                   = "wm8994",
1479                 .addr           = 0x1a,
1480                 .flags                  = 0,
1481         #if defined(CONFIG_MFD_WM8994)  
1482                 .platform_data  = &wm8994_platdata,     
1483         #endif  
1484         },
1485 #endif
1486 #if defined (CONFIG_BATTERY_STC3100)
1487         {
1488                 .type                   = "stc3100",
1489                 .addr           = 0x70,
1490                 .flags                  = 0,
1491         },
1492 #endif
1493 #if defined (CONFIG_BATTERY_BQ27510)
1494         {
1495                 .type                   = "bq27510",
1496                 .addr           = 0x55,
1497                 .flags                  = 0,
1498         },
1499 #endif
1500 #if defined (CONFIG_RTC_HYM8563)
1501         {
1502                 .type                   = "rtc_hym8563",
1503                 .addr           = 0x51,
1504                 .flags                  = 0,
1505                 .irq            = RK29_PIN0_PA1,
1506         },
1507 #endif
1508 #if defined (CONFIG_GS_MMA8452)
1509     {
1510       .type           = "gs_mma8452",
1511       .addr           = 0x1c,
1512       .flags          = 0,
1513       .irq            = MMA8452_INT_PIN,
1514       .platform_data  = &mma8452_info,
1515     },
1516 #endif
1517 #if defined (CONFIG_COMPASS_AK8973)
1518         {
1519                 .type                   = "ak8973",
1520                 .addr           = 0x1d,
1521                 .flags                  = 0,
1522                 .irq                    = RK29_PIN6_PC5,
1523         },
1524 #endif
1525 #if defined (CONFIG_COMPASS_AK8975)
1526         {
1527                 .type                   = "ak8975",
1528                 .addr           = 0x0d,
1529                 .flags                  = 0,
1530                 .irq                    = RK29_PIN6_PC5,
1531         },
1532 #endif
1533 #if defined (CONFIG_INPUT_LPSENSOR_ISL29028)
1534         {
1535                 .type           = "isl29028",
1536                 .addr           = 0x44,
1537                 .flags          = 0,
1538                 .irq            = RK29_PIN4_PD3,
1539         },
1540 #endif
1541 #if defined (CONFIG_ANX7150)
1542     {
1543                 .type           = "anx7150",
1544         .addr           = 0x39,             //0x39, 0x3d
1545         .flags          = 0,
1546         .irq            = RK29_PIN2_PA3,
1547     },
1548 #endif
1549 };
1550 #endif
1551
1552 #ifdef CONFIG_I2C1_RK29
1553 static struct i2c_board_info __initdata board_i2c1_devices[] = {
1554 #if defined (CONFIG_RK1000_CONTROL1)
1555         {
1556                 .type                   = "rk1000_control",
1557                 .addr                   = 0x40,
1558                 .flags                  = 0,
1559         },
1560 #endif
1561
1562 };
1563 #endif
1564
1565 #ifdef CONFIG_I2C2_RK29
1566 static struct i2c_board_info __initdata board_i2c2_devices[] = {
1567 #if defined (CONFIG_TOUCHSCREEN_GT801_IIC)
1568 {
1569         .type           = "gt801_ts",
1570         .addr           = 0x55,
1571         .flags          = 0,
1572         .irq            = RK29_PIN4_PD5,
1573         .platform_data = &gt801_info,
1574 },      
1575 #endif
1576 #if defined (CONFIG_MFD_WM831X_I2C)
1577 {
1578         .type           = "wm8310",
1579         .addr           = 0x34,
1580         .flags          = 0,
1581         .irq            = RK29_PIN4_PD0,
1582         .platform_data = &wm831x_platdata,
1583 },      
1584 #endif
1585 #if defined (CONFIG_HANNSTAR_P1003)
1586     {
1587       .type           = "p1003_touch",
1588       .addr           = 0x04,
1589       .flags          = 0,
1590       .irq            = RK29_PIN0_PA2,
1591       .platform_data  = &p1003_info,
1592     },
1593 #endif
1594 #if defined (CONFIG_EETI_EGALAX)
1595     {
1596       .type           = "egalax_i2c",
1597       .addr           = 0x04,
1598       .flags          = 0,
1599       .irq            = RK29_PIN4_PD5,
1600       .platform_data  = &eeti_egalax_info,
1601     },
1602 #endif
1603 };
1604 #endif
1605
1606 #ifdef CONFIG_I2C3_RK29
1607 static struct i2c_board_info __initdata board_i2c3_devices[] = {
1608 };
1609 #endif
1610
1611 /*****************************************************************************************
1612  * camera  devices
1613  * author: ddl@rock-chips.com
1614  *****************************************************************************************/
1615 #ifdef CONFIG_VIDEO_RK29
1616 #define SENSOR_NAME_0 RK29_CAM_SENSOR_NAME_OV5642                       /* back camera sensor */
1617 #define SENSOR_IIC_ADDR_0           0x78
1618 #define SENSOR_IIC_ADAPTER_ID_0    1
1619 #define SENSOR_POWER_PIN_0         INVALID_GPIO
1620 #define SENSOR_RESET_PIN_0         INVALID_GPIO
1621 #define SENSOR_POWERDN_PIN_0       RK29_PIN6_PB7
1622 #define SENSOR_FALSH_PIN_0         INVALID_GPIO
1623 #define SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
1624 #define SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
1625 #define SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
1626 #define SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
1627
1628 #define SENSOR_NAME_1 RK29_CAM_SENSOR_NAME_OV2659                       /* front camera sensor */
1629 #define SENSOR_IIC_ADDR_1           0x60
1630 #define SENSOR_IIC_ADAPTER_ID_1    1
1631 #define SENSOR_POWER_PIN_1         INVALID_GPIO
1632 #define SENSOR_RESET_PIN_1         INVALID_GPIO
1633 #define SENSOR_POWERDN_PIN_1       RK29_PIN5_PD7
1634 #define SENSOR_FALSH_PIN_1         INVALID_GPIO
1635 #define SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
1636 #define SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
1637 #define SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
1638 #define SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
1639
1640 static int rk29_sensor_io_init(void);
1641 static int rk29_sensor_io_deinit(int sensor);
1642 static int rk29_sensor_ioctrl(struct device *dev,enum rk29camera_ioctrl_cmd cmd,int on);
1643
1644 static struct rk29camera_platform_data rk29_camera_platform_data = {
1645     .io_init = rk29_sensor_io_init,
1646     .io_deinit = rk29_sensor_io_deinit,
1647     .sensor_ioctrl = rk29_sensor_ioctrl,
1648     .gpio_res = {
1649         {
1650             .gpio_reset = SENSOR_RESET_PIN_0,
1651             .gpio_power = SENSOR_POWER_PIN_0,
1652             .gpio_powerdown = SENSOR_POWERDN_PIN_0,
1653             .gpio_flash = SENSOR_FALSH_PIN_0,
1654             .gpio_flag = (SENSOR_POWERACTIVE_LEVEL_0|SENSOR_RESETACTIVE_LEVEL_0|SENSOR_POWERDNACTIVE_LEVEL_0|SENSOR_FLASHACTIVE_LEVEL_0),
1655             .gpio_init = 0,
1656             .dev_name = SENSOR_NAME_0,
1657         }, {
1658             .gpio_reset = SENSOR_RESET_PIN_1,
1659             .gpio_power = SENSOR_POWER_PIN_1,
1660             .gpio_powerdown = SENSOR_POWERDN_PIN_1,
1661             .gpio_flash = SENSOR_FALSH_PIN_1,
1662             .gpio_flag = (SENSOR_POWERACTIVE_LEVEL_1|SENSOR_RESETACTIVE_LEVEL_1|SENSOR_POWERDNACTIVE_LEVEL_1|SENSOR_FLASHACTIVE_LEVEL_1),
1663             .gpio_init = 0,
1664             .dev_name = SENSOR_NAME_1,
1665         }
1666     },
1667         #ifdef CONFIG_VIDEO_RK29_WORK_IPP
1668         .meminfo = {
1669             .name  = "camera_ipp_mem",
1670                 .start = MEM_CAMIPP_BASE,
1671                 .size   = MEM_CAMIPP_SIZE,
1672         }
1673         #endif
1674 };
1675
1676 static int rk29_sensor_io_init(void)
1677 {
1678     int ret = 0, i;
1679     unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
1680         unsigned int camera_powerdown = INVALID_GPIO, camera_flash = INVALID_GPIO;
1681         unsigned int camera_ioflag;
1682
1683     for (i=0; i<2; i++) {
1684         camera_reset = rk29_camera_platform_data.gpio_res[i].gpio_reset;
1685         camera_power = rk29_camera_platform_data.gpio_res[i].gpio_power;
1686                 camera_powerdown = rk29_camera_platform_data.gpio_res[i].gpio_powerdown;
1687         camera_flash = rk29_camera_platform_data.gpio_res[i].gpio_flash;
1688                 camera_ioflag = rk29_camera_platform_data.gpio_res[i].gpio_flag;
1689                 rk29_camera_platform_data.gpio_res[i].gpio_init = 0;
1690
1691         if (camera_power != INVALID_GPIO) {
1692             ret = gpio_request(camera_power, "camera power");
1693             if (ret)
1694                                 goto sensor_io_int_loop_end;
1695                         rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_POWERACTIVE_MASK;
1696             gpio_set_value(camera_reset, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
1697             gpio_direction_output(camera_power, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
1698
1699                         //printk("\n%s....power pin(%d) init success(0x%x)  \n",__FUNCTION__,camera_power,(((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
1700
1701         }
1702
1703         if (camera_reset != INVALID_GPIO) {
1704             ret = gpio_request(camera_reset, "camera reset");
1705             if (ret)
1706                                 goto sensor_io_int_loop_end;
1707                         rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_RESETACTIVE_MASK;
1708             gpio_set_value(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
1709             gpio_direction_output(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
1710
1711                         //printk("\n%s....reset pin(%d) init success(0x%x)\n",__FUNCTION__,camera_reset,((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
1712
1713         }
1714
1715                 if (camera_powerdown != INVALID_GPIO) {
1716             ret = gpio_request(camera_powerdown, "camera powerdown");
1717             if (ret)
1718                                 goto sensor_io_int_loop_end;
1719                         rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_POWERDNACTIVE_MASK;
1720             gpio_set_value(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
1721             gpio_direction_output(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
1722
1723                         //printk("\n%s....powerdown pin(%d) init success(0x%x) \n",__FUNCTION__,camera_powerdown,((camera_ioflag&RK29_CAM_POWERDNACTIVE_BITPOS)>>RK29_CAM_POWERDNACTIVE_BITPOS));
1724
1725         }
1726
1727                 if (camera_flash != INVALID_GPIO) {
1728             ret = gpio_request(camera_flash, "camera flash");
1729             if (ret)
1730                                 goto sensor_io_int_loop_end;
1731                         rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_FLASHACTIVE_MASK;
1732             gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
1733             gpio_direction_output(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
1734
1735                         //printk("\n%s....flash pin(%d) init success(0x%x) \n",__FUNCTION__,camera_flash,((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
1736
1737         }
1738                 continue;
1739 sensor_io_int_loop_end:
1740                 rk29_sensor_io_deinit(i);
1741                 continue;
1742     }
1743
1744     return 0;
1745 }
1746
1747 static int rk29_sensor_io_deinit(int sensor)
1748 {
1749     unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
1750         unsigned int camera_powerdown = INVALID_GPIO, camera_flash = INVALID_GPIO;
1751
1752     camera_reset = rk29_camera_platform_data.gpio_res[sensor].gpio_reset;
1753     camera_power = rk29_camera_platform_data.gpio_res[sensor].gpio_power;
1754         camera_powerdown = rk29_camera_platform_data.gpio_res[sensor].gpio_powerdown;
1755     camera_flash = rk29_camera_platform_data.gpio_res[sensor].gpio_flash;
1756
1757         if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_POWERACTIVE_MASK) {
1758             if (camera_power != INVALID_GPIO) {
1759                 gpio_direction_input(camera_power);
1760                 gpio_free(camera_power);
1761             }
1762         }
1763
1764         if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_RESETACTIVE_MASK) {
1765             if (camera_reset != INVALID_GPIO)  {
1766                 gpio_direction_input(camera_reset);
1767                 gpio_free(camera_reset);
1768             }
1769         }
1770
1771         if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_POWERDNACTIVE_MASK) {
1772             if (camera_powerdown != INVALID_GPIO)  {
1773                 gpio_direction_input(camera_powerdown);
1774                 gpio_free(camera_powerdown);
1775             }
1776         }
1777
1778         if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_FLASHACTIVE_MASK) {
1779             if (camera_flash != INVALID_GPIO)  {
1780                 gpio_direction_input(camera_flash);
1781                 gpio_free(camera_flash);
1782             }
1783         }
1784
1785         rk29_camera_platform_data.gpio_res[sensor].gpio_init = 0;
1786     return 0;
1787 }
1788 static int rk29_sensor_ioctrl(struct device *dev,enum rk29camera_ioctrl_cmd cmd, int on)
1789 {
1790     unsigned int camera_power=INVALID_GPIO,camera_reset=INVALID_GPIO, camera_powerdown=INVALID_GPIO,camera_flash = INVALID_GPIO;
1791         unsigned int camera_ioflag,camera_io_init;
1792         int ret = RK29_CAM_IO_SUCCESS;
1793
1794     if(rk29_camera_platform_data.gpio_res[0].dev_name &&  (strcmp(rk29_camera_platform_data.gpio_res[0].dev_name, dev_name(dev)) == 0)) {
1795                 camera_power = rk29_camera_platform_data.gpio_res[0].gpio_power;
1796                 camera_reset = rk29_camera_platform_data.gpio_res[0].gpio_reset;
1797         camera_powerdown = rk29_camera_platform_data.gpio_res[0].gpio_powerdown;
1798                 camera_flash = rk29_camera_platform_data.gpio_res[0].gpio_flash;
1799                 camera_ioflag = rk29_camera_platform_data.gpio_res[0].gpio_flag;
1800                 camera_io_init = rk29_camera_platform_data.gpio_res[0].gpio_init;
1801     } 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)) {
1802         camera_power = rk29_camera_platform_data.gpio_res[1].gpio_power;
1803         camera_reset = rk29_camera_platform_data.gpio_res[1].gpio_reset;
1804         camera_powerdown = rk29_camera_platform_data.gpio_res[1].gpio_powerdown;
1805                 camera_flash = rk29_camera_platform_data.gpio_res[1].gpio_flash;
1806                 camera_ioflag = rk29_camera_platform_data.gpio_res[1].gpio_flag;
1807                 camera_io_init = rk29_camera_platform_data.gpio_res[1].gpio_init;
1808     }
1809
1810         switch (cmd)
1811         {
1812                 case Cam_Power:
1813                 {
1814                         if (camera_power != INVALID_GPIO)  {
1815                                 if (camera_io_init & RK29_CAM_POWERACTIVE_MASK) {
1816                                 if (on) {
1817                                         gpio_set_value(camera_power, ((camera_ioflag&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
1818                                                 //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));
1819                                                 msleep(10);
1820                                         } else {
1821                                                 gpio_set_value(camera_power, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
1822                                                 //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));
1823                                         }
1824                                 } else {
1825                                         ret = RK29_CAM_EIO_REQUESTFAIL;
1826                                         printk("\n%s..%s..ResetPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
1827                                 }
1828                     } else {
1829                                 ret = RK29_CAM_EIO_INVALID;
1830                     }
1831                         break;
1832                 }
1833                 case Cam_Reset:
1834                 {
1835                         if (camera_reset != INVALID_GPIO) {
1836                                 if (camera_io_init & RK29_CAM_RESETACTIVE_MASK) {
1837                                         if (on) {
1838                                         gpio_set_value(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
1839                                         //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));
1840                                         } else {
1841                                                 gpio_set_value(camera_reset,(((~camera_ioflag)&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
1842                                         //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));
1843                                 }
1844                                 } else {
1845                                         ret = RK29_CAM_EIO_REQUESTFAIL;
1846                                         printk("\n%s..%s..ResetPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
1847                                 }
1848                     } else {
1849                                 ret = RK29_CAM_EIO_INVALID;
1850                     }
1851                         break;
1852                 }
1853
1854                 case Cam_PowerDown:
1855                 {
1856                         if (camera_powerdown != INVALID_GPIO) {
1857                                 if (camera_io_init & RK29_CAM_POWERDNACTIVE_MASK) {
1858                                         if (on) {
1859                                         gpio_set_value(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
1860                                         //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));
1861                                         } else {
1862                                                 gpio_set_value(camera_powerdown,(((~camera_ioflag)&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
1863                                         //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));
1864                                 }
1865                                 } else {
1866                                         ret = RK29_CAM_EIO_REQUESTFAIL;
1867                                         printk("\n%s..%s..PowerDownPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_powerdown);
1868                                 }
1869                     } else {
1870                                 ret = RK29_CAM_EIO_INVALID;
1871                     }
1872                         break;
1873                 }
1874
1875                 case Cam_Flash:
1876                 {
1877                         if (camera_flash != INVALID_GPIO) {
1878                                 if (camera_io_init & RK29_CAM_FLASHACTIVE_MASK) {
1879                                         if (on) {
1880                                         gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
1881                                         //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));
1882                                         } else {
1883                                                 gpio_set_value(camera_flash,(((~camera_ioflag)&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
1884                                         //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));
1885                                 }
1886                                 } else {
1887                                         ret = RK29_CAM_EIO_REQUESTFAIL;
1888                                         printk("\n%s..%s..FlashPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_flash);
1889                                 }
1890                     } else {
1891                                 ret = RK29_CAM_EIO_INVALID;
1892                     }
1893                         break;
1894                 }
1895
1896                 default:
1897                 {
1898                         printk("%s cmd(0x%x) is unknown!\n",__FUNCTION__, cmd);
1899                         break;
1900                 }
1901         }
1902     return ret;
1903 }
1904 static int rk29_sensor_power(struct device *dev, int on)
1905 {
1906         rk29_sensor_ioctrl(dev,Cam_Power,on);
1907     return 0;
1908 }
1909 static int rk29_sensor_reset(struct device *dev)
1910 {
1911         rk29_sensor_ioctrl(dev,Cam_Reset,1);
1912         msleep(2);
1913         rk29_sensor_ioctrl(dev,Cam_Reset,0);
1914         return 0;
1915 }
1916 static int rk29_sensor_powerdown(struct device *dev, int on)
1917 {
1918         return rk29_sensor_ioctrl(dev,Cam_PowerDown,on);
1919 }
1920 #if (SENSOR_IIC_ADDR_0 != 0x00)
1921 static struct i2c_board_info rk29_i2c_cam_info_0[] = {
1922         {
1923                 I2C_BOARD_INFO(SENSOR_NAME_0, SENSOR_IIC_ADDR_0>>1)
1924         },
1925 };
1926
1927 static struct soc_camera_link rk29_iclink_0 = {
1928         .bus_id         = RK29_CAM_PLATFORM_DEV_ID,
1929         .power          = rk29_sensor_power,
1930         .powerdown  = rk29_sensor_powerdown,
1931         .board_info     = &rk29_i2c_cam_info_0[0],
1932         .i2c_adapter_id = SENSOR_IIC_ADAPTER_ID_0,
1933         .module_name    = SENSOR_NAME_0,
1934 };
1935
1936 /*platform_device : soc-camera need  */
1937 static struct platform_device rk29_soc_camera_pdrv_0 = {
1938         .name   = "soc-camera-pdrv",
1939         .id     = 0,
1940         .dev    = {
1941                 .init_name = SENSOR_NAME_0,
1942                 .platform_data = &rk29_iclink_0,
1943         },
1944 };
1945 #endif
1946 static struct i2c_board_info rk29_i2c_cam_info_1[] = {
1947         {
1948                 I2C_BOARD_INFO(SENSOR_NAME_1, SENSOR_IIC_ADDR_1>>1)
1949         },
1950 };
1951
1952 static struct soc_camera_link rk29_iclink_1 = {
1953         .bus_id         = RK29_CAM_PLATFORM_DEV_ID,
1954         .power          = rk29_sensor_power,
1955         .powerdown  = rk29_sensor_powerdown,
1956         .board_info     = &rk29_i2c_cam_info_1[0],
1957         .i2c_adapter_id = SENSOR_IIC_ADAPTER_ID_1,
1958         .module_name    = SENSOR_NAME_1,
1959 };
1960
1961 /*platform_device : soc-camera need  */
1962 static struct platform_device rk29_soc_camera_pdrv_1 = {
1963         .name   = "soc-camera-pdrv",
1964         .id     = 1,
1965         .dev    = {
1966                 .init_name = SENSOR_NAME_1,
1967                 .platform_data = &rk29_iclink_1,
1968         },
1969 };
1970
1971
1972 static u64 rockchip_device_camera_dmamask = 0xffffffffUL;
1973 static struct resource rk29_camera_resource[] = {
1974         [0] = {
1975                 .start = RK29_VIP_PHYS,
1976                 .end   = RK29_VIP_PHYS + RK29_VIP_SIZE - 1,
1977                 .flags = IORESOURCE_MEM,
1978         },
1979         [1] = {
1980                 .start = IRQ_VIP,
1981                 .end   = IRQ_VIP,
1982                 .flags = IORESOURCE_IRQ,
1983         }
1984 };
1985
1986 /*platform_device : */
1987 static struct platform_device rk29_device_camera = {
1988         .name             = RK29_CAM_DRV_NAME,
1989         .id               = RK29_CAM_PLATFORM_DEV_ID,               /* This is used to put cameras on this interface */
1990         .num_resources    = ARRAY_SIZE(rk29_camera_resource),
1991         .resource         = rk29_camera_resource,
1992         .dev            = {
1993                 .dma_mask = &rockchip_device_camera_dmamask,
1994                 .coherent_dma_mask = 0xffffffffUL,
1995                 .platform_data  = &rk29_camera_platform_data,
1996         }
1997 };
1998 #endif
1999 /*****************************************************************************************
2000  * backlight  devices
2001  * author: nzy@rock-chips.com
2002  *****************************************************************************************/
2003 #ifdef CONFIG_BACKLIGHT_RK29_BL
2004  /*
2005  GPIO1B5_PWM0_NAME,       GPIO1L_PWM0
2006  GPIO5D2_PWM1_UART1SIRIN_NAME,  GPIO5H_PWM1
2007  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME,   GPIO2L_PWM2
2008  GPIO1A5_EMMCPWREN_PWM3_NAME,     GPIO1L_PWM3
2009  */
2010
2011 #define PWM_ID            0
2012 #define PWM_MUX_NAME      GPIO1B5_PWM0_NAME
2013 #define PWM_MUX_MODE      GPIO1L_PWM0
2014 #define PWM_MUX_MODE_GPIO GPIO1L_GPIO1B5
2015 #define PWM_EFFECT_VALUE  1
2016
2017 //#define LCD_DISP_ON_PIN
2018
2019 #ifdef  LCD_DISP_ON_PIN
2020 #define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
2021 #define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
2022
2023 #define BL_EN_PIN         GPIO0L_GPIO0A5
2024 #define BL_EN_VALUE       GPIO_HIGH
2025 #endif
2026 static int rk29_backlight_io_init(void)
2027 {
2028     int ret = 0;
2029
2030     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
2031         #ifdef  LCD_DISP_ON_PIN
2032     rk29_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
2033
2034     ret = gpio_request(BL_EN_PIN, NULL);
2035     if(ret != 0)
2036     {
2037         gpio_free(BL_EN_PIN);
2038     }
2039
2040     gpio_direction_output(BL_EN_PIN, 0);
2041     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
2042         #endif
2043     return ret;
2044 }
2045
2046 static int rk29_backlight_io_deinit(void)
2047 {
2048     int ret = 0;
2049     #ifdef  LCD_DISP_ON_PIN
2050     gpio_free(BL_EN_PIN);
2051     #endif
2052     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
2053     return ret;
2054 }
2055 struct rk29_bl_info rk29_bl_info = {
2056     .pwm_id   = PWM_ID,
2057     .bl_ref   = PWM_EFFECT_VALUE,
2058     .io_init   = rk29_backlight_io_init,
2059     .io_deinit = rk29_backlight_io_deinit,
2060 };
2061 #endif
2062 /*****************************************************************************************
2063 * pwm voltage regulator devices
2064 ******************************************************************************************/
2065 #if defined (CONFIG_RK29_PWM_REGULATOR)
2066
2067 #define REGULATOR_PWM_ID                                        2
2068 #define REGULATOR_PWM_MUX_NAME                  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME
2069 #define REGULATOR_PWM_MUX_MODE                                          GPIO2L_PWM2
2070 #define REGULATOR_PWM_MUX_MODE_GPIO                             GPIO2L_GPIO2A3
2071 #define REGULATOR_PWM_GPIO                              RK29_PIN2_PA3
2072
2073 static struct regulator_consumer_supply pwm_consumers[] = {
2074         {
2075                 .supply = "vcore",
2076         }
2077 };
2078
2079 static struct regulator_init_data rk29_pwm_regulator_data = {
2080         .constraints = {
2081                 .name = "PWM2",
2082                 .min_uV =  950000,
2083                 .max_uV = 1400000,
2084                 .apply_uV = 1,
2085                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
2086         },
2087         .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
2088         .consumer_supplies = pwm_consumers,
2089 };
2090
2091 static struct pwm_platform_data rk29_regulator_pwm_platform_data = {
2092         .pwm_id = REGULATOR_PWM_ID,
2093         .pwm_gpio = REGULATOR_PWM_GPIO,
2094         //.pwm_iomux_name[] = REGULATOR_PWM_MUX_NAME;
2095         .pwm_iomux_name = REGULATOR_PWM_MUX_NAME,
2096         .pwm_iomux_pwm = REGULATOR_PWM_MUX_MODE,
2097         .pwm_iomux_gpio = REGULATOR_PWM_MUX_MODE_GPIO,
2098         .init_data  = &rk29_pwm_regulator_data,
2099 };
2100
2101 static struct platform_device rk29_device_pwm_regulator = {
2102         .name = "pwm-voltage-regulator",
2103         .id   = -1,
2104         .dev  = {
2105                 .platform_data = &rk29_regulator_pwm_platform_data,
2106         },
2107 };
2108
2109 #endif
2110
2111
2112 #if defined(CONFIG_MTK23D)
2113 struct rk2818_23d_data rk2818_23d_info = {
2114         .bp_power = RK29_PIN0_PA0,
2115         //.bp_reset = TCA6424_P11,
2116         //.bp_statue = RK2818_PIN_PH7,//input  high bp sleep;
2117         //.ap_statue = RK2818_PIN_PA4,//output high ap sleep;
2118         //.ap_bp_wakeup = RK2818_PIN_PF5, //output AP wake up BP used rising edge;
2119         //.bp_ap_wakeup = RK2818_PIN_PE0,//input BP wake up AP
2120 };
2121 struct platform_device rk2818_device_mtk23d = { 
2122         .name = "mtk23d",       
2123         .id = -1,       
2124         .dev            = {
2125                 .platform_data = &rk2818_23d_info,
2126         }       
2127     };
2128 #endif
2129
2130
2131 /*****************************************************************************************
2132  * SDMMC devices
2133 *****************************************************************************************/
2134 #ifdef CONFIG_SDMMC0_RK29
2135 static int rk29_sdmmc0_cfg_gpio(void)
2136 {
2137         rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
2138         rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
2139         rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
2140         rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
2141         rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
2142         rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
2143         rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_SDMMC0_DETECT_N);
2144         rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5);   ///GPIO5H_SDMMC0_PWR_EN);  ///GPIO5H_GPIO5D5);
2145         gpio_request(RK29_PIN5_PD5,"sdmmc");
2146         gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
2147         mdelay(100);
2148         gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
2149         return 0;
2150 }
2151
2152 #define CONFIG_SDMMC0_USE_DMA
2153 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
2154         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
2155                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
2156                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
2157         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
2158         .io_init = rk29_sdmmc0_cfg_gpio,
2159         .dma_name = "sd_mmc",
2160 #ifdef CONFIG_SDMMC0_USE_DMA
2161         .use_dma  = 1,
2162 #else
2163         .use_dma = 0,
2164 #endif
2165 };
2166 #endif
2167 #ifdef CONFIG_SDMMC1_RK29
2168 #define CONFIG_SDMMC1_USE_DMA
2169 static int rk29_sdmmc1_cfg_gpio(void)
2170 {
2171         rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
2172         rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
2173         rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
2174         rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
2175         rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
2176         rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
2177         //rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_SDMMC1_DETECT_N);
2178         return 0;
2179 }
2180
2181 #ifdef CONFIG_WIFI_CONTROL_FUNC
2182 static int rk29sdk_wifi_status(struct device *dev);
2183 static int rk29sdk_wifi_status_register(void (*callback)(int card_presend, void *dev_id), void *dev_id);
2184 #endif
2185
2186 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK29_PIN1_PD6
2187
2188 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
2189         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
2190                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
2191                                            MMC_VDD_32_33|MMC_VDD_33_34),
2192         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
2193                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
2194         .io_init = rk29_sdmmc1_cfg_gpio,
2195         .dma_name = "sdio",
2196 #ifdef CONFIG_SDMMC1_USE_DMA
2197         .use_dma  = 1,
2198 #else
2199         .use_dma = 0,
2200 #endif
2201 #ifdef CONFIG_WIFI_CONTROL_FUNC
2202         .status = rk29sdk_wifi_status,
2203         .register_status_notify = rk29sdk_wifi_status_register,
2204 #endif
2205 #if 0
2206         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
2207 #endif
2208 };
2209 #endif
2210
2211 #ifdef CONFIG_WIFI_CONTROL_FUNC
2212 #define RK29SDK_WIFI_BT_GPIO_POWER_N       RK29_PIN5_PD6
2213 #define RK29SDK_WIFI_GPIO_RESET_N          RK29_PIN6_PC0
2214 #define RK29SDK_BT_GPIO_RESET_N            RK29_PIN6_PC7
2215
2216 static int rk29sdk_wifi_cd = 0;   /* wifi virtual 'card detect' status */
2217 static void (*wifi_status_cb)(int card_present, void *dev_id);
2218 static void *wifi_status_cb_devid;
2219 int rk29sdk_wifi_power_state = 0;
2220 int rk29sdk_bt_power_state = 0;
2221
2222 static int rk29sdk_wifi_status(struct device *dev)
2223 {
2224         return rk29sdk_wifi_cd;
2225 }
2226
2227 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
2228 {
2229         if(wifi_status_cb)
2230                 return -EAGAIN;
2231         wifi_status_cb = callback;
2232         wifi_status_cb_devid = dev_id;
2233         return 0;
2234 }
2235
2236 static int rk29sdk_wifi_bt_gpio_control_init(void)
2237 {
2238     if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
2239            pr_info("%s: request wifi_bt power gpio failed\n", __func__);
2240            return -1;
2241     }
2242
2243     if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
2244            pr_info("%s: request wifi reset gpio failed\n", __func__);
2245            gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
2246            return -1;
2247     }
2248
2249     if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
2250           pr_info("%s: request bt reset gpio failed\n", __func__);
2251           gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
2252           return -1;
2253     }
2254
2255     gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
2256     gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N,    GPIO_HIGH);
2257     gpio_direction_output(RK29SDK_BT_GPIO_RESET_N,      GPIO_HIGH);
2258
2259     pr_info("%s: init finished\n",__func__);
2260
2261     return 0;
2262 }
2263
2264 static int rk29sdk_wifi_power(int on)
2265 {
2266         pr_info("%s: %d\n", __func__, on);
2267         if (on){
2268                 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, on);
2269                 mdelay(100);
2270                 pr_info("wifi turn on power\n");
2271         }else{
2272                 if (!rk29sdk_bt_power_state){
2273                         gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, on);
2274                         mdelay(100);
2275                         pr_info("wifi shut off power\n");
2276                 }else
2277                 {
2278                         pr_info("wifi shouldn't shut off power, bt is using it!\n");
2279                 }
2280
2281         }
2282
2283         rk29sdk_wifi_power_state = on;
2284         return 0;
2285 }
2286
2287 static int rk29sdk_wifi_reset_state;
2288 static int rk29sdk_wifi_reset(int on)
2289 {
2290         pr_info("%s: %d\n", __func__, on);
2291         gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
2292         mdelay(100);
2293         rk29sdk_wifi_reset_state = on;
2294         return 0;
2295 }
2296
2297 int rk29sdk_wifi_set_carddetect(int val)
2298 {
2299         pr_info("%s:%d\n", __func__, val);
2300         rk29sdk_wifi_cd = val;
2301         if (wifi_status_cb){
2302                 wifi_status_cb(val, wifi_status_cb_devid);
2303         }else {
2304                 pr_warning("%s, nobody to notify\n", __func__);
2305         }
2306         return 0;
2307 }
2308 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
2309
2310 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
2311         {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
2312         {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
2313         {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
2314         {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
2315 };
2316
2317 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
2318 {
2319         if (section == PREALLOC_WLAN_SEC_NUM)
2320                 return wlan_static_skb;
2321
2322         if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
2323                 return NULL;
2324
2325         if (wifi_mem_array[section].size < size)
2326                 return NULL;
2327
2328         return wifi_mem_array[section].mem_ptr;
2329 }
2330
2331 int __init rk29sdk_init_wifi_mem(void)
2332 {
2333         int i;
2334         int j;
2335
2336         for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
2337                 wlan_static_skb[i] = dev_alloc_skb(
2338                                 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
2339
2340                 if (!wlan_static_skb[i])
2341                         goto err_skb_alloc;
2342         }
2343
2344         for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
2345                 wifi_mem_array[i].mem_ptr =
2346                                 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
2347
2348                 if (!wifi_mem_array[i].mem_ptr)
2349                         goto err_mem_alloc;
2350         }
2351         return 0;
2352
2353  err_mem_alloc:
2354         pr_err("Failed to mem_alloc for WLAN\n");
2355         for (j = 0 ; j < i ; j++)
2356                 kfree(wifi_mem_array[j].mem_ptr);
2357
2358         i = WLAN_SKB_BUF_NUM;
2359
2360  err_skb_alloc:
2361         pr_err("Failed to skb_alloc for WLAN\n");
2362         for (j = 0 ; j < i ; j++)
2363                 dev_kfree_skb(wlan_static_skb[j]);
2364
2365         return -ENOMEM;
2366 }
2367
2368 static struct wifi_platform_data rk29sdk_wifi_control = {
2369         .set_power = rk29sdk_wifi_power,
2370         .set_reset = rk29sdk_wifi_reset,
2371         .set_carddetect = rk29sdk_wifi_set_carddetect,
2372         .mem_prealloc   = rk29sdk_mem_prealloc,
2373 };
2374 static struct platform_device rk29sdk_wifi_device = {
2375         .name = "bcm4329_wlan",
2376         .id = 1,
2377         .dev = {
2378                 .platform_data = &rk29sdk_wifi_control,
2379          },
2380 };
2381 #endif
2382
2383
2384 /* bluetooth rfkill device */
2385 static struct platform_device rk29sdk_rfkill = {
2386         .name = "rk29sdk_rfkill",
2387         .id = -1,
2388 };
2389
2390
2391 #ifdef CONFIG_VIVANTE
2392 static struct resource resources_gpu[] = {
2393     [0] = {
2394                 .name   = "gpu_irq",
2395         .start  = IRQ_GPU,
2396         .end    = IRQ_GPU,
2397         .flags  = IORESOURCE_IRQ,
2398     },
2399     [1] = {
2400                 .name = "gpu_base",
2401         .start  = RK29_GPU_PHYS,
2402         .end    = RK29_GPU_PHYS + RK29_GPU_SIZE,
2403         .flags  = IORESOURCE_MEM,
2404     },
2405     [2] = {
2406                 .name = "gpu_mem",
2407         .start  = PMEM_GPU_BASE,
2408         .end    = PMEM_GPU_BASE + PMEM_GPU_SIZE,
2409         .flags  = IORESOURCE_MEM,
2410     },
2411 };
2412 static struct platform_device rk29_device_gpu = {
2413     .name             = "galcore",
2414     .id               = 0,
2415     .num_resources    = ARRAY_SIZE(resources_gpu),
2416     .resource         = resources_gpu,
2417 };
2418 #endif
2419 #ifdef CONFIG_KEYS_RK29
2420 extern struct rk29_keys_platform_data rk29_keys_pdata;
2421 static struct platform_device rk29_device_keys = {
2422         .name           = "rk29-keypad",
2423         .id             = -1,
2424         .dev            = {
2425                 .platform_data  = &rk29_keys_pdata,
2426         },
2427 };
2428 #endif
2429
2430 static void __init rk29_board_iomux_init(void)
2431 {
2432         #ifdef CONFIG_UART0_RK29
2433         rk29_mux_api_set(GPIO1B7_UART0SOUT_NAME, GPIO1L_UART0_SOUT);
2434         rk29_mux_api_set(GPIO1B6_UART0SIN_NAME, GPIO1L_UART0_SIN);
2435         #ifdef CONFIG_UART0_CTS_RTS_RK29
2436         rk29_mux_api_set(GPIO1C1_UART0RTSN_SDMMC1WRITEPRT_NAME, GPIO1H_UART0_RTS_N);
2437         rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_UART0_CTS_N);
2438         #endif
2439         #endif
2440         #ifdef CONFIG_UART1_RK29
2441         rk29_mux_api_set(GPIO2A5_UART1SOUT_NAME, GPIO2L_UART1_SOUT);
2442         rk29_mux_api_set(GPIO2A4_UART1SIN_NAME, GPIO2L_UART1_SIN);
2443         #endif
2444         #ifdef CONFIG_UART2_RK29
2445         rk29_mux_api_set(GPIO2B1_UART2SOUT_NAME, GPIO2L_UART2_SOUT);
2446         rk29_mux_api_set(GPIO2B0_UART2SIN_NAME, GPIO2L_UART2_SIN);
2447         #ifdef CONFIG_UART2_CTS_RTS_RK29
2448         rk29_mux_api_set(GPIO2A7_UART2RTSN_NAME, GPIO2L_UART2_RTS_N);
2449         rk29_mux_api_set(GPIO2A6_UART2CTSN_NAME, GPIO2L_UART2_CTS_N);
2450         #endif
2451         #endif
2452         #ifdef CONFIG_UART3_RK29
2453         rk29_mux_api_set(GPIO2B3_UART3SOUT_NAME, GPIO2L_UART3_SOUT);
2454         rk29_mux_api_set(GPIO2B2_UART3SIN_NAME, GPIO2L_UART3_SIN);
2455         #ifdef CONFIG_UART3_CTS_RTS_RK29
2456         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_UART3_RTS_N);
2457         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_UART3_CTS_N);
2458         #endif
2459         #endif
2460         #ifdef CONFIG_SPIM0_RK29
2461     rk29_mux_api_set(GPIO2C0_SPI0CLK_NAME, GPIO2H_SPI0_CLK);
2462         rk29_mux_api_set(GPIO2C1_SPI0CSN0_NAME, GPIO2H_SPI0_CSN0);
2463         rk29_mux_api_set(GPIO2C2_SPI0TXD_NAME, GPIO2H_SPI0_TXD);
2464         rk29_mux_api_set(GPIO2C3_SPI0RXD_NAME, GPIO2H_SPI0_RXD);
2465     #endif
2466     #ifdef CONFIG_SPIM1_RK29
2467     rk29_mux_api_set(GPIO2C4_SPI1CLK_NAME, GPIO2H_SPI1_CLK);
2468         rk29_mux_api_set(GPIO2C5_SPI1CSN0_NAME, GPIO2H_SPI1_CSN0);
2469         rk29_mux_api_set(GPIO2C6_SPI1TXD_NAME, GPIO2H_SPI1_TXD);
2470         rk29_mux_api_set(GPIO2C7_SPI1RXD_NAME, GPIO2H_SPI1_RXD);
2471     #endif
2472         #ifdef CONFIG_RK29_VMAC
2473     rk29_mux_api_set(GPIO4C0_RMIICLKOUT_RMIICLKIN_NAME, GPIO4H_RMII_CLKOUT);
2474     rk29_mux_api_set(GPIO4C1_RMIITXEN_MIITXEN_NAME, GPIO4H_RMII_TX_EN);
2475     rk29_mux_api_set(GPIO4C2_RMIITXD1_MIITXD1_NAME, GPIO4H_RMII_TXD1);
2476     rk29_mux_api_set(GPIO4C3_RMIITXD0_MIITXD0_NAME, GPIO4H_RMII_TXD0);
2477     rk29_mux_api_set(GPIO4C4_RMIIRXERR_MIIRXERR_NAME, GPIO4H_RMII_RX_ERR);
2478     rk29_mux_api_set(GPIO4C5_RMIICSRDVALID_MIIRXDVALID_NAME, GPIO4H_RMII_CSR_DVALID);
2479     rk29_mux_api_set(GPIO4C6_RMIIRXD1_MIIRXD1_NAME, GPIO4H_RMII_RXD1);
2480     rk29_mux_api_set(GPIO4C7_RMIIRXD0_MIIRXD0_NAME, GPIO4H_RMII_RXD0);
2481
2482         rk29_mux_api_set(GPIO0A7_MIIMDCLK_NAME, GPIO0L_MII_MDCLK);
2483         rk29_mux_api_set(GPIO0A6_MIIMD_NAME, GPIO0L_MII_MD);
2484         #endif
2485         #ifdef CONFIG_RK29_PWM_REGULATOR
2486         rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
2487         #endif
2488 }
2489
2490 static struct platform_device *devices[] __initdata = {
2491 #ifdef CONFIG_UART1_RK29
2492         &rk29_device_uart1,
2493 #endif
2494 #ifdef CONFIG_UART0_RK29
2495         &rk29_device_uart0,
2496 #endif
2497 #ifdef CONFIG_UART2_RK29
2498         &rk29_device_uart2,
2499 #endif
2500
2501 #ifdef CONFIG_RK29_PWM_REGULATOR
2502         &rk29_device_pwm_regulator,
2503 #endif
2504 #ifdef CONFIG_SPIM0_RK29
2505     &rk29xx_device_spi0m,
2506 #endif
2507 #ifdef CONFIG_SPIM1_RK29
2508     &rk29xx_device_spi1m,
2509 #endif
2510 #ifdef CONFIG_ADC_RK29
2511         &rk29_device_adc,
2512 #endif
2513 #ifdef CONFIG_I2C0_RK29
2514         &rk29_device_i2c0,
2515 #endif
2516 #ifdef CONFIG_I2C1_RK29
2517         &rk29_device_i2c1,
2518 #endif
2519 #ifdef CONFIG_I2C2_RK29
2520         &rk29_device_i2c2,
2521 #endif
2522 #ifdef CONFIG_I2C3_RK29
2523         &rk29_device_i2c3,
2524 #endif
2525
2526 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
2527         &rk29_device_iis_2ch,
2528 #endif
2529 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
2530         &rk29_device_iis_8ch,
2531 #endif
2532
2533 #ifdef CONFIG_KEYS_RK29
2534         &rk29_device_keys,
2535 #endif
2536 #ifdef CONFIG_SDMMC0_RK29
2537         &rk29_device_sdmmc0,
2538 #endif
2539 #ifdef CONFIG_SDMMC1_RK29
2540         &rk29_device_sdmmc1,
2541 #endif
2542
2543 #ifdef CONFIG_MTD_NAND_RK29XX
2544         &rk29xx_device_nand,
2545 #endif
2546
2547 #ifdef CONFIG_WIFI_CONTROL_FUNC
2548         &rk29sdk_wifi_device,
2549 #endif
2550
2551 #ifdef CONFIG_BT
2552         &rk29sdk_rfkill,
2553 #endif
2554
2555 #if defined(CONFIG_MTK23D)
2556         &rk2818_device_mtk23d,
2557 #endif
2558
2559 #ifdef CONFIG_MTD_NAND_RK29
2560         &rk29_device_nand,
2561 #endif
2562
2563 #ifdef CONFIG_FB_RK29
2564         &rk29_device_fb,
2565         &rk29_device_dma_cpy,
2566 #endif
2567 #ifdef CONFIG_BACKLIGHT_RK29_BL
2568         &rk29_device_backlight,
2569 #endif
2570 #ifdef CONFIG_RK29_VMAC
2571         &rk29_device_vmac,
2572 #endif
2573 #ifdef CONFIG_VIVANTE
2574         &rk29_device_gpu,
2575 #endif
2576 #ifdef CONFIG_VIDEO_RK29
2577         &rk29_device_camera,      /* ddl@rock-chips.com : camera support  */
2578         #if (SENSOR_IIC_ADDR_0 != 0x00)
2579         &rk29_soc_camera_pdrv_0,
2580         #endif
2581         &rk29_soc_camera_pdrv_1,
2582         &android_pmem_cam_device,
2583 #endif
2584         &android_pmem_device,
2585         &rk29_vpu_mem_device,
2586 #ifdef CONFIG_USB20_OTG
2587         &rk29_device_usb20_otg,
2588 #endif
2589 #ifdef CONFIG_USB20_HOST
2590         &rk29_device_usb20_host,
2591 #endif
2592 #ifdef CONFIG_USB11_HOST
2593         &rk29_device_usb11_host,
2594 #endif
2595 #ifdef CONFIG_USB_ANDROID
2596         &android_usb_device,
2597         &usb_mass_storage_device,
2598 #endif
2599 #ifdef CONFIG_RK29_IPP
2600         &rk29_device_ipp,
2601 #endif
2602 #ifdef CONFIG_VIDEO_RK29XX_VOUT
2603         &rk29_v4l2_output_devce,
2604 #endif
2605 };
2606
2607 #ifdef CONFIG_RK29_VMAC
2608 /*****************************************************************************************
2609  * vmac devices
2610  * author: lyx@rock-chips.com
2611  *****************************************************************************************/
2612 static int rk29_vmac_register_set(void)
2613 {
2614         //config rk29 vmac as rmii, 100MHz
2615         u32 value= readl(RK29_GRF_BASE + 0xbc);
2616         value = (value & 0xfff7ff) | (0x400);
2617         writel(value, RK29_GRF_BASE + 0xbc);
2618         return 0;
2619 }
2620
2621 static int rk29_rmii_io_init(void)
2622 {
2623         int err;
2624
2625         //phy power gpio
2626         err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
2627         if (err) {
2628                 gpio_free(RK29_PIN6_PB0);
2629                 printk("-------request RK29_PIN6_PB0 fail--------\n");
2630                 return -1;
2631         }
2632         //phy power down
2633         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2634         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2635
2636         return 0;
2637 }
2638
2639 static int rk29_rmii_io_deinit(void)
2640 {
2641         //phy power down
2642         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2643         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2644         //free
2645         gpio_free(RK29_PIN6_PB0);
2646         return 0;
2647 }
2648
2649 static int rk29_rmii_power_control(int enable)
2650 {
2651         if (enable) {
2652                 //enable phy power
2653                 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
2654                 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
2655         }
2656         else {
2657                 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2658                 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2659         }
2660         return 0;
2661 }
2662
2663 struct rk29_vmac_platform_data rk29_vmac_pdata = {
2664         .vmac_register_set = rk29_vmac_register_set,
2665         .rmii_io_init = rk29_rmii_io_init,
2666         .rmii_io_deinit = rk29_rmii_io_deinit,
2667         .rmii_power_control = rk29_rmii_power_control,
2668 };
2669 #endif
2670
2671 /*****************************************************************************************
2672  * spi devices
2673  * author: cmc@rock-chips.com
2674  *****************************************************************************************/
2675 #define SPI_CHIPSELECT_NUM 2
2676 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
2677     {
2678                 .name = "spi0 cs0",
2679                 .cs_gpio = RK29_PIN2_PC1,
2680                 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
2681                 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
2682         },
2683         {
2684                 .name = "spi0 cs1",
2685                 .cs_gpio = RK29_PIN1_PA4,
2686                 .cs_iomux_name = GPIO1A4_EMMCWRITEPRT_SPI0CS1_NAME,//if no iomux,set it NULL
2687                 .cs_iomux_mode = GPIO1L_SPI0_CSN1,
2688         }
2689 };
2690
2691 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
2692     {
2693                 .name = "spi1 cs0",
2694                 .cs_gpio = RK29_PIN2_PC5,
2695                 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
2696                 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
2697         },
2698         {
2699                 .name = "spi1 cs1",
2700                 .cs_gpio = RK29_PIN1_PA3,
2701                 .cs_iomux_name = GPIO1A3_EMMCDETECTN_SPI1CS1_NAME,//if no iomux,set it NULL
2702                 .cs_iomux_mode = GPIO1L_SPI1_CSN1,
2703         }
2704 };
2705
2706 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
2707 {
2708 #if 1
2709                 int i;
2710                 if (cs_gpios) {
2711                         for (i=0; i<cs_num; i++) {
2712                                 rk29_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
2713                         }
2714                 }
2715 #endif
2716         return 0;
2717 }
2718
2719 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
2720 {
2721         return 0;
2722 }
2723
2724 static int spi_io_fix_leakage_bug(void)
2725 {
2726 #if 0
2727         gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
2728 #endif
2729         return 0;
2730 }
2731
2732 static int spi_io_resume_leakage_bug(void)
2733 {
2734 #if 0
2735         gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
2736 #endif
2737         return 0;
2738 }
2739
2740 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
2741         .num_chipselect = SPI_CHIPSELECT_NUM,
2742         .chipselect_gpios = rk29xx_spi0_cs_gpios,
2743         .io_init = spi_io_init,
2744         .io_deinit = spi_io_deinit,
2745         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
2746         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
2747 };
2748
2749 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
2750         .num_chipselect = SPI_CHIPSELECT_NUM,
2751         .chipselect_gpios = rk29xx_spi1_cs_gpios,
2752         .io_init = spi_io_init,
2753         .io_deinit = spi_io_deinit,
2754         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
2755         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
2756 };
2757
2758 /*****************************************************************************************
2759  * xpt2046 touch panel
2760  * author: hhb@rock-chips.com
2761  *****************************************************************************************/
2762 #if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
2763 #define XPT2046_GPIO_INT           RK29_PIN4_PD5 //中æ\96­è\84?#define DEBOUNCE_REPTIME  3
2764
2765 static struct xpt2046_platform_data xpt2046_info = {
2766         .model                  = 2046,
2767         .keep_vref_on   = 1,
2768         .swap_xy                = 0,
2769         .debounce_max           = 7,
2770         .debounce_rep           = DEBOUNCE_REPTIME,
2771         .debounce_tol           = 20,
2772         .gpio_pendown           = XPT2046_GPIO_INT,
2773         .pendown_iomux_name = GPIO4D5_CPUTRACECTL_NAME, 
2774         .pendown_iomux_mode = GPIO4H_GPIO4D5,   
2775         .touch_virtualkey_length = 60,
2776         .penirq_recheck_delay_usecs = 1,
2777 #if defined(CONFIG_TOUCHSCREEN_480X800)
2778         .x_min                  = 0,
2779         .x_max                  = 480,
2780         .y_min                  = 0,
2781         .y_max                  = 800,
2782         .touch_ad_top = 3940,
2783         .touch_ad_bottom = 310,
2784         .touch_ad_left = 3772,
2785         .touch_ad_right = 340,
2786 #elif defined(CONFIG_TOUCHSCREEN_800X480)
2787         .x_min                  = 0,
2788         .x_max                  = 800,
2789         .y_min                  = 0,
2790         .y_max                  = 480,
2791         .touch_ad_top = 2447,
2792         .touch_ad_bottom = 207,
2793         .touch_ad_left = 5938,
2794         .touch_ad_right = 153,
2795 #elif defined(CONFIG_TOUCHSCREEN_320X480)
2796         .x_min                  = 0,
2797         .x_max                  = 320,
2798         .y_min                  = 0,
2799         .y_max                  = 480,
2800         .touch_ad_top = 3166,
2801         .touch_ad_bottom = 256,
2802         .touch_ad_left = 3658,
2803         .touch_ad_right = 380,
2804 #endif  
2805 };
2806 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
2807 static struct xpt2046_platform_data xpt2046_info = {
2808         .model                  = 2046,
2809         .keep_vref_on   = 1,
2810         .swap_xy                = 0,
2811         .debounce_max           = 7,
2812         .debounce_rep           = DEBOUNCE_REPTIME,
2813         .debounce_tol           = 20,
2814         .gpio_pendown           = XPT2046_GPIO_INT,
2815         .pendown_iomux_name = GPIO4D5_CPUTRACECTL_NAME, 
2816         .pendown_iomux_mode = GPIO4H_GPIO4D5,   
2817         .touch_virtualkey_length = 60,
2818         .penirq_recheck_delay_usecs = 1,
2819         
2820 #if defined(CONFIG_TOUCHSCREEN_480X800)
2821         .x_min                  = 0,
2822         .x_max                  = 480,
2823         .y_min                  = 0,
2824         .y_max                  = 800,
2825         .screen_x = { 70,  410, 70, 410, 240},
2826         .screen_y = { 50, 50,  740, 740, 400},
2827         .uncali_x_default = {  3267,  831, 3139, 715, 1845 },
2828         .uncali_y_default = { 3638,  3664, 564,  591, 2087 },
2829 #elif defined(CONFIG_TOUCHSCREEN_800X480)
2830         .x_min                  = 0,
2831         .x_max                  = 800,
2832         .y_min                  = 0,
2833         .y_max                  = 480,
2834         .screen_x[5] = { 50, 750,  50, 750, 400};
2835         .screen_y[5] = { 40,  40, 440, 440, 240};
2836         .uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };
2837         .uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };
2838 #elif defined(CONFIG_TOUCHSCREEN_320X480)
2839         .x_min                  = 0,
2840         .x_max                  = 320,
2841         .y_min                  = 0,
2842         .y_max                  = 480,
2843         .screen_x[5] = { 50, 270,  50, 270, 160}; 
2844         .screen_y[5] = { 40,  40, 440, 440, 240}; 
2845         .uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };
2846         .uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };
2847 #endif  
2848 };
2849 #endif
2850
2851 static struct spi_board_info board_spi_devices[] = {
2852 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
2853         {
2854                 .modalias       = "xpt2046_ts",
2855                 .chip_select    = 0,// 2,
2856                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
2857                 .bus_num        = 0,
2858                 .irq = XPT2046_GPIO_INT,
2859                 .platform_data = &xpt2046_info,
2860         },
2861 #endif
2862
2863 #if defined(CONFIG_MFD_WM831X_SPI)
2864         {
2865                 .modalias       = "wm8310",
2866                 .chip_select    = 1,
2867                 .max_speed_hz   = 1*1000*1000,
2868                 .bus_num        = 1,
2869                 .irq            = RK29_PIN4_PD0,
2870                 .platform_data = &wm831x_platdata,
2871         },
2872 #endif
2873
2874 };
2875
2876
2877 /**********************************************************************************************
2878  *
2879  * The virtual keys for android "back", "home", "menu", "search", these four keys are touch key
2880  * on the touch screen panel. (added by hhb@rock-chips.com 2011.03.31)
2881  *
2882  ***********************************************************************************************/
2883 static ssize_t rk29xx_virtual_keys_show(struct kobject *kobj,
2884                         struct kobj_attribute *attr, char *buf)
2885 {
2886 #if (defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) && defined(CONFIG_TOUCHSCREEN_480X800)) \
2887         || defined(CONFIG_TOUCHSCREEN_HX8520_IIC) || defined(CONFIG_TOUCHSCREEN_GT801_IIC)
2888         /* center: x: home: 50, menu: 184, back: 315, search 435, y: 830*/
2889     /* centerx;centery;width;height; */
2890         return sprintf(buf,
2891                 __stringify(EV_KEY) ":" __stringify(KEY_BACK)       ":315:815:120:50"     //":50:830:98:50"  //":210:796:98:50"
2892                 ":" __stringify(EV_KEY) ":" __stringify(KEY_MENU)   ":85:815:88:50"   // ":184:830:120:50"  // ":435:796:120:50"
2893                 ":" __stringify(EV_KEY) ":" __stringify(KEY_HOME)   ":184:815:100:50"   //":315:830:100:50"  //":320:796:100:50"
2894                 ":" __stringify(EV_KEY) ":" __stringify(KEY_SEARCH) ":435:815:88:50"   //":50:815:98:50"    //   //":85:796:88:50"
2895                 "\n");
2896 #endif
2897         return 0;
2898 }
2899
2900 static struct kobj_attribute rk29xx_virtual_keys_attr = {
2901         .attr = {
2902 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
2903                 .name = "virtualkeys.xpt2046-touchscreen",
2904 #elif defined(CONFIG_TOUCHSCREEN_HX8520_IIC)
2905         .name = "virtualkeys.hx8520-touchscreen",
2906 #elif defined(CONFIG_TOUCHSCREEN_GT801_IIC)
2907                 .name = "virtualkeys.gt801-touchscreen",
2908 #endif
2909
2910
2911                 .mode = S_IRUGO,
2912         },
2913         .show = &rk29xx_virtual_keys_show,
2914 };
2915
2916 static struct attribute *rk29xx_properties_attrs[] = {
2917         &rk29xx_virtual_keys_attr.attr,
2918         NULL
2919 };
2920
2921 static struct attribute_group rk29xx_properties_attr_group = {
2922         .attrs = rk29xx_properties_attrs,
2923 };
2924 static int rk29xx_virtual_keys_init(void)
2925 {
2926         int ret;
2927         struct kobject *properties_kobj;
2928         printk("rk29xx_virtual_keys_init \n");
2929         properties_kobj = kobject_create_and_add("board_properties", NULL);
2930         if (properties_kobj)
2931                 ret = sysfs_create_group(properties_kobj,
2932                                 &rk29xx_properties_attr_group);
2933         if (!properties_kobj || ret)
2934         {
2935                 pr_err("failed to create board_properties\n");
2936         }
2937         return ret;
2938 }
2939
2940
2941 static void __init rk29_gic_init_irq(void)
2942 {
2943         gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
2944         gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
2945 }
2946
2947 static void __init machine_rk29_init_irq(void)
2948 {
2949         rk29_gic_init_irq();
2950         rk29_gpio_init();
2951 }
2952
2953 #define POWER_ON_PIN RK29_PIN4_PA4
2954 static void rk29_pm_power_off(void)
2955 {
2956         printk(KERN_ERR "rk29_pm_power_off start...\n");
2957         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
2958         while (1);
2959 }
2960
2961 static void __init machine_rk29_board_init(void)
2962 {
2963         rk29_board_iomux_init();
2964
2965         gpio_request(POWER_ON_PIN,"poweronpin");
2966         gpio_set_value(POWER_ON_PIN, GPIO_HIGH);
2967         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2968         pm_power_off = rk29_pm_power_off;
2969
2970 // codec                 
2971         gpio_request(RK29_PIN5_PA1, NULL);                       
2972         gpio_direction_output(RK29_PIN5_PA1,GPIO_HIGH);                 
2973         gpio_free(RK29_PIN5_PA1);
2974
2975         platform_add_devices(devices, ARRAY_SIZE(devices));
2976 #ifdef CONFIG_I2C0_RK29
2977         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
2978                         ARRAY_SIZE(board_i2c0_devices));
2979 #endif
2980 #ifdef CONFIG_I2C1_RK29
2981         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
2982                         ARRAY_SIZE(board_i2c1_devices));
2983 #endif
2984 #ifdef CONFIG_I2C2_RK29
2985         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
2986                         ARRAY_SIZE(board_i2c2_devices));
2987 #endif
2988 #ifdef CONFIG_I2C3_RK29
2989         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
2990                         ARRAY_SIZE(board_i2c3_devices));
2991 #endif
2992
2993         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
2994
2995 #ifdef CONFIG_WIFI_CONTROL_FUNC
2996         rk29sdk_wifi_bt_gpio_control_init();
2997         rk29sdk_init_wifi_mem();
2998 #endif
2999
3000         rk29xx_virtual_keys_init();
3001 }
3002
3003 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
3004                                         char **cmdline, struct meminfo *mi)
3005 {
3006         mi->nr_banks = 1;
3007         mi->bank[0].start = RK29_SDRAM_PHYS;
3008         mi->bank[0].node = PHYS_TO_NID(RK29_SDRAM_PHYS);
3009         mi->bank[0].size = LINUX_SIZE;
3010 }
3011
3012 static void __init machine_rk29_mapio(void)
3013 {
3014         rk29_map_common_io();
3015         rk29_setup_early_printk();
3016         rk29_sram_init();
3017         rk29_clock_init();
3018         rk29_iomux_init();
3019 }
3020
3021 MACHINE_START(RK29, "RK29board")
3022         /* UART for LL DEBUG */
3023         .phys_io        = RK29_UART1_PHYS,
3024         .io_pg_offst    = ((RK29_UART1_BASE) >> 18) & 0xfffc,
3025         .boot_params    = RK29_SDRAM_PHYS + 0x88000,
3026         .fixup          = machine_rk29_fixup,
3027         .map_io         = machine_rk29_mapio,
3028         .init_irq       = machine_rk29_init_irq,
3029         .init_machine   = machine_rk29_board_init,
3030         .timer          = &rk29_timer,
3031 MACHINE_END