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