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