[PATCH v5 1/7] pinctrl: introduce pinctrl_gpio_get_config()

Dan Carpenter posted 7 patches 1 week, 6 days ago
[PATCH v5 1/7] pinctrl: introduce pinctrl_gpio_get_config()
Posted by Dan Carpenter 1 week, 6 days ago
From: AKASHI Takahiro <takahiro.akashi@linaro.org>

This is a counterpart of pinctrl_gpio_set_config(), which will be used
to implement the ->get() interface in a GPIO driver for SCMI.

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>
---
v5: No change
v4: Fix kernel-doc (Andy).  Add r-b tags
v3: Forward port

 drivers/pinctrl/core.c           | 31 +++++++++++++++++++++++++++++++
 include/linux/pinctrl/consumer.h |  9 +++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 2edc9bdad183..c471f3fbd035 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -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)
 {
diff --git a/include/linux/pinctrl/consumer.h b/include/linux/pinctrl/consumer.h
index 63ce16191eb9..11b8f0b8da0c 100644
--- a/include/linux/pinctrl/consumer.h
+++ b/include/linux/pinctrl/consumer.h
@@ -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)
-- 
2.51.0
Re: [PATCH v5 1/7] pinctrl: introduce pinctrl_gpio_get_config()
Posted by Andy Shevchenko 1 week, 4 days ago
On Sat, Mar 21, 2026 at 01:13:22PM +0300, Dan Carpenter wrote:

> This is a counterpart of pinctrl_gpio_set_config(), which will be used
> to implement the ->get() interface in a GPIO driver for SCMI.

...

> +	ret = pin_config_get_for_pin(pctldev, pin, config);

Seems you need also add a stub for this for !CONFIG_GENERIC_PINCONF.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v5 1/7] pinctrl: introduce pinctrl_gpio_get_config()
Posted by kernel test robot 1 week, 5 days ago
Hi Dan,

kernel test robot noticed the following build errors:

[auto build test ERROR on linusw-pinctrl/devel]
[also build test ERROR on linusw-pinctrl/for-next brgl/gpio/for-next linus/master v7.0-rc4 next-20260320]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dan-Carpenter/pinctrl-introduce-pinctrl_gpio_get_config/20260321-225727
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel
patch link:    https://lore.kernel.org/r/f7a41ed017fba4a0986ffe72e06933cc1bba2406.1774087290.git.dan.carpenter%40linaro.org
patch subject: [PATCH v5 1/7] pinctrl: introduce pinctrl_gpio_get_config()
config: loongarch-loongson32_defconfig (https://download.01.org/0day-ci/archive/20260322/202603221553.6g9sSgFm-lkp@intel.com/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 4abb927bacf37f18f6359a41639a6d1b3bffffb5)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/202603221553.6g9sSgFm-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603221553.6g9sSgFm-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/pinctrl/core.c:961:8: error: call to undeclared function 'pin_config_get_for_pin'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     961 |         ret = pin_config_get_for_pin(pctldev, pin, config);
         |               ^
   1 error generated.


vim +/pin_config_get_for_pin +961 drivers/pinctrl/core.c

   941	
   942	/**
   943	 * pinctrl_gpio_get_config() - Get the config for a given GPIO pin
   944	 * @gc: GPIO chip structure from the GPIO subsystem
   945	 * @offset: hardware offset of the GPIO relative to the controller
   946	 * @config: the configuration to query.  On success it holds the result
   947	 * Return: 0 on success, negative errno otherwise
   948	 */
   949	int pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset, unsigned long *config)
   950	{
   951		struct pinctrl_gpio_range *range;
   952		struct pinctrl_dev *pctldev;
   953		int ret, pin;
   954	
   955		ret = pinctrl_get_device_gpio_range(gc, offset, &pctldev, &range);
   956		if (ret)
   957			return ret;
   958	
   959		mutex_lock(&pctldev->mutex);
   960		pin = gpio_to_pin(range, gc, offset);
 > 961		ret = pin_config_get_for_pin(pctldev, pin, config);
   962		mutex_unlock(&pctldev->mutex);
   963	
   964		if (ret)
   965			return ret;
   966	
   967		*config = pinconf_to_config_argument(*config);
   968		return 0;
   969	}
   970	EXPORT_SYMBOL_GPL(pinctrl_gpio_get_config);
   971	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki