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 INVALID_GPIO
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 /*****************************************************************************************
143 * touch screen devices
144 * author: cf@rock-chips.com
145 *****************************************************************************************/
146 #define TOUCH_SCREEN_STANDBY_PIN RK29_PIN6_PD1
147 #define TOUCH_SCREEN_STANDBY_VALUE GPIO_HIGH
148 #define TOUCH_SCREEN_DISPLAY_PIN INVALID_GPIO
149 #define TOUCH_SCREEN_DISPLAY_VALUE GPIO_HIGH
151 static int rk29_lcd_io_init(void)
157 static int rk29_lcd_io_deinit(void)
163 static struct rk29lcd_info rk29_lcd_info = {
164 .txd_pin = LCD_TXD_PIN,
165 .clk_pin = LCD_CLK_PIN,
166 .cs_pin = LCD_CS_PIN,
167 .io_init = rk29_lcd_io_init,
168 .io_deinit = rk29_lcd_io_deinit,
172 static int rk29_fb_io_init(struct rk29_fb_setting_info *fb_setting)
175 if(fb_setting->mcu_fmk_en && (FB_MCU_FMK_PIN != INVALID_GPIO))
177 ret = gpio_request(FB_MCU_FMK_PIN, NULL);
180 gpio_free(FB_MCU_FMK_PIN);
181 printk(">>>>>> FB_MCU_FMK_PIN gpio_request err \n ");
183 gpio_direction_input(FB_MCU_FMK_PIN);
185 if(fb_setting->disp_on_en)
187 if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
189 ret = gpio_request(FB_DISPLAY_ON_PIN, NULL);
192 gpio_free(FB_DISPLAY_ON_PIN);
193 printk(">>>>>> FB_DISPLAY_ON_PIN gpio_request err \n ");
198 ret = gpio_request(TOUCH_SCREEN_DISPLAY_PIN, NULL);
201 gpio_free(TOUCH_SCREEN_DISPLAY_PIN);
202 printk(">>>>>> TOUCH_SCREEN_DISPLAY_PIN gpio_request err \n ");
204 gpio_direction_output(TOUCH_SCREEN_DISPLAY_PIN, 0);
205 gpio_set_value(TOUCH_SCREEN_DISPLAY_PIN, TOUCH_SCREEN_DISPLAY_VALUE);
209 if(fb_setting->disp_on_en)
211 if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
213 ret = gpio_request(FB_LCD_STANDBY_PIN, NULL);
216 gpio_free(FB_LCD_STANDBY_PIN);
217 printk(">>>>>> FB_LCD_STANDBY_PIN gpio_request err \n ");
222 ret = gpio_request(TOUCH_SCREEN_STANDBY_PIN, NULL);
225 gpio_free(TOUCH_SCREEN_STANDBY_PIN);
226 printk(">>>>>> TOUCH_SCREEN_STANDBY_PIN gpio_request err \n ");
228 gpio_direction_output(TOUCH_SCREEN_STANDBY_PIN, 0);
229 gpio_set_value(TOUCH_SCREEN_STANDBY_PIN, TOUCH_SCREEN_STANDBY_VALUE);
233 if(FB_LCD_CABC_EN_PIN != INVALID_GPIO)
235 ret = gpio_request(FB_LCD_CABC_EN_PIN, NULL);
238 gpio_free(FB_LCD_CABC_EN_PIN);
239 printk(">>>>>> FB_LCD_CABC_EN_PIN gpio_request err \n ");
241 gpio_direction_output(FB_LCD_CABC_EN_PIN, 0);
242 gpio_set_value(FB_LCD_CABC_EN_PIN, GPIO_LOW);
248 static struct rk29fb_info rk29_fb_info = {
250 .disp_on_pin = FB_DISPLAY_ON_PIN,
251 .disp_on_value = FB_DISPLAY_ON_VALUE,
252 .standby_pin = FB_LCD_STANDBY_PIN,
253 .standby_value = FB_LCD_STANDBY_VALUE,
254 .mcu_fmk_pin = FB_MCU_FMK_PIN,
255 .lcd_info = &rk29_lcd_info,
256 .io_init = rk29_fb_io_init,
259 /* rk29 fb resource */
260 static struct resource rk29_fb_resource[] = {
263 .start = RK29_LCDC_PHYS,
264 .end = RK29_LCDC_PHYS + RK29_LCDC_SIZE - 1,
265 .flags = IORESOURCE_MEM,
271 .flags = IORESOURCE_IRQ,
275 .start = MEM_FB_BASE,
276 .end = MEM_FB_BASE + MEM_FB_SIZE - 1,
277 .flags = IORESOURCE_MEM,
279 #ifdef CONFIG_FB_WORK_IPP
281 .name = "win1 ipp buf",
282 .start = MEM_FBIPP_BASE,
283 .end = MEM_FBIPP_BASE + MEM_FBIPP_SIZE - 1,
284 .flags = IORESOURCE_MEM,
290 struct platform_device rk29_device_fb = {
293 .num_resources = ARRAY_SIZE(rk29_fb_resource),
294 .resource = rk29_fb_resource,
296 .platform_data = &rk29_fb_info,
300 struct platform_device rk29_device_dma_cpy = {
301 .name = "dma_memcpy",
308 static struct android_pmem_platform_data android_pmem_pdata = {
310 .start = PMEM_UI_BASE,
311 .size = PMEM_UI_SIZE,
316 static struct platform_device android_pmem_device = {
317 .name = "android_pmem",
320 .platform_data = &android_pmem_pdata,
325 static struct android_pmem_platform_data android_pmem_cam_pdata = {
327 .start = PMEM_CAM_BASE,
328 .size = PMEM_CAM_SIZE,
333 static struct platform_device android_pmem_cam_device = {
334 .name = "android_pmem",
337 .platform_data = &android_pmem_cam_pdata,
342 static struct vpu_mem_platform_data vpu_mem_pdata = {
344 .start = PMEM_VPU_BASE,
345 .size = PMEM_VPU_SIZE,
349 static struct platform_device rk29_vpu_mem_device = {
353 .platform_data = &vpu_mem_pdata,
357 static struct platform_device rk29_v4l2_output_devce = {
361 /*HANNSTAR_P1003 touch*/
362 #if defined (CONFIG_HANNSTAR_P1003)
363 #define TOUCH_RESET_PIN RK29_PIN6_PC3
364 #define TOUCH_INT_PIN RK29_PIN0_PA2
366 int p1003_init_platform_hw(void)
368 if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
369 gpio_free(TOUCH_RESET_PIN);
370 printk("p1003_init_platform_hw gpio_request error\n");
374 if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
375 gpio_free(TOUCH_INT_PIN);
376 printk("p1003_init_platform_hw gpio_request error\n");
379 gpio_pull_updown(TOUCH_INT_PIN, 1);
380 gpio_direction_output(TOUCH_RESET_PIN, 0);
382 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
384 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
390 struct p1003_platform_data p1003_info = {
392 .init_platform_hw= p1003_init_platform_hw,
396 #if defined (CONFIG_EETI_EGALAX)
397 #define TOUCH_RESET_PIN RK29_PIN6_PC3
398 #define TOUCH_INT_PIN RK29_PIN0_PA2
400 static int EETI_EGALAX_init_platform_hw(void)
402 if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
403 gpio_free(TOUCH_RESET_PIN);
404 printk("p1003_init_platform_hw gpio_request error\n");
408 if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
409 gpio_free(TOUCH_INT_PIN);
410 printk("p1003_init_platform_hw gpio_request error\n");
413 gpio_pull_updown(TOUCH_INT_PIN, 1);
414 gpio_direction_output(TOUCH_RESET_PIN, 0);
416 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
418 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
424 static struct eeti_egalax_platform_data eeti_egalax_info = {
426 .init_platform_hw= EETI_EGALAX_init_platform_hw,
427 .standby_pin = TOUCH_SCREEN_STANDBY_PIN,
428 .standby_value = TOUCH_SCREEN_STANDBY_VALUE,
429 .disp_on_pin = TOUCH_SCREEN_DISPLAY_PIN,
430 .disp_on_value = TOUCH_SCREEN_DISPLAY_VALUE,
434 #if defined (CONFIG_GS_MMA8452)
435 #define MMA8452_INT_PIN RK29_PIN0_PA3
437 static int mma8452_init_platform_hw(void)
440 if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
441 gpio_free(MMA8452_INT_PIN);
442 printk("mma8452_init_platform_hw gpio_request error\n");
445 gpio_pull_updown(MMA8452_INT_PIN, 1);
450 static struct mma8452_platform_data mma8452_info = {
453 .init_platform_hw= mma8452_init_platform_hw,
458 #if defined (CONFIG_BATTERY_BQ27510)
459 #define DC_CHECK_PIN RK29_PIN4_PA1
460 #define LI_LION_BAT_NUM 2
461 static int bq27510_init_dc_check_pin(void){
462 if(gpio_request(DC_CHECK_PIN,"dc_check") != 0){
463 gpio_free(DC_CHECK_PIN);
464 printk("bq27510 init dc check pin request error\n");
467 gpio_direction_input(DC_CHECK_PIN);
471 struct bq27510_platform_data bq27510_info = {
472 .init_dc_check_pin = bq27510_init_dc_check_pin,
473 .dc_check_pin = DC_CHECK_PIN,
474 .bat_num = LI_LION_BAT_NUM,
479 /*****************************************************************************************
481 * author: kfx@rock-chips.com
482 *****************************************************************************************/
483 static int rk29_i2c0_io_init(void)
485 rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_I2C0_SCL);
486 rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_I2C0_SDA);
490 static int rk29_i2c1_io_init(void)
492 rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_I2C1_SCL);
493 rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_I2C1_SDA);
496 static int rk29_i2c2_io_init(void)
498 rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_I2C2_SCL);
499 rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_I2C2_SDA);
503 static int rk29_i2c3_io_init(void)
505 rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_I2C3_SCL);
506 rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_I2C3_SDA);
510 struct rk29_i2c_platform_data default_i2c0_data = {
514 .scl_rate = 400*1000,
515 .mode = I2C_MODE_IRQ,
516 .io_init = rk29_i2c0_io_init,
519 struct rk29_i2c_platform_data default_i2c1_data = {
523 .scl_rate = 400*1000,
524 .mode = I2C_MODE_POLL,
525 .io_init = rk29_i2c1_io_init,
528 struct rk29_i2c_platform_data default_i2c2_data = {
532 .scl_rate = 400*1000,
533 .mode = I2C_MODE_IRQ,
534 .io_init = rk29_i2c2_io_init,
537 struct rk29_i2c_platform_data default_i2c3_data = {
541 .scl_rate = 400*1000,
542 .mode = I2C_MODE_POLL,
543 .io_init = rk29_i2c3_io_init,
546 #ifdef CONFIG_I2C0_RK29
547 static struct i2c_board_info __initdata board_i2c0_devices[] = {
548 #if defined (CONFIG_RK1000_CONTROL)
550 .type = "rk1000_control",
555 #if defined (CONFIG_SND_SOC_alc5621)
562 #if defined (CONFIG_SND_SOC_alc5631)
569 #if defined (CONFIG_SND_SOC_RK1000)
571 .type = "rk1000_i2c_codec",
576 #if defined (CONFIG_SND_SOC_WM8900)
583 #if defined (CONFIG_BATTERY_STC3100)
590 #if defined (CONFIG_BATTERY_BQ27510)
595 .platform_data = &bq27510_info,
598 #if defined (CONFIG_RTC_HYM8563)
600 .type = "rtc_hym8563",
603 .irq = RK29_PIN0_PA1,
606 #if defined (CONFIG_GS_MMA8452)
608 .type = "gs_mma8452",
611 .irq = MMA8452_INT_PIN,
612 .platform_data = &mma8452_info,
615 #if defined (CONFIG_COMPASS_AK8973)
620 .irq = RK29_PIN0_PA4,
623 #if defined (CONFIG_COMPASS_AK8975)
628 .irq = RK29_PIN0_PA4,
634 #ifdef CONFIG_I2C1_RK29
635 static struct i2c_board_info __initdata board_i2c1_devices[] = {
636 #if defined (CONFIG_RK1000_CONTROL1)
638 .type = "rk1000_control",
643 #if defined (CONFIG_ANX7150)
646 .addr = 0x39, //0x39, 0x3d
648 .irq = RK29_PIN1_PD7,
655 #ifdef CONFIG_I2C2_RK29
656 static struct i2c_board_info __initdata board_i2c2_devices[] = {
657 #if defined (CONFIG_HANNSTAR_P1003)
659 .type = "p1003_touch",
661 .flags = 0, //I2C_M_NEED_DELAY
662 .irq = RK29_PIN0_PA2,
663 .platform_data = &p1003_info,
667 #if defined (CONFIG_EETI_EGALAX)
669 .type = "egalax_i2c",
672 .irq = RK29_PIN0_PA2,
673 .platform_data = &eeti_egalax_info,
679 #ifdef CONFIG_I2C3_RK29
680 static struct i2c_board_info __initdata board_i2c3_devices[] = {
684 /*****************************************************************************************
686 * author: ddl@rock-chips.com
687 *****************************************************************************************/
688 #ifdef CONFIG_VIDEO_RK29
689 #define SENSOR_NAME_0 RK29_CAM_SENSOR_NAME_OV5642 /* back camera sensor */
690 #define SENSOR_IIC_ADDR_0 0x78
691 #define SENSOR_IIC_ADAPTER_ID_0 1
692 #define SENSOR_POWER_PIN_0 INVALID_GPIO
693 #define SENSOR_RESET_PIN_0 INVALID_GPIO
694 #define SENSOR_POWERDN_PIN_0 RK29_PIN6_PB7
695 #define SENSOR_FALSH_PIN_0 INVALID_GPIO
696 #define SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
697 #define SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
698 #define SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
699 #define SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
701 #define SENSOR_NAME_1 RK29_CAM_SENSOR_NAME_OV2659 /* front camera sensor */
702 #define SENSOR_IIC_ADDR_1 0x60
703 #define SENSOR_IIC_ADAPTER_ID_1 1
704 #define SENSOR_POWER_PIN_1 INVALID_GPIO
705 #define SENSOR_RESET_PIN_1 INVALID_GPIO
706 #define SENSOR_POWERDN_PIN_1 RK29_PIN5_PD7
707 #define SENSOR_FALSH_PIN_1 INVALID_GPIO
708 #define SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
709 #define SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
710 #define SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
711 #define SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
713 static int rk29_sensor_io_init(void);
714 static int rk29_sensor_io_deinit(int sensor);
715 static int rk29_sensor_ioctrl(struct device *dev,enum rk29camera_ioctrl_cmd cmd,int on);
717 static struct rk29camera_platform_data rk29_camera_platform_data = {
718 .io_init = rk29_sensor_io_init,
719 .io_deinit = rk29_sensor_io_deinit,
720 .sensor_ioctrl = rk29_sensor_ioctrl,
723 .gpio_reset = SENSOR_RESET_PIN_0,
724 .gpio_power = SENSOR_POWER_PIN_0,
725 .gpio_powerdown = SENSOR_POWERDN_PIN_0,
726 .gpio_flash = SENSOR_FALSH_PIN_0,
727 .gpio_flag = (SENSOR_POWERACTIVE_LEVEL_0|SENSOR_RESETACTIVE_LEVEL_0|SENSOR_POWERDNACTIVE_LEVEL_0|SENSOR_FLASHACTIVE_LEVEL_0),
729 .dev_name = SENSOR_NAME_0,
731 .gpio_reset = SENSOR_RESET_PIN_1,
732 .gpio_power = SENSOR_POWER_PIN_1,
733 .gpio_powerdown = SENSOR_POWERDN_PIN_1,
734 .gpio_flash = SENSOR_FALSH_PIN_1,
735 .gpio_flag = (SENSOR_POWERACTIVE_LEVEL_1|SENSOR_RESETACTIVE_LEVEL_1|SENSOR_POWERDNACTIVE_LEVEL_1|SENSOR_FLASHACTIVE_LEVEL_1),
737 .dev_name = SENSOR_NAME_1,
740 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
742 .name = "camera_ipp_mem",
743 .start = MEM_CAMIPP_BASE,
744 .size = MEM_CAMIPP_SIZE,
749 static int rk29_sensor_io_init(void)
752 unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
753 unsigned int camera_powerdown = INVALID_GPIO, camera_flash = INVALID_GPIO;
754 unsigned int camera_ioflag;
756 for (i=0; i<2; i++) {
757 camera_reset = rk29_camera_platform_data.gpio_res[i].gpio_reset;
758 camera_power = rk29_camera_platform_data.gpio_res[i].gpio_power;
759 camera_powerdown = rk29_camera_platform_data.gpio_res[i].gpio_powerdown;
760 camera_flash = rk29_camera_platform_data.gpio_res[i].gpio_flash;
761 camera_ioflag = rk29_camera_platform_data.gpio_res[i].gpio_flag;
762 rk29_camera_platform_data.gpio_res[i].gpio_init = 0;
764 if (camera_power != INVALID_GPIO) {
765 ret = gpio_request(camera_power, "camera power");
767 goto sensor_io_int_loop_end;
768 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_POWERACTIVE_MASK;
769 gpio_set_value(camera_reset, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
770 gpio_direction_output(camera_power, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
772 //printk("\n%s....power pin(%d) init success(0x%x) \n",__FUNCTION__,camera_power,(((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
776 if (camera_reset != INVALID_GPIO) {
777 ret = gpio_request(camera_reset, "camera reset");
779 goto sensor_io_int_loop_end;
780 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_RESETACTIVE_MASK;
781 gpio_set_value(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
782 gpio_direction_output(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
784 //printk("\n%s....reset pin(%d) init success(0x%x)\n",__FUNCTION__,camera_reset,((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
788 if (camera_powerdown != INVALID_GPIO) {
789 ret = gpio_request(camera_powerdown, "camera powerdown");
791 goto sensor_io_int_loop_end;
792 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_POWERDNACTIVE_MASK;
793 gpio_set_value(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
794 gpio_direction_output(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
796 //printk("\n%s....powerdown pin(%d) init success(0x%x) \n",__FUNCTION__,camera_powerdown,((camera_ioflag&RK29_CAM_POWERDNACTIVE_BITPOS)>>RK29_CAM_POWERDNACTIVE_BITPOS));
800 if (camera_flash != INVALID_GPIO) {
801 ret = gpio_request(camera_flash, "camera flash");
803 goto sensor_io_int_loop_end;
804 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_FLASHACTIVE_MASK;
805 gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
806 gpio_direction_output(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
808 //printk("\n%s....flash pin(%d) init success(0x%x) \n",__FUNCTION__,camera_flash,((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
812 sensor_io_int_loop_end:
813 rk29_sensor_io_deinit(i);
820 static int rk29_sensor_io_deinit(int sensor)
822 unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
823 unsigned int camera_powerdown = INVALID_GPIO, camera_flash = INVALID_GPIO;
825 camera_reset = rk29_camera_platform_data.gpio_res[sensor].gpio_reset;
826 camera_power = rk29_camera_platform_data.gpio_res[sensor].gpio_power;
827 camera_powerdown = rk29_camera_platform_data.gpio_res[sensor].gpio_powerdown;
828 camera_flash = rk29_camera_platform_data.gpio_res[sensor].gpio_flash;
830 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_POWERACTIVE_MASK) {
831 if (camera_power != INVALID_GPIO) {
832 gpio_direction_input(camera_power);
833 gpio_free(camera_power);
837 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_RESETACTIVE_MASK) {
838 if (camera_reset != INVALID_GPIO) {
839 gpio_direction_input(camera_reset);
840 gpio_free(camera_reset);
844 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_POWERDNACTIVE_MASK) {
845 if (camera_powerdown != INVALID_GPIO) {
846 gpio_direction_input(camera_powerdown);
847 gpio_free(camera_powerdown);
851 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_FLASHACTIVE_MASK) {
852 if (camera_flash != INVALID_GPIO) {
853 gpio_direction_input(camera_flash);
854 gpio_free(camera_flash);
858 rk29_camera_platform_data.gpio_res[sensor].gpio_init = 0;
861 static int rk29_sensor_ioctrl(struct device *dev,enum rk29camera_ioctrl_cmd cmd, int on)
863 unsigned int camera_power=INVALID_GPIO,camera_reset=INVALID_GPIO, camera_powerdown=INVALID_GPIO,camera_flash = INVALID_GPIO;
864 unsigned int camera_ioflag,camera_io_init;
865 int ret = RK29_CAM_IO_SUCCESS;
867 if(rk29_camera_platform_data.gpio_res[0].dev_name && (strcmp(rk29_camera_platform_data.gpio_res[0].dev_name, dev_name(dev)) == 0)) {
868 camera_power = rk29_camera_platform_data.gpio_res[0].gpio_power;
869 camera_reset = rk29_camera_platform_data.gpio_res[0].gpio_reset;
870 camera_powerdown = rk29_camera_platform_data.gpio_res[0].gpio_powerdown;
871 camera_flash = rk29_camera_platform_data.gpio_res[0].gpio_flash;
872 camera_ioflag = rk29_camera_platform_data.gpio_res[0].gpio_flag;
873 camera_io_init = rk29_camera_platform_data.gpio_res[0].gpio_init;
874 } 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)) {
875 camera_power = rk29_camera_platform_data.gpio_res[1].gpio_power;
876 camera_reset = rk29_camera_platform_data.gpio_res[1].gpio_reset;
877 camera_powerdown = rk29_camera_platform_data.gpio_res[1].gpio_powerdown;
878 camera_flash = rk29_camera_platform_data.gpio_res[1].gpio_flash;
879 camera_ioflag = rk29_camera_platform_data.gpio_res[1].gpio_flag;
880 camera_io_init = rk29_camera_platform_data.gpio_res[1].gpio_init;
887 if (camera_power != INVALID_GPIO) {
888 if (camera_io_init & RK29_CAM_POWERACTIVE_MASK) {
890 gpio_set_value(camera_power, ((camera_ioflag&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
891 //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));
894 gpio_set_value(camera_power, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
895 //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));
898 ret = RK29_CAM_EIO_REQUESTFAIL;
899 printk("\n%s..%s..PowerPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
902 ret = RK29_CAM_EIO_INVALID;
908 if (camera_reset != INVALID_GPIO) {
909 if (camera_io_init & RK29_CAM_RESETACTIVE_MASK) {
911 gpio_set_value(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
912 //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));
914 gpio_set_value(camera_reset,(((~camera_ioflag)&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
915 //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));
918 ret = RK29_CAM_EIO_REQUESTFAIL;
919 printk("\n%s..%s..ResetPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
922 ret = RK29_CAM_EIO_INVALID;
929 if (camera_powerdown != INVALID_GPIO) {
930 if (camera_io_init & RK29_CAM_POWERDNACTIVE_MASK) {
932 gpio_set_value(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
933 //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));
935 gpio_set_value(camera_powerdown,(((~camera_ioflag)&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
936 //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));
939 ret = RK29_CAM_EIO_REQUESTFAIL;
940 printk("\n%s..%s..PowerDownPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_powerdown);
943 ret = RK29_CAM_EIO_INVALID;
950 if (camera_flash != INVALID_GPIO) {
951 if (camera_io_init & RK29_CAM_FLASHACTIVE_MASK) {
956 gpio_set_value(camera_flash,(((~camera_ioflag)&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
957 //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));
963 gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
964 //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));
970 gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
971 //printk("\n%s..%s..FlashPin=%d ..PinLevel = %x \n",__FUNCTION__,dev_name(dev),camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
977 printk("\n%s..%s..Flash command(%d) is invalidate \n",__FUNCTION__,dev_name(dev),on);
982 ret = RK29_CAM_EIO_REQUESTFAIL;
983 printk("\n%s..%s..FlashPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_flash);
986 ret = RK29_CAM_EIO_INVALID;
993 printk("%s cmd(0x%x) is unknown!\n",__FUNCTION__, cmd);
999 static int rk29_sensor_power(struct device *dev, int on)
1001 rk29_sensor_ioctrl(dev,Cam_Power,on);
1004 static int rk29_sensor_reset(struct device *dev)
1006 rk29_sensor_ioctrl(dev,Cam_Reset,1);
1008 rk29_sensor_ioctrl(dev,Cam_Reset,0);
1011 static int rk29_sensor_powerdown(struct device *dev, int on)
1013 return rk29_sensor_ioctrl(dev,Cam_PowerDown,on);
1015 #if (SENSOR_IIC_ADDR_0 != 0x00)
1016 static struct i2c_board_info rk29_i2c_cam_info_0[] = {
1018 I2C_BOARD_INFO(SENSOR_NAME_0, SENSOR_IIC_ADDR_0>>1)
1022 static struct soc_camera_link rk29_iclink_0 = {
1023 .bus_id = RK29_CAM_PLATFORM_DEV_ID,
1024 .power = rk29_sensor_power,
1025 .powerdown = rk29_sensor_powerdown,
1026 .board_info = &rk29_i2c_cam_info_0[0],
1027 .i2c_adapter_id = SENSOR_IIC_ADAPTER_ID_0,
1028 .module_name = SENSOR_NAME_0,
1031 /*platform_device : soc-camera need */
1032 static struct platform_device rk29_soc_camera_pdrv_0 = {
1033 .name = "soc-camera-pdrv",
1036 .init_name = SENSOR_NAME_0,
1037 .platform_data = &rk29_iclink_0,
1041 static struct i2c_board_info rk29_i2c_cam_info_1[] = {
1043 I2C_BOARD_INFO(SENSOR_NAME_1, SENSOR_IIC_ADDR_1>>1)
1047 static struct soc_camera_link rk29_iclink_1 = {
1048 .bus_id = RK29_CAM_PLATFORM_DEV_ID,
1049 .power = rk29_sensor_power,
1050 .powerdown = rk29_sensor_powerdown,
1051 .board_info = &rk29_i2c_cam_info_1[0],
1052 .i2c_adapter_id = SENSOR_IIC_ADAPTER_ID_1,
1053 .module_name = SENSOR_NAME_1,
1056 /*platform_device : soc-camera need */
1057 static struct platform_device rk29_soc_camera_pdrv_1 = {
1058 .name = "soc-camera-pdrv",
1061 .init_name = SENSOR_NAME_1,
1062 .platform_data = &rk29_iclink_1,
1067 static u64 rockchip_device_camera_dmamask = 0xffffffffUL;
1068 static struct resource rk29_camera_resource[] = {
1070 .start = RK29_VIP_PHYS,
1071 .end = RK29_VIP_PHYS + RK29_VIP_SIZE - 1,
1072 .flags = IORESOURCE_MEM,
1077 .flags = IORESOURCE_IRQ,
1081 /*platform_device : */
1082 static struct platform_device rk29_device_camera = {
1083 .name = RK29_CAM_DRV_NAME,
1084 .id = RK29_CAM_PLATFORM_DEV_ID, /* This is used to put cameras on this interface */
1085 .num_resources = ARRAY_SIZE(rk29_camera_resource),
1086 .resource = rk29_camera_resource,
1088 .dma_mask = &rockchip_device_camera_dmamask,
1089 .coherent_dma_mask = 0xffffffffUL,
1090 .platform_data = &rk29_camera_platform_data,
1094 /*****************************************************************************************
1096 * author: nzy@rock-chips.com
1097 *****************************************************************************************/
1098 #ifdef CONFIG_BACKLIGHT_RK29_BL
1100 GPIO1B5_PWM0_NAME, GPIO1L_PWM0
1101 GPIO5D2_PWM1_UART1SIRIN_NAME, GPIO5H_PWM1
1102 GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME, GPIO2L_PWM2
1103 GPIO1A5_EMMCPWREN_PWM3_NAME, GPIO1L_PWM3
1107 #define PWM_MUX_NAME GPIO1B5_PWM0_NAME
1108 #define PWM_MUX_MODE GPIO1L_PWM0
1109 #define PWM_MUX_MODE_GPIO GPIO1L_GPIO1B5
1110 #define PWM_GPIO RK29_PIN1_PB5
1111 #define PWM_EFFECT_VALUE 1
1113 //#define LCD_DISP_ON_PIN
1115 #ifdef LCD_DISP_ON_PIN
1116 #define BL_EN_MUX_NAME GPIOF34_UART3_SEL_NAME
1117 #define BL_EN_MUX_MODE IOMUXB_GPIO1_B34
1119 #define BL_EN_PIN GPIO0L_GPIO0A5
1120 #define BL_EN_VALUE GPIO_HIGH
1122 static int rk29_backlight_io_init(void)
1126 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
1127 #ifdef LCD_DISP_ON_PIN
1128 rk29_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
1130 ret = gpio_request(BL_EN_PIN, NULL);
1133 gpio_free(BL_EN_PIN);
1136 gpio_direction_output(BL_EN_PIN, 0);
1137 gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
1142 static int rk29_backlight_io_deinit(void)
1145 #ifdef LCD_DISP_ON_PIN
1146 gpio_free(BL_EN_PIN);
1148 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
1152 static int rk29_backlight_pwm_suspend(void)
1155 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
1156 if (ret = gpio_request(PWM_GPIO, NULL)) {
1157 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
1160 gpio_direction_output(PWM_GPIO, GPIO_LOW);
1164 static int rk29_backlight_pwm_resume(void)
1166 gpio_free(PWM_GPIO);
1167 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
1171 struct rk29_bl_info rk29_bl_info = {
1173 .bl_ref = PWM_EFFECT_VALUE,
1174 .io_init = rk29_backlight_io_init,
1175 .io_deinit = rk29_backlight_io_deinit,
1176 .pwm_suspend = rk29_backlight_pwm_suspend,
1177 .pwm_resume = rk29_backlight_pwm_resume,
1180 /*****************************************************************************************
1181 * pwm voltage regulator devices
1182 ******************************************************************************************/
1183 #if defined (CONFIG_RK29_PWM_REGULATOR)
1185 #define REGULATOR_PWM_ID 2
1186 #define REGULATOR_PWM_MUX_NAME GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME
1187 #define REGULATOR_PWM_MUX_MODE GPIO2L_PWM2
1188 #define REGULATOR_PWM_MUX_MODE_GPIO GPIO2L_GPIO2A3
1189 #define REGULATOR_PWM_GPIO RK29_PIN2_PA3
1191 static struct regulator_consumer_supply pwm_consumers[] = {
1197 static struct regulator_init_data rk29_pwm_regulator_data = {
1203 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1205 .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
1206 .consumer_supplies = pwm_consumers,
1209 static struct pwm_platform_data rk29_regulator_pwm_platform_data = {
1210 .pwm_id = REGULATOR_PWM_ID,
1211 .pwm_gpio = REGULATOR_PWM_GPIO,
1212 //.pwm_iomux_name[] = REGULATOR_PWM_MUX_NAME;
1213 .pwm_iomux_name = REGULATOR_PWM_MUX_NAME,
1214 .pwm_iomux_pwm = REGULATOR_PWM_MUX_MODE,
1215 .pwm_iomux_gpio = REGULATOR_PWM_MUX_MODE_GPIO,
1216 .init_data = &rk29_pwm_regulator_data,
1219 static struct platform_device rk29_device_pwm_regulator = {
1220 .name = "pwm-voltage-regulator",
1223 .platform_data = &rk29_regulator_pwm_platform_data,
1229 /*****************************************************************************************
1231 *****************************************************************************************/
1232 #ifdef CONFIG_SDMMC0_RK29
1233 static int rk29_sdmmc0_cfg_gpio(void)
1235 rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
1236 rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
1237 rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
1238 rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
1239 rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
1240 rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
1241 rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
1242 rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5); ///GPIO5H_SDMMC0_PWR_EN); ///GPIO5H_GPIO5D5);
1243 gpio_request(RK29_PIN5_PD5,"sdmmc");
1245 gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
1247 gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
1249 gpio_direction_output(RK29_PIN5_PD5,GPIO_LOW);
1254 #define CONFIG_SDMMC0_USE_DMA
1255 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
1256 .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
1257 MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
1258 MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
1259 .host_caps = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1260 .io_init = rk29_sdmmc0_cfg_gpio,
1261 .dma_name = "sd_mmc",
1262 #ifdef CONFIG_SDMMC0_USE_DMA
1267 .detect_irq = RK29_PIN2_PA2, // INVALID_GPIO
1268 .enable_sd_wakeup = 0,
1271 #ifdef CONFIG_SDMMC1_RK29
1272 #define CONFIG_SDMMC1_USE_DMA
1273 static int rk29_sdmmc1_cfg_gpio(void)
1275 rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
1276 rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
1277 rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
1278 rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
1279 rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
1280 rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
1281 //rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_SDMMC1_DETECT_N);
1285 #ifdef CONFIG_WIFI_CONTROL_FUNC
1286 static int rk29sdk_wifi_status(struct device *dev);
1287 static int rk29sdk_wifi_status_register(void (*callback)(int card_presend, void *dev_id), void *dev_id);
1290 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N RK29_PIN1_PD6
1292 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
1293 .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
1294 MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
1295 MMC_VDD_32_33|MMC_VDD_33_34),
1296 .host_caps = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
1297 MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1298 .io_init = rk29_sdmmc1_cfg_gpio,
1300 #ifdef CONFIG_SDMMC1_USE_DMA
1305 #ifdef CONFIG_WIFI_CONTROL_FUNC
1306 .status = rk29sdk_wifi_status,
1307 .register_status_notify = rk29sdk_wifi_status_register,
1310 .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
1315 #ifdef CONFIG_WIFI_CONTROL_FUNC
1316 #define RK29SDK_WIFI_BT_GPIO_POWER_N RK29_PIN5_PD6
1317 #define RK29SDK_WIFI_GPIO_RESET_N RK29_PIN6_PC0
1318 #define RK29SDK_BT_GPIO_RESET_N RK29_PIN6_PC4
1320 static int rk29sdk_wifi_cd = 0; /* wifi virtual 'card detect' status */
1321 static void (*wifi_status_cb)(int card_present, void *dev_id);
1322 static void *wifi_status_cb_devid;
1323 int rk29sdk_wifi_power_state = 0;
1324 int rk29sdk_bt_power_state = 0;
1326 static int rk29sdk_wifi_status(struct device *dev)
1328 return rk29sdk_wifi_cd;
1331 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
1335 wifi_status_cb = callback;
1336 wifi_status_cb_devid = dev_id;
1340 static int rk29sdk_wifi_bt_gpio_control_init(void)
1342 if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
1343 pr_info("%s: request wifi_bt power gpio failed\n", __func__);
1347 if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
1348 pr_info("%s: request wifi reset gpio failed\n", __func__);
1349 gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
1353 if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
1354 pr_info("%s: request bt reset gpio failed\n", __func__);
1355 gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
1359 gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1360 gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1361 gpio_direction_output(RK29SDK_BT_GPIO_RESET_N, GPIO_LOW);
1363 pr_info("%s: init finished\n",__func__);
1368 static int rk29sdk_wifi_power(int on)
1370 pr_info("%s: %d\n", __func__, on);
1372 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
1373 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
1375 pr_info("wifi turn on power\n");
1377 if (!rk29sdk_bt_power_state){
1378 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1380 pr_info("wifi shut off power\n");
1383 pr_info("wifi shouldn't shut off power, bt is using it!\n");
1385 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1389 rk29sdk_wifi_power_state = on;
1393 static int rk29sdk_wifi_reset_state;
1394 static int rk29sdk_wifi_reset(int on)
1396 pr_info("%s: %d\n", __func__, on);
1397 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
1399 rk29sdk_wifi_reset_state = on;
1403 int rk29sdk_wifi_set_carddetect(int val)
1405 pr_info("%s:%d\n", __func__, val);
1406 rk29sdk_wifi_cd = val;
1407 if (wifi_status_cb){
1408 wifi_status_cb(val, wifi_status_cb_devid);
1410 pr_warning("%s, nobody to notify\n", __func__);
1414 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
1416 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
1417 {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
1418 {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
1419 {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
1420 {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
1423 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
1425 if (section == PREALLOC_WLAN_SEC_NUM)
1426 return wlan_static_skb;
1428 if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
1431 if (wifi_mem_array[section].size < size)
1434 return wifi_mem_array[section].mem_ptr;
1437 int __init rk29sdk_init_wifi_mem(void)
1442 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
1443 wlan_static_skb[i] = dev_alloc_skb(
1444 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
1446 if (!wlan_static_skb[i])
1450 for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
1451 wifi_mem_array[i].mem_ptr =
1452 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
1454 if (!wifi_mem_array[i].mem_ptr)
1460 pr_err("Failed to mem_alloc for WLAN\n");
1461 for (j = 0 ; j < i ; j++)
1462 kfree(wifi_mem_array[j].mem_ptr);
1464 i = WLAN_SKB_BUF_NUM;
1467 pr_err("Failed to skb_alloc for WLAN\n");
1468 for (j = 0 ; j < i ; j++)
1469 dev_kfree_skb(wlan_static_skb[j]);
1474 static struct wifi_platform_data rk29sdk_wifi_control = {
1475 .set_power = rk29sdk_wifi_power,
1476 .set_reset = rk29sdk_wifi_reset,
1477 .set_carddetect = rk29sdk_wifi_set_carddetect,
1478 .mem_prealloc = rk29sdk_mem_prealloc,
1480 static struct platform_device rk29sdk_wifi_device = {
1481 .name = "bcm4329_wlan",
1484 .platform_data = &rk29sdk_wifi_control,
1490 /* bluetooth rfkill device */
1491 static struct platform_device rk29sdk_rfkill = {
1492 .name = "rk29sdk_rfkill",
1497 #ifdef CONFIG_VIVANTE
1498 static struct resource resources_gpu[] = {
1503 .flags = IORESOURCE_IRQ,
1507 .start = RK29_GPU_PHYS,
1508 .end = RK29_GPU_PHYS + RK29_GPU_SIZE,
1509 .flags = IORESOURCE_MEM,
1513 .start = PMEM_GPU_BASE,
1514 .end = PMEM_GPU_BASE + PMEM_GPU_SIZE,
1515 .flags = IORESOURCE_MEM,
1518 static struct platform_device rk29_device_gpu = {
1521 .num_resources = ARRAY_SIZE(resources_gpu),
1522 .resource = resources_gpu,
1525 #ifdef CONFIG_KEYS_RK29
1526 extern struct rk29_keys_platform_data rk29_keys_pdata;
1527 static struct platform_device rk29_device_keys = {
1528 .name = "rk29-keypad",
1531 .platform_data = &rk29_keys_pdata,
1536 static void __init rk29_board_iomux_init(void)
1538 #ifdef CONFIG_RK29_PWM_REGULATOR
1539 rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
1543 static struct platform_device *devices[] __initdata = {
1544 #ifdef CONFIG_UART1_RK29
1547 #ifdef CONFIG_UART0_RK29
1550 #ifdef CONFIG_UART2_RK29
1553 #ifdef CONFIG_UART3_RK29
1557 #ifdef CONFIG_RK29_PWM_REGULATOR
1558 &rk29_device_pwm_regulator,
1560 #ifdef CONFIG_SPIM0_RK29
1561 &rk29xx_device_spi0m,
1563 #ifdef CONFIG_SPIM1_RK29
1564 &rk29xx_device_spi1m,
1566 #ifdef CONFIG_ADC_RK29
1569 #ifdef CONFIG_I2C0_RK29
1572 #ifdef CONFIG_I2C1_RK29
1575 #ifdef CONFIG_I2C2_RK29
1578 #ifdef CONFIG_I2C3_RK29
1582 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
1583 &rk29_device_iis_2ch,
1585 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
1586 &rk29_device_iis_8ch,
1589 #ifdef CONFIG_KEYS_RK29
1592 #ifdef CONFIG_SDMMC0_RK29
1593 &rk29_device_sdmmc0,
1595 #ifdef CONFIG_SDMMC1_RK29
1596 &rk29_device_sdmmc1,
1599 #ifdef CONFIG_MTD_NAND_RK29XX
1600 &rk29xx_device_nand,
1603 #ifdef CONFIG_WIFI_CONTROL_FUNC
1604 &rk29sdk_wifi_device,
1611 #ifdef CONFIG_MTD_NAND_RK29
1615 #ifdef CONFIG_FB_RK29
1617 &rk29_device_dma_cpy,
1619 #ifdef CONFIG_BACKLIGHT_RK29_BL
1620 &rk29_device_backlight,
1622 #ifdef CONFIG_RK29_VMAC
1625 #ifdef CONFIG_VIVANTE
1628 #ifdef CONFIG_VIDEO_RK29
1629 &rk29_device_camera, /* ddl@rock-chips.com : camera support */
1630 #if (SENSOR_IIC_ADDR_0 != 0x00)
1631 &rk29_soc_camera_pdrv_0,
1633 &rk29_soc_camera_pdrv_1,
1634 &android_pmem_cam_device,
1636 &android_pmem_device,
1637 &rk29_vpu_mem_device,
1638 #ifdef CONFIG_USB20_OTG
1639 &rk29_device_usb20_otg,
1641 #ifdef CONFIG_USB20_HOST
1642 &rk29_device_usb20_host,
1644 #ifdef CONFIG_USB11_HOST
1645 &rk29_device_usb11_host,
1647 #ifdef CONFIG_USB_ANDROID
1648 &android_usb_device,
1649 &usb_mass_storage_device,
1651 #ifdef CONFIG_RK29_IPP
1654 #ifdef CONFIG_VIDEO_RK29XX_VOUT
1655 &rk29_v4l2_output_devce,
1659 /*****************************************************************************************
1661 * author: cmc@rock-chips.com
1662 *****************************************************************************************/
1663 static int rk29_vmac_register_set(void)
1665 //config rk29 vmac as rmii, 100MHz
1666 u32 value= readl(RK29_GRF_BASE + 0xbc);
1667 value = (value & 0xfff7ff) | (0x400);
1668 writel(value, RK29_GRF_BASE + 0xbc);
1672 static int rk29_rmii_io_init(void)
1677 err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
1679 gpio_free(RK29_PIN6_PB0);
1680 printk("-------request RK29_PIN6_PB0 fail--------\n");
1684 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1685 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1690 static int rk29_rmii_io_deinit(void)
1693 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1694 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1696 gpio_free(RK29_PIN6_PB0);
1700 static int rk29_rmii_power_control(int enable)
1704 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
1705 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
1708 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1709 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1714 struct rk29_vmac_platform_data rk29_vmac_pdata = {
1715 .vmac_register_set = rk29_vmac_register_set,
1716 .rmii_io_init = rk29_rmii_io_init,
1717 .rmii_io_deinit = rk29_rmii_io_deinit,
1718 .rmii_power_control = rk29_rmii_power_control,
1721 /*****************************************************************************************
1723 * author: cmc@rock-chips.com
1724 *****************************************************************************************/
1725 #define SPI_CHIPSELECT_NUM 2
1726 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
1729 .cs_gpio = RK29_PIN2_PC1,
1730 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
1731 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
1735 .cs_gpio = RK29_PIN1_PA4,
1736 .cs_iomux_name = GPIO1A4_EMMCWRITEPRT_SPI0CS1_NAME,//if no iomux,set it NULL
1737 .cs_iomux_mode = GPIO1L_SPI0_CSN1,
1741 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
1744 .cs_gpio = RK29_PIN2_PC5,
1745 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
1746 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
1750 .cs_gpio = RK29_PIN1_PA3,
1751 .cs_iomux_name = GPIO1A3_EMMCDETECTN_SPI1CS1_NAME,//if no iomux,set it NULL
1752 .cs_iomux_mode = GPIO1L_SPI1_CSN1,
1756 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
1761 for (i=0; i<cs_num; i++) {
1762 rk29_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
1769 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
1774 static int spi_io_fix_leakage_bug(void)
1777 gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
1782 static int spi_io_resume_leakage_bug(void)
1785 gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
1790 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
1791 .num_chipselect = SPI_CHIPSELECT_NUM,
1792 .chipselect_gpios = rk29xx_spi0_cs_gpios,
1793 .io_init = spi_io_init,
1794 .io_deinit = spi_io_deinit,
1795 .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1796 .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1799 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
1800 .num_chipselect = SPI_CHIPSELECT_NUM,
1801 .chipselect_gpios = rk29xx_spi1_cs_gpios,
1802 .io_init = spi_io_init,
1803 .io_deinit = spi_io_deinit,
1804 .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1805 .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1808 /*****************************************************************************************
1809 * xpt2046 touch panel
1810 * author: cmc@rock-chips.com
1811 *****************************************************************************************/
1812 #define XPT2046_GPIO_INT RK29_PIN0_PA3
1813 #define DEBOUNCE_REPTIME 3
1815 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI)
1816 static struct xpt2046_platform_data xpt2046_info = {
1825 .debounce_rep = DEBOUNCE_REPTIME,
1827 .gpio_pendown = XPT2046_GPIO_INT,
1828 .penirq_recheck_delay_usecs = 1,
1830 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)
1831 static struct xpt2046_platform_data xpt2046_info = {
1840 .debounce_rep = DEBOUNCE_REPTIME,
1842 .gpio_pendown = XPT2046_GPIO_INT,
1843 .penirq_recheck_delay_usecs = 1,
1845 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
1846 static struct xpt2046_platform_data xpt2046_info = {
1855 .debounce_rep = DEBOUNCE_REPTIME,
1857 .gpio_pendown = XPT2046_GPIO_INT,
1859 .penirq_recheck_delay_usecs = 1,
1861 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1862 static struct xpt2046_platform_data xpt2046_info = {
1871 .debounce_rep = DEBOUNCE_REPTIME,
1873 .gpio_pendown = XPT2046_GPIO_INT,
1875 .penirq_recheck_delay_usecs = 1,
1879 static struct spi_board_info board_spi_devices[] = {
1880 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\
1881 ||defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1883 .modalias = "xpt2046_ts",
1885 .max_speed_hz = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
1887 .irq = XPT2046_GPIO_INT,
1888 .platform_data = &xpt2046_info,
1894 static void __init rk29_gic_init_irq(void)
1896 gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
1897 gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
1900 static void __init machine_rk29_init_irq(void)
1902 rk29_gic_init_irq();
1906 static void __init machine_rk29_board_init(void)
1908 rk29_board_iomux_init();
1912 platform_add_devices(devices, ARRAY_SIZE(devices));
1913 #ifdef CONFIG_I2C0_RK29
1914 i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
1915 ARRAY_SIZE(board_i2c0_devices));
1917 #ifdef CONFIG_I2C1_RK29
1918 i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
1919 ARRAY_SIZE(board_i2c1_devices));
1921 #ifdef CONFIG_I2C2_RK29
1922 i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
1923 ARRAY_SIZE(board_i2c2_devices));
1925 #ifdef CONFIG_I2C3_RK29
1926 i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
1927 ARRAY_SIZE(board_i2c3_devices));
1930 spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1932 #ifdef CONFIG_WIFI_CONTROL_FUNC
1933 rk29sdk_wifi_bt_gpio_control_init();
1934 rk29sdk_init_wifi_mem();
1937 board_usb_detect_init(RK29_PIN0_PA0);
1940 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
1941 char **cmdline, struct meminfo *mi)
1944 mi->bank[0].start = RK29_SDRAM_PHYS;
1945 mi->bank[0].node = PHYS_TO_NID(RK29_SDRAM_PHYS);
1946 mi->bank[0].size = LINUX_SIZE;
1949 static void __init machine_rk29_mapio(void)
1951 rk29_map_common_io();
1952 rk29_setup_early_printk();
1954 rk29_clock_init(periph_pll_288mhz);
1958 MACHINE_START(RK29, "RK29board")
1959 /* UART for LL DEBUG */
1960 .phys_io = RK29_UART1_PHYS,
1961 .io_pg_offst = ((RK29_UART1_BASE) >> 18) & 0xfffc,
1962 .boot_params = RK29_SDRAM_PHYS + 0x88000,
1963 .fixup = machine_rk29_fixup,
1964 .map_io = machine_rk29_mapio,
1965 .init_irq = machine_rk29_init_irq,
1966 .init_machine = machine_rk29_board_init,
1967 .timer = &rk29_timer,