From patchwork Mon Oct 26 16:57:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Siyuan X-Patchwork-Id: 3761 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 9B3321C1F8E for ; Mon, 26 Oct 2026 18:03:57 +0100 (CET) Authentication-Results: mxe881; dkim=pass header.d=163.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-26907-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-26907-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 3DAD4202B0 for ; Mon, 26 Oct 2026 16:58:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1793033906; b=cL97/+mN/Dzh7+2gUF1fuHhrb99l7AUXckcQJAg7X9l1z0FOGyAgTuE1gMebsOx/tf7r /o322dz4EUXwltwwQhmaApfoRyioZm8V1uDmU74ZRSM0gzwwieaz2TOu/6HdNSTs/4jj3 GBq5pzk4vtZIT6gddQ91AY014M2gRynJDMOj5S0snXZfpQSbwftT+Ya4ZN+ahsL+kmuIp utD6cUix3s5xKApUrxb3n+7veN2gL70OnJtH+C39Rgl7zQszJ+A8p9pdThM/lqw/UWN4Z 17sfxa5xkOBNUZTInRbx7KjrbAls8JRcjddknMdGiO+B/4dLNklJ43dKLePT7eWAIkw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793033906; h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:From:To: Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=yxHn6IyMEc/gFXG0FL2K57vaxjrPtjjGVPSWUg++9V4=; b=Hq7VIYAj3Z2Rr8aqnFQO9i66wnGa9YG5mn0KxmpfoodXgdMvPzeNdQD4pIwbXypC0Gyc fP5pANLtpFFh+IhSyvox6EJjjOTSCQHYEEJ8j/6hRplV+zA04gmxHWzgibepNO+lhnTyq FdRheNpk1XL655Sp7LvcBgAaYn8MYRE255zEjqyDgrxmEGiR4KLZlV/PgItNmsVV8djUL 2JAgLMiIm3F29EAzUPgWBC4I/PKFNWm8W7lQBdgE8quJlPcBWOLaooU7Ter7Dqs1Qwydm 1C4nnNkoHr34cH62xxI7VSC/Yqrlfc8mYJciQWIjX+kQea1MbUtGfxeAynYdakoynUQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=AllCAX8h; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; arc=fail smtp.remote-ip=127.0.0.1 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74A89606A31D; Mon, 26 Oct 2026 16:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=AllCAX8h X-Original-To: linux-sunxi@lists.linux.dev Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.31.2 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793033906; b=j/uAao0kj5P+f3bF/fwuOmApvGvBdO/CDJtXxF7+5v5gMGjhNrml2hgg/p7koV4YRnhW AamymBPinAV+5nNYzt7sg8seJMsyTgdbqlpoKfMeMW6PMJ9UWBkgJ4SGS/mjt9Kg1C7GI mBaz1QAWC2EFQGgHIjqm5a+d9EKD6QdDHNbC0MuPcjhD4tWYe2i1IYS/ZILAhgns8bSbm wL8XmPq6X59JE5k2BE3//HgB8aiCVDj2YpkfF0AobhqgHY3jJa4nzCaSTchNjnwG+uTjC c48zhPl38+V5RIM4W8irJMMinJrOEkISkZ/x4hcw9BFcRFyJPptasN9l/qVhyckGxsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793033906; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-Originating-IP:X-CM-SenderInfo; bh=yxHn6IyMEc/gFXG0FL2K57vaxjrPtjjGVPSWUg++9V4=; b=uFp6iqXa9yw0MVgzCw2/n+B9nCFZCuHx9yKHQTwBOCZ2zhE3ezrhOKzheENI1Mp9I6ct tCS/T++GAdWPadLTluMrAV7Jmg9yRDOxIpEzKDTNkfffqoYG7Pj+biH9aHmV0K53Eer5n ZnjFM2jSwpVJsaLhN5983WOnZUVyvBuI50qDRZGMZBuxNY4HedA6/c8Tps1aV9FZXqdyT 0GpbFGHKVm5d4PcEffCTiq5wDJqTxDv+zYTOKf44rOpBHnVHBPouMFkeygJ94PyhMc8DF tKALP5trkFxxMzstAxc9rGr6jjk+ccx2dPzBfE/xqkFrWdz6EQ1orV8gSH96qQiV+SA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=AllCAX8h; arc=none smtp.remote-ip=220.197.31.2 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFA0D606A31A for ; Mon, 26 Oct 2026 16:58:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DFA0D606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=yx Hn6IyMEc/gFXG0FL2K57vaxjrPtjjGVPSWUg++9V4=; b=AllCAX8heHI5B0M6rm uaSDf4/DxlryL9aKMWSKG8xrdThIwsF0UzOUPYKhIEu1YCaVCbfQUg/R7Fx4GiZi zJfs2C8k0BgUyq8xI3c2XrEIOZHOHSy/8afrTgu1XvFxofxm+RE5zXWdOcCVKh6H Zb93DHSNEyOlUZ1u3TouaW65g= Received: from SYPC (unknown []) by gzsmtp4 (Coremail) with SMTP id PygvCgBXWG+fht9qNCbrCA--.16615S2; Tue, 27 Oct 2026 00:58:08 +0800 (CST) From: Yang Siyuan To: Linus Walleij Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v3] pinctrl: sunxi: request the per-bank supply optionally Date: Tue, 27 Oct 2026 00:57:42 +0800 Message-ID: <20261026165742.1478383-1-hsyysy@163.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261026152027.1417178-1-hsyysy@163.com> References: <20261026152027.1417178-1-hsyysy@163.com> X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-CM-TRANSID: PygvCgBXWG+fht9qNCbrCA--.16615S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxCFW7AF4rCr1UtrW5trW7CFg_yoWrtF1xpr 4fXryayr4rJFyxJw4xAw12yryS9a1xJa43CFykK345AFn8GFy3Jw1jkF4YkFs8Cr4kJr4Y vFyDZ34xGFn8X3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07ULo7_UUUUU= X-CM-SenderInfo: 5kv152r16rljoofrz/xtbC7QBckGrfhqBnzgAA3b X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [0.31 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; ARC_REJECT(1.00)[cv is fail on i=2]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; MAILLIST(-0.18)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; TAGGED_RCPT(0.00)[]; FROM_HAS_DN(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[100.77.114.92:received,220.197.31.2:received]; FREEMAIL_CC(0.00)[kernel.org,gmail.com,sholland.org,vger.kernel.org,lists.infradead.org,lists.linux.dev]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:helo,sea.lore.kernel.org:rdns]; FORGED_SENDER_MAILLIST(0.00)[]; R_DKIM_ALLOW(0.00)[163.com:s=s110527]; FROM_NEQ_ENVFROM(0.00)[hsyysy@163.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-26907-noreply=patchwork.local]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; DKIM_TRACE(0.00)[163.com:+]; FREEMAIL_FROM(0.00)[163.com]; TO_DN_SOME(0.00)[]; RCVD_COUNT_FIVE(0.00)[5]; DMARC_POLICY_ALLOW(0.00)[163.com,none]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[172.234.253.10:from] X-Rspamd-Queue-Id: 9B3321C1F8E X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= The per-bank "vcc-pX" supplies are optional in the device tree: the binding documents them, but notes that many boards do not describe them. sunxi_pmx_request() uses regulator_get() anyway, so the regulator core falls back to a dummy regulator and warns for every bank that has no supply: sun50i-h616-r-pinctrl 7022000.pinctrl: supply vcc-pl not found, using dummy regulator The H616 R_PIO is such a controller, and its PL0/PL1 pins drive the R_I2C bus, so every H616 board hits the warning during boot. Use of_regulator_get_optional() instead. A bank supply that is described in the device tree is still acquired and enabled, as it powers the physical VCC-Px rail, but one that is absent is skipped without a warning. The OF-only lookup matters here: regulator_get_optional() also falls back to a global regulator-name lookup. If a regulator with the same name as an absent bank supply is registered later, a subsequent pin request in that bank could acquire it and start the per-bank refcount at one, after earlier pins in the bank had already been requested without a regulator. Freeing any of those pins would then disable the supply while other pins in the bank are still active. Restricting the lookup to the pinctrl node makes an absent supply permanent; record that state so later pin requests do not retry the lookup. The refcount therefore stays balanced. Signed-off-by: Yang Siyuan --- Changes in v3: - Use of_regulator_get_optional() instead of regulator_get_optional(). The latter still performs a global regulator-name lookup, which can bind an unrelated regulator that appears after some pins were already requested and unbalance the per-bank refcount. - Remember that a bank has no supply so later pin requests skip the lookup, and keep the existing no-regulator check in sunxi_pmx_free(). - Link to v2: https://lore.kernel.org/linux-gpio/20261026152027.1417178-1-hsyysy@163.com/ - Link to v1: https://lore.kernel.org/linux-gpio/20261026144751.1392715-1-hsyysy@163.com/ --- --- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 29 +++++++++++++++++++++++++-- drivers/pinctrl/sunxi/pinctrl-sunxi.h | 1 + 2 files changed, 28 insertions(+), 2 deletions(-) base-commit: 091b06388b117fefdcb63336ac09956a4914b961 diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c index 70099052d..d2345a85a 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -913,23 +913,44 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset) PINS_PER_BANK; struct sunxi_pinctrl_regulator *s_reg = &pctl->regulators[bank_offset]; struct regulator *reg = s_reg->regulator; + struct device_node *np = dev_of_node(pctl->dev); char supply[16]; int ret; if (WARN_ON_ONCE(bank_offset >= ARRAY_SIZE(pctl->regulators))) return -EINVAL; + if (s_reg->supply_absent) + return 0; + if (reg) { refcount_inc(&s_reg->refcount); return 0; } + if (!np) { + s_reg->supply_absent = true; + return 0; + } + snprintf(supply, sizeof(supply), "vcc-p%c", 'a' + bank); - reg = regulator_get(pctl->dev, supply); - if (IS_ERR(reg)) + /* + * Use the OF-only lookup: regulator_get_optional() would also match + * a same-named regulator from another device. Such a regulator can + * appear after some pins in this bank have already been requested, + * which would unbalance the per-bank refcount. + */ + reg = of_regulator_get_optional(pctl->dev, np, supply); + if (IS_ERR(reg)) { + if (PTR_ERR(reg) == -ENODEV) { + s_reg->supply_absent = true; + return 0; + } + return dev_err_probe(pctl->dev, PTR_ERR(reg), "Couldn't get bank P%c regulator\n", 'A' + bank); + } ret = regulator_enable(reg); if (ret) { @@ -959,6 +980,10 @@ static int sunxi_pmx_free(struct pinctrl_dev *pctldev, unsigned offset) PINS_PER_BANK; struct sunxi_pinctrl_regulator *s_reg = &pctl->regulators[bank_offset]; + /* The per-bank supply is optional, so this bank may not have one. */ + if (!s_reg->regulator) + return 0; + if (!refcount_dec_and_test(&s_reg->refcount)) return 0; diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.h b/drivers/pinctrl/sunxi/pinctrl-sunxi.h index 8bd00c6ff..651249b23 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.h +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.h @@ -162,6 +162,7 @@ struct sunxi_pinctrl_group { struct sunxi_pinctrl_regulator { struct regulator *regulator; refcount_t refcount; + bool supply_absent; }; struct sunxi_pinctrl {