<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 30, 2022 at 6:37 PM Mark Brown <<a href="mailto:broonie@kernel.org">broonie@kernel.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Jun 30, 2022 at 01:39:11PM +0800, Shengjiu Wang wrote:<br>
<br>
> +static int fsl_micfil_reparent_rootclk(struct fsl_micfil *micfil, unsigned int sample_rate)<br>
> +{<br>
> + struct device *dev = &micfil->pdev->dev;<br>
> + u64 ratio = sample_rate;<br>
> + struct clk *clk;<br>
> + int ret;<br>
> +<br>
> + /* Reparent clock if required condition is true */<br>
> + if (!micfil->pll8k_clk || !micfil->pll11k_clk)<br>
> + return 0;<br>
> +<br>
> + ratio = do_div(ratio, 8000) ? CLK_11K_FREQ : CLK_8K_FREQ;<br>
> +<br>
> + /* Get root clock */<br>
> + clk = micfil->mclk;<br>
> + if (IS_ERR_OR_NULL(clk)) {<br>
> + dev_err(dev, "no mclk clock in devicetree\n");<br>
> + return PTR_ERR(clk);<br>
> + }<br>
> +<br>
> + /* Disable clock first, for it was enabled by pm_runtime */<br>
> + clk_disable_unprepare(clk);<br>
> + fsl_asoc_reparent_pll_clocks(dev, clk, micfil->pll8k_clk,<br>
> + micfil->pll11k_clk, ratio);<br>
> + ret = clk_prepare_enable(clk);<br>
> + if (ret)<br>
> + return ret;<br>
> +<br>
> + return 0;<br>
> +}<br>
<br>
Seems like more of this logic could be factored out into the reparent<br>
function if the target sample rate is passed in?<br></blockquote><div><br></div><div>Yes, let me update. </div><div><br></div><div>Best regards</div><div>Wang Shengjiu</div></div></div>