linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] cpufreq: sun50i: Fix CPU speed bin detection
@ 2019-11-01 16:41 Ondrej Jirman
  2019-11-03 15:59 ` Maxime Ripard
  0 siblings, 1 reply; 3+ messages in thread
From: Ondrej Jirman @ 2019-11-01 16:41 UTC (permalink / raw)
  To: linux-sunxi
  Cc: Ondrej Jirman, Yangtao Li, Rafael J. Wysocki, Viresh Kumar,
	Maxime Ripard, Chen-Yu Tsai, open list:ALLWINNER CPUFREQ DRIVER,
	moderated list:ARM/Allwinner sunXi SoC support, open list

I have observed failures to boot on Orange Pi 3, because this driver
determined that my SoC is from the normal bin, but my SoC only works
reliably with the OPP values for the slowest bin.

By querying H6 owners, it was found that e-fuse values found in the wild
are in the range of 1-3, value of 7 was not reported, yet. From this and
from unused defines in BSP code, it can be assumed that meaning of efuse
values on H6 actually is:

- 1 = slowest bin
- 2 = normal bin
- 3 = fastest bin

Vendor code actually treats 0 and 2 as invalid efuse values, but later
treats all invalid values as a normal bin. This looks like a mistake in
bin detection code, that was plastered over by a hack in cpufreq code,
so let's not repeat it here. It probably only works because there are no
SoCs in the wild with efuse value of 0, and fast bin SoCs are made to
use normal bin OPP tables, which is also safe.

Let's play it safe and interpret 0 as the slowest bin, but fix detection
of other bins to match this research. More research will be done before
actual OPP tables are merged.

Fixes: f328584f7bff ("cpufreq: Add sun50i nvmem based CPU scaling driver")
Signed-off-by: Ondrej Jirman <megous@megous.com>
---

 See also https://lkml.org/lkml/2019/11/1/496

 drivers/cpufreq/sun50i-cpufreq-nvmem.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
index eca32e443716..9907a165135b 100644
--- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
+++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
@@ -25,7 +25,7 @@
 static struct platform_device *cpufreq_dt_pdev, *sun50i_cpufreq_pdev;
 
 /**
- * sun50i_cpufreq_get_efuse() - Parse and return efuse value present on SoC
+ * sun50i_cpufreq_get_efuse() - Determine speed grade from efuse value
  * @versions: Set to the value parsed from efuse
  *
  * Returns 0 if success.
@@ -69,21 +69,16 @@ static int sun50i_cpufreq_get_efuse(u32 *versions)
 		return PTR_ERR(speedbin);
 
 	efuse_value = (*speedbin >> NVMEM_SHIFT) & NVMEM_MASK;
-	switch (efuse_value) {
-	case 0b0001:
-		*versions = 1;
-		break;
-	case 0b0011:
-		*versions = 2;
-		break;
-	default:
-		/*
-		 * For other situations, we treat it as bin0.
-		 * This vf table can be run for any good cpu.
-		 */
+
+	/*
+	 * We treat unexpected efuse values as if the SoC was from
+	 * the slowest bin. Expected efuse values are 1-3, slowest
+	 * to fastest.
+	 */
+	if (efuse_value >= 1 && efuse_value <= 3)
+		*versions = efuse_value - 1;
+	else
 		*versions = 0;
-		break;
-	}
 
 	kfree(speedbin);
 	return 0;
-- 
2.23.0


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

* Re: [PATCH v2] cpufreq: sun50i: Fix CPU speed bin detection
  2019-11-01 16:41 [PATCH v2] cpufreq: sun50i: Fix CPU speed bin detection Ondrej Jirman
@ 2019-11-03 15:59 ` Maxime Ripard
  2019-11-05  9:37   ` Viresh Kumar
  0 siblings, 1 reply; 3+ messages in thread
From: Maxime Ripard @ 2019-11-03 15:59 UTC (permalink / raw)
  To: Ondrej Jirman
  Cc: linux-sunxi, Yangtao Li, Rafael J. Wysocki, Viresh Kumar,
	Chen-Yu Tsai, open list:ALLWINNER CPUFREQ DRIVER,
	moderated list:ARM/Allwinner sunXi SoC support, open list

[-- Attachment #1: Type: text/plain, Size: 1358 bytes --]

On Fri, Nov 01, 2019 at 05:41:51PM +0100, Ondrej Jirman wrote:
> I have observed failures to boot on Orange Pi 3, because this driver
> determined that my SoC is from the normal bin, but my SoC only works
> reliably with the OPP values for the slowest bin.
>
> By querying H6 owners, it was found that e-fuse values found in the wild
> are in the range of 1-3, value of 7 was not reported, yet. From this and
> from unused defines in BSP code, it can be assumed that meaning of efuse
> values on H6 actually is:
>
> - 1 = slowest bin
> - 2 = normal bin
> - 3 = fastest bin
>
> Vendor code actually treats 0 and 2 as invalid efuse values, but later
> treats all invalid values as a normal bin. This looks like a mistake in
> bin detection code, that was plastered over by a hack in cpufreq code,
> so let's not repeat it here. It probably only works because there are no
> SoCs in the wild with efuse value of 0, and fast bin SoCs are made to
> use normal bin OPP tables, which is also safe.
>
> Let's play it safe and interpret 0 as the slowest bin, but fix detection
> of other bins to match this research. More research will be done before
> actual OPP tables are merged.
>
> Fixes: f328584f7bff ("cpufreq: Add sun50i nvmem based CPU scaling driver")
> Signed-off-by: Ondrej Jirman <megous@megous.com>

Acked-by: Maxime Ripard <mripard@kernel.org>

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v2] cpufreq: sun50i: Fix CPU speed bin detection
  2019-11-03 15:59 ` Maxime Ripard
