Linux LED subsystem development
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: Manuel Fombuena <fombuena@outlook.com>
Cc: pavel@kernel.org, vicentiu.galanopulo@remote-tech.co.uk,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 00/10] leds: st1202: fix multiple bugs in pattern engine and brightness handling
Date: Thu, 4 Jun 2026 16:20:16 +0100	[thread overview]
Message-ID: <20260604152016.GC4151951@google.com> (raw)
In-Reply-To: <WA0P291MB03855101311F0506B6448A8EC50D2@WA0P291MB0385.POLP291.PROD.OUTLOOK.COM>

Can you take a look through these Sashiko reviews please:

https://sashiko.dev/#/patchset/WA0P291MB03855101311F0506B6448A8EC50D2%40WA0P291MB0385.POLP291.PROD.OUTLOOK.COM

> 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.
> 
> --- Changes in v2 ---
> 
>   Patch 3: Fix commit message wording — programmed durations were ~22ms
>   too short, not too long.
>   Patch 7: Fix Signed-off-by typo.
>   Patch 10: Add missing quotes around commit subject in Fixes: tag.
> 
> v1: https://lore.kernel.org/all/WA0P291MB03850F4E9B4EC7389FE89779C5052@WA0P291MB0385.POLP291.PROD.OUTLOOK.COM/
> 
> 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
> 

-- 
Lee Jones

      parent reply	other threads:[~2026-06-04 15:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 22:17 [PATCH v2 00/10] leds: st1202: fix multiple bugs in pattern engine and brightness handling Manuel Fombuena
2026-05-24 22:22 ` [PATCH v2 01/10] leds: st1202: stop pattern sequence before reprogramming Manuel Fombuena
2026-05-24 22:23 ` [PATCH v2 02/10] leds: st1202: validate pattern input before stopping the sequence Manuel Fombuena
2026-05-24 22:24 ` [PATCH v2 03/10] leds: st1202: fix pattern duration register calculation Manuel Fombuena
2026-05-24 22:25 ` [PATCH v2 04/10] leds: st1202: fix pattern_clear to explicitly mark unused slots as skip Manuel Fombuena
2026-05-24 22:26 ` [PATCH v2 05/10] leds: st1202: reset PAT_REP to POR default in pattern_clear Manuel Fombuena
2026-05-24 22:27 ` [PATCH v2 06/10] leds: st1202: restore Pattern0 PWM to full on after clearing pattern Manuel Fombuena
2026-05-24 22:28 ` [PATCH v2 07/10] leds: st1202: fix spurious pattern sequence start in setup Manuel Fombuena
2026-05-24 22:29 ` [PATCH v2 08/10] leds: st1202: fix brightness having no effect while pattern mode is active Manuel Fombuena
2026-05-24 22:30 ` [PATCH v2 09/10] leds: st1202: disable channel when brightness is set to zero Manuel Fombuena
2026-05-24 22:30 ` [PATCH v2 10/10] leds: st1202: correct and extend hw_pattern documentation Manuel Fombuena
2026-06-04 15:20 ` Lee Jones [this message]

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=20260604152016.GC4151951@google.com \
    --to=lee@kernel.org \
    --cc=fombuena@outlook.com \
    --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