From nobody Tue Feb 10 06:58:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.50 as permitted sender) client-ip=209.85.221.50; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f50.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1623860100; cv=none; d=zohomail.com; s=zohoarc; b=KVk3LAGrxW+zoc6nKkiLsMbLotDjRAkN43VIHTVbeWpLzRDsHPHXA2MXEXFPPhxTAS9CJOF9DBPOTz6O4fiAOq04pnHdlXDhqzz4AUUtiXNrY3J1DaCwTFfAnivnQpQKJYa/E5CKhvWDvfPfUK/rB7V3kACIBWctUF4o7NOqiSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623860100; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YnpC7skv5DHlC3FSHAcwV7gYnTT6SGeWYmONsyLMX7o=; b=L86Ay3M4/yWNXOxBl6o0AZ7ibQa/rPy5MgESHiOnDjU+zPuEz/rGeLAl7ZP2vXQ+3pCwcEble+b7ITI2Mh6N33qNwqt1zzRbM0Fy8Av7CG7mqfdKOdcdyizE/SCOssNC6ans0BdJrMSds8eICLjfwtM8sY2UjDE8MrU0gRSZONc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by mx.zohomail.com with SMTPS id 1623860100837875.0282011578198; Wed, 16 Jun 2021 09:15:00 -0700 (PDT) Received: by mail-wr1-f50.google.com with SMTP id y7so3302553wrh.7 for ; Wed, 16 Jun 2021 09:15:00 -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 t4sm2632791wru.53.2021.06.16.09.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 09:14:58 -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=YnpC7skv5DHlC3FSHAcwV7gYnTT6SGeWYmONsyLMX7o=; b=U5uFFXrmFtFFjMKEeqShBc9WfToviVZLjgbgBoqIyAGpSlHZtRpiLMM0iriDBgFQzt cMwMdXSVbmzdk8RWge+lRqdkdeN4lpe0fhEdEEDgxhy/lsayVCH2EyziNR9A0rZR38T4 HLSia8GhrZKIfV5+UfIJ18ByCxZSd4SWWjcyYheDahNBk1uN4ISgi+jGLOxprQGD8nSq kQXS5gWU7HWwbhYSyzDtmGLuXujf2u0VHOqoefpKO3vbNi5QQIXTw3QxmzTZobL/X126 cxUfk/zkEMnaAwnoheu1x358yyyBjv+twwjyhy8Gq2AnFe08hTvnAXoJ9i6xTIsl8NE5 vyJw== 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=YnpC7skv5DHlC3FSHAcwV7gYnTT6SGeWYmONsyLMX7o=; b=IpDZ/OUYW0O20py7etywCM2c0FRULVYYMZJBWAzJshSBuAWcU2NzUJgOoVjRSo819K oYlSrE8KPqy8MKLLAr7+7DQt/s51Kh9kmX4QluBCBbqXN8IAWsSOamaXDtfO04unFb1p mbetzg7uAXZ2yhktf27u/KjpO/3oiL/uGwppW1xFX3CQRlDDOy+9gIIv8Fs/4ge2/kdc juWtT7KRyoVVfHbLv9urt4ASX2bBwQ07HB1WDo+4NONQGZc0/nGwKRdIg49FeImOsblh Tcl8cpWfjiNSzK6K306s6fznyPizw69f8dppwQLAHmaOnmTtd/NN1bQvVyHLyOg0tUfm 7B2Q== X-Gm-Message-State: AOAM531c99XfWLEfbEbTKBZjjjyPucPIxCMgIfHEtL4VldE0zbx3IJn8 z4//LbV4IKRV3kW++BAGpR8= X-Google-Smtp-Source: ABdhPJyCuvQerzDa/gdwo6sxV9DH8UybXciVgOuTuI/Fyc6mpfF0UiFmhZfn4TG7F6tPw1ux3Tdwbg== X-Received: by 2002:adf:f648:: with SMTP id x8mr200267wrp.215.1623860099030; Wed, 16 Jun 2021 09:14:59 -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: qemu-arm@nongnu.org, Corey Minyard , qemu-ppc@nongnu.org, "Signed-off-by : Frederic Konrad" , BALATON Zoltan , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 08/13] hw/misc/auxbus: Explode READ_I2C / WRITE_I2C_MOT cases Date: Wed, 16 Jun 2021 18:14:13 +0200 Message-Id: <20210616161418.2514095-9-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210616161418.2514095-1-f4bug@amsat.org> References: <20210616161418.2514095-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. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- 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