Skip to contentSkip to conversation

gpiolib: Take MUX usage into account

PATCH Superseded Ramon Fried 3 participants 5 messages Aug 13, 2019 – Aug 14, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpiolib: Take MUX usage into account

From: Stefan Wahren <[email protected]>

The user space like gpioinfo only see the GPIO usage but not the MUX usage (e.g. I2C or SPI usage) of a pin. As a user we want to know which pin is free/safe to use. So take the MUX usage of strict pinmux controllers into account to get a more realistic view for ioctl GPIO_GET_LINEINFO_IOCTL.

---
v2: Address review from linus:
* ** Please notive logic was reversed **
* renamed pinctrl_gpio_is_in_use() to pinctrl_gpio_can_use_line()
* renamed pinmux_is_in_use() to pinmux_can_be_used_for_gpio()
* changed dev_err to dev_dbg (Linus suggested removing it altogether, I find it better to keep it for debug).

 drivers/gpio/gpiolib.c           |  3 ++-
 drivers/pinctrl/core.c           | 28 ++++++++++++++++++++++++++++
 drivers/pinctrl/pinmux.c         | 27 +++++++++++++++++++++++++++
 drivers/pinctrl/pinmux.h         |  8 ++++++++
 include/linux/pinctrl/consumer.h |  6 ++++++
 5 files changed, 71 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +2 -1
index f497003f119c..52937bf8e514 100644
@@ -1084,7 +1084,8 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		    test_bit(FLAG_IS_HOGGED, &desc->flags) ||
 		    test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
 		    test_bit(FLAG_EXPORT, &desc->flags) ||
-		    test_bit(FLAG_SYSFS, &desc->flags))
+		    test_bit(FLAG_SYSFS, &desc->flags) ||
+		    !pinctrl_gpio_can_use_line(chip->base + lineinfo.line_offset))
 			lineinfo.flags |= GPIOLINE_FLAG_KERNEL;
 		if (test_bit(FLAG_IS_OUT, &desc->flags))
 			lineinfo.flags |= GPIOLINE_FLAG_IS_OUT;
drivers/pinctrl/core.c +28 -0
index b70df27874d1..2bbd8ee93507 100644
@@ -736,6 +736,34 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
 	return -EINVAL;
 }
 
+bool pinctrl_gpio_can_use_line(unsigned gpio)
+{
+	struct pinctrl_dev *pctldev;
+	struct pinctrl_gpio_range *range;
+	bool result;
+	int pin;
+
+	/*
+	 * Try to obtain GPIO range, if it fails
+	 * we're probably dealing with GPIO driver
+	 * without a backing pin controller - bail out.
+	 */
+	if (pinctrl_get_device_gpio_range(gpio, &pctldev, &range))
+		return true;
+
+	mutex_lock(&pctldev->mutex);
+
+	/* Convert to the pin controllers number space */
+	pin = gpio_to_pin(range, gpio);
+
+	result = pinmux_can_be_used_for_gpio(pctldev, pin);
+
+	mutex_unlock(&pctldev->mutex);
+
+	return result;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line);
+
 /**
  * pinctrl_gpio_request() - request a single pin to be used as GPIO
  * @gpio: the GPIO pin number from the GPIO subsystem number space
drivers/pinctrl/pinmux.c +27 -0
index 020e54f843f9..7e42a5738d82 100644
@@ -70,6 +70,33 @@ int pinmux_validate_map(const struct pinctrl_map *map, int i)
 	return 0;
 }
 
+/**
+ * pinmux_can_be_used_for_gpio() - check if a specific pin
+ *	is either muxed to a different function or used as gpio.
+ *
+ * @pin: the pin number in the global pin space
+ *
+ * Controllers not defined as strict will always return true,
+ * menaning that the gpio can be used.
+ */
+bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin)
+{
+	struct pin_desc *desc = pin_desc_get(pctldev, pin);
+	const struct pinmux_ops *ops = pctldev->desc->pmxops;
+
+	if (!desc) {
+		dev_dbg(pctldev->dev,
+			"pin %u is not registered so it cannot be requested\n",
+			pin);
+		return true;
+	}
+
+	if (ops->strict && desc->mux_usecount)
+		return false;
+
+	return !(ops->strict && !!desc->gpio_owner);
+}
+
 /**
  * pin_request() - request a single pin to be muxed in, typically for GPIO
  * @pin: the pin number in the global pin space
drivers/pinctrl/pinmux.h +8 -0
index 794cb3a003ff..78c3a31be882 100644
@@ -15,6 +15,8 @@ int pinmux_check_ops(struct pinctrl_dev *pctldev);
 
 int pinmux_validate_map(const struct pinctrl_map *map, int i);
 
+bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin);
+
 int pinmux_request_gpio(struct pinctrl_dev *pctldev,
 			struct pinctrl_gpio_range *range,
 			unsigned pin, unsigned gpio);
@@ -42,6 +44,12 @@ static inline int pinmux_validate_map(const struct pinctrl_map *map, int i)
 	return 0;
 }
 
+static inline bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev,
+					       unsigned pin)
+{
+	return true;
+}
+
 static inline int pinmux_request_gpio(struct pinctrl_dev *pctldev,
 			struct pinctrl_gpio_range *range,
 			unsigned pin, unsigned gpio)
include/linux/pinctrl/consumer.h +6 -0
index 86720a5a384f..7f8c7d9583d3 100644
@@ -24,6 +24,7 @@ struct device;
 #ifdef CONFIG_PINCTRL
 
 /* External interface to pin control */
