Skip to contentSkip to conversation

clk:aspeed:Fix AST2600 hpll calculate formula

PATCH Superseded Ryan Chen 4 participants 7 messages Sep 8, 2021 – Sep 15, 2021 Common clk

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ryan Chen

author
#0 lore raw

PATCH v2 1/1 clk:aspeed:Fix AST2600 hpll calculate formula

AST2600 HPLL calculate formula [SCU200]
HPLL Numerator(M): have fixed value depend on SCU strap. M = SCU500[10] ? 0x5F : SCU500[8] ? 0xBF : SCU200[12:0]

if SCU500[10] = 1, M=0x5F.
else if SCU500[10]=0 & SCU500[8]=1, M=0xBF. others (SCU510[10]=0 and SCU510[8]=0)
depend on SCU200[12:0] (default 0x8F) register setting.

HPLL Denumerator (N) = SCU200[18:13] (default 0x2)
HPLL Divider (P) = SCU200[22:19] (default 0x0)

Fixes d3d04f6c330a ("clk: Add support for AST2600 SoC")
---
 drivers/clk/clk-ast2600.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +28 -1
index 085d0a18b2b6..5d8c46bcf237 100644
@@ -169,6 +169,33 @@ static const struct clk_div_table ast2600_div_table[] = {
 };
 
 /* For hpll/dpll/epll/mpll */
