diff --git a/sys/arm64/freescale/imx/clk/imx_clk_composite.c b/sys/arm64/freescale/imx/clk/imx_clk_composite.c --- a/sys/arm64/freescale/imx/clk/imx_clk_composite.c +++ b/sys/arm64/freescale/imx/clk/imx_clk_composite.c @@ -163,7 +163,7 @@ best_diff = INT64_MAX; for (prediv = 1; prediv <= TARGET_ROOT_PRE_PODF_MAX + 1; prediv++) { for (postdiv = 1; postdiv <= TARGET_ROOT_POST_PODF_MAX + 1; postdiv++) { - cur= fparent / prediv / postdiv; + cur = fparent / prediv / postdiv; diff = (int64_t)ftarget - (int64_t)cur; if (flags & CLK_SET_ROUND_DOWN) { if (diff >= 0 && diff < best_diff) { @@ -216,7 +216,7 @@ dprintf("Finding best parent/div for target freq of %ju\n", *fout); p_names = clknode_get_parent_names(clk); - best_diff = 0; + best_diff = INT64_MAX; best_parent = -1; for (p_idx = 0; p_idx != clknode_get_parents_num(clk); p_idx++) { @@ -225,7 +225,7 @@ dprintf("Testing with parent %s (%d) at freq %ju\n", clknode_get_name(p_clk), p_idx, fparent); - if (!imx_clk_composite_find_best(fparent, *fout, &pre_div, &post_div, sc->flags)) + if (imx_clk_composite_find_best(fparent, *fout, &pre_div, &post_div, sc->flags)) continue; cur = fparent / pre_div / post_div; diff = abs((int64_t)*fout - (int64_t)cur); @@ -265,8 +265,9 @@ DEVICE_LOCK(clk); READ4(clk, sc->offset, &val); val &= ~(TARGET_ROOT_PRE_PODF_MASK | TARGET_ROOT_POST_PODF_MASK); - val |= TARGET_ROOT_PRE_PODF(pre_div); - val |= TARGET_ROOT_POST_PODF(post_div); + val |= TARGET_ROOT_PRE_PODF(best_pre_div); + val |= TARGET_ROOT_POST_PODF(best_post_div); + WRITE4(clk, sc->offset, val); DEVICE_UNLOCK(clk); *fout = best;