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