Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

LI Qingwu and committed by
Lee Jones
bb642062 d7dca03a

+19
+19
drivers/leds/leds-pwm.c
··· 9 9 * based on leds-gpio.c by Raphael Assenat <raph@8d.com> 10 10 */ 11 11 12 + #include <linux/gpio/consumer.h> 12 13 #include <linux/module.h> 13 14 #include <linux/kernel.h> 14 15 #include <linux/platform_device.h> ··· 27 26 }; 28 27 29 28 struct led_pwm_data { 29 + struct gpio_desc *enable_gpio; 30 30 struct led_classdev cdev; 31 31 struct pwm_device *pwm; 32 32 struct pwm_state pwmstate; ··· 52 50 53 51 if (led_dat->active_low) 54 52 duty = led_dat->pwmstate.period - duty; 53 + 54 + gpiod_set_value_cansleep(led_dat->enable_gpio, !!brightness); 55 55 56 56 led_dat->pwmstate.duty_cycle = duty; 57 57 /* ··· 135 131 } 136 132 break; 137 133 } 134 + 135 + /* 136 + * Claim the GPIO as GPIOD_ASIS and set the value 137 + * later on to honor the different default states 138 + */ 139 + led_data->enable_gpio = devm_fwnode_gpiod_get(dev, fwnode, "enable", GPIOD_ASIS, NULL); 140 + if (IS_ERR(led_data->enable_gpio)) { 141 + if (PTR_ERR(led_data->enable_gpio) == -ENOENT) 142 + /* Enable GPIO is optional */ 143 + led_data->enable_gpio = NULL; 144 + else 145 + return PTR_ERR(led_data->enable_gpio); 146 + } 147 + 148 + gpiod_direction_output(led_data->enable_gpio, !!led_data->cdev.brightness); 138 149 139 150 ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data); 140 151 if (ret) {