* [PATCH V9 0/3] leds: pwm: Add optional GPIO enable pin support
@ 2025-11-05 6:50 LI Qingwu
2025-11-05 6:50 ` [PATCH V9 1/3] dt-bindings: leds: pwm: Add enable-gpios property LI Qingwu
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: LI Qingwu @ 2025-11-05 6:50 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 V9
Reorder include files to alphabetic.
LI Qingwu (3):
dt-bindings: leds: pwm: Add enable-gpios property
leds: pwm: Add optional GPIO enable pin support
leds: pwm: Reorder include files to alphabetic order
.../devicetree/bindings/leds/leds-pwm.yaml | 7 +++++
drivers/leds/leds-pwm.c | 27 ++++++++++++++++---
2 files changed, 30 insertions(+), 4 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH V9 1/3] dt-bindings: leds: pwm: Add enable-gpios property
2025-11-05 6:50 [PATCH V9 0/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
@ 2025-11-05 6:50 ` LI Qingwu
2025-11-05 6:50 ` [PATCH V9 2/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
2025-11-05 6:50 ` [PATCH V9 3/3] leds: pwm: Reorder include files to alphabetic order LI Qingwu
2 siblings, 0 replies; 5+ messages in thread
From: LI Qingwu @ 2025-11-05 6:50 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 61b97e8bc36d..6c4fcefbe25f 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] 5+ messages in thread
* [PATCH V9 2/3] leds: pwm: Add optional GPIO enable pin support
2025-11-05 6:50 [PATCH V9 0/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
2025-11-05 6:50 ` [PATCH V9 1/3] dt-bindings: leds: pwm: Add enable-gpios property LI Qingwu
@ 2025-11-05 6:50 ` LI Qingwu
2025-11-13 15:53 ` Lee Jones
2025-11-05 6:50 ` [PATCH V9 3/3] leds: pwm: Reorder include files to alphabetic order LI Qingwu
2 siblings, 1 reply; 5+ messages in thread
From: LI Qingwu @ 2025-11-05 6:50 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 | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index c73134e7b951..aa9e14d912bf 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -9,6 +9,7 @@
* based on leds-gpio.c by Raphael Assenat <raph@8d.com>
*/
+#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
@@ -26,6 +27,7 @@ struct led_pwm {
};
struct led_pwm_data {
+ struct gpio_desc *enable_gpio;
struct led_classdev cdev;
struct pwm_device *pwm;
struct pwm_state pwmstate;
@@ -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_dat->pwmstate.duty_cycle = duty;
/*
* Disabling a PWM doesn't guarantee that it emits the inactive level.
@@ -132,6 +136,21 @@ 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] 5+ messages in thread
* [PATCH V9 3/3] leds: pwm: Reorder include files to alphabetic order
2025-11-05 6:50 [PATCH V9 0/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
2025-11-05 6:50 ` [PATCH V9 1/3] dt-bindings: leds: pwm: Add enable-gpios property LI Qingwu
2025-11-05 6:50 ` [PATCH V9 2/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
@ 2025-11-05 6:50 ` LI Qingwu
2 siblings, 0 replies; 5+ messages in thread
From: LI Qingwu @ 2025-11-05 6:50 UTC (permalink / raw)
To: lee, pavel, robh, krzk+dt, conor+dt, linux-leds, devicetree,
linux-kernel, Qing-wu.Li
Reorder include files to alphabetic order to simplify maintenance
No functional change.
Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
drivers/leds/leds-pwm.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index aa9e14d912bf..dc68f993545a 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -9,13 +9,13 @@
* based on leds-gpio.c by Raphael Assenat <raph@8d.com>
*/
+#include <linux/err.h>
#include <linux/gpio/consumer.h>
-#include <linux/module.h>
#include <linux/kernel.h>
-#include <linux/platform_device.h>
-#include <linux/of.h>
#include <linux/leds.h>
-#include <linux/err.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
#include <linux/pwm.h>
#include <linux/slab.h>
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V9 2/3] leds: pwm: Add optional GPIO enable pin support
2025-11-05 6:50 ` [PATCH V9 2/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
@ 2025-11-13 15:53 ` Lee Jones
0 siblings, 0 replies; 5+ messages in thread
From: Lee Jones @ 2025-11-13 15:53 UTC (permalink / raw)
To: LI Qingwu
Cc: pavel, robh, krzk+dt, conor+dt, linux-leds, devicetree,
linux-kernel
On Wed, 05 Nov 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 | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
> index c73134e7b951..aa9e14d912bf 100644
> --- a/drivers/leds/leds-pwm.c
> +++ b/drivers/leds/leds-pwm.c
> @@ -9,6 +9,7 @@
> * based on leds-gpio.c by Raphael Assenat <raph@8d.com>
> */
>
> +#include <linux/gpio/consumer.h>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/platform_device.h>
> @@ -26,6 +27,7 @@ struct led_pwm {
> };
>
> struct led_pwm_data {
> + struct gpio_desc *enable_gpio;
> struct led_classdev cdev;
> struct pwm_device *pwm;
> struct pwm_state pwmstate;
> @@ -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);
Nit: Too many spaces.
Didn't checkpatch.pl pick this up?
The rest of the set looks okay.
> +
> led_dat->pwmstate.duty_cycle = duty;
> /*
> * Disabling a PWM doesn't guarantee that it emits the inactive level.
> @@ -132,6 +136,21 @@ 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
>
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-13 15:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-05 6:50 [PATCH V9 0/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
2025-11-05 6:50 ` [PATCH V9 1/3] dt-bindings: leds: pwm: Add enable-gpios property LI Qingwu
2025-11-05 6:50 ` [PATCH V9 2/3] leds: pwm: Add optional GPIO enable pin support LI Qingwu
2025-11-13 15:53 ` Lee Jones
2025-11-05 6:50 ` [PATCH V9 3/3] leds: pwm: Reorder include files to alphabetic order LI Qingwu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).