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