Skip to contentSkip to conversation

clk:aspeed:Fix AST2600 hpll calculate formula

PATCH In review Ryan Chen 3 participants 6 messages Sep 25, 2021 – Oct 29, 2021 Common clk

lore
Share & tools
lore

Ryan Chen

author
#0 lore raw

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

v2 -> v3: change else than if to directly else if
v1 -> v2: add Fixes commit hash

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 | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +27 -1
index 085d0a18b2b6..d30188355aaf 100644
@@ -169,6 +169,32 @@ 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 +742,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
author
#1 lore raw

Hello Joel,
Do you have time check this path?

Ryan Chen

Tel : 886-3-5751185 ext:8857

Quoted 79 lines

-----Original Message-----
From: Ryan Chen <[email protected]>
Sent: Saturday, September 25, 2021 10:24 AM
To: Ryan Chen <[email protected]>; Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Joel Stanley <[email protected]>; Andrew Jeffery <[email protected]>; [email protected]; [email protected]
Subject: [PATCHv3] clk:aspeed:Fix AST2600 hpll calculate formula

v2 -> v3: change else than if to directly else if
v1 -> v2: add Fixes commit hash

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 | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c index renamed from drivers/clk/clk-ast2600.c +0 -0

085d0a18b2b6..d30188355aaf 100644

drivers/clk/clk-ast2600.c +27 -1
@@ -169,6 +169,32 @@ 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 +742,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

#2 lore raw
In reply to Ryan Chen
Quoted 1 line · Ryan Chen

A few notes on process:

Quoted 2 lines

v2 -> v3: change else than if to directly else if
v1 -> v2: add Fixes commit hash

As this is normally information for reviewers to know what you've changed since the last version, we normally put this below the --- in the patch, which means it is not included in the commit message.

Also we put a space between the PATCH and v3 in the subject. If you use the tools, it will generate this for you:

git format-patch -v3 -1 --to=...

Quoted 4 lines

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]

I recommend adding to the commit message the text from my first review:

From the datasheet:

CPU frequency selection
000 1.2GHz
001 1.6GHz
010 1.2GHz
011 1.6GHz
100 800MHz
101 800MHz
110 800MHz
111 800MHz

So when the system is running at 800MHz or 1.6GHz, the value for the numerator (m) in SCU204 is incorrect, and must be overridden.

Quoted 27 lines

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 | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +4 -0
index 085d0a18b2b6..d30188355aaf 100644
@@ -169,6 +169,32 @@ 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);

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

Quoted 10 lines
drivers/clk/clk-ast2600.c +10 -0
+
+       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;
+

Add a comment:

/* If the CPU is running at 800Mhz. */

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

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

/* If the CPU is running at 1600Mhz. */

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

Quoted 2 lines
drivers/clk/clk-ast2600.c +2 -0
+               else if (hwstrap & BIT(8))
+                       m = 0xBF;

Or you could copy what I suggested in the first patch, and write it like this, which I think is clear:

ff (hwstrap & BIT(10)) {
    /* CPU running at 800MHz */
   m = 95;
} else if (hwstrap & BIT(10)) {
    /* CPU running at 1.6GHz */

m = 191;
} else {
/* CPU running at 1.2Ghz */
m = val & 0x1fff;
}

Please send a v4 with some more comments so we don't need to go back to the datasheet each time we read this code. Feel free to cut/paste my suggestion and use it as-is.

Cheers,

Joel

Quoted 23 lines
drivers/clk/clk-ast2600.c +9 -2
+
+               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 +742,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
#3 lore raw
Quoted 47 lines

-----Original Message-----
From: Joel Stanley <[email protected]>
Sent: Friday, October 8, 2021 12:06 PM
To: Ryan Chen <[email protected]>
Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Andrew Jeffery <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCHv3] clk:aspeed:Fix AST2600 hpll calculate formula

Quoted 1 line · Ryan Chen

A few notes on process:

Quoted 2 lines

v2 -> v3: change else than if to directly else if
v1 -> v2: add Fixes commit hash

As this is normally information for reviewers to know what you've changed since the last version, we normally put this below the --- in the patch, which means it is not included in the commit message.

Also we put a space between the PATCH and v3 in the subject. If you use the tools, it will generate this for you:

git format-patch -v3 -1 --to=...

Quoted 4 lines

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]

I recommend adding to the commit message the text from my first review:

