Skip to contentSkip to conversation

led: gpio: Use NOP uclass driver for top-level node

PATCH In review Marek Vasut 3 participants 3 messages Apr 22, 2022 – Apr 28, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 led: gpio: Use NOP uclass driver for top-level node

The top level DT node of gpio-leds is not a LED itself, bind NOP uclass driver to it, and bind different LED uclass driver to its subnodes which represent the actual LEDs. This simplifies the probe() implementation and fixes the bogus top-level not-an-LED in 'led list' command output:

```
=> led list
led             Error -121 <--- This is removed/fixed by this patch
green:user0     off
```
Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Simon Glass <[email protected]>
Cc Steven Lawrance <[email protected]>
---
 drivers/led/led_gpio.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/led/led_gpio.c +13 -17
index 23156907593..fbed151b5d9 100644
@@ -58,17 +58,8 @@ static enum led_state_t gpio_led_get_state(struct udevice *dev)
 static int led_gpio_probe(struct udevice *dev)
 {
 	struct led_gpio_priv *priv = dev_get_priv(dev);
-	int ret;
-
-	/* Ignore the top-level LED node */
-	if (device_is_compatible(dev, "gpio-leds"))
-		return 0;
-
-	ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
-	if (ret)
-		return ret;
 
-	return 0;
+	return gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
 }
 
 static int led_gpio_remove(struct udevice *dev)
@@ -109,18 +100,23 @@ static const struct led_ops gpio_led_ops = {
 	.get_state	= gpio_led_get_state,
 };
 
-static const struct udevice_id led_gpio_ids[] = {
-	{ .compatible = "gpio-leds" },
-	{ }
-};
-
 U_BOOT_DRIVER(led_gpio) = {
 	.name	= "gpio_led",
 	.id	= UCLASS_LED,
-	.of_match = led_gpio_ids,
 	.ops	= &gpio_led_ops,
 	.priv_auto	= sizeof(struct led_gpio_priv),
-	.bind	= led_gpio_bind,
 	.probe	= led_gpio_probe,
 	.remove	= led_gpio_remove,
 };
+
+static const struct udevice_id led_gpio_ids[] = {
+	{ .compatible = "gpio-leds" },
+	{ }
+};
+
+U_BOOT_DRIVER(led_gpio_wrap) = {
+	.name	= "gpio_led_wrap",
+	.id	= UCLASS_NOP,
+	.of_match = led_gpio_ids,
+	.bind	= led_gpio_bind,
+};
Signature · 1 line
2.35.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw

Hi Marek

Quoted 65 lines · Marek Vasut

The top level DT node of gpio-leds is not a LED itself, bind NOP uclass driver to it, and bind different LED uclass driver to its subnodes which represent the actual LEDs. This simplifies the probe() implementation and fixes the bogus top-level not-an-LED in 'led list' command output:

```
=> led list
led             Error -121 <--- This is removed/fixed by this patch
green:user0     off
```
Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Simon Glass <[email protected]>
Cc Steven Lawrance <[email protected]>
---
 drivers/led/led_gpio.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/led/led_gpio.c +3 -17
index 23156907593..fbed151b5d9 100644
@@ -58,17 +58,8 @@ static enum led_state_t gpio_led_get_state(struct udevice *dev)
 static int led_gpio_probe(struct udevice *dev)
 {
 	struct led_gpio_priv *priv = dev_get_priv(dev);
-	int ret;
-
-	/* Ignore the top-level LED node */
-	if (device_is_compatible(dev, "gpio-leds"))
-		return 0;
-
-	ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
-	if (ret)
-		return ret;
 
-	return 0;
+	return gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_OUT);
 }
 
 static int led_gpio_remove(struct udevice *dev)
@@ -109,18 +100,23 @@ static const struct led_ops gpio_led_ops = {
 	.get_state	= gpio_led_get_state,
 };
 
-static const struct udevice_id led_gpio_ids[] = {
-	{ .compatible = "gpio-leds" },
-	{ }
-};
-
 U_BOOT_DRIVER(led_gpio) = {
 	.name	= "gpio_led",
 	.id	= UCLASS_LED,
-	.of_match = led_gpio_ids,
 	.ops	= &gpio_led_ops,
 	.priv_auto	= sizeof(struct led_gpio_priv),
-	.bind	= led_gpio_bind,
 	.probe	= led_gpio_probe,
 	.remove	= led_gpio_remove,
 };
+
+static const struct udevice_id led_gpio_ids[] = {

drivers/led/led_gpio.c static const struct led_ops gpio_led_ops = { · line 122

Quoted 10 lines
drivers/led/led_gpio.c +10 -0
+	{ .compatible = "gpio-leds" },
+	{ }
+};
+
+U_BOOT_DRIVER(led_gpio_wrap) = {
+	.name	= "gpio_led_wrap",
+	.id	= UCLASS_NOP,
+	.of_match = led_gpio_ids,
+	.bind	= led_gpio_bind,
+};

Tested on stm32mp157c-dk2
Thanks
Patrice

Thanks

#2 lore raw
In reply to Marek Vasut
Quoted 11 lines · Marek Vasut

The top level DT node of gpio-leds is not a LED itself, bind NOP uclass driver to it, and bind different LED uclass driver to its subnodes which represent the actual LEDs. This simplifies the probe() implementation and fixes the bogus top-level not-an-LED in 'led list' command output:

```
=> led list
led             Error -121 <--- This is removed/fixed by this patch
green:user0     off
```
Quoted 8 lines
Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
Cc Sean Anderson <[email protected]>
Cc Simon Glass <[email protected]>
Cc Steven Lawrance <[email protected]>

Applied to u-boot/master, thanks!

Signature · 1 line
Tom