hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/spi/spi-rockchip-test.c
....@@ -7,33 +7,6 @@
77 * GNU General Public License for more details.
88 */
99
10
-/* dts config
11
-&spi0 {
12
- status = "okay";
13
- max-freq = <48000000>; //spi internal clk, don't modify
14
- //dma-names = "tx", "rx"; //enable dma
15
- pinctrl-names = "default"; //pinctrl according to you board
16
- pinctrl-0 = <&spi0_clk &spi0_tx &spi0_rx &spi0_cs0 &spi0_cs1>;
17
- spi_test@00 {
18
- compatible = "rockchip,spi_test_bus0_cs0";
19
- reg = <0>; //chip select 0:cs0 1:cs1
20
- id = <0>;
21
- spi-max-frequency = <24000000>; //spi output clock
22
- //spi-cpha; not support
23
- //spi-cpol; //if the property is here it is 1:clk is high, else 0:clk is low when idle
24
- };
25
-
26
- spi_test@01 {
27
- compatible = "rockchip,spi_test_bus0_cs1";
28
- reg = <1>;
29
- id = <1>;
30
- spi-max-frequency = <24000000>;
31
- spi-cpha;
32
- spi-cpol;
33
- };
34
-};
35
-*/
36
-
3710 /* how to test spi
3811 * echo write 0 10 255 > /dev/spi_misc_test
3912 * echo write 0 10 255 init.rc > /dev/spi_misc_test
....@@ -50,7 +23,6 @@
5023 #include <linux/interrupt.h>
5124 #include <linux/delay.h>
5225 #include <linux/clk.h>
53
-#include <linux/fs.h>
5426 #include <linux/dma-mapping.h>
5527 #include <linux/dmaengine.h>
5628 #include <linux/platform_device.h>
....@@ -65,7 +37,7 @@
6537 #include <linux/uaccess.h>
6638 #include <linux/syscalls.h>
6739
68
-#define MAX_SPI_DEV_NUM 8
40
+#define MAX_SPI_DEV_NUM 10
6941 #define SPI_MAX_SPEED_HZ 12000000
7042
7143 struct spi_test_data {
....@@ -102,7 +74,11 @@
10274
10375 spi_message_init(&m);
10476 spi_message_add_tail(&t, &m);
105
- return spi_sync(spi, &m);
77
+ ret = spi_sync(spi, &m);
78
+ if (m.actual_length && m.actual_length != n)
79
+ pr_err("%s len=%d actual_length=%d\n", __func__, n, m.actual_length);
80
+
81
+ return ret;
10682 }
10783
10884 int spi_read_slt(int id, void *rxbuf, size_t n)
....@@ -127,11 +103,15 @@
127103
128104 spi_message_init(&m);
129105 spi_message_add_tail(&t, &m);
130
- return spi_sync(spi, &m);
106
+ ret = spi_sync(spi, &m);
107
+ if (m.actual_length && m.actual_length != n)
108
+ pr_err("%s len=%d actual_length=%d\n", __func__, n, m.actual_length);
109
+
110
+ return ret;
131111 }
132112
133
-int spi_write_then_read_slt(int id, const void *txbuf, unsigned n_tx,
134
- void *rxbuf, unsigned n_rx)
113
+int spi_write_then_read_slt(int id, const void *txbuf, unsigned int n_tx,
114
+ void *rxbuf, unsigned int n_rx)
135115 {
136116 int ret = -1;
137117 struct spi_device *spi = NULL;
....@@ -225,17 +205,9 @@
225205 }
226206 spi->max_speed_hz = val;
227207 } else if (!strcmp(cmd, "write")) {
228
- char name[64];
229
- int fd;
230
- mm_segment_t old_fs = get_fs();
231
-
232208 sscanf(argv[0], "%d", &id);
233209 sscanf(argv[1], "%d", &times);
234210 sscanf(argv[2], "%d", &size);
235
- if (argc > 3) {
236
- sscanf(argv[3], "%s", name);
237
- set_fs(KERNEL_DS);
238
- }
239211
240212 txbuf = kzalloc(size, GFP_KERNEL);
241213 if (!txbuf) {
....@@ -243,19 +215,8 @@
243215 return n;
244216 }
245217
246
- if (argc > 3) {
247
- fd = ksys_open(name, O_RDONLY, 0);
248
- if (fd < 0) {
249
- printk("open %s fail\n", name);
250
- } else {
251
- ksys_read(fd, (char __user *)txbuf, size);
252
- ksys_close(fd);
253
- }
254
- set_fs(old_fs);
255
- } else {
256
- for (i = 0; i < size; i++)
257
- txbuf[i] = i % 256;
258
- }
218
+ for (i = 0; i < size; i++)
219
+ txbuf[i] = i % 256;
259220
260221 start_time = ktime_get();
261222 for (i = 0; i < times; i++)
....@@ -340,14 +301,21 @@
340301 kfree(txbuf);
341302 kfree(rxbuf);
342303 } else if (!strcmp(cmd, "config")) {
343
- int width;
304
+ int width, mode;
344305
345
- sscanf(argv[0], "%d", &width);
306
+ sscanf(argv[0], "%d", &id);
307
+ sscanf(argv[1], "%d", &width);
308
+ sscanf(argv[2], "mode=0x%x", &mode);
346309
347310 if (width == 16)
348311 bit_per_word = 16;
349312 else
350313 bit_per_word = 8;
314
+
315
+ if (mode) {
316
+ g_spi_test_data[id]->spi->mode = mode;
317
+ spi_setup(g_spi_test_data[id]->spi);
318
+ }
351319 } else {
352320 printk("echo id number size > /dev/spi_misc_test\n");
353321 printk("echo write 0 10 255 > /dev/spi_misc_test\n");
....@@ -355,7 +323,7 @@
355323 printk("echo read 0 10 255 > /dev/spi_misc_test\n");
356324 printk("echo loop 0 10 255 > /dev/spi_misc_test\n");
357325 printk("echo setspeed 0 1000000 > /dev/spi_misc_test\n");
358
- printk("echo config 8 > /dev/spi_misc_test\n");
326
+ printk("echo config 0 8 mode=0xb > /dev/spi_misc_test\n");
359327 }
360328
361329 return n;
....@@ -380,9 +348,6 @@
380348 if (!spi)
381349 return -ENOMEM;
382350
383
- if (!spi->dev.of_node)
384
- return -ENOMEM;
385
-
386351 spi_test_data = (struct spi_test_data *)kzalloc(sizeof(struct spi_test_data), GFP_KERNEL);
387352 if (!spi_test_data) {
388353 dev_err(&spi->dev, "ERR: no memory for spi_test_data\n");
....@@ -399,7 +364,7 @@
399364 return -1;
400365 }
401366
402
- if (of_property_read_u32(spi->dev.of_node, "id", &id)) {
367
+ if (device_property_read_u32(&spi->dev, "id", &id)) {
403368 dev_warn(&spi->dev, "fail to get id, default set 0\n");
404369 id = 0;
405370 }