Skip to contentSkip to conversation

clk: si5351: fix .round_rate for multisynth 6-7

PATCH Superseded Sergej Sawazki 2 participants 3 messages Apr 6, 2015 – Apr 7, 2015 Common clk

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: si5351: fix .round_rate for multisynth 6-7

The divider calculation for multisynth 6 and 7 differs from the calculation for multisynth 0-5.

For MS6 and MS7, set MSx_P1 directly, MSx_P1=divide value [AN619, p. 6].

Referenced document:
[AN619] Manually Generating an Si5351 Register Map, Rev. 0.4

---
 drivers/clk/clk-si5351.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/clk/clk-si5351.c +10 -2
index 44ea107..310078d 100644
@@ -552,7 +552,8 @@ static const struct clk_ops si5351_pll_ops = {
  * MSx_P2[19:0] = 128 * b - c * floor(128 * b/c) = (128*b) mod c
  * MSx_P3[19:0] = c
  *
- * MS[6,7] are integer (P1) divide only, P2 = 0, P3 = 0
+ * MS[6,7] are integer (P1) divide only, P1 = divide value,
+ * P2 and P3 are not applicable
  *
  * for 150MHz < fOUT <= 160MHz:
  *
@@ -718,11 +719,18 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
 	do_div(lltmp, a * c + b);
 	rate  = (unsigned long)lltmp;
 
-	/* calculate parameters */
+	/*
+	 * calculate parameters
+	 * for multisync6-7 set p1 directly, fOUT = fIN / p1
+	 */
 	if (divby4) {
 		hwdata->params.p3 = 1;
 		hwdata->params.p2 = 0;
 		hwdata->params.p1 = 0;
+	} else if (hwdata->num >= 6) {
+		hwdata->params.p3 = 1;
+		hwdata->params.p2 = 0;
+		hwdata->params.p1 = a;
 	} else {
 		hwdata->params.p3  = c;
 		hwdata->params.p2  = (128 * b) % c;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 10 lines · Sergej Sawazki

The divider calculation for multisynth 6 and 7 differs from the calculation for multisynth 0-5.

For MS6 and MS7, set MSx_P1 directly, MSx_P1=divide value [AN619, p. 6].

Referenced document:
[AN619] Manually Generating an Si5351 Register Map, Rev. 0.4

Sergej,

thanks for the patch, I do have some remarks though.

Quoted 19 lines
---
  drivers/clk/clk-si5351.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
drivers/clk/clk-si5351.c +2 -1
index 44ea107..310078d 100644
@@ -552,7 +552,8 @@ static const struct clk_ops si5351_pll_ops = {
   * MSx_P2[19:0] = 128 * b - c * floor(128 * b/c) = (128*b) mod c
   * MSx_P3[19:0] = c
   *
- * MS[6,7] are integer (P1) divide only, P2 = 0, P3 = 0
+ * MS[6,7] are integer (P1) divide only, P1 = divide value,
+ * P2 and P3 are not applicable
   *
   * for 150MHz < fOUT <= 160MHz:
   *

drivers/clk/clk-si5351.c static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate, · line 724

Quoted 7 lines
drivers/clk/clk-si5351.c +3 -1
@@ -718,11 +719,18 @@ static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate,
  	do_div(lltmp, a * c + b);
  	rate  = (unsigned long)lltmp;
 
-	/* calculate parameters */
+	/*
+	 * calculate parameters
+	 * for multisync6-7 set p1 directly, fOUT = fIN / p1

I'd say the comment about the differences of MS6,7 in the function's comment block is enough, no need to repeat it again here.

drivers/clk/clk-si5351.c static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate, · line 733

Quoted 9 lines
drivers/clk/clk-si5351.c +5 -0
+	 */
  	if (divby4) {
  		hwdata->params.p3 = 1;
  		hwdata->params.p2 = 0;
  		hwdata->params.p1 = 0;
+	} else if (hwdata->num >= 6) {
+		hwdata->params.p3 = 1;
+		hwdata->params.p2 = 0;
+		hwdata->params.p1 = a;

Hmm. Just overruling what will be written in the registers is definitely not enough. If you look at the first two lines of this hunk, you'll admit that the visible representation (rate) of the MS frequency isn't affected by your patch at all.

That basically means that real frequency and frequency in the kernel will differ, so we have to put this change in the param calculation above this hunk instead. The extra else-if-path here is ok though.

Sebastian

Quoted 3 lines
drivers/clk/clk-si5351.c +0 -0
  	} else {
  		hwdata->params.p3  = c;
  		hwdata->params.p2  = (128 * b) % c;
#2 lore raw

Sebastian,

thanks for your reply, please find my comments below:

Quoted 39 lines · Sebastian Hesselbarth
Quoted 10 lines · Sergej Sawazki

The divider calculation for multisynth 6 and 7 differs from the calculation for multisynth 0-5.

For MS6 and MS7, set MSx_P1 directly, MSx_P1=divide value [AN619, p. 6].

Referenced document:
[AN619] Manually Generating an Si5351 Register Map, Rev. 0.4

Sergej,

thanks for the patch, I do have some remarks though.

Quoted 23 lines
---
  drivers/clk/clk-si5351.c | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)
drivers/clk/clk-si5351.c +2 -1
index 44ea107..310078d 100644
@@ -552,7 +552,8 @@ static const struct clk_ops si5351_pll_ops = {
   * MSx_P2[19:0] = 128 * b - c * floor(128 * b/c) = (128*b) mod c
   * MSx_P3[19:0] = c
   *
- * MS[6,7] are integer (P1) divide only, P2 = 0, P3 = 0
+ * MS[6,7] are integer (P1) divide only, P1 = divide value,
+ * P2 and P3 are not applicable
   *
   * for 150MHz < fOUT <= 160MHz:
   *
@@ -718,11 +719,18 @@ static long si5351_msynth_round_rate(struct
 clk_hw *hw, unsigned long rate,
      do_div(lltmp, a * c + b);
      rate  = (unsigned long)lltmp;
 
Quoted 8 lines

drivers/clk/clk-si5351.c static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate, · line 724

Quoted 4 lines
drivers/clk/clk-si5351.c +3 -1
-    /* calculate parameters */
+    /*
+     * calculate parameters
+     * for multisync6-7 set p1 directly, fOUT = fIN / p1

I'd say the comment about the differences of MS6,7 in the function's comment block is enough, no need to repeat it again here.

I agree.

Quoted 10 lines

drivers/clk/clk-si5351.c static long si5351_msynth_round_rate(struct clk_hw *hw, unsigned long rate, · line 733

Quoted 9 lines
drivers/clk/clk-si5351.c +5 -0
+     */
      if (divby4) {
          hwdata->params.p3 = 1;
          hwdata->params.p2 = 0;
          hwdata->params.p1 = 0;
+    } else if (hwdata->num >= 6) {
+        hwdata->params.p3 = 1;
+        hwdata->params.p2 = 0;
+        hwdata->params.p1 = a;
Quoted 9 lines

Hmm. Just overruling what will be written in the registers is definitely not enough. If you look at the first two lines of this hunk, you'll admit that the visible representation (rate) of the MS frequency isn't affected by your patch at all.

That basically means that real frequency and frequency in the kernel will differ, so we have to put this change in the param calculation above this hunk instead. The extra else-if-path here is ok though.

You right, I will take a look at that and provide a patch v2.

Sergej