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