Skip to content

Commit

Permalink
clk: renesas: rcar-gen3: Increase Z clock accuracy
Browse files Browse the repository at this point in the history
Improve accuracy in the .determine_rate() callback for Z and Z2 clocks
by using rounded divisions.  This is similar to the calculation of rates
and multipliers in the .recalc_rate() resp. set_rate() callbacks.

Sample impact for a few requested clock rates:
  - R-Car H3:
      - Z 500 MHz:	468 MHz => 515 MHz
      - Z2 1000 MHz:	973 MHz => 1011 MHz
  - R-Car M3-W:
      - Z 500 MHz:	422 MHz => 516 MHz
      - Z2 800 MHz:	750 MHz => 788 MHz

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Stephen Boyd <sboyd@kernel.org>
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20210326120100.1577596-6-geert+renesas@glider.be
  • Loading branch information
Geert Uytterhoeven committed May 11, 2021
1 parent 67a1b9b commit 5008604
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/clk/renesas/rcar-gen3-cpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ static int cpg_z_clk_determine_rate(struct clk_hw *hw,
if (max_mult < min_mult)
return -EINVAL;

mult = div64_ul(req->rate * 32ULL, prate);
mult = DIV_ROUND_CLOSEST_ULL(req->rate * 32ULL, prate);
mult = clamp(mult, min_mult, max_mult);

req->rate = div_u64((u64)prate * mult, 32);
req->rate = DIV_ROUND_CLOSEST_ULL((u64)prate * mult, 32);
return 0;
}

Expand Down

0 comments on commit 5008604

Please sign in to comment.