add spi bus test code
authorlw <lw@rock-chips.com>
Wed, 20 Jun 2012 07:20:39 +0000 (15:20 +0800)
committerlw <lw@rock-chips.com>
Wed, 20 Jun 2012 07:20:39 +0000 (15:20 +0800)
arch/arm/mach-rk30/board-rk30-sdk.c
drivers/spi/Kconfig
drivers/spi/Makefile
drivers/spi/spi_test.c [new file with mode: 0755]

index fd47452bc23201c9a0e61b94792c65eb2d876070..1a486057d2c617abb68ce0deecf37a31796c5578 100755 (executable)
@@ -715,7 +715,7 @@ static struct sensor_platform_data lis3dh_info = {
        .irq_enable = 1,
        .poll_delay_ms = 30,
         .init_platform_hw = lis3dh_init_platform_hw,
-        .orientation = {0, 1, 0, 0, 0, 1, -1, 0, 0},
+       .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
 };
 #endif
 #if defined (CONFIG_COMPASS_AK8975)
index db08a9b79c29be279bf656520aefec713ae538c5..51fc9c9f56abe953fb4fac3b0718060b3a6a2e96 100755 (executable)
@@ -440,7 +440,11 @@ config SPIM1_RK29
        bool "RK SPI1 master controller"
        depends on SPIM_RK29
        help
-         enable SPI1 master controller for RK29                
+         enable SPI1 master controller for RK29        
+
+config RK_SPIM_TEST
+       bool "RK SPIM test"
+       depends on (SPIM0_RK29 && SPIM1_RK29)
 
 config LCD_USE_SPIM_CONTROL
        bool "Switch gpio to spim with spin lock"
index 58a98b01e0c8fd4e03eea36d7418c369ee1c2738..7f1a2aee862026df661349ca063fcd7ccb28f5dc 100755 (executable)
@@ -13,14 +13,15 @@ obj-$(CONFIG_SPI_ALTERA)            += spi_altera.o
 obj-$(CONFIG_SPI_ATMEL)                        += atmel_spi.o
 obj-$(CONFIG_SPI_ATH79)                        += ath79_spi.o
 obj-$(CONFIG_SPI_BFIN)                 += spi_bfin5xx.o
-obj-$(CONFIG_SPI_BFIN_SPORT)           += spi_bfin_sport.o
+obj-$(CONFIG_SPI_BFIN_SPORT)   += spi_bfin_sport.o
 obj-$(CONFIG_SPI_BITBANG)              += spi_bitbang.o
 obj-$(CONFIG_SPI_AU1550)               += au1550_spi.o
 obj-$(CONFIG_SPI_BUTTERFLY)            += spi_butterfly.o
-obj-$(CONFIG_SPIM_RK29)                        += rk29_spim.o
-obj-$(CONFIG_SPI_COLDFIRE_QSPI)                += coldfire_qspi.o
+obj-$(CONFIG_SPIM_RK29)                    += rk29_spim.o
+obj-$(CONFIG_RK_SPIM_TEST)             += spi_test.o
+obj-$(CONFIG_SPI_COLDFIRE_QSPI)        += coldfire_qspi.o
 obj-$(CONFIG_SPI_DAVINCI)              += davinci_spi.o
-obj-$(CONFIG_SPI_DESIGNWARE)           += dw_spi.o
+obj-$(CONFIG_SPI_DESIGNWARE)   += dw_spi.o
 obj-$(CONFIG_SPI_DW_PCI)               += dw_spi_midpci.o
 dw_spi_midpci-objs                     := dw_spi_pci.o dw_spi_mid.o
 obj-$(CONFIG_SPI_DW_MMIO)              += dw_spi_mmio.o