+static struct clk_hw *ast2600_calc_hpll(const char *name, u32 val)
+{
+	unsigned int mult, div;
+	u32 hwstrap = readl(scu_g6_base + ASPEED_G6_STRAP1);
+
+	if (val & BIT(24)) {
+		/* Pass through mode */
+		mult = div = 1;
+	} else {
+		/* F = 25Mhz * [(M + 2) / (n + 1)] / (p + 1) */
+		u32 m = val  & 0x1fff;
+		u32 n = (val >> 13) & 0x3f;
+		u32 p = (val >> 19) & 0xf;
+
+		if (hwstrap & BIT(10))
+			m = 0x5F;
+		else {
+			if (hwstrap & BIT(8))
+				m = 0xBF;
+		}
+		mult = (m + 1) / (n + 1);
+		div = (p + 1);
+	}
+	return clk_hw_register_fixed_factor(NULL, name, "clkin", 0,
+			mult, div);
+};
+
 static struct clk_hw *ast2600_calc_pll(const char *name, u32 val)
 {
 	unsigned int mult, div;
@@ -716,7 +743,7 @@ static void __init aspeed_g6_cc(struct regmap *map)
 	 * and we assume that it is enabled
 	 */
 	regmap_read(map, ASPEED_HPLL_PARAM, &val);
-	aspeed_g6_clk_data->hws[ASPEED_CLK_HPLL] = ast2600_calc_pll("hpll", val);
+	aspeed_g6_clk_data->hws[ASPEED_CLK_HPLL] = ast2600_calc_hpll("hpll", val);
 
 	regmap_read(map, ASPEED_MPLL_PARAM, &val);
 	aspeed_g6_clk_data->hws[ASPEED_CLK_MPLL] = ast2600_calc_pll("mpll", val);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 36 lines · Ryan Chen

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

AST2600 HPLL calculate formula [SCU200]
HPLL Numerator(M): have fixed value depend on SCU strap. M = SCU500[10] ? 0x5F : SCU500[8] ? 0xBF : SCU200[12:0]

if SCU500[10] = 1, M=0x5F.
else if SCU500[10]=0 & SCU500[8]=1, M=0xBF. others (SCU510[10]=0 and SCU510[8]=0)
depend on SCU200[12:0] (default 0x8F) register setting.

HPLL Denumerator (N) = SCU200[18:13] (default 0x2)
HPLL Divider (P) = SCU200[22:19] (default 0x0)

Fixes d3d04f6c330a ("clk: Add support for AST2600 SoC")
---
 drivers/clk/clk-ast2600.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +8 -0
index 085d0a18b2b6..5d8c46bcf237 100644
@@ -169,6 +169,33 @@ static const struct clk_div_table ast2600_div_table[] = {
 };
 
 /* For hpll/dpll/epll/mpll */
+static struct clk_hw *ast2600_calc_hpll(const char *name, u32 val)
+{
+       unsigned int mult, div;
+       u32 hwstrap = readl(scu_g6_base + ASPEED_G6_STRAP1);
+
+       if (val & BIT(24)) {
+               /* Pass through mode */
+               mult = div = 1;

drivers/clk/clk-ast2600.c static const struct clk_div_table ast2600_div_table[] = { · line 189

Quoted 10 lines
drivers/clk/clk-ast2600.c +10 -0
+       } else {
+               /* F = 25Mhz * [(M + 2) / (n + 1)] / (p + 1) */
+               u32 m = val  & 0x1fff;
+               u32 n = (val >> 13) & 0x3f;
+               u32 p = (val >> 19) & 0xf;
+
+               if (hwstrap & BIT(10))
+                       m = 0x5F;
+               else {
+                       if (hwstrap & BIT(8))

You may write it directly:
else if (hwstrap & BIT(8))

Quoted 24 lines
drivers/clk/clk-ast2600.c +10 -2
+                               m = 0xBF;
+               }
+               mult = (m + 1) / (n + 1);
+               div = (p + 1);
+       }
+       return clk_hw_register_fixed_factor(NULL, name, "clkin", 0,
+                       mult, div);
+};
+
 static struct clk_hw *ast2600_calc_pll(const char *name, u32 val)
 {
        unsigned int mult, div;
@@ -716,7 +743,7 @@ static void __init aspeed_g6_cc(struct regmap *map)
         * and we assume that it is enabled
         */
        regmap_read(map, ASPEED_HPLL_PARAM, &val);
-       aspeed_g6_clk_data->hws[ASPEED_CLK_HPLL] = ast2600_calc_pll("hpll", val);
+       aspeed_g6_clk_data->hws[ASPEED_CLK_HPLL] = ast2600_calc_hpll("hpll", val);
 
        regmap_read(map, ASPEED_MPLL_PARAM, &val);
        aspeed_g6_clk_data->hws[ASPEED_CLK_MPLL] = ast2600_calc_pll("mpll", val);
--

2.17.1

author
#2 lore raw
Quoted 50 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Monday, September 13, 2021 1:26 PM
To: Ryan Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCHv2] clk:aspeed:Fix AST2600 hpll calculate formula

Quoted 41 lines · Ryan Chen

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

AST2600 HPLL calculate formula [SCU200] HPLL Numerator(M): have fixed value depend on SCU strap.
M = SCU500[10] ? 0x5F : SCU500[8] ? 0xBF : SCU200[12:0]

if SCU500[10] = 1, M=0x5F.
else if SCU500[10]=0 & SCU500[8]=1, M=0xBF. others (SCU510[10]=0 and SCU510[8]=0)
depend on SCU200[12:0] (default 0x8F) register setting.

HPLL Denumerator (N) = SCU200[18:13] (default 0x2)
HPLL Divider (P) = SCU200[22:19] (default 0x0)

Fixes d3d04f6c330a ("clk: Add support for AST2600 SoC")
---
 drivers/clk/clk-ast2600.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +12 -0
index 085d0a18b2b6..5d8c46bcf237 100644
@@ -169,6 +169,33 @@ static const struct clk_div_table
 ast2600_div_table[] = {  };
 
 /* For hpll/dpll/epll/mpll */
+static struct clk_hw *ast2600_calc_hpll(const char *name, u32 val) {
+       unsigned int mult, div;
+       u32 hwstrap = readl(scu_g6_base + ASPEED_G6_STRAP1);
+
+       if (val & BIT(24)) {
+               /* Pass through mode */
+               mult = div = 1;
+       } else {
+               /* F = 25Mhz * [(M + 2) / (n + 1)] / (p + 1) */
+               u32 m = val  & 0x1fff;
+               u32 n = (val >> 13) & 0x3f;
+               u32 p = (val >> 19) & 0xf;
Quoted 9 lines

drivers/clk/clk-ast2600.c static const struct clk_div_table ast2600_div_table[] = { · line 189

Quoted 5 lines
drivers/clk/clk-ast2600.c +5 -0
+
+               if (hwstrap & BIT(10))
+                       m = 0x5F;
+               else {
+                       if (hwstrap & BIT(8))

You may write it directly:
else if (hwstrap & BIT(8))

Hello,

	Like I commit message M = SCU500[10] ? 0x5F : SCU500[8] ? 0xBF : SCU200[12:0]
	it need keep from register read, if BIT(8)/BIT(10) not 1.
Quoted 27 lines

drivers/clk/clk-ast2600.c static void __init aspeed_g6_cc(struct regmap

Quoted 12 lines
drivers/clk/clk-ast2600.c +9 -0
+                               m = 0xBF;
+               }
+               mult = (m + 1) / (n + 1);
+               div = (p + 1);
+       }
+       return clk_hw_register_fixed_factor(NULL, name, "clkin", 0,
+                       mult, div);
+};
+
 static struct clk_hw *ast2600_calc_pll(const char *name, u32 val)  {
        unsigned int mult, div;
@@ -716,7 +743,7 @@ static void __init aspeed_g6_cc(struct regmap

*map)

drivers/clk/clk-ast2600.c static void __init aspeed_g6_cc(struct regmap *map)

Quoted 4 lines
drivers/clk/clk-ast2600.c +0 -1
         * and we assume that it is enabled
         */
        regmap_read(map, ASPEED_HPLL_PARAM, &val);
-       aspeed_g6_clk_data->hws[ASPEED_CLK_HPLL] =

ast2600_calc_pll("hpll", val);

Quoted 9 lines
drivers/clk/clk-ast2600.c +2 -0
+       aspeed_g6_clk_data->hws[ASPEED_CLK_HPLL] =
+ ast2600_calc_hpll("hpll", val);
 
        regmap_read(map, ASPEED_MPLL_PARAM, &val);
        aspeed_g6_clk_data->hws[ASPEED_CLK_MPLL] =

ast2600_calc_pll("mpll", val);
--
2.17.1

maintainer
#3 lore raw

Quoting Ryan Chen (2021-09-12 22:31:46)

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/clk/clk-ast2600.c +4 -0
+               if (hwstrap & BIT(10))
+                       m = 0x5F;
+               else {
+                       if (hwstrap & BIT(8))
Quoted 7 lines
Quoted 3 lines

You may write it directly:
else if (hwstrap & BIT(8))

Hello,
Like I commit message M = SCU500[10] ? 0x5F : SCU500[8] ? 0xBF : SCU200[12:0] it need keep from register read, if BIT(8)/BIT(10) not 1.

I don't get it. The review comment was that the else { if (...) can be collapsed into an else if (..) What does commit message have to do with it?

author
#4 lore raw
Quoted 18 lines

-----Original Message-----
From: Stephen Boyd <[email protected]>
Sent: Wednesday, September 15, 2021 9:17 AM
To: [email protected]; Ryan Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCHv2] clk:aspeed:Fix AST2600 hpll calculate formula

Quoting Ryan Chen (2021-09-12 22:31:46)

Quoted 8 lines
Quoted 8 lines

drivers/clk/clk-ast2600.c static const struct clk_div_table ast2600_div_table[] = { · line 189

Quoted 4 lines
drivers/clk/clk-ast2600.c +4 -0
+               if (hwstrap & BIT(10))
+                       m = 0x5F;
+               else {
+                       if (hwstrap & BIT(8))

You may write it directly:
else if (hwstrap & BIT(8))

Quoted 8 lines
Quoted 2 lines

Hello,

        Like I commit message M = SCU500[10] ? 0x5F : SCU500[8] ? 0xBF :

SCU200[12:0]

Quoted 2 lines

it need keep from register read, if BIT(8)/BIT(10) not 1.

I don't get it. The review comment was that the else { if (...) can be collapsed into an else if (..) What does commit message have to do with it?

Sorry for confuse.
Or do you mean like following modification?

               if (hwstrap & BIT(10))
                       m = 0x5F;
               else if (hwstrap & BIT(8))
                       m = 0xBF;
#5 lore raw
Quoted 27 lines · Ryan Chen
Quoted 19 lines

-----Original Message-----
From: Stephen Boyd <[email protected]>
Sent: Wednesday, September 15, 2021 9:17 AM
To: [email protected]; Ryan Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCHv2] clk:aspeed:Fix AST2600 hpll calculate formula

Quoting Ryan Chen (2021-09-12 22:31:46)

Quoted 8 lines
Quoted 8 lines

drivers/clk/clk-ast2600.c static const struct clk_div_table ast2600_div_table[] = { · line 189

Quoted 4 lines
drivers/clk/clk-ast2600.c +4 -0
+               if (hwstrap & BIT(10))
+                       m = 0x5F;
+               else {
+                       if (hwstrap & BIT(8))

You may write it directly:
else if (hwstrap & BIT(8))

Quoted 8 lines
Quoted 2 lines

Hello,

        Like I commit message M = SCU500[10] ? 0x5F : SCU500[8] ? 0xBF :

SCU200[12:0]

Quoted 2 lines

it need keep from register read, if BIT(8)/BIT(10) not 1.

I don't get it. The review comment was that the else { if (...) can be collapsed into an else if (..) What does commit message have to do with it?

Quoted 7 lines

Sorry for confuse.
Or do you mean like following modification?

               if (hwstrap & BIT(10))
                       m = 0x5F;
               else if (hwstrap & BIT(8))
                       m = 0xBF;

Yep!

Take a look at my review of v1. I wrote it out there.

author
#6 lore raw
Quoted 43 lines

-----Original Message-----
From: Joel Stanley <[email protected]>
Sent: Wednesday, September 15, 2021 11:07 AM
To: Ryan Chen <[email protected]>
Cc: Stephen Boyd <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCHv2] clk:aspeed:Fix AST2600 hpll calculate formula

Quoted 16 lines · Ryan Chen
Quoted 16 lines

-----Original Message-----
From: Stephen Boyd <[email protected]>
Sent: Wednesday, September 15, 2021 9:17 AM
To: [email protected]; Ryan Chen <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCHv2] clk:aspeed:Fix AST2600 hpll calculate formula

Quoting Ryan Chen (2021-09-12 22:31:46)

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
drivers/clk/clk-ast2600.c +4 -0
+               if (hwstrap & BIT(10))
+                       m = 0x5F;
+               else {
+                       if (hwstrap & BIT(8))
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

You may write it directly:
else if (hwstrap & BIT(8))

Hello,

        Like I commit message M = SCU500[10] ? 0x5F : SCU500[8] ?

0xBF :

Quoted 6 lines
Quoted 6 lines

SCU200[12:0]

Quoted 2 lines

it need keep from register read, if BIT(8)/BIT(10) not 1.

I don't get it. The review comment was that the else { if (...) can be collapsed into an else if (..) What does commit message have to do with

it?

Quoted 3 lines

Sorry for confuse.
Or do you mean like following modification?

Quoted 8 lines
Quoted 4 lines
               if (hwstrap & BIT(10))
                       m = 0x5F;
               else if (hwstrap & BIT(8))
                       m = 0xBF;

Yep!

Take a look at my review of v1. I wrote it out there.

Got it will modify by this.