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