]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pinctrl: introduce pinctrl_gpio_get_config()
authorAKASHI Takahiro <takahiro.akashi@linaro.org>
Mon, 23 Mar 2026 19:01:10 +0000 (22:01 +0300)
committerLinus Walleij <linusw@kernel.org>
Tue, 24 Mar 2026 12:50:30 +0000 (13:50 +0100)
This is a counterpart of pinctrl_gpio_set_config(), which will be used
to implement the ->get() interface in a GPIO driver for SCMI.

This also requires that we create a stub so pin_config_get_for_pin()
can build when CONFIG_PINCONF is disabled.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Linus Walleij <linusw@kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Linus Walleij <linusw@kernel.org>
drivers/pinctrl/core.c
drivers/pinctrl/pinconf.h
include/linux/pinctrl/consumer.h

index b5e97689589fbf1b6750620fc193bc820012be2b..da0a0774246068bf80b72c370781d31d9c294753 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/pinctrl/consumer.h>
 #include <linux/pinctrl/devinfo.h>
 #include <linux/pinctrl/machine.h>
+#include <linux/pinctrl/pinconf.h>
 #include <linux/pinctrl/pinctrl.h>
 
 #include "core.h"
@@ -938,6 +939,36 @@ int pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
 }
 EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config);
 
+/**
+ * pinctrl_gpio_get_config() - Get the config for a given GPIO pin
+ * @gc: GPIO chip structure from the GPIO subsystem
+ * @offset: hardware offset of the GPIO relative to the controller
+ * @config: the configuration to query.  On success it holds the result
+ * Return: 0 on success, negative errno otherwise
+ */
+int pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset, unsigned long *config)
+{
+       struct pinctrl_gpio_range *range;
+       struct pinctrl_dev *pctldev;
+       int ret, pin;
+
+       ret = pinctrl_get_device_gpio_range(gc, offset, &pctldev, &range);
+       if (ret)
+               return ret;
+
+       mutex_lock(&pctldev->mutex);
+       pin = gpio_to_pin(range, gc, offset);
+       ret = pin_config_get_for_pin(pctldev, pin, config);
+       mutex_unlock(&pctldev->mutex);
+
+       if (ret)
+               return ret;
+
+       *config = pinconf_to_config_argument(*config);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_get_config);
+
 static struct pinctrl_state *find_state(struct pinctrl *p,
                                        const char *name)
 {
index 2880adef476e68950ffdd540ea42cdee6a16ec27..659a781e20911db4b27c7c3663c31fbbbf57c521 100644 (file)
@@ -74,6 +74,12 @@ static inline int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned int p
        return -ENOTSUPP;
 }
 
+static inline int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned int pin,
+                          unsigned long *config)
+{
+       return -ENOTSUPP;
+}
+
 #endif
 
 #if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS)
index 63ce16191eb94728828803048fcf8d2db5ba8398..11b8f0b8da0c4948c19fe533b39861d558cc76a5 100644 (file)
@@ -35,6 +35,8 @@ int pinctrl_gpio_direction_output(struct gpio_chip *gc,
                                  unsigned int offset);
 int pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
                                unsigned long config);
+int pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset,
+                           unsigned long *config);
 
 struct pinctrl * __must_check pinctrl_get(struct device *dev);
 void pinctrl_put(struct pinctrl *p);
@@ -101,6 +103,13 @@ pinctrl_gpio_direction_output(struct gpio_chip *gc, unsigned int offset)
        return 0;
 }
 
+static inline int
+pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset,
+                       unsigned long *config)
+{
+       return 0;
+}
+
 static inline int
 pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
                            unsigned long config)