clk: nuvoton: ma35d1-divider: use direct formula instead of divider table
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest1 patch 5 repliesIn review
- v11 patch 0 repliesSuperseded
Changes in v2 from the cover letter
- Fix a possible division by zero: 2 * rate in determine_rate() and set_rate() could overflow for very large requested rates, making the divisor zero. Rates above parent_rate / 2 now short-circuit to a divider of 1 before the multiplication.
- Fix the mismatch between determine_rate() and set_rate(): both used a ceiling to pick the divider, yet determine_rate() reported a closest-rounded rate, so set_rate() could program a different divider than the one promised. Both now use closest rounding, as the original CLK_DIVIDER_ROUND_CLOSEST code did, via a single shared helper (ma35d1_clkdiv_get_val()) that also clamps the divider to its valid range.
- Not changed: min_rate/max_rate are not checked in the driver, since the clk core already applies them and the previous divider_determine_rate() based code did not either.
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/1 | clk: nuvoton: ma35d1-divider: use direct formula instead of divider tabledrivers/ drivers/ drivers/ | +42 | 4 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH v2 0/1] clk: nuvoton: ma35d1-divider: use direct formula instead of divider table
The MA35D1 ADC clock divider register implements a simple closed-form relation, rate = parent_rate / (2 * (N + 1)), but the driver models it by building a clk_div_table with one entry per possible divider value (up to 2^width entries) and feeding it through the generic divider_recalc_rate()/divider_determine_rate()/divider_get_val() helpers. Replace the table with direct arithmetic in recalc_rate()/determine_rate()/ set_rate(), and drop the unused mask_bit mechanism, whose only call site passed a bitmask instead of a bit index, causing an out-of-range BIT() shift.
Changes in v2 (addressing the Sashiko AI review of v1):
- Fix a possible division by zero: 2 * rate in determine_rate() and set_rate() could overflow for very large requested rates, making the divisor zero. Rates above parent_rate / 2 now short-circuit to a divider of 1 before the multiplication.
- Fix the mismatch between determine_rate() and set_rate(): both used a ceiling to pick the divider, yet determine_rate() reported a closest-rounded rate, so set_rate() could program a different divider than the one promised. Both now use closest rounding, as the original CLK_DIVIDER_ROUND_CLOSEST code did, via a single shared helper (ma35d1_clkdiv_get_val()) that also clamps the divider to its valid range.
- Not changed: min_rate/max_rate are not checked in the driver, since the clk core already applies them and the previous divider_determine_rate() based code did not either.
Joey Lu (1):
clk: nuvoton: ma35d1-divider: use direct formula instead of divider
table
drivers/clk/nuvoton/clk-ma35d1-divider.c | 79 ++++++++++++------------ drivers/clk/nuvoton/clk-ma35d1.c | 2 +- drivers/clk/nuvoton/clk-ma35d1.h | 2 +- 3 files changed, 42 insertions(+), 41 deletions(-)
Signature · 1 line
2.43.0