Skip to content

Commit 549f4ae

Browse files
claudiubezneageertu
authored andcommitted
clk: renesas: rzg2l: Wait for status bit of SD mux before continuing
The hardware user manual for RZ/G2L (r01uh0914ej0130-rzg2l-rzg2lc.pdf, chapter 7.4.7 Procedure for Switching Clocks by the Dynamic Switching Frequency Selectors) specifies that we need to check CPG_PL2SDHI_DSEL for SD clock switching status. Fixes: eaff336 ("clk: renesas: rzg2l: Add SDHI clk mux support") Signed-off-by: Claudiu Beznea <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Geert Uytterhoeven <[email protected]>
1 parent d5252d9 commit 549f4ae

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/clk/renesas/rzg2l-cpg.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ static int rzg2l_cpg_sd_clk_mux_set_parent(struct clk_hw *hw, u8 index)
188188
u32 off = GET_REG_OFFSET(hwdata->conf);
189189
u32 shift = GET_SHIFT(hwdata->conf);
190190
const u32 clk_src_266 = 2;
191-
u32 bitmask;
191+
u32 msk, val, bitmask;
192+
int ret;
192193

193194
/*
194195
* As per the HW manual, we should not directly switch from 533 MHz to
@@ -202,14 +203,10 @@ static int rzg2l_cpg_sd_clk_mux_set_parent(struct clk_hw *hw, u8 index)
202203
* the index to value mapping is done by adding 1 to the index.
203204
*/
204205
bitmask = (GENMASK(GET_WIDTH(hwdata->conf) - 1, 0) << shift) << 16;
206+
msk = off ? CPG_CLKSTATUS_SELSDHI1_STS : CPG_CLKSTATUS_SELSDHI0_STS;
205207
if (index != clk_src_266) {
206-
u32 msk, val;
207-
int ret;
208-
209208
writel(bitmask | ((clk_src_266 + 1) << shift), priv->base + off);
210209

211-
msk = off ? CPG_CLKSTATUS_SELSDHI1_STS : CPG_CLKSTATUS_SELSDHI0_STS;
212-
213210
ret = readl_poll_timeout(priv->base + CPG_CLKSTATUS, val,
214211
!(val & msk), 100,
215212
CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US);
@@ -221,7 +218,13 @@ static int rzg2l_cpg_sd_clk_mux_set_parent(struct clk_hw *hw, u8 index)
221218

222219
writel(bitmask | ((index + 1) << shift), priv->base + off);
223220

224-
return 0;
221+
ret = readl_poll_timeout(priv->base + CPG_CLKSTATUS, val,
222+
!(val & msk), 100,
223+
CPG_SDHI_CLK_SWITCH_STATUS_TIMEOUT_US);
224+
if (ret)
225+
dev_err(priv->dev, "failed to switch clk source\n");
226+
227+
return ret;
225228
}
226229

227230
static u8 rzg2l_cpg_sd_clk_mux_get_parent(struct clk_hw *hw)

0 commit comments

Comments
 (0)