From: Michael Davidsaver <mdavidsaver@gmail.com>
To: Alexander Graf <agraf@suse.de>,
David Gibson <david@gibson.dropbear.id.au>,
qemu-ppc@nongnu.org
Cc: qemu-devel@nongnu.org, Michael Davidsaver <mdavidsaver@gmail.com>
Subject: [Qemu-devel] [PATCH 07/12] qtest: add e500_i2c_create()
Date: Sun, 19 Nov 2017 21:24:15 -0600 [thread overview]
Message-ID: <20171120032420.9134-8-mdavidsaver@gmail.com> (raw)
In-Reply-To: <20171120032420.9134-1-mdavidsaver@gmail.com>
Add interface for testing i2c devices
with PPC e500.
Signed-off-by: Michael Davidsaver <mdavidsaver@gmail.com>
---
tests/Makefile.include | 1 +
tests/libqos/i2c-e500.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/libqos/i2c.h | 3 +++
3 files changed, 70 insertions(+)
create mode 100644 tests/libqos/i2c-e500.c
diff --git a/tests/Makefile.include b/tests/Makefile.include
index c002352134..ad1c219423 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -721,6 +721,7 @@ libqos-pc-obj-y += tests/libqos/malloc-pc.o tests/libqos/libqos-pc.o
libqos-pc-obj-y += tests/libqos/ahci.o
libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
libqos-imx-obj-y = $(libqos-obj-y) tests/libqos/i2c-imx.o
+libqos-e500-obj-y = $(libqos-obj-y) tests/libqos/i2c-e500.o
libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o
libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o
diff --git a/tests/libqos/i2c-e500.c b/tests/libqos/i2c-e500.c
new file mode 100644
index 0000000000..4272ada0a5
--- /dev/null
+++ b/tests/libqos/i2c-e500.c
@@ -0,0 +1,66 @@
+/*
+ * QTest I2C driver
+ *
+ * Copyright (c) 2016 Michael Davidsaver
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "libqos/i2c.h"
+
+
+#include "qemu/bswap.h"
+#include "libqtest.h"
+
+typedef struct E500I2C {
+ I2CAdapter parent;
+
+ uint64_t addr;
+} E500I2C;
+
+static void e500_i2c_send(I2CAdapter *i2c, uint8_t addr,
+ const uint8_t *buf, uint16_t len)
+{
+ E500I2C *s = (E500I2C *)i2c;
+
+ writeb(s->addr + 0x8, 0xb0); /* Enable and START a write */
+ writeb(s->addr + 0x10, addr & 0xfe); /* Send address for write */
+
+ while (len--) {
+ writeb(s->addr + 0x10, *buf++);
+ }
+
+ writeb(s->addr + 0x8, 0x80); /* STOP but leave enabled */
+}
+
+static void e500_i2c_recv(I2CAdapter *i2c, uint8_t addr,
+ uint8_t *buf, uint16_t len)
+{
+ E500I2C *s = (E500I2C *)i2c;
+
+ writeb(s->addr + 0x8, 0xa0); /* Enable and START a read */
+ writeb(s->addr + 0x10, addr | 1); /* Send address for read */
+
+ /* reads are "pipelined" so the initial value is junk */
+ readb(s->addr + 0x10);
+
+ while (len--) {
+ *buf++ = readb(s->addr + 0x10);
+ }
+
+ writeb(s->addr + 0x8, 0x80); /* STOP but leave enabled */
+}
+
+I2CAdapter *e500_i2c_create(uint64_t ccsr_base)
+{
+ E500I2C *s = g_malloc0(sizeof(*s));
+ I2CAdapter *i2c = (I2CAdapter *)s;
+
+ s->addr = ccsr_base + 0x3000;
+
+ i2c->send = e500_i2c_send;
+ i2c->recv = e500_i2c_recv;
+
+ return i2c;
+}
diff --git a/tests/libqos/i2c.h b/tests/libqos/i2c.h
index 6e648f922a..40c59a7997 100644
--- a/tests/libqos/i2c.h
+++ b/tests/libqos/i2c.h
@@ -29,4 +29,7 @@ I2CAdapter *omap_i2c_create(uint64_t addr);
/* libi2c-imx.c */
I2CAdapter *imx_i2c_create(uint64_t addr);
+/* i2c-e500.c */
+I2CAdapter *e500_i2c_create(uint64_t ccsr_base);
+
#endif
--
2.11.0
next prev parent reply other threads:[~2017-11-20 3:24 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-20 3:24 [Qemu-devel] [PATCH 00/12] Add MVME3100 PPC SBC Michael Davidsaver
2017-11-20 3:24 ` [Qemu-devel] [PATCH 01/12] e500: add board config options Michael Davidsaver
2017-11-22 3:28 ` David Gibson
2017-11-22 17:55 ` Michael Davidsaver
2017-11-23 16:07 ` [Qemu-devel] [Qemu-ppc] " Cédric Le Goater
2017-11-24 0:21 ` [Qemu-devel] " David Gibson
2017-11-20 3:24 ` [Qemu-devel] [PATCH 03/12] e500: note possible bug with host bridge Michael Davidsaver
2017-11-22 3:46 ` David Gibson
2017-11-22 4:57 ` Michael Davidsaver
2017-11-20 3:24 ` [Qemu-devel] [PATCH 04/12] e500: additional CCSR registers Michael Davidsaver
2017-11-22 3:57 ` David Gibson
2017-11-20 3:24 ` [Qemu-devel] [PATCH 05/12] e500: name openpic and pci host bridge Michael Davidsaver
2017-11-22 3:58 ` David Gibson
2017-11-20 3:24 ` [Qemu-devel] [PATCH 06/12] i2c: add mpc8540 i2c controller Michael Davidsaver
2017-11-22 4:06 ` David Gibson
2017-11-23 15:39 ` [Qemu-devel] [Qemu-ppc] " Cédric Le Goater
2017-11-24 0:13 ` David Gibson
2017-11-20 3:24 ` Michael Davidsaver [this message]
2017-11-20 3:24 ` [Qemu-devel] [PATCH 08/12] e500: add mpc8540 i2c controller to ccsr Michael Davidsaver
2017-11-22 4:08 ` David Gibson
2017-11-22 16:46 ` Michael Davidsaver
2017-11-20 3:24 ` [Qemu-devel] [PATCH 09/12] nvram: add AT24Cx i2c eeprom Michael Davidsaver
2017-11-22 4:10 ` David Gibson
2017-11-20 3:24 ` [Qemu-devel] [PATCH 10/12] timer: add ds1375 RTC Michael Davidsaver
2017-11-22 4:11 ` David Gibson
2017-11-20 3:24 ` [Qemu-devel] [PATCH 11/12] ppc: add mvme3100 machine Michael Davidsaver
2017-11-20 3:24 ` [Qemu-devel] [PATCH 12/12] tests: add mvme3100-test Michael Davidsaver
[not found] ` <20171120032420.9134-3-mdavidsaver@gmail.com>
2017-11-22 3:36 ` [Qemu-devel] [PATCH 02/12] e500: consolidate mpc8540 guts with e500-ccsr David Gibson
2017-12-06 3:12 ` David Gibson
2017-12-06 3:18 ` Michael Davidsaver
2017-12-06 4:23 ` David Gibson
2017-11-22 4:12 ` [Qemu-devel] [PATCH 00/12] Add MVME3100 PPC SBC David Gibson
2017-11-22 4:58 ` Michael Davidsaver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171120032420.9134-8-mdavidsaver@gmail.com \
--to=mdavidsaver@gmail.com \
--cc=agraf@suse.de \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.