[PATCH v1 05/11] leds: st1202: Clear unused pattern slots in pattern_set()

From: Manuel Fombuena

Date: Sat Sep 12 2026 - 18:34:57 EST


The pattern duration registers are chip-wide while the PWM registers are
per-channel, so a channel can end up driven by a sequencer timeline it
never programmed.

st1202_led_pattern_set() programs only the first len slots. The pattern
trigger calls pattern_clear() before pattern_set() only once a channel is
already in PATTERN_TYPE_HW mode, so the first hardware pattern written to
a given channel skips it. If another channel has already programmed a
longer pattern, durations [len, 8) are still set, and this channel's PWM
for those slots is whatever st1202_led_pattern_clear() left at probe.

That used to be LED_OFF, so a channel stayed dark for the slots it had
not programmed itself. Since commit d2ca0e2b6d64 ("leds: st1202: Set all
pattern PWM slots to full after clearing pattern") it is
ST1202_PATTERN_PWM_FULL, so the channel now plays its own steps and then
sits at full brightness for the rest of the sequence.

Zero this channel's PWM for the unused slots so it stays dark for the
remainder of the timeline, as st1202_blink_set() already does for the
channels it is not driving.

The duration registers are deliberately left alone. All twelve channels
share them, so clearing them would truncate a longer pattern still
running elsewhere on the same device. A channel whose pattern is shorter
than the active timeline therefore keeps the longer period; that follows
from having a single hardware sequencer and is not something this can
correct.

Fixes: d2ca0e2b6d64 ("leds: st1202: Set all pattern PWM slots to full after clearing pattern")
Signed-off-by: Manuel Fombuena <fombuena@xxxxxxxxxxx>
Assisted-by: LLM
---
drivers/leds/leds-st1202.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/leds/leds-st1202.c b/drivers/leds/leds-st1202.c
index 90f69ac16714..9985b4b60989 100644
--- a/drivers/leds/leds-st1202.c
+++ b/drivers/leds/leds-st1202.c
@@ -263,6 +263,12 @@ static int st1202_led_pattern_set(struct led_classdev *ldev,
return ret;
}

+ for (int pattern = len; pattern < ST1202_MAX_PATTERNS; pattern++) {
+ ret = st1202_pwm_pattern_write(chip, led->led_num, pattern, LED_OFF);
+ if (ret != 0)
+ return ret;
+ }
+
ret = st1202_write_reg(chip, ST1202_PATTERN_REP, repeat);
if (ret != 0)
return ret;
--
2.55.0