1 /* linux/arch/arm/mach-rk2818/board-midsdk.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>
26 #include <mach/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/mach/flash.h>
32 #include <mach/irqs.h>
33 #include <mach/board.h>
34 #include <mach/rk2818_iomap.h>
35 #include <mach/iomux.h>
36 #include <mach/gpio.h>
38 #include <linux/mtd/nand.h>
39 #include <linux/mtd/partitions.h>
40 #include <linux/dm9000.h>
45 /* --------------------------------------------------------------------
46 * ÉùÃ÷ÁËrk2818_gpioBankÊý×飬²¢¶¨ÒåÁËGPIO¼Ä´æÆ÷×éIDºÍ¼Ä´æÆ÷»ùµØÖ·¡£
47 * -------------------------------------------------------------------- */
49 static struct rk2818_gpio_bank rk2818_gpioBank[] = {
52 .offset = RK2818_GPIO0_BASE,
57 .offset = RK2818_GPIO0_BASE,
62 .offset = RK2818_GPIO0_BASE,
67 .offset = RK2818_GPIO0_BASE,
72 .offset = RK2818_GPIO1_BASE,
77 .offset = RK2818_GPIO1_BASE,
82 .offset = RK2818_GPIO1_BASE,
87 .offset = RK2818_GPIO1_BASE,
92 //IOÓ³É䷽ʽÃèÊö £¬Ã¿¸öΪһ¶ÎÏßÐÔÁ¬ÐøÓ³Éä
93 static struct map_desc rk2818_io_desc[] __initdata = {
96 .virtual = RK2818_MCDMA_BASE, //ÐéÄâµØÖ·
97 .pfn = __phys_to_pfn(RK2818_MCDMA_PHYS), //ÎïÀíµØÖ·£¬ÐëÓëÒ³±í¶ÔÆë
98 .length = RK2818_MCDMA_SIZE, //³¤¶È
99 .type = MT_DEVICE //Ó³É䷽ʽ
103 .virtual = RK2818_DWDMA_BASE,
104 .pfn = __phys_to_pfn(RK2818_DWDMA_PHYS),
105 .length = RK2818_DWDMA_SIZE,
110 .virtual = RK2818_INTC_BASE,
111 .pfn = __phys_to_pfn(RK2818_INTC_PHYS),
112 .length = RK2818_INTC_SIZE,
117 .virtual = RK2818_NANDC_BASE,
118 .pfn = __phys_to_pfn(RK2818_NANDC_PHYS),
119 .length = RK2818_NANDC_SIZE,
124 .virtual = RK2818_SDRAMC_BASE,
125 .pfn = __phys_to_pfn(RK2818_SDRAMC_PHYS),
126 .length = RK2818_SDRAMC_SIZE,
131 .virtual = RK2818_ARMDARBITER_BASE,
132 .pfn = __phys_to_pfn(RK2818_ARMDARBITER_PHYS),
133 .length = RK2818_ARMDARBITER_SIZE,
138 .virtual = RK2818_APB_BASE,
139 .pfn = __phys_to_pfn(RK2818_APB_PHYS),
145 .virtual = RK2818_WDT_BASE,
146 .pfn = __phys_to_pfn(RK2818_WDT_PHYS),
147 .length = 0xa0000, ///apb bus i2s i2c spi no map in this
151 /*****************************************************************************************
154 *****************************************************************************************/
155 void rk2818_sdmmc0_cfg_gpio(struct platform_device *dev)
157 rk2818_mux_api_set(GPIOF3_APWM1_MMC0DETN_NAME, IOMUXA_SDMMC1_DETECT_N);
158 rk2818_mux_api_set(GPIOH_MMC0D_SEL_NAME, IOMUXA_SDMMC0_DATA123);
159 rk2818_mux_api_set(GPIOH_MMC0_SEL_NAME, IOMUXA_SDMMC0_CMD_DATA0_CLKOUT);
162 void rk2818_sdmmc1_cfg_gpio(struct platform_device *dev)
164 rk2818_mux_api_set(GPIOG_MMC1_SEL_NAME, IOMUXA_SDMMC1_CMD_DATA0_CLKOUT);
165 rk2818_mux_api_set(GPIOG_MMC1D_SEL_NAME, IOMUXA_SDMMC1_DATA123);
167 /* wifi power up (gpio control) */
168 rk2818_mux_api_set(GPIOH7_HSADCCLK_SEL_NAME,IOMUXB_GPIO1_D7);
169 rk2818_mux_api_set(GPIOF5_APWM3_DPWM3_NAME,IOMUXB_GPIO1_B5);
170 gpio_request(RK2818_PIN_PH7, "sdio");
171 gpio_direction_output(RK2818_PIN_PH7,GPIO_HIGH);
175 #define CONFIG_SDMMC0_USE_DMA
176 #define CONFIG_SDMMC1_USE_DMA
177 struct rk2818_sdmmc_platform_data default_sdmmc0_data = {
178 .host_ocr_avail = (MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
179 MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
180 MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
181 .host_caps = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
182 .cfg_gpio = rk2818_sdmmc0_cfg_gpio,
184 .dma_name = "sd_mmc",
185 #ifdef CONFIG_SDMMC0_USE_DMA
191 struct rk2818_sdmmc_platform_data default_sdmmc1_data = {
192 .host_ocr_avail = (MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
193 MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
194 MMC_VDD_32_33|MMC_VDD_33_34),
195 .host_caps = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
196 MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
197 .cfg_gpio = rk2818_sdmmc1_cfg_gpio,
200 #ifdef CONFIG_SDMMC1_USE_DMA
207 /*****************************************************************************************
208 * extern gpio devices
210 *****************************************************************************************/
211 #if defined (CONFIG_GPIO_PCA9554)
212 struct rk2818_gpio_expander_info extern_gpio_settinginfo[] = {
214 .gpio_num =RK2818_PIN_PI0,
216 //.pin_value =GPIO_HIGH,
220 .gpio_num =RK2818_PIN_PI4,// tp3
222 //.pin_value =GPIO_HIGH,
226 .gpio_num =RK2818_PIN_PI5,//tp4
228 //.pin_value =GPIO_HIGH,
231 .gpio_num =RK2818_PIN_PI6,//tp2
232 .pin_type = GPIO_OUT,
233 //.pin_value =GPIO_HIGH,
236 .gpio_num =RK2818_PIN_PI7,//tp1
237 .pin_type = GPIO_OUT,
238 .pin_value =GPIO_HIGH,
245 struct pca9554_platform_data rk2818_pca9554_data={
246 .gpio_base=GPIOS_EXPANDER_BASE,
247 .gpio_pin_num=CONFIG_EXPANDED_GPIO_NUM,
248 .gpio_irq_start=NR_AIC_IRQS + 2*NUM_GROUP,
249 .irq_pin_num=CONFIG_EXPANDED_GPIO_IRQ_NUM,
250 .pca9954_irq_pin=RK2818_PIN_PE2,
251 .settinginfo=extern_gpio_settinginfo,
252 .settinginfolen=ARRAY_SIZE(extern_gpio_settinginfo),
257 /*****************************************************************************************
260 *****************************************************************************************/
261 void rk2818_i2c0_cfg_gpio(struct platform_device *dev)
263 rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, IOMUXA_I2C0);
266 void rk2818_i2c1_cfg_gpio(struct platform_device *dev)
268 rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_I2C1);
270 struct rk2818_i2c_platform_data default_i2c0_data = {
274 .scl_rate = 400*1000,
275 .mode = I2C_MODE_IRQ, //I2C_MODE_POLL
276 .cfg_gpio = rk2818_i2c0_cfg_gpio,
278 struct rk2818_i2c_platform_data default_i2c1_data = {
279 #ifdef CONFIG_I2C0_RK2818
286 .scl_rate = 400*1000,
287 .mode = I2C_MODE_IRQ, //I2C_MODE_POLL
288 .cfg_gpio = rk2818_i2c1_cfg_gpio,
291 struct rk2818_i2c_spi_data default_i2c2_data = {
295 .scl_rate = 400*1000,
298 struct rk2818_i2c_spi_data default_i2c3_data = {
303 .scl_rate = 400*1000,
306 static struct i2c_board_info __initdata board_i2c0_devices[] = {
307 #if defined (CONFIG_RK1000_CONTROL)
309 .type = "rk1000_control",
315 #if defined (CONFIG_RK1000_TVOUT)
317 .type = "rk1000_tvout",
322 #if defined (CONFIG_SND_SOC_RK1000)
324 .type = "rk1000_i2c_codec",
329 #if defined (CONFIG_SND_SOC_WM8988)
337 static struct i2c_board_info __initdata board_i2c1_devices[] = {
338 #if defined (CONFIG_RTC_HYM8563)
340 .type = "rtc_hym8563",
345 #if defined (CONFIG_FM_QN8006)
352 #if defined (CONFIG_GPIO_PCA9554)
354 .type = "extend_gpio_pca9554",
357 .platform_data=&rk2818_pca9554_data.gpio_base,
360 #if defined (CONFIG_PMIC_LP8725)
370 static struct i2c_board_info __initdata board_i2c2_devices[] = {
373 static struct i2c_board_info __initdata board_i2c3_devices[] = {
374 #if defined (CONFIG_SND_SOC_WM8994)
383 /*****************************************************************************************
386 *****************************************************************************************/
387 static struct spi_board_info board_spi_devices[] = {
388 #if defined(CONFIG_SPI_FPGA)
389 { /* fpga ice65l08xx */
390 .modalias = "spi_fpga",
392 .max_speed_hz = 8 * 1000 * 1000,
397 #if defined(CONFIG_ENC28J60)
399 .modalias = "enc28j60",
401 .max_speed_hz = 12 * 1000 * 1000,
406 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
408 .modalias = "xpt2046_ts",
410 .max_speed_hz = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
412 .irq = RK2818_PIN_PE3,
417 /*rk2818_fb gpio information*/
418 static struct rk2818_fb_gpio rk2818_fb_gpio_info = {
419 .display_on = (GPIO_LOW<<16)|RK2818_PIN_PA2,
424 /*rk2818_fb iomux information*/
425 static struct rk2818_fb_iomux rk2818_fb_iomux_info = {
426 .data16 = GPIOC_LCDC16BIT_SEL_NAME,
427 .data18 = GPIOC_LCDC18BIT_SEL_NAME,
428 .data24 = GPIOC_LCDC24BIT_SEL_NAME,
429 .den = CXGPIO_LCDDEN_SEL_NAME,
430 .vsync = CXGPIO_LCDVSYNC_SEL_NAME,
434 struct rk2818_fb_mach_info rk2818_fb_mach_info = {
435 .gpio = &rk2818_fb_gpio_info,
436 .iomux = &rk2818_fb_iomux_info,
439 struct rk2818bl_info rk2818_bl_info = {
441 .pw_pin = GPIO_HIGH | (RK2818_PIN_PA3<< 8) ,
443 .pw_iomux = GPIOA23_UART2_SEL_NAME,
447 #define NET_INT_PIN RK2818_PIN_PE2
449 int dm9k_gpio_set(void)
452 #ifdef CONFIG_DM9000_CHIP_SELECT
453 switch (CONFIG_DM9000_CHIP_SELECT) {
455 rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
458 rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2);
461 rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3);
465 rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45);
469 rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL_NAME, IOMUXA_FLASH_CS67);
477 rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_GPIO1_A12);
478 if (gpio_request(NET_INT_PIN, "dm9000 interrupt")) {
479 gpio_free(NET_INT_PIN);
480 rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME);
481 printk("[fun:%s line:%d], request gpio for net interrupt fail\n", __func__,__LINE__);
485 gpio_pull_updown(NET_INT_PIN, GPIOPullDown);
486 gpio_direction_input(NET_INT_PIN);
490 #ifdef CONFIG_DM9000_CHIP_SELECT
491 switch (CONFIG_DM9000_CHIP_SELECT) {
493 rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME);
496 rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME);
499 rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME);
503 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME);
507 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME);
515 void dm9k_gpio_free(void)
517 gpio_free(NET_INT_PIN);
518 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME);
519 #ifdef CONFIG_DM9000_CHIP_SELECT
520 switch (CONFIG_DM9000_CHIP_SELECT) {
522 rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME);
525 rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME);
528 rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME);
532 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME);
536 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME);
544 struct dm9000_plat_data dm9k_platdata = {
545 .flags = DM9000_PLATF_8BITONLY,
546 .pin_int = NET_INT_PIN,
547 .net_gpio_set = dm9k_gpio_set,
548 .net_gpio_free = dm9k_gpio_free,
552 static struct platform_device *devices[] __initdata = {
553 &rk2818_device_uart1,
554 #ifdef CONFIG_I2C0_RK2818
557 #ifdef CONFIG_I2C1_RK2818
560 #ifdef CONFIG_SDMMC0_RK2818
561 &rk2818_device_sdmmc0,
563 #ifdef CONFIG_SDMMC1_RK2818
564 &rk2818_device_sdmmc1,
568 #if defined(CONFIG_ANDROID_PMEM)
570 &rk2818_device_pmem_dsp,
573 &rk2818_device_adckey,
574 &rk2818_device_battery,
576 &rk2818_device_backlight,
578 #ifdef CONFIG_MTD_NAND_RK2818
585 #ifdef CONFIG_DWC_OTG
586 &rk2818_device_dwc_otg,
588 #ifdef CONFIG_RK2818_HOST11
589 &rk2818_device_host11,
591 #ifdef CONFIG_USB_ANDROID
593 &usb_mass_storage_device,
598 extern struct sys_timer rk2818_timer;
599 #define POWER_PIN RK2818_PIN_PA3
600 static void rk2818_power_on(void)
603 ret = gpio_request(POWER_PIN, NULL);
605 printk("failed to request power_off gpio\n");
609 gpio_pull_updown(POWER_PIN, GPIOPullUp);
610 ret = gpio_direction_output(POWER_PIN, GPIO_HIGH);
612 printk("failed to set power_off gpio output\n");
616 gpio_set_value(POWER_PIN, 1);/*power on*/
619 gpio_free(POWER_PIN);
622 static void rk2818_power_off(void)
624 printk("shut down system now ...\n");
625 gpio_set_value(POWER_PIN, 0);/*power down*/
628 void lcd_set_iomux(u8 enable)
634 rk2818_mux_api_set(CXGPIO_HSADC_SEL_NAME, 0);
635 ret = gpio_request(RK2818_PIN_PA4, NULL);
638 gpio_free(RK2818_PIN_PA4);
639 printk(">>>>>> lcd cs gpio_request err \n ");
643 rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, 0);
645 ret = gpio_request(RK2818_PIN_PE7, NULL);
648 gpio_free(RK2818_PIN_PE7);
649 printk(">>>>>> lcd clk gpio_request err \n ");
653 ret = gpio_request(RK2818_PIN_PE6, NULL);
656 gpio_free(RK2818_PIN_PE6);
657 printk(">>>>>> lcd txd gpio_request err \n ");
663 gpio_free(RK2818_PIN_PA4);
664 //rk2818_mux_api_set(CXGPIO_HSADC_SEL_NAME, 1);
665 rk2818_mux_api_mode_resume(CXGPIO_HSADC_SEL_NAME);
667 gpio_free(RK2818_PIN_PE7);
668 gpio_free(RK2818_PIN_PE6);
669 //rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, 2);
670 rk2818_mux_api_mode_resume(GPIOE_U1IR_I2C1_NAME);
678 struct lcd_td043mgea1_data lcd_td043mgea1 = {
679 .pin_txd = RK2818_PIN_PE6,
680 .pin_clk = RK2818_PIN_PE7,
681 .pin_cs = RK2818_PIN_PA4,
682 .screen_set_iomux = lcd_set_iomux,
686 static ADC_keyst gAdcValueTab[] =
688 {95, AD2KEY1},///VOLUME_DOWN
689 {192, AD2KEY2},///VOLUME_UP
690 {280, AD2KEY3},///MENU
691 {376, AD2KEY4},///HOME
692 {467, AD2KEY5},///BACK
693 {560, AD2KEY6},///CALL
697 static unsigned char gInitKeyCode[] =
699 AD2KEY1,AD2KEY2,AD2KEY3,AD2KEY4,AD2KEY5,AD2KEY6,
700 ENDCALL,KEYSTART,KEY_WAKEUP,
703 struct adc_key_data rk2818_adc_key = {
704 .pin_playon = RK2818_PIN_PA3,
710 .adc_key_table = gAdcValueTab,
711 .initKeyCode = gInitKeyCode,
715 static void __init machine_rk2818_init_irq(void)
718 rk2818_gpio_init(rk2818_gpioBank, 8);
719 rk2818_gpio_irq_setup();
722 static void __init machine_rk2818_board_init(void)
725 pm_power_off = rk2818_power_off;
726 #ifdef CONFIG_I2C0_RK2818
727 i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
728 ARRAY_SIZE(board_i2c0_devices));
730 #ifdef CONFIG_I2C1_RK2818
731 i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
732 ARRAY_SIZE(board_i2c1_devices));
734 #ifdef CONFIG_SPI_I2C
735 i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
736 ARRAY_SIZE(board_i2c2_devices));
737 i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
738 ARRAY_SIZE(board_i2c3_devices));
740 platform_add_devices(devices, ARRAY_SIZE(devices));
741 spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
742 rk2818_mux_api_set(GPIOB4_SPI0CS0_MMC0D4_NAME,IOMUXA_GPIO0_B4); //IOMUXA_SPI0_CSN0);//use for gpio SPI CS0
743 rk2818_mux_api_set(GPIOB0_SPI0CSN1_MMC1PCA_NAME,IOMUXA_GPIO0_B0); //IOMUXA_SPI0_CSN1);//use for gpio SPI CS1
744 rk2818_mux_api_set(GPIOB_SPI0_MMC0_NAME,IOMUXA_SPI0);//use for SPI CLK SDI SDO
747 static void __init machine_rk2818_mapio(void)
749 iotable_init(rk2818_io_desc, ARRAY_SIZE(rk2818_io_desc));
754 MACHINE_START(RK2818, "RK28board")
756 /* UART for LL DEBUG */
757 .phys_io = 0x18002000,
758 .io_pg_offst = ((0xFF100000) >> 18) & 0xfffc,
759 .boot_params = RK2818_SDRAM_PHYS + 0xf8000,
760 .map_io = machine_rk2818_mapio,
761 .init_irq = machine_rk2818_init_irq,
762 .init_machine = machine_rk2818_board_init,
763 .timer = &rk2818_timer,