@ 2019-11-05  9:37   ` Viresh Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: Viresh Kumar @ 2019-11-05  9:37 UTC (permalink / raw)
  To: Maxime Ripard
  Cc: Ondrej Jirman, linux-sunxi, Yangtao Li, Rafael J. Wysocki,
	Chen-Yu Tsai, open list:ALLWINNER CPUFREQ DRIVER,
	moderated list:ARM/Allwinner sunXi SoC support, open list

On 03-11-19, 16:59, Maxime Ripard wrote:
> On Fri, Nov 01, 2019 at 05:41:51PM +0100, Ondrej Jirman wrote:
> > I have observed failures to boot on Orange Pi 3, because this driver
> > determined that my SoC is from the normal bin, but my SoC only works
> > reliably with the OPP values for the slowest bin.
> >
> > By querying H6 owners, it was found that e-fuse values found in the wild
> > are in the range of 1-3, value of 7 was not reported, yet. From this and
> > from unused defines in BSP code, it can be assumed that meaning of efuse
> > values on H6 actually is:
> >
> > - 1 = slowest bin
> > - 2 = normal bin
> > - 3 = fastest bin
> >
> > Vendor code actually treats 0 and 2 as invalid efuse values, but later
> > treats all invalid values as a normal bin. This looks like a mistake in
> > bin detection code, that was plastered over by a hack in cpufreq code,
> > so let's not repeat it here. It probably only works because there are no
> > SoCs in the wild with efuse value of 0, and fast bin SoCs are made to
> > use normal bin OPP tables, which is also safe.
> >
> > Let's play it safe and interpret 0 as the slowest bin, but fix detection
> > of other bins to match this research. More research will be done before
> > actual OPP tables are merged.
> >
> > Fixes: f328584f7bff ("cpufreq: Add sun50i nvmem based CPU scaling driver")
> > Signed-off-by: Ondrej Jirman <megous@megous.com>
> 
> Acked-by: Maxime Ripard <mripard@kernel.org>

Applied. Thanks.

-- 
viresh

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

end of thread, other threads:[~2019-11-05  9:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-01 16:41 [PATCH v2] cpufreq: sun50i: Fix CPU speed bin detection Ondrej Jirman
2019-11-03 15:59 ` Maxime Ripard
2019-11-05  9:37   ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).