From the datasheet:

CPU frequency selection
000 1.2GHz
001 1.6GHz
010 1.2GHz
011 1.6GHz
100 800MHz
101 800MHz
110 800MHz
111 800MHz

Quoted 2 lines

So when the system is running at 800MHz or 1.6GHz, the value for the numerator (m) in SCU204 is incorrect, and must be overridden.

Yes, SCU204 will be overridden by chip design.
Let me clarify m is in SCU200[12:0] not SCU204. SCU204 is NB not related with freq.

Quoted 62 lines
Quoted 27 lines

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 | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +3 -0
index 085d0a18b2b6..d30188355aaf 100644
@@ -169,6 +169,32 @@ 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);

drivers/clk/clk-ast2600.c static const struct clk_div_table · line 184

Quoted 10 lines
drivers/clk/clk-ast2600.c +10 -0
+
+       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;
+

Add a comment:

/* If the CPU is running at 800Mhz. */

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

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

/* If the CPU is running at 1600Mhz. */

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

Quoted 2 lines
drivers/clk/clk-ast2600.c +2 -0
+               else if (hwstrap & BIT(8))
+                       m = 0xBF;

Or you could copy what I suggested in the first patch, and write it like this, which I think is clear:

ff (hwstrap & BIT(10)) {
    /* CPU running at 800MHz */
   m = 95;
} else if (hwstrap & BIT(10)) {
    /* CPU running at 1.6GHz */
  m  = 191;
} else {
   /* CPU running at 1.2Ghz */
Quoted 2 lines

m = val & 0x1fff;
}

How about following

ff (hwstrap & BIT(10)) {
    /* CPU running at 800MHz */
    m = 0x5F;
} else if (hwstrap & BIT(10)) {
    /* CPU running at 1.6GHz */
    m = 0xBF;
} else {

/* CPU running at 1.2Ghz */
m = val & 0x1fff;
}

Quoted 5 lines

Please send a v4 with some more comments so we don't need to go back to the datasheet each time we read this code. Feel free to cut/paste my suggestion and use it as-is.

Thanks a lot.

Quoted 30 lines

Cheers,

Joel

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

Quoted 11 lines
drivers/clk/clk-ast2600.c +8 -0
+
+               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 +742,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);

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

Quoted 5 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);

Quoted 3 lines

--
2.17.1

#4 lore raw
Quoted 119 lines · Ryan Chen
Quoted 47 lines

-----Original Message-----
From: Joel Stanley <[email protected]>
Sent: Friday, October 8, 2021 12:06 PM
To: Ryan Chen <[email protected]>
Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Andrew Jeffery <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCHv3] clk:aspeed:Fix AST2600 hpll calculate formula

Quoted 1 line · Ryan Chen

A few notes on process:

Quoted 2 lines

v2 -> v3: change else than if to directly else if
v1 -> v2: add Fixes commit hash

As this is normally information for reviewers to know what you've changed since the last version, we normally put this below the --- in the patch, which means it is not included in the commit message.

Also we put a space between the PATCH and v3 in the subject. If you use the tools, it will generate this for you:

git format-patch -v3 -1 --to=...

Quoted 4 lines

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]

I recommend adding to the commit message the text from my first review:

From the datasheet:

CPU frequency selection
000 1.2GHz
001 1.6GHz
010 1.2GHz
011 1.6GHz
100 800MHz
101 800MHz
110 800MHz
111 800MHz

Quoted 2 lines

So when the system is running at 800MHz or 1.6GHz, the value for the numerator (m) in SCU204 is incorrect, and must be overridden.

Yes, SCU204 will be overridden by chip design.
Let me clarify m is in SCU200[12:0] not SCU204. SCU204 is NB not related with freq.

Quoted 62 lines
Quoted 27 lines

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 | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +3 -0
index 085d0a18b2b6..d30188355aaf 100644
@@ -169,6 +169,32 @@ 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);

drivers/clk/clk-ast2600.c static const struct clk_div_table · line 184

Quoted 10 lines
drivers/clk/clk-ast2600.c +10 -0
+
+       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;
+

Add a comment:

/* If the CPU is running at 800Mhz. */

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

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

/* If the CPU is running at 1600Mhz. */

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

Quoted 2 lines
drivers/clk/clk-ast2600.c +2 -0
+               else if (hwstrap & BIT(8))
+                       m = 0xBF;

