Linux LED subsystem development
 help / color / mirror / Atom feed
* [PATCH V8 0/2] leds: pwm: Add optional GPIO enable pin support
@ 2025-07-24  8:02 LI Qingwu
  2025-07-24  8:02 ` [PATCH V8 1/2] dt-bindings: leds: pwm: Add enable-gpios property LI Qingwu
  2025-07-24  8:02 ` [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support LI Qingwu
  0 siblings, 2 replies; 6+ messages in thread
From: LI Qingwu @ 2025-07-24  8:02 UTC (permalink / raw)
  To: lee, pavel, robh, krzk+dt, conor+dt, linux-leds, devicetree,
	linux-kernel, Qing-wu.Li

Add support for an optional GPIO enable pin to the PWM LED driver.
Some LED controllers require an additional enable GPIO to be enabled
on the device before PWM control can take effect.

Testing:
- Tested on i.MX8MP EVK board with TPS92380 LED backlight driver
- Verified GPIO enable/disable functionality works correctly
- Confirmed both GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW polarities
  work properly


Device tree configuration used for testing:

	backlight_keypad: backlight-keypad {
		compatible = "pwm-leds";

		led {
			color = <LED_COLOR_ID_WHITE>;
			enable-gpios = <&pca6416 11 GPIO_ACTIVE_HIGH>;
			function = LED_FUNCTION_KBD_BACKLIGHT;
			max-brightness = <100>;
			pwms = <&pwm3 0 2500 0>;
		};
	};

Changes in V8:
- Format to one line according the review comments from Lee Jones.

LI Qingwu (2):
  dt-bindings: leds: pwm: Add enable-gpios property
  leds: pwm: Add optional GPIO enable pin support

 .../devicetree/bindings/leds/leds-pwm.yaml    |  7 +++++++
 drivers/leds/leds-pwm.c                       | 20 +++++++++++++++++++
 2 files changed, 27 insertions(+)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH V8 1/2] dt-bindings: leds: pwm: Add enable-gpios property
  2025-07-24  8:02 [PATCH V8 0/2] leds: pwm: Add optional GPIO enable pin support LI Qingwu
