summaryrefslogtreecommitdiffstats
path: root/tests/libqos/i2c-omap.c
diff options
context:
space:
mode:
authorPeter Maydell2019-06-03 19:26:21 +0200
committerPeter Maydell2019-06-03 19:26:21 +0200
commite2a58ff493a2e00db3e963c1839c5374500110f2 (patch)
tree1136df9621eb962326714fa330eaad310fb8de12 /tests/libqos/i2c-omap.c
parentMerge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jun-1-2019' i... (diff)
parentq35: Revert to kernel irqchip (diff)
downloadqemu-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-omap.c')
-rw-r--r--tests/libqos/i2c-omap.c70
1 files changed, 47 insertions, 23 deletions
diff --git a/tests/libqos/i2c-omap.c b/tests/libqos/i2c-omap.c
index 1ef6e7b200..9ae8214fa8 100644
--- a/tests/libqos/i2c-omap.c
+++ b/tests/libqos/i2c-omap.c
@@ -40,12 +40,6 @@ enum OMAPI2CCONBits {
OMAP_I2C_CON_I2C_EN = 1 << 15,
};
-typedef struct OMAPI2C {
- I2CAdapter parent;
-
- uint64_t addr;
-} OMAPI2C;
-
static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr)
{
@@ -59,7 +53,7 @@ static void omap_i2c_set_slave_addr(OMAPI2C *s, uint8_t addr)
static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr,
const uint8_t *buf, uint16_t len)
{
- OMAPI2C *s = (OMAPI2C *)i2c;
+ OMAPI2C *s = container_of(i2c, OMAPI2C, parent);
uint16_t data;
omap_i2c_set_slave_addr(s, addr);
@@ -103,8 +97,9 @@ static void omap_i2c_send(I2CAdapter *i2c, uint8_t addr,
static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr,
uint8_t *buf, uint16_t len)
{
- OMAPI2C *s = (OMAPI2C *)i2c;
+ OMAPI2C *s = container_of(i2c, OMAPI2C, parent);
uint16_t data, stat;
+ uint16_t orig_len = len;
omap_i2c_set_slave_addr(s, addr);
@@ -116,16 +111,24 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr,
OMAP_I2C_CON_STT |
OMAP_I2C_CON_STP;
qtest_writew(i2c->qts, s->addr + OMAP_I2C_CON, data);
- data = qtest_readw(i2c->qts, s->addr + OMAP_I2C_CON);
- g_assert((data & OMAP_I2C_CON_STP) == 0);
data = qtest_readw(i2c->qts, s->addr + OMAP_I2C_STAT);
g_assert((data & OMAP_I2C_STAT_NACK) == 0);
- data = qtest_readw(i2c->qts, s->addr + OMAP_I2C_CNT);
- g_assert_cmpuint(data, ==, len);
-
while (len > 0) {
+ data = qtest_readw(i2c->qts, s->addr + OMAP_I2C_CON);
+ if (len <= 4) {
+ g_assert((data & OMAP_I2C_CON_STP) == 0);
+
+ data = qtest_readw(i2c->qts, s->addr + OMAP_I2C_CNT);
+ g_assert_cmpuint(data, ==, orig_len);
+ } else {
+ g_assert((data & OMAP_I2C_CON_STP) != 0);
+
+ data = qtest_readw(i2c->qts, s->addr + OMAP_I2C_CNT);
+ g_assert_cmpuint(data, ==, len - 4);
+ }
+
data = qtest_readw(i2c->qts, s->addr + OMAP_I2C_STAT);
g_assert((data & OMAP_I2C_STAT_RRDY) != 0);
g_assert((data & OMAP_I2C_STAT_ROVR) == 0);
@@ -152,21 +155,42 @@ static void omap_i2c_recv(I2CAdapter *i2c, uint8_t addr,
g_assert((data & OMAP_I2C_CON_STP) == 0);
}
-I2CAdapter *omap_i2c_create(QTestState *qts, uint64_t addr)
+static void *omap_i2c_get_driver(void *obj, const char *interface)
+{
+ OMAPI2C *s = obj;
+ if (!g_strcmp0(interface, "i2c-bus")) {
+ return &s->parent;
+ }
+ fprintf(stderr, "%s not present in omap_i2c\n", interface);
+ g_assert_not_reached();
+}
+
+static void omap_i2c_start_hw(QOSGraphObject *object)
{
- OMAPI2C *s = g_malloc0(sizeof(*s));
- I2CAdapter *i2c = (I2CAdapter *)s;
+ OMAPI2C *s = (OMAPI2C *) object;
uint16_t data;
+ /* verify the mmio address by looking for a known signature */
+ data = qtest_readw(s->parent.qts, s->addr + OMAP_I2C_REV);
+ g_assert_cmphex(data, ==, 0x34);
+}
+
+void omap_i2c_init(OMAPI2C *s, QTestState *qts, uint64_t addr)
+{
s->addr = addr;
- i2c->send = omap_i2c_send;
- i2c->recv = omap_i2c_recv;
- i2c->qts = qts;
+ s->obj.get_driver = omap_i2c_get_driver;
+ s->obj.start_hw = omap_i2c_start_hw;
- /* verify the mmio address by looking for a known signature */
- data = qtest_readw(qts, addr + OMAP_I2C_REV);
- g_assert_cmphex(data, ==, 0x34);
+ s->parent.send = omap_i2c_send;
+ s->parent.recv = omap_i2c_recv;
+ s->parent.qts = qts;
+}
- return i2c;
+static void omap_i2c_register_nodes(void)
+{
+ qos_node_create_driver("omap_i2c", NULL);
+ qos_node_produces("omap_i2c", "i2c-bus");
}
+
+libqos_init(omap_i2c_register_nodes);