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