1 /* arch/arm/mach-rk2928/devices.c
3 * Copyright (C) 2012 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.
17 #include <linux/kernel.h>
18 #include <linux/platform_device.h>
19 #ifdef CONFIG_USB_ANDROID
20 #include <linux/usb/android_composite.h>
22 #include <linux/delay.h>
23 #include <linux/dma-mapping.h>
25 #include <mach/irqs.h>
26 #include <mach/board.h>
27 #include <mach/dma-pl330.h>
28 #include <mach/gpio.h>
29 #include <mach/iomux.h>
30 #include <plat/rk_fiq_debugger.h>
32 #ifdef CONFIG_ADC_RK30
33 static struct resource rk30_adc_resource[] = {
37 .flags = IORESOURCE_IRQ,
40 .start = RK2928_SARADC_PHYS,
41 .end = RK2928_SARADC_PHYS + RK2928_SARADC_SIZE - 1,
42 .flags = IORESOURCE_MEM,
46 struct platform_device device_adc = {
49 .num_resources = ARRAY_SIZE(rk30_adc_resource),
50 .resource = rk30_adc_resource,
54 static u64 dma_dmamask = DMA_BIT_MASK(32);
56 static struct resource resource_dmac[] = {
58 .start = RK2928_DMAC_PHYS,
59 .end = RK2928_DMAC_PHYS + RK2928_DMAC_SIZE -1,
60 .flags = IORESOURCE_MEM,
65 .flags = IORESOURCE_IRQ,
69 static struct rk29_pl330_platdata dmac_pdata = {
71 [0] = DMACH_I2S0_8CH_TX,
72 [1] = DMACH_I2S0_8CH_RX,
84 [13] = DMACH_DMAC1_MEMTOMEM,
106 static struct platform_device device_dmac = {
107 .name = "rk29-pl330",
109 .num_resources = ARRAY_SIZE(resource_dmac),
110 .resource = resource_dmac,
112 .dma_mask = &dma_dmamask,
113 .coherent_dma_mask = DMA_BIT_MASK(32),
114 .platform_data = &dmac_pdata,
118 static struct platform_device *rk2928_dmacs[] __initdata = {
122 static void __init rk2928_init_dma(void)
124 platform_add_devices(rk2928_dmacs, ARRAY_SIZE(rk2928_dmacs));
127 #ifdef CONFIG_UART0_RK29
128 static struct resource resources_uart0[] = {
132 .flags = IORESOURCE_IRQ,
135 .start = RK2928_UART0_PHYS,
136 .end = RK2928_UART0_PHYS + RK2928_UART0_SIZE - 1,
137 .flags = IORESOURCE_MEM,
141 static struct platform_device device_uart0 = {
144 .num_resources = ARRAY_SIZE(resources_uart0),
145 .resource = resources_uart0,
149 #ifdef CONFIG_UART1_RK29
150 static struct resource resources_uart1[] = {
154 .flags = IORESOURCE_IRQ,
157 .start = RK2928_UART1_PHYS,
158 .end = RK2928_UART1_PHYS + RK2928_UART1_SIZE - 1,
159 .flags = IORESOURCE_MEM,
163 static struct platform_device device_uart1 = {
166 .num_resources = ARRAY_SIZE(resources_uart1),
167 .resource = resources_uart1,
171 #ifdef CONFIG_UART2_RK29
172 static struct resource resources_uart2[] = {
176 .flags = IORESOURCE_IRQ,
179 .start = RK2928_UART2_PHYS,
180 .end = RK2928_UART2_PHYS + RK2928_UART2_SIZE - 1,
181 .flags = IORESOURCE_MEM,
185 static struct platform_device device_uart2 = {
188 .num_resources = ARRAY_SIZE(resources_uart2),
189 .resource = resources_uart2,
193 static void __init rk2928_init_uart(void)
195 #ifdef CONFIG_UART0_RK29
196 platform_device_register(&device_uart0);
198 #ifdef CONFIG_UART1_RK29
199 platform_device_register(&device_uart1);
201 #ifdef CONFIG_UART2_RK29
202 platform_device_register(&device_uart2);
207 #ifdef CONFIG_I2C_RK30
208 #ifdef CONFIG_I2C0_CONTROLLER_RK29
209 #define I2C0_ADAP_TYPE I2C_RK29_ADAP
210 #define I2C0_START RK2928_I2C0_PHYS
211 #define I2C0_END RK2928_I2C0_PHYS + RK2928_I2C0_SIZE - 1
213 #ifdef CONFIG_I2C0_CONTROLLER_RK30
214 #define I2C0_ADAP_TYPE I2C_RK30_ADAP
215 #define I2C0_START RK2928_RKI2C0_PHYS
216 #define I2C0_END RK2928_RKI2C0_PHYS + RK2928_RKI2C0_SIZE - 1
219 #ifdef CONFIG_I2C1_CONTROLLER_RK29
220 #define I2C1_ADAP_TYPE I2C_RK29_ADAP
221 #define I2C1_START RK2928_I2C1_PHYS
222 #define I2C1_END RK2928_I2C1_PHYS + RK2928_I2C1_SIZE - 1
224 #ifdef CONFIG_I2C1_CONTROLLER_RK30
225 #define I2C1_ADAP_TYPE I2C_RK30_ADAP
226 #define I2C1_START RK2928_RKI2C1_PHYS
227 #define I2C1_END RK2928_RKI2C1_PHYS + RK2928_RKI2C1_SIZE - 1
230 #ifdef CONFIG_I2C2_CONTROLLER_RK29
231 #define I2C2_ADAP_TYPE I2C_RK29_ADAP
232 #define I2C2_START RK2928_I2C2_PHYS
233 #define I2C2_END RK2928_I2C2_PHYS + RK2928_I2C2_SIZE - 1
235 #ifdef CONFIG_I2C2_CONTROLLER_RK30
236 #define I2C2_ADAP_TYPE I2C_RK30_ADAP
237 #define I2C2_START RK2928_RKI2C2_PHYS
238 #define I2C2_END RK2928_RKI2C2_PHYS + RK2928_RKI2C2_SIZE - 1
241 #ifdef CONFIG_I2C3_CONTROLLER_RK29
242 #define I2C3_ADAP_TYPE I2C_RK29_ADAP
243 #define I2C3_START RK2928_I2C3_PHYS
244 #define I2C3_END RK2928_I2C3_PHYS + RK2928_I2C3_SIZE - 1
246 #ifdef CONFIG_I2C3_CONTROLLER_RK30
247 #define I2C3_ADAP_TYPE I2C_RK30_ADAP
248 #define I2C3_START RK2928_RKI2C3_PHYS
249 #define I2C3_END RK2928_RKI2C3_PHYS + RK2928_RKI2C3_SIZE - 1
255 unsigned int scl_i2c_mode;
256 unsigned int scl_gpio_mode;
260 unsigned int sda_i2c_mode;
261 unsigned int sda_gpio_mode;
265 static struct i2c_iomux iomux[] = {
267 .scl_pin = RK2928_PIN0_PA0,
268 .scl_name = GPIO0A0_I2C0_SCL_NAME,
269 .scl_i2c_mode = GPIO0A_I2C0_SCL,
271 .sda_pin = RK2928_PIN0_PA1,
272 .sda_name = GPIO0A1_I2C0_SDA_NAME,
273 .sda_i2c_mode = GPIO0A_I2C0_SDA,
278 .scl_pin = RK2928_PIN0_PA2,
279 .scl_name = GPIO0A2_I2C1_SCL_NAME,
280 .scl_i2c_mode = GPIO0A_I2C1_SCL,
282 .sda_pin = RK2928_PIN0_PA3,
283 .sda_name = GPIO0A3_I2C1_SDA_NAME,
284 .sda_i2c_mode = GPIO0A_I2C1_SDA,
289 .scl_pin = RK2928_PIN2_PC5,
290 .scl_name = GPIO2C5_LCDC0_D19_LCDC1_D19_I2C2_SCL_NAME,
291 .scl_i2c_mode = GPIO2C_I2C2_SCL,
293 .sda_pin = RK2928_PIN2_PC4,
294 .sda_name = GPIO2C4_LCDC0_D18_LCDC1_D18_I2C2_SDA_NAME,
295 .sda_i2c_mode = GPIO2C_I2C2_SDA,
300 .scl_pin = RK2928_PIN0_PA6,
301 .scl_name = GPIO0A6_I2C3_SCL_HDMI_DDCSCL_NAME,
302 .scl_i2c_mode = GPIO0A_I2C3_SCL,
304 .sda_pin = RK2928_PIN0_PA7,
305 .sda_name = GPIO0A7_I2C3_SDA_HDMI_DDCSDA_NAME,
306 .sda_i2c_mode = GPIO0A_I2C3_SDA,
311 static int i2c_check_idle(int id)
313 int sda_level, scl_level;
315 if(id < 0 || id > 3){
316 printk("Error: id: %d\n", id);
319 rk30_mux_api_set(iomux[id].scl_name, iomux[id].scl_gpio_mode);
320 rk30_mux_api_set(iomux[id].sda_name, iomux[id].sda_gpio_mode);
322 gpio_request(iomux[id].scl_pin, iomux[id].req_name);
323 gpio_request(iomux[id].sda_pin, iomux[id].req_name);
325 gpio_direction_input(iomux[id].scl_pin);
326 gpio_direction_input(iomux[id].sda_pin);
328 scl_level = gpio_get_value(iomux[id].scl_pin);
329 sda_level = gpio_get_value(iomux[id].sda_pin);
331 gpio_free(iomux[id].scl_pin);
332 gpio_free(iomux[id].sda_pin);
334 rk30_mux_api_set(iomux[id].scl_name, iomux[id].scl_i2c_mode);
335 rk30_mux_api_set(iomux[id].sda_name, iomux[id].sda_i2c_mode);
337 if(sda_level == 1 && scl_level == 1)
339 else if(sda_level == 0 && scl_level == 1)
341 else if(sda_level == 1 && scl_level == 0)
347 #ifdef CONFIG_I2C2_RK30
348 static struct rk30_i2c_platform_data default_i2c0_data = {
350 .is_div_from_arm = 1,
351 .adap_type = I2C0_ADAP_TYPE,
352 .check_idle = &i2c_check_idle,
355 static struct resource resources_i2c0[] = {
359 .flags = IORESOURCE_IRQ,
364 .flags = IORESOURCE_MEM,
368 static struct platform_device device_i2c0 = {
371 .num_resources = ARRAY_SIZE(resources_i2c0),
372 .resource = resources_i2c0,
374 .platform_data = &default_i2c0_data,
379 #ifdef CONFIG_I2C1_RK30
380 static struct rk30_i2c_platform_data default_i2c1_data = {
382 .is_div_from_arm = 1,
383 .adap_type = I2C1_ADAP_TYPE,
384 .check_idle = &i2c_check_idle,
387 static struct resource resources_i2c1[] = {
391 .flags = IORESOURCE_IRQ,
396 .flags = IORESOURCE_MEM,
400 static struct platform_device device_i2c1 = {
403 .num_resources = ARRAY_SIZE(resources_i2c1),
404 .resource = resources_i2c1,
406 .platform_data = &default_i2c1_data,
411 #ifdef CONFIG_I2C2_RK30
412 static struct rk30_i2c_platform_data default_i2c2_data = {
414 .is_div_from_arm = 0,
415 .adap_type = I2C2_ADAP_TYPE,
416 .check_idle = &i2c_check_idle,
419 static struct resource resources_i2c2[] = {
423 .flags = IORESOURCE_IRQ,
428 .flags = IORESOURCE_MEM,
432 static struct platform_device device_i2c2 = {
435 .num_resources = ARRAY_SIZE(resources_i2c2),
436 .resource = resources_i2c2,
438 .platform_data = &default_i2c2_data,
443 #ifdef CONFIG_I2C3_RK30
444 static struct rk30_i2c_platform_data default_i2c3_data = {
446 .is_div_from_arm = 0,
447 .adap_type = I2C3_ADAP_TYPE,
448 .check_idle = &i2c_check_idle,
451 static struct resource resources_i2c3[] = {
455 .flags = IORESOURCE_IRQ,
460 .flags = IORESOURCE_MEM,
464 static struct platform_device device_i2c3 = {
467 .num_resources = ARRAY_SIZE(resources_i2c3),
468 .resource = resources_i2c3,
470 .platform_data = &default_i2c3_data,
475 #ifdef CONFIG_I2C_GPIO_RK30
476 static struct platform_device device_i2c_gpio = {
480 .platform_data = &default_i2c_gpio_data,
485 static void __init rk2928_init_i2c(void)
487 #ifdef CONFIG_I2C0_RK30
488 platform_device_register(&device_i2c0);
490 #ifdef CONFIG_I2C1_RK30
491 platform_device_register(&device_i2c1);
493 #ifdef CONFIG_I2C2_RK30
494 platform_device_register(&device_i2c2);
496 #ifdef CONFIG_I2C3_RK30
497 platform_device_register(&device_i2c3);
499 #ifdef CONFIG_I2C_GPIO_RK30
500 platform_device_register(&device_i2c_gpio);
505 #if defined(CONFIG_SPIM0_RK29) || defined(CONFIG_SPIM1_RK29)
506 /*****************************************************************************************
508 * author: cmc@rock-chips.com
509 *****************************************************************************************/
510 #define SPI_CHIPSELECT_NUM 2
512 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
516 for (i = 0; i < cs_num; i++) {
517 rk30_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
523 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
528 static int spi_io_fix_leakage_bug(void)
531 gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
536 static int spi_io_resume_leakage_bug(void)
539 gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
546 * rk29xx spi master device
548 #ifdef CONFIG_SPIM0_RK29
549 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
552 .cs_gpio = RK2928_PIN1_PB3,
553 .cs_iomux_name = GPIO1B3_SPI_CSN0_UART1_RTSN_NAME,
554 .cs_iomux_mode = GPIO1B_SPI_CSN0,
558 .cs_gpio = RK2928_PIN1_PB4,
559 .cs_iomux_name = GPIO1B4_SPI_CSN1_UART1_CTSN_NAME,//if no iomux,set it NULL
560 .cs_iomux_mode = GPIO1B_SPI_CSN1,
564 static struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
565 .num_chipselect = SPI_CHIPSELECT_NUM,
566 .chipselect_gpios = rk29xx_spi0_cs_gpios,
567 .io_init = spi_io_init,
568 .io_deinit = spi_io_deinit,
569 .io_fix_leakage_bug = spi_io_fix_leakage_bug,
570 .io_resume_leakage_bug = spi_io_resume_leakage_bug,
573 static struct resource rk29_spi0_resources[] = {
577 .flags = IORESOURCE_IRQ,
580 .start = RK2928_SPI_PHYS,
581 .end = RK2928_SPI_PHYS + RK2928_SPI_SIZE - 1,
582 .flags = IORESOURCE_MEM,
585 .start = DMACH_SPI0_TX,
586 .end = DMACH_SPI0_TX,
587 .flags = IORESOURCE_DMA,
590 .start = DMACH_SPI0_RX,
591 .end = DMACH_SPI0_RX,
592 .flags = IORESOURCE_DMA,
596 struct platform_device rk29xx_device_spi0m = {
597 .name = "rk29xx_spim",
599 .num_resources = ARRAY_SIZE(rk29_spi0_resources),
600 .resource = rk29_spi0_resources,
602 .dma_mask = &dma_dmamask,
603 .coherent_dma_mask = DMA_BIT_MASK(32),
604 .platform_data = &rk29xx_spi0_platdata,
609 static void __init rk2928_init_spim(void)
611 #ifdef CONFIG_SPIM0_RK29
612 platform_device_register(&rk29xx_device_spi0m);
616 #ifdef CONFIG_MTD_NAND_RK29XX
617 static struct resource resources_nand[] = {
619 .start = RK2928_NANDC_PHYS,
620 .end = RK2928_NANDC_PHYS + RK2928_NANDC_SIZE - 1,
621 .flags = IORESOURCE_MEM,
625 static struct platform_device device_nand = {
626 .name = "rk29xxnand",
628 .resource = resources_nand,
629 .num_resources = ARRAY_SIZE(resources_nand),
632 #ifdef CONFIG_HDMI_RK2928
633 static struct resource resource_hdmi[] = {
635 .start = RK2928_HDMI_PHYS,
636 .end = RK2928_HDMI_PHYS + RK2928_HDMI_SIZE - 1,
637 .flags = IORESOURCE_MEM,
642 .flags = IORESOURCE_IRQ,
646 static struct platform_device device_hdmi = {
647 .name = "rk2928-hdmi",
649 .num_resources = ARRAY_SIZE(resource_hdmi),
650 .resource = resource_hdmi,
653 #ifdef CONFIG_RGA_RK30
654 static struct resource resource_rga[] = {
656 .start = RK2928_RGA_PHYS,
657 .end = RK2928_RGA_PHYS + RK2928_RGA_SIZE - 1,
658 .flags = IORESOURCE_MEM,
663 .flags = IORESOURCE_IRQ,
667 static struct platform_device device_rga = {
670 .num_resources = ARRAY_SIZE(resource_rga),
671 .resource = resource_rga,
674 #ifdef CONFIG_SND_RK29_SOC_I2S
675 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
676 static struct resource resource_iis0_8ch[] = {
678 .start = RK2928_I2S_PHYS,
679 .end = RK2928_I2S_PHYS + RK2928_I2S_SIZE - 1,
680 .flags = IORESOURCE_MEM,
683 .start = DMACH_I2S0_8CH_TX,
684 .end = DMACH_I2S0_8CH_TX,
685 .flags = IORESOURCE_DMA,
688 .start = DMACH_I2S0_8CH_RX,
689 .end = DMACH_I2S0_8CH_RX,
690 .flags = IORESOURCE_DMA,
695 .flags = IORESOURCE_IRQ,
699 static struct platform_device device_iis0_8ch = {
702 .num_resources = ARRAY_SIZE(resource_iis0_8ch),
703 .resource = resource_iis0_8ch,
707 static struct platform_device device_pcm = {
708 .name = "rockchip-audio",
712 static void __init rk2928_init_i2s(void)
714 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
715 platform_device_register(&device_iis0_8ch);
717 platform_device_register(&device_pcm);
719 #ifdef CONFIG_KEYS_RK29
720 extern struct rk29_keys_platform_data rk29_keys_pdata;
721 static struct platform_device device_keys = {
722 .name = "rk29-keypad",
725 .platform_data = &rk29_keys_pdata,
730 #ifdef CONFIG_SDMMC0_RK29
731 static struct resource resources_sdmmc0[] = {
735 .flags = IORESOURCE_IRQ,
738 .start = RK2928_SDMMC_PHYS,
739 .end = RK2928_SDMMC_PHYS + RK2928_SDMMC_SIZE -1,
740 .flags = IORESOURCE_MEM,
744 static struct platform_device device_sdmmc0 = {
745 .name = "rk29_sdmmc",
747 .num_resources = ARRAY_SIZE(resources_sdmmc0),
748 .resource = resources_sdmmc0,
750 .platform_data = &default_sdmmc0_data,
755 #ifdef CONFIG_SDMMC1_RK29
756 static struct resource resources_sdmmc1[] = {
760 .flags = IORESOURCE_IRQ,
763 .start = RK2928_SDIO_PHYS,
764 .end = RK2928_SDIO_PHYS + RK2928_SDIO_SIZE - 1,
765 .flags = IORESOURCE_MEM,
769 static struct platform_device device_sdmmc1 = {
770 .name = "rk29_sdmmc",
772 .num_resources = ARRAY_SIZE(resources_sdmmc1),
773 .resource = resources_sdmmc1,
775 .platform_data = &default_sdmmc1_data,
779 static void __init rk2928_init_sdmmc(void)
781 #ifdef CONFIG_SDMMC0_RK29
782 platform_device_register(&device_sdmmc0);
784 #ifdef CONFIG_SDMMC1_RK29
785 platform_device_register(&device_sdmmc1);
789 static struct resource resource_arm_pmu = {
790 .start = IRQ_ARM_PMU,
792 .flags = IORESOURCE_IRQ,
795 struct platform_device device_arm_pmu = {
797 .id = ARM_PMU_DEVICE_CPU,
799 .resource = &resource_arm_pmu,
802 static int __init rk2928_init_devices(void)
808 #ifdef CONFIG_MTD_NAND_RK29XX
809 platform_device_register(&device_nand);
811 #ifdef CONFIG_ADC_RK30
812 platform_device_register(&device_adc);
814 #ifdef CONFIG_KEYS_RK29
815 platform_device_register(&device_keys);
817 #ifdef CONFIG_RGA_RK30
818 platform_device_register(&device_rga);
821 #if defined(CONFIG_FIQ_DEBUGGER) && defined(DEBUG_UART_PHYS)
822 rk_serial_debug_init(DEBUG_UART_BASE, IRQ_DEBUG_UART, IRQ_UART_SIGNAL, -1);
825 #ifdef CONFIG_HDMI_RK2928
826 platform_device_register(&device_hdmi);
828 platform_device_register(&device_arm_pmu);
831 arch_initcall(rk2928_init_devices);