Skip to contentSkip to conversation

leds: gpio: Configure per-LED pin control

PATCH Superseded Marek Vasut 3 participants 6 messages Nov 7, 2022 – May 7, 2023 LED

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: gpio: Configure per-LED pin control

Each gpio-leds DT node DT subnode can have a pinctrl property assigned to it, parse the DT subnode pinctrl properties and configure each pin accordingly.

---
Cc: Christoph Niedermaier <[email protected]>
Cc: Pavel Machek <[email protected]>
To: [email protected]

---
 drivers/leds/leds-gpio.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/leds/leds-gpio.c +18 -0
index 092eb59a7d325..01ca88876f008 100644
@@ -13,6 +13,7 @@
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/slab.h>
@@ -77,6 +78,7 @@ static int create_gpio_led(const struct gpio_led *template,
 	struct fwnode_handle *fwnode, gpio_blink_set_t blink_set)
 {
 	struct led_init_data init_data = {};
+	struct pinctrl *pinctrl;
 	int ret, state;
 
 	led_dat->cdev.default_trigger = template->default_trigger;
@@ -119,6 +121,22 @@ static int create_gpio_led(const struct gpio_led *template,
 						     &init_data);
 	}
 
+	if (ret)
+		return ret;
+
+	pinctrl = devm_pinctrl_get_select_default(led_dat->cdev.dev);
+	if (IS_ERR(pinctrl)) {
+		ret = PTR_ERR(pinctrl);
+		if (ret != -ENODEV) {
+			dev_warn(led_dat->cdev.dev,
+				 "Failed to select %pOF pinctrl: %d\n",
+				 to_of_node(fwnode), ret);
+		} else {
+			/* pinctrl-%d not present, not an error */
+			ret = 0;
+		}
+	}
+
 	return ret;
 }
 
Signature · 1 line
2.35.1
Tested-by on v1 1/1
#1 lore raw

From: Marek Vasut [mailto:[email protected]]
Sent: Monday, November 7, 2022 1:32 AM

Quoted 46 lines

Each gpio-leds DT node DT subnode can have a pinctrl property assigned to it, parse the DT subnode pinctrl properties and configure each pin accordingly.

---
Cc: Christoph Niedermaier <[email protected]>
Cc: Pavel Machek <[email protected]>
To: [email protected]

---
 drivers/leds/leds-gpio.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/leds/leds-gpio.c +11 -0
index 092eb59a7d325..01ca88876f008 100644
@@ -13,6 +13,7 @@
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/slab.h>
@@ -77,6 +78,7 @@ static int create_gpio_led(const struct gpio_led *template,
        struct fwnode_handle *fwnode, gpio_blink_set_t blink_set)
 {
        struct led_init_data init_data = {};
+       struct pinctrl *pinctrl;
        int ret, state;
 
        led_dat->cdev.default_trigger = template->default_trigger;
@@ -119,6 +121,22 @@ static int create_gpio_led(const struct gpio_led *template,
                                                     &init_data);
        }
 
+       if (ret)
+               return ret;
+
+       pinctrl = devm_pinctrl_get_select_default(led_dat->cdev.dev);
+       if (IS_ERR(pinctrl)) {
+               ret = PTR_ERR(pinctrl);
+               if (ret != -ENODEV) {
+                       dev_warn(led_dat->cdev.dev,
+                                "Failed to select %pOF pinctrl: %d\n",

drivers/leds/leds-gpio.c static int create_gpio_led(const struct gpio_led *template, · line 142

Quoted 10 lines
drivers/leds/leds-gpio.c +7 -0
+                                to_of_node(fwnode), ret);
+               } else {
+                       /* pinctrl-%d not present, not an error */
+                       ret = 0;
+               }
+       }
+
        return ret;
 }
 

Regards
Christoph

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

Each gpio-leds DT node DT subnode can have a pinctrl property assigned to it, parse the DT subnode pinctrl properties and configure each pin accordingly.

---
Cc: Christoph Niedermaier <[email protected]>
Cc: Pavel Machek <[email protected]>
To: [email protected]

---
  drivers/leds/leds-gpio.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
drivers/leds/leds-gpio.c +11 -0
index 092eb59a7d325..01ca88876f008 100644
@@ -13,6 +13,7 @@
  #include <linux/leds.h>
  #include <linux/module.h>
  #include <linux/of.h>
