From: Manuel Fombuena <fombuena@outlook.com>
To: lee@kernel.org, pavel@kernel.org,
vicentiu.galanopulo@remote-tech.co.uk,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 00/10] leds: st1202: fix multiple bugs in pattern engine and brightness handling
Date: Sat, 16 May 2026 15:25:26 +0100 [thread overview]
Message-ID: <WA0P291MB03850F4E9B4EC7389FE89779C5052@WA0P291MB0385.POLP291.PROD.OUTLOOK.COM> (raw)
This series fixes several bugs in the LED1202 driver related to hardware
pattern programming and brightness control. The issues were found during
testing on a Linksys MX4200v2 router running OpenWrt.
--- Pattern sequence not stopped before reprogramming ---
The LED1202 datasheet (section 4.8) states that writes to PAT_REP and
pattern duration registers are only applied after the sequence completes
or is stopped. When running in infinite loop mode the sequence never
completes on its own, so these writes are silently ignored by the
hardware.
Patch 1: Stop the running sequence by clearing PATS in the
configuration register at the start of both pattern_clear() and
pattern_set(), ensuring the hardware accepts new values immediately.
Patch 2: Validate pattern input before stopping the sequence. An
out-of-range duration value should be rejected without disrupting a
running pattern, so input validation is moved ahead of the sequence
stop.
--- pattern_clear() leaving hardware in inconsistent state ---
Several independent bugs in pattern_clear() left the hardware in a state
that affected subsequent pattern or brightness operations.
Patch 3: Fix the duration prescaler formula. The original formula
(value / ST1202_MILLIS_PATTERN_DUR_MIN - 1) produced an off-by-one
result, writing the minimum valid duration (22ms, register value 0x01)
instead of the skip marker (0x00) for unused slots.
Patch 4: Write the skip marker (0x00) directly to unused duration
registers in pattern_clear() rather than going through
st1202_duration_pattern_write(), which operates on millisecond values
and cannot express register value zero.
Patch 5: Reset PAT_REP to its power-on default of 1 in pattern_clear().
A stale value — most critically 0xFF from a previous infinite loop —
would be picked up by a subsequent pattern_set() call in the window
between pattern_clear() returning and pattern_set() writing its own
value.
Patch 6: Restore Pattern0 PWM to full brightness (0x0FFF) after
clearing. pattern_clear() zeroes all PWM slots as part of the clear,
but leaves Pattern0 at zero, so a subsequent direct brightness write
has no visible effect until Pattern0 PWM is restored.
--- Spurious pattern sequence start during setup ---
Patch 7: Remove the write of PATS|PATSR to the configuration register
in st1202_setup(). This accidentally started a pattern sequence before
any pattern data was programmed, producing undefined output on startup.
--- Brightness control broken while pattern mode is active ---
Patch 8: Exit pattern mode in brightness_set() before writing the ILED
register. With PATS set, the LED output is determined by the pattern
engine regardless of the ILED value, making direct brightness writes
have no visible effect while a pattern is active.
Patch 9: Disable the hardware channel in brightness_set() when value
is zero. Previously only the ILED DAC was zeroed while the channel
remained enabled, causing residual current through the enabled channel
and a visible dim glow on the LED.
--- Documentation ---
Patch 10: Correct and extend the hw_pattern documentation. The maximum
pattern duration was stated as 5660ms but the correct value derived
from the prescaler formula is 5610ms. The repeat field documentation
is also corrected and the brightness range is made explicit.
--- Testing ---
Tested on LED1202 hardware via I2C. Register state verified with i2cget
at each step. Correct LED behaviour confirmed across pattern cycling,
infinite repeat, pattern_clear, and direct brightness control with
trigger=none.
Manuel Fombuena (10):
leds: st1202: stop pattern sequence before reprogramming
leds: st1202: validate pattern input before stopping the sequence
leds: st1202: fix pattern duration register calculation
leds: st1202: fix pattern_clear to explicitly mark unused slots as
skip
leds: st1202: reset PAT_REP to POR default in pattern_clear
leds: st1202: restore Pattern0 PWM to full on after clearing pattern
leds: st1202: fix spurious pattern sequence start in setup
leds: st1202: fix brightness having no effect while pattern mode is
active
leds: st1202: disable channel when brightness is set to zero
leds: st1202: correct and extend hw_pattern documentation
Documentation/leds/leds-st1202.rst | 9 ++-
drivers/leds/leds-st1202.c | 95 ++++++++++++++++++------------
2 files changed, 62 insertions(+), 42 deletions(-)
--
2.54.0
next reply other threads:[~2026-05-16 14:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-16 14:25 Manuel Fombuena [this message]
2026-05-16 14:30 ` [PATCH 01/10] leds: st1202: stop pattern sequence before reprogramming Manuel Fombuena
2026-05-16 14:32 ` [PATCH 02/10] leds: st1202: validate pattern input before stopping the sequence Manuel Fombuena
2026-05-16 14:33 ` [PATCH 03/10] leds: st1202: fix pattern duration register calculation Manuel Fombuena
2026-05-16 14:34 ` [PATCH 04/10] leds: st1202: fix pattern_clear to explicitly mark unused slots as skip Manuel Fombuena
2026-05-16 14:34 ` [PATCH 05/10] leds: st1202: reset PAT_REP to POR default in pattern_clear Manuel Fombuena
2026-05-16 14:35 ` [PATCH 06/10] leds: st1202: restore Pattern0 PWM to full on after clearing pattern Manuel Fombuena
2026-05-16 14:36 ` [PATCH 07/10] leds: st1202: fix spurious pattern sequence start in setup Manuel Fombuena
2026-05-16 14:39 ` [PATCH 08/10] leds: st1202: fix brightness having no effect while pattern mode is active Manuel Fombuena
2026-05-16 14:40 ` [PATCH 09/10] leds: st1202: disable channel when brightness is set to zero Manuel Fombuena
2026-05-16 14:42 ` [PATCH 10/10] leds: st1202: correct and extend hw_pattern documentation Manuel Fombuena
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=WA0P291MB03850F4E9B4EC7389FE89779C5052@WA0P291MB0385.POLP291.PROD.OUTLOOK.COM \
--to=fombuena@outlook.com \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=vicentiu.galanopulo@remote-tech.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®