+extern bool pinctrl_gpio_can_use_line(unsigned gpio);
 extern int pinctrl_gpio_request(unsigned gpio);
 extern void pinctrl_gpio_free(unsigned gpio);
 extern int pinctrl_gpio_direction_input(unsigned gpio);
@@ -61,6 +62,11 @@ static inline int pinctrl_pm_select_idle_state(struct device *dev)
 
 #else /* !CONFIG_PINCTRL */
 
+static inline bool pinctrl_gpio_can_use_line(unsigned gpio)
+{
+	return true;
+}
+
 static inline int pinctrl_gpio_request(unsigned gpio)
 {
 	return 0;
Signature · 1 line
2.20.1
#1 lore raw

Hi Ramon,

Quoted 10 lines · Ramon Fried

From: Stefan Wahren <[email protected]>

The user space like gpioinfo only see the GPIO usage but not the MUX usage (e.g. I2C or SPI usage) of a pin. As a user we want to know which pin is free/safe to use. So take the MUX usage of strict pinmux controllers into account to get a more realistic view for ioctl GPIO_GET_LINEINFO_IOCTL.

Quoted 7 lines

---
v2: Address review from linus:
* ** Please notive logic was reversed **
* renamed pinctrl_gpio_is_in_use() to pinctrl_gpio_can_use_line()
* renamed pinmux_is_in_use() to pinmux_can_be_used_for_gpio()
* changed dev_err to dev_dbg (Linus suggested removing it altogether, I find it better to keep it for debug).

thanks for taking care of this.

Quoted 78 lines
 drivers/gpio/gpiolib.c           |  3 ++-
 drivers/pinctrl/core.c           | 28 ++++++++++++++++++++++++++++
 drivers/pinctrl/pinmux.c         | 27 +++++++++++++++++++++++++++
 drivers/pinctrl/pinmux.h         |  8 ++++++++
 include/linux/pinctrl/consumer.h |  6 ++++++
 5 files changed, 71 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +2 -1
index f497003f119c..52937bf8e514 100644
@@ -1084,7 +1084,8 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		    test_bit(FLAG_IS_HOGGED, &desc->flags) ||
 		    test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
 		    test_bit(FLAG_EXPORT, &desc->flags) ||
-		    test_bit(FLAG_SYSFS, &desc->flags))
+		    test_bit(FLAG_SYSFS, &desc->flags) ||
+		    !pinctrl_gpio_can_use_line(chip->base + lineinfo.line_offset))
 			lineinfo.flags |= GPIOLINE_FLAG_KERNEL;
 		if (test_bit(FLAG_IS_OUT, &desc->flags))
 			lineinfo.flags |= GPIOLINE_FLAG_IS_OUT;
drivers/pinctrl/core.c +28 -0
index b70df27874d1..2bbd8ee93507 100644
@@ -736,6 +736,34 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
 	return -EINVAL;
 }
 
