1 /* arch/arm/mach-rk29/board-rk29.c
3 * Copyright (C) 2010 ROCKCHIP, Inc.
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.
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.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.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>
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>
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>
47 #include <linux/regulator/rk29-pwm-regulator.h>
48 #include <linux/regulator/machine.h>
50 #include <linux/mtd/nand.h>
51 #include <linux/mtd/partitions.h>
54 #include "../../../drivers/input/touchscreen/xpt2046_cbn_ts.h"
57 /* Set memory size of pmem */
58 #ifdef CONFIG_RK29_MEM_SIZE_M
59 #define SDRAM_SIZE (CONFIG_RK29_MEM_SIZE_M * SZ_1M)
61 #define SDRAM_SIZE SZ_512M
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
70 #define MEM_CAMIPP_SIZE 0
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
76 #define MEM_FBIPP_SIZE 0
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)
87 #define PREALLOC_WLAN_SEC_NUM 4
88 #define PREALLOC_WLAN_BUF_NUM 160
89 #define PREALLOC_WLAN_SECTION_HEADER 24
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)
96 #define WLAN_SKB_BUF_NUM 16
98 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
100 struct wifi_mem_prealloc {
105 extern struct sys_timer rk29_timer;
107 static int rk29_nand_io_init(void)
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 */
116 .io_init = rk29_nand_io_init,
119 #ifdef CONFIG_FB_RK29
120 /*****************************************************************************************
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 *****************************************************************************************/
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
138 #define FB_DISPLAY_ON_VALUE GPIO_HIGH
139 #define FB_LCD_STANDBY_VALUE GPIO_HIGH
142 static int rk29_lcd_io_init(void)
148 static int rk29_lcd_io_deinit(void)
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,
163 static int rk29_fb_io_init(struct rk29_fb_setting_info *fb_setting)
166 if(fb_setting->mcu_fmk_en && (FB_MCU_FMK_PIN != INVALID_GPIO))
168 ret = gpio_request(FB_MCU_FMK_PIN, NULL);
171 gpio_free(FB_MCU_FMK_PIN);
172 printk(">>>>>> FB_MCU_FMK_PIN gpio_request err \n ");
174 gpio_direction_input(FB_MCU_FMK_PIN);
176 if(fb_setting->disp_on_en && (FB_DISPLAY_ON_PIN != INVALID_GPIO))
178 ret = gpio_request(FB_DISPLAY_ON_PIN, NULL);
181 gpio_free(FB_DISPLAY_ON_PIN);
182 printk(">>>>>> FB_DISPLAY_ON_PIN gpio_request err \n ");
186 if(fb_setting->disp_on_en && (FB_LCD_STANDBY_PIN != INVALID_GPIO))
188 ret = gpio_request(FB_LCD_STANDBY_PIN, NULL);
191 gpio_free(FB_LCD_STANDBY_PIN);
192 printk(">>>>>> FB_LCD_STANDBY_PIN gpio_request err \n ");
196 if(FB_LCD_CABC_EN_PIN != INVALID_GPIO)
198 ret = gpio_request(FB_LCD_CABC_EN_PIN, NULL);
201 gpio_free(FB_LCD_CABC_EN_PIN);
202 printk(">>>>>> FB_LCD_CABC_EN_PIN gpio_request err \n ");
204 gpio_direction_output(FB_LCD_CABC_EN_PIN, 0);
205 gpio_set_value(FB_LCD_CABC_EN_PIN, GPIO_LOW);
211 static struct rk29fb_info rk29_fb_info = {
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,
222 /* rk29 fb resource */
223 static struct resource rk29_fb_resource[] = {
226 .start = RK29_LCDC_PHYS,
227 .end = RK29_LCDC_PHYS + RK29_LCDC_SIZE - 1,
228 .flags = IORESOURCE_MEM,
234 .flags = IORESOURCE_IRQ,
238 .start = MEM_FB_BASE,
239 .end = MEM_FB_BASE + MEM_FB_SIZE - 1,
240 .flags = IORESOURCE_MEM,
242 #ifdef CONFIG_FB_WORK_IPP
244 .name = "win1 ipp buf",
245 .start = MEM_FBIPP_BASE,
246 .end = MEM_FBIPP_BASE + MEM_FBIPP_SIZE - 1,
247 .flags = IORESOURCE_MEM,
253 struct platform_device rk29_device_fb = {
256 .num_resources = ARRAY_SIZE(rk29_fb_resource),
257 .resource = rk29_fb_resource,
259 .platform_data = &rk29_fb_info,
263 struct platform_device rk29_device_dma_cpy = {
264 .name = "dma_memcpy",
271 static struct android_pmem_platform_data android_pmem_pdata = {
273 .start = PMEM_UI_BASE,
274 .size = PMEM_UI_SIZE,
279 static struct platform_device android_pmem_device = {
280 .name = "android_pmem",
283 .platform_data = &android_pmem_pdata,
288 static struct android_pmem_platform_data android_pmem_cam_pdata = {
290 .start = PMEM_CAM_BASE,
291 .size = PMEM_CAM_SIZE,
296 static struct platform_device android_pmem_cam_device = {
297 .name = "android_pmem",
300 .platform_data = &android_pmem_cam_pdata,
305 static struct vpu_mem_platform_data vpu_mem_pdata = {
307 .start = PMEM_VPU_BASE,
308 .size = PMEM_VPU_SIZE,
312 static struct platform_device rk29_vpu_mem_device = {
316 .platform_data = &vpu_mem_pdata,
320 static struct platform_device rk29_v4l2_output_devce = {
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
329 int p1003_init_platform_hw(void)
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");
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");
342 gpio_pull_updown(TOUCH_INT_PIN, 1);
343 gpio_direction_output(TOUCH_RESET_PIN, 0);
345 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
347 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
353 struct p1003_platform_data p1003_info = {
355 .init_platform_hw= p1003_init_platform_hw,
359 #if defined (CONFIG_EETI_EGALAX)
360 #define TOUCH_RESET_PIN RK29_PIN6_PC3
361 #define TOUCH_INT_PIN RK29_PIN0_PA2
363 static int EETI_EGALAX_init_platform_hw(void)
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");
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");
376 gpio_pull_updown(TOUCH_INT_PIN, 1);
377 gpio_direction_output(TOUCH_RESET_PIN, 0);
379 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
381 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
387 static struct eeti_egalax_platform_data eeti_egalax_info = {
389 .init_platform_hw= EETI_EGALAX_init_platform_hw,
394 #if defined (CONFIG_GS_MMA8452)
395 #define MMA8452_INT_PIN RK29_PIN0_PA3
397 static int mma8452_init_platform_hw(void)
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");
405 gpio_pull_updown(MMA8452_INT_PIN, 1);
410 static struct mma8452_platform_data mma8452_info = {
413 .init_platform_hw= mma8452_init_platform_hw,
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");
427 gpio_direction_input(DC_CHECK_PIN);
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,
439 /*****************************************************************************************
441 * author: kfx@rock-chips.com
442 *****************************************************************************************/
443 static int rk29_i2c0_io_init(void)
445 rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_I2C0_SCL);
446 rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_I2C0_SDA);
450 static int rk29_i2c1_io_init(void)
452 rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_I2C1_SCL);
453 rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_I2C1_SDA);
456 static int rk29_i2c2_io_init(void)
458 rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_I2C2_SCL);
459 rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_I2C2_SDA);
463 static int rk29_i2c3_io_init(void)
465 rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_I2C3_SCL);
466 rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_I2C3_SDA);
470 struct rk29_i2c_platform_data default_i2c0_data = {
474 .scl_rate = 400*1000,
475 .mode = I2C_MODE_IRQ,
476 .io_init = rk29_i2c0_io_init,
479 struct rk29_i2c_platform_data default_i2c1_data = {
483 .scl_rate = 400*1000,
484 .mode = I2C_MODE_POLL,
485 .io_init = rk29_i2c1_io_init,
488 struct rk29_i2c_platform_data default_i2c2_data = {
492 .scl_rate = 400*1000,
493 .mode = I2C_MODE_IRQ,
494 .io_init = rk29_i2c2_io_init,
497 struct rk29_i2c_platform_data default_i2c3_data = {
501 .scl_rate = 400*1000,
502 .mode = I2C_MODE_POLL,
503 .io_init = rk29_i2c3_io_init,
506 #ifdef CONFIG_I2C0_RK29
507 static struct i2c_board_info __initdata board_i2c0_devices[] = {
508 #if defined (CONFIG_RK1000_CONTROL)
510 .type = "rk1000_control",
515 #if defined (CONFIG_SND_SOC_RK1000)
517 .type = "rk1000_i2c_codec",
522 #if defined (CONFIG_SND_SOC_WM8900)
529 #if defined (CONFIG_BATTERY_STC3100)
536 #if defined (CONFIG_BATTERY_BQ27510)
541 .platform_data = &bq27510_info,
544 #if defined (CONFIG_RTC_HYM8563)
546 .type = "rtc_hym8563",
549 .irq = RK29_PIN0_PA1,
552 #if defined (CONFIG_GS_MMA8452)
554 .type = "gs_mma8452",
557 .irq = MMA8452_INT_PIN,
558 .platform_data = &mma8452_info,
561 #if defined (CONFIG_COMPASS_AK8973)
566 .irq = RK29_PIN0_PA4,
569 #if defined (CONFIG_COMPASS_AK8975)
574 .irq = RK29_PIN0_PA4,
580 #ifdef CONFIG_I2C1_RK29
581 static struct i2c_board_info __initdata board_i2c1_devices[] = {
582 #if defined (CONFIG_RK1000_CONTROL1)
584 .type = "rk1000_control",
589 #if defined (CONFIG_ANX7150)
592 .addr = 0x39, //0x39, 0x3d
594 .irq = RK29_PIN1_PD7,
601 #ifdef CONFIG_I2C2_RK29
602 static struct i2c_board_info __initdata board_i2c2_devices[] = {
603 #if defined (CONFIG_HANNSTAR_P1003)
605 .type = "p1003_touch",
608 .irq = RK29_PIN0_PA2,
609 .platform_data = &p1003_info,
612 #if defined (CONFIG_EETI_EGALAX)
614 .type = "egalax_i2c",
617 .irq = RK29_PIN0_PA2,
618 .platform_data = &eeti_egalax_info,
624 #ifdef CONFIG_I2C3_RK29
625 static struct i2c_board_info __initdata board_i2c3_devices[] = {
629 /*****************************************************************************************
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
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
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);
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,
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),
674 .dev_name = SENSOR_NAME_0,
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),
682 .dev_name = SENSOR_NAME_1,
685 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
687 .name = "camera_ipp_mem",
688 .start = MEM_CAMIPP_BASE,
689 .size = MEM_CAMIPP_SIZE,
694 static int rk29_sensor_io_init(void)
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;
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;
709 if (camera_power != INVALID_GPIO) {
710 ret = gpio_request(camera_power, "camera power");
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));
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));
721 if (camera_reset != INVALID_GPIO) {
722 ret = gpio_request(camera_reset, "camera reset");
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));
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));
733 if (camera_powerdown != INVALID_GPIO) {
734 ret = gpio_request(camera_powerdown, "camera powerdown");
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));
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));
745 if (camera_flash != INVALID_GPIO) {
746 ret = gpio_request(camera_flash, "camera flash");
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));
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));
757 sensor_io_int_loop_end:
758 rk29_sensor_io_deinit(i);
765 static int rk29_sensor_io_deinit(int sensor)
767 unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
768 unsigned int camera_powerdown = INVALID_GPIO, camera_flash = INVALID_GPIO;
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;
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);
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);
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);
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);
803 rk29_camera_platform_data.gpio_res[sensor].gpio_init = 0;
806 static int rk29_sensor_ioctrl(struct device *dev,enum rk29camera_ioctrl_cmd cmd, int on)
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;
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;
832 if (camera_power != INVALID_GPIO) {
833 if (camera_io_init & RK29_CAM_POWERACTIVE_MASK) {
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));
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));
843 ret = RK29_CAM_EIO_REQUESTFAIL;
844 printk("\n%s..%s..PowerPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
847 ret = RK29_CAM_EIO_INVALID;
853 if (camera_reset != INVALID_GPIO) {
854 if (camera_io_init & RK29_CAM_RESETACTIVE_MASK) {
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));
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));
863 ret = RK29_CAM_EIO_REQUESTFAIL;
864 printk("\n%s..%s..ResetPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
867 ret = RK29_CAM_EIO_INVALID;
874 if (camera_powerdown != INVALID_GPIO) {
875 if (camera_io_init & RK29_CAM_POWERDNACTIVE_MASK) {
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));
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));
884 ret = RK29_CAM_EIO_REQUESTFAIL;
885 printk("\n%s..%s..PowerDownPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_powerdown);
888 ret = RK29_CAM_EIO_INVALID;
895 if (camera_flash != INVALID_GPIO) {
896 if (camera_io_init & RK29_CAM_FLASHACTIVE_MASK) {
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));
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));
905 ret = RK29_CAM_EIO_REQUESTFAIL;
906 printk("\n%s..%s..FlashPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_flash);
909 ret = RK29_CAM_EIO_INVALID;
916 printk("%s cmd(0x%x) is unknown!\n",__FUNCTION__, cmd);
922 static int rk29_sensor_power(struct device *dev, int on)
924 rk29_sensor_ioctrl(dev,Cam_Power,on);
927 static int rk29_sensor_reset(struct device *dev)
929 rk29_sensor_ioctrl(dev,Cam_Reset,1);
931 rk29_sensor_ioctrl(dev,Cam_Reset,0);
934 static int rk29_sensor_powerdown(struct device *dev, int on)
936 return rk29_sensor_ioctrl(dev,Cam_PowerDown,on);
938 #if (SENSOR_IIC_ADDR_0 != 0x00)
939 static struct i2c_board_info rk29_i2c_cam_info_0[] = {
941 I2C_BOARD_INFO(SENSOR_NAME_0, SENSOR_IIC_ADDR_0>>1)
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,
954 /*platform_device : soc-camera need */
955 static struct platform_device rk29_soc_camera_pdrv_0 = {
956 .name = "soc-camera-pdrv",
959 .init_name = SENSOR_NAME_0,
960 .platform_data = &rk29_iclink_0,
964 static struct i2c_board_info rk29_i2c_cam_info_1[] = {
966 I2C_BOARD_INFO(SENSOR_NAME_1, SENSOR_IIC_ADDR_1>>1)
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,
979 /*platform_device : soc-camera need */
980 static struct platform_device rk29_soc_camera_pdrv_1 = {
981 .name = "soc-camera-pdrv",
984 .init_name = SENSOR_NAME_1,
985 .platform_data = &rk29_iclink_1,
990 static u64 rockchip_device_camera_dmamask = 0xffffffffUL;
991 static struct resource rk29_camera_resource[] = {
993 .start = RK29_VIP_PHYS,
994 .end = RK29_VIP_PHYS + RK29_VIP_SIZE - 1,
995 .flags = IORESOURCE_MEM,
1000 .flags = IORESOURCE_IRQ,
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,
1011 .dma_mask = &rockchip_device_camera_dmamask,
1012 .coherent_dma_mask = 0xffffffffUL,
1013 .platform_data = &rk29_camera_platform_data,
1017 /*****************************************************************************************
1019 * author: nzy@rock-chips.com
1020 *****************************************************************************************/
1021 #ifdef CONFIG_BACKLIGHT_RK29_BL
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
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
1036 //#define LCD_DISP_ON_PIN
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
1042 #define BL_EN_PIN GPIO0L_GPIO0A5
1043 #define BL_EN_VALUE GPIO_HIGH
1045 static int rk29_backlight_io_init(void)
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);
1053 ret = gpio_request(BL_EN_PIN, NULL);
1056 gpio_free(BL_EN_PIN);
1059 gpio_direction_output(BL_EN_PIN, 0);
1060 gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
1065 static int rk29_backlight_io_deinit(void)
1068 #ifdef LCD_DISP_ON_PIN
1069 gpio_free(BL_EN_PIN);
1071 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
1075 static int rk29_backlight_pwm_suspend(void)
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__);
1083 gpio_direction_output(PWM_GPIO, GPIO_LOW);
1087 static int rk29_backlight_pwm_resume(void)
1089 gpio_free(PWM_GPIO);
1090 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
1094 struct rk29_bl_info rk29_bl_info = {
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,
1103 /*****************************************************************************************
1104 * pwm voltage regulator devices
1105 ******************************************************************************************/
1106 #if defined (CONFIG_RK29_PWM_REGULATOR)
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
1114 static struct regulator_consumer_supply pwm_consumers[] = {
1120 static struct regulator_init_data rk29_pwm_regulator_data = {
1126 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1128 .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
1129 .consumer_supplies = pwm_consumers,
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,
1142 static struct platform_device rk29_device_pwm_regulator = {
1143 .name = "pwm-voltage-regulator",
1146 .platform_data = &rk29_regulator_pwm_platform_data,
1152 /*****************************************************************************************
1154 *****************************************************************************************/
1155 #ifdef CONFIG_SDMMC0_RK29
1156 static int rk29_sdmmc0_cfg_gpio(void)
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");
1168 gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
1170 gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
1172 gpio_direction_output(RK29_PIN5_PD5,GPIO_LOW);
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
1192 #ifdef CONFIG_SDMMC1_RK29
1193 #define CONFIG_SDMMC1_USE_DMA
1194 static int rk29_sdmmc1_cfg_gpio(void)
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);
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);
1211 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N RK29_PIN1_PD6
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,
1221 #ifdef CONFIG_SDMMC1_USE_DMA
1226 #ifdef CONFIG_WIFI_CONTROL_FUNC
1227 .status = rk29sdk_wifi_status,
1228 .register_status_notify = rk29sdk_wifi_status_register,
1231 .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
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
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;
1247 static int rk29sdk_wifi_status(struct device *dev)
1249 return rk29sdk_wifi_cd;
1252 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
1256 wifi_status_cb = callback;
1257 wifi_status_cb_devid = dev_id;
1261 static int rk29sdk_wifi_bt_gpio_control_init(void)
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__);
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);
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);
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);
1284 pr_info("%s: init finished\n",__func__);
1289 static int rk29sdk_wifi_power(int on)
1291 pr_info("%s: %d\n", __func__, on);
1293 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
1294 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
1296 pr_info("wifi turn on power\n");
1298 if (!rk29sdk_bt_power_state){
1299 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1301 pr_info("wifi shut off power\n");
1304 pr_info("wifi shouldn't shut off power, bt is using it!\n");
1306 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1310 rk29sdk_wifi_power_state = on;
1314 static int rk29sdk_wifi_reset_state;
1315 static int rk29sdk_wifi_reset(int on)
1317 pr_info("%s: %d\n", __func__, on);
1318 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
1320 rk29sdk_wifi_reset_state = on;
1324 int rk29sdk_wifi_set_carddetect(int val)
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);
1331 pr_warning("%s, nobody to notify\n", __func__);
1335 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
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)}
1344 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
1346 if (section == PREALLOC_WLAN_SEC_NUM)
1347 return wlan_static_skb;
1349 if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
1352 if (wifi_mem_array[section].size < size)
1355 return wifi_mem_array[section].mem_ptr;
1358 int __init rk29sdk_init_wifi_mem(void)
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));
1367 if (!wlan_static_skb[i])
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);
1375 if (!wifi_mem_array[i].mem_ptr)
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);
1385 i = WLAN_SKB_BUF_NUM;
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]);
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,
1401 static struct platform_device rk29sdk_wifi_device = {
1402 .name = "bcm4329_wlan",
1405 .platform_data = &rk29sdk_wifi_control,
1411 /* bluetooth rfkill device */
1412 static struct platform_device rk29sdk_rfkill = {
1413 .name = "rk29sdk_rfkill",
1418 #ifdef CONFIG_VIVANTE
1419 static struct resource resources_gpu[] = {
1424 .flags = IORESOURCE_IRQ,
1428 .start = RK29_GPU_PHYS,
1429 .end = RK29_GPU_PHYS + RK29_GPU_SIZE,
1430 .flags = IORESOURCE_MEM,
1434 .start = PMEM_GPU_BASE,
1435 .end = PMEM_GPU_BASE + PMEM_GPU_SIZE,
1436 .flags = IORESOURCE_MEM,
1439 static struct platform_device rk29_device_gpu = {
1442 .num_resources = ARRAY_SIZE(resources_gpu),
1443 .resource = resources_gpu,
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",
1452 .platform_data = &rk29_keys_pdata,
1457 static void __init rk29_board_iomux_init(void)
1459 #ifdef CONFIG_RK29_PWM_REGULATOR
1460 rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
1464 static struct platform_device *devices[] __initdata = {
1465 #ifdef CONFIG_UART1_RK29
1468 #ifdef CONFIG_UART0_RK29
1471 #ifdef CONFIG_UART2_RK29
1474 #ifdef CONFIG_UART3_RK29
1478 #ifdef CONFIG_RK29_PWM_REGULATOR
1479 &rk29_device_pwm_regulator,
1481 #ifdef CONFIG_SPIM0_RK29
1482 &rk29xx_device_spi0m,
1484 #ifdef CONFIG_SPIM1_RK29
1485 &rk29xx_device_spi1m,
1487 #ifdef CONFIG_ADC_RK29
1490 #ifdef CONFIG_I2C0_RK29
1493 #ifdef CONFIG_I2C1_RK29
1496 #ifdef CONFIG_I2C2_RK29
1499 #ifdef CONFIG_I2C3_RK29
1503 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
1504 &rk29_device_iis_2ch,
1506 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
1507 &rk29_device_iis_8ch,
1510 #ifdef CONFIG_KEYS_RK29
1513 #ifdef CONFIG_SDMMC0_RK29
1514 &rk29_device_sdmmc0,
1516 #ifdef CONFIG_SDMMC1_RK29
1517 &rk29_device_sdmmc1,
1520 #ifdef CONFIG_MTD_NAND_RK29XX
1521 &rk29xx_device_nand,
1524 #ifdef CONFIG_WIFI_CONTROL_FUNC
1525 &rk29sdk_wifi_device,
1532 #ifdef CONFIG_MTD_NAND_RK29
1536 #ifdef CONFIG_FB_RK29
1538 &rk29_device_dma_cpy,
1540 #ifdef CONFIG_BACKLIGHT_RK29_BL
1541 &rk29_device_backlight,
1543 #ifdef CONFIG_RK29_VMAC
1546 #ifdef CONFIG_VIVANTE
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,
1554 &rk29_soc_camera_pdrv_1,
1555 &android_pmem_cam_device,
1557 &android_pmem_device,
1558 &rk29_vpu_mem_device,
1559 #ifdef CONFIG_USB20_OTG
1560 &rk29_device_usb20_otg,
1562 #ifdef CONFIG_USB20_HOST
1563 &rk29_device_usb20_host,
1565 #ifdef CONFIG_USB11_HOST
1566 &rk29_device_usb11_host,
1568 #ifdef CONFIG_USB_ANDROID
1569 &android_usb_device,
1570 &usb_mass_storage_device,
1572 #ifdef CONFIG_RK29_IPP
1575 #ifdef CONFIG_VIDEO_RK29XX_VOUT
1576 &rk29_v4l2_output_devce,
1580 /*****************************************************************************************
1582 * author: cmc@rock-chips.com
1583 *****************************************************************************************/
1584 static int rk29_vmac_register_set(void)
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);
1593 static int rk29_rmii_io_init(void)
1598 err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
1600 gpio_free(RK29_PIN6_PB0);
1601 printk("-------request RK29_PIN6_PB0 fail--------\n");
1605 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1606 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1611 static int rk29_rmii_io_deinit(void)
1614 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1615 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1617 gpio_free(RK29_PIN6_PB0);
1621 static int rk29_rmii_power_control(int enable)
1625 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
1626 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
1629 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1630 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
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,
1642 /*****************************************************************************************
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] = {
1650 .cs_gpio = RK29_PIN2_PC1,
1651 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
1652 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
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,
1662 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
1665 .cs_gpio = RK29_PIN2_PC5,
1666 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
1667 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
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,
1677 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
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);
1690 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
1695 static int spi_io_fix_leakage_bug(void)
1698 gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
1703 static int spi_io_resume_leakage_bug(void)
1706 gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
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,
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,
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
1736 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI)
1737 static struct xpt2046_platform_data xpt2046_info = {
1746 .debounce_rep = DEBOUNCE_REPTIME,
1748 .gpio_pendown = XPT2046_GPIO_INT,
1749 .penirq_recheck_delay_usecs = 1,
1751 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)
1752 static struct xpt2046_platform_data xpt2046_info = {
1761 .debounce_rep = DEBOUNCE_REPTIME,
1763 .gpio_pendown = XPT2046_GPIO_INT,
1764 .penirq_recheck_delay_usecs = 1,
1766 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
1767 static struct xpt2046_platform_data xpt2046_info = {
1776 .debounce_rep = DEBOUNCE_REPTIME,
1778 .gpio_pendown = XPT2046_GPIO_INT,
1780 .penirq_recheck_delay_usecs = 1,
1782 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1783 static struct xpt2046_platform_data xpt2046_info = {
1792 .debounce_rep = DEBOUNCE_REPTIME,
1794 .gpio_pendown = XPT2046_GPIO_INT,
1796 .penirq_recheck_delay_usecs = 1,
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)
1804 .modalias = "xpt2046_ts",
1806 .max_speed_hz = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
1808 .irq = XPT2046_GPIO_INT,
1809 .platform_data = &xpt2046_info,
1815 static void __init rk29_gic_init_irq(void)
1817 gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
1818 gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
1821 static void __init machine_rk29_init_irq(void)
1823 rk29_gic_init_irq();
1827 static void __init machine_rk29_board_init(void)
1829 rk29_board_iomux_init();
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));
1838 #ifdef CONFIG_I2C1_RK29
1839 i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
1840 ARRAY_SIZE(board_i2c1_devices));
1842 #ifdef CONFIG_I2C2_RK29
1843 i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
1844 ARRAY_SIZE(board_i2c2_devices));
1846 #ifdef CONFIG_I2C3_RK29
1847 i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
1848 ARRAY_SIZE(board_i2c3_devices));
1851 spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1853 #ifdef CONFIG_WIFI_CONTROL_FUNC
1854 rk29sdk_wifi_bt_gpio_control_init();
1855 rk29sdk_init_wifi_mem();
1858 board_usb_detect_init(RK29_PIN0_PA0);
1861 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
1862 char **cmdline, struct meminfo *mi)
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;
1870 static void __init machine_rk29_mapio(void)
1872 rk29_map_common_io();
1873 rk29_setup_early_printk();
1875 rk29_clock_init(periph_pll_300mhz);
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,