forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
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,7 +103,11 @@
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
133113 int spi_write_then_read_slt(int id, const void *txbuf, unsigned n_tx,
....@@ -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++)
....@@ -380,9 +341,6 @@
380341 if (!spi)
381342 return -ENOMEM;
382343
383
- if (!spi->dev.of_node)
384
- return -ENOMEM;
385
-
386344 spi_test_data = (struct spi_test_data *)kzalloc(sizeof(struct spi_test_data), GFP_KERNEL);
387345 if (!spi_test_data) {
388346 dev_err(&spi->dev, "ERR: no memory for spi_test_data\n");
....@@ -399,7 +357,7 @@
399357 return -1;
400358 }
401359
402
- if (of_property_read_u32(spi->dev.of_node, "id", &id)) {
360
+ if (device_property_read_u32(&spi->dev, "id", &id)) {
403361 dev_warn(&spi->dev, "fail to get id, default set 0\n");
404362 id = 0;
405363 }