Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c45693a6 authored by Chao Xie's avatar Chao Xie Committed by Mike Turquette
Browse files

clk: mmp: fix the wrong calculation formula



The formula is numerator/denominator = Fin / (Fout * factor)
So
Fout = Fin * denominator / (numerator * factor).
Current clk_factor_round_rate and clk_factor_recalc_rate use
wrong formula. This patch will fix them.

Signed-off-by: default avatarChao Xie <chao.xie@marvell.com>
Signed-off-by: default avatarMike Turquette <mturquette@linaro.org>
parent 7433ab43
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -40,12 +40,12 @@ static long clk_factor_round_rate(struct clk_hw *hw, unsigned long drate,

	for (i = 0; i < factor->ftbl_cnt; i++) {
		prev_rate = rate;
		rate = (((*prate / 10000) * factor->ftbl[i].num) /
			(factor->ftbl[i].den * factor->masks->factor)) * 10000;
		rate = (((*prate / 10000) * factor->ftbl[i].den) /
			(factor->ftbl[i].num * factor->masks->factor)) * 10000;
		if (rate > drate)
			break;
	}
	if (i == 0)
	if ((i == 0) || (i == factor->ftbl_cnt))
		return rate;
	else
		return prev_rate;
@@ -85,8 +85,8 @@ static int clk_factor_set_rate(struct clk_hw *hw, unsigned long drate,

	for (i = 0; i < factor->ftbl_cnt; i++) {
		prev_rate = rate;
		rate = (((prate / 10000) * factor->ftbl[i].num) /
			(factor->ftbl[i].den * factor->masks->factor)) * 10000;
		rate = (((prate / 10000) * factor->ftbl[i].den) /
			(factor->ftbl[i].num * factor->masks->factor)) * 10000;
		if (rate > drate)
			break;
	}