Commit graph

14 commits

Author SHA1 Message Date
Yuval Peress b58b03196b bus: emul: Update i2c/spi emulators with mock transport
Adding a hook for tests to inject a mock transport and migrating the
accel test to test bmi160 specific things. The old version of the test
which checks for read values is now covered by the generic test in
the sensor build_all target.

Signed-off-by: Yuval Peress <peress@google.com>
2024-01-16 10:01:00 +01:00
Tristan Honscheid 0198b7d5f7 emul: Add stub release impl. for emulated SPI driver
`release` is a mandatory method in the `struct spi_driver_api` API but
is not implemented in the SPI emulator. This can cause a test calling
`spi_release()` to segfault. Add a stub implementation that just returns
zero.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2024-01-09 10:27:06 +01:00
Pisit Sawangvonganan 3ffcd75469 drivers: spi: set 'spi_driver_api' as 'static const'
This change marks each instance of the 'spi_driver_api' as 'static const'.
The rationale is that 'spi_driver_api' is used for declaring internal
module interfaces and is not intended to be modified at runtime.
By using 'static const', we ensure immutability, leading to usage of only
.rodata and a reduction in the .data area.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-01-05 09:04:51 +01:00
Tristan Honscheid 8fd1ce7579 emul: Only add enabled DT nodes to bus emulators
The eSPI, I2C, and SPI emulators use devicetree macros to build an array
of devices on the virtual bus. Currently, they will add device nodes that
are not status-okay. This leads to linker errors because the respective
device drivers would not have instantiated device structs for these
nodes --assuming the driver was even compiled. This can be frustrating
if nodes need to be disabled for debugging or configuration purposes.

Update the bus emulators to only consider status-okay nodes by changing
the macros used to iterate over bus devices.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2023-07-12 09:25:18 +02:00
Tristan Honscheid 81310769a9 emul: spi: SPI_EMUL_INIT(n) hard-coded to instance #0
The `SPI_EMUL_INIT(n)` macro used to instantiate SPI bus emulators
builds an array of SPI devices attached to the bus, but always checks
instance #0 of the bus and not `n`. This makes multiple instances of an
emulated SPI bus unusable and popualtes them all with bus 0's devices.

Change the `0` to `n`, which matches how the I2C bus emulator does it.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2023-07-07 09:17:12 +02:00
Kumar Gala 8fb2210cfb emul: remove name param from bus register APIs
Rework the <BUS>_emul_register calls to not pass the name param.  The
name param is only used for logging and we can get it from the
struct <BUS>_emul instead.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-19 15:52:36 -05:00
Aaron Massey fc98549952 emul: Use DEVICE_DT_GET instead of DT_LABEL
DT nodes aren't guaranteed to define a label property. But emulated bus
controllers currently make use of this property to dispatch to the
associated emulator.

Have emulated bus controllers use DEVICE_DT_GET(node_id) to dispatch to
right target peripheral emulator. This also change makes emul_get_binding
and device_get_binding synonymous in behavior with respect to their
parameters.

This also strictly enforces a 1:1 correspondence between invocations of
DEVICE_DT_DEFINE and EMUL_DEFINE.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-07-19 11:43:30 -05:00
Aaron Massey 9d7b9dc807 emul: Simplify emulator bus initialization and API
Allow emulator creators to write an init function that can be used
across multiple busses so as to reduce the boilerplate and cognitive
load in creating an emulator.

Part of this change includes allowing access to the emul struct from a
field in a {bus}_struct api (e.g. i2c_struct), which removes the need for
sporadic usages of CONTAINER_OF to access the emul struct.

Overall, this change simplifies and reduces the amount of boilerplate
code to get a device emulator up and running, thus reducing excise work
to writing tests.

TEST=twister on accel,espi, and eeprom drivers tests

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-07-19 11:43:30 -05:00
Aaron Massey 1028459afd emul: Run clang-format
Run clang-format on all files touched by improved emulator API pull-request
that allowed access to the target device emulator from its bus api without
CONTAINER_OF usage.

drivers/i2c/i2c_emul.c
drivers/spi/spi_emul.c
include/zephyr/drivers/emul.h
include/zephyr/drivers/espi_emul.h
include/zephyr/drivers/i2c_emul.h
include/zephyr/drivers/spi_emul.h
subsys/emul/emul.c
subsys/emul/emul_bmi160.c
subsys/emul/espi/emul_espi_host.c
subsys/emul/i2c/emul_atmel_at24.c

TEST=twister on accel,espi, and eeprom drivers tests

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2022-07-19 11:43:30 -05:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Gerard Marull-Paretas 90118b265f drivers: spi: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 12:25:39 -04:00
Kumar Gala e1032ad2c3 include: Move emul.h to drivers/emul.h
Move emul.h out of the top level include/ dir into
include/drivers/emul.h and deprecated the old location.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-04-22 12:51:01 -04:00
Kumar Gala 03ad31b0e4 drivers: spi: Convert drivers to new DT device macros
Convert spi drivers from:

DEVICE_AND_API_INIT -> DEVICE_DT_INST_DEFINE
DEVICE_GET -> DEVICE_DT_INST_GET

etc..

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-10 08:53:24 -06:00
Simon Glass a1d8e55cad emul: spi: Add support for SPI emulators
Add an emulation controller which routes SPI traffic to an attached
emulator. Only one emulator is supported per bus at present, since
chip-selction functionality is not present.

This allows drivers for SPI peripherals to be tested on systems that
don't have that peripheral attached, with the emulator handling the SPI
traffic.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-05 15:33:00 -04:00