From nobody Tue Feb 10 03:38:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.48 as permitted sender) client-ip=209.85.221.48; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f48.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1623930855; cv=none; d=zohomail.com; s=zohoarc; b=FEUCVxf0W/fFPsxlVsbeXaP62endXDBL0lOjFsJAoXnFrhgyZAou00n7ijWVpDyi5+mT97RcrgrXDvrk2TaKfybozBjvhULlmdB2boByjcoKjqe/Q77OWJbqMFUEVogW52Q70HJlqgminBSV+NpMzAwpwyAIOKpiI5bWPHukY4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623930855; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=mF7eiAdIfTv9rlxceo15bFIxRiqB6zGPW3KZaJR5WqY=; b=Ii69dIvH3rSxaZNcCoHY+YjGt0SNLDWvnJsj5utjuuytocoMM5GmHD9SZfxhZ0IgyqNPLfJZtfHAjgFbRGQAY5dW90vPNU4DPy2LQINkLX4aQ5Ux8NefxLmuvrjRDjxPo+j/lZO37f52mBJCOtCn8JvieTt1KASqWBL+SX2AvVA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by mx.zohomail.com with SMTPS id 1623930855707655.4328350184384; Thu, 17 Jun 2021 04:54:15 -0700 (PDT) Received: by mail-wr1-f48.google.com with SMTP id d11so4085857wrm.0 for ; Thu, 17 Jun 2021 04:54:15 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (93.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.93]) by smtp.gmail.com with ESMTPSA id q3sm5353360wrz.71.2021.06.17.04.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 04:54:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mF7eiAdIfTv9rlxceo15bFIxRiqB6zGPW3KZaJR5WqY=; b=JPiiubiExRrQKBsdszp7UUvTYYhP0JJkS8zd/Voextvc83gla6v7bKo/p9EuBXcTHK kK6LtQeWATZc8kBPBsAoV6UpFkPVlfDe0MH7/+C6LwAcvJwny6UdrKjniGQEADe2Ebf6 w3pSKIQ0wIAxctL2tj30eKV5yPO7gl5RpeQjNqRYOd8cO2yQeKlDpgxHgdoQLkQRfp5c Q2gp2C6hXQXfRHpBxN3tFgqzfUJ5JXtxJTudZYt5OibUyQc+rTrFaxfahfwumD3NAhCP E2O2UH+O/77PYxgOFxbUAB4nvWZmdHA4Uk+fW93aHDP62WvLDnkfbynccnZy3PRxIOov LEHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mF7eiAdIfTv9rlxceo15bFIxRiqB6zGPW3KZaJR5WqY=; b=Z/qctaNqdSxkokaZjFGeuXP2sSYLp/lTTFOmCZgcLuOZMOJ/SP5P1LMqYllvd5+D57 tBo/abbyKTBoGog2+0ltzmtD7+3NBstyJ28t9EfFdsrgSAINOYJfeQqVBsB7PFFtHaIP 6gzB05kRlLnGMnzod/pCv8nGM0aAkVPuc9nVoMUvDxxPpaczaZr81Scu6H1jKnykCtBd Fhviu7WEGVlPMKBtKYZLCznS3RbK8KPjhihpMqo/wCCAg0yg0LEU3916cChBe8dLUpzO ucvF2CQcJDkDtdfnYh4k9pGPv+NJWqUaCfrreIg/rehxQ7ROjvgg/6LBNeWvwpa8gPqx 9spA== X-Gm-Message-State: AOAM533vj6DdlA4c41RNw/ZE75QbK2A2UgJikaX83a6dUjYJ+PP01ww2 Y5ewpw7tylg4cYmiXtX/dm0= X-Google-Smtp-Source: ABdhPJy7L9o0KzEjyXX1qK62ulMKIaKv2GZAJCvx2gqqCFd3u/qYax0aNC2uDu0Z8yii393mGwUAdg== X-Received: by 2002:adf:a1c1:: with SMTP id v1mr5230119wrv.234.1623930854005; Thu, 17 Jun 2021 04:54:14 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Corey Minyard , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson Subject: [PATCH v5 08/15] hw/misc/auxbus: Explode READ_I2C / WRITE_I2C_MOT cases Date: Thu, 17 Jun 2021 13:53:27 +0200 Message-Id: <20210617115334.2761573-9-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617115334.2761573-1-f4bug@amsat.org> References: <20210617115334.2761573-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) To allow further simplifications in the following commits, start copying WRITE_I2C code to the READ_I2C, and READ_I2C_MOT to WRITE_I2C_MOT. No logical change. Reviewed-by: Richard Henderson Acked-by: Corey Minyard Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/misc/auxbus.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/hw/misc/auxbus.c b/hw/misc/auxbus.c index 148b070ce4a..9cc9cf3be32 100644 --- a/hw/misc/auxbus.c +++ b/hw/misc/auxbus.c @@ -133,6 +133,26 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint= 32_t address, * Classic I2C transactions.. */ case READ_I2C: + is_write =3D cmd =3D=3D READ_I2C ? false : true; + if (i2c_bus_busy(i2c_bus)) { + i2c_end_transfer(i2c_bus); + } + + if (i2c_start_transfer(i2c_bus, address, !is_write)) { + ret =3D AUX_I2C_NACK; + break; + } + + ret =3D AUX_I2C_ACK; + while (len > 0) { + if (i2c_send_recv(i2c_bus, data++, is_write) < 0) { + ret =3D AUX_I2C_NACK; + break; + } + len--; + } + i2c_end_transfer(i2c_bus); + break; case WRITE_I2C: is_write =3D cmd =3D=3D READ_I2C ? false : true; if (i2c_bus_busy(i2c_bus)) { @@ -163,6 +183,39 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint= 32_t address, * - We changed the address. */ case WRITE_I2C_MOT: + is_write =3D cmd =3D=3D READ_I2C_MOT ? false : true; + ret =3D AUX_I2C_NACK; + if (!i2c_bus_busy(i2c_bus)) { + /* + * No transactions started.. + */ + if (i2c_start_transfer(i2c_bus, address, !is_write)) { + break; + } + } else if ((address !=3D bus->last_i2c_address) || + (bus->last_transaction !=3D cmd)) { + /* + * Transaction started but we need to restart.. + */ + i2c_end_transfer(i2c_bus); + if (i2c_start_transfer(i2c_bus, address, !is_write)) { + break; + } + } + + bus->last_transaction =3D cmd; + bus->last_i2c_address =3D address; + while (len > 0) { + if (i2c_send_recv(i2c_bus, data++, is_write) < 0) { + i2c_end_transfer(i2c_bus); + break; + } + len--; + } + if (len =3D=3D 0) { + ret =3D AUX_I2C_ACK; + } + break; case READ_I2C_MOT: is_write =3D cmd =3D=3D READ_I2C_MOT ? false : true; ret =3D AUX_I2C_NACK; --=20 2.31.1