diff options
author | Peter Maydell | 2019-06-03 19:26:21 +0200 |
---|---|---|
committer | Peter Maydell | 2019-06-03 19:26:21 +0200 |
commit | e2a58ff493a2e00db3e963c1839c5374500110f2 (patch) | |
tree | 1136df9621eb962326714fa330eaad310fb8de12 /tests/libqos/i2c.c | |
parent | Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jun-1-2019' i... (diff) | |
parent | q35: Revert to kernel irqchip (diff) | |
download | qemu-e2a58ff493a2e00db3e963c1839c5374500110f2.tar.gz qemu-e2a58ff493a2e00db3e963c1839c5374500110f2.tar.xz qemu-e2a58ff493a2e00db3e963c1839c5374500110f2.zip |
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
* Revert q35 to kernel irqchip (Alex)
* edu device fixes (Li Qiang)
* cleanups (Marc-André, Peter)
* Improvements to -accel help
* Better support for IA32_MISC_ENABLE MSR (Wanpeng)
* I2C test conversion to qgraph (Paolo)
# gpg: Signature made Mon 03 Jun 2019 14:20:12 BST
# gpg: using RSA key BFFBD25F78C7AE83
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full]
# gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" [full]
# Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1
# Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83
* remotes/bonzini/tags/for-upstream: (24 commits)
q35: Revert to kernel irqchip
configure: remove tpm_passthrough & tpm_emulator
ci: store Patchew configuration in the tree
libqos: i2c: move address into QI2CDevice
tests: convert ds1338-test to qtest
tests: convert OMAP i2c tests to qgraph
libqos: add ARM imx25-pdk machine object
libqos: add ARM n800 machine object
libqos: convert I2C to qgraph
libqos: split I2CAdapter initialization and allocation
imx25-pdk: create ds1338 for qtest inside the test
pca9552-test: do not rely on state across tests
libqos: fix omap-i2c receiving more than 4 bytes
libqos: move common i2c code to libqos
qgraph: fix qos_node_contains with options
qgraph: allow extra_device_opts on contains nodes
edu: uses uint64_t in dma operation
edu: mmio: allow 64-bit access in read dispatch
edu: mmio: allow 64-bit access
i386: Enable IA32_MISC_ENABLE MWAIT bit when exposing mwait/monitor
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests/libqos/i2c.c')
-rw-r--r-- | tests/libqos/i2c.c | 74 |
1 files changed, 68 insertions, 6 deletions
diff --git a/tests/libqos/i2c.c b/tests/libqos/i2c.c index 23bc2a3eb2..156114e745 100644 --- a/tests/libqos/i2c.c +++ b/tests/libqos/i2c.c @@ -10,14 +10,76 @@ #include "libqos/i2c.h" #include "libqtest.h" -void i2c_send(I2CAdapter *i2c, uint8_t addr, - const uint8_t *buf, uint16_t len) +void i2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len) { - i2c->send(i2c, addr, buf, len); + i2cdev->bus->send(i2cdev->bus, i2cdev->addr, buf, len); } -void i2c_recv(I2CAdapter *i2c, uint8_t addr, - uint8_t *buf, uint16_t len) +void i2c_recv(QI2CDevice *i2cdev, uint8_t *buf, uint16_t len) { - i2c->recv(i2c, addr, buf, len); + i2cdev->bus->recv(i2cdev->bus, i2cdev->addr, buf, len); +} + +void i2c_read_block(QI2CDevice *i2cdev, uint8_t reg, + uint8_t *buf, uint16_t len) +{ + i2c_send(i2cdev, ®, 1); + i2c_recv(i2cdev, buf, len); +} + +void i2c_write_block(QI2CDevice *i2cdev, uint8_t reg, + const uint8_t *buf, uint16_t len) +{ + uint8_t *cmd = g_malloc(len + 1); + cmd[0] = reg; + memcpy(&cmd[1], buf, len); + i2c_send(i2cdev, cmd, len + 1); + g_free(cmd); +} + +uint8_t i2c_get8(QI2CDevice *i2cdev, uint8_t reg) +{ + uint8_t resp[1]; + i2c_read_block(i2cdev, reg, resp, sizeof(resp)); + return resp[0]; +} + +uint16_t i2c_get16(QI2CDevice *i2cdev, uint8_t reg) +{ + uint8_t resp[2]; + i2c_read_block(i2cdev, reg, resp, sizeof(resp)); + return (resp[0] << 8) | resp[1]; +} + +void i2c_set8(QI2CDevice *i2cdev, uint8_t reg, uint8_t value) +{ + i2c_write_block(i2cdev, reg, &value, 1); +} + +void i2c_set16(QI2CDevice *i2cdev, uint8_t reg, uint16_t value) +{ + uint8_t data[2]; + + data[0] = value >> 8; + data[1] = value & 255; + i2c_write_block(i2cdev, reg, data, sizeof(data)); +} + +void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr) +{ + QI2CDevice *i2cdev = g_new0(QI2CDevice, 1); + + i2cdev->bus = i2c_bus; + if (addr) { + i2cdev->addr = ((QI2CAddress *)addr)->addr; + } + return &i2cdev->obj; +} + +void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr) +{ + g_assert(addr); + + opts->arg = addr; + opts->size_arg = sizeof(QI2CAddress); } |