Skip to content

Commit 4dd432d

Browse files
a3fabelvesa
authored andcommitted
clk: imx: composite-8m: fix clock pauses when set_rate would be a no-op
Reconfiguring the clock divider to the exact same value is observed on an i.MX8MN to often cause a longer than usual clock pause, probably because the divider restarts counting whenever the register is rewritten. This issue doesn't show up normally, because the clock framework will take care to not call set_rate when the clock rate is the same. However, when we reconfigure an upstream clock, the common code will call set_rate with the newly calculated rate on all children, e.g.: - sai5 is running normally and divides Audio PLL out by 16. - Audio PLL rate is increased by 32Hz (glitch-free kdiv change) - rates for children are recalculated and rates are set recursively - imx8m_clk_composite_divider_set_rate(sai5) is called with 32/16 = 2Hz more - imx8m_clk_composite_divider_set_rate computes same divider as before - divider register is written, so it restarts counting from zero and MCLK is briefly paused, so instead of e.g. 40ns, MCLK is low for 120ns. Some external clock consumers can be upset by such unexpected clock pauses, so let's make sure we only rewrite the divider value when the value to be written is actually different. Fixes: d3ff972 ("clk: imx: Add imx composite clock") Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Reviewed-by: Peng Fan <peng.fan@nxp.com> Link: https://lore.kernel.org/r/20230807082201.2332746-1-a.fatoum@pengutronix.de Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
1 parent 5dc1760 commit 4dd432d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/clk/imx/clk-composite-8m.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
9797
int prediv_value;
9898
int div_value;
9999
int ret;
100-
u32 val;
100+
u32 orig, val;
101101

102102
ret = imx8m_clk_composite_compute_dividers(rate, parent_rate,
103103
&prediv_value, &div_value);
@@ -106,13 +106,15 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
106106

107107
spin_lock_irqsave(divider->lock, flags);
108108

109-
val = readl(divider->reg);
110-
val &= ~((clk_div_mask(divider->width) << divider->shift) |
111-
(clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT));
109+
orig = readl(divider->reg);
110+
val = orig & ~((clk_div_mask(divider->width) << divider->shift) |
111+
(clk_div_mask(PCG_DIV_WIDTH) << PCG_DIV_SHIFT));
112112

113113
val |= (u32)(prediv_value - 1) << divider->shift;
114114
val |= (u32)(div_value - 1) << PCG_DIV_SHIFT;
115-
writel(val, divider->reg);
115+
116+
if (val != orig)
117+
writel(val, divider->reg);
116118

117119
spin_unlock_irqrestore(divider->lock, flags);
118120

0 commit comments

Comments
 (0)