+bool pinctrl_gpio_can_use_line(unsigned gpio)
+{
+	struct pinctrl_dev *pctldev;
+	struct pinctrl_gpio_range *range;
+	bool result;
+	int pin;
+
+	/*
+	 * Try to obtain GPIO range, if it fails
+	 * we're probably dealing with GPIO driver
+	 * without a backing pin controller - bail out.
+	 */
+	if (pinctrl_get_device_gpio_range(gpio, &pctldev, &range))
+		return true;
+
+	mutex_lock(&pctldev->mutex);
+
+	/* Convert to the pin controllers number space */
+	pin = gpio_to_pin(range, gpio);
+
+	result = pinmux_can_be_used_for_gpio(pctldev, pin);
+
+	mutex_unlock(&pctldev->mutex);
+
+	return result;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line);
+
 /**
  * pinctrl_gpio_request() - request a single pin to be used as GPIO
  * @gpio: the GPIO pin number from the GPIO subsystem number space
drivers/pinctrl/pinmux.c +9 -0
index 020e54f843f9..7e42a5738d82 100644
@@ -70,6 +70,33 @@ int pinmux_validate_map(const struct pinctrl_map *map, int i)
 	return 0;
 }
 
+/**
+ * pinmux_can_be_used_for_gpio() - check if a specific pin
+ *	is either muxed to a different function or used as gpio.
+ *
+ * @pin: the pin number in the global pin space
+ *
+ * Controllers not defined as strict will always return true,
+ * menaning that the gpio can be used.
+ */

drivers/pinctrl/pinmux.c int pinmux_validate_map(const struct pinctrl_map *map, int i) · line 91

Quoted 10 lines
drivers/pinctrl/pinmux.c +10 -0
+bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin)
+{
+	struct pin_desc *desc = pin_desc_get(pctldev, pin);
+	const struct pinmux_ops *ops = pctldev->desc->pmxops;
+
+	if (!desc) {
+		dev_dbg(pctldev->dev,
+			"pin %u is not registered so it cannot be requested\n",
+			pin);
+		return true;

This return value looks strange to me.

Stefan

#2 lore raw
Quoted 101 lines · Stefan Wahren

Hi Ramon,

Quoted 10 lines · Ramon Fried

From: Stefan Wahren <[email protected]>

The user space like gpioinfo only see the GPIO usage but not the MUX usage (e.g. I2C or SPI usage) of a pin. As a user we want to know which pin is free/safe to use. So take the MUX usage of strict pinmux controllers into account to get a more realistic view for ioctl GPIO_GET_LINEINFO_IOCTL.

Quoted 7 lines

---
v2: Address review from linus:
* ** Please notive logic was reversed **
* renamed pinctrl_gpio_is_in_use() to pinctrl_gpio_can_use_line()
* renamed pinmux_is_in_use() to pinmux_can_be_used_for_gpio()
* changed dev_err to dev_dbg (Linus suggested removing it altogether, I find it better to keep it for debug).

thanks for taking care of this.

Quoted 80 lines
  drivers/gpio/gpiolib.c           |  3 ++-
  drivers/pinctrl/core.c           | 28 ++++++++++++++++++++++++++++
  drivers/pinctrl/pinmux.c         | 27 +++++++++++++++++++++++++++
  drivers/pinctrl/pinmux.h         |  8 ++++++++
  include/linux/pinctrl/consumer.h |  6 ++++++
  5 files changed, 71 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +2 -1
index f497003f119c..52937bf8e514 100644
@@ -1084,7 +1084,8 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  		    test_bit(FLAG_IS_HOGGED, &desc->flags) ||
  		    test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
  		    test_bit(FLAG_EXPORT, &desc->flags) ||
-		    test_bit(FLAG_SYSFS, &desc->flags))
+		    test_bit(FLAG_SYSFS, &desc->flags) ||
+		    !pinctrl_gpio_can_use_line(chip->base + lineinfo.line_offset))
  			lineinfo.flags |= GPIOLINE_FLAG_KERNEL;
  		if (test_bit(FLAG_IS_OUT, &desc->flags))
  			lineinfo.flags |= GPIOLINE_FLAG_IS_OUT;
