From 23e938cdb48268fc1ea5823399c97d0b71e9fd91 Mon Sep 17 00:00:00 2001 From: Lucas Goossen Date: Sun, 25 Oct 2026 17:17:26 -0300 Subject: [PATCH] leds: pwm: do not force the LED off when period readback is zero Apple FPWM comes out of reset with ON_CYCLES and OFF_CYCLES both zero. pwm-apple get_state reports that as period 0. leds-pwm, on default-state = "keep", treats a zero period as a failed read, switches to off, and applies duty 0. On J313 the keyboard backlight is that device: fpwm1 channel 0, pwms = <&fpwm1 0 40000>, default-state = "keep". Every boot logs leds_pwm led-controller: failed to read period for kbd_backlight, default to off and probe programs a 0% waveform before systemd-backlight can restore the saved level. The period in the pwms cell is already in pwm->args by the time led_pwm_add() runs. When the hardware period is 0 and that args period is not, keep the args period for later brightness updates and do not apply a duty of 0. Apply off only when there is still no period to use. The fpwm1 suspend power-state failure is a separate bug and is not touched here. Signed-off-by: Lucas Goossen --- drivers/leds/leds-pwm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index 6c1f2f50ff854f..3865cd7bee86c7 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -108,6 +108,19 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, pwm_get_state(led_data->pwm, &led_data->pwmstate); if (led_data->pwmstate.period) break; + /* + * Cycle registers at reset are zero, so pwm-apple reports period + * 0. The pwms specifier still has a period. Use that for later + * brightness updates, but do not apply duty 0: that is what forces + * the LED off at probe. + */ + pwm_init_state(led_data->pwm, &led_data->pwmstate); + if (led_data->pwmstate.period) { + dev_info(dev, + "no PWM period read back for %s; using %llu ns and leaving the output unchanged\n", + led->name, led_data->pwmstate.period); + break; + } led->default_state = LEDS_DEFSTATE_OFF; dev_warn(dev, "failed to read period for %s, default to off",