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 /*****************************************************************************************
143 * touch screen devices
144 * author: cf@rock-chips.com
145 *****************************************************************************************/
146 #define TOUCH_SCREEN_STANDBY_PIN INVALID_GPIO
147 #define TOUCH_SCREEN_STANDBY_VALUE GPIO_HIGH
148 #define TOUCH_SCREEN_DISPLAY_PIN INVALID_GPIO
149 #define TOUCH_SCREEN_DISPLAY_VALUE GPIO_HIGH
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_IRQ,
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_IRQ,
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) || defined (CONFIG_ANX7150_NEW)
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 /*---------------- Camera Sensor Configuration Begin ------------------------*/
690 #define CONFIG_SENSOR_0 RK29_CAM_SENSOR_OV5642 /* back camera sensor */
691 #define CONFIG_SENSOR_IIC_ADDR_0 0x78
692 #define CONFIG_SENSOR_IIC_ADAPTER_ID_0 1
693 #define CONFIG_SENSOR_POWER_PIN_0 INVALID_GPIO
694 #define CONFIG_SENSOR_RESET_PIN_0 INVALID_GPIO
695 #define CONFIG_SENSOR_POWERDN_PIN_0 RK29_PIN6_PB7
696 #define CONFIG_SENSOR_FALSH_PIN_0 INVALID_GPIO
697 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
698 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
699 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
700 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
702 #define CONFIG_SENSOR_1 RK29_CAM_SENSOR_OV2659 /* front camera sensor */
703 #define CONFIG_SENSOR_IIC_ADDR_1 0x60
704 #define CONFIG_SENSOR_IIC_ADAPTER_ID_1 1
705 #define CONFIG_SENSOR_POWER_PIN_1 INVALID_GPIO
706 #define CONFIG_SENSOR_RESET_PIN_1 INVALID_GPIO
707 #define CONFIG_SENSOR_POWERDN_PIN_1 RK29_PIN5_PD7
708 #define CONFIG_SENSOR_FALSH_PIN_1 INVALID_GPIO
709 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
710 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
711 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
712 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
713 /*---------------- Camera Sensor Configuration End------------------------*/
715 #define _CONS(a,b) a##b
716 #define CONS(a,b) _CONS(a,b)
719 #define _STR(x) __STR(x)
720 #define STR(x) _STR(x)
722 #define SENSOR_NAME_0 STR(CONFIG_SENSOR_0) /* back camera sensor */
723 #define SENSOR_NAME_1 STR(CONFIG_SENSOR_1) /* front camera sensor */
724 #define SENSOR_DEVICE_NAME_0 STR(CONS(CONFIG_SENSOR_0, _back))
725 #define SENSOR_DEVICE_NAME_1 STR(CONS(CONFIG_SENSOR_1, _front))
727 static int rk29_sensor_io_init(void);
728 static int rk29_sensor_io_deinit(int sensor);
729 static int rk29_sensor_ioctrl(struct device *dev,enum rk29camera_ioctrl_cmd cmd,int on);
731 static struct rk29camera_platform_data rk29_camera_platform_data = {
732 .io_init = rk29_sensor_io_init,
733 .io_deinit = rk29_sensor_io_deinit,
734 .sensor_ioctrl = rk29_sensor_ioctrl,
737 .gpio_reset = CONFIG_SENSOR_RESET_PIN_0,
738 .gpio_power = CONFIG_SENSOR_POWER_PIN_0,
739 .gpio_powerdown = CONFIG_SENSOR_POWERDN_PIN_0,
740 .gpio_flash = CONFIG_SENSOR_FALSH_PIN_0,
741 .gpio_flag = (CONFIG_SENSOR_POWERACTIVE_LEVEL_0|CONFIG_SENSOR_RESETACTIVE_LEVEL_0|CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0|CONFIG_SENSOR_FLASHACTIVE_LEVEL_0),
743 .dev_name = SENSOR_DEVICE_NAME_0,
745 .gpio_reset = CONFIG_SENSOR_RESET_PIN_1,
746 .gpio_power = CONFIG_SENSOR_POWER_PIN_1,
747 .gpio_powerdown = CONFIG_SENSOR_POWERDN_PIN_1,
748 .gpio_flash = CONFIG_SENSOR_FALSH_PIN_1,
749 .gpio_flag = (CONFIG_SENSOR_POWERACTIVE_LEVEL_1|CONFIG_SENSOR_RESETACTIVE_LEVEL_1|CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1|CONFIG_SENSOR_FLASHACTIVE_LEVEL_1),
751 .dev_name = SENSOR_DEVICE_NAME_1,
754 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
756 .name = "camera_ipp_mem",
757 .start = MEM_CAMIPP_BASE,
758 .size = MEM_CAMIPP_SIZE,
763 static int rk29_sensor_io_init(void)
766 unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
767 unsigned int camera_powerdown = INVALID_GPIO, camera_flash = INVALID_GPIO;
768 unsigned int camera_ioflag;
770 for (i=0; i<2; i++) {
771 camera_reset = rk29_camera_platform_data.gpio_res[i].gpio_reset;
772 camera_power = rk29_camera_platform_data.gpio_res[i].gpio_power;
773 camera_powerdown = rk29_camera_platform_data.gpio_res[i].gpio_powerdown;
774 camera_flash = rk29_camera_platform_data.gpio_res[i].gpio_flash;
775 camera_ioflag = rk29_camera_platform_data.gpio_res[i].gpio_flag;
776 rk29_camera_platform_data.gpio_res[i].gpio_init = 0;
778 if (camera_power != INVALID_GPIO) {
779 ret = gpio_request(camera_power, "camera power");
781 goto sensor_io_int_loop_end;
782 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_POWERACTIVE_MASK;
783 gpio_set_value(camera_reset, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
784 gpio_direction_output(camera_power, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
786 //printk("\n%s....power pin(%d) init success(0x%x) \n",__FUNCTION__,camera_power,(((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
790 if (camera_reset != INVALID_GPIO) {
791 ret = gpio_request(camera_reset, "camera reset");
793 goto sensor_io_int_loop_end;
794 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_RESETACTIVE_MASK;
795 gpio_set_value(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
796 gpio_direction_output(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
798 //printk("\n%s....reset pin(%d) init success(0x%x)\n",__FUNCTION__,camera_reset,((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
802 if (camera_powerdown != INVALID_GPIO) {
803 ret = gpio_request(camera_powerdown, "camera powerdown");
805 goto sensor_io_int_loop_end;
806 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_POWERDNACTIVE_MASK;
807 gpio_set_value(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
808 gpio_direction_output(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
810 //printk("\n%s....powerdown pin(%d) init success(0x%x) \n",__FUNCTION__,camera_powerdown,((camera_ioflag&RK29_CAM_POWERDNACTIVE_BITPOS)>>RK29_CAM_POWERDNACTIVE_BITPOS));
814 if (camera_flash != INVALID_GPIO) {
815 ret = gpio_request(camera_flash, "camera flash");
817 goto sensor_io_int_loop_end;
818 rk29_camera_platform_data.gpio_res[i].gpio_init |= RK29_CAM_FLASHACTIVE_MASK;
819 gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
820 gpio_direction_output(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
822 //printk("\n%s....flash pin(%d) init success(0x%x) \n",__FUNCTION__,camera_flash,((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
826 sensor_io_int_loop_end:
827 rk29_sensor_io_deinit(i);
834 static int rk29_sensor_io_deinit(int sensor)
836 unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
837 unsigned int camera_powerdown = INVALID_GPIO, camera_flash = INVALID_GPIO;
839 camera_reset = rk29_camera_platform_data.gpio_res[sensor].gpio_reset;
840 camera_power = rk29_camera_platform_data.gpio_res[sensor].gpio_power;
841 camera_powerdown = rk29_camera_platform_data.gpio_res[sensor].gpio_powerdown;
842 camera_flash = rk29_camera_platform_data.gpio_res[sensor].gpio_flash;
844 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_POWERACTIVE_MASK) {
845 if (camera_power != INVALID_GPIO) {
846 gpio_direction_input(camera_power);
847 gpio_free(camera_power);
851 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_RESETACTIVE_MASK) {
852 if (camera_reset != INVALID_GPIO) {
853 gpio_direction_input(camera_reset);
854 gpio_free(camera_reset);
858 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_POWERDNACTIVE_MASK) {
859 if (camera_powerdown != INVALID_GPIO) {
860 gpio_direction_input(camera_powerdown);
861 gpio_free(camera_powerdown);
865 if (rk29_camera_platform_data.gpio_res[sensor].gpio_init & RK29_CAM_FLASHACTIVE_MASK) {
866 if (camera_flash != INVALID_GPIO) {
867 gpio_direction_input(camera_flash);
868 gpio_free(camera_flash);
872 rk29_camera_platform_data.gpio_res[sensor].gpio_init = 0;
875 static int rk29_sensor_ioctrl(struct device *dev,enum rk29camera_ioctrl_cmd cmd, int on)
877 unsigned int camera_power=INVALID_GPIO,camera_reset=INVALID_GPIO, camera_powerdown=INVALID_GPIO,camera_flash = INVALID_GPIO;
878 unsigned int camera_ioflag,camera_io_init;
879 int ret = RK29_CAM_IO_SUCCESS;
881 if(rk29_camera_platform_data.gpio_res[0].dev_name && (strcmp(rk29_camera_platform_data.gpio_res[0].dev_name, dev_name(dev)) == 0)) {
882 camera_power = rk29_camera_platform_data.gpio_res[0].gpio_power;
883 camera_reset = rk29_camera_platform_data.gpio_res[0].gpio_reset;
884 camera_powerdown = rk29_camera_platform_data.gpio_res[0].gpio_powerdown;
885 camera_flash = rk29_camera_platform_data.gpio_res[0].gpio_flash;
886 camera_ioflag = rk29_camera_platform_data.gpio_res[0].gpio_flag;
887 camera_io_init = rk29_camera_platform_data.gpio_res[0].gpio_init;
888 } else if (rk29_camera_platform_data.gpio_res[1].dev_name && (strcmp(rk29_camera_platform_data.gpio_res[1].dev_name, dev_name(dev)) == 0)) {
889 camera_power = rk29_camera_platform_data.gpio_res[1].gpio_power;
890 camera_reset = rk29_camera_platform_data.gpio_res[1].gpio_reset;
891 camera_powerdown = rk29_camera_platform_data.gpio_res[1].gpio_powerdown;
892 camera_flash = rk29_camera_platform_data.gpio_res[1].gpio_flash;
893 camera_ioflag = rk29_camera_platform_data.gpio_res[1].gpio_flag;
894 camera_io_init = rk29_camera_platform_data.gpio_res[1].gpio_init;
901 if (camera_power != INVALID_GPIO) {
902 if (camera_io_init & RK29_CAM_POWERACTIVE_MASK) {
904 gpio_set_value(camera_power, ((camera_ioflag&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
905 //printk("\n%s..%s..PowerPin=%d ..PinLevel = %x \n",__FUNCTION__,dev_name(dev), camera_power, ((camera_ioflag&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
908 gpio_set_value(camera_power, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
909 //printk("\n%s..%s..PowerPin=%d ..PinLevel = %x \n",__FUNCTION__,dev_name(dev), camera_power, (((~camera_ioflag)&RK29_CAM_POWERACTIVE_MASK)>>RK29_CAM_POWERACTIVE_BITPOS));
912 ret = RK29_CAM_EIO_REQUESTFAIL;
913 printk("\n%s..%s..PowerPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
916 ret = RK29_CAM_EIO_INVALID;
922 if (camera_reset != INVALID_GPIO) {
923 if (camera_io_init & RK29_CAM_RESETACTIVE_MASK) {
925 gpio_set_value(camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
926 //printk("\n%s..%s..ResetPin=%d ..PinLevel = %x \n",__FUNCTION__,dev_name(dev),camera_reset, ((camera_ioflag&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
928 gpio_set_value(camera_reset,(((~camera_ioflag)&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
929 //printk("\n%s..%s..ResetPin= %d..PinLevel = %x \n",__FUNCTION__,dev_name(dev), camera_reset, (((~camera_ioflag)&RK29_CAM_RESETACTIVE_MASK)>>RK29_CAM_RESETACTIVE_BITPOS));
932 ret = RK29_CAM_EIO_REQUESTFAIL;
933 printk("\n%s..%s..ResetPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_reset);
936 ret = RK29_CAM_EIO_INVALID;
943 if (camera_powerdown != INVALID_GPIO) {
944 if (camera_io_init & RK29_CAM_POWERDNACTIVE_MASK) {
946 gpio_set_value(camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
947 printk("\n%s..%s..PowerDownPin=%d ..PinLevel = %x \n",__FUNCTION__,dev_name(dev),camera_powerdown, ((camera_ioflag&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
949 gpio_set_value(camera_powerdown,(((~camera_ioflag)&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
950 printk("\n%s..%s..PowerDownPin= %d..PinLevel = %x \n",__FUNCTION__,dev_name(dev), camera_powerdown, (((~camera_ioflag)&RK29_CAM_POWERDNACTIVE_MASK)>>RK29_CAM_POWERDNACTIVE_BITPOS));
953 ret = RK29_CAM_EIO_REQUESTFAIL;
954 printk("\n%s..%s..PowerDownPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_powerdown);
957 ret = RK29_CAM_EIO_INVALID;
964 if (camera_flash != INVALID_GPIO) {
965 if (camera_io_init & RK29_CAM_FLASHACTIVE_MASK) {
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 gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
978 //printk("\n%s..%s..FlashPin=%d ..PinLevel = %x \n",__FUNCTION__,dev_name(dev),camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
984 gpio_set_value(camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
985 //printk("\n%s..%s..FlashPin=%d ..PinLevel = %x \n",__FUNCTION__,dev_name(dev),camera_flash, ((camera_ioflag&RK29_CAM_FLASHACTIVE_MASK)>>RK29_CAM_FLASHACTIVE_BITPOS));
991 printk("\n%s..%s..Flash command(%d) is invalidate \n",__FUNCTION__,dev_name(dev),on);
996 ret = RK29_CAM_EIO_REQUESTFAIL;
997 printk("\n%s..%s..FlashPin=%d request failed!\n",__FUNCTION__,dev_name(dev),camera_flash);
1000 ret = RK29_CAM_EIO_INVALID;
1007 printk("%s cmd(0x%x) is unknown!\n",__FUNCTION__, cmd);
1013 static int rk29_sensor_power(struct device *dev, int on)
1015 rk29_sensor_ioctrl(dev,Cam_Power,on);
1018 static int rk29_sensor_reset(struct device *dev)
1020 rk29_sensor_ioctrl(dev,Cam_Reset,1);
1022 rk29_sensor_ioctrl(dev,Cam_Reset,0);
1025 static int rk29_sensor_powerdown(struct device *dev, int on)
1027 return rk29_sensor_ioctrl(dev,Cam_PowerDown,on);
1029 #if (CONFIG_SENSOR_IIC_ADDR_0 != 0x00)
1030 static struct i2c_board_info rk29_i2c_cam_info_0[] = {
1032 I2C_BOARD_INFO(SENSOR_NAME_0, CONFIG_SENSOR_IIC_ADDR_0>>1)
1036 static struct soc_camera_link rk29_iclink_0 = {
1037 .bus_id = RK29_CAM_PLATFORM_DEV_ID,
1038 .power = rk29_sensor_power,
1039 .powerdown = rk29_sensor_powerdown,
1040 .board_info = &rk29_i2c_cam_info_0[0],
1041 .i2c_adapter_id = CONFIG_SENSOR_IIC_ADAPTER_ID_0,
1042 .module_name = SENSOR_NAME_0,
1045 /*platform_device : soc-camera need */
1046 static struct platform_device rk29_soc_camera_pdrv_0 = {
1047 .name = "soc-camera-pdrv",
1050 .init_name = SENSOR_DEVICE_NAME_0,
1051 .platform_data = &rk29_iclink_0,
1055 static struct i2c_board_info rk29_i2c_cam_info_1[] = {
1057 I2C_BOARD_INFO(SENSOR_NAME_1, CONFIG_SENSOR_IIC_ADDR_1>>1)
1061 static struct soc_camera_link rk29_iclink_1 = {
1062 .bus_id = RK29_CAM_PLATFORM_DEV_ID,
1063 .power = rk29_sensor_power,
1064 .powerdown = rk29_sensor_powerdown,
1065 .board_info = &rk29_i2c_cam_info_1[0],
1066 .i2c_adapter_id = CONFIG_SENSOR_IIC_ADAPTER_ID_1,
1067 .module_name = SENSOR_NAME_1,
1070 /*platform_device : soc-camera need */
1071 static struct platform_device rk29_soc_camera_pdrv_1 = {
1072 .name = "soc-camera-pdrv",
1075 .init_name = SENSOR_DEVICE_NAME_1,
1076 .platform_data = &rk29_iclink_1,
1081 static u64 rockchip_device_camera_dmamask = 0xffffffffUL;
1082 static struct resource rk29_camera_resource[] = {
1084 .start = RK29_VIP_PHYS,
1085 .end = RK29_VIP_PHYS + RK29_VIP_SIZE - 1,
1086 .flags = IORESOURCE_MEM,
1091 .flags = IORESOURCE_IRQ,
1095 /*platform_device : */
1096 static struct platform_device rk29_device_camera = {
1097 .name = RK29_CAM_DRV_NAME,
1098 .id = RK29_CAM_PLATFORM_DEV_ID, /* This is used to put cameras on this interface */
1099 .num_resources = ARRAY_SIZE(rk29_camera_resource),
1100 .resource = rk29_camera_resource,
1102 .dma_mask = &rockchip_device_camera_dmamask,
1103 .coherent_dma_mask = 0xffffffffUL,
1104 .platform_data = &rk29_camera_platform_data,
1108 /*****************************************************************************************
1110 * author: nzy@rock-chips.com
1111 *****************************************************************************************/
1112 #ifdef CONFIG_BACKLIGHT_RK29_BL
1114 GPIO1B5_PWM0_NAME, GPIO1L_PWM0
1115 GPIO5D2_PWM1_UART1SIRIN_NAME, GPIO5H_PWM1
1116 GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME, GPIO2L_PWM2
1117 GPIO1A5_EMMCPWREN_PWM3_NAME, GPIO1L_PWM3
1121 #define PWM_MUX_NAME GPIO1B5_PWM0_NAME
1122 #define PWM_MUX_MODE GPIO1L_PWM0
1123 #define PWM_MUX_MODE_GPIO GPIO1L_GPIO1B5
1124 #define PWM_GPIO RK29_PIN1_PB5
1125 #define PWM_EFFECT_VALUE 1
1127 //#define LCD_DISP_ON_PIN
1129 #ifdef LCD_DISP_ON_PIN
1130 #define BL_EN_MUX_NAME GPIOF34_UART3_SEL_NAME
1131 #define BL_EN_MUX_MODE IOMUXB_GPIO1_B34
1133 #define BL_EN_PIN GPIO0L_GPIO0A5
1134 #define BL_EN_VALUE GPIO_HIGH
1136 static int rk29_backlight_io_init(void)
1140 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
1141 #ifdef LCD_DISP_ON_PIN
1142 rk29_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
1144 ret = gpio_request(BL_EN_PIN, NULL);
1147 gpio_free(BL_EN_PIN);
1150 gpio_direction_output(BL_EN_PIN, 0);
1151 gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
1156 static int rk29_backlight_io_deinit(void)
1159 #ifdef LCD_DISP_ON_PIN
1160 gpio_free(BL_EN_PIN);
1162 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
1166 static int rk29_backlight_pwm_suspend(void)
1169 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
1170 if (ret = gpio_request(PWM_GPIO, NULL)) {
1171 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
1174 gpio_direction_output(PWM_GPIO, GPIO_LOW);
1178 static int rk29_backlight_pwm_resume(void)
1180 gpio_free(PWM_GPIO);
1181 rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
1185 struct rk29_bl_info rk29_bl_info = {
1187 .bl_ref = PWM_EFFECT_VALUE,
1188 .io_init = rk29_backlight_io_init,
1189 .io_deinit = rk29_backlight_io_deinit,
1190 .pwm_suspend = rk29_backlight_pwm_suspend,
1191 .pwm_resume = rk29_backlight_pwm_resume,
1194 /*****************************************************************************************
1195 * pwm voltage regulator devices
1196 ******************************************************************************************/
1197 #if defined (CONFIG_RK29_PWM_REGULATOR)
1199 #define REGULATOR_PWM_ID 2
1200 #define REGULATOR_PWM_MUX_NAME GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME
1201 #define REGULATOR_PWM_MUX_MODE GPIO2L_PWM2
1202 #define REGULATOR_PWM_MUX_MODE_GPIO GPIO2L_GPIO2A3
1203 #define REGULATOR_PWM_GPIO RK29_PIN2_PA3
1205 static struct regulator_consumer_supply pwm_consumers[] = {
1211 static struct regulator_init_data rk29_pwm_regulator_data = {
1217 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1219 .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
1220 .consumer_supplies = pwm_consumers,
1223 static struct pwm_platform_data rk29_regulator_pwm_platform_data = {
1224 .pwm_id = REGULATOR_PWM_ID,
1225 .pwm_gpio = REGULATOR_PWM_GPIO,
1226 //.pwm_iomux_name[] = REGULATOR_PWM_MUX_NAME;
1227 .pwm_iomux_name = REGULATOR_PWM_MUX_NAME,
1228 .pwm_iomux_pwm = REGULATOR_PWM_MUX_MODE,
1229 .pwm_iomux_gpio = REGULATOR_PWM_MUX_MODE_GPIO,
1230 .init_data = &rk29_pwm_regulator_data,
1233 static struct platform_device rk29_device_pwm_regulator = {
1234 .name = "pwm-voltage-regulator",
1237 .platform_data = &rk29_regulator_pwm_platform_data,
1243 /*****************************************************************************************
1245 *****************************************************************************************/
1246 #ifdef CONFIG_SDMMC0_RK29
1247 static int rk29_sdmmc0_cfg_gpio(void)
1249 rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
1250 rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
1251 rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
1252 rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
1253 rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
1254 rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
1255 rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
1256 rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5); ///GPIO5H_SDMMC0_PWR_EN); ///GPIO5H_GPIO5D5);
1257 gpio_request(RK29_PIN5_PD5,"sdmmc");
1259 gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
1261 gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
1263 gpio_direction_output(RK29_PIN5_PD5,GPIO_LOW);
1268 #define CONFIG_SDMMC0_USE_DMA
1269 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
1270 .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
1271 MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
1272 MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
1273 .host_caps = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1274 .io_init = rk29_sdmmc0_cfg_gpio,
1275 .dma_name = "sd_mmc",
1276 #ifdef CONFIG_SDMMC0_USE_DMA
1281 .detect_irq = RK29_PIN2_PA2, // INVALID_GPIO
1282 .enable_sd_wakeup = 0,
1285 #ifdef CONFIG_SDMMC1_RK29
1286 #define CONFIG_SDMMC1_USE_DMA
1287 static int rk29_sdmmc1_cfg_gpio(void)
1289 rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
1290 rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
1291 rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
1292 rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
1293 rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
1294 rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
1295 //rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_SDMMC1_DETECT_N);
1299 #ifdef CONFIG_WIFI_CONTROL_FUNC
1300 static int rk29sdk_wifi_status(struct device *dev);
1301 static int rk29sdk_wifi_status_register(void (*callback)(int card_presend, void *dev_id), void *dev_id);
1304 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N RK29_PIN1_PD6
1306 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
1307 .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
1308 MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
1309 MMC_VDD_32_33|MMC_VDD_33_34),
1310 .host_caps = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
1311 MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
1312 .io_init = rk29_sdmmc1_cfg_gpio,
1314 #ifdef CONFIG_SDMMC1_USE_DMA
1319 #ifdef CONFIG_WIFI_CONTROL_FUNC
1320 .status = rk29sdk_wifi_status,
1321 .register_status_notify = rk29sdk_wifi_status_register,
1324 .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
1329 #ifdef CONFIG_WIFI_CONTROL_FUNC
1330 #define RK29SDK_WIFI_BT_GPIO_POWER_N RK29_PIN5_PD6
1331 #define RK29SDK_WIFI_GPIO_RESET_N RK29_PIN6_PC0
1332 #define RK29SDK_BT_GPIO_RESET_N RK29_PIN6_PC4
1334 static int rk29sdk_wifi_cd = 0; /* wifi virtual 'card detect' status */
1335 static void (*wifi_status_cb)(int card_present, void *dev_id);
1336 static void *wifi_status_cb_devid;
1337 int rk29sdk_wifi_power_state = 0;
1338 int rk29sdk_bt_power_state = 0;
1340 static int rk29sdk_wifi_status(struct device *dev)
1342 return rk29sdk_wifi_cd;
1345 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
1349 wifi_status_cb = callback;
1350 wifi_status_cb_devid = dev_id;
1354 static int rk29sdk_wifi_bt_gpio_control_init(void)
1356 if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
1357 pr_info("%s: request wifi_bt power gpio failed\n", __func__);
1361 if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
1362 pr_info("%s: request wifi reset gpio failed\n", __func__);
1363 gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
1367 if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
1368 pr_info("%s: request bt reset gpio failed\n", __func__);
1369 gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
1373 gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1374 gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1375 gpio_direction_output(RK29SDK_BT_GPIO_RESET_N, GPIO_LOW);
1377 pr_info("%s: init finished\n",__func__);
1382 static int rk29sdk_wifi_power(int on)
1384 pr_info("%s: %d\n", __func__, on);
1386 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
1387 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
1389 pr_info("wifi turn on power\n");
1391 if (!rk29sdk_bt_power_state){
1392 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1394 pr_info("wifi shut off power\n");
1397 pr_info("wifi shouldn't shut off power, bt is using it!\n");
1399 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1403 rk29sdk_wifi_power_state = on;
1407 static int rk29sdk_wifi_reset_state;
1408 static int rk29sdk_wifi_reset(int on)
1410 pr_info("%s: %d\n", __func__, on);
1411 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
1413 rk29sdk_wifi_reset_state = on;
1417 int rk29sdk_wifi_set_carddetect(int val)
1419 pr_info("%s:%d\n", __func__, val);
1420 rk29sdk_wifi_cd = val;
1421 if (wifi_status_cb){
1422 wifi_status_cb(val, wifi_status_cb_devid);
1424 pr_warning("%s, nobody to notify\n", __func__);
1428 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
1430 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
1431 {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
1432 {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
1433 {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
1434 {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
1437 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
1439 if (section == PREALLOC_WLAN_SEC_NUM)
1440 return wlan_static_skb;
1442 if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
1445 if (wifi_mem_array[section].size < size)
1448 return wifi_mem_array[section].mem_ptr;
1451 int __init rk29sdk_init_wifi_mem(void)
1456 for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
1457 wlan_static_skb[i] = dev_alloc_skb(
1458 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
1460 if (!wlan_static_skb[i])
1464 for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
1465 wifi_mem_array[i].mem_ptr =
1466 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
1468 if (!wifi_mem_array[i].mem_ptr)
1474 pr_err("Failed to mem_alloc for WLAN\n");
1475 for (j = 0 ; j < i ; j++)
1476 kfree(wifi_mem_array[j].mem_ptr);
1478 i = WLAN_SKB_BUF_NUM;
1481 pr_err("Failed to skb_alloc for WLAN\n");
1482 for (j = 0 ; j < i ; j++)
1483 dev_kfree_skb(wlan_static_skb[j]);
1488 static struct wifi_platform_data rk29sdk_wifi_control = {
1489 .set_power = rk29sdk_wifi_power,
1490 .set_reset = rk29sdk_wifi_reset,
1491 .set_carddetect = rk29sdk_wifi_set_carddetect,
1492 .mem_prealloc = rk29sdk_mem_prealloc,
1494 static struct platform_device rk29sdk_wifi_device = {
1495 .name = "bcm4329_wlan",
1498 .platform_data = &rk29sdk_wifi_control,
1504 /* bluetooth rfkill device */
1505 static struct platform_device rk29sdk_rfkill = {
1506 .name = "rk29sdk_rfkill",
1511 #ifdef CONFIG_VIVANTE
1512 static struct resource resources_gpu[] = {
1517 .flags = IORESOURCE_IRQ,
1521 .start = RK29_GPU_PHYS,
1522 .end = RK29_GPU_PHYS + RK29_GPU_SIZE,
1523 .flags = IORESOURCE_MEM,
1527 .start = PMEM_GPU_BASE,
1528 .end = PMEM_GPU_BASE + PMEM_GPU_SIZE,
1529 .flags = IORESOURCE_MEM,
1532 static struct platform_device rk29_device_gpu = {
1535 .num_resources = ARRAY_SIZE(resources_gpu),
1536 .resource = resources_gpu,
1539 #ifdef CONFIG_KEYS_RK29
1540 extern struct rk29_keys_platform_data rk29_keys_pdata;
1541 static struct platform_device rk29_device_keys = {
1542 .name = "rk29-keypad",
1545 .platform_data = &rk29_keys_pdata,
1550 static void __init rk29_board_iomux_init(void)
1552 #ifdef CONFIG_RK29_PWM_REGULATOR
1553 rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
1557 static struct platform_device *devices[] __initdata = {
1558 #ifdef CONFIG_UART1_RK29
1561 #ifdef CONFIG_UART0_RK29
1564 #ifdef CONFIG_UART2_RK29
1567 #ifdef CONFIG_UART3_RK29
1571 #ifdef CONFIG_RK29_PWM_REGULATOR
1572 &rk29_device_pwm_regulator,
1574 #ifdef CONFIG_SPIM0_RK29
1575 &rk29xx_device_spi0m,
1577 #ifdef CONFIG_SPIM1_RK29
1578 &rk29xx_device_spi1m,
1580 #ifdef CONFIG_ADC_RK29
1583 #ifdef CONFIG_I2C0_RK29
1586 #ifdef CONFIG_I2C1_RK29
1589 #ifdef CONFIG_I2C2_RK29
1592 #ifdef CONFIG_I2C3_RK29
1596 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
1597 &rk29_device_iis_2ch,
1599 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
1600 &rk29_device_iis_8ch,
1603 #ifdef CONFIG_KEYS_RK29
1606 #ifdef CONFIG_SDMMC0_RK29
1607 &rk29_device_sdmmc0,
1609 #ifdef CONFIG_SDMMC1_RK29
1610 &rk29_device_sdmmc1,
1613 #ifdef CONFIG_MTD_NAND_RK29XX
1614 &rk29xx_device_nand,
1617 #ifdef CONFIG_WIFI_CONTROL_FUNC
1618 &rk29sdk_wifi_device,
1625 #ifdef CONFIG_MTD_NAND_RK29
1629 #ifdef CONFIG_FB_RK29
1631 &rk29_device_dma_cpy,
1633 #ifdef CONFIG_BACKLIGHT_RK29_BL
1634 &rk29_device_backlight,
1636 #ifdef CONFIG_RK29_VMAC
1639 #ifdef CONFIG_VIVANTE
1642 #ifdef CONFIG_VIDEO_RK29
1643 &rk29_device_camera, /* ddl@rock-chips.com : camera support */
1644 #if (CONFIG_SENSOR_IIC_ADDR_0 != 0x00)
1645 &rk29_soc_camera_pdrv_0,
1647 &rk29_soc_camera_pdrv_1,
1648 &android_pmem_cam_device,
1650 &android_pmem_device,
1651 &rk29_vpu_mem_device,
1652 #ifdef CONFIG_USB20_OTG
1653 &rk29_device_usb20_otg,
1655 #ifdef CONFIG_USB20_HOST
1656 &rk29_device_usb20_host,
1658 #ifdef CONFIG_USB11_HOST
1659 &rk29_device_usb11_host,
1661 #ifdef CONFIG_USB_ANDROID
1662 &android_usb_device,
1663 &usb_mass_storage_device,
1665 #ifdef CONFIG_RK29_IPP
1668 #ifdef CONFIG_VIDEO_RK29XX_VOUT
1669 &rk29_v4l2_output_devce,
1673 /*****************************************************************************************
1675 * author: cmc@rock-chips.com
1676 *****************************************************************************************/
1677 static int rk29_vmac_register_set(void)
1679 //config rk29 vmac as rmii, 100MHz
1680 u32 value= readl(RK29_GRF_BASE + 0xbc);
1681 value = (value & 0xfff7ff) | (0x400);
1682 writel(value, RK29_GRF_BASE + 0xbc);
1686 static int rk29_rmii_io_init(void)
1691 err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
1693 gpio_free(RK29_PIN6_PB0);
1694 printk("-------request RK29_PIN6_PB0 fail--------\n");
1698 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1699 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1704 static int rk29_rmii_io_deinit(void)
1707 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1708 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1710 gpio_free(RK29_PIN6_PB0);
1714 static int rk29_rmii_power_control(int enable)
1718 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
1719 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
1722 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1723 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1728 struct rk29_vmac_platform_data rk29_vmac_pdata = {
1729 .vmac_register_set = rk29_vmac_register_set,
1730 .rmii_io_init = rk29_rmii_io_init,
1731 .rmii_io_deinit = rk29_rmii_io_deinit,
1732 .rmii_power_control = rk29_rmii_power_control,
1735 /*****************************************************************************************
1737 * author: cmc@rock-chips.com
1738 *****************************************************************************************/
1739 #define SPI_CHIPSELECT_NUM 2
1740 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
1743 .cs_gpio = RK29_PIN2_PC1,
1744 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
1745 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
1749 .cs_gpio = RK29_PIN1_PA4,
1750 .cs_iomux_name = GPIO1A4_EMMCWRITEPRT_SPI0CS1_NAME,//if no iomux,set it NULL
1751 .cs_iomux_mode = GPIO1L_SPI0_CSN1,
1755 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
1758 .cs_gpio = RK29_PIN2_PC5,
1759 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
1760 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
1764 .cs_gpio = RK29_PIN1_PA3,
1765 .cs_iomux_name = GPIO1A3_EMMCDETECTN_SPI1CS1_NAME,//if no iomux,set it NULL
1766 .cs_iomux_mode = GPIO1L_SPI1_CSN1,
1770 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
1775 for (i=0; i<cs_num; i++) {
1776 rk29_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
1783 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
1788 static int spi_io_fix_leakage_bug(void)
1791 gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
1796 static int spi_io_resume_leakage_bug(void)
1799 gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
1804 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
1805 .num_chipselect = SPI_CHIPSELECT_NUM,
1806 .chipselect_gpios = rk29xx_spi0_cs_gpios,
1807 .io_init = spi_io_init,
1808 .io_deinit = spi_io_deinit,
1809 .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1810 .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1813 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
1814 .num_chipselect = SPI_CHIPSELECT_NUM,
1815 .chipselect_gpios = rk29xx_spi1_cs_gpios,
1816 .io_init = spi_io_init,
1817 .io_deinit = spi_io_deinit,
1818 .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1819 .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1822 /*****************************************************************************************
1823 * xpt2046 touch panel
1824 * author: cmc@rock-chips.com
1825 *****************************************************************************************/
1826 #define XPT2046_GPIO_INT RK29_PIN0_PA3
1827 #define DEBOUNCE_REPTIME 3
1829 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI)
1830 static struct xpt2046_platform_data xpt2046_info = {
1839 .debounce_rep = DEBOUNCE_REPTIME,
1841 .gpio_pendown = XPT2046_GPIO_INT,
1842 .penirq_recheck_delay_usecs = 1,
1844 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)
1845 static struct xpt2046_platform_data xpt2046_info = {
1854 .debounce_rep = DEBOUNCE_REPTIME,
1856 .gpio_pendown = XPT2046_GPIO_INT,
1857 .penirq_recheck_delay_usecs = 1,
1859 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
1860 static struct xpt2046_platform_data xpt2046_info = {
1869 .debounce_rep = DEBOUNCE_REPTIME,
1871 .gpio_pendown = XPT2046_GPIO_INT,
1873 .penirq_recheck_delay_usecs = 1,
1875 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1876 static struct xpt2046_platform_data xpt2046_info = {
1885 .debounce_rep = DEBOUNCE_REPTIME,
1887 .gpio_pendown = XPT2046_GPIO_INT,
1889 .penirq_recheck_delay_usecs = 1,
1893 static struct spi_board_info board_spi_devices[] = {
1894 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\
1895 ||defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1897 .modalias = "xpt2046_ts",
1899 .max_speed_hz = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
1901 .irq = XPT2046_GPIO_INT,
1902 .platform_data = &xpt2046_info,
1908 static void __init rk29_gic_init_irq(void)
1910 gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
1911 gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
1914 static void __init machine_rk29_init_irq(void)
1916 rk29_gic_init_irq();
1920 static void __init machine_rk29_board_init(void)
1922 rk29_board_iomux_init();
1926 platform_add_devices(devices, ARRAY_SIZE(devices));
1927 #ifdef CONFIG_I2C0_RK29
1928 i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
1929 ARRAY_SIZE(board_i2c0_devices));
1931 #ifdef CONFIG_I2C1_RK29
1932 i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
1933 ARRAY_SIZE(board_i2c1_devices));
1935 #ifdef CONFIG_I2C2_RK29
1936 i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
1937 ARRAY_SIZE(board_i2c2_devices));
1939 #ifdef CONFIG_I2C3_RK29
1940 i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
1941 ARRAY_SIZE(board_i2c3_devices));
1944 spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1946 #ifdef CONFIG_WIFI_CONTROL_FUNC
1947 rk29sdk_wifi_bt_gpio_control_init();
1948 rk29sdk_init_wifi_mem();
1951 board_usb_detect_init(RK29_PIN0_PA0);
1954 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
1955 char **cmdline, struct meminfo *mi)
1958 mi->bank[0].start = RK29_SDRAM_PHYS;
1959 mi->bank[0].node = PHYS_TO_NID(RK29_SDRAM_PHYS);
1960 mi->bank[0].size = LINUX_SIZE;
1963 static void __init machine_rk29_mapio(void)
1965 rk29_map_common_io();
1966 rk29_setup_early_printk();
1968 rk29_clock_init(periph_pll_288mhz);
1972 MACHINE_START(RK29, "RK29board")
1973 /* UART for LL DEBUG */
1974 .phys_io = RK29_UART1_PHYS,
1975 .io_pg_offst = ((RK29_UART1_BASE) >> 18) & 0xfffc,
1976 .boot_params = RK29_SDRAM_PHYS + 0x88000,
1977 .fixup = machine_rk29_fixup,
1978 .map_io = machine_rk29_mapio,
1979 .init_irq = machine_rk29_init_irq,
1980 .init_machine = machine_rk29_board_init,
1981 .timer = &rk29_timer,