From nobody Fri Dec 19 08:11:50 2025 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 1511148734137774.3439829506204; Sun, 19 Nov 2017 19:32:14 -0800 (PST) Received: from localhost ([::1]:55233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGcoV-0006yp-A0 for importer@patchew.org; Sun, 19 Nov 2017 22:32:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGchc-0001lX-Ru for qemu-devel@nongnu.org; Sun, 19 Nov 2017 22:24:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGchb-0006WX-RP for qemu-devel@nongnu.org; Sun, 19 Nov 2017 22:24:56 -0500 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]:42840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eGchX-0006Tv-Ar; Sun, 19 Nov 2017 22:24:51 -0500 Received: by mail-it0-x242.google.com with SMTP id n134so10359485itg.1; Sun, 19 Nov 2017 19:24:51 -0800 (PST) Received: from localhost.localdomain (173-29-146-33.client.mchsi.com. [173.29.146.33]) by smtp.gmail.com with ESMTPSA id o207sm4476119itc.27.2017.11.19.19.24.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Nov 2017 19:24:49 -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; bh=pyTrrSquw4d1Nle1yjS1JoLIC5veExrkfU3XwIcr/Sk=; b=EwPs4Z9mSKgaHqul9cue9IvSgAQoEFLZI2zkj7oBs1Yvk/6GrEetHsModeTQdAWvq+ ccdtRPUCyFqIlLTrUL/g4qHTNX1JOENOY/3Y+Z8D+nTkfDxn0XrNU+rWJz8tT/kteDJU FY/cHpPSl3LAja8ufkqhUejckZWiiTDKBOH9nztz5zJkX6UH13Em36jdCaWYELs2fR+V 7+GSzNt2m5Qc9FRbnZjKMSMTXDXvb1E1e8VxZPiR1YR4D0eIwHV6Knxy6zV0oFUgPt7c z+9ejFfIgJLpQkI+segqYQWE6dg5u6sbFcMHhhj/6QebE+4FAev3idTIYYYRnwM0ciUa SiyA== 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; bh=pyTrrSquw4d1Nle1yjS1JoLIC5veExrkfU3XwIcr/Sk=; b=prRVH2hp8COL8exA4vDni0AJGA+gv5bN3LSVYsmCdZMQbWXQ02OZlZtzmCoZK/DX5q lwFdhWV8MOOjF7KF/JucfTcA1KccJkCYSeb1vtEjviwtSiY/Bjw9sOlwzrLg35nDQk89 hlkjiZo6lpbb+UPiqjdIEy9xqEP8fC2jq4Jpwgnpf+7EBKqIoFOnkJvBbozgx+FyVfm5 /Db+DWT0rMbD2f8QZEFWaiMJenmjhU3lnrhfAGvBE55//BhrJJ0Ci0K4dXZ1BuMGfa7o ujC99OF72T2GhYyt/kvSPk4Jj1aNz5LKV6MlNOUoebtodCsLr28u952rBDkxDpNhl21H pESA== X-Gm-Message-State: AJaThX4UUT1TCAonBY22gQ2UmLBaR03eEiUhvCQ7SbGuVZpBOAseytcb nBZHLYUNpT5LgbTQ8880bXI= X-Google-Smtp-Source: AGs4zMahRj8ADk8g01kLqjyeaWKKT1mxiAS/KsLHUuqcoSStmSZ7ubwHWYwcIStg8MSMaYzKdzI0vw== X-Received: by 10.36.57.76 with SMTP id l73mr16476246ita.17.1511148290727; Sun, 19 Nov 2017 19:24:50 -0800 (PST) From: Michael Davidsaver To: Alexander Graf , David Gibson , qemu-ppc@nongnu.org Date: Sun, 19 Nov 2017 21:24:15 -0600 Message-Id: <20171120032420.9134-8-mdavidsaver@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171120032420.9134-1-mdavidsaver@gmail.com> References: <20171120032420.9134-1-mdavidsaver@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::242 Subject: [Qemu-devel] [PATCH 07/12] 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-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