1 /* arch/arm/mach-rk30/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 #include <linux/delay.h>
20 #include <linux/dma-mapping.h>
22 #include <mach/irqs.h>
23 #include <mach/board.h>
24 #include <plat/dma-pl330.h>
25 #include <mach/gpio.h>
26 #include <mach/iomux.h>
27 static u64 dma_dmamask = DMA_BIT_MASK(32);
29 static struct resource resource_dmac1[] = {
31 .start = RK30_DMACS1_PHYS,
32 .end = RK30_DMACS1_PHYS + RK30_DMACS1_SIZE -1,
33 .flags = IORESOURCE_MEM,
38 .flags = IORESOURCE_IRQ,
42 static struct rk29_pl330_platdata dmac1_pdata = {
48 [4] = DMACH_I2S0_8CH_TX,
49 [5] = DMACH_I2S0_8CH_RX,
50 [6] = DMACH_I2S1_2CH_TX,
51 [7] = DMACH_I2S1_2CH_RX,
53 [9] = DMACH_I2S2_2CH_TX,
54 [10] = DMACH_I2S2_2CH_RX,
79 static struct platform_device device_dmac1 = {
82 .num_resources = ARRAY_SIZE(resource_dmac1),
83 .resource = resource_dmac1,
85 .dma_mask = &dma_dmamask,
86 .coherent_dma_mask = DMA_BIT_MASK(32),
87 .platform_data = &dmac1_pdata,
91 static struct resource resource_dmac2[] = {
93 .start = RK30_DMAC2_PHYS,
94 .end = RK30_DMAC2_PHYS + RK30_DMAC2_SIZE - 1,
95 .flags = IORESOURCE_MEM,
100 .flags = IORESOURCE_IRQ,
104 static struct rk29_pl330_platdata dmac2_pdata = {
111 [5] = DMACH_PID_FILTER,
112 [6] = DMACH_UART2_TX,
113 [7] = DMACH_UART2_RX,
114 [8] = DMACH_UART3_TX,
115 [9] = DMACH_UART3_RX,
116 [10] = DMACH_SPI0_TX,
117 [11] = DMACH_SPI0_RX,
118 [12] = DMACH_SPI1_TX,
119 [13] = DMACH_SPI1_RX,
120 [14] = DMACH_DMAC2_MEMTOMEM,
141 static struct platform_device device_dmac2 = {
142 .name = "rk29-pl330",
144 .num_resources = ARRAY_SIZE(resource_dmac2),
145 .resource = resource_dmac2,
147 .dma_mask = &dma_dmamask,
148 .coherent_dma_mask = DMA_BIT_MASK(32),
149 .platform_data = &dmac2_pdata,
153 static struct platform_device *rk30_dmacs[] __initdata = {
158 static void __init rk30_init_dma(void)
160 platform_add_devices(rk30_dmacs, ARRAY_SIZE(rk30_dmacs));
163 #ifdef CONFIG_UART0_RK29
164 static struct resource resources_uart0[] = {
168 .flags = IORESOURCE_IRQ,
171 .start = RK30_UART0_PHYS,
172 .end = RK30_UART0_PHYS + RK30_UART0_SIZE - 1,
173 .flags = IORESOURCE_MEM,
177 static struct platform_device device_uart0 = {
180 .num_resources = ARRAY_SIZE(resources_uart0),
181 .resource = resources_uart0,
185 #ifdef CONFIG_UART1_RK29
186 static struct resource resources_uart1[] = {
190 .flags = IORESOURCE_IRQ,
193 .start = RK30_UART1_PHYS,
194 .end = RK30_UART1_PHYS + RK30_UART1_SIZE - 1,
195 .flags = IORESOURCE_MEM,
199 static struct platform_device device_uart1 = {
202 .num_resources = ARRAY_SIZE(resources_uart1),
203 .resource = resources_uart1,
207 #ifdef CONFIG_UART2_RK29
208 static struct resource resources_uart2[] = {
212 .flags = IORESOURCE_IRQ,
215 .start = RK30_UART2_PHYS,
216 .end = RK30_UART2_PHYS + RK30_UART2_SIZE - 1,
217 .flags = IORESOURCE_MEM,
221 static struct platform_device device_uart2 = {
224 .num_resources = ARRAY_SIZE(resources_uart2),
225 .resource = resources_uart2,
229 #ifdef CONFIG_UART3_RK29
230 static struct resource resources_uart3[] = {
234 .flags = IORESOURCE_IRQ,
237 .start = RK30_UART3_PHYS,
238 .end = RK30_UART3_PHYS + RK30_UART3_SIZE - 1,
239 .flags = IORESOURCE_MEM,
243 static struct platform_device device_uart3 = {
246 .num_resources = ARRAY_SIZE(resources_uart3),
247 .resource = resources_uart3,
251 static void __init rk30_init_uart(void)
253 #ifdef CONFIG_UART0_RK29
254 platform_device_register(&device_uart0);
256 #ifdef CONFIG_UART1_RK29
257 platform_device_register(&device_uart1);
259 #ifdef CONFIG_UART2_RK29
260 platform_device_register(&device_uart2);
262 #ifdef CONFIG_UART3_RK29
263 platform_device_register(&device_uart3);
268 #ifdef CONFIG_I2C0_CONTROLLER_RK29
269 #define I2C0_ADAP_TYPE I2C_RK29_ADAP
270 #define I2C0_START RK30_I2C0_PHYS
271 #define I2C0_END RK30_I2C0_PHYS + SZ_4K - 1
273 #ifdef CONFIG_I2C0_CONTROLLER_RK30
274 #define I2C0_ADAP_TYPE I2C_RK30_ADAP
275 #define I2C0_START RK30_I2C0_PHYS + SZ_4K
276 #define I2C0_END RK30_I2C0_PHYS + SZ_8K - 1
279 #ifdef CONFIG_I2C1_CONTROLLER_RK29
280 #define I2C1_ADAP_TYPE I2C_RK29_ADAP
281 #define I2C1_START RK30_I2C1_PHYS
282 #define I2C1_END RK30_I2C1_PHYS + SZ_4K - 1
284 #ifdef CONFIG_I2C1_CONTROLLER_RK30
285 #define I2C1_ADAP_TYPE I2C_RK30_ADAP
286 #define I2C1_START RK30_I2C1_PHYS + SZ_4K
287 #define I2C1_END RK30_I2C1_PHYS + SZ_8K - 1
290 #ifdef CONFIG_I2C2_CONTROLLER_RK29
291 #define I2C2_ADAP_TYPE I2C_RK29_ADAP
292 #define I2C2_START RK30_I2C2_PHYS
293 #define I2C2_END RK30_I2C2_PHYS + SZ_4K - 1
295 #ifdef CONFIG_I2C2_CONTROLLER_RK30
296 #define I2C2_ADAP_TYPE I2C_RK30_ADAP
297 #define I2C2_START RK30_I2C2_PHYS + SZ_4K
298 #define I2C2_END RK30_I2C2_PHYS + SZ_8K - 1
301 #ifdef CONFIG_I2C3_CONTROLLER_RK29
302 #define I2C3_ADAP_TYPE I2C_RK29_ADAP
303 #define I2C3_START RK30_I2C3_PHYS
304 #define I2C3_END RK30_I2C3_PHYS + SZ_4K - 1
306 #ifdef CONFIG_I2C3_CONTROLLER_RK30
307 #define I2C3_ADAP_TYPE I2C_RK30_ADAP
308 #define I2C3_START RK30_I2C3_PHYS + SZ_4K
309 #define I2C3_END RK30_I2C3_PHYS + SZ_8K - 1
312 #ifdef CONFIG_I2C4_CONTROLLER_RK29
313 #define I2C4_ADAP_TYPE I2C_RK29_ADAP
314 #define I2C4_START RK30_I2C4_PHYS
315 #define I2C4_END RK30_I2C4_PHYS + SZ_4K - 1
317 #ifdef CONFIG_I2C4_CONTROLLER_RK30
318 #define I2C4_ADAP_TYPE I2C_RK30_ADAP
319 #define I2C4_START RK30_I2C4_PHYS + SZ_4K
320 #define I2C4_END RK30_I2C4_PHYS + SZ_8K - 1
323 #ifdef CONFIG_I2C0_RK30
324 static struct rk30_i2c_platform_data default_i2c0_data = {
326 .is_div_from_arm = 1,
327 .adap_type = I2C0_ADAP_TYPE,
330 static struct resource resources_i2c0[] = {
334 .flags = IORESOURCE_IRQ,
339 .flags = IORESOURCE_MEM,
343 static struct platform_device device_i2c0 = {
346 .num_resources = ARRAY_SIZE(resources_i2c0),
347 .resource = resources_i2c0,
349 .platform_data = &default_i2c0_data,
354 #ifdef CONFIG_I2C1_RK30
355 static struct rk30_i2c_platform_data default_i2c1_data = {
357 .is_div_from_arm = 1,
358 .adap_type = I2C1_ADAP_TYPE,
361 static struct resource resources_i2c1[] = {
365 .flags = IORESOURCE_IRQ,
370 .flags = IORESOURCE_MEM,
374 static struct platform_device device_i2c1 = {
377 .num_resources = ARRAY_SIZE(resources_i2c1),
378 .resource = resources_i2c1,
380 .platform_data = &default_i2c1_data,
385 #ifdef CONFIG_I2C2_RK30
386 static struct rk30_i2c_platform_data default_i2c2_data = {
388 .is_div_from_arm = 0,
389 .adap_type = I2C2_ADAP_TYPE,
392 static struct resource resources_i2c2[] = {
396 .flags = IORESOURCE_IRQ,
401 .flags = IORESOURCE_MEM,
405 static struct platform_device device_i2c2 = {
408 .num_resources = ARRAY_SIZE(resources_i2c2),
409 .resource = resources_i2c2,
411 .platform_data = &default_i2c2_data,
416 #ifdef CONFIG_I2C3_RK30
417 static struct rk30_i2c_platform_data default_i2c3_data = {
419 .is_div_from_arm = 0,
420 .adap_type = I2C3_ADAP_TYPE,
423 static struct resource resources_i2c3[] = {
427 .flags = IORESOURCE_IRQ,
432 .flags = IORESOURCE_MEM,
436 static struct platform_device device_i2c3 = {
439 .num_resources = ARRAY_SIZE(resources_i2c3),
440 .resource = resources_i2c3,
442 .platform_data = &default_i2c3_data,
447 #ifdef CONFIG_I2C4_RK30
448 static struct rk30_i2c_platform_data default_i2c4_data = {
450 .is_div_from_arm = 0,
451 .adap_type = I2C4_ADAP_TYPE,
454 static struct resource resources_i2c4[] = {
458 .flags = IORESOURCE_IRQ,
463 .flags = IORESOURCE_MEM,
467 static struct platform_device device_i2c4 = {
470 .num_resources = ARRAY_SIZE(resources_i2c4),
471 .resource = resources_i2c4,
473 .platform_data = &default_i2c4_data,
478 static void __init rk30_init_i2c(void)
480 #ifdef CONFIG_I2C0_RK30
481 platform_device_register(&device_i2c0);
483 #ifdef CONFIG_I2C1_RK30
484 platform_device_register(&device_i2c1);
486 #ifdef CONFIG_I2C2_RK30
487 platform_device_register(&device_i2c2);
489 #ifdef CONFIG_I2C3_RK30
490 platform_device_register(&device_i2c3);
492 #ifdef CONFIG_I2C4_RK30
493 platform_device_register(&device_i2c4);
498 /*****************************************************************************************
500 * author: cmc@rock-chips.com
501 *****************************************************************************************/
502 #define SPI_CHIPSELECT_NUM 2
503 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
506 .cs_gpio = RK30_PIN1_PA4,
507 .cs_iomux_name = GPIO1A4_UART1SIN_SPI0CSN0_NAME,
508 .cs_iomux_mode = GPIO1A_SPI0_CSN0,
512 .cs_gpio = RK30_PIN4_PB7,
513 .cs_iomux_name = GPIO4B7_SPI0CSN1_NAME,//if no iomux,set it NULL
514 .cs_iomux_mode = GPIO4B_SPI0_CSN1,
518 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
521 .cs_gpio = RK30_PIN2_PC4,
522 .cs_iomux_name = GPIO2C4_LCDC1DATA20_SPI1CSN0_HSADCDATA1_NAME,
523 .cs_iomux_mode = GPIO2C_SPI1_CSN0,
527 .cs_gpio = RK30_PIN2_PC7,
528 .cs_iomux_name = GPIO2C7_LCDC1DATA23_SPI1CSN1_HSADCDATA4_NAME,//if no iomux,set it NULL
529 .cs_iomux_mode = GPIO2C_SPI1_CSN1,
533 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
537 for (i=0; i<cs_num; i++) {
538 rk30_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
544 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
549 static int spi_io_fix_leakage_bug(void)
552 gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
557 static int spi_io_resume_leakage_bug(void)
560 gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
565 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
566 .num_chipselect = SPI_CHIPSELECT_NUM,
567 .chipselect_gpios = rk29xx_spi0_cs_gpios,
568 .io_init = spi_io_init,
569 .io_deinit = spi_io_deinit,
570 .io_fix_leakage_bug = spi_io_fix_leakage_bug,
571 .io_resume_leakage_bug = spi_io_resume_leakage_bug,
574 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
575 .num_chipselect = SPI_CHIPSELECT_NUM,
576 .chipselect_gpios = rk29xx_spi1_cs_gpios,
577 .io_init = spi_io_init,
578 .io_deinit = spi_io_deinit,
579 .io_fix_leakage_bug = spi_io_fix_leakage_bug,
580 .io_resume_leakage_bug = spi_io_resume_leakage_bug,
586 * rk29xx spi master device
588 #ifdef CONFIG_SPIM0_RK29
589 static struct resource rk29_spi0_resources[] = {
593 .flags = IORESOURCE_IRQ,
596 .start = RK30_SPI0_PHYS,
597 .end = RK30_SPI0_PHYS + RK30_SPI0_SIZE - 1,
598 .flags = IORESOURCE_MEM,
601 .start = DMACH_SPI0_TX,
602 .end = DMACH_SPI0_TX,
603 .flags = IORESOURCE_DMA,
606 .start = DMACH_SPI0_RX,
607 .end = DMACH_SPI0_RX,
608 .flags = IORESOURCE_DMA,
612 struct platform_device rk29xx_device_spi0m = {
613 .name = "rk29xx_spim",
615 .num_resources = ARRAY_SIZE(rk29_spi0_resources),
616 .resource = rk29_spi0_resources,
618 .dma_mask = &dma_dmamask,
619 .coherent_dma_mask = DMA_BIT_MASK(32),
620 .platform_data = &rk29xx_spi0_platdata,
625 #ifdef CONFIG_SPIM1_RK29
626 static struct resource rk29_spi1_resources[] = {
630 .flags = IORESOURCE_IRQ,
633 .start = RK30_SPI1_PHYS,
634 .end = RK30_SPI1_PHYS + RK30_SPI1_SIZE - 1,
635 .flags = IORESOURCE_MEM,
638 .start = DMACH_SPI1_TX,
639 .end = DMACH_SPI1_TX,
640 .flags = IORESOURCE_DMA,
643 .start = DMACH_SPI1_RX,
644 .end = DMACH_SPI1_RX,
645 .flags = IORESOURCE_DMA,
649 struct platform_device rk29xx_device_spi1m = {
650 .name = "rk29xx_spim",
652 .num_resources = ARRAY_SIZE(rk29_spi1_resources),
653 .resource = rk29_spi1_resources,
655 .dma_mask = &dma_dmamask,
656 .coherent_dma_mask = DMA_BIT_MASK(32),
657 .platform_data = &rk29xx_spi1_platdata,
662 static void __init rk30_init_spim(void)
664 #ifdef CONFIG_SPIM0_RK29
665 platform_device_register(&rk29xx_device_spi0m);
667 #ifdef CONFIG_SPIM1_RK29
668 platform_device_register(&rk29xx_device_spi1m);
673 /***********************************************************
675 ************************************************************/
676 #ifdef CONFIG_BACKLIGHT_RK29_BL
678 #define PWM_MUX_NAME GPIO0A3_PWM0_NAME
679 #define PWM_MUX_MODE GPIO0A_PWM0
680 #define PWM_MUX_MODE_GPIO GPIO0A_GPIO0A3
681 #define PWM_GPIO RK30_PIN0_PA3
682 #define PWM_EFFECT_VALUE 1
684 #define LCD_DISP_ON_PIN
686 #ifdef LCD_DISP_ON_PIN
687 //#define BL_EN_MUX_NAME GPIOF34_UART3_SEL_NAME
688 //#define BL_EN_MUX_MODE IOMUXB_GPIO1_B34
690 #define BL_EN_PIN INVALID_GPIO //?
691 #define BL_EN_VALUE GPIO_HIGH
693 static int rk29_backlight_io_init(void)
696 rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
697 #ifdef LCD_DISP_ON_PIN
698 // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
700 ret = gpio_request(BL_EN_PIN, NULL);
703 gpio_free(BL_EN_PIN);
706 gpio_direction_output(BL_EN_PIN, 0);
707 gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
712 static int rk29_backlight_io_deinit(void)
715 #ifdef LCD_DISP_ON_PIN
716 gpio_free(BL_EN_PIN);
718 rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
722 static int rk29_backlight_pwm_suspend(void)
725 rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
726 if (gpio_request(PWM_GPIO, NULL)) {
727 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
730 gpio_direction_output(PWM_GPIO, GPIO_LOW);
731 #ifdef LCD_DISP_ON_PIN
732 gpio_direction_output(BL_EN_PIN, 0);
733 gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
738 static int rk29_backlight_pwm_resume(void)
741 rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
742 #ifdef LCD_DISP_ON_PIN
744 gpio_direction_output(BL_EN_PIN, 1);
745 gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
750 struct rk29_bl_info rk29_bl_info = {
752 .bl_ref = PWM_EFFECT_VALUE,
753 .io_init = rk29_backlight_io_init,
754 .io_deinit = rk29_backlight_io_deinit,
755 .pwm_suspend = rk29_backlight_pwm_suspend,
756 .pwm_resume = rk29_backlight_pwm_resume,
760 struct platform_device rk29_device_backlight = {
761 .name = "rk29_backlight",
764 .platform_data = &rk29_bl_info,
770 #ifdef CONFIG_MTD_NAND_RK29XX
771 static struct resource resources_nand[] = {
773 .start = RK30_NANDC_PHYS,
774 .end = RK30_NANDC_PHYS + RK30_NANDC_SIZE - 1,
775 .flags = IORESOURCE_MEM,
779 static struct platform_device device_nand = {
780 .name = "rk30xxnand",
782 .resource = resources_nand,
783 .num_resources = ARRAY_SIZE(resources_nand),
787 #ifdef CONFIG_KEYS_RK29
788 extern struct rk29_keys_platform_data rk29_keys_pdata;
789 static struct platform_device device_keys = {
790 .name = "rk29-keypad",
793 .platform_data = &rk29_keys_pdata,
798 static int __init rk30_init_devices(void)
805 #ifdef CONFIG_BACKLIGHT_RK29_BL
806 platform_device_register(&rk29_device_backlight);
808 #ifdef CONFIG_MTD_NAND_RK29XX
809 platform_device_register(&device_nand);
811 #ifdef CONFIG_KEYS_RK29
812 platform_device_register(&device_keys);
816 arch_initcall(rk30_init_devices);