Merge branch 'develop' of 10.10.10.29:/home/rockchip/kernel into develop
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk29 / board-rk29-ddr3sdk.c
1 /* arch/arm/mach-rk29/board-rk29.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 #include <mach/ddr.h>
47 #include <mach/cpufreq.h>
48
49 #include <linux/regulator/rk29-pwm-regulator.h>
50 #include <linux/regulator/machine.h>
51
52 #include <linux/mtd/nand.h>
53 #include <linux/mtd/partitions.h>
54 #include <linux/i2c-gpio.h>
55
56 #include "devices.h"
57 #include "../../../drivers/input/touchscreen/xpt2046_cbn_ts.h"
58
59 #ifdef CONFIG_VIDEO_RK29
60 /*---------------- Camera Sensor Macro Define Begin  ------------------------*/
61 /*---------------- Camera Sensor Configuration Macro Begin ------------------------*/
62 #define CONFIG_SENSOR_0 RK29_CAM_SENSOR_OV5642                      /* back camera sensor */
63 #define CONFIG_SENSOR_IIC_ADDR_0            0x78
64 #define CONFIG_SENSOR_IIC_ADAPTER_ID_0    1
65 #define CONFIG_SENSOR_POWER_PIN_0         INVALID_GPIO
66 #define CONFIG_SENSOR_RESET_PIN_0         INVALID_GPIO
67 #define CONFIG_SENSOR_POWERDN_PIN_0       RK29_PIN6_PB7
68 #define CONFIG_SENSOR_FALSH_PIN_0         INVALID_GPIO
69 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
70 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
71 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
72 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
73
74 #define CONFIG_SENSOR_1 RK29_CAM_SENSOR_OV2659                      /* front camera sensor */
75 #define CONFIG_SENSOR_IIC_ADDR_1            0x60
76 #define CONFIG_SENSOR_IIC_ADAPTER_ID_1    1
77 #define CONFIG_SENSOR_POWER_PIN_1         INVALID_GPIO
78 #define CONFIG_SENSOR_RESET_PIN_1         INVALID_GPIO
79 #define CONFIG_SENSOR_POWERDN_PIN_1       RK29_PIN5_PD7
80 #define CONFIG_SENSOR_FALSH_PIN_1         INVALID_GPIO
81 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
82 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
83 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
84 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
85 #endif  //#ifdef CONFIG_VIDEO_RK29
86 /*---------------- Camera Sensor Configuration Macro End------------------------*/
87 #include "../../../drivers/media/video/rk29_camera.c"
88 /*---------------- Camera Sensor Macro Define End  ------------------------*/
89
90 /* Set memory size of pmem */
91 #ifdef CONFIG_RK29_MEM_SIZE_M
92 #define SDRAM_SIZE          (CONFIG_RK29_MEM_SIZE_M * SZ_1M)
93 #else
94 #define SDRAM_SIZE          SZ_512M
95 #endif
96 #define PMEM_GPU_SIZE       SZ_64M
97 #define PMEM_UI_SIZE        SZ_32M
98 #define PMEM_VPU_SIZE       SZ_64M
99 #define PMEM_CAM_SIZE       PMEM_CAM_NECESSARY
100 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
101 #define MEM_CAMIPP_SIZE     SZ_4M
102 #else
103 #define MEM_CAMIPP_SIZE     0
104 #endif
105 #define MEM_FB_SIZE         (3*SZ_2M)
106 #ifdef CONFIG_FB_WORK_IPP
107 #define MEM_FBIPP_SIZE      SZ_8M   //1920 x 1080 x 2 x 2  //RGB565 = x2;RGB888 = x4
108 #else
109 #define MEM_FBIPP_SIZE      0
110 #endif
111 #if SDRAM_SIZE > SZ_512M
112 #define PMEM_GPU_BASE       (RK29_SDRAM_PHYS + SZ_512M - PMEM_GPU_SIZE)
113 #else
114 #define PMEM_GPU_BASE       (RK29_SDRAM_PHYS + SDRAM_SIZE - PMEM_GPU_SIZE)
115 #endif
116 #define PMEM_UI_BASE        (PMEM_GPU_BASE - PMEM_UI_SIZE)
117 #define PMEM_VPU_BASE       (PMEM_UI_BASE - PMEM_VPU_SIZE)
118 #define PMEM_CAM_BASE       (PMEM_VPU_BASE - PMEM_CAM_SIZE)
119 #define MEM_CAMIPP_BASE     (PMEM_CAM_BASE - MEM_CAMIPP_SIZE)
120 #define MEM_FB_BASE         (MEM_CAMIPP_BASE - MEM_FB_SIZE)
121 #define MEM_FBIPP_BASE      (MEM_FB_BASE - MEM_FBIPP_SIZE)
122 #define LINUX_SIZE          (MEM_FBIPP_BASE - RK29_SDRAM_PHYS)
123
124 #define PREALLOC_WLAN_SEC_NUM           4
125 #define PREALLOC_WLAN_BUF_NUM           160
126 #define PREALLOC_WLAN_SECTION_HEADER    24
127
128 #define WLAN_SECTION_SIZE_0     (PREALLOC_WLAN_BUF_NUM * 128)
129 #define WLAN_SECTION_SIZE_1     (PREALLOC_WLAN_BUF_NUM * 128)
130 #define WLAN_SECTION_SIZE_2     (PREALLOC_WLAN_BUF_NUM * 512)
131 #define WLAN_SECTION_SIZE_3     (PREALLOC_WLAN_BUF_NUM * 1024)
132
133 #define WLAN_SKB_BUF_NUM        16
134
135 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
136
137 struct wifi_mem_prealloc {
138         void *mem_ptr;
139         unsigned long size;
140 };
141
142 extern struct sys_timer rk29_timer;
143
144 static int rk29_nand_io_init(void)
145 {
146     return 0;
147 }
148
149 struct rk29_nand_platform_data rk29_nand_data = {
150     .width      = 1,     /* data bus width in bytes */
151     .hw_ecc     = 1,     /* hw ecc 0: soft ecc */
152     .num_flash    = 1,
153     .io_init   = rk29_nand_io_init,
154 };
155
156 #define TOUCH_SCREEN_STANDBY_PIN          RK29_PIN6_PD1
157 #define TOUCH_SCREEN_STANDBY_VALUE        GPIO_HIGH
158 #define TOUCH_SCREEN_DISPLAY_PIN          INVALID_GPIO
159 #define TOUCH_SCREEN_DISPLAY_VALUE        GPIO_HIGH
160 #ifdef CONFIG_FB_RK29
161 /*****************************************************************************************
162  * lcd  devices
163  * author: zyw@rock-chips.com
164  *****************************************************************************************/
165 //#ifdef  CONFIG_LCD_TD043MGEA1
166 #define LCD_TXD_PIN          INVALID_GPIO
167 #define LCD_CLK_PIN          INVALID_GPIO
168 #define LCD_CS_PIN           INVALID_GPIO
169 /*****************************************************************************************
170 * frame buffe  devices
171 * author: zyw@rock-chips.com
172 *****************************************************************************************/
173 #define FB_ID                       0
174 #define FB_DISPLAY_ON_PIN           INVALID_GPIO// RK29_PIN6_PD0
175 #define FB_LCD_STANDBY_PIN          INVALID_GPIO
176 #define FB_LCD_CABC_EN_PIN          RK29_PIN6_PD2
177 #define FB_MCU_FMK_PIN              INVALID_GPIO
178
179 #define FB_DISPLAY_ON_VALUE         GPIO_HIGH
180 #define FB_LCD_STANDBY_VALUE        GPIO_HIGH
181
182 static int rk29_lcd_io_init(void)
183 {
184     int ret = 0;
185     return ret;
186 }
187
188 static int rk29_lcd_io_deinit(void)
189 {
190     int ret = 0;
191     return ret;
192 }
193
194 static struct rk29lcd_info rk29_lcd_info = {
195     .txd_pin  = LCD_TXD_PIN,
196     .clk_pin = LCD_CLK_PIN,
197     .cs_pin = LCD_CS_PIN,
198     .io_init   = rk29_lcd_io_init,
199     .io_deinit = rk29_lcd_io_deinit,
200 };
201
202 int rk29_fb_io_enable(void)
203 {
204     if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
205     {
206         gpio_direction_output(FB_DISPLAY_ON_PIN, 0);
207         gpio_set_value(FB_DISPLAY_ON_PIN, FB_DISPLAY_ON_VALUE);              
208     }
209     if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
210     {
211         gpio_direction_output(FB_LCD_STANDBY_PIN, 0);
212         gpio_set_value(FB_LCD_STANDBY_PIN, FB_LCD_STANDBY_VALUE);             
213     }
214     return 0;
215 }
216
217 int rk29_fb_io_disable(void)
218 {
219     if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
220     {
221         gpio_direction_output(FB_DISPLAY_ON_PIN, 0);
222         gpio_set_value(FB_DISPLAY_ON_PIN, !FB_DISPLAY_ON_VALUE);              
223     }
224     if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
225     {
226         gpio_direction_output(FB_LCD_STANDBY_PIN, 0);
227         gpio_set_value(FB_LCD_STANDBY_PIN, !FB_LCD_STANDBY_VALUE);             
228     }
229     return 0;
230 }
231
232 static int rk29_fb_io_init(struct rk29_fb_setting_info *fb_setting)
233 {
234     int ret = 0;
235     if(fb_setting->mcu_fmk_en && (FB_MCU_FMK_PIN != INVALID_GPIO))
236     {
237         ret = gpio_request(FB_MCU_FMK_PIN, NULL);
238         if(ret != 0)
239         {
240             gpio_free(FB_MCU_FMK_PIN);
241             printk(">>>>>> FB_MCU_FMK_PIN gpio_request err \n ");
242         }
243         gpio_direction_input(FB_MCU_FMK_PIN);
244     }
245     if(fb_setting->disp_on_en)
246     {
247         if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
248         {
249             ret = gpio_request(FB_DISPLAY_ON_PIN, NULL);
250             if(ret != 0)
251             {
252                 gpio_free(FB_DISPLAY_ON_PIN);
253                 printk(">>>>>> FB_DISPLAY_ON_PIN gpio_request err \n ");
254             }
255         }
256         else
257         {
258              ret = gpio_request(TOUCH_SCREEN_DISPLAY_PIN, NULL);
259              if(ret != 0)
260              {
261                  gpio_free(TOUCH_SCREEN_DISPLAY_PIN);
262                  printk(">>>>>> TOUCH_SCREEN_DISPLAY_PIN gpio_request err \n ");
263              }
264              gpio_direction_output(TOUCH_SCREEN_DISPLAY_PIN, 0);
265              gpio_set_value(TOUCH_SCREEN_DISPLAY_PIN, TOUCH_SCREEN_DISPLAY_VALUE);
266         }
267     }
268
269     if(fb_setting->disp_on_en)
270     {
271         if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
272         {
273              ret = gpio_request(FB_LCD_STANDBY_PIN, NULL);
274              if(ret != 0)
275              {
276                  gpio_free(FB_LCD_STANDBY_PIN);
277                  printk(">>>>>> FB_LCD_STANDBY_PIN gpio_request err \n ");
278              }
279         }
280         else
281         {
282              ret = gpio_request(TOUCH_SCREEN_STANDBY_PIN, NULL);
283              if(ret != 0)
284              {
285                  gpio_free(TOUCH_SCREEN_STANDBY_PIN);
286                  printk(">>>>>> TOUCH_SCREEN_STANDBY_PIN gpio_request err \n ");
287              }
288              gpio_direction_output(TOUCH_SCREEN_STANDBY_PIN, 0);
289              gpio_set_value(TOUCH_SCREEN_STANDBY_PIN, TOUCH_SCREEN_STANDBY_VALUE);
290          }
291     }
292
293     if(FB_LCD_CABC_EN_PIN != INVALID_GPIO)
294     {
295         ret = gpio_request(FB_LCD_CABC_EN_PIN, NULL);
296         if(ret != 0)
297         {
298             gpio_free(FB_LCD_CABC_EN_PIN);
299             printk(">>>>>> FB_LCD_CABC_EN_PIN gpio_request err \n ");
300         }
301         gpio_direction_output(FB_LCD_CABC_EN_PIN, 0);
302         gpio_set_value(FB_LCD_CABC_EN_PIN, GPIO_LOW);
303     }
304     
305     rk29_fb_io_enable();   //enable it
306
307     return ret;
308 }
309
310 static struct rk29fb_info rk29_fb_info = {
311     .fb_id   = FB_ID,
312     .mcu_fmk_pin = FB_MCU_FMK_PIN,
313     .lcd_info = &rk29_lcd_info,
314     .io_init   = rk29_fb_io_init,
315     .io_enable = rk29_fb_io_enable,
316     .io_disable = rk29_fb_io_disable,
317 };
318
319 /* rk29 fb resource */
320 static struct resource rk29_fb_resource[] = {
321         [0] = {
322         .name  = "lcdc reg",
323                 .start = RK29_LCDC_PHYS,
324                 .end   = RK29_LCDC_PHYS + RK29_LCDC_SIZE - 1,
325                 .flags = IORESOURCE_MEM,
326         },
327         [1] = {
328             .name  = "lcdc irq",
329                 .start = IRQ_LCDC,
330                 .end   = IRQ_LCDC,
331                 .flags = IORESOURCE_IRQ,
332         },
333         [2] = {
334             .name   = "win1 buf",
335         .start  = MEM_FB_BASE,
336         .end    = MEM_FB_BASE + MEM_FB_SIZE - 1,
337         .flags  = IORESOURCE_MEM,
338     },
339     #ifdef CONFIG_FB_WORK_IPP
340     [3] = {
341             .name   = "win1 ipp buf",
342         .start  = MEM_FBIPP_BASE,
343         .end    = MEM_FBIPP_BASE + MEM_FBIPP_SIZE - 1,
344         .flags  = IORESOURCE_MEM,
345     },
346     #endif
347 };
348
349 /*platform_device*/
350 struct platform_device rk29_device_fb = {
351         .name             = "rk29-fb",
352         .id               = 4,
353         .num_resources    = ARRAY_SIZE(rk29_fb_resource),
354         .resource         = rk29_fb_resource,
355         .dev            = {
356                 .platform_data  = &rk29_fb_info,
357         }
358 };
359
360 struct platform_device rk29_device_dma_cpy = {
361         .name             = "dma_memcpy",
362         .id               = 4,
363
364 };
365
366 #endif
367
368 static struct android_pmem_platform_data android_pmem_pdata = {
369         .name           = "pmem",
370         .start          = PMEM_UI_BASE,
371         .size           = PMEM_UI_SIZE,
372         .no_allocator   = 0,
373         .cached         = 1,
374 };
375
376 static struct platform_device android_pmem_device = {
377         .name           = "android_pmem",
378         .id             = 0,
379         .dev            = {
380                 .platform_data = &android_pmem_pdata,
381         },
382 };
383
384
385 static struct vpu_mem_platform_data vpu_mem_pdata = {
386         .name           = "vpu_mem",
387         .start          = PMEM_VPU_BASE,
388         .size           = PMEM_VPU_SIZE,
389         .cached         = 1,
390 };
391
392 static struct platform_device rk29_vpu_mem_device = {
393         .name           = "vpu_mem",
394         .id                 = 2,
395         .dev            = {
396         .platform_data = &vpu_mem_pdata,
397         },
398 };
399 #ifdef CONFIG_VIDEO_RK29XX_VOUT
400 static struct platform_device rk29_v4l2_output_devce = {
401         .name           = "rk29_vout",
402 };
403 #endif
404 /*HANNSTAR_P1003 touch*/
405 #if defined (CONFIG_HANNSTAR_P1003)
406 #define TOUCH_RESET_PIN RK29_PIN6_PC3
407 #define TOUCH_INT_PIN   RK29_PIN0_PA2
408
409 int p1003_init_platform_hw(void)
410 {
411     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
412       gpio_free(TOUCH_RESET_PIN);
413       printk("p1003_init_platform_hw gpio_request error\n");
414       return -EIO;
415     }
416
417     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
418       gpio_free(TOUCH_INT_PIN);
419       printk("p1003_init_platform_hw gpio_request error\n");
420       return -EIO;
421     }
422     gpio_pull_updown(TOUCH_INT_PIN, 1);
423     gpio_direction_output(TOUCH_RESET_PIN, 0);
424     msleep(500);
425     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
426     msleep(500);
427     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
428
429     return 0;
430 }
431
432
433 struct p1003_platform_data p1003_info = {
434   .model= 1003,
435   .init_platform_hw= p1003_init_platform_hw,
436
437 };
438 #endif
439 #if defined (CONFIG_EETI_EGALAX)
440 #define TOUCH_RESET_PIN RK29_PIN6_PC3
441 #define TOUCH_INT_PIN   RK29_PIN0_PA2
442
443 static int EETI_EGALAX_init_platform_hw(void)
444 {
445     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
446       gpio_free(TOUCH_RESET_PIN);
447       printk("p1003_init_platform_hw gpio_request error\n");
448       return -EIO;
449     }
450
451     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
452       gpio_free(TOUCH_INT_PIN);
453       printk("p1003_init_platform_hw gpio_request error\n");
454       return -EIO;
455     }
456     gpio_pull_updown(TOUCH_INT_PIN, 1);
457     gpio_direction_output(TOUCH_RESET_PIN, 0);
458     msleep(500);
459     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
460     msleep(500);
461     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
462
463     return 0;
464 }
465
466
467 static struct eeti_egalax_platform_data eeti_egalax_info = {
468   .model= 1003,
469   .init_platform_hw= EETI_EGALAX_init_platform_hw,
470   .standby_pin = TOUCH_SCREEN_STANDBY_PIN,
471   .standby_value = TOUCH_SCREEN_STANDBY_VALUE,
472   .disp_on_pin = TOUCH_SCREEN_DISPLAY_PIN,
473   .disp_on_value = TOUCH_SCREEN_DISPLAY_VALUE,
474 };
475 #endif
476 /*MMA8452 gsensor*/
477 #if defined (CONFIG_GS_MMA8452)
478 #define MMA8452_INT_PIN   RK29_PIN0_PA3
479
480 static int mma8452_init_platform_hw(void)
481 {
482
483     if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
484       gpio_free(MMA8452_INT_PIN);
485       printk("mma8452_init_platform_hw gpio_request error\n");
486       return -EIO;
487     }
488     gpio_pull_updown(MMA8452_INT_PIN, 1);
489     return 0;
490 }
491
492
493 static struct mma8452_platform_data mma8452_info = {
494   .model= 8452,
495   .swap_xy = 0,
496   .init_platform_hw= mma8452_init_platform_hw,
497
498 };
499 #endif
500 #if defined (CONFIG_MPU_SENSORS_MPU3050)
501 /*mpu3050*/
502 static struct mpu3050_platform_data mpu3050_data = {
503                 .int_config = 0x10,
504                 //.orientation = { 1, 0, 0,0, -1, 0,0, 0, 1 },
505                 //.orientation = { 0, 1, 0,-1, 0, 0,0, 0, -1 },
506                 //.orientation = { -1, 0, 0,0, -1, 0,0, 0, -1 },
507                 .orientation = { 0, 1, 0, -1, 0, 0, 0, 0, 1 },
508                 .level_shifter = 0,
509 #if defined (CONFIG_MPU_SENSORS_KXTF9)
510                 .accel = {
511 #ifdef CONFIG_MPU_SENSORS_MPU3050_MODULE
512                                 .get_slave_descr = NULL ,
513 #else
514                                 .get_slave_descr = get_accel_slave_descr ,                      
515 #endif
516                                 .adapt_num = 0, // The i2c bus to which the mpu device is
517                                 // connected
518                                 //.irq = RK29_PIN0_PA3,
519                                 .bus = EXT_SLAVE_BUS_SECONDARY,  //The secondary I2C of MPU
520                                 .address = 0x0f,
521                                 //.orientation = { 1, 0, 0,0, 1, 0,0, 0, 1 },
522                                 //.orientation = { 0, -1, 0,-1, 0, 0,0, 0, -1 },
523                                 //.orientation = { 0, 1, 0,1, 0, 0,0, 0, -1 },
524                                 .orientation = { 0, 1 ,0, -1 ,0, 0, 0, 0, 1 },
525                 },
526 #endif
527 #if defined (CONFIG_MPU_SENSORS_AK8975)
528                 .compass = {
529 #ifdef CONFIG_MPU_SENSORS_MPU3050_MODULE
530                                 .get_slave_descr = NULL,/*ak5883_get_slave_descr,*/
531 #else
532                                 .get_slave_descr = get_compass_slave_descr,
533 #endif                                          
534                                 .adapt_num = 0, // The i2c bus to which the compass device is. 
535                                 // It can be difference with mpu
536                                 // connected
537                                 //.irq = RK29_PIN0_PA4,
538                                 .bus = EXT_SLAVE_BUS_PRIMARY,
539                                 .address = 0x0d,
540                                 //.orientation = { -1, 0, 0,0, -1, 0,0, 0, 1 },
541                                 //.orientation = { 0, -1, 0,-1, 0, 0,0, 0, -1 },
542                                 //.orientation = { 0, 1, 0,1, 0, 0,0, 0, -1 },
543                                 //.orientation = { 0, -1, 0, 1, 0, 0, 0, 0, 1 },
544                                 .orientation = { 0, 1, 0, -1, 0, 0, 0, 0, 1 },
545                 },
546 };
547 #endif
548 #endif
549 #if defined (CONFIG_BATTERY_BQ27510)
550 #define DC_CHECK_PIN    RK29_PIN4_PA1
551 #define LI_LION_BAT_NUM 2
552 static int bq27510_init_dc_check_pin(void){     
553         if(gpio_request(DC_CHECK_PIN,"dc_check") != 0){      
554                 gpio_free(DC_CHECK_PIN);      
555                 printk("bq27510 init dc check pin request error\n");      
556                 return -EIO;    
557         }       
558         gpio_direction_input(DC_CHECK_PIN);     
559         return 0;
560 }
561
562 struct bq27510_platform_data bq27510_info = {   
563         .init_dc_check_pin = bq27510_init_dc_check_pin, 
564         .dc_check_pin =  DC_CHECK_PIN,          
565         .bat_num = LI_LION_BAT_NUM,
566 };
567 #endif
568
569
570 /*****************************************************************************************
571  * i2c devices
572  * author: kfx@rock-chips.com
573 *****************************************************************************************/
574 static int rk29_i2c0_io_init(void)
575 {
576 #ifdef CONFIG_RK29_I2C0_CONTROLLER
577         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_I2C0_SCL);
578         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_I2C0_SDA);
579 #else
580         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_GPIO2B7);
581         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_GPIO2B6);
582 #endif
583         return 0;
584 }
585
586 static int rk29_i2c1_io_init(void)
587 {
588 #ifdef CONFIG_RK29_I2C1_CONTROLLER
589         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_I2C1_SCL);
590         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_I2C1_SDA);
591 #else
592         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_GPIO1A7);
593         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_GPIO1A6);
594 #endif
595         return 0;
596 }
597 static int rk29_i2c2_io_init(void)
598 {
599 #ifdef CONFIG_RK29_I2C2_CONTROLLER
600         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_I2C2_SCL);
601         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_I2C2_SDA);
602 #else
603         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_GPIO5D4);
604         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_GPIO5D3);
605 #endif
606         return 0;
607 }
608
609 static int rk29_i2c3_io_init(void)
610 {
611 #ifdef CONFIG_RK29_I2C3_CONTROLLER
612         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_I2C3_SCL);
613         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_I2C3_SDA);
614 #else
615         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_GPIO2B5);
616         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_GPIO2B4);
617 #endif
618         return 0;
619 }
620 #ifdef CONFIG_RK29_I2C0_CONTROLLER
621 struct rk29_i2c_platform_data default_i2c0_data = {
622         .bus_num    = 0,
623         .flags      = 0,
624         .slave_addr = 0xff,
625         .scl_rate  = 400*1000,
626         .mode           = I2C_MODE_IRQ,
627         .io_init = rk29_i2c0_io_init,
628 };
629 #else
630 struct i2c_gpio_platform_data default_i2c0_data = {
631        .sda_pin = RK29_PIN2_PB6,
632        .scl_pin = RK29_PIN2_PB7,
633        .udelay = 5, // clk = 500/udelay = 100Khz
634        .timeout = 100,//msecs_to_jiffies(200),
635        .bus_num    = 0,
636        .io_init = rk29_i2c0_io_init,
637 };
638 #endif
639 #ifdef CONFIG_RK29_I2C1_CONTROLLER
640 struct rk29_i2c_platform_data default_i2c1_data = {
641         .bus_num    = 1,
642         .flags      = 0,
643         .slave_addr = 0xff,
644         .scl_rate  = 400*1000,
645         .mode           = I2C_MODE_IRQ,
646         .io_init = rk29_i2c1_io_init,
647 };
648 #else
649 struct i2c_gpio_platform_data default_i2c1_data = {
650        .sda_pin = RK29_PIN1_PA6,
651        .scl_pin = RK29_PIN1_PA7,
652        .udelay = 5, // clk = 500/udelay = 100Khz
653        .timeout = 100,//msecs_to_jiffies(200),
654        .bus_num    = 1,
655        .io_init = rk29_i2c1_io_init,
656 };
657 #endif
658 #ifdef CONFIG_RK29_I2C2_CONTROLLER
659 struct rk29_i2c_platform_data default_i2c2_data = {
660         .bus_num    = 2,
661         .flags      = 0,
662         .slave_addr = 0xff,
663         .scl_rate  = 400*1000,
664         .mode           = I2C_MODE_IRQ,
665         .io_init = rk29_i2c2_io_init,
666 };
667 #else
668 struct i2c_gpio_platform_data default_i2c2_data = {
669        .sda_pin = RK29_PIN5_PD3,
670        .scl_pin = RK29_PIN5_PD4,
671        .udelay = 5, // clk = 500/udelay = 100Khz
672        .timeout = 100,//msecs_to_jiffies(200),
673        .bus_num    = 2,
674        .io_init = rk29_i2c2_io_init,
675 };
676 #endif
677 #ifdef CONFIG_RK29_I2C3_CONTROLLER
678 struct rk29_i2c_platform_data default_i2c3_data = {
679         .bus_num    = 3,
680         .flags      = 0,
681         .slave_addr = 0xff,
682         .scl_rate  = 400*1000,
683         .mode           = I2C_MODE_IRQ,
684         .io_init = rk29_i2c3_io_init,
685 };
686 #else
687 struct i2c_gpio_platform_data default_i2c3_data = {
688        .sda_pin = RK29_PIN5_PB5,
689        .scl_pin = RK29_PIN5_PB4,
690        .udelay = 5, // clk = 500/udelay = 100Khz
691        .timeout = 100,//msecs_to_jiffies(200),
692        .bus_num    = 3,
693        .io_init = rk29_i2c3_io_init,
694 };
695 #endif
696 #ifdef CONFIG_I2C0_RK29
697 static struct i2c_board_info __initdata board_i2c0_devices[] = {
698 #if defined (CONFIG_RK1000_CONTROL)
699         {
700                 .type                   = "rk1000_control",
701                 .addr           = 0x40,
702                 .flags                  = 0,
703         },
704 #endif
705 #if defined (CONFIG_SND_SOC_alc5621)
706         {
707                 .type                   = "ALC5621",
708                 .addr                   = 0x1a,
709                 .flags                  = 0,
710         },
711 #endif
712 #if defined (CONFIG_SND_SOC_alc5631)
713         {
714                 .type                   = "rt5631",
715                 .addr                   = 0x1a,
716                 .flags                  = 0,
717         },
718 #endif
719 #if defined (CONFIG_SND_SOC_RK1000)
720         {
721                 .type                   = "rk1000_i2c_codec",
722                 .addr           = 0x60,
723                 .flags                  = 0,
724         },
725 #endif
726 #if defined (CONFIG_SND_SOC_WM8900)
727         {
728                 .type                   = "wm8900",
729                 .addr           = 0x1A,
730                 .flags                  = 0,
731         },
732 #endif
733 #if defined (CONFIG_BATTERY_STC3100)
734         {
735                 .type                   = "stc3100",
736                 .addr           = 0x70,
737                 .flags                  = 0,
738         },
739 #endif
740 #if defined (CONFIG_BATTERY_BQ27510)
741         {
742                 .type                   = "bq27510",
743                 .addr           = 0x55,
744                 .flags                  = 0,
745                 .platform_data  = &bq27510_info,
746         },
747 #endif
748 #if defined (CONFIG_RTC_HYM8563)
749         {
750                 .type                   = "rtc_hym8563",
751                 .addr           = 0x51,
752                 .flags                  = 0,
753                 .irq            = RK29_PIN0_PA1,
754         },
755 #endif
756 #if defined (CONFIG_GS_MMA8452)
757     {
758       .type           = "gs_mma8452",
759       .addr           = 0x1c,
760       .flags          = 0,
761       .irq            = MMA8452_INT_PIN,
762       .platform_data  = &mma8452_info,
763     },
764 #endif
765 #if defined (CONFIG_COMPASS_AK8973)
766         {
767                 .type                   = "ak8973",
768                 .addr           = 0x1d,
769                 .flags                  = 0,
770                 .irq                    = RK29_PIN0_PA4,
771         },
772 #endif
773 #if defined (CONFIG_COMPASS_AK8975)
774         {
775                 .type                   = "ak8975",
776                 .addr           = 0x0d,
777                 .flags                  = 0,
778                 .irq                    = RK29_PIN0_PA4,
779         },
780 #endif
781 #if defined (CONFIG_MPU_SENSORS_MPU3050) 
782         {
783                 .type                   = "mpu3050",
784                 .addr                   = 0x68,
785                 .flags                  = 0,
786                 .irq                    = RK29_PIN5_PA3,
787                 .platform_data  = &mpu3050_data,
788         },
789 #endif
790 };
791 #endif
792 #if defined (CONFIG_ANX7150)
793 struct hdmi_platform_data anx7150_data  = {
794         //.io_init = anx7150_io_init,
795 };
796 #endif
797
798 #ifdef CONFIG_I2C1_RK29
799 static struct i2c_board_info __initdata board_i2c1_devices[] = {
800 #if defined (CONFIG_RK1000_CONTROL1)
801         {
802                 .type                   = "rk1000_control",
803                 .addr                   = 0x40,
804                 .flags                  = 0,
805         },
806 #endif
807 #if defined (CONFIG_ANX7150)
808     {
809                 .type           = "anx7150",
810         .addr           = 0x39,             //0x39, 0x3d
811         .flags          = 0,
812         .irq            = RK29_PIN1_PD7,
813                 .platform_data  = &anx7150_data,
814     },
815 #endif
816
817 };
818 #endif
819
820 #ifdef CONFIG_I2C2_RK29
821 static struct i2c_board_info __initdata board_i2c2_devices[] = {
822 #if defined (CONFIG_HANNSTAR_P1003)
823     {
824       .type           = "p1003_touch",
825       .addr           = 0x04,
826       .flags          = 0, //I2C_M_NEED_DELAY
827       .irq            = RK29_PIN0_PA2,
828       .platform_data  = &p1003_info,
829       //.udelay           = 100
830     },
831 #endif
832 #if defined (CONFIG_EETI_EGALAX)
833     {
834       .type           = "egalax_i2c",
835       .addr           = 0x04,
836       .flags          = 0,
837       .irq            = RK29_PIN0_PA2,
838       .platform_data  = &eeti_egalax_info,
839     },
840 #endif
841 };
842 #endif
843
844 #ifdef CONFIG_I2C3_RK29
845 static struct i2c_board_info __initdata board_i2c3_devices[] = {
846 };
847 #endif
848
849 /*****************************************************************************************
850  * camera  devices
851  * author: ddl@rock-chips.com
852  *****************************************************************************************/
853 #ifdef CONFIG_VIDEO_RK29 
854 #define CONFIG_SENSOR_POWER_IOCTL_USR      0
855 #define CONFIG_SENSOR_RESET_IOCTL_USR      0
856 #define CONFIG_SENSOR_POWERDOWN_IOCTL_USR      0
857 #define CONFIG_SENSOR_FLASH_IOCTL_USR      0
858
859 #if CONFIG_SENSOR_POWER_IOCTL_USR
860 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
861 {
862     #error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
863 }
864 #endif
865
866 #if CONFIG_SENSOR_RESET_IOCTL_USR
867 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
868 {
869     #error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
870 }
871 #endif
872
873 #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
874 static int sensor_powerdown_usr_cb (struct rk29camera_gpio_res *res,int on)
875 {
876     #error "CONFIG_SENSOR_POWERDOWN_IOCTL_USR is 1, sensor_powerdown_usr_cb function must be writed!!";
877 }
878 #endif
879
880 #if CONFIG_SENSOR_FLASH_IOCTL_USR
881 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
882 {
883     #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
884 }
885 #endif
886
887 static struct rk29camera_platform_ioctl_cb  sensor_ioctl_cb = {
888     #if CONFIG_SENSOR_POWER_IOCTL_USR
889     .sensor_power_cb = sensor_power_usr_cb,
890     #else
891     .sensor_power_cb = NULL,
892     #endif
893
894     #if CONFIG_SENSOR_RESET_IOCTL_USR
895     .sensor_reset_cb = sensor_reset_usr_cb,
896     #else
897     .sensor_reset_cb = NULL,
898     #endif
899
900     #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
901     .sensor_powerdown_cb = sensor_powerdown_usr_cb,
902     #else
903     .sensor_powerdown_cb = NULL,
904     #endif
905
906     #if CONFIG_SENSOR_FLASH_IOCTL_USR
907     .sensor_flash_cb = sensor_flash_usr_cb,
908     #else
909     .sensor_flash_cb = NULL,
910     #endif
911 };
912
913 #include "../../../drivers/media/video/rk29_camera.c"
914 #endif
915 /*****************************************************************************************
916  * backlight  devices
917  * author: nzy@rock-chips.com
918  *****************************************************************************************/
919 #ifdef CONFIG_BACKLIGHT_RK29_BL
920  /*
921  GPIO1B5_PWM0_NAME,       GPIO1L_PWM0
922  GPIO5D2_PWM1_UART1SIRIN_NAME,  GPIO5H_PWM1
923  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME,   GPIO2L_PWM2
924  GPIO1A5_EMMCPWREN_PWM3_NAME,     GPIO1L_PWM3
925  */
926
927 #define PWM_ID            0
928 #define PWM_MUX_NAME      GPIO1B5_PWM0_NAME
929 #define PWM_MUX_MODE      GPIO1L_PWM0
930 #define PWM_MUX_MODE_GPIO GPIO1L_GPIO1B5
931 #define PWM_GPIO RK29_PIN1_PB5
932 #define PWM_EFFECT_VALUE  1
933
934 #define LCD_DISP_ON_PIN
935
936 #ifdef  LCD_DISP_ON_PIN
937 //#define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
938 //#define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
939
940 #define BL_EN_PIN         RK29_PIN6_PD0
941 #define BL_EN_VALUE       GPIO_HIGH
942 #endif
943 static int rk29_backlight_io_init(void)
944 {
945     int ret = 0;
946
947     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
948         #ifdef  LCD_DISP_ON_PIN
949    // rk29_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
950
951     ret = gpio_request(BL_EN_PIN, NULL);
952     if(ret != 0)
953     {
954         gpio_free(BL_EN_PIN);
955     }
956
957     gpio_direction_output(BL_EN_PIN, 0);
958     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
959         #endif
960     return ret;
961 }
962
963 static int rk29_backlight_io_deinit(void)
964 {
965     int ret = 0;
966     #ifdef  LCD_DISP_ON_PIN
967     gpio_free(BL_EN_PIN);
968     #endif
969     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
970     return ret;
971 }
972
973 static int rk29_backlight_pwm_suspend(void)
974 {
975         int ret = 0;
976         rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
977         if (gpio_request(PWM_GPIO, NULL)) {
978                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
979                 return -1;
980         }
981         gpio_direction_output(PWM_GPIO, GPIO_LOW);
982    #ifdef  LCD_DISP_ON_PIN
983     gpio_direction_output(BL_EN_PIN, 0);
984     gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
985    #endif
986         return ret;
987 }
988
989 static int rk29_backlight_pwm_resume(void)
990 {
991         gpio_free(PWM_GPIO);
992         rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
993
994     #ifdef  LCD_DISP_ON_PIN
995     msleep(30);
996     gpio_direction_output(BL_EN_PIN, 1);
997     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
998     #endif
999         return 0;
1000 }
1001
1002 struct rk29_bl_info rk29_bl_info = {
1003     .pwm_id   = PWM_ID,
1004     .bl_ref   = PWM_EFFECT_VALUE,
1005     .io_init   = rk29_backlight_io_init,
1006     .io_deinit = rk29_backlight_io_deinit,
1007     .pwm_suspend = rk29_backlight_pwm_suspend,
1008     .pwm_resume = rk29_backlight_pwm_resume,
1009 };
1010 #endif
1011 /*****************************************************************************************
1012 * pwm voltage regulator devices
1013 ******************************************************************************************/
1014 #if defined (CONFIG_RK29_PWM_REGULATOR)
1015
1016 #define REGULATOR_PWM_ID                                        2
1017 #define REGULATOR_PWM_MUX_NAME                  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME
1018 #define REGULATOR_PWM_MUX_MODE                                          GPIO2L_PWM2
1019 #define REGULATOR_PWM_MUX_MODE_GPIO                             GPIO2L_GPIO2A3
1020 #define REGULATOR_PWM_GPIO                              RK29_PIN2_PA3
1021
1022 static struct regulator_consumer_supply pwm_consumers[] = {
1023         {
1024                 .supply = "vcore",
1025         }
1026 };
1027
1028 static struct regulator_init_data rk29_pwm_regulator_data = {
1029         .constraints = {
1030                 .name = "PWM2",
1031                 .min_uV =  950000,
1032                 .max_uV = 1400000,
1033                 .apply_uV = 1,
1034                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1035         },
1036         .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
1037         .consumer_supplies = pwm_consumers,
1038 };
1039
1040 static struct pwm_platform_data rk29_regulator_pwm_platform_data = {
1041         .pwm_id = REGULATOR_PWM_ID,
1042         .pwm_gpio = REGULATOR_PWM_GPIO,
1043         //.pwm_iomux_name[] = REGULATOR_PWM_MUX_NAME;
1044         .pwm_iomux_name = REGULATOR_PWM_MUX_NAME,
1045         .pwm_iomux_pwm = REGULATOR_PWM_MUX_MODE,
1046         .pwm_iomux_gpio = REGULATOR_PWM_MUX_MODE_GPIO,
1047         .init_data  = &rk29_pwm_regulator_data,
1048 };
1049
1050 static struct platform_device rk29_device_pwm_regulator = {
1051         .name = "pwm-voltage-regulator",
1052         .id   = -1,
1053         .dev  = {
1054                 .platform_data = &rk29_regulator_pwm_platform_data,
1055         },
1056 };
1057
1058 #endif
1059
1060 /*****************************************************************************************
1061  * SDMMC devices
1062 *****************************************************************************************/
1063 #ifdef CONFIG_SDMMC0_RK29
1064 static int rk29_sdmmc0_cfg_gpio(void)
1065 {
1066         rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
1067         rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
1068         rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
1069         rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
1070         rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
1071         rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
1072
1073 #ifdef CONFIG_SDMMC_RK29_OLD    
1074         rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
1075 #else
1076         rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_SDMMC0_DETECT_N);//Modifyed by xbw.
1077 #endif
1078
1079         rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5);   ///GPIO5H_SDMMC0_PWR_EN);  ///GPIO5H_GPIO5D5);
1080         gpio_request(RK29_PIN5_PD5,"sdmmc");
1081 #if 0
1082         gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
1083         mdelay(100);
1084         gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
1085 #else
1086         gpio_direction_output(RK29_PIN5_PD5,GPIO_LOW);
1087 #endif
1088         return 0;
1089 }
1090
1091 #define CONFIG_SDMMC0_USE_DMA
1092 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
1093         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
1094                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
1095                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
1096         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1097         .io_init = rk29_sdmmc0_cfg_gpio,
1098         .dma_name = "sd_mmc",
1099 #ifdef CONFIG_SDMMC0_USE_DMA
1100         .use_dma  = 1,
1101 #else
1102         .use_dma = 0,
1103 #endif
1104         .detect_irq = RK29_PIN2_PA2, // INVALID_GPIO
1105         .enable_sd_wakeup = 0,
1106 };
1107 #endif
1108 #ifdef CONFIG_SDMMC1_RK29
1109 #define CONFIG_SDMMC1_USE_DMA
1110 static int rk29_sdmmc1_cfg_gpio(void)
1111 {
1112         rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
1113         rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
1114         rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
1115         rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
1116         rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
1117         rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
1118         //rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_SDMMC1_DETECT_N);
1119         return 0;
1120 }
1121
1122 #ifdef CONFIG_WIFI_CONTROL_FUNC
1123 static int rk29sdk_wifi_status(struct device *dev);
1124 static int rk29sdk_wifi_status_register(void (*callback)(int card_presend, void *dev_id), void *dev_id);
1125 #endif
1126
1127 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK29_PIN1_PD6
1128
1129 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
1130         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
1131                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
1132                                            MMC_VDD_32_33|MMC_VDD_33_34),
1133         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
1134                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1135         .io_init = rk29_sdmmc1_cfg_gpio,
1136         .dma_name = "sdio",
1137 #ifdef CONFIG_SDMMC1_USE_DMA
1138         .use_dma  = 1,
1139 #else
1140         .use_dma = 0,
1141 #endif
1142 #ifdef CONFIG_WIFI_CONTROL_FUNC
1143         .status = rk29sdk_wifi_status,
1144         .register_status_notify = rk29sdk_wifi_status_register,
1145 #endif
1146 #if 0
1147         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
1148 #endif
1149 };
1150 #endif
1151
1152 #ifdef CONFIG_WIFI_CONTROL_FUNC
1153 #define RK29SDK_WIFI_BT_GPIO_POWER_N       RK29_PIN5_PD6
1154 #define RK29SDK_WIFI_GPIO_RESET_N          RK29_PIN6_PC0
1155 #define RK29SDK_BT_GPIO_RESET_N            RK29_PIN6_PC4
1156
1157 static int rk29sdk_wifi_cd = 0;   /* wifi virtual 'card detect' status */
1158 static void (*wifi_status_cb)(int card_present, void *dev_id);
1159 static void *wifi_status_cb_devid;
1160 int rk29sdk_wifi_power_state = 0;
1161 int rk29sdk_bt_power_state = 0;
1162
1163 static int rk29sdk_wifi_status(struct device *dev)
1164 {
1165         return rk29sdk_wifi_cd;
1166 }
1167
1168 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
1169 {
1170         if(wifi_status_cb)
1171                 return -EAGAIN;
1172         wifi_status_cb = callback;
1173         wifi_status_cb_devid = dev_id;
1174         return 0;
1175 }
1176
1177 static int rk29sdk_wifi_bt_gpio_control_init(void)
1178 {
1179     if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
1180            pr_info("%s: request wifi_bt power gpio failed\n", __func__);
1181            return -1;
1182     }
1183
1184     if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
1185            pr_info("%s: request wifi reset gpio failed\n", __func__);
1186            gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
1187            return -1;
1188     }
1189
1190     if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
1191           pr_info("%s: request bt reset gpio failed\n", __func__);
1192           gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
1193           return -1;
1194     }
1195
1196     gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1197     gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N,    GPIO_LOW);
1198     gpio_direction_output(RK29SDK_BT_GPIO_RESET_N,      GPIO_LOW);
1199
1200     pr_info("%s: init finished\n",__func__);
1201
1202     return 0;
1203 }
1204
1205 static int rk29sdk_wifi_power(int on)
1206 {
1207         pr_info("%s: %d\n", __func__, on);
1208         if (on){
1209                 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
1210                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
1211                 mdelay(100);
1212                 pr_info("wifi turn on power\n");
1213         }else{
1214                 if (!rk29sdk_bt_power_state){
1215                         gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1216                         mdelay(100);
1217                         pr_info("wifi shut off power\n");
1218                 }else
1219                 {
1220                         pr_info("wifi shouldn't shut off power, bt is using it!\n");
1221                 }
1222                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1223
1224         }
1225
1226         rk29sdk_wifi_power_state = on;
1227         return 0;
1228 }
1229
1230 static int rk29sdk_wifi_reset_state;
1231 static int rk29sdk_wifi_reset(int on)
1232 {
1233         pr_info("%s: %d\n", __func__, on);
1234         gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
1235         mdelay(100);
1236         rk29sdk_wifi_reset_state = on;
1237         return 0;
1238 }
1239
1240 int rk29sdk_wifi_set_carddetect(int val)
1241 {
1242         pr_info("%s:%d\n", __func__, val);
1243         rk29sdk_wifi_cd = val;
1244         if (wifi_status_cb){
1245                 wifi_status_cb(val, wifi_status_cb_devid);
1246         }else {
1247                 pr_warning("%s, nobody to notify\n", __func__);
1248         }
1249         return 0;
1250 }
1251 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
1252
1253 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
1254         {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
1255         {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
1256         {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
1257         {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
1258 };
1259
1260 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
1261 {
1262         if (section == PREALLOC_WLAN_SEC_NUM)
1263                 return wlan_static_skb;
1264
1265         if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
1266                 return NULL;
1267
1268         if (wifi_mem_array[section].size < size)
1269                 return NULL;
1270
1271         return wifi_mem_array[section].mem_ptr;
1272 }
1273
1274 int __init rk29sdk_init_wifi_mem(void)
1275 {
1276         int i;
1277         int j;
1278
1279         for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
1280                 wlan_static_skb[i] = dev_alloc_skb(
1281                                 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
1282
1283                 if (!wlan_static_skb[i])
1284                         goto err_skb_alloc;
1285         }
1286
1287         for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
1288                 wifi_mem_array[i].mem_ptr =
1289                                 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
1290
1291                 if (!wifi_mem_array[i].mem_ptr)
1292                         goto err_mem_alloc;
1293         }
1294         return 0;
1295
1296 err_mem_alloc:
1297         pr_err("Failed to mem_alloc for WLAN\n");
1298         for (j = 0 ; j < i ; j++)
1299                kfree(wifi_mem_array[j].mem_ptr);
1300
1301         i = WLAN_SKB_BUF_NUM;
1302
1303 err_skb_alloc:
1304         pr_err("Failed to skb_alloc for WLAN\n");
1305         for (j = 0 ; j < i ; j++)
1306                 dev_kfree_skb(wlan_static_skb[j]);
1307
1308         return -ENOMEM;
1309 }
1310
1311 static struct wifi_platform_data rk29sdk_wifi_control = {
1312         .set_power = rk29sdk_wifi_power,
1313         .set_reset = rk29sdk_wifi_reset,
1314         .set_carddetect = rk29sdk_wifi_set_carddetect,
1315         .mem_prealloc   = rk29sdk_mem_prealloc,
1316 };
1317 static struct platform_device rk29sdk_wifi_device = {
1318         .name = "bcm4329_wlan",
1319         .id = 1,
1320         .dev = {
1321                 .platform_data = &rk29sdk_wifi_control,
1322          },
1323 };
1324 #endif
1325
1326
1327 /* bluetooth rfkill device */
1328 static struct platform_device rk29sdk_rfkill = {
1329         .name = "rk29sdk_rfkill",
1330         .id = -1,
1331 };
1332
1333
1334 #ifdef CONFIG_VIVANTE
1335 #define GPU_HIGH_CLOCK        552
1336 #define GPU_LOW_CLOCK         (periph_pll_default / 1000000) /* same as general pll clock rate below */
1337 static struct resource resources_gpu[] = {
1338     [0] = {
1339                 .name   = "gpu_irq",
1340         .start  = IRQ_GPU,
1341         .end    = IRQ_GPU,
1342         .flags  = IORESOURCE_IRQ,
1343     },
1344     [1] = {
1345                 .name   = "gpu_base",
1346         .start  = RK29_GPU_PHYS,
1347         .end    = RK29_GPU_PHYS + RK29_GPU_SIZE - 1,
1348         .flags  = IORESOURCE_MEM,
1349     },
1350     [2] = {
1351                 .name   = "gpu_mem",
1352         .start  = PMEM_GPU_BASE,
1353         .end    = PMEM_GPU_BASE + PMEM_GPU_SIZE - 1,
1354         .flags  = IORESOURCE_MEM,
1355     },
1356     [3] = {
1357                 .name   = "gpu_clk",
1358         .start  = GPU_LOW_CLOCK,
1359         .end    = GPU_HIGH_CLOCK,
1360         .flags  = IORESOURCE_IO,
1361     },
1362 };
1363 static struct platform_device rk29_device_gpu = {
1364     .name             = "galcore",
1365     .id               = 0,
1366     .num_resources    = ARRAY_SIZE(resources_gpu),
1367     .resource         = resources_gpu,
1368 };
1369 #endif
1370
1371 #ifdef CONFIG_KEYS_RK29
1372 extern struct rk29_keys_platform_data rk29_keys_pdata;
1373 static struct platform_device rk29_device_keys = {
1374         .name           = "rk29-keypad",
1375         .id             = -1,
1376         .dev            = {
1377                 .platform_data  = &rk29_keys_pdata,
1378         },
1379 };
1380 #endif
1381
1382 static void __init rk29_board_iomux_init(void)
1383 {
1384         #ifdef CONFIG_RK29_PWM_REGULATOR
1385         rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
1386         #endif
1387 }
1388
1389 static struct platform_device *devices[] __initdata = {
1390
1391 #ifdef CONFIG_RK29_WATCHDOG
1392         &rk29_device_wdt,
1393 #endif
1394
1395 #ifdef CONFIG_UART1_RK29
1396         &rk29_device_uart1,
1397 #endif
1398 #ifdef CONFIG_UART0_RK29
1399         &rk29_device_uart0,
1400 #endif
1401 #ifdef CONFIG_UART2_RK29
1402         &rk29_device_uart2,
1403 #endif
1404 #ifdef CONFIG_UART3_RK29
1405         &rk29_device_uart3,
1406 #endif
1407
1408 #ifdef CONFIG_RK29_PWM_REGULATOR
1409         &rk29_device_pwm_regulator,
1410 #endif
1411 #ifdef CONFIG_SPIM0_RK29
1412     &rk29xx_device_spi0m,
1413 #endif
1414 #ifdef CONFIG_SPIM1_RK29
1415     &rk29xx_device_spi1m,
1416 #endif
1417 #ifdef CONFIG_ADC_RK29
1418         &rk29_device_adc,
1419 #endif
1420 #ifdef CONFIG_I2C0_RK29
1421         &rk29_device_i2c0,
1422 #endif
1423 #ifdef CONFIG_I2C1_RK29
1424         &rk29_device_i2c1,
1425 #endif
1426 #ifdef CONFIG_I2C2_RK29
1427         &rk29_device_i2c2,
1428 #endif
1429 #ifdef CONFIG_I2C3_RK29
1430         &rk29_device_i2c3,
1431 #endif
1432
1433 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
1434         &rk29_device_iis_2ch,
1435 #endif
1436 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
1437         &rk29_device_iis_8ch,
1438 #endif
1439
1440 #ifdef CONFIG_KEYS_RK29
1441         &rk29_device_keys,
1442 #endif
1443 #ifdef CONFIG_SDMMC0_RK29
1444         &rk29_device_sdmmc0,
1445 #endif
1446 #ifdef CONFIG_SDMMC1_RK29
1447         &rk29_device_sdmmc1,
1448 #endif
1449
1450 #ifdef CONFIG_MTD_NAND_RK29XX
1451         &rk29xx_device_nand,
1452 #endif
1453
1454 #ifdef CONFIG_WIFI_CONTROL_FUNC
1455         &rk29sdk_wifi_device,
1456 #endif
1457
1458 #ifdef CONFIG_BT
1459         &rk29sdk_rfkill,
1460 #endif
1461
1462 #ifdef CONFIG_MTD_NAND_RK29
1463         &rk29_device_nand,
1464 #endif
1465
1466 #ifdef CONFIG_FB_RK29
1467         &rk29_device_fb,
1468         &rk29_device_dma_cpy,
1469 #endif
1470 #ifdef CONFIG_BACKLIGHT_RK29_BL
1471         &rk29_device_backlight,
1472 #endif
1473 #ifdef CONFIG_RK29_VMAC
1474         &rk29_device_vmac,
1475 #endif
1476 #ifdef CONFIG_VIVANTE
1477         &rk29_device_gpu,
1478 #endif
1479 #ifdef CONFIG_VIDEO_RK29
1480         &rk29_device_camera,      /* ddl@rock-chips.com : camera support  */
1481         #if (CONFIG_SENSOR_IIC_ADDR_0 != 0x00)
1482         &rk29_soc_camera_pdrv_0,
1483         #endif
1484         &rk29_soc_camera_pdrv_1,
1485         &android_pmem_cam_device,
1486 #endif
1487         &android_pmem_device,
1488         &rk29_vpu_mem_device,
1489 #ifdef CONFIG_USB20_OTG
1490         &rk29_device_usb20_otg,
1491 #endif
1492 #ifdef CONFIG_USB20_HOST
1493         &rk29_device_usb20_host,
1494 #endif
1495 #ifdef CONFIG_USB11_HOST
1496         &rk29_device_usb11_host,
1497 #endif
1498 #ifdef CONFIG_USB_ANDROID
1499         &android_usb_device,
1500         &usb_mass_storage_device,
1501 #endif
1502 #ifdef CONFIG_RK29_IPP
1503         &rk29_device_ipp,
1504 #endif
1505 #ifdef CONFIG_VIDEO_RK29XX_VOUT
1506         &rk29_v4l2_output_devce,
1507 #endif
1508 };
1509
1510 /*****************************************************************************************
1511  * spi devices
1512  * author: cmc@rock-chips.com
1513  *****************************************************************************************/
1514 static int rk29_vmac_register_set(void)
1515 {
1516         //config rk29 vmac as rmii, 100MHz
1517         u32 value= readl(RK29_GRF_BASE + 0xbc);
1518         value = (value & 0xfff7ff) | (0x400);
1519         writel(value, RK29_GRF_BASE + 0xbc);
1520         return 0;
1521 }
1522
1523 static int rk29_rmii_io_init(void)
1524 {
1525         int err;
1526
1527         //phy power gpio
1528         err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
1529         if (err) {
1530                 gpio_free(RK29_PIN6_PB0);
1531                 printk("-------request RK29_PIN6_PB0 fail--------\n");
1532                 return -1;
1533         }
1534         //phy power down
1535         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1536         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1537
1538         return 0;
1539 }
1540
1541 static int rk29_rmii_io_deinit(void)
1542 {
1543         //phy power down
1544         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1545         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1546         //free
1547         gpio_free(RK29_PIN6_PB0);
1548         return 0;
1549 }
1550
1551 static int rk29_rmii_power_control(int enable)
1552 {
1553         if (enable) {
1554                 //enable phy power
1555                 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
1556                 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
1557         }
1558         else {
1559                 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1560                 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1561         }
1562         return 0;
1563 }
1564
1565 struct rk29_vmac_platform_data rk29_vmac_pdata = {
1566         .vmac_register_set = rk29_vmac_register_set,
1567         .rmii_io_init = rk29_rmii_io_init,
1568         .rmii_io_deinit = rk29_rmii_io_deinit,
1569         .rmii_power_control = rk29_rmii_power_control,
1570 };
1571
1572 /*****************************************************************************************
1573  * spi devices
1574  * author: cmc@rock-chips.com
1575  *****************************************************************************************/
1576 #define SPI_CHIPSELECT_NUM 2
1577 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
1578     {
1579                 .name = "spi0 cs0",
1580                 .cs_gpio = RK29_PIN2_PC1,
1581                 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
1582                 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
1583         },
1584         {
1585                 .name = "spi0 cs1",
1586                 .cs_gpio = RK29_PIN1_PA4,
1587                 .cs_iomux_name = GPIO1A4_EMMCWRITEPRT_SPI0CS1_NAME,//if no iomux,set it NULL
1588                 .cs_iomux_mode = GPIO1L_SPI0_CSN1,
1589         }
1590 };
1591
1592 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
1593     {
1594                 .name = "spi1 cs0",
1595                 .cs_gpio = RK29_PIN2_PC5,
1596                 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
1597                 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
1598         },
1599         {
1600                 .name = "spi1 cs1",
1601                 .cs_gpio = RK29_PIN1_PA3,
1602                 .cs_iomux_name = GPIO1A3_EMMCDETECTN_SPI1CS1_NAME,//if no iomux,set it NULL
1603                 .cs_iomux_mode = GPIO1L_SPI1_CSN1,
1604         }
1605 };
1606
1607 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
1608 {
1609 #if 1
1610         int i;
1611         if (cs_gpios) {
1612                 for (i=0; i<cs_num; i++) {
1613                         rk29_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
1614                 }
1615         }
1616 #endif
1617         return 0;
1618 }
1619
1620 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
1621 {
1622         return 0;
1623 }
1624
1625 static int spi_io_fix_leakage_bug(void)
1626 {
1627 #if 0
1628         gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
1629 #endif
1630         return 0;
1631 }
1632
1633 static int spi_io_resume_leakage_bug(void)
1634 {
1635 #if 0
1636         gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
1637 #endif
1638         return 0;
1639 }
1640
1641 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
1642         .num_chipselect = SPI_CHIPSELECT_NUM,
1643         .chipselect_gpios = rk29xx_spi0_cs_gpios,
1644         .io_init = spi_io_init,
1645         .io_deinit = spi_io_deinit,
1646         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1647         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1648 };
1649
1650 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
1651         .num_chipselect = SPI_CHIPSELECT_NUM,
1652         .chipselect_gpios = rk29xx_spi1_cs_gpios,
1653         .io_init = spi_io_init,
1654         .io_deinit = spi_io_deinit,
1655         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1656         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1657 };
1658
1659 /*****************************************************************************************
1660  * xpt2046 touch panel
1661  * author: cmc@rock-chips.com
1662  *****************************************************************************************/
1663 #define XPT2046_GPIO_INT           RK29_PIN0_PA3
1664 #define DEBOUNCE_REPTIME  3
1665
1666 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI)
1667 static struct xpt2046_platform_data xpt2046_info = {
1668         .model                  = 2046,
1669         .keep_vref_on   = 1,
1670         .swap_xy                = 0,
1671         .x_min                  = 0,
1672         .x_max                  = 320,
1673         .y_min                  = 0,
1674         .y_max                  = 480,
1675         .debounce_max           = 7,
1676         .debounce_rep           = DEBOUNCE_REPTIME,
1677         .debounce_tol           = 20,
1678         .gpio_pendown           = XPT2046_GPIO_INT,
1679         .penirq_recheck_delay_usecs = 1,
1680 };
1681 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)
1682 static struct xpt2046_platform_data xpt2046_info = {
1683         .model                  = 2046,
1684         .keep_vref_on   = 1,
1685         .swap_xy                = 0,
1686         .x_min                  = 0,
1687         .x_max                  = 320,
1688         .y_min                  = 0,
1689         .y_max                  = 480,
1690         .debounce_max           = 7,
1691         .debounce_rep           = DEBOUNCE_REPTIME,
1692         .debounce_tol           = 20,
1693         .gpio_pendown           = XPT2046_GPIO_INT,
1694         .penirq_recheck_delay_usecs = 1,
1695 };
1696 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
1697 static struct xpt2046_platform_data xpt2046_info = {
1698         .model                  = 2046,
1699         .keep_vref_on   = 1,
1700         .swap_xy                = 1,
1701         .x_min                  = 0,
1702         .x_max                  = 800,
1703         .y_min                  = 0,
1704         .y_max                  = 480,
1705         .debounce_max           = 7,
1706         .debounce_rep           = DEBOUNCE_REPTIME,
1707         .debounce_tol           = 20,
1708         .gpio_pendown           = XPT2046_GPIO_INT,
1709
1710         .penirq_recheck_delay_usecs = 1,
1711 };
1712 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1713 static struct xpt2046_platform_data xpt2046_info = {
1714         .model                  = 2046,
1715         .keep_vref_on   = 1,
1716         .swap_xy                = 1,
1717         .x_min                  = 0,
1718         .x_max                  = 800,
1719         .y_min                  = 0,
1720         .y_max                  = 480,
1721         .debounce_max           = 7,
1722         .debounce_rep           = DEBOUNCE_REPTIME,
1723         .debounce_tol           = 20,
1724         .gpio_pendown           = XPT2046_GPIO_INT,
1725
1726         .penirq_recheck_delay_usecs = 1,
1727 };
1728 #endif
1729
1730 static struct spi_board_info board_spi_devices[] = {
1731 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\
1732     ||defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1733         {
1734                 .modalias       = "xpt2046_ts",
1735                 .chip_select    = 0,
1736                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
1737                 .bus_num        = 0,
1738                 .irq = XPT2046_GPIO_INT,
1739                 .platform_data = &xpt2046_info,
1740         },
1741 #endif
1742 };
1743
1744
1745 static void __init rk29_gic_init_irq(void)
1746 {
1747         gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
1748         gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
1749 }
1750
1751 static void __init machine_rk29_init_irq(void)
1752 {
1753         rk29_gic_init_irq();
1754         rk29_gpio_init();
1755 }
1756
1757 static struct cpufreq_frequency_table freq_table[] = {
1758         { .index = 1200000, .frequency =  408000 },
1759         { .index = 1200000, .frequency =  816000 },
1760         { .index = 1300000, .frequency = 1008000 },
1761         { .frequency = CPUFREQ_TABLE_END },
1762 };
1763
1764 static void __init machine_rk29_board_init(void)
1765 {
1766         rk29_board_iomux_init();
1767
1768         board_power_init();
1769         board_update_cpufreq_table(freq_table);
1770
1771                 platform_add_devices(devices, ARRAY_SIZE(devices));
1772 #ifdef CONFIG_I2C0_RK29
1773         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
1774                         ARRAY_SIZE(board_i2c0_devices));
1775 #endif
1776 #ifdef CONFIG_I2C1_RK29
1777         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
1778                         ARRAY_SIZE(board_i2c1_devices));
1779 #endif
1780 #ifdef CONFIG_I2C2_RK29
1781         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
1782                         ARRAY_SIZE(board_i2c2_devices));
1783 #endif
1784 #ifdef CONFIG_I2C3_RK29
1785         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
1786                         ARRAY_SIZE(board_i2c3_devices));
1787 #endif
1788
1789         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1790         
1791 #ifdef CONFIG_WIFI_CONTROL_FUNC
1792         rk29sdk_wifi_bt_gpio_control_init();
1793         rk29sdk_init_wifi_mem();
1794 #endif
1795
1796         board_usb_detect_init(RK29_PIN0_PA0);
1797 }
1798
1799 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
1800                                         char **cmdline, struct meminfo *mi)
1801 {
1802         mi->nr_banks = 1;
1803         mi->bank[0].start = RK29_SDRAM_PHYS;
1804         mi->bank[0].node = PHYS_TO_NID(RK29_SDRAM_PHYS);
1805         mi->bank[0].size = LINUX_SIZE;
1806 #if SDRAM_SIZE > SZ_512M
1807         mi->nr_banks = 2;
1808         mi->bank[1].start = RK29_SDRAM_PHYS + SZ_512M;
1809         mi->bank[1].size = SDRAM_SIZE - SZ_512M;
1810 #endif
1811 }
1812
1813 static void __init machine_rk29_mapio(void)
1814 {
1815         rk29_map_common_io();
1816         rk29_setup_early_printk();
1817         rk29_sram_init();
1818         rk29_clock_init(periph_pll_default);
1819         rk29_iomux_init();
1820         ddr_init(DDR_TYPE, DDR_FREQ);
1821 }
1822
1823 MACHINE_START(RK29, "RK29board")
1824         /* UART for LL DEBUG */
1825         .phys_io        = RK29_UART1_PHYS & 0xfff00000,
1826         .io_pg_offst    = ((RK29_UART1_BASE) >> 18) & 0xfffc,
1827         .boot_params    = RK29_SDRAM_PHYS + 0x88000,
1828         .fixup          = machine_rk29_fixup,
1829         .map_io         = machine_rk29_mapio,
1830         .init_irq       = machine_rk29_init_irq,
1831         .init_machine   = machine_rk29_board_init,
1832         .timer          = &rk29_timer,
1833 MACHINE_END