rk30:add spi support
authorlw <lw@rock-chips.com>
Fri, 10 Feb 2012 08:12:10 +0000 (16:12 +0800)
committerlw <lw@rock-chips.com>
Fri, 10 Feb 2012 08:12:10 +0000 (16:12 +0800)
arch/arm/mach-rk30/board-rk30-sdk.c
arch/arm/mach-rk30/devices.c [changed mode: 0644->0755]
arch/arm/mach-rk30/include/mach/board.h
arch/arm/mach-rk30/include/mach/iomux.h
arch/arm/mach-rk30/iomux.c
drivers/spi/Kconfig
drivers/spi/rk29_spim.c
drivers/spi/rk29_spim.h

index ee4a335a83d1adedbac5f8778d51a5794e2978b9..1ed255ab2091ab4e96dea39fede8c94c3e79b1c3 100755 (executable)
 #include <mach/board.h>
 #include <mach/hardware.h>
 #include <mach/io.h>
+#include <mach/gpio.h>
+#include <mach/iomux.h>
+/*set touchscreen different type header*/
+#if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI)
+#include "../../../drivers/input/touchscreen/xpt2046_ts.h"
+#elif defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
+#include "../../../drivers/input/touchscreen/xpt2046_tslib_ts.h"
+#elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
+#include "../../../drivers/input/touchscreen/xpt2046_cbn_ts.h"
+#endif
+
+
+/*****************************************************************************************
+ * xpt2046 touch panel
+ * author: hhb@rock-chips.com
+ *****************************************************************************************/
+#if defined(CONFIG_TOUCHSCREEN_XPT2046_NORMAL_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_TSLIB_SPI)
+#define XPT2046_GPIO_INT       RK30_PIN6_PB7 
+#define DEBOUNCE_REPTIME       3
+
+
+static struct xpt2046_platform_data xpt2046_info = {
+       .model                  = 2046,
+       .keep_vref_on           = 1,
+       .swap_xy                = 0,
+       .debounce_max           = 7,
+       .debounce_rep           = DEBOUNCE_REPTIME,
+       .debounce_tol           = 20,
+       .gpio_pendown           = XPT2046_GPIO_INT,
+       .pendown_iomux_name = GPIO6B7_TESTCLOCKOUT_NAME,        
+       .pendown_iomux_mode = GPIO6B_GPIO6B7,   
+       .touch_virtualkey_length = 60,
+       .penirq_recheck_delay_usecs = 1,
+#if defined(CONFIG_TOUCHSCREEN_480X800)
+       .x_min                  = 0,
+       .x_max                  = 480,
+       .y_min                  = 0,
+       .y_max                  = 800,
+       .touch_ad_top = 3940,
+       .touch_ad_bottom = 310,
+       .touch_ad_left = 3772,
+       .touch_ad_right = 340,
+#elif defined(CONFIG_TOUCHSCREEN_800X480)
+       .x_min                  = 0,
+       .x_max                  = 800,
+       .y_min                  = 0,
+       .y_max                  = 480,
+       .touch_ad_top = 2447,
+       .touch_ad_bottom = 207,
+       .touch_ad_left = 5938,
+       .touch_ad_right = 153,
+#elif defined(CONFIG_TOUCHSCREEN_320X480)
+       .x_min                  = 0,
+       .x_max                  = 320,
+       .y_min                  = 0,
+       .y_max                  = 480,
+       .touch_ad_top = 3166,
+       .touch_ad_bottom = 256,
+       .touch_ad_left = 3658,
+       .touch_ad_right = 380,
+#endif 
+};
+#elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
+static struct xpt2046_platform_data xpt2046_info = {
+       .model                  = 2046,
+       .keep_vref_on   = 1,
+       .swap_xy                = 0,
+       .debounce_max           = 7,
+       .debounce_rep           = DEBOUNCE_REPTIME,
+       .debounce_tol           = 20,
+       .gpio_pendown           = XPT2046_GPIO_INT,
+       .pendown_iomux_name = GPIO6B7_TESTCLOCKOUT_NAME,        
+       .pendown_iomux_mode = GPIO6B_GPIO6B7,   
+       .touch_virtualkey_length = 60,
+       .penirq_recheck_delay_usecs = 1,
+       
+#if defined(CONFIG_TOUCHSCREEN_480X800)
+       .x_min                  = 0,
+       .x_max                  = 480,
+       .y_min                  = 0,
+       .y_max                  = 800,
+       .screen_x = { 70,  410, 70, 410, 240},
+       .screen_y = { 50, 50,  740, 740, 400},
+       .uncali_x_default = {  3267,  831, 3139, 715, 1845 },
+       .uncali_y_default = { 3638,  3664, 564,  591, 2087 },
+#elif defined(CONFIG_TOUCHSCREEN_800X480)
+       .x_min                  = 0,
+       .x_max                  = 800,
+       .y_min                  = 0,
+       .y_max                  = 480,
+       .screen_x[5] = { 50, 750,  50, 750, 400};
+       .screen_y[5] = { 40,  40, 440, 440, 240};
+       .uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };
+       .uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };
+#elif defined(CONFIG_TOUCHSCREEN_320X480)
+       .x_min                  = 0,
+       .x_max                  = 320,
+       .y_min                  = 0,
+       .y_max                  = 480,
+       .screen_x[5] = { 50, 270,  50, 270, 160}; 
+       .screen_y[5] = { 40,  40, 440, 440, 240}; 
+       .uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };
+       .uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };
+#endif 
+};
+#endif
+
+static struct spi_board_info board_spi_devices[] = {
+#if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
+       {
+               .modalias       = "xpt2046_ts",
+               .chip_select    = 1,// 2,
+               .max_speed_hz   = 1 * 1000 * 1000,/* (max sample rate @ 3V) * (cmd + data + overhead) */
+               .bus_num        = 0,
+               .irq            = XPT2046_GPIO_INT,
+               .platform_data = &xpt2046_info,
+       },
+#endif
+
+};
+
+
 
 static struct platform_device *devices[] __initdata = {
 };