diff --git a/drivers/spi/spi_test.c b/drivers/spi/spi_test.c
new file mode 100755 (executable)
index 0000000..9c7bc8f
--- /dev/null
@@ -0,0 +1,175 @@
+/*drivers/serial/spi_test.c -spi test driver\r
+ *\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ */\r
+\r
+#include <linux/dma-mapping.h>\r
+#include <linux/interrupt.h>\r
+#include <linux/highmem.h>\r
+#include <linux/delay.h>\r
+#include <linux/slab.h>\r
+#include <linux/platform_device.h>\r
+#include <linux/clk.h>\r
+#include <linux/cpufreq.h>\r
+#include <mach/gpio.h>\r
+#include <mach/irqs.h>\r
+#include <linux/miscdevice.h>\r
+#include <asm/dma.h>\r
+#include <linux/preempt.h>\r
+#include "rk29_spim.h"\r
+#include <linux/spi/spi.h>\r
+#include <mach/board.h>\r
+\r
+struct spi_test_data {\r
+       struct device   *dev;\r
+       struct spi_device       *spi;   \r
+       char *rx_buf;\r
+       int rx_len; \r
+       char *tx_buf;\r
+       int tx_len; \r
+};\r
+static struct spi_test_data *g_spi_test_data;\r
+\r
+\r
+static struct rk29xx_spi_chip spi_test_chip = {\r
+       //.poll_mode = 1,\r
+       .enable_dma = 1,\r
+};\r
+       \r
+static struct spi_board_info board_spi_test_devices[] = {      \r
+       {\r
+               .modalias  = "spi_test",\r
+               .bus_num = 0,   //0 or 1\r
+               .max_speed_hz  = 12*1000*1000,\r
+               .chip_select   = 0,             \r
+               .controller_data = &spi_test_chip,\r
+       },      \r
+       \r
+};\r
+\r
+static ssize_t spi_test_write(struct file *file, \r
+                       const char __user *buf, size_t count, loff_t *offset)\r
+{\r
+        char nr_buf[8];\r
+        int nr = 0, ret;\r
+       int i = 0;\r
+       struct spi_device *spi = g_spi_test_data->spi;\r
+       char txbuf[256],rxbuf[256];\r
+\r
+        if(count > 3)\r
+                return -EFAULT;\r
+        ret = copy_from_user(nr_buf, buf, count);\r
+        if(ret < 0)\r
+                return -EFAULT;\r
+\r
+        sscanf(nr_buf, "%d", &nr);\r
+        if(nr >= 2 || nr < 0)\r
+        {\r
+               printk("%s:data is error\n",__func__);\r
+                return -EFAULT;\r
+        }\r
+       \r
+       for(i=0; i<256; i++)\r
+       txbuf[i] = i;\r
+\r
+       switch(nr)\r
+       {\r
+               case 0:\r
+                       spi->chip_select = 0;\r
+                       break;\r
+               case 1:\r
+                       spi->chip_select = 1;\r
+                       break;\r
+\r
+               default:\r
+                       break;\r
+\r
+       }\r
+\r
+       for(i=0; i<10; i++)\r
+       {\r
+               ret = spi_write(spi, txbuf, 256);\r
+               ret = spi_read(spi, rxbuf, 256);\r
+               ret = spi_write_then_read(spi,txbuf,256,rxbuf,256);\r
+               printk("%s:test %d times\n\n",__func__,i+1);\r
+       }\r
+       \r
+       if(!ret)\r
+       printk("%s:ok\n",__func__);\r
+       else\r
+       printk("%s:error\n",__func__);\r
+       \r
+        return count;\r
+}\r
+\r
+\r
+static const struct file_operations spi_test_fops = {\r
+       .write = spi_test_write,\r
+};\r
+\r
+static struct miscdevice spi_test_misc = {\r
+       .minor = MISC_DYNAMIC_MINOR,\r
+       .name = "spi_misc_test",\r
+       .fops = &spi_test_fops,\r
+};\r
+\r
+static int __devinit spi_test_probe(struct spi_device *spi)\r
+{      \r
+       struct spi_test_data *spi_test_data;\r
+       int ret;\r
+       \r
+       spi_test_data = (struct spi_test_data *)kzalloc(sizeof(struct spi_test_data), GFP_KERNEL);\r
+       if(!spi_test_data){\r
+               dev_err(&spi->dev, "ERR: no memory for spi_test_data\n");\r
+               return -ENOMEM;
+       }\r
+\r
+       spi->bits_per_word = 8;\r
+       spi->mode = SPI_MODE_0;\r
+       \r
+       spi_test_data->spi = spi;\r
+       spi_test_data->dev = &spi->dev;\r
+       ret = spi_setup(spi);\r
+       if (ret < 0){\r
+               dev_err(spi_test_data->dev, "ERR: fail to setup spi\n");\r
+               return -1;\r
+       }       \r
+\r
+       g_spi_test_data = spi_test_data;\r
+\r
+       printk("%s:bus_num=%d,ok\n",__func__,spi->bus_num);\r
+\r
+       return ret;\r
+\r
+}\r
+\r
+\r
+static struct spi_driver spi_test_driver = {\r
+       .driver = {\r
+               .name           = "spi_test",\r
+               .bus            = &spi_bus_type,\r
+               .owner          = THIS_MODULE,\r
+       },\r
+\r
+       .probe          = spi_test_probe,\r
+};\r
+\r
+static int __init spi_test_init(void)\r
+{      \r
+       spi_register_board_info(board_spi_test_devices, ARRAY_SIZE(board_spi_test_devices));\r
+       misc_register(&spi_test_misc);\r
+       return spi_register_driver(&spi_test_driver);\r
+}\r
+\r
+static void __exit spi_test_exit(void)\r
+{\r
+        misc_deregister(&spi_test_misc);\r
+       return spi_unregister_driver(&spi_test_driver);\r
+}\r
+module_init(spi_test_init);\r
+module_exit(spi_test_exit);\r
+\r