1 /*
2  * Copyright (c) 2021, Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * This is not a real SPI driver. It is used to instantiate struct
9  * devices for the "vnd,spi" devicetree compatible used in test code.
10  */
11 
12 #include <zephyr/kernel.h>
13 #include <zephyr/drivers/spi.h>
14 #include <zephyr/drivers/spi/rtio.h>
15 
16 #define DT_DRV_COMPAT vnd_spi
17 
vnd_spi_transceive(const struct device * dev,const struct spi_config * spi_cfg,const struct spi_buf_set * tx_bufs,const struct spi_buf_set * rx_bufs)18 static int vnd_spi_transceive(const struct device *dev,
19 			      const struct spi_config *spi_cfg,
20 			      const struct spi_buf_set *tx_bufs,
21 			      const struct spi_buf_set *rx_bufs)
22 {
23 	return -ENOTSUP;
24 }
25 
26 #ifdef CONFIG_SPI_ASYNC
vnd_spi_transceive_async(const struct device * dev,const struct spi_config * spi_cfg,const struct spi_buf_set * tx_bufs,const struct spi_buf_set * rx_bufs,spi_callback_t cb,void * userdata)27 static int vnd_spi_transceive_async(const struct device *dev,
28 				    const struct spi_config *spi_cfg,
29 				    const struct spi_buf_set *tx_bufs,
30 				    const struct spi_buf_set *rx_bufs,
31 				    spi_callback_t cb,
32 				    void *userdata)
33 {
34 	return -ENOTSUP;
35 }
36 #endif
37 
vnd_spi_release(const struct device * dev,const struct spi_config * spi_cfg)38 static int vnd_spi_release(const struct device *dev,
39 			   const struct spi_config *spi_cfg)
40 {
41 	return -ENOTSUP;
42 }
43 
44 static DEVICE_API(spi, vnd_spi_api) = {
45 	.transceive = vnd_spi_transceive,
46 #ifdef CONFIG_SPI_ASYNC
47 	.transceive_async = vnd_spi_transceive_async,
48 #endif
49 #ifdef CONFIG_SPI_RTIO
50 	.iodev_submit = spi_rtio_iodev_default_submit,
51 #endif
52 	.release = vnd_spi_release,
53 };
54 
55 #define VND_SPI_INIT(n)                                                                            \
56 	SPI_DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL,                          \
57 				  CONFIG_SPI_INIT_PRIORITY, &vnd_spi_api);
58 
59 DT_INST_FOREACH_STATUS_OKAY(VND_SPI_INIT)
60