Commit Graph

18 Commits

Author SHA1 Message Date
Dawid Niedzwiecki 65277d4770 i2c: emul: Add get_config function
Add get_config function to I2C emulator.

Also update tests using I2C emulator to use i2c_get_config.

Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
2021-11-02 16:46:33 +01:00
Yuval Peress 2629fc566d emul: Add data and parent pointers to emulators
Emulators are difficult to work with, they generally require maintaining
some state in a mutable data struct. Since the emulator struct doesn't
support a data field like devices do, the pattern seems to be to add it
to the configuration. This makes following the logic of where things are
difficult.

1. Add a `struct emul *parent` structure to the espi/i2c/spi emulator
   structs to make it easier when casting up.
2. Add a `void *data` field to `struct emul` to hold the data for
   emulators.

Signed-off-by: Yuval Peress <peress@chromium.org>
2021-10-05 19:21:39 -04:00
Yuval Peress 03bcf8276a emul: Support getting an emulator by name
Issue #38271

Implement a getter for emulators similar to device_get_binding. This
function can be used to get the emulator instance during tests to call
emulator specific functions.

Example: The current BMI160 emulator pre-defines a finite set of data
samples that will be returned. If a test was to be written for logic
that uses that data, then the emulator would become completely useless
without the ability for the test to define what data should be returned.

This will also help in exercising error conditions in tests.

Signed-off-by: Yuval Peress <peress@chromium.org>
2021-09-28 20:12:37 -04:00
Yuval Peress ab6e724ab4 emul: espi: Add ACPI Shared Memory functions
Add the bare minimum to set and access the ACPI shared memory via the
eSPI emulator.

Signed-off-by: Yuval Peress <peress@chromium.org>
2021-08-26 13:14:05 -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
Dawid Niedzwiecki 6ec4ff22e3 emul: Add an emulator for the eSPI Host
This emulator pretends a generic eSPI Host. It supports basic virtual
wires and port80 operations.

There are functions to trigger actions on the host side e.g. for
setting a virtual wire from the host to the eSPI slave, use
emul_espi_host_send_vw. It will prepare data and set a proper event
on the slave side which will trigger callback (if there is any).

Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com>
2021-01-20 17:49:19 -05:00
Yuval Peress beaf0230ba drivers: sensors: bmi160: Fix issue with sample read
When testing the bmi160 I've come across an issue where the readings
didn't make sense to me. The issue comes from reading the
BMI160_SAMPLE_BURST_READ_ADDR which is 0x0C assuming both accelerometer
and gyroscope. At this point we would normally read 12 bytes
(2 bytes per sample * 3 axes * 2 sensors). This reading takes place in
bmi160_sample_fetch and begins writing to data->sample.raw

Without this change, the first byte written is actually to the dummy
byte which effectively gets tossed. The issue is that this is the
GYR_X<7:0>(LSB) according to the BMI160 data sheet. When we later call
either bmi160_gyr_channel_get or bmi160_acc_channel_get we're looking
at sample.gyr and sample.acc (which is effectively shiften by 1 byte).

This change gets rid of the dummy byte which re-alignes gyr with the
start of the raw buffer.

Signed-off-by: Yuval Peress <peress@chromium.org>
2020-12-01 17:58:06 -05:00
Simon Glass 129cfec28a emul: spi: bmi160: Add a check for a missing rx buffer
If a read is requested without a read buffer, the emulator currently
crashes. Fix this by adding a check.

Fixes: #29703
Fixes: #29702
Fixes: #29017
Fixes: #29016

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-11-19 11:26:32 -06:00
Simon Glass 20116f0fdf emul: spi: bmi160: Add support for I2C
At present this emulator only supports SPI. Add support for I2C as
well.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass f4ef4daa8a emul: spi: bmi160: Prepare to support I2C
At present this driver only supports SPI. Refactor it so that SPI is
just one of the options. This does not change any functionality.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass fa90b5c243 emul: spi: bmi160: Move to top-level directory
This emulator currently only supports SPI. Before making it also
support I2C, move it up a directory to avoid I2C uses missing it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass e43c181934 emul: spi: emul_bmi160: Move logging to access functions
Move the logging for transactions to the functions that actually access
registers and sample data. This avoids needed to repeat this code when
I2C starts calling these functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass c953c32cbd emul: spi: emul_bmi160: Rename 'spi' to 'bus'
Update the language to refer to a bus instead of SPI. This will make it
more applicable with I2C support is added.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass 442f38d610 emul: Add an emulator for the Bosch BMI160 accelerometer
This emulator supports enable functionality to start up the device and
read a few samples. It connects itself to any BMI160 device it finds in
the device tree. The SPI emulation controller driver is used to direct
SPI messages from the BMI160 driver to the BMI160 emulator.

Add a few more definitions to the header file, as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-05 15:33:00 -04:00
Simon Glass 4d77edd6ba emul: Add messages in emul_init_for_bus_from_list
Add a log message to indicate that a new emulator is attached. Also add
a message in the assert to make it clearer what has gone wrong.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-05 15:33:00 -04:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Simon Glass d1adbc2133 emul: Add an emulator for the Atmel AT24 series
This emulator supports basic reads and writes with 8-bit addressing.
It connects itself to any AT24 devices it finds in the device tree. The
I2C emulation controller driver is used to direct I2C messages from the
AT24 driver to the AT24 emulator.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-09-01 14:30:46 -04:00
Simon Glass 302d671ea2 emul: Create an emulation implementation
Create a header file and implementation for emulators. Set up a linker
list so that emulators can be found and initialised at start-up.

Emulators are used to emulate hardware devices, to support testing of
various subsystems. For example, it is possible to write an emulator
for an I2C compass such that it appears on the I2C bus and can be used
just like a real hardware device.

Emulators often implement special features for testing. For example a
compass may support returning bogus data if the I2C bus speed is too
high, or may return invalid measurements if calibration has not yet
been completed. This allows for testing that high-level code can
handle these situations correctly. Test coverage can therefore
approach 100% if all failure conditions are emulated.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Simon Glass <sjg@chromium.org>
2020-09-01 14:30:46 -04:00