From: chao.xie@marvell.com (Chao Xie)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3] clk: mmp: fix the wrong calculation formula
Date: Thu, 23 Jan 2014 10:47:41 +0800 [thread overview]
Message-ID: <1390445262-27486-3-git-send-email-chao.xie@marvell.com> (raw)
In-Reply-To: <1390445262-27486-1-git-send-email-chao.xie@marvell.com>
From: Chao Xie <chao.xie@marvell.com>
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: Chao Xie <chao.xie@marvell.com>
---
drivers/clk/mmp/clk-frac.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/mmp/clk-frac.c b/drivers/clk/mmp/clk-frac.c
index f6e7691..5863a37 100644
--- a/drivers/clk/mmp/clk-frac.c
+++ b/drivers/clk/mmp/clk-frac.c
@@ -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;
}
--
1.8.3.2
next prev parent reply other threads:[~2014-01-23 2:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-23 2:47 [PATCH 0/3] clk: mmp: bug fix for clk-frac Chao Xie
2014-01-23 2:47 ` [PATCH 1/3] clk: mmp: fix wrong mask when calculate denominator Chao Xie
2014-01-23 2:47 ` Chao Xie [this message]
2014-01-23 2:47 ` [PATCH 3/3] clk: mmp: try to use closer one when do round rate Chao Xie
2014-02-13 6:41 ` [PATCH 0/3] clk: mmp: bug fix for clk-frac Chao Xie
2014-03-27 4:37 ` Mike Turquette
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1390445262-27486-3-git-send-email-chao.xie@marvell.com \
--to=chao.xie@marvell.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).