\r
#include "spi-rockchip-core.h"\r
\r
+#define MAX_SPI_DEV_NUM 6\r
+#define SPI_MAX_SPEED_HZ 12000000\r
\r
-#define MAX_SPI_BUS_NUM 2\r
\r
struct spi_test_data {\r
struct device *dev;\r
- struct spi_device *spi; \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[MAX_SPI_BUS_NUM];\r
\r
+static struct spi_test_data *g_spi_test_data[MAX_SPI_DEV_NUM];\r
\r
-static struct dw_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
- \r
-static struct spi_board_info board_spi_test_devices[] = { \r
-//#if defined(CONFIG_SPIM0_RK29)\r
- {\r
- .modalias = "spi_test_bus0",\r
- .bus_num = 0, //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[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
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
+ if(count > 5)\r
return -EFAULT;\r
\r
ret = copy_from_user(nr_buf, buf, count);\r
return -EFAULT;\r
\r
sscanf(nr_buf, "%d", &nr);\r
- if(nr >= 4 || nr < 0)\r
+ if(nr >= 6 || nr < 0)\r
{\r
printk("%s:cmd is error\n",__func__);\r
return -EFAULT;\r
for(i=0; i<256; i++)\r
txbuf[i] = i;\r
\r
-\r
-/*\r
- if((nr == 0) || (nr == 1))\r
+ if(!g_spi_test_data[nr] || !g_spi_test_data[nr]->spi)\r
{\r
- printk("%s:error SPIM0 need selected\n",__func__); \r
+ printk("%s:error g_spi_test_data is null\n",__func__); \r
return -EFAULT;\r
}\r
\r
- if((nr == 2) || (nr == 3))\r
- {\r
- printk("%s:error SPIM1 need selected\n",__func__); \r
- return -EFAULT;\r
- }\r
-*/\r
-\r
- switch(nr)\r
- {\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
- 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
- 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
+ spi = g_spi_test_data[nr]->spi;\r
\r
for(i=0; i<100; i++)\r
{\r
.fops = &spi_test_fops,\r
};\r
\r
-static int spi_test_probe(struct spi_device *spi)\r
+#ifdef CONFIG_OF\r
+static struct dw_spi_chip *rockchip_spi_parse_dt(struct device *dev)\r
+{\r
+ u32 temp;\r
+ struct dw_spi_chip *spi_chip_data; \r
+\r
+ spi_chip_data = devm_kzalloc(dev, sizeof(*spi_chip_data), GFP_KERNEL);\r
+ if (!spi_chip_data) {\r
+ dev_err(dev, "memory allocation for spi_chip_data failed\n");\r
+ return ERR_PTR(-ENOMEM);\r
+ }\r
+ \r
+ if (of_property_read_u32(dev->of_node, "poll_mode", &temp)) {\r
+ dev_warn(dev, "fail to get poll_mode, default set 0\n");\r
+ spi_chip_data->poll_mode = 0;\r
+ } else {\r
+ spi_chip_data->poll_mode = temp;\r
+ }\r
+\r
+ if (of_property_read_u32(dev->of_node, "type", &temp)) {\r
+ dev_warn(dev, "fail to get type, default set 0\n");\r
+ spi_chip_data->type = 0;\r
+ } else {\r
+ spi_chip_data->type = temp;\r
+ }\r
+\r
+ if (of_property_read_u32(dev->of_node, "enable_dma", &temp)) {\r
+ dev_warn(dev, "fail to get enable_dma, default set 0\n");\r
+ spi_chip_data->enable_dma = 0;\r
+ } else {\r
+ spi_chip_data->enable_dma = temp;\r
+ }\r
+ \r
+\r
+ return spi_chip_data;\r
+}\r
+#else\r
+static struct spi_board_info *rockchip_spi_parse_dt(struct device *dev)\r
+{\r
+ return dev->platform_data;\r
+}\r
+#endif\r
+\r
+\r
+static int rockchip_spi_test_probe(struct spi_device *spi)\r
{ \r
- struct spi_test_data *spi_test_data;\r
int ret;\r
int i =0;\r
- char txbuf[256],rxbuf[256];\r
+ char txbuf[256],rxbuf[256]; \r
+ int id = 0;\r
+ static struct dw_spi_chip *spi_chip_data;\r
+ struct spi_test_data *spi_test_data;\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
+ if (!spi_chip_data && spi->dev.of_node) {\r
+ spi_chip_data = rockchip_spi_parse_dt(&spi->dev);\r
+ if (IS_ERR(spi_chip_data))\r
return -ENOMEM;\r
}\r
\r
return -ENOMEM;
}\r
\r
- spi->bits_per_word = 8;\r
+ spi->bits_per_word = 8; \r
+ spi->controller_data = spi_chip_data;\r
\r
spi_test_data->spi = spi;\r
spi_test_data->dev = &spi->dev;\r
+ \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->master->bus_num] = spi_test_data;\r
+ if((spi->master->bus_num == 0) && (spi->chip_select == 0))\r
+ id = 0;\r
+ else if((spi->master->bus_num == 0) && (spi->chip_select == 1))\r
+ id = 1;\r
+ else if ((spi->master->bus_num == 1) && (spi->chip_select == 0))\r
+ id = 2;\r
+ else if ((spi->master->bus_num == 1) && (spi->chip_select == 1))\r
+ id = 3;\r
+ else if ((spi->master->bus_num == 2) && (spi->chip_select == 0))\r
+ id = 4;\r
+ else if ((spi->master->bus_num == 2) && (spi->chip_select == 1))\r
+ id = 5;\r
+\r
+ g_spi_test_data[id] = spi_test_data;\r
+ \r
+ printk("%s:name=%s,bus_num=%d,cs=%d,mode=%d,speed=%d\n",__func__,spi->modalias, spi->master->bus_num, spi->chip_select, spi->mode, spi->max_speed_hz);\r
\r
- printk("%s:bus_num=%d,ok\n",__func__,spi->master->bus_num);\r
+ printk("%s:poll_mode=%d, type=%d, enable_dma=%d\n",__func__, spi_chip_data->poll_mode, spi_chip_data->type, spi_chip_data->enable_dma);\r
return ret;\r
\r
}\r
\r
-static const struct spi_device_id spi_test_id[] = { \r
- {"spi_test_bus0", 0},\r
- {"spi_test_bus1", 1},\r
+static int rockchip_spi_test_remove(struct spi_device *spi)\r
+{\r
+ printk("%s\n",__func__);\r
+ return 0;\r
+}\r
+\r
+#ifdef CONFIG_OF\r
+static const struct of_device_id rockchip_spi_test_dt_match[] = {\r
+ { .compatible = "rockchip,spi_test_bus0_cs0", },\r
+ { .compatible = "rockchip,spi_test_bus0_cs1", },\r
+ { .compatible = "rockchip,spi_test_bus1_cs0", },\r
+ { .compatible = "rockchip,spi_test_bus1_cs1", },\r
{},\r
};\r
+MODULE_DEVICE_TABLE(of, rockchip_spi_test_dt_match);\r
\r
+#endif /* CONFIG_OF */\r
\r
-static struct spi_driver spi_test_driver = {\r
+static struct spi_driver spi_rockchip_test_driver = {\r
.driver = {\r
- .name = "spi_test",\r
- .bus = &spi_bus_type,\r
- .owner = THIS_MODULE,\r
+ .name = "spi_test",\r
+ .owner = THIS_MODULE,\r
+ .of_match_table = of_match_ptr(rockchip_spi_test_dt_match),\r
},\r
- .id_table = spi_test_id,\r
-\r
- .probe = spi_test_probe,\r
+ .probe = rockchip_spi_test_probe,\r
+ .remove = rockchip_spi_test_remove,\r
};\r
\r
-static int __init spi_test_init(void)\r
+static int __init spi_rockchip_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
+ int ret= 0;\r
misc_register(&spi_test_misc);\r
- return spi_register_driver(&spi_test_driver);\r
+ ret = spi_register_driver(&spi_rockchip_test_driver);\r
+ \r
+ return ret;\r
}\r
+module_init(spi_rockchip_test_init);\r
\r
-static void __exit spi_test_exit(void)\r
+static void __exit spi_rockchip_test_exit(void)\r
{\r
- misc_deregister(&spi_test_misc);\r
- return spi_unregister_driver(&spi_test_driver);\r
+ misc_deregister(&spi_test_misc);\r
+ return spi_unregister_driver(&spi_rockchip_test_driver);\r
}\r
-module_init(spi_test_init);\r
-module_exit(spi_test_exit);\r
+module_exit(spi_rockchip_test_exit);\r
+\r
+MODULE_AUTHOR("Luo Wei <lw@rock-chips.com>");\r
+MODULE_DESCRIPTION("ROCKCHIP SPI TEST Driver");\r
+MODULE_LICENSE("GPL");\r
+MODULE_ALIAS("spi:spi_test");\r
\r