1
0

510-clk-mvebu-armada-37xx-periph-Fix-switching-CPU-rate-.patch 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From 61c40f35f5cd6f67ccbd7319a1722eb78c815989 Mon Sep 17 00:00:00 2001
  2. From: Gregory CLEMENT <gregory.clement@bootlin.com>
  3. Date: Tue, 19 Jun 2018 14:34:45 +0200
  4. Subject: [PATCH] clk: mvebu: armada-37xx-periph: Fix switching CPU rate from
  5. 300Mhz to 1.2GHz
  6. Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz
  7. respectively) to L0 frequency (1.2 Ghz) requires a significant amount
  8. of time to let VDD stabilize to the appropriate voltage. This amount of
  9. time is large enough that it cannot be covered by the hardware
  10. countdown register. Due to this, the CPU might start operating at L0
  11. before the voltage is stabilized, leading to CPU stalls.
  12. To work around this problem, we prevent switching directly from the
  13. L2/L3 frequencies to the L0 frequency, and instead switch to the L1
  14. frequency in-between. The sequence therefore becomes:
  15. 1. First switch from L2/L3(200/300MHz) to L1(600MHZ)
  16. 2. Sleep 20ms for stabling VDD voltage
  17. 3. Then switch from L1(600MHZ) to L0(1200Mhz).
  18. It is based on the work done by Ken Ma <make@marvell.com>
  19. Cc: stable@vger.kernel.org
  20. Fixes: 2089dc33ea0e ("clk: mvebu: armada-37xx-periph: add DVFS support for cpu clocks")
  21. Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
  22. Signed-off-by: Stephen Boyd <sboyd@kernel.org>
  23. ---
  24. drivers/clk/mvebu/armada-37xx-periph.c | 38 ++++++++++++++++++++++++++
  25. 1 file changed, 38 insertions(+)
  26. --- a/drivers/clk/mvebu/armada-37xx-periph.c
  27. +++ b/drivers/clk/mvebu/armada-37xx-periph.c
  28. @@ -35,6 +35,7 @@
  29. #define CLK_SEL 0x10
  30. #define CLK_DIS 0x14
  31. +#define ARMADA_37XX_DVFS_LOAD_1 1
  32. #define LOAD_LEVEL_NR 4
  33. #define ARMADA_37XX_NB_L0L1 0x18
  34. @@ -507,6 +508,40 @@ static long clk_pm_cpu_round_rate(struct
  35. return -EINVAL;
  36. }
  37. +/*
  38. + * Switching the CPU from the L2 or L3 frequencies (300 and 200 Mhz
  39. + * respectively) to L0 frequency (1.2 Ghz) requires a significant
  40. + * amount of time to let VDD stabilize to the appropriate
  41. + * voltage. This amount of time is large enough that it cannot be
  42. + * covered by the hardware countdown register. Due to this, the CPU
  43. + * might start operating at L0 before the voltage is stabilized,
  44. + * leading to CPU stalls.
  45. + *
  46. + * To work around this problem, we prevent switching directly from the
  47. + * L2/L3 frequencies to the L0 frequency, and instead switch to the L1
  48. + * frequency in-between. The sequence therefore becomes:
  49. + * 1. First switch from L2/L3(200/300MHz) to L1(600MHZ)
  50. + * 2. Sleep 20ms for stabling VDD voltage
  51. + * 3. Then switch from L1(600MHZ) to L0(1200Mhz).
  52. + */
  53. +static void clk_pm_cpu_set_rate_wa(unsigned long rate, struct regmap *base)
  54. +{
  55. + unsigned int cur_level;
  56. +
  57. + if (rate != 1200 * 1000 * 1000)
  58. + return;
  59. +
  60. + regmap_read(base, ARMADA_37XX_NB_CPU_LOAD, &cur_level);
  61. + cur_level &= ARMADA_37XX_NB_CPU_LOAD_MASK;
  62. + if (cur_level <= ARMADA_37XX_DVFS_LOAD_1)
  63. + return;
  64. +
  65. + regmap_update_bits(base, ARMADA_37XX_NB_CPU_LOAD,
  66. + ARMADA_37XX_NB_CPU_LOAD_MASK,
  67. + ARMADA_37XX_DVFS_LOAD_1);
  68. + msleep(20);
  69. +}
  70. +
  71. static int clk_pm_cpu_set_rate(struct clk_hw *hw, unsigned long rate,
  72. unsigned long parent_rate)
  73. {
  74. @@ -537,6 +572,9 @@ static int clk_pm_cpu_set_rate(struct cl
  75. */
  76. reg = ARMADA_37XX_NB_CPU_LOAD;
  77. mask = ARMADA_37XX_NB_CPU_LOAD_MASK;
  78. +
  79. + clk_pm_cpu_set_rate_wa(rate, base);
  80. +
  81. regmap_update_bits(base, reg, mask, load_level);
  82. return rate;