Lines Matching +full:spi +full:- +full:dev
4 * SPDX-License-Identifier: Apache-2.0
6 * This driver creates fake SPI buses which can contain emulated devices,
19 #include <zephyr/drivers/spi.h>
20 #include <zephyr/drivers/spi/rtio.h>
27 /* SPI host configuration */
31 uint32_t spi_emul_get_config(const struct device *dev) in spi_emul_get_config() argument
33 struct spi_emul_data *data = dev->data; in spi_emul_get_config()
35 return data->config; in spi_emul_get_config()
39 * Find an emulator for a SPI bus
45 * @param dev SPI emulation controller device
46 * @param chipsel Chip-select value
50 static struct spi_emul *spi_emul_find(const struct device *dev, unsigned int chipsel) in spi_emul_find() argument
52 struct spi_emul_data *data = dev->data; in spi_emul_find()
55 SYS_SLIST_FOR_EACH_NODE(&data->emuls, node) { in spi_emul_find()
59 if (emul->chipsel == chipsel) { in spi_emul_find()
67 static int spi_emul_io(const struct device *dev, const struct spi_config *config, in spi_emul_io() argument
74 emul = spi_emul_find(dev, config->slave); in spi_emul_io()
76 return -EIO; in spi_emul_io()
79 api = emul->api; in spi_emul_io()
80 __ASSERT_NO_MSG(emul->api); in spi_emul_io()
81 __ASSERT_NO_MSG(emul->api->io); in spi_emul_io()
83 if (emul->mock_api != NULL && emul->mock_api->io != NULL) { in spi_emul_io()
84 ret = emul->mock_api->io(emul->target, config, tx_bufs, rx_bufs); in spi_emul_io()
85 if (ret != -ENOSYS) { in spi_emul_io()
90 return api->io(emul->target, config, tx_bufs, rx_bufs); in spi_emul_io()
94 * @brief This is a no-op stub of the SPI API's `release` method to protect drivers under test
97 static int spi_emul_release(const struct device *dev, const struct spi_config *config) in spi_emul_release() argument
99 ARG_UNUSED(dev); in spi_emul_release()
108 * @param dev SPI emulation controller device
110 static int spi_emul_init(const struct device *dev) in spi_emul_init() argument
112 struct spi_emul_data *data = dev->data; in spi_emul_init()
114 sys_slist_init(&data->emuls); in spi_emul_init()
116 return emul_init_for_bus(dev); in spi_emul_init()
119 int spi_emul_register(const struct device *dev, struct spi_emul *emul) in spi_emul_register() argument
121 struct spi_emul_data *data = dev->data; in spi_emul_register()
122 const char *name = emul->target->dev->name; in spi_emul_register()
124 sys_slist_append(&data->emuls, &emul->node); in spi_emul_register()
126 LOG_INF("Register emulator '%s' at cs %u\n", name, emul->chipsel); in spi_emul_register()
133 static DEVICE_API(spi, spi_emul_api) = {
143 .dev = DEVICE_DT_GET(node_id), \