#include <linux/spi/spi.h>\r
#include <mach/board.h>\r
\r
+#define MAX_SPI_BUS_NUM 2\r
+\r
struct spi_test_data {\r
struct device *dev;\r
struct spi_device *spi; \r
char *tx_buf;\r
int tx_len; \r
};\r
-static struct spi_test_data *g_spi_test_data;\r
+static struct spi_test_data *g_spi_test_data[MAX_SPI_BUS_NUM];\r
\r
\r
-static struct rk29xx_spi_chip spi_test_chip = {\r
+static struct rk29xx_spi_chip spi_test_chip[] = {\r
+{\r
+ //.poll_mode = 1,\r
+ .enable_dma = 1,\r
+},\r
+{\r
//.poll_mode = 1,\r
.enable_dma = 1,\r
+},\r
+\r
};\r
\r
static struct spi_board_info board_spi_test_devices[] = { \r
+#if defined(CONFIG_SPIM0_RK29)\r
{\r
- .modalias = "spi_test",\r
+ .modalias = "spi_test_bus0",\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
+ .mode = SPI_MODE_0,\r
+ .controller_data = &spi_test_chip[0],\r
+ },\r
+#endif\r
+#if defined(CONFIG_SPIM1_RK29)\r
+ {\r
+ .modalias = "spi_test_bus1",\r
+ .bus_num = 1, //0 or 1\r
+ .max_speed_hz = 12*1000*1000,\r
+ .chip_select = 0, \r
+ .mode = SPI_MODE_0,\r
+ .controller_data = &spi_test_chip[1],\r
+ }\r
+#endif\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
+ char nr_buf[8];\r
+ int nr = 0, ret;\r
int i = 0;\r
- struct spi_device *spi = g_spi_test_data->spi;\r
+ struct spi_device *spi = NULL;\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
+ printk("%s:0:bus=0,cs=0; 1:bus=0,cs=1; 2:bus=1,cs=0; 3:bus=1,cs=1\n",__func__);\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 >= 4 || nr < 0)\r
+ {\r
+ printk("%s:cmd is error\n",__func__);\r
+ return -EFAULT;\r
+ }\r
\r
for(i=0; i<256; i++)\r
txbuf[i] = i;\r
\r
+\r
+#if !defined(CONFIG_SPIM0_RK29)\r
+ if((nr == 0) || (nr == 1))\r
+ {\r
+ printk("%s:error SPIM0 need selected\n",__func__); \r
+ return -EFAULT;\r
+ }\r
+#endif\r
+\r
+#if !defined(CONFIG_SPIM1_RK29)\r
+ if((nr == 2) || (nr == 3))\r
+ {\r
+ printk("%s:error SPIM1 need selected\n",__func__); \r
+ return -EFAULT;\r
+ }\r
+#endif\r
+\r
switch(nr)\r
{\r
- case 0:\r
+ case 0: \r
+ if(!g_spi_test_data[0]->spi) \r
+ return -EFAULT;\r
+ spi = g_spi_test_data[0]->spi;\r
spi->chip_select = 0;\r
break;\r
- case 1:\r
+ case 1: \r
+ if(!g_spi_test_data[0]->spi) \r
+ return -EFAULT;\r
+ spi = g_spi_test_data[0]->spi;\r
spi->chip_select = 1;\r
break;\r
-\r
+ case 2: \r
+ if(!g_spi_test_data[1]->spi) \r
+ return -EFAULT;\r
+ spi = g_spi_test_data[1]->spi;\r
+ spi->chip_select = 0;\r
+ break;\r
+ case 3: \r
+ if(!g_spi_test_data[1]->spi) \r
+ return -EFAULT;\r
+ spi = g_spi_test_data[1]->spi;\r
+ spi->chip_select = 1;\r
+ break;\r
+ \r
default:\r
break;\r
-\r
}\r
\r
for(i=0; i<10; i++)\r
}\r
\r
if(!ret)\r
- printk("%s:ok\n",__func__);\r
+ printk("%s:bus_num=%d,chip_select=%d,ok\n",__func__,spi->master->bus_num, spi->chip_select);\r
else\r
- printk("%s:error\n",__func__);\r
+ printk("%s:bus_num=%d,chip_select=%d,error\n",__func__,spi->master->bus_num, spi->chip_select);\r
\r
- return count;\r
+ return count;\r
}\r
\r
\r
{ \r
struct spi_test_data *spi_test_data;\r
int ret;\r
+\r
+ if(!spi) \r
+ return -ENOMEM;\r
+\r
+ if((spi->master->bus_num >= MAX_SPI_BUS_NUM) || (spi->master->bus_num < 0))\r
+ {\r
+ printk("%s:error:bus_num=%d\n",__func__, spi->master->bus_num); \r
+ return -ENOMEM;\r
+ }\r
\r
spi_test_data = (struct spi_test_data *)kzalloc(sizeof(struct spi_test_data), GFP_KERNEL);\r
if(!spi_test_data){\r
}\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
return -1;\r
} \r
\r
- g_spi_test_data = spi_test_data;\r
+ g_spi_test_data[spi->master->bus_num] = spi_test_data;\r
\r
printk("%s:bus_num=%d,ok\n",__func__,spi->master->bus_num);\r
\r
\r
}\r
\r
+static const struct spi_device_id spi_test_id[] = { \r
+ {"spi_test_bus0", 0},\r
+ {"spi_test_bus1", 1},\r
+ {},\r
+};\r
+\r
\r
static struct spi_driver spi_test_driver = {\r
.driver = {\r
.bus = &spi_bus_type,\r
.owner = THIS_MODULE,\r
},\r
+ .id_table = spi_test_id,\r
\r
.probe = spi_test_probe,\r
};\r
\r
static int __init spi_test_init(void)\r
{ \r
+ printk("%s\n",__func__);\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