From nobody Sat Jul 1 17:20:49 2023 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 4Qtf8y0xclz4l8X6; Sat, 1 Jul 2023 17:20:50 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Qtf8x6cN9z3pTX; Sat, 1 Jul 2023 17:20:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688232049; 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=IRRjMDlYChW/YW593gRE53QcXcZ9me/ZgPqd6Jh4cVk=; b=o6HIQoC3d/gA1JicSRGa2kWhhju1Q9UzogFi3M56SS97VW595Qd+IUqYD7YAcSEWQ7O7X6 HoU2ZzuybhCu1D/WOWoNlRTNL5Cg0rl27a6xPgjkNkN6e6UTdpGALEp9l7tCWC/ehkXxBW PqLGpEwV6De4CH3dLi6I+VKxYHLhkws9/XOM4lfTkk0DRnnfnzDpKI2qhO+J0zClEjDwhK ylbBpgq6Tb6X5P52Kd6ugiHLDDascaki3DMnWKIlveIer1I/H+Kv9Sf/CSCEj0Lkq/282T laVuUk8kmNYXrfngFNoi7QKga+1Ug7E4c7rx8G3QNIMCkEnodkcwbck0fMDxjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688232049; 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=IRRjMDlYChW/YW593gRE53QcXcZ9me/ZgPqd6Jh4cVk=; b=fsK7AdV/+FW026jR4C1GwojAskeRSU641xsIs0AzuTDXxwUWTB91TWM+qjDIjiaDE7PY0T i1/mOWAhYAHm6aJMigZjsHTC6TO2HKdMayqutlaTUhXOwdBoeHt4r6kW8H/dhgUGuh0m+l Uc1zkJzi/XwclYT8wi1dgKT+NzI/1LyO3TjTzKz0C/dEcl+VlGsX5jJb/9j5t37NaKkfjP N0gbKK0hdxUEYE1ZMAe94r9fxdvjtlHA6m1zJ/VicC/6VqDs6jd5Evy+t2buvqQwTmbmjN mxy+6do4NS1PV84ZuX2iVm87U8YSjk0ZyfWH3KcRJ418YwMGNqds4AmW+BjTNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688232049; a=rsa-sha256; cv=none; b=dyOCdIuJKayIlp25EZyFIcoufKz7E5IoVFixMF31E5hqLjAg1tVcUItaUDU8M3pgqvXOYU UC8a/+hJezAHOoKHiywhCQsz4B6ny6AFG/zkhwAaK+7B4fj8KAzXIrqTRGpQ/HC4bjh/kx IpyEa7NdiQ0tgxXb2VfGm3o7J/sNLDhuNGEFY8xRh+Pyzmy70RXsz0GvpecOGsIYmSpidm cGXDTfymFbq29h0OJQs9wzhzIznN0TLj1JX/SOMBYeTpeqEBXgCX6BTWYNR3bhYwW+qzws +Y430HRW+Iah5U80u+rpEuh1cWMIHoLYEqBKYZPgdRQO63OoYAkl+Ix8r9WWOA== 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 4Qtf8x5jDpzZJ3; Sat, 1 Jul 2023 17:20:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 361HKnx6066414; Sat, 1 Jul 2023 17:20:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 361HKn4o066413; Sat, 1 Jul 2023 17:20:49 GMT (envelope-from git) Date: Sat, 1 Jul 2023 17:20:49 GMT Message-Id: <202307011720.361HKn4o066413@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: f03a7e52769e - main - nctgpio: Populate the cache earlier 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f03a7e52769e7d5cf706021d4b21953e5bd945a4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f03a7e52769e7d5cf706021d4b21953e5bd945a4 commit f03a7e52769e7d5cf706021d4b21953e5bd945a4 Author: Stéphane Rochoy AuthorDate: 2023-07-01 17:19:44 +0000 Commit: Warner Losh CommitDate: 2023-07-01 17:19:54 +0000 nctgpio: Populate the cache earlier Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/719 --- sys/dev/nctgpio/nctgpio.c | 53 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/sys/dev/nctgpio/nctgpio.c b/sys/dev/nctgpio/nctgpio.c index fc3de033968f..07208e0fbd90 100644 --- a/sys/dev/nctgpio/nctgpio.c +++ b/sys/dev/nctgpio/nctgpio.c @@ -1200,6 +1200,32 @@ nct_attach(device_t dev) pin_num = 0; sc->npins = 0; for (g = 0, gp = sc->nctdevp->groups; g < sc->nctdevp->ngroups; g++, gp++) { + + sc->grpmap[gp->grpnum] = gp; + + /* + * Caching input values is meaningless as an input can be changed at any + * time by an external agent. But outputs are controlled by this + * driver, so it can cache their state. Also, the hardware remembers + * the output state of a pin when the pin is switched to input mode and + * then back to output mode. So, the cache stays valid. + * The only problem is with pins that are in input mode at the attach + * time. For them the output state is not known until it is set by the + * driver for the first time. + * 'out' and 'out_known' bits form a tri-state output cache: + * |-----+-----------+---------| + * | out | out_known | cache | + * |-----+-----------+---------| + * | X | 0 | invalid | + * | 0 | 1 | 0 | + * | 1 | 1 | 1 | + * |-----+-----------+---------| + */ + sc->cache.inv[gp->grpnum] = nct_read_reg(sc, REG_INV, gp->grpnum); + sc->cache.ior[gp->grpnum] = nct_read_reg(sc, REG_IOR, gp->grpnum); + sc->cache.out[gp->grpnum] = nct_read_reg(sc, REG_DAT, gp->grpnum); + sc->cache.out_known[gp->grpnum] = ~sc->cache.ior[gp->grpnum]; + sc->npins += gp->npins; for (i = 0; i < gp->npins; i++, pin_num++) { struct gpio_pin *pin; @@ -1208,8 +1234,6 @@ nct_attach(device_t dev) sc->pinmap[pin_num].grpnum = gp->grpnum; sc->pinmap[pin_num].bit = gp->pinbits[i]; - sc->grpmap[gp->grpnum] = gp; - pin = &sc->pins[pin_num]; pin->gp_pin = pin_num; pin->gp_caps = gp->caps; @@ -1234,31 +1258,6 @@ nct_attach(device_t dev) } NCT_VERBOSE_PRINTF(dev, "%d pins available\n", sc->npins); - /* - * Caching input values is meaningless as an input can be changed at any - * time by an external agent. But outputs are controlled by this - * driver, so it can cache their state. Also, the hardware remembers - * the output state of a pin when the pin is switched to input mode and - * then back to output mode. So, the cache stays valid. - * The only problem is with pins that are in input mode at the attach - * time. For them the output state is not known until it is set by the - * driver for the first time. - * 'out' and 'out_known' bits form a tri-state output cache: - * |-----+-----------+---------| - * | out | out_known | cache | - * |-----+-----------+---------| - * | X | 0 | invalid | - * | 0 | 1 | 0 | - * | 1 | 1 | 1 | - * |-----+-----------+---------| - */ - for (g = 0, gp = sc->nctdevp->groups; g < sc->nctdevp->ngroups; g++, gp++) { - sc->cache.inv[gp->grpnum] = nct_read_reg(sc, REG_INV, gp->grpnum); - sc->cache.ior[gp->grpnum] = nct_read_reg(sc, REG_IOR, gp->grpnum); - sc->cache.out[gp->grpnum] = nct_read_reg(sc, REG_DAT, gp->grpnum); - sc->cache.out_known[gp->grpnum] = ~sc->cache.ior[gp->grpnum]; - } - GPIO_UNLOCK(sc); sc->busdev = gpiobus_attach_bus(dev);