clk: Fix switching CPU rate from 300Mhz to 1.2GHz on Armada 3700
Subsystems (3)
Gregory CLEMENT
maintainercover clk: Fix switching CPU rate from 300Mhz to 1.2GHz on Armada 3700
Hello,
in this series the first patch is the main patch which fixes the case when switching CPU rate from 300Mhz (or 200M MHz) to 1.2GH. See the commit log for the details. As this one is a fix, it should be applied on v4.18-rc.
While I was on this file, I also switch to SPDX license identifier, this one is fine for 4.19*;
Thanks,
Gregory
Gregory CLEMENT (2):
clk: mvebu: armada-37xx-periph: Fix switching CPU rate from 300Mhz to
1.2GHz
clk: mvebu: armada-37xx-periph: switch to SPDX license identifier
drivers/clk/mvebu/armada-37xx-periph.c | 43 +++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
Gregory CLEMENT
maintainerPATCH 1/2 clk: mvebu: armada-37xx-periph: Fix switching CPU rate from 300Mhz to 1.2GHz
Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz respectively) to L0 frequency (1.2 Ghz) requires a significant amount of time to let VDD stabilize to the appropriate voltage. This amount of time is large enough that it cannot be covered by the hardware countdown register. Due to this, the CPU might start operating at L0 before the voltage is stabilized, leading to CPU stalls.
To work around this problem, we prevent switching directly from the L2/L3 frequencies to the L0 frequency, and instead switch to the L1 frequency in-between. The sequence therefore becomes:
1. First switch from L2/L3(200/300MHz) to L1(600MHZ)
2. Sleep 20ms for stabling VDD voltage
3. Then switch from L1(600MHZ) to L0(1200Mhz).
It is based on the work done by Ken Ma <[email protected]>
--- drivers/clk/mvebu/armada-37xx-periph.c | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
drivers/clk/mvebu/armada-37xx-periph.c +38 -0
@@ -35,6 +35,7 @@#define CLK_SEL 0x10#define CLK_DIS 0x14 +#define ARMADA_37XX_DVFS_LOAD_1 1#define LOAD_LEVEL_NR 4#define ARMADA_37XX_NB_L0L1 0x18
@@ -507,6 +508,40 @@ static long clk_pm_cpu_round_rate(struct clk_hw *hw, unsigned long rate,return -EINVAL ; } +/* +* Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz +* respectively) to L0 frequency (1.2 Ghz) requires a significant +* amount of time to let VDD stabilize to the appropriate +* voltage. This amount of time is large enough that it cannot be +* covered by the hardware countdown register. Due to this, the CPU +* might start operating at L0 before the voltage is stabilized, +* leading to CPU stalls. +* +* To work around this problem, we prevent switching directly from the +* L2/L3 frequencies to the L0 frequency, and instead switch to the L1 +* frequency in-between. The sequence therefore becomes: +* 1. First switch from L2/L3(200/300MHz) to L1(600MHZ) +* 2. Sleep 20ms for stabling VDD voltage +* 3. Then switch from L1(600MHZ) to L0(1200Mhz). +*/ +static void clk_pm_cpu_set_rate_wa (unsigned long rate,struct regmap *base) +{ +unsigned int cur_level; + +if (rate !=1200 *1000 *1000 ) +return ; + +regmap_read (base,ARMADA_37XX_NB_CPU_LOAD , &cur_level); + cur_level &=ARMADA_37XX_NB_CPU_LOAD_MASK ; +if (cur_level <=ARMADA_37XX_DVFS_LOAD_1 ) +return ; + +regmap_update_bits (base,ARMADA_37XX_NB_CPU_LOAD , +ARMADA_37XX_NB_CPU_LOAD_MASK , +ARMADA_37XX_DVFS_LOAD_1 ); +msleep (20 ); +} +static int clk_pm_cpu_set_rate (struct clk_hw *hw,unsigned long rate,unsigned long parent_rate) {
@@ -537,6 +572,9 @@ static int clk_pm_cpu_set_rate(struct clk_hw *hw, unsigned long rate,*/ reg =ARMADA_37XX_NB_CPU_LOAD ; mask =ARMADA_37XX_NB_CPU_LOAD_MASK ; + +clk_pm_cpu_set_rate_wa (rate, base); +regmap_update_bits (base, reg, mask, load_level);return rate;
Signature · 1 line
2.17.1
Gregory CLEMENT
maintainerRe: [PATCH 1/2] clk: mvebu: armada-37xx-periph: Fix switching CPU rate from 300Mhz to 1.2GHz
Hi,
Quoted 7 lines · Gregory CLEMENT
Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz respectively) to L0 frequency (1.2 Ghz) requires a significant amount of time to let VDD stabilize to the appropriate voltage. This amount of time is large enough that it cannot be covered by the hardware countdown register. Due to this, the CPU might start operating at L0 before the voltage is stabilized, leading to CPU stalls.
Quoted 7 lines
To work around this problem, we prevent switching directly from the L2/L3 frequencies to the L0 frequency, and instead switch to the L1 frequency in-between. The sequence therefore becomes:
1. First switch from L2/L3(200/300MHz) to L1(600MHZ)
2. Sleep 20ms for stabling VDD voltage
3. Then switch from L1(600MHZ) to L0(1200Mhz).
Do you have any comment on this fix?
Gregory
Quoted 81 lines
It is based on the work done by Ken Ma <[email protected]>
Cc stable at vger.kernel.orgFixes 2089dc33ea0e ("clk: mvebu: armada-37xx-periph: add DVFS support for cpu clocks")Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/clk/mvebu/armada-37xx-periph.c | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)drivers/clk/mvebu/armada-37xx-periph.c +38
-0@@ -35,6 +35,7 @@#define CLK_SEL 0x10#define CLK_DIS 0x14 +#define ARMADA_37XX_DVFS_LOAD_1 1#define LOAD_LEVEL_NR 4#define ARMADA_37XX_NB_L0L1 0x18@@ -507,6 +508,40 @@ static long clk_pm_cpu_round_rate(struct clk_hw *hw, unsigned long rate,return -EINVAL ; } +/* +* Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz +* respectively) to L0 frequency (1.2 Ghz) requires a significant +* amount of time to let VDD stabilize to the appropriate +* voltage. This amount of time is large enough that it cannot be +* covered by the hardware countdown register. Due to this, the CPU +* might start operating at L0 before the voltage is stabilized, +* leading to CPU stalls. +* +* To work around this problem, we prevent switching directly from the +* L2/L3 frequencies to the L0 frequency, and instead switch to the L1 +* frequency in-between. The sequence therefore becomes: +* 1. First switch from L2/L3(200/300MHz) to L1(600MHZ) +* 2. Sleep 20ms for stabling VDD voltage +* 3. Then switch from L1(600MHZ) to L0(1200Mhz). +*/ +static void clk_pm_cpu_set_rate_wa (unsigned long rate,struct regmap *base) +{ +unsigned int cur_level; + +if (rate !=1200 *1000 *1000 ) +return ; + +regmap_read (base,ARMADA_37XX_NB_CPU_LOAD , &cur_level); + cur_level &=ARMADA_37XX_NB_CPU_LOAD_MASK ; +if (cur_level <=ARMADA_37XX_DVFS_LOAD_1 ) +return ; + +regmap_update_bits (base,ARMADA_37XX_NB_CPU_LOAD , +ARMADA_37XX_NB_CPU_LOAD_MASK , +ARMADA_37XX_DVFS_LOAD_1 ); +msleep (20 ); +} +static int clk_pm_cpu_set_rate (struct clk_hw *hw,unsigned long rate,unsigned long parent_rate) {@@ -537,6 +572,9 @@ static int clk_pm_cpu_set_rate(struct clk_hw *hw, unsigned long rate,*/ reg =ARMADA_37XX_NB_CPU_LOAD ; mask =ARMADA_37XX_NB_CPU_LOAD_MASK ; + +clk_pm_cpu_set_rate_wa (rate, base); +regmap_update_bits (base, reg, mask, load_level);return rate;Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Signature · 3 lines
Gregory Clement, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com
Stephen Boyd
maintainerRe: [PATCH 1/2] clk: mvebu: armada-37xx-periph: Fix switching CPU rate from 300Mhz to 1.2GHz
Quoting Gregory CLEMENT (2018-06-29 07:44:02)
Quoted 15 lines
Hi,
Quoted 11 lines · Gregory CLEMENT
Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz respectively) to L0 frequency (1.2 Ghz) requires a significant amount of time to let VDD stabilize to the appropriate voltage. This amount of time is large enough that it cannot be covered by the hardware countdown register. Due to this, the CPU might start operating at L0 before the voltage is stabilized, leading to CPU stalls.
To work around this problem, we prevent switching directly from the L2/L3 frequencies to the L0 frequency, and instead switch to the L1 frequency in-between. The sequence therefore becomes:
Quoted 6 lines
Quoted 3 lines
1. First switch from L2/L3(200/300MHz) to L1(600MHZ)
2. Sleep 20ms for stabling VDD voltage
3. Then switch from L1(600MHZ) to L0(1200Mhz).Do you have any comment on this fix?
Looks good. Is it crashing right now? I can throw it into clk-fixes if it's fixing pain.
Gregory CLEMENT
maintainerRe: [PATCH 1/2] clk: mvebu: armada-37xx-periph: Fix switching CPU rate from 300Mhz to 1.2GHz
Hi Stephen,
Quoted 20 lines · Stephen Boyd
Quoting Gregory CLEMENT (2018-06-29 07:44:02)
Quoted 19 lines
Hi,
Quoted 14 lines · Gregory CLEMENT
Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz respectively) to L0 frequency (1.2 Ghz) requires a significant amount of time to let VDD stabilize to the appropriate voltage. This amount of time is large enough that it cannot be covered by the hardware countdown register. Due to this, the CPU might start operating at L0 before the voltage is stabilized, leading to CPU stalls.
To work around this problem, we prevent switching directly from the L2/L3 frequencies to the L0 frequency, and instead switch to the L1 frequency in-between. The sequence therefore becomes:
1. First switch from L2/L3(200/300MHz) to L1(600MHZ)
2. Sleep 20ms for stabling VDD voltage
3. Then switch from L1(600MHZ) to L0(1200Mhz).
Quoted 5 lines
Quoted 2 lines
Do you have any comment on this fix?
Looks good. Is it crashing right now? I can throw it into clk-fixes if it's fixing pain.
Yes for the SoC capable to run at 1200Mhz it crashes. At the time the initial support was provided, my SoC version only ran at 1000MHz, so the problem was not noticed.
Thanks,
Gregory
Signature · 3 lines
Gregory Clement, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering http://bootlin.com
Stephen Boyd
maintainerRe: [PATCH 1/2] clk: mvebu: armada-37xx-periph: Fix switching CPU rate from 300Mhz to 1.2GHz
Quoting Gregory CLEMENT (2018-07-09 08:42:31)
Quoted 27 lines
Hi Stephen,
Quoted 23 lines · Stephen Boyd
Quoting Gregory CLEMENT (2018-06-29 07:44:02)
Quoted 21 lines
Hi,
Quoted 7 lines · Gregory CLEMENT
Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz respectively) to L0 frequency (1.2 Ghz) requires a significant amount of time to let VDD stabilize to the appropriate voltage. This amount of time is large enough that it cannot be covered by the hardware countdown register. Due to this, the CPU might start operating at L0 before the voltage is stabilized, leading to CPU stalls.
Quoted 7 lines
To work around this problem, we prevent switching directly from the L2/L3 frequencies to the L0 frequency, and instead switch to the L1 frequency in-between. The sequence therefore becomes:
1. First switch from L2/L3(200/300MHz) to L1(600MHZ)
2. Sleep 20ms for stabling VDD voltage
3. Then switch from L1(600MHZ) to L0(1200Mhz).Do you have any comment on this fix?
Quoted 7 lines
Quoted 2 lines
Looks good. Is it crashing right now? I can throw it into clk-fixes if it's fixing pain.
Yes for the SoC capable to run at 1200Mhz it crashes. At the time the initial support was provided, my SoC version only ran at 1000MHz, so the problem was not noticed.
Ok. Applied to clk-fixes.
Gregory CLEMENT
maintainerPATCH 2/2 clk: mvebu: armada-37xx-periph: switch to SPDX license identifier
In reply to Gregory CLEMENTAdopt the SPDX license identifier headers to ease license compliance management.
--- drivers/clk/mvebu/armada-37xx-periph.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/clk/mvebu/armada-37xx-periph.c +1 -4
@@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Marvell Armada 37xx SoC Peripheral clocks *
@@ -5,10 +6,6 @@* * Gregory CLEMENT <[email protected]> * -* This file is licensed under the terms of the GNU General Public -* License version 2 or later. This program is licensed "as is" -* without any warranty of any kind, whether express or implied. -* * Most of the peripheral clocks can be modelled like this: * _____ _______ _______ * TBG-A-P --| | | | | | ______
Signature · 1 line
2.17.1
Re: [PATCH 2/2] clk: mvebu: armada-37xx-periph: switch to SPDX license identifier
Quoting Gregory CLEMENT (2018-06-19 05:34:46)
Quoted 5 lines
Adopt the SPDX license identifier headers to ease license compliance management.
Signed-off-by Gregory CLEMENT <[email protected]>---
Applied to clk-next