Skip to contentSkip to conversation

clk: mmp: bug fix for clk-frac

PATCH New Chao Xie 3 participants 6 messages Jan 23, 2014 – Mar 27, 2014 Common clk

lore
Share & tools
lore

Chao Xie

author
#0 lore raw

cover clk: mmp: bug fix for clk-frac

From: Chao Xie <[email protected]>

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(-)
Signature · 1 line
1.8.3.2
author
#1 lore raw

PATCH 1/3 clk: mmp: fix wrong mask when calculate denominator

From: Chao Xie <[email protected]>

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

---
 drivers/clk/mmp/clk-frac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/mmp/clk-frac.c +1 -1
index 80c1dd1..f6e7691 100644
@@ -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;
Signature · 1 line
1.8.3.2
author
#2 lore raw

PATCH 2/3 clk: mmp: fix the wrong calculation formula

In reply to Chao Xie

From: Chao Xie <[email protected]>

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.

---
 drivers/clk/mmp/clk-frac.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/clk/mmp/clk-frac.c +5 -5
index f6e7691..5863a37 100644
@@ -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;
 	}
Signature · 1 line
1.8.3.2
author
#3 lore raw

PATCH 3/3 clk: mmp: try to use closer one when do round rate

In reply to Chao Xie

From: Chao Xie <[email protected]>

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".

---
 drivers/clk/mmp/clk-frac.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/clk/mmp/clk-frac.c +7 -3
index 5863a37..23a56f5 100644
@@ -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,
Signature · 1 line
1.8.3.2
#4 lore raw

cover clk: mmp: bug fix for clk-frac

In reply to Chao Xie

hi, Mike
How about these fix patches?

Quoted 16 lines · Chao Xie

From: Chao Xie <[email protected]>

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

#5 lore raw

cover clk: mmp: bug fix for clk-frac

In reply to Chao Xie

Quoting Chao Xie (2014-01-22 18:47:39)

Quoted 4 lines

From: Chao Xie <[email protected]>

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

Quoted 12 lines

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(-)
Signature · 1 line
1.8.3.2