@@ -88,6 +210,7 @@ static void __init rk30_i2c_register_board_info(void)
 static void __init machine_rk30_board_init(void)
 {
        rk30_i2c_register_board_info();
+       spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
        platform_add_devices(devices, ARRAY_SIZE(devices));
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index fcc81ea..9daef9b
@@ -22,7 +22,8 @@
 #include <mach/irqs.h>
 #include <mach/board.h>
 #include <plat/dma-pl330.h>
-
+#include <mach/gpio.h>
+#include <mach/iomux.h>
 static u64 dma_dmamask = DMA_BIT_MASK(32);
 
 static struct resource resource_dmac1[] = {
@@ -464,6 +465,177 @@ static void __init rk30_init_i2c(void)
 }
 //end of i2c
 
+/*****************************************************************************************
+ * spi devices
+ * author: cmc@rock-chips.com
+ *****************************************************************************************/
+#define SPI_CHIPSELECT_NUM 2
+static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
+       {
+               .name = "spi0 cs0",
+               .cs_gpio = RK30_PIN1_PA4,
+               .cs_iomux_name = GPIO1A4_UART1SIN_SPI0CSN0_NAME,
+               .cs_iomux_mode = GPIO1A_SPI0_CSN0,
+       },
+       {
+               .name = "spi0 cs1",
+               .cs_gpio = RK30_PIN4_PB7,
+               .cs_iomux_name = GPIO4B7_SPI0CSN1_NAME,//if no iomux,set it NULL
+               .cs_iomux_mode = GPIO4B_SPI0_CSN1,
+       }
+};
+
+static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
+       {
+               .name = "spi1 cs0",
+               .cs_gpio = RK30_PIN2_PC4,
+               .cs_iomux_name = GPIO2C4_LCDC1DATA20_SPI1CSN0_HSADCDATA1_NAME,
+               .cs_iomux_mode = GPIO2C_SPI1_CSN0,
+       },
+       {
+               .name = "spi1 cs1",
+               .cs_gpio = RK30_PIN2_PC7,
+               .cs_iomux_name = GPIO2C7_LCDC1DATA23_SPI1CSN1_HSADCDATA4_NAME,//if no iomux,set it NULL
+               .cs_iomux_mode = GPIO2C_SPI1_CSN1,
+       }
+};
+
+static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
+{
+       int i;
+       if (cs_gpios) {
+               for (i=0; i<cs_num; i++) {
+               rk30_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
+               }
+       }
+       return 0;
+}
+
+static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
+{
+       return 0;
+}
+
+static int spi_io_fix_leakage_bug(void)
+{
+#if 0
+       gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
+#endif
+       return 0;
+}
+
+static int spi_io_resume_leakage_bug(void)
+{
+#if 0
+       gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
+#endif
+       return 0;
+}
+
+struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
+       .num_chipselect = SPI_CHIPSELECT_NUM,
+       .chipselect_gpios = rk29xx_spi0_cs_gpios,
+       .io_init = spi_io_init,
+       .io_deinit = spi_io_deinit,
+       .io_fix_leakage_bug = spi_io_fix_leakage_bug,
+       .io_resume_leakage_bug = spi_io_resume_leakage_bug,
+};
+
+struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
+       .num_chipselect = SPI_CHIPSELECT_NUM,
+       .chipselect_gpios = rk29xx_spi1_cs_gpios,
+       .io_init = spi_io_init,
+       .io_deinit = spi_io_deinit,
+       .io_fix_leakage_bug = spi_io_fix_leakage_bug,
+       .io_resume_leakage_bug = spi_io_resume_leakage_bug,
+};
+
+
+
+/*
+ * rk29xx spi master device
+ */
+#ifdef CONFIG_SPIM0_RK29
+static struct resource rk29_spi0_resources[] = {
+       {
+               .start  = IRQ_SPI0,
+               .end    = IRQ_SPI0,
+               .flags  = IORESOURCE_IRQ,
+       },
+       {
+               .start  = RK30_SPI0_PHYS,
+               .end    = RK30_SPI0_PHYS + RK30_SPI0_SIZE - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       {
+               .start  = DMACH_SPI0_TX,
+               .end    = DMACH_SPI0_TX,
+               .flags  = IORESOURCE_DMA,
+       },
+       {
+               .start  = DMACH_SPI0_RX,
+               .end    = DMACH_SPI0_RX,
+               .flags  = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device rk29xx_device_spi0m = {
+       .name   = "rk29xx_spim",
+       .id     = 0,
+       .num_resources  = ARRAY_SIZE(rk29_spi0_resources),
+       .resource       = rk29_spi0_resources,
+       .dev                    = {
+               .platform_data  = &rk29xx_spi0_platdata,
+       },
+};
+#endif
+
+#ifdef CONFIG_SPIM1_RK29
+static struct resource rk29_spi1_resources[] = {
+       {
+               .start  = IRQ_SPI1,
+               .end    = IRQ_SPI1,
+               .flags  = IORESOURCE_IRQ,
+       },
+       {
+               .start  = RK30_SPI1_PHYS,
+               .end    = RK30_SPI1_PHYS + RK30_SPI1_SIZE - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       {
+               .start  = DMACH_SPI1_TX,
+               .end    = DMACH_SPI1_TX,
+               .flags  = IORESOURCE_DMA,
+       },
+       {
+               .start  = DMACH_SPI1_RX,
+               .end    = DMACH_SPI1_RX,
+               .flags  = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device rk29xx_device_spi1m = {
+       .name   = "rk29xx_spim",
+       .id     = 1,
+       .num_resources  = ARRAY_SIZE(rk29_spi1_resources),
+       .resource       = rk29_spi1_resources,
+       .dev                    = {
+               .platform_data  = &rk29xx_spi1_platdata,
+       },
+};
+#endif
+
+static void __init rk30_init_spim(void)
+{
+#ifdef CONFIG_SPIM0_RK29
+       platform_device_register(&rk29xx_device_spi0m);
+#endif
+#ifdef CONFIG_SPIM1_RK29
+       platform_device_register(&rk29xx_device_spi1m);
+#endif
+}
+
+
 #ifdef CONFIG_MTD_NAND_RK29XX
 static struct resource resources_nand[] = {
        {
@@ -495,6 +667,7 @@ static int __init rk30_init_devices(void)
        rk30_init_dma();
        rk30_init_uart();
        rk30_init_i2c();
+       rk30_init_spim();
 #ifdef CONFIG_MTD_NAND_RK29XX
        platform_device_register(&device_nand);
 #endif
index 5791f97f6eac213bf734b9402e56c175ab01032a..58fc85d14599008932c6df167d3f504b0864a894 100644 (file)
@@ -19,4 +19,22 @@ void __init rk30_clock_init(void);
 
 extern struct sys_timer rk30_timer;
 
+/*spi*/
+struct spi_cs_gpio {
+       const char *name;
+       unsigned int cs_gpio;
+       char *cs_iomux_name;
+       unsigned int cs_iomux_mode;
+};
+
+struct rk29xx_spi_platform_data {
+       int (*io_init)(struct spi_cs_gpio*, int);
+       int (*io_deinit)(struct spi_cs_gpio*, int);
+       int (*io_fix_leakage_bug)(void);
+       int (*io_resume_leakage_bug)(void);
+       struct spi_cs_gpio *chipselect_gpios;   
+       u16 num_chipselect;
+};
+
+
 #endif
index 1035a96a9950c97efd9dc4a53ea3a956480c04d8..f2794f93e5555a290b6e6103fc1c70b3a985848c 100755 (executable)
@@ -824,6 +824,7 @@ struct mux_config {
        const unsigned int interleave;
        unsigned int flags;
 };
+#define rk29_mux_api_set rk30_mux_api_set
 
 extern int __init rk30_iomux_init(void);
 extern void rk30_mux_api_set(char *name, unsigned int mode);
index 2db9f58648af1c26336336382b02c4c720a12114..27cc8598d28e6c64ba5f85038e13cb68b6b96107 100755 (executable)
@@ -262,7 +262,7 @@ int __init rk30_iomux_init(void)
                        rk30_mux_set(&rk30_muxs[i]);    
        }
 
-#ifdef CONFIG_UART0_RK30
+#ifdef CONFIG_UART0_RK29
        rk30_mux_api_set(GPIO1A1_UART0SOUT_NAME, GPIO1A_UART0_SOUT);
        rk30_mux_api_set(GPIO1A0_UART0SIN_NAME, GPIO1A_UART0_SIN);
 #ifdef CONFIG_UART0_CTS_RTS_RK30
@@ -270,36 +270,36 @@ int __init rk30_iomux_init(void)
        rk30_mux_api_set(GPIO1A2_UART0CTSN_NAME, GPIO1A_UART0_CTS_N);
 #endif
 #endif
-#ifdef CONFIG_UART1_RK30       
+#ifdef CONFIG_UART1_RK29       
        //UART1 OR SPIM0
        rk30_mux_api_set(GPIO1A5_UART1SOUT_SPI0CLK_NAME, GPIO1A_UART1_SOUT);
        rk30_mux_api_set(GPIO1A4_UART1SIN_SPI0CSN0_NAME, GPIO1A_UART1_SIN);
-#ifdef CONFIG_UART1_CTS_RTS_RK30
+#ifdef CONFIG_UART1_CTS_RTS_RK29
        rk30_mux_api_set(GPIO1A7_UART1RTSN_SPI0TXD_NAME, GPIO1A_UART1_RTS_N);
        rk30_mux_api_set(GPIO1A6_UART1CTSN_SPI0RXD_NAME, GPIO1A_UART1_CTS_N);
 #endif
 #endif
 
-#ifdef CONFIG_UART2_RK30
+#ifdef CONFIG_UART2_RK29
        rk30_mux_api_set(GPIO1B1_UART2SOUT_NAME, GPIO1B_UART2_SOUT);
        rk30_mux_api_set(GPIO1B0_UART2SIN_NAME, GPIO1B_UART2_SIN);
 #endif
-#ifdef CONFIG_UART3_RK30
+#ifdef CONFIG_UART3_RK29
        rk30_mux_api_set(GPIO3D4_UART3SOUT_NAME, GPIO3D_UART3_SOUT);
        rk30_mux_api_set(GPIO3D3_UART3SIN_NAME, GPIO3D_UART3_SIN);
-#ifdef CONFIG_UART3_CTS_RTS_RK30
+#ifdef CONFIG_UART3_CTS_RTS_RK29
        rk30_mux_api_set(GPIO3D6_UART3RTSN_NAME, GPIO3D_UART3_RTS_N);
        rk30_mux_api_set(GPIO3D5_UART3CTSN_NAME, GPIO3D_UART3_CTS_N);
 #endif
 #endif
-#ifdef CONFIG_SPIM0_RK30
+#ifdef CONFIG_SPIM0_RK29
        //UART1 OR SPIM0
        rk30_mux_api_set(GPIO1A5_UART1SOUT_SPI0CLK_NAME, GPIO1A_SPI0_CLK);
        rk30_mux_api_set(GPIO1A4_UART1SIN_SPI0CSN0_NAME, GPIO1A_SPI0_CSN0);
        rk30_mux_api_set(GPIO1A7_UART1RTSN_SPI0TXD_NAME, GPIO1A_SPI0_TXD);
        rk30_mux_api_set(GPIO1A6_UART1CTSN_SPI0RXD_NAME, GPIO1A_SPI0_RXD);
 #endif
-#ifdef CONFIG_SPIM1_RK30
+#ifdef CONFIG_SPIM1_RK29
        //rk30_mux_api_set(GPIO2C7_LCDC1DATA23_SPI1CSN1_HSADCDATA4_NAME, GPIO2C_SPI1_CSN1);
        rk30_mux_api_set(GPIO2C6_LCDC1DATA22_SPI1RXD_HSADCDATA3_NAME, GPIO2C_SPI1_RXD);
        rk30_mux_api_set(GPIO2C5_LCDC1DATA21_SPI1TXD_HSADCDATA2_NAME, GPIO2C_SPI1_TXD);
index a4d446fe8d02a85ff3673672bbf9bbc7a94f19fa..db08a9b79c29be279bf656520aefec713ae538c5 100755 (executable)
@@ -425,19 +425,19 @@ config SPI_NUC900
 #
 
 config SPIM_RK29
-       tristate "RK29 SPI master controller core support"
-       depends on ARCH_RK29 && SPI_MASTER
+       tristate "RK SPI master controller core support"
+       depends on (ARCH_RK29 || ARCH_RK30) && SPI_MASTER
        help
          general driver for SPI controller core from RockChips 
 
 config SPIM0_RK29
-       bool "RK29 SPI0 master controller"
+       bool "RK SPI0 master controller"
        depends on SPIM_RK29
        help
          enable SPI0 master controller for RK29         
 
 config SPIM1_RK29
-       bool "RK29 SPI1 master controller"
+       bool "RK SPI1 master controller"
        depends on SPIM_RK29
        help
          enable SPI1 master controller for RK29                
index dcf46e271893433aedb386fa92e6c01428ffdc47..a74996db72134f4f335a8e0d98c1cc08a6e5aa55 100755 (executable)
@@ -1902,7 +1902,7 @@ static int __init rk29xx_spim_probe(struct platform_device *pdev)
                return -EBUSY;\r
        }\r
        DBG(KERN_INFO "dws->regs: %p\n", dws->regs);\r
-    dws->irq = irq;\r
+       dws->irq = irq;\r
        dws->irq_polarity = IRQF_TRIGGER_NONE;\r
        dws->master = master;\r
        dws->type = SSI_MOTO_SPI;\r
index fb3ab62c602da7c692fc828dde5a52b33bb79657..6ac3853150389c7a538c7f961a3fa44112edfee8 100755 (executable)
 #ifndef __DRIVERS_SPIM_RK29XX_HEADER_H\r
 #define __DRIVERS_SPIM_RK29XX_HEADER_H\r
 #include <linux/io.h>\r
-#include <mach/rk29-dma-pl330.h>\r
+#ifdef CONFIG_ARCH_RK30\r
+#include <plat/dma-pl330.h>\r
+#else\r
+#include <mach/dma-pl330.h>\r
+#endif\r
 \r
 /* SPI register offsets */\r
 #define SPIM_CTRLR0                            0x0000\r