Or you could copy what I suggested in the first patch, and write it like this, which I think is clear:

ff (hwstrap & BIT(10)) {
    /* CPU running at 800MHz */
   m = 95;
} else if (hwstrap & BIT(10)) {
    /* CPU running at 1.6GHz */
  m  = 191;
} else {
   /* CPU running at 1.2Ghz */
Quoted 2 lines

m = val & 0x1fff;
}

Quoted 6 lines

How about following

ff (hwstrap & BIT(10)) {
    /* CPU running at 800MHz */
    m = 0x5F;
} else if (hwstrap & BIT(10)) {

This is the same condition as the if above. That doesn't seem right.

Quoted 8 lines
    /* CPU running at 1.6GHz */
    m = 0xBF;
} else {

/* CPU running at 1.2Ghz */
m = val & 0x1fff;
}

Quoted 1 line
author
#5 lore raw
Quoted 131 lines

-----Original Message-----
From: Andrew Jeffery <[email protected]>
Sent: Friday, October 29, 2021 11:46 AM
To: Ryan Chen <[email protected]>; Joel Stanley <[email protected]>
Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCHv3] clk:aspeed:Fix AST2600 hpll calculate formula

Quoted 119 lines · Ryan Chen
Quoted 47 lines

-----Original Message-----
From: Joel Stanley <[email protected]>
Sent: Friday, October 8, 2021 12:06 PM
To: Ryan Chen <[email protected]>
Cc: Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Andrew Jeffery <[email protected]>; [email protected]; Linux Kernel Mailing List <[email protected]>
Subject: Re: [PATCHv3] clk:aspeed:Fix AST2600 hpll calculate formula

Quoted 1 line · Ryan Chen

A few notes on process:

Quoted 2 lines

v2 -> v3: change else than if to directly else if
v1 -> v2: add Fixes commit hash

As this is normally information for reviewers to know what you've changed since the last version, we normally put this below the --- in the patch, which means it is not included in the commit message.

Also we put a space between the PATCH and v3 in the subject. If you use the tools, it will generate this for you:

git format-patch -v3 -1 --to=...

Quoted 4 lines

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]

I recommend adding to the commit message the text from my first review:

From the datasheet:

CPU frequency selection
000 1.2GHz
001 1.6GHz
010 1.2GHz
011 1.6GHz
100 800MHz
101 800MHz
110 800MHz
111 800MHz

Quoted 2 lines

So when the system is running at 800MHz or 1.6GHz, the value for the numerator (m) in SCU204 is incorrect, and must be overridden.

Yes, SCU204 will be overridden by chip design.
Let me clarify m is in SCU200[12:0] not SCU204. SCU204 is NB not related with freq.

Quoted 64 lines
Quoted 27 lines

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 | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/clk/clk-ast2600.c +3 -0
index 085d0a18b2b6..d30188355aaf 100644
@@ -169,6 +169,32 @@ 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);

drivers/clk/clk-ast2600.c static const struct clk_div_table · line 184

Quoted 10 lines
drivers/clk/clk-ast2600.c +10 -0
+
+       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;
+

Add a comment:

/* If the CPU is running at 800Mhz. */

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

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

/* If the CPU is running at 1600Mhz. */

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

Quoted 2 lines
drivers/clk/clk-ast2600.c +2 -0
+               else if (hwstrap & BIT(8))
+                       m = 0xBF;

Or you could copy what I suggested in the first patch, and write it like this, which I think is clear:

ff (hwstrap & BIT(10)) {
    /* CPU running at 800MHz */
   m = 95;
} else if (hwstrap & BIT(10)) {
    /* CPU running at 1.6GHz */
  m  = 191;
} else {
   /* CPU running at 1.2Ghz */

m = val & 0x1fff;
}

Quoted 8 lines
Quoted 6 lines

How about following

ff (hwstrap & BIT(10)) {
    /* CPU running at 800MHz */
    m = 0x5F;
} else if (hwstrap & BIT(10)) {

This is the same condition as the if above. That doesn't seem right.

It would modify to following

	} else if (hwstrap & BIT(8)) {
Quoted 9 lines
Quoted 9 lines
    /* CPU running at 1.6GHz */
    m = 0xBF;
} else {

/* CPU running at 1.2Ghz */
m = val & 0x1fff;
}

Quoted 1 line