From nobody Sun Feb 8 19:56:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511733731160931.2214555558371; Sun, 26 Nov 2017 14:02:11 -0800 (PST) Received: from localhost ([::1]:58147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJ4zu-0008Qb-0O for importer@patchew.org; Sun, 26 Nov 2017 17:01:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJ4xm-00072G-Rm for qemu-devel@nongnu.org; Sun, 26 Nov 2017 16:59:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJ4xl-0002rs-Fc for qemu-devel@nongnu.org; Sun, 26 Nov 2017 16:59:46 -0500 Received: from mail-io0-x244.google.com ([2607:f8b0:4001:c06::244]:44913) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eJ4xl-0002rk-Af; Sun, 26 Nov 2017 16:59:45 -0500 Received: by mail-io0-x244.google.com with SMTP id w127so34263754iow.11; Sun, 26 Nov 2017 13:59:45 -0800 (PST) Received: from localhost.localdomain (173-29-146-33.client.mchsi.com. [173.29.146.33]) by smtp.gmail.com with ESMTPSA id n184sm6517218itg.9.2017.11.26.13.59.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Nov 2017 13:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=pyTrrSquw4d1Nle1yjS1JoLIC5veExrkfU3XwIcr/Sk=; b=LgS5xVbHtD69VrnJFUziRr+ybSCN2Ry1Lf85Bji5vVZh9DpBkGKMYIxJE6gm1IVDfq T3eXMrLEcsbUqAR3vLBWrfnD2qNsZQnSHLwRcA2NJVLaCEPRRBccTYaDKVA7b/Mglkjs +pfYIJUWKLCY5vlFTLT7Jwfk1qQfV4eP1f6zophlLQPu9cmnbHNNJtQTPQf3KAhaNpn0 OZjoqWFtI7Hgh+yj6qyfEJt2UB6BURIE6thuuhB35bIOKR1SxgdFe+eEZhhh2EFW5Zya ytCXC/GFdkFFXe+myw5yy1LZ8hZHbJL37jlnpH24YsKnHpzJWvAQ/YENyizuZDxJNryz PnXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=pyTrrSquw4d1Nle1yjS1JoLIC5veExrkfU3XwIcr/Sk=; b=HFliImmnbfMBh6WGgc2ibrbqLfxLxfxgAZk9deNoQl6eBhXWs4AJHwPh6JABaES0IN SdI0Vnu/CIaNqIpd4MajSXiby2+kefUwJ9QpOxFpC+tOIb2XizL/I8YHY1mCxtgIMlRq uXTHEE5+uh5k6fs/vZftAcCBrXX64e3YYoPtns4WbN+br+6bguMhWM4dUHkIzSngX85j jwpAxJWW/wyfTHpyXgksowNaHYyhr6GoyQ5JKQyX6/Q3NquM/+KbGcQUO8urJzFD3s2F euA90uPMspckbwmVNq8Z1DlH/9x9kFQ5l7IUJtp1ZrA9lyGuCnWdRaT54yg/6+VDGz0I JFaQ== X-Gm-Message-State: AJaThX5/AYQM7pb1QZnOrW4oRJvWwRVHpehnPCh048iQQ/gY6zpOdzWs tjPxgrwskCK4JtXicmmOXG4= X-Google-Smtp-Source: AGs4zMacuKvjp/r5WrWStn77jObVJ7KLvMNoClmSmOYwFx6vB8xtXEeO3/cOofq0xLUUGpjywJxUvA== X-Received: by 10.107.10.69 with SMTP id u66mr39442277ioi.230.1511733584588; Sun, 26 Nov 2017 13:59:44 -0800 (PST) From: Michael Davidsaver To: Alexander Graf , David Gibson Date: Sun, 26 Nov 2017 15:59:02 -0600 Message-Id: <5525ca41a3ce3d5af7755d337b382fede3ef530e.1511731946.git.mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::244 Subject: [Qemu-devel] [PATCH 04/17] qtest: add e500_i2c_create() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Davidsaver , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add interface for testing i2c devices with PPC e500. Signed-off-by: Michael Davidsaver --- 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 +=3D tests/libqos/malloc-pc.o tests/lib= qos/libqos-pc.o libqos-pc-obj-y +=3D tests/libqos/ahci.o libqos-omap-obj-y =3D $(libqos-obj-y) tests/libqos/i2c-omap.o libqos-imx-obj-y =3D $(libqos-obj-y) tests/libqos/i2c-imx.o +libqos-e500-obj-y =3D $(libqos-obj-y) tests/libqos/i2c-e500.o libqos-usb-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos= /usb.o libqos-virtio-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/lib= qos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/lib= qos/malloc-generic.o =20 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 late= r. + * 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 =3D (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 =3D (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++ =3D readb(s->addr + 0x10); + } + + writeb(s->addr + 0x8, 0x80); /* STOP but leave enabled */ +} + +I2CAdapter *e500_i2c_create(uint64_t ccsr_base) +{ + E500I2C *s =3D g_malloc0(sizeof(*s)); + I2CAdapter *i2c =3D (I2CAdapter *)s; + + s->addr =3D ccsr_base + 0x3000; + + i2c->send =3D e500_i2c_send; + i2c->recv =3D 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); =20 +/* i2c-e500.c */ +I2CAdapter *e500_i2c_create(uint64_t ccsr_base); + #endif --=20 2.11.0