drivers/pinctrl/core.c +28 -0
index b70df27874d1..2bbd8ee93507 100644
@@ -736,6 +736,34 @@ int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
  	return -EINVAL;
  }
 
+bool pinctrl_gpio_can_use_line(unsigned gpio)
+{
+	struct pinctrl_dev *pctldev;
+	struct pinctrl_gpio_range *range;
+	bool result;
+	int pin;
+
+	/*
+	 * Try to obtain GPIO range, if it fails
+	 * we're probably dealing with GPIO driver
+	 * without a backing pin controller - bail out.
+	 */
+	if (pinctrl_get_device_gpio_range(gpio, &pctldev, &range))
+		return true;
+
+	mutex_lock(&pctldev->mutex);
+
+	/* Convert to the pin controllers number space */
+	pin = gpio_to_pin(range, gpio);
+
+	result = pinmux_can_be_used_for_gpio(pctldev, pin);
+
+	mutex_unlock(&pctldev->mutex);
+
+	return result;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line);
+
  /**
   * pinctrl_gpio_request() - request a single pin to be used as GPIO
   * @gpio: the GPIO pin number from the GPIO subsystem number space
drivers/pinctrl/pinmux.c +12 -0
index 020e54f843f9..7e42a5738d82 100644
@@ -70,6 +70,33 @@ int pinmux_validate_map(const struct pinctrl_map *map, int i)
  	return 0;
  }
 
+/**
+ * pinmux_can_be_used_for_gpio() - check if a specific pin
+ *	is either muxed to a different function or used as gpio.
+ *
+ * @pin: the pin number in the global pin space
+ *
+ * Controllers not defined as strict will always return true,
+ * menaning that the gpio can be used.
+ */
+bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin)
+{
+	struct pin_desc *desc = pin_desc_get(pctldev, pin);
Quoted 8 lines

drivers/pinctrl/pinmux.c int pinmux_validate_map(const struct pinctrl_map *map, int i) · line 91

Quoted 7 lines
drivers/pinctrl/pinmux.c +7 -0
+	const struct pinmux_ops *ops = pctldev->desc->pmxops;
+
+	if (!desc) {
+		dev_dbg(pctldev->dev,
+			"pin %u is not registered so it cannot be requested\n",
+			pin);
+		return true;

This return value looks strange to me.

Basically, it's just the reversed return value you returned in the original patch, It means in this context that if the pin is not owned by a pin-controller it can be used for GPIO.

Thanks,
Ramon.

Quoted 3 lines

Stefan

#3 lore raw

Am 13.08.19 um 08:10 schrieb Fried, Ramon:

Quoted 118 lines · Stefan Wahren
Quoted 107 lines

Hi Ramon,

Quoted 13 lines · Ramon Fried

From: Stefan Wahren <[email protected]>

The user space like gpioinfo only see the GPIO usage but not the MUX usage (e.g. I2C or SPI usage) of a pin. As a user we want to know which
pin is free/safe to use. So take the MUX usage of strict pinmux controllers
into account to get a more realistic view for ioctl GPIO_GET_LINEINFO_IOCTL.

Quoted 7 lines

---
v2: Address review from linus:
* ** Please notive logic was reversed **
* renamed pinctrl_gpio_is_in_use() to pinctrl_gpio_can_use_line()
* renamed pinmux_is_in_use() to pinmux_can_be_used_for_gpio()
* changed dev_err to dev_dbg (Linus suggested removing it altogether, I find it better to keep it for debug).

thanks for taking care of this.

Quoted 83 lines

  drivers/gpio/gpiolib.c           |  3 ++- drivers/pinctrl/core.c           | 28 ++++++++++++++++++++++++++++ drivers/pinctrl/pinmux.c         | 27 +++++++++++++++++++++++++++ drivers/pinctrl/pinmux.h         |  8 ++++++++ include/linux/pinctrl/consumer.h |  6 ++++++

  5 files changed, 71 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +0 -0
index f497003f119c..52937bf8e514 100644
@@ -1084,7 +1084,8 @@ static long gpio_ioctl(struct file *filp,
 unsigned int cmd, unsigned long arg)

              test_bit(FLAG_IS_HOGGED, &desc->flags) || test_bit(FLAG_USED_AS_IRQ, &desc->flags) || test_bit(FLAG_EXPORT, &desc->flags) || -            test_bit(FLAG_SYSFS, &desc->flags)) +            test_bit(FLAG_SYSFS, &desc->flags) || +            !pinctrl_gpio_can_use_line(chip->base + lineinfo.line_offset))
              lineinfo.flags |= GPIOLINE_FLAG_KERNEL; if (test_bit(FLAG_IS_OUT, &desc->flags)) lineinfo.flags |= GPIOLINE_FLAG_IS_OUT;

