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 {
....@@ -233,17 +205,9 @@
233205 }
234206 spi->max_speed_hz = val;
235207 } else if (!strcmp(cmd, "write")) {
236
- char name[64];
237
- int fd;
238
- mm_segment_t old_fs = get_fs();
239
-
240208 sscanf(argv[0], "%d", &id);
241209 sscanf(argv[1], "%d", &times);
242210 sscanf(argv[2], "%d", &size);
243
- if (argc > 3) {
244
- sscanf(argv[3], "%s", name);
245
- set_fs(KERNEL_DS);
246
- }
247211
248212 txbuf = kzalloc(size, GFP_KERNEL);
249213 if (!txbuf) {
....@@ -251,19 +215,8 @@
251215 return n;
252216 }
253217
254
- if (argc > 3) {
255
- fd = ksys_open(name, O_RDONLY, 0);
256
- if (fd < 0) {
257
- printk("open %s fail\n", name);
258
- } else {
259
- ksys_read(fd, (char __user *)txbuf, size);
260
- ksys_close(fd);
261
- }
262
- set_fs(old_fs);
263
- } else {
264
- for (i = 0; i < size; i++)
265
- txbuf[i] = i % 256;
266
- }
218
+ for (i = 0; i < size; i++)
219
+ txbuf[i] = i % 256;
267220
268221 start_time = ktime_get();
269222 for (i = 0; i < times; i++)
....@@ -388,9 +341,6 @@
388341 if (!spi)
389342 return -ENOMEM;
390343
391
- if (!spi->dev.of_node)
392
- return -ENOMEM;
393
-
394344 spi_test_data = (struct spi_test_data *)kzalloc(sizeof(struct spi_test_data), GFP_KERNEL);
395345 if (!spi_test_data) {
396346 dev_err(&spi->dev, "ERR: no memory for spi_test_data\n");
....@@ -407,7 +357,7 @@
407357 return -1;
408358 }
409359
410
- if (of_property_read_u32(spi->dev.of_node, "id", &id)) {
360
+ if (device_property_read_u32(&spi->dev, "id", &id)) {
411361 dev_warn(&spi->dev, "fail to get id, default set 0\n");
412362 id = 0;
413363 }