Skip to contentSkip to conversation

gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found

PATCH In review Mika Westerberg 5 participants 5 messages Jun 10, 2015 – Jun 11, 2015 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio / ACPI: Return -EPROBE_DEFER if the gpiochip was not found

If a driver requests a GPIO described in its _CRS but the GPIO host controller (gpiochip) driver providing the GPIO has not been loaded yet acpi_get_gpiod() returns -ENODEV which causes the calling driver to fail.

If the gpiochip driver is loaded afterwards the driver requesting the GPIO will not notice this.

Better approach is to return -EPROBE_DEFER in such case. Then when the gpiochip driver appears the driver requesting the GPIO will be probed again. This also aligns ACPI GPIO lookup code closer to DT as it does pretty much the same when no gpiochip driver was found.

---
 drivers/gpio/gpiolib-acpi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib-acpi.c +5 -4
index 19b99d0c2bf0..b49006c81a7f 100644
@@ -114,10 +114,11 @@ static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip,
  * @path:	ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
  * @pin:	ACPI GPIO pin number (0-based, controller-relative)
  *
- * Returns GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
- * error value
+ * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
+ * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO
+ * controller does not have gpiochip registered at the moment. This is to
+ * support probe deferral.
  */
-
 static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 {
 	struct gpio_chip *chip;
@@ -131,7 +132,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 
 	chip = gpiochip_find(handle, acpi_gpiochip_find);
 	if (!chip)
-		return ERR_PTR(-ENODEV);
+		return ERR_PTR(-EPROBE_DEFER);
 
 	offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
 	if (offset < 0)
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Mika Westerberg

If a driver requests a GPIO described in its _CRS but the GPIO host controller (gpiochip) driver providing the GPIO has not been loaded yet acpi_get_gpiod() returns -ENODEV which causes the calling driver to fail.

If the gpiochip driver is loaded afterwards the driver requesting the GPIO will not notice this.

Quoted 7 lines

Better approach is to return -EPROBE_DEFER in such case. Then when the gpiochip driver appears the driver requesting the GPIO will be probed again. This also aligns ACPI GPIO lookup code closer to DT as it does pretty much the same when no gpiochip driver was found.

Makes sense to me.

Quoted 33 lines
---
 drivers/gpio/gpiolib-acpi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib-acpi.c +5 -4
index 19b99d0c2bf0..b49006c81a7f 100644
@@ -114,10 +114,11 @@ static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip,
  * @path:	ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")
  * @pin:	ACPI GPIO pin number (0-based, controller-relative)
  *
- * Returns GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
- * error value
+ * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
+ * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO
+ * controller does not have gpiochip registered at the moment. This is to
+ * support probe deferral.
  */
-
 static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 {
 	struct gpio_chip *chip;
@@ -131,7 +132,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 
 	chip = gpiochip_find(handle, acpi_gpiochip_find);
 	if (!chip)
-		return ERR_PTR(-ENODEV);
+		return ERR_PTR(-EPROBE_DEFER);
 
 	offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
 	if (offset < 0)
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#2 lore raw
Quoted 13 lines · Rafael J. Wysocki
Quoted 12 lines · Mika Westerberg

If a driver requests a GPIO described in its _CRS but the GPIO host controller (gpiochip) driver providing the GPIO has not been loaded yet acpi_get_gpiod() returns -ENODEV which causes the calling driver to fail.

If the gpiochip driver is loaded afterwards the driver requesting the GPIO will not notice this.

Better approach is to return -EPROBE_DEFER in such case. Then when the gpiochip driver appears the driver requesting the GPIO will be probed again. This also aligns ACPI GPIO lookup code closer to DT as it does pretty much the same when no gpiochip driver was found.

Quoted 6 lines
Quoted 2 lines

Makes sense to me.

Signature · 1 line
Tobias						PGP: http://8ef7ddba.uguu.de
Reviewed-by on v1 1/1
#3 lore raw
In reply to Mika Westerberg
Quoted 24 lines · Mika Westerberg

If a driver requests a GPIO described in its _CRS but the GPIO host controller (gpiochip) driver providing the GPIO has not been loaded yet acpi_get_gpiod() returns -ENODEV which causes the calling driver to fail.

If the gpiochip driver is loaded afterwards the driver requesting the GPIO will not notice this.

Better approach is to return -EPROBE_DEFER in such case. Then when the gpiochip driver appears the driver requesting the GPIO will be probed again. This also aligns ACPI GPIO lookup code closer to DT as it does pretty much the same when no gpiochip driver was found.

---
 drivers/gpio/gpiolib-acpi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib-acpi.c +0 -0
index 19b99d0c2bf0..b49006c81a7f 100644
@@ -114,10 +114,11 @@ static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip,
  * @path:      ACPI GPIO controller full path name, (e.g. "\\_SB.GPO1")

drivers/gpio/gpiolib-acpi.c static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, · line 120

Quoted 10 lines
drivers/gpio/gpiolib-acpi.c +4 -3
  * @pin:       ACPI GPIO pin number (0-based, controller-relative)
  *
- * Returns GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
- * error value
+ * Return: GPIO descriptor to use with Linux generic GPIO API, or ERR_PTR
+ * error value. Specifically returns %-EPROBE_DEFER if the referenced GPIO
+ * controller does not have gpiochip registered at the moment. This is to
+ * support probe deferral.
  */
-

api_get_gpiod() is called in preprobe stage, we still have chance to probe the device.

Quoted 20 lines
drivers/gpio/gpiolib-acpi.c +1 -2
 static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 {
        struct gpio_chip *chip;
@@ -131,7 +132,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
 
        chip = gpiochip_find(handle, acpi_gpiochip_find);
        if (!chip)
-               return ERR_PTR(-ENODEV);
+               return ERR_PTR(-EPROBE_DEFER);
 
        offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin);
        if (offset < 0)
--

2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
In reply to Mika Westerberg
Quoted 7 lines · Mika Westerberg

If a driver requests a GPIO described in its _CRS but the GPIO host controller (gpiochip) driver providing the GPIO has not been loaded yet acpi_get_gpiod() returns -ENODEV which causes the calling driver to fail.

If the gpiochip driver is loaded afterwards the driver requesting the GPIO will not notice this.

Quoted 7 lines

Better approach is to return -EPROBE_DEFER in such case. Then when the gpiochip driver appears the driver requesting the GPIO will be probed again. This also aligns ACPI GPIO lookup code closer to DT as it does pretty much the same when no gpiochip driver was found.

Patch applied with the ACKs etc.

Yours,
Linus Walleij