From nobody Tue Nov 17 07:54:35 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jTH7c13rJz70qj2 for ; Tue, 17 Nov 2026 07:54:36 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jTH7b6ptXz3KFT for ; Tue, 17 Nov 2026 07:54:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794902076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6fH+bufnqpU1umgz/NL7S0OuJAXsFYU+U+viRp+S8lE=; b=o8/KlbnAXTE2BfAYusdUv9C6ESm1zaQHR/UV5eXJL8WnuiGyg/3BB8aRzbL2gWet4VTtwP 6SPM4aM2TILGa/a1F96Rcou5zMgfQYp90GcUCfHTdlNvJD5rMsvWBdRvVzdpx+yCol2sN0 6KA9GMp1Oc/pOEQ5VHse46vqEAa4ptvKE1k19rr4bLrdM8x+NFdPTFpRi9pqljGFMQ0hb2 M8pd2UteXOxkIeDE/sNKg4CnRGSkL43+H9O2GRXAAl+kkB12PBhO81neSqpS7enu3aXiji ADBuJUVDPDDabs/uVVxPmWme1F/PVofpLZDi2re2YZNbEWlRmWxjvxtzjbQ26A== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794902076; b=uATkDBRA9XDik9kLnjxeG6MWYjmK2XkACBEHSiE5pGGCe9Ik8SdVehuN+Aang2AcbEkcqc IbrF8ZuP++6wQxnSJzyUfhk9Y3aED7afQc3JlRML3BCExIpAe9fFOyaqy3x/HKY/DcOAdQ Aj7dnq3Ke6l9cahKiDTZfCaO2zWxGtU3zNdsmZslLlGLFiIdG0OYywVc1AFLgdeOmbRmDj GV5SgrkX6K0I0AVKNz/L21TGBZ2AsyAl2gX7PVXE9xo0RGqD5TNgi/BOrFhBI3S+YHEMFe Xm+zvJToKSlyLkBhyIChGyGLf6kyQTDF8nBFCwLli1pwaDKu/9IxBBre6ekbMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794902076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6fH+bufnqpU1umgz/NL7S0OuJAXsFYU+U+viRp+S8lE=; b=L1KZx+/oZhDMCnavJa+y2jxnncNKnyq+ufuP+5PTN/WjSr7Mxevo8JPIof4VP6/R0fd7d1 xyp6TnR4b/9KFSUrtwP6E4tN/97ilV++kCAJ1Qw6tULm82v1eIliNOIQNxK2NRQgkgdu7g TeNi7wqSkMEMXcN1akRPgerRSgXVMLZsO4BhUeUbBsY/UTiSO6OrGvR7GsQfCmZfOtCS2Y 2zH+BSMdZc4rxrGwG5yHOQ5H6SaVhOc7m7n1QQNrfz/NDpymQeBHV9t20NRhvpLbtpEtGW eDQ1L16dAGDuqP9V24p1hwsZ+JMCCbk4MwntHl3lWmDdz3oR+nUx1AXCUBsuOQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jTH7b4kDmzYLK for ; Tue, 17 Nov 2026 07:54:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4a59 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 07:54:35 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 5daad0ba461e - main - twsi: Wait for the bus to go idle before starting a transfer List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5daad0ba461e063efbee8317a4244497d52cebb0 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 07:54:35 +0000 Message-Id: <6afc083b.4a59.76aed2d9@gitrepo.freebsd.org> The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=5daad0ba461e063efbee8317a4244497d52cebb0 commit 5daad0ba461e063efbee8317a4244497d52cebb0 Author: Emmanuel Vadot AuthorDate: 2026-11-17 07:52:05 +0000 Commit: Emmanuel Vadot CommitDate: 2026-11-17 07:53:59 +0000 twsi: Wait for the bus to go idle before starting a transfer The status register does not read as idle (0xf8) right after the previous transfer ended and the module was disabled. On fast (optimised) kernels the next transfer starts too early, sees a different status and fails with EIO ("Bad status at start of transfer"). On the Pine H64 this made the AXP805 write that disables the PHY supply fail from awg_shutdown(), leaving the PHY powered and the board hanging on warm reboot. Poll the status register for up to 1ms before declaring the bus not idle. Tested on: Pine H64 (5 warm reboots with a NODEBUG kernel) Fixes: cb167e1ae954 ("twsi: do not attempt transfer if bus is not idle") --- sys/dev/iicbus/controller/twsi/twsi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/sys/dev/iicbus/controller/twsi/twsi.c b/sys/dev/iicbus/controller/twsi/twsi.c index 570f3f81c37d..2caf1faa9924 100644 --- a/sys/dev/iicbus/controller/twsi/twsi.c +++ b/sys/dev/iicbus/controller/twsi/twsi.c @@ -79,6 +79,7 @@ #define TWSI_STATUS_DATA_RD_ACK 0x50 #define TWSI_STATUS_DATA_RD_NOACK 0x58 #define TWSI_STATUS_IDLE 0xf8 +#define TWSI_IDLE_RETRY 100 #define TWSI_DEBUG #undef TWSI_DEBUG @@ -488,6 +489,28 @@ twsi_error(struct twsi_softc *sc, int err) TWSI_WRITE(sc, sc->reg_control, sc->control_val | TWSI_CONTROL_STOP); } +/* + * The status register takes a short time to go back to the idle value after + * the module was disabled at the end of the previous transfer, and it reads + * other values in the meantime. Wait a little before saying that the bus is + * not idle. + */ +static uint32_t +twsi_wait_idle(struct twsi_softc *sc) +{ + uint32_t status; + int retry; + + status = TWSI_READ(sc, sc->reg_status); + for (retry = TWSI_IDLE_RETRY; + status != TWSI_STATUS_IDLE && retry > 0; retry--) { + DELAY(10); + status = TWSI_READ(sc, sc->reg_status); + } + + return (status); +} + static int twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) { @@ -505,7 +528,7 @@ twsi_transfer(device_t dev, struct iic_msg *msgs, uint32_t nmsgs) ("starting a transfer while another is active")); debugf(sc, "transmitting %d messages\n", nmsgs); - status = TWSI_READ(sc, sc->reg_status); + status = twsi_wait_idle(sc); debugf(sc, "status=0x%x\n", status); if (status != TWSI_STATUS_IDLE) { debugf(sc, "Bad status at start of transfer\n");