@ 2025-07-24  8:02 ` LI Qingwu
  2025-07-24  8:02 ` [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support LI Qingwu
  1 sibling, 0 replies; 6+ messages in thread
From: LI Qingwu @ 2025-07-24  8:02 UTC (permalink / raw)
  To: lee, pavel, robh, krzk+dt, conor+dt, linux-leds, devicetree,
	linux-kernel, Qing-wu.Li
  Cc: Krzysztof Kozlowski

Some PWM LED driver chips like TPS92380 and LT3743 require a separate
enable signal in addition to PWM control. Add this property to allow
device trees to specify such GPIO, which will be controlled
automatically by the driver based on the LED brightness state.

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 Documentation/devicetree/bindings/leds/leds-pwm.yaml | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Documentation/devicetree/bindings/leds/leds-pwm.yaml b/Documentation/devicetree/bindings/leds/leds-pwm.yaml
index 61b97e8bc36d0..6c4fcefbe25f9 100644
--- a/Documentation/devicetree/bindings/leds/leds-pwm.yaml
+++ b/Documentation/devicetree/bindings/leds/leds-pwm.yaml
@@ -40,6 +40,13 @@ patternProperties:
           initialization. If the option is not set then max brightness is used.
         $ref: /schemas/types.yaml#/definitions/uint32
 
+      enable-gpios:
+        description:
+          GPIO for LED hardware enable control. Set active when brightness is
+          non-zero and inactive when brightness is zero.
+          The GPIO default state follows the "default-state" property.
+        maxItems: 1
+
     required:
       - pwms
       - max-brightness
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support
  2025-07-24  8:02 [PATCH V8 0/2] leds: pwm: Add optional GPIO enable pin support LI Qingwu
  2025-07-24  8:02 ` [PATCH V8 1/2] dt-bindings: leds: pwm: Add enable-gpios property LI Qingwu
@ 2025-07-24  8:02 ` LI Qingwu
  2025-07-31 10:46   ` Lee Jones
  1 sibling, 1 reply; 6+ messages in thread
From: LI Qingwu @ 2025-07-24  8:02 UTC (permalink / raw)
  To: lee, pavel, robh, krzk+dt, conor+dt, linux-leds, devicetree,
	linux-kernel, Qing-wu.Li

Add support for optional GPIO-based enable pin control to PWM LED driver.
Some PWM LED driver chips like TPS92380 and LT3743 require a separate
enable signal in addition to PWM control. Implement support for such
GPIO control through the "enable-gpios" device tree property, activating
the pin when LED brightness is non-zero and deactivating it when off.

Tested on i.MX8MP EVK with TPS92380 LED driver chip

Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 drivers/leds/leds-pwm.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index c73134e7b9514..08a1f735166ad 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -17,6 +17,7 @@
 #include <linux/err.h>
 #include <linux/pwm.h>
 #include <linux/slab.h>
+#include <linux/gpio/consumer.h>
 
 struct led_pwm {
 	const char	*name;
@@ -29,6 +30,7 @@ struct led_pwm_data {
 	struct led_classdev	cdev;
 	struct pwm_device	*pwm;
 	struct pwm_state	pwmstate;
+	struct gpio_desc	*enable_gpio;
 	unsigned int		active_low;
 };
 
@@ -51,6 +53,8 @@ static int led_pwm_set(struct led_classdev *led_cdev,
 	if (led_dat->active_low)
 		duty = led_dat->pwmstate.period - duty;
 
+	gpiod_set_value_cansleep(led_dat->enable_gpio, brightness == LED_OFF ? 0 : 1);
+
 	led_dat->pwmstate.duty_cycle = duty;
 	/*
 	 * Disabling a PWM doesn't guarantee that it emits the inactive level.
@@ -132,6 +136,22 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
 		break;
 	}
 
+	/*
+	 * Claim the GPIO as GPIOD_ASIS and set the value
+	 * later on to honor the different default states
+	 */
+	led_data->enable_gpio = devm_fwnode_gpiod_get(dev, fwnode, "enable", GPIOD_ASIS, NULL);
+
+	if (IS_ERR(led_data->enable_gpio)) {
+		if (PTR_ERR(led_data->enable_gpio) == -ENOENT)
+			/* Enable GPIO is optional */
+			led_data->enable_gpio = NULL;
+		else
+			return PTR_ERR(led_data->enable_gpio);
+	}
+
+	gpiod_direction_output(led_data->enable_gpio, !!led_data->cdev.brightness);
+
 	ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data);
 	if (ret) {
 		dev_err(dev, "failed to register PWM led for %s: %d\n",
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support
  2025-07-24  8:02 ` [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support LI Qingwu
@ 2025-07-31 10:46   ` Lee Jones
  2025-08-12 11:44     ` LI Qingwu
  0 siblings, 1 reply; 6+ messages in thread
From: Lee Jones @ 2025-07-31 10:46 UTC (permalink / raw)
  To: LI Qingwu
  Cc: pavel, robh, krzk+dt, conor+dt, linux-leds, devicetree,
	linux-kernel

On Thu, 24 Jul 2025, LI Qingwu wrote:

> Add support for optional GPIO-based enable pin control to PWM LED driver.
> Some PWM LED driver chips like TPS92380 and LT3743 require a separate
> enable signal in addition to PWM control. Implement support for such
> GPIO control through the "enable-gpios" device tree property, activating
> the pin when LED brightness is non-zero and deactivating it when off.
> 
> Tested on i.MX8MP EVK with TPS92380 LED driver chip
> 
> Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
> ---
>  drivers/leds/leds-pwm.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
> index c73134e7b9514..08a1f735166ad 100644
> --- a/drivers/leds/leds-pwm.c
> +++ b/drivers/leds/leds-pwm.c
> @@ -17,6 +17,7 @@
>  #include <linux/err.h>
>  #include <linux/pwm.h>
>  #include <linux/slab.h>
> +#include <linux/gpio/consumer.h>

This list is alphabetical.

>  struct led_pwm {
>  	const char	*name;
> @@ -29,6 +30,7 @@ struct led_pwm_data {
>  	struct led_classdev	cdev;
>  	struct pwm_device	*pwm;
>  	struct pwm_state	pwmstate;
> +	struct gpio_desc	*enable_gpio;
>  	unsigned int		active_low;
>  };
>  
> @@ -51,6 +53,8 @@ static int led_pwm_set(struct led_classdev *led_cdev,
>  	if (led_dat->active_low)
>  		duty = led_dat->pwmstate.period - duty;
>  
> +	gpiod_set_value_cansleep(led_dat->enable_gpio, brightness == LED_OFF ? 0 : 1);

How about the more succinct:

  brightness ? 1 : 0

Or:

  !!brightness

> +
>  	led_dat->pwmstate.duty_cycle = duty;
>  	/*
>  	 * Disabling a PWM doesn't guarantee that it emits the inactive level.
> @@ -132,6 +136,22 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
>  		break;
>  	}
>  
> +	/*
> +	 * Claim the GPIO as GPIOD_ASIS and set the value
> +	 * later on to honor the different default states
> +	 */
> +	led_data->enable_gpio = devm_fwnode_gpiod_get(dev, fwnode, "enable", GPIOD_ASIS, NULL);
> +

Remove this line.

> +	if (IS_ERR(led_data->enable_gpio)) {
> +		if (PTR_ERR(led_data->enable_gpio) == -ENOENT)
> +			/* Enable GPIO is optional */
> +			led_data->enable_gpio = NULL;
> +		else
> +			return PTR_ERR(led_data->enable_gpio);
> +	}
> +
> +	gpiod_direction_output(led_data->enable_gpio, !!led_data->cdev.brightness);
> +
>  	ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data);
>  	if (ret) {
>  		dev_err(dev, "failed to register PWM led for %s: %d\n",
> -- 
> 2.43.0
> 

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support
  2025-07-31 10:46   ` Lee Jones
@ 2025-08-12 11:44     ` LI Qingwu
  2025-09-02 10:26       ` Lee Jones
  0 siblings, 1 reply; 6+ messages in thread
From: LI Qingwu @ 2025-08-12 11:44 UTC (permalink / raw)
  To: Lee Jones
  Cc: pavel@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, linux-leds@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org



> -----Original Message-----
> From: Lee Jones <lee@kernel.org>
> Sent: Thursday, July 31, 2025 6:46 PM
> To: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
> Cc: pavel@kernel.org; robh@kernel.org; krzk+dt@kernel.org;
> conor+dt@kernel.org; linux-leds@vger.kernel.org; devicetree@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support
> 
> 
> On Thu, 24 Jul 2025, LI Qingwu wrote:
> 
> > Add support for optional GPIO-based enable pin control to PWM LED driver.
> > Some PWM LED driver chips like TPS92380 and LT3743 require a separate
> > enable signal in addition to PWM control. Implement support for such
> > GPIO control through the "enable-gpios" device tree property,
> > activating the pin when LED brightness is non-zero and deactivating it when
> off.
> >
> > Tested on i.MX8MP EVK with TPS92380 LED driver chip
> >
> > Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
> > ---
> >  drivers/leds/leds-pwm.c | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> >
> > diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index
> > c73134e7b9514..08a1f735166ad 100644
> > --- a/drivers/leds/leds-pwm.c
> > +++ b/drivers/leds/leds-pwm.c
> > @@ -17,6 +17,7 @@
> >  #include <linux/err.h>
> >  #include <linux/pwm.h>
> >  #include <linux/slab.h>
> > +#include <linux/gpio/consumer.h>
> 
> This list is alphabetical.
> 
The original code's include order is not alphabetical,
If you prefer, I can reorder all or just put "#include <linux/gpio/consumer.h>" to first line,
Please let me know your preference.

Li Qingwu

> >  struct led_pwm {
> >       const char      *name;
> > @@ -29,6 +30,7 @@ struct led_pwm_data {
> >       struct led_classdev     cdev;
> >       struct pwm_device       *pwm;
> >       struct pwm_state        pwmstate;
> > +     struct gpio_desc        *enable_gpio;
> >       unsigned int            active_low;
> >  };
> >
> > @@ -51,6 +53,8 @@ static int led_pwm_set(struct led_classdev *led_cdev,
> >       if (led_dat->active_low)
> >               duty = led_dat->pwmstate.period - duty;
> >
> > +     gpiod_set_value_cansleep(led_dat->enable_gpio, brightness ==
> > + LED_OFF ? 0 : 1);
> 
> How about the more succinct:
> 
>   brightness ? 1 : 0
> 
> Or:
> 
>   !!brightness
> 
> > +
> >       led_dat->pwmstate.duty_cycle = duty;
> >       /*
> >        * Disabling a PWM doesn't guarantee that it emits the inactive level.
> > @@ -132,6 +136,22 @@ static int led_pwm_add(struct device *dev, struct
> led_pwm_priv *priv,
> >               break;
> >       }
> >
> > +     /*
> > +      * Claim the GPIO as GPIOD_ASIS and set the value
> > +      * later on to honor the different default states
> > +      */
> > +     led_data->enable_gpio = devm_fwnode_gpiod_get(dev, fwnode,
> > + "enable", GPIOD_ASIS, NULL);
> > +
> 
> Remove this line.
> 
> > +     if (IS_ERR(led_data->enable_gpio)) {
> > +             if (PTR_ERR(led_data->enable_gpio) == -ENOENT)
> > +                     /* Enable GPIO is optional */
> > +                     led_data->enable_gpio = NULL;
> > +             else
> > +                     return PTR_ERR(led_data->enable_gpio);
> > +     }
> > +
> > +     gpiod_direction_output(led_data->enable_gpio,
> > + !!led_data->cdev.brightness);
> > +
> >       ret = devm_led_classdev_register_ext(dev, &led_data->cdev,
> &init_data);
> >       if (ret) {
> >               dev_err(dev, "failed to register PWM led for %s: %d\n",
> > --
> > 2.43.0
> >
> 
> --
> Lee Jones [李琼斯]



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support
  2025-08-12 11:44     ` LI Qingwu
@ 2025-09-02 10:26       ` Lee Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2025-09-02 10:26 UTC (permalink / raw)
  To: LI Qingwu
  Cc: pavel@kernel.org, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, linux-leds@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org

On Tue, 12 Aug 2025, LI Qingwu wrote:

> 
> 
> > -----Original Message-----
> > From: Lee Jones <lee@kernel.org>
> > Sent: Thursday, July 31, 2025 6:46 PM
> > To: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
> > Cc: pavel@kernel.org; robh@kernel.org; krzk+dt@kernel.org;
> > conor+dt@kernel.org; linux-leds@vger.kernel.org; devicetree@vger.kernel.org;
> > linux-kernel@vger.kernel.org
> > Subject: Re: [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support
> > 
> > 
> > On Thu, 24 Jul 2025, LI Qingwu wrote:
> > 
> > > Add support for optional GPIO-based enable pin control to PWM LED driver.
> > > Some PWM LED driver chips like TPS92380 and LT3743 require a separate
> > > enable signal in addition to PWM control. Implement support for such
> > > GPIO control through the "enable-gpios" device tree property,
> > > activating the pin when LED brightness is non-zero and deactivating it when
> > off.
> > >
> > > Tested on i.MX8MP EVK with TPS92380 LED driver chip
> > >
> > > Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
> > > ---
> > >  drivers/leds/leds-pwm.c | 20 ++++++++++++++++++++
> > >  1 file changed, 20 insertions(+)
> > >
> > > diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index
> > > c73134e7b9514..08a1f735166ad 100644
> > > --- a/drivers/leds/leds-pwm.c
> > > +++ b/drivers/leds/leds-pwm.c
> > > @@ -17,6 +17,7 @@
> > >  #include <linux/err.h>
> > >  #include <linux/pwm.h>
> > >  #include <linux/slab.h>
> > > +#include <linux/gpio/consumer.h>
> > 
> > This list is alphabetical.
> > 
> The original code's include order is not alphabetical,
> If you prefer, I can reorder all or just put "#include <linux/gpio/consumer.h>" to first line,
> Please let me know your preference.

First line is okay for now.

Then, if you feel like it, submit another patch to place them in order.

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-02 10:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-24  8:02 [PATCH V8 0/2] leds: pwm: Add optional GPIO enable pin support LI Qingwu
2025-07-24  8:02 ` [PATCH V8 1/2] dt-bindings: leds: pwm: Add enable-gpios property LI Qingwu
2025-07-24  8:02 ` [PATCH V8 2/2] leds: pwm: Add optional GPIO enable pin support LI Qingwu
2025-07-31 10:46   ` Lee Jones
2025-08-12 11:44     ` LI Qingwu
2025-09-02 10:26       ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox