From nobody Fri Mar 07 06:28:04 2025 X-Original-To: dev-commits-src-main@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 4Z8GYw5rf4zt3rZ; Fri, 07 Mar 2025 06:28:04 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z8GYw3g8lz3Ms2; Fri, 07 Mar 2025 06:28:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741328884; 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=hbjDr1HcPoC3p5rrQbllFeLrkaYK8J0stwl6s7oI0+k=; b=j6QhuOq4q8dlH9zsN5gY4Ox1ML4V+YBOVdjZeBdwzCBRnyp2hA8vylM0CCzEZRDURu1VSh qW3V9XIxwmPUu1jiv1L0KKbTU7JI4L7W+EAgf1CG64IBvoeQl7NNSf1T+6W54PCTWoSJ4A hBQtPP0VZxxKIe8FTc7/l9jiGMGjp5R8PG6vL9rkS09t4Cek6mcWLcH3jLDCAeaJYId+KC UAZ6FrSeYn0mfJpwdXEDuqPdcZftbxB39TTyVMXg6LS04fZ1DDRmQsErG6PFgYe4gDAY6C q8JIhVoNsK6qp7Hl1/zNpzR987GehHxnCUfhvKK++HcjHPuEKZcY4eyEfOQEPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741328884; a=rsa-sha256; cv=none; b=u4TtqTpfueaTWt7uFkpP2H5D3/m1JUKMsk3Y9ESY4u2S7qFInyjUZKkAUatxB3EZNvTPNV 3Rep1LJIftc+d3O9Zy+nllr8lNrm2fldMyBOOtNmamQXQcBLSuqk36s4D30DSJsxrwIopT zCBd1xARMda7XjfWqV63anm1HzvXFpZSnMem7Vzd67rcc60I2GPiREUiLDY+EVEoefC6AB Dd/4pQAuSpi1or+r7dgPviEcpqSkEXIF/e08Uhouy3jKFItJLrvmH+eY9FJ4V7nS2xP/v9 hGe6Rk4UXr2YOA+Wyj/RuFuosmp4GP5xu0wVUWZ95/UzyrMso4OyDgXXtUcZhg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741328884; 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=hbjDr1HcPoC3p5rrQbllFeLrkaYK8J0stwl6s7oI0+k=; b=wmEV+qUT8PJgSLm1CcBYzhVT+4eTrH5jIzwQzcGwKodDGAMcUVPkhSR4VGI5zwL9JSmqMf Luw3zEkR8IYuJJgVJo0hyO8AcMqfk0vVJsEBCvD4je06ZSi90R+LM0O5z9VV7pAS4fsIc2 V+JiQlPSsqOGsUEKLlgZd2q235i7rT8f4Wla9RKn1q6hD3cl1QB9fq8Rcj6QbRXqMwyZhb XPfgeNKVu/o0/IlD8cRjXNezcqbwWf3ldUlUmHTE1XJLjYMeSTPELoExgplu+FXMTMWT4M /VS4HGqnxxWDRmEwj1iYNw52OjfTIyBkuB+F1m2GYJQS3DNdi4fJKIlODvUGug== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Z8GYw34pWz8vv; Fri, 07 Mar 2025 06:28:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5276S4tP093059; Fri, 7 Mar 2025 06:28:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5276S46x093056; Fri, 7 Mar 2025 06:28:04 GMT (envelope-from git) Date: Fri, 7 Mar 2025 06:28:04 GMT Message-Id: <202503070628.5276S46x093056@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: daa098cc37b9 - main - iichid(4): Wait for RESET command response while attaching List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: daa098cc37b9db36281623c00558976aea4fa90e Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=daa098cc37b9db36281623c00558976aea4fa90e commit daa098cc37b9db36281623c00558976aea4fa90e Author: Vladimir Kondratyev AuthorDate: 2025-03-07 06:26:51 +0000 Commit: Vladimir Kondratyev CommitDate: 2025-03-07 06:26:51 +0000 iichid(4): Wait for RESET command response while attaching before starting of children initialization to ensure that parent device is fully functional. Sponsored by: Future Crew LLC MFC after: 2 month Differential Revision: https://reviews.freebsd.org/D48958 --- sys/dev/iicbus/iichid.c | 55 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/sys/dev/iicbus/iichid.c b/sys/dev/iicbus/iichid.c index 1a08bd1d824a..b86858791a4d 100644 --- a/sys/dev/iicbus/iichid.c +++ b/sys/dev/iicbus/iichid.c @@ -98,6 +98,8 @@ enum { #define I2C_HID_POWER_ON 0x0 #define I2C_HID_POWER_OFF 0x1 +#define IICHID_RESET_TIMEOUT 5 /* seconds */ + /* * Since interrupt resource acquisition is not always possible (in case of GPIO * interrupts) iichid now supports a sampling_mode. @@ -156,6 +158,7 @@ enum iichid_powerstate_how { */ struct iichid_softc { device_t dev; + struct mtx mtx; bool probe_done; int probe_result; @@ -190,6 +193,7 @@ struct iichid_softc { bool open; /* iicbus lock */ bool suspend; /* iicbus lock */ bool power_on; /* iicbus lock */ + bool reset_acked; /* iichid mtx */ }; static device_probe_t iichid_probe; @@ -295,6 +299,12 @@ iichid_cmd_read(struct iichid_softc* sc, void *buf, iichid_size_t maxlen, { sc->addr, IIC_M_RD | IIC_M_NOSTART, le16toh(sc->desc.wMaxInputLength) - 2, sc->intr_buf }; actlen = 0; + if (!sc->reset_acked) { + mtx_lock(&sc->mtx); + sc->reset_acked = true; + wakeup(&sc->reset_acked); + mtx_unlock(&sc->mtx); + } #ifdef IICHID_SAMPLING } else if ((actlen <= 2 || actlen == 0xFFFF) && sc->sampling_rate_slow >= 0) { @@ -1136,21 +1146,9 @@ iichid_attach(device_t dev) device_printf(dev, "failed to power on: %d\n", error); return (ENXIO); } - /* - * Windows driver sleeps for 1ms between the SET_POWER and RESET - * commands. So we too as some devices may depend on this. - */ - pause("iichid", (hz + 999) / 1000); - - error = iichid_reset(sc); - if (error) { - device_printf(dev, "failed to reset hardware: %d\n", error); - error = ENXIO; - goto done; - } - sc->power_on = true; + mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); sc->intr_bufsize = le16toh(sc->desc.wMaxInputLength) - 2; sc->intr_buf = malloc(sc->intr_bufsize, M_DEVBUF, M_WAITOK | M_ZERO); TASK_INIT(&sc->suspend_task, 0, iichid_suspend_task, sc); @@ -1209,12 +1207,40 @@ iichid_attach(device_t dev) &sc->sampling_hysteresis, 0, "number of missing samples before enabling of slow mode"); hid_add_dynamic_quirk(&sc->hw, HQ_IICHID_SAMPLING); +#endif /* IICHID_SAMPLING */ + + /* + * Windows driver sleeps for 1ms between the SET_POWER and RESET + * commands. So we too as some devices may depend on this. + */ + pause("iichid", (hz + 999) / 1000); + + error = iichid_reset(sc); + if (error) { + device_printf(dev, "failed to reset hardware: %d\n", error); + iichid_detach(dev); + error = ENXIO; + goto done; + } + /* Wait for RESET response */ +#ifdef IICHID_SAMPLING if (sc->sampling_rate_slow >= 0) { pause("iichid", (hz + 999) / 1000); (void)iichid_cmd_read(sc, sc->intr_buf, 0, NULL); - } + } else #endif /* IICHID_SAMPLING */ + { + mtx_lock(&sc->mtx); + if (!sc->reset_acked && !cold) { + error = mtx_sleep(&sc->reset_acked, &sc->mtx, 0, + "iichid_reset", hz * IICHID_RESET_TIMEOUT); + if (error != 0) + device_printf(sc->dev, + "Reset timeout expired\n"); + } + mtx_unlock(&sc->mtx); + } child = device_add_child(dev, "hidbus", DEVICE_UNIT_ANY); if (child == NULL) { @@ -1258,6 +1284,7 @@ iichid_detach(device_t dev) free(sc->dup_buf, M_DEVBUF); #endif free(sc->intr_buf, M_DEVBUF); + mtx_destroy(&sc->mtx); return (0); }