From nobody Wed Apr 1 22:18:43 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEE2840F8F8 for ; Wed, 1 Apr 2026 16:25:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775060736; cv=none; b=rF33w70nLvrwVqo0IR8IatT5wwwZNPuoIDiqwn10VgTfgQf3xC8e6uKJr0OYrpQ8KWuyoBf24yTABLCspLA2AUDLjnaxwmhkv175wpxy/nWQZvdnrZqd94S6knLAzIwyfrs5oRIa0d2UvHoNdLM1yH6eDbz5Y4jzHrmKJz13K2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775060736; c=relaxed/simple; bh=WvK6S3EH+UF3IaHlTEj/g84sdayFTuw0gIz6FR4c1Zw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NN1BklCGyqvL60z32BQI+oPKsaNOfqVDtZxa5yj2DOiBN0xwF144NdN7VgpDE1pdwJSQR7XnsckO9UDik7D4wZeAGpKEqcaBs8TBBRCyDFCCysWhuyxT89Xe52oRg2aQW7bIHiM17XZ6srXpUD/T4DH1Z+23RxMe8U9KgrWCeuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1w7yNV-00088i-RK; Wed, 01 Apr 2026 18:25:13 +0200 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac] helo=dude04) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w7yNV-003EjF-0p; Wed, 01 Apr 2026 18:25:13 +0200 Received: from ore by dude04 with local (Exim 4.98.2) (envelope-from ) id 1w7yNV-000000079r6-0jYi; Wed, 01 Apr 2026 18:25:13 +0200 From: Oleksij Rempel To: Guenter Roeck , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lee Jones , Peter Rosin , Linus Walleij Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-gpio@vger.kernel.org, David Jander Subject: [PATCH v10 3/6] pinctrl: core: Make pin group callbacks optional for pin-only drivers Date: Wed, 1 Apr 2026 18:25:07 +0200 Message-ID: <20260401162510.1706073-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260401162510.1706073-1-o.rempel@pengutronix.de> References: <20260401162510.1706073-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently, the pinctrl core strictly requires all drivers to implement .get_groups_count and .get_group_name callbacks in their pinctrl_ops. However, for simple pinctrl drivers that act purely as GPIO controllers and pin-specific configuration proxies, without any concept of muxing or pin groups, this strict requirement forces the implementation of dummy callbacks just to satisfy pinctrl_check_ops(). Relax this requirement for pin-only drivers by making the group callbacks optional when no muxing or group pin configuration support is provided. Update the core and debugfs helpers to check for the existence of these callbacks before invoking them. Drivers that provide muxing or group pin configuration operations still must implement group enumeration and naming callbacks, and are rejected at registration time if they do not. Suggested-by: Linus Walleij Signed-off-by: Oleksij Rempel Reviewed-by: Linus Walleij --- changes v10: - no changes changes v9: - no changes changes v8: - no changes changes v7: - no changes changes v6: - Reject drivers in pinctrl_check_ops() that use pmxops or group confops without providing group callbacks. - Add to core.c. - Revert the unnecessary NULL check in pinconf_show_setting(), since group settings are now strictly gated. - Keep debugfs group listings tolerant of drivers without group callbacks. changes v5: - no changes changes v4: - add Reviewed-by: Linus Walleij ... changes v3: - no changes --- drivers/pinctrl/core.c | 41 ++++++++++++++++++++++++++++++++++----- drivers/pinctrl/pinconf.c | 9 +++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index b5e97689589f..19a9a370d7b9 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -30,6 +30,7 @@ #include #include #include +#include #include =20 #include "core.h" @@ -621,8 +622,13 @@ static int pinctrl_generic_group_name_to_selector(stru= ct pinctrl_dev *pctldev, const char *function) { const struct pinctrl_ops *ops =3D pctldev->desc->pctlops; - int ngroups =3D ops->get_groups_count(pctldev); int selector =3D 0; + int ngroups; + + if (!ops->get_groups_count || !ops->get_group_name) + return -EINVAL; + + ngroups =3D ops->get_groups_count(pctldev); =20 /* See if this pctldev has this group */ while (selector < ngroups) { @@ -737,8 +743,15 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pct= ldev, const char *pin_group) { const struct pinctrl_ops *pctlops =3D pctldev->desc->pctlops; - unsigned int ngroups =3D pctlops->get_groups_count(pctldev); unsigned int group_selector =3D 0; + unsigned int ngroups; + + if (!pctlops->get_groups_count || !pctlops->get_group_name) { + dev_err(pctldev->dev, "does not support pin groups\n"); + return -EINVAL; + } + + ngroups =3D pctlops->get_groups_count(pctldev); =20 while (group_selector < ngroups) { const char *gname =3D pctlops->get_group_name(pctldev, @@ -1769,6 +1782,11 @@ static int pinctrl_groups_show(struct seq_file *s, v= oid *what) =20 mutex_lock(&pctldev->mutex); =20 + if (!ops->get_groups_count || !ops->get_group_name) { + mutex_unlock(&pctldev->mutex); + return 0; + } + ngroups =3D ops->get_groups_count(pctldev); =20 seq_puts(s, "registered pin groups:\n"); @@ -2049,12 +2067,25 @@ static void pinctrl_remove_device_debugfs(struct pi= nctrl_dev *pctldev) static int pinctrl_check_ops(struct pinctrl_dev *pctldev) { const struct pinctrl_ops *ops =3D pctldev->desc->pctlops; + const struct pinconf_ops *confops =3D pctldev->desc->confops; + bool needs_groups =3D false; =20 - if (!ops || - !ops->get_groups_count || - !ops->get_group_name) + if (!ops) return -EINVAL; =20 + if (pctldev->desc->pmxops) + needs_groups =3D true; + + if (confops && (confops->pin_config_group_get || + confops->pin_config_group_set)) + needs_groups =3D true; + + if (needs_groups && (!ops->get_groups_count || !ops->get_group_name)) { + dev_err(pctldev->dev, + "driver needs group callbacks for mux or group config\n"); + return -EINVAL; + } + return 0; } =20 diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index dca963633b5d..81686844dfa5 100644 --- a/drivers/pinctrl/pinconf.c +++ b/drivers/pinctrl/pinconf.c @@ -275,7 +275,7 @@ void pinconf_show_setting(struct seq_file *s, case PIN_MAP_TYPE_CONFIGS_GROUP: seq_printf(s, "group %s (%d)", pctlops->get_group_name(pctldev, - setting->data.configs.group_or_pin), + setting->data.configs.group_or_pin), setting->data.configs.group_or_pin); break; default: @@ -348,8 +348,13 @@ static int pinconf_groups_show(struct seq_file *s, voi= d *what) { struct pinctrl_dev *pctldev =3D s->private; const struct pinctrl_ops *pctlops =3D pctldev->desc->pctlops; - unsigned int ngroups =3D pctlops->get_groups_count(pctldev); unsigned int selector =3D 0; + unsigned int ngroups; + + if (!pctlops->get_groups_count || !pctlops->get_group_name) + return 0; + + ngroups =3D pctlops->get_groups_count(pctldev); =20 seq_puts(s, "Pin config settings per pin group\n"); seq_puts(s, "Format: group (name): configs\n"); --=20 2.47.3