drivers/pinctrl/core.c +27 -0
index b70df27874d1..2bbd8ee93507 100644
@@ -736,6 +736,34 @@ int pinctrl_get_group_selector(struct
 pinctrl_dev *pctldev,
       return -EINVAL;
   }
   +bool pinctrl_gpio_can_use_line(unsigned gpio)
+{
+    struct pinctrl_dev *pctldev;
+    struct pinctrl_gpio_range *range;
+    bool result;
+    int pin;
+
+    /*
+     * Try to obtain GPIO range, if it fails
+     * we're probably dealing with GPIO driver
+     * without a backing pin controller - bail out.
+     */
+    if (pinctrl_get_device_gpio_range(gpio, &pctldev, &range))
+        return true;
+
+    mutex_lock(&pctldev->mutex);
+
+    /* Convert to the pin controllers number space */
+    pin = gpio_to_pin(range, gpio);
+
+    result = pinmux_can_be_used_for_gpio(pctldev, pin);
+
+    mutex_unlock(&pctldev->mutex);
+
+    return result;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line);
+
   /**
    * pinctrl_gpio_request() - request a single pin to be used as GPIO

   * @gpio: the GPIO pin number from the GPIO subsystem number space

drivers/pinctrl/pinmux.c +0 -0
index 020e54f843f9..7e42a5738d82 100644
@@ -70,6 +70,33 @@ int pinmux_validate_map(const struct pinctrl_map
 *map, int i)
       return 0;
   }

  +/**
+ * pinmux_can_be_used_for_gpio() - check if a specific pin
+ *    is either muxed to a different function or used as gpio.
+ *
+ * @pin: the pin number in the global pin space
+ *
+ * Controllers not defined as strict will always return true,
+ * menaning that the gpio can be used.
+ */
+bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin)
+{
+    struct pin_desc *desc = pin_desc_get(pctldev, pin);

Quoted 8 lines
Quoted 7 lines

+    const struct pinmux_ops *ops = pctldev->desc->pmxops; +
+    if (!desc) {
+        dev_dbg(pctldev->dev,
+            "pin %u is not registered so it cannot be requested\n", +            pin);
+        return true;

This return value looks strange to me.

Quoted 4 lines

Basically, it's just the reversed return value you returned in the original patch,
It means in this context that if the pin is not owned by a pin-controller it can be used for GPIO.

As long as the provided pin is valid. Btw shouldn't we change the logic in the debug message?

Quoted 7 lines

Thanks,
Ramon.

Quoted 3 lines

Stefan

#4 lore raw
Quoted 129 lines · Stefan Wahren

Am 13.08.19 um 08:10 schrieb Fried, Ramon:

Quoted 128 lines · Stefan Wahren
Quoted 126 lines

Hi Ramon,

Quoted 15 lines · Ramon Fried

From: Stefan Wahren <[email protected]>

The user space like gpioinfo only see the GPIO usage but not the
MUX usage (e.g. I2C or SPI usage) of a pin. As a user we want to
know which
pin is free/safe to use. So take the MUX usage of strict pinmux controllers
into account to get a more realistic view for ioctl GPIO_GET_LINEINFO_IOCTL.

Quoted 9 lines

---
v2: Address review from linus:
* ** Please notive logic was reversed **
* renamed pinctrl_gpio_is_in_use() to pinctrl_gpio_can_use_line()
* renamed pinmux_is_in_use() to pinmux_can_be_used_for_gpio()
* changed dev_err to dev_dbg (Linus suggested removing it altogether, I
find it better to keep it for debug).

thanks for taking care of this.

Quoted 95 lines
  drivers/gpio/gpiolib.c           |  3 ++-
  drivers/pinctrl/core.c           | 28
++++++++++++++++++++++++++++
  drivers/pinctrl/pinmux.c         | 27
+++++++++++++++++++++++++++
  drivers/pinctrl/pinmux.h         |  8 ++++++++
  include/linux/pinctrl/consumer.h |  6 ++++++
  5 files changed, 71 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +2 -1
index f497003f119c..52937bf8e514 100644
@@ -1084,7 +1084,8 @@ static long gpio_ioctl(struct file *filp,
 unsigned int cmd, unsigned long arg)
              test_bit(FLAG_IS_HOGGED, &desc->flags) ||
              test_bit(FLAG_USED_AS_IRQ, &desc->flags) ||
              test_bit(FLAG_EXPORT, &desc->flags) ||
-            test_bit(FLAG_SYSFS, &desc->flags))
+            test_bit(FLAG_SYSFS, &desc->flags) ||
+            !pinctrl_gpio_can_use_line(chip->base +
 lineinfo.line_offset))
              lineinfo.flags |= GPIOLINE_FLAG_KERNEL;
          if (test_bit(FLAG_IS_OUT, &desc->flags))
              lineinfo.flags |= GPIOLINE_FLAG_IS_OUT;
