From nobody Mon May 13 22:39:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1592751222; cv=none; d=zohomail.com; s=zohoarc; b=cf8MeYTZdELkb2gPSJm+hKDsi8OwFZJ/zmMhveqFdqn7DpukYvHSKn0gzOR81hUNNLPMbF9dhoYKHN9jpeWJM5qC23d6KB5inNFonFwgl3jCY+MWgWCNYQ9YKXqbauyW83mYfJiBCLgBa/iXwl9EHQtCwFMce+bSw76aGTtrwu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592751222; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=SE0t/qG4yJZQ6BJCzmQe6ZLEi6JfOLNuWA8KygLuqws=; b=mt3IuIRHvC/zQzJtJvCaStfE13eHQ4SUxUrEbX+ya46S28PHsoccp0Re8MoLL3x/ek/KWb73iPCOOfTq1VcXaFoiuqqGucwIBldAOYoZDWZxRa9Vm7bv8k4D/uzvkqEARNFs5kRAfX1GPjUGthaDfTa3p7FoflmP+JT+b5LIbRI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592751222647809.6343465230111; Sun, 21 Jun 2020 07:53:42 -0700 (PDT) Received: from localhost ([::1]:58048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jn1Lo-0006Kr-SM for importer@patchew.org; Sun, 21 Jun 2020 10:53:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jn1Kv-0005IB-6j for qemu-devel@nongnu.org; Sun, 21 Jun 2020 10:52:45 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:52758) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jn1Kr-00022w-Q8 for qemu-devel@nongnu.org; Sun, 21 Jun 2020 10:52:44 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id C759074594E; Sun, 21 Jun 2020 16:52:35 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 9E241745712; Sun, 21 Jun 2020 16:52:35 +0200 (CEST) From: BALATON Zoltan Subject: [PATCH] i2c: Match parameters of i2c_start_transfer and i2c_send_recv Date: Sun, 21 Jun 2020 16:43:38 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Message-Id: <20200621145235.9E241745712@zero.eik.bme.hu> X-Spam-Probability: 8% Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , KONRAD Frederic , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" These functions have a parameter that decides the direction of transfer but totally confusingly they don't match but inverted sense. To avoid frequent mistakes when using these functions change i2c_send_recv to match i2c_start_transfer. Also use bool in i2c_start_transfer instead of int to match i2c_send_recv. Signed-off-by: BALATON Zoltan --- Looks like hw/misc/auxbus.c already got this wrong and calls both i2c_start_transfer and i2c_send_recv with same is_write parameter. Although the name of the is_write variable suggest this may need to be inverted I'm not sure what that value actially means and which usage was correct so I did not touch it. Someone knowing this device might want to review and fix it. hw/display/sm501.c | 2 +- hw/i2c/core.c | 34 +++++++++++++++++----------------- hw/i2c/ppc4xx_i2c.c | 2 +- include/hw/i2c/i2c.h | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/hw/display/sm501.c b/hw/display/sm501.c index 2db347dcbc..ccd0a6e376 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -1034,7 +1034,7 @@ static void sm501_i2c_write(void *opaque, hwaddr addr= , uint64_t value, int i; for (i =3D 0; i <=3D s->i2c_byte_count; i++) { res =3D i2c_send_recv(s->i2c_bus, &s->i2c_data[i], - !(s->i2c_addr & 1)); + s->i2c_addr & 1); if (res) { s->i2c_status |=3D SM501_I2C_STATUS_ERROR; return; diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 1aac457a2a..c9d01df427 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -91,7 +91,7 @@ int i2c_bus_busy(I2CBus *bus) * without releasing the bus. If that fails, the bus is still * in a transaction. */ -int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv) +int i2c_start_transfer(I2CBus *bus, uint8_t address, bool recv) { BusChild *kid; I2CSlaveClass *sc; @@ -175,26 +175,14 @@ void i2c_end_transfer(I2CBus *bus) bus->broadcast =3D false; } =20 -int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send) +int i2c_send_recv(I2CBus *bus, uint8_t *data, bool recv) { I2CSlaveClass *sc; I2CSlave *s; I2CNode *node; int ret =3D 0; =20 - if (send) { - QLIST_FOREACH(node, &bus->current_devs, next) { - s =3D node->elt; - sc =3D I2C_SLAVE_GET_CLASS(s); - if (sc->send) { - trace_i2c_send(s->address, *data); - ret =3D ret || sc->send(s, *data); - } else { - ret =3D -1; - } - } - return ret ? -1 : 0; - } else { + if (recv) { ret =3D 0xff; if (!QLIST_EMPTY(&bus->current_devs) && !bus->broadcast) { sc =3D I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->el= t); @@ -206,19 +194,31 @@ int i2c_send_recv(I2CBus *bus, uint8_t *data, bool se= nd) } *data =3D ret; return 0; + } else { + QLIST_FOREACH(node, &bus->current_devs, next) { + s =3D node->elt; + sc =3D I2C_SLAVE_GET_CLASS(s); + if (sc->send) { + trace_i2c_send(s->address, *data); + ret =3D ret || sc->send(s, *data); + } else { + ret =3D -1; + } + } + return ret ? -1 : 0; } } =20 int i2c_send(I2CBus *bus, uint8_t data) { - return i2c_send_recv(bus, &data, true); + return i2c_send_recv(bus, &data, false); } =20 uint8_t i2c_recv(I2CBus *bus) { uint8_t data =3D 0xff; =20 - i2c_send_recv(bus, &data, false); + i2c_send_recv(bus, &data, true); return data; } =20 diff --git a/hw/i2c/ppc4xx_i2c.c b/hw/i2c/ppc4xx_i2c.c index c0a8e04567..d3899203a4 100644 --- a/hw/i2c/ppc4xx_i2c.c +++ b/hw/i2c/ppc4xx_i2c.c @@ -239,7 +239,7 @@ static void ppc4xx_i2c_writeb(void *opaque, hwaddr addr= , uint64_t value, } } if (!(i2c->sts & IIC_STS_ERR) && - i2c_send_recv(i2c->bus, &i2c->mdata[i], !recv)) { + i2c_send_recv(i2c->bus, &i2c->mdata[i], recv)) { i2c->sts |=3D IIC_STS_ERR; i2c->extsts |=3D IIC_EXTSTS_XFRA; break; diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index 4117211565..a09ab9230b 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -72,10 +72,10 @@ struct I2CBus { I2CBus *i2c_init_bus(DeviceState *parent, const char *name); void i2c_set_slave_address(I2CSlave *dev, uint8_t address); int i2c_bus_busy(I2CBus *bus); -int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv); +int i2c_start_transfer(I2CBus *bus, uint8_t address, bool recv); void i2c_end_transfer(I2CBus *bus); void i2c_nack(I2CBus *bus); -int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send); +int i2c_send_recv(I2CBus *bus, uint8_t *data, bool recv); int i2c_send(I2CBus *bus, uint8_t data); uint8_t i2c_recv(I2CBus *bus); =20 --=20 2.21.3