Skip to content

Commit bb64206

Browse files
Qingwu-Lilag-linaro
authored andcommitted
leds: pwm: Add optional GPIO enable pin support
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> Link: https://patch.msgid.link/20251117054511.730246-2-Qing-wu.Li@leica-geosystems.com.cn Signed-off-by: Lee Jones <lee@kernel.org>
1 parent d7dca03 commit bb64206

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

drivers/leds/leds-pwm.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* based on leds-gpio.c by Raphael Assenat <raph@8d.com>
1010
*/
1111

12+
#include <linux/gpio/consumer.h>
1213
#include <linux/module.h>
1314
#include <linux/kernel.h>
1415
#include <linux/platform_device.h>
@@ -26,6 +27,7 @@ struct led_pwm {
2627
};
2728

2829
struct led_pwm_data {
30+
struct gpio_desc *enable_gpio;
2931
struct led_classdev cdev;
3032
struct pwm_device *pwm;
3133
struct pwm_state pwmstate;
@@ -51,6 +53,8 @@ static int led_pwm_set(struct led_classdev *led_cdev,
5153
if (led_dat->active_low)
5254
duty = led_dat->pwmstate.period - duty;
5355

56+
gpiod_set_value_cansleep(led_dat->enable_gpio, !!brightness);
57+
5458
led_dat->pwmstate.duty_cycle = duty;
5559
/*
5660
* 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,
132136
break;
133137
}
134138

139+
/*
140+
* Claim the GPIO as GPIOD_ASIS and set the value
141+
* later on to honor the different default states
142+
*/
143+
led_data->enable_gpio = devm_fwnode_gpiod_get(dev, fwnode, "enable", GPIOD_ASIS, NULL);
144+
if (IS_ERR(led_data->enable_gpio)) {
145+
if (PTR_ERR(led_data->enable_gpio) == -ENOENT)
146+
/* Enable GPIO is optional */
147+
led_data->enable_gpio = NULL;
148+
else
149+
return PTR_ERR(led_data->enable_gpio);
150+
}
151+
152+
gpiod_direction_output(led_data->enable_gpio, !!led_data->cdev.brightness);
153+
135154
ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data);
136155
if (ret) {
137156
dev_err(dev, "failed to register PWM led for %s: %d\n",

0 commit comments

Comments
 (0)