drivers/pinctrl/core.c +27 -0
index b70df27874d1..2bbd8ee93507 100644
@@ -736,6 +736,34 @@ int pinctrl_get_group_selector(struct
 pinctrl_dev *pctldev,
      return -EINVAL;
  }
  +bool pinctrl_gpio_can_use_line(unsigned gpio)
+{
+    struct pinctrl_dev *pctldev;
+    struct pinctrl_gpio_range *range;
+    bool result;
+    int pin;
+
+    /*
+     * Try to obtain GPIO range, if it fails
+     * we're probably dealing with GPIO driver
+     * without a backing pin controller - bail out.
+     */
+    if (pinctrl_get_device_gpio_range(gpio, &pctldev, &range))
+        return true;
+
+    mutex_lock(&pctldev->mutex);
+
+    /* Convert to the pin controllers number space */
+    pin = gpio_to_pin(range, gpio);
+
+    result = pinmux_can_be_used_for_gpio(pctldev, pin);
+
+    mutex_unlock(&pctldev->mutex);
+
+    return result;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_can_use_line);
+
  /**
   * pinctrl_gpio_request() - request a single pin to be used

as GPIO
* @gpio: the GPIO pin number from the GPIO subsystem number
space

drivers/pinctrl/pinmux.c +0 -0
index 020e54f843f9..7e42a5738d82 100644
@@ -70,6 +70,33 @@ int pinmux_validate_map(const struct

pinctrl_map
*map, int i)

      return 0;

}
+/**
+ * pinmux_can_be_used_for_gpio() - check if a specific pin
+ * is either muxed to a different function or used as gpio.
+ *
+ * @pin: the pin number in the global pin space
+ *
+ * Controllers not defined as strict will always return true,
+ * menaning that the gpio can be used.
+ */
+bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned pin)

drivers/pinctrl/pinmux.c +7 -0
+{
+    struct pin_desc *desc = pin_desc_get(pctldev, pin);
+    const struct pinmux_ops *ops = pctldev->desc->pmxops;
+
+    if (!desc) {
+        dev_dbg(pctldev->dev,
+            "pin %u is not registered so it cannot be

requested\n",

drivers/pinctrl/pinmux.c int pinmux_validate_map(const struct pinctrl_map *map, int i) · line 91

Quoted 2 lines
drivers/pinctrl/pinmux.c +2 -0
+            pin);
+        return true;

This return value looks strange to me.

Quoted 7 lines
Quoted 4 lines

Basically, it's just the reversed return value you returned in the original patch,
It means in this context that if the pin is not owned by a pin-controller it can be used for GPIO.

As long as the provided pin is valid. Btw shouldn't we change the logic
in the debug message?

Good catch. yes we should.
I'll send V3 shortly.
Thanks,
Ramon.

Quoted 5 lines
Quoted 5 lines

Thanks,
Ramon.

Quoted 2 lines

Stefan