All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] clk: mmp: bug fix for clk-frac
@ 2014-01-23  2:47 Chao Xie
  2014-01-23  2:47 ` [PATCH 1/3] clk: mmp: fix wrong mask when calculate denominator Chao Xie
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Chao Xie @ 2014-01-23  2:47 UTC (permalink / raw)
  To: linux-arm-kernel

From: Chao Xie <chao.xie@marvell.com>

When use the clk-frac type of mmp, some bugs are found.
The following 3 patches are bug fix for clk-frac

Chao Xie (3):
  clk: mmp: fix wrong mask when calculate denominator
  clk: mmp: fix the wrong calculation formula
  clk: mmp: try to use closer one when do round rate

 drivers/clk/mmp/clk-frac.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

-- 
1.8.3.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] clk: mmp: fix wrong mask when calculate denominator
  2014-01-23  2:47 [PATCH 0/3] clk: mmp: bug fix for clk-frac Chao Xie
@ 2014-01-23  2:47 ` Chao Xie
  2014-01-23  2:47 ` [PATCH 2/3] clk: mmp: fix the wrong calculation formula Chao Xie
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Chao Xie @ 2014-01-23  2:47 UTC (permalink / raw)
  To: linux-arm-kernel

From: Chao Xie <chao.xie@marvell.com>

The code has typo when calculate denominator. It should use
den_mask instead of num_mask.

Signed-off-by: Chao Xie <chao.xie@marvell.com>
---
 drivers/clk/mmp/clk-frac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/mmp/clk-frac.c b/drivers/clk/mmp/clk-frac.c
index 80c1dd1..f6e7691 100644
--- a/drivers/clk/mmp/clk-frac.c
+++ b/drivers/clk/mmp/clk-frac.c
@@ -64,7 +64,7 @@ static unsigned long clk_factor_recalc_rate(struct clk_hw *hw,
 	num = (val >> masks->num_shift) & masks->num_mask;
 
 	/* calculate denominator */
-	den = (val >> masks->den_shift) & masks->num_mask;
+	den = (val >> masks->den_shift) & masks->den_mask;
 
 	if (!den)
 		return 0;
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] clk: mmp: fix the wrong calculation formula
  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
  2014-01-23  2:47 ` [PATCH 3/3] clk: mmp: try to use closer one when do round rate Chao Xie
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Chao Xie @ 2014-01-23  2:47 UTC (permalink / raw)
  To: linux-arm-kernel

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] clk: mmp: try to use closer one when do round rate
  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 ` [PATCH 2/3] clk: mmp: fix the wrong calculation formula Chao Xie
@ 2014-01-23  2:47 ` 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
  4 siblings, 0 replies; 6+ messages in thread
From: Chao Xie @ 2014-01-23  2:47 UTC (permalink / raw)
  To: linux-arm-kernel

From: Chao Xie <chao.xie@marvell.com>

The orignal code will use the bigger rate between
"previous rate" and "current rate" when caculate the
rate.
In fact, hardware cares about the closest one.
So choose the closer rate between "previous rate" and
"current rate".

Signed-off-by: Chao Xie <chao.xie@marvell.com>
---
 drivers/clk/mmp/clk-frac.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/mmp/clk-frac.c b/drivers/clk/mmp/clk-frac.c
index 5863a37..23a56f5 100644
--- a/drivers/clk/mmp/clk-frac.c
+++ b/drivers/clk/mmp/clk-frac.c
@@ -45,10 +45,14 @@ static long clk_factor_round_rate(struct clk_hw *hw, unsigned long drate,
 		if (rate > drate)
 			break;
 	}
-	if ((i == 0) || (i == factor->ftbl_cnt))
+	if ((i == 0) || (i == factor->ftbl_cnt)) {
 		return rate;
-	else
-		return prev_rate;
+	} else {
+		if ((drate - prev_rate) > (rate - drate))
+			return rate;
+		else
+			return prev_rate;
+	}
 }
 
 static unsigned long clk_factor_recalc_rate(struct clk_hw *hw,
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 0/3] clk: mmp: bug fix for clk-frac
  2014-01-23  2:47 [PATCH 0/3] clk: mmp: bug fix for clk-frac Chao Xie
                   ` (2 preceding siblings ...)
  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 ` Chao Xie
  2014-03-27  4:37 ` Mike Turquette
  4 siblings, 0 replies; 6+ messages in thread
From: Chao Xie @ 2014-02-13  6:41 UTC (permalink / raw)
  To: linux-arm-kernel

hi, Mike
How about these fix patches?

On Thu, Jan 23, 2014 at 10:47 AM, Chao Xie <chao.xie@marvell.com> wrote:
> From: Chao Xie <chao.xie@marvell.com>
>
> When use the clk-frac type of mmp, some bugs are found.
> The following 3 patches are bug fix for clk-frac
>
> Chao Xie (3):
>   clk: mmp: fix wrong mask when calculate denominator
>   clk: mmp: fix the wrong calculation formula
>   clk: mmp: try to use closer one when do round rate
>
>  drivers/clk/mmp/clk-frac.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
>
> --
> 1.8.3.2
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 0/3] clk: mmp: bug fix for clk-frac
  2014-01-23  2:47 [PATCH 0/3] clk: mmp: bug fix for clk-frac Chao Xie
                   ` (3 preceding siblings ...)
  2014-02-13  6:41 ` [PATCH 0/3] clk: mmp: bug fix for clk-frac Chao Xie
@ 2014-03-27  4:37 ` Mike Turquette
  4 siblings, 0 replies; 6+ messages in thread
From: Mike Turquette @ 2014-03-27  4:37 UTC (permalink / raw)
  To: linux-arm-kernel

Quoting Chao Xie (2014-01-22 18:47:39)
> From: Chao Xie <chao.xie@marvell.com>
> 
> When use the clk-frac type of mmp, some bugs are found.
> The following 3 patches are bug fix for clk-frac

Taken into clk-next!

Regards,
Mike

> 
> Chao Xie (3):
>   clk: mmp: fix wrong mask when calculate denominator
>   clk: mmp: fix the wrong calculation formula
>   clk: mmp: try to use closer one when do round rate
> 
>  drivers/clk/mmp/clk-frac.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
> 
> -- 
> 1.8.3.2
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-03-27  4:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/3] clk: mmp: fix the wrong calculation formula Chao Xie
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.