+#include <linux/pinctrl/consumer.h>
  #include <linux/platform_device.h>
  #include <linux/property.h>
  #include <linux/slab.h>
@@ -77,6 +78,7 @@ static int create_gpio_led(const struct gpio_led *template,
  	struct fwnode_handle *fwnode, gpio_blink_set_t blink_set)
  {
  	struct led_init_data init_data = {};
+	struct pinctrl *pinctrl;
  	int ret, state;
 
  	led_dat->cdev.default_trigger = template->default_trigger;
@@ -119,6 +121,22 @@ static int create_gpio_led(const struct gpio_led *template,
  						     &init_data);
  	}
 
+	if (ret)
+		return ret;
+
+	pinctrl = devm_pinctrl_get_select_default(led_dat->cdev.dev);
+	if (IS_ERR(pinctrl)) {
+		ret = PTR_ERR(pinctrl);
+		if (ret != -ENODEV) {
+			dev_warn(led_dat->cdev.dev,
+				 "Failed to select %pOF pinctrl: %d\n",

drivers/leds/leds-gpio.c static int create_gpio_led(const struct gpio_led *template, · line 142

Quoted 10 lines
drivers/leds/leds-gpio.c +7 -0
+				 to_of_node(fwnode), ret);
+		} else {
+			/* pinctrl-%d not present, not an error */
+			ret = 0;
+		}
+	}
+
  	return ret;
  }
 

Any news on this patch ?

#3 lore raw
In reply to Marek Vasut

Hi!

Quoted 3 lines

Each gpio-leds DT node DT subnode can have a pinctrl property assigned to it, parse the DT subnode pinctrl properties and configure each pin accordingly.

Do we need update to Documentation/devicetree/bindings/leds/leds-gpio.yaml ?

Otherwise looks good to me.

Thank you,
Pavel

Quoted 40 lines

+++ b/drivers/leds/leds-gpio.c

drivers/leds/leds-gpio.c +18 -0
@@ -13,6 +13,7 @@
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/slab.h>
@@ -77,6 +78,7 @@ static int create_gpio_led(const struct gpio_led *template,
 	struct fwnode_handle *fwnode, gpio_blink_set_t blink_set)
 {
 	struct led_init_data init_data = {};
+	struct pinctrl *pinctrl;
 	int ret, state;
 
 	led_dat->cdev.default_trigger = template->default_trigger;
@@ -119,6 +121,22 @@ static int create_gpio_led(const struct gpio_led *template,
 						     &init_data);
 	}
 
+	if (ret)
+		return ret;
+
+	pinctrl = devm_pinctrl_get_select_default(led_dat->cdev.dev);
+	if (IS_ERR(pinctrl)) {
+		ret = PTR_ERR(pinctrl);
+		if (ret != -ENODEV) {
+			dev_warn(led_dat->cdev.dev,
+				 "Failed to select %pOF pinctrl: %d\n",
+				 to_of_node(fwnode), ret);
+		} else {
+			/* pinctrl-%d not present, not an error */
+			ret = 0;
+		}
+	}
+
 	return ret;
 }
 
Signature · 1 line
People of Russia, stop Putin before his war on Ukraine escalates.
#4 lore raw
Quoted 8 lines · Pavel Machek

Hi!

Quoted 3 lines

Each gpio-leds DT node DT subnode can have a pinctrl property assigned to it, parse the DT subnode pinctrl properties and configure each pin accordingly.

Do we need update to Documentation/devicetree/bindings/leds/leds-gpio.yaml ?

As far as I can tell, no. The pinctrl properties are generic and outside of the leds-gpio yaml schema.

#5 lore raw
Quoted 11 lines · Marek Vasut
Quoted 8 lines · Pavel Machek

Hi!

Quoted 3 lines

Each gpio-leds DT node DT subnode can have a pinctrl property assigned to it, parse the DT subnode pinctrl properties and configure each pin accordingly.

Do we need update to Documentation/devicetree/bindings/leds/leds-gpio.yaml ?

As far as I can tell, no. The pinctrl properties are generic and outside of the leds-gpio yaml schema.

Are there any further concerns or can this patch be applied now ?

Thanks!