]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pinctrl: core: Make pin group callbacks optional for pin-only drivers
authorOleksij Rempel <o.rempel@pengutronix.de>
Fri, 15 May 2026 16:05:31 +0000 (18:05 +0200)
committerLinus Walleij <linusw@kernel.org>
Mon, 25 May 2026 07:51:22 +0000 (09:51 +0200)
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 <linusw@kernel.org>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Signed-off-by: Linus Walleij <linusw@kernel.org>
drivers/pinctrl/core.c
drivers/pinctrl/pinconf.c

index 6cbcaa6709da176bd8010547bb1f6c5994bda938..3fcb7e584a9373d2cde6f14bb5c59cc6c6efc3ca 100644 (file)
@@ -622,8 +622,13 @@ static int pinctrl_generic_group_name_to_selector(struct pinctrl_dev *pctldev,
                                                  const char *function)
 {
        const struct pinctrl_ops *ops = pctldev->desc->pctlops;
-       int ngroups = ops->get_groups_count(pctldev);
        int selector = 0;
+       int ngroups;
+
+       if (!ops->get_groups_count || !ops->get_group_name)
+               return -EINVAL;
+
+       ngroups = ops->get_groups_count(pctldev);
 
        /* See if this pctldev has this group */
        while (selector < ngroups) {
@@ -738,8 +743,15 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
                               const char *pin_group)
 {
        const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
-       unsigned int ngroups = pctlops->get_groups_count(pctldev);
        unsigned int group_selector = 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 = pctlops->get_groups_count(pctldev);
 
        while (group_selector < ngroups) {
                const char *gname = pctlops->get_group_name(pctldev,
@@ -1801,6 +1813,11 @@ static int pinctrl_groups_show(struct seq_file *s, void *what)
 
        mutex_lock(&pctldev->mutex);
 
+       if (!ops->get_groups_count || !ops->get_group_name) {
+               mutex_unlock(&pctldev->mutex);
+               return 0;
+       }
+
        ngroups = ops->get_groups_count(pctldev);
 
        seq_puts(s, "registered pin groups:\n");
@@ -2081,12 +2098,25 @@ static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
 static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
 {
        const struct pinctrl_ops *ops = pctldev->desc->pctlops;
+       const struct pinconf_ops *confops = pctldev->desc->confops;
+       bool needs_groups = false;
 
-       if (!ops ||
-           !ops->get_groups_count ||
-           !ops->get_group_name)
+       if (!ops)
                return -EINVAL;
 
+       if (pctldev->desc->pmxops)
+               needs_groups = true;
+
+       if (confops && (confops->pin_config_group_get ||
+                       confops->pin_config_group_set))
+               needs_groups = 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;
 }
 
index dca963633b5d136b9459d8389a509c8874f518b5..81686844dfa5f103c8f4e02820d8d2d9462c26b2 100644 (file)
@@ -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, void *what)
 {
        struct pinctrl_dev *pctldev = s->private;
        const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
-       unsigned int ngroups = pctlops->get_groups_count(pctldev);
        unsigned int selector = 0;
+       unsigned int ngroups;
+
+       if (!pctlops->get_groups_count || !pctlops->get_group_name)
+               return 0;
+
+       ngroups = pctlops->get_groups_count(pctldev);
 
        seq_puts(s, "Pin config settings per pin group\n");
        seq_puts(s, "Format: group (name): configs\n");