Skip to contentSkip to conversation

clk: imx: lpcg-scu: SW workaround for errata (e10858)

PATCH In review [email protected] 3 participants 4 messages Sep 8, 2020

Subsystems (3)
lore
Share & tools
lore

[email protected]

author reviewer
#0 lore raw

PATCH 1/1 clk: imx: lpcg-scu: SW workaround for errata (e10858)

From: Peng Fan <[email protected]>

Back-to-back LPCG writes can be ignored by the LPCG register due to a HW bug. The writes need to be separated by at least 4 cycles of the gated clock.

The workaround is implemented as follows:
1. For clocks running greater than or equal to 24MHz, a read followed by the write will provide sufficient delay.
2. For clocks running below 24MHz, add a delay of 4 clock cylces after the write to the LPCG register.

---
 drivers/clk/imx/clk-lpcg-scu.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/clk/imx/clk-lpcg-scu.c +29 -2
index 1f0e44f921ae..6ee9d2caedf2 100644
@@ -6,6 +6,7 @@
 
 #include <linux/bits.h>
 #include <linux/clk-provider.h>
+#include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/slab.h>
@@ -38,6 +39,31 @@ struct clk_lpcg_scu {
 
 #define to_clk_lpcg_scu(_hw) container_of(_hw, struct clk_lpcg_scu, hw)
 
+/* e10858 -LPCG clock gating register synchronization errata */
+static void do_lpcg_workaround(u32 rate, void __iomem *reg, u32 val)
+{
+	writel(val, reg);
+
+	if (rate >= 24000000 || rate == 0) {
+		u32 reg1;
+
+		/*
+		 * The time taken to access the LPCG registers from the AP core
+		 * through the interconnect is longer than the minimum delay
+		 * of 4 clock cycles required by the errata.
+		 * Adding a readl will provide sufficient delay to prevent
+		 * back-to-back writes.
+		 */
+		reg1 = readl(reg);
+	} else {
+		/*
+		 * For clocks running below 24MHz, wait a minimum of
+		 * 4 clock cycles.
+		 */
+		ndelay(4 * (DIV_ROUND_UP(1000000000, rate)));
+	}
+}
+
 static int clk_lpcg_scu_enable(struct clk_hw *hw)
 {
 	struct clk_lpcg_scu *clk = to_clk_lpcg_scu(hw);
@@ -54,7 +80,8 @@ static int clk_lpcg_scu_enable(struct clk_hw *hw)
 		val |= CLK_GATE_SCU_LPCG_HW_SEL;
 
 	reg |= val << clk->bit_idx;
-	writel(reg, clk->reg);
+
+	do_lpcg_workaround(clk_hw_get_rate(hw), clk->reg, reg);
 
 	spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);
 
@@ -71,7 +98,7 @@ static void clk_lpcg_scu_disable(struct clk_hw *hw)
 
 	reg = readl_relaxed(clk->reg);
 	reg &= ~(CLK_GATE_SCU_LPCG_MASK << clk->bit_idx);
-	writel(reg, clk->reg);
+	do_lpcg_workaround(clk_hw_get_rate(hw), clk->reg, reg);
 
 	spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);
 }
Signature · 1 line
2.28.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 46 lines · On 20-09-08 17:14:47, [email protected] wrote:

From: Peng Fan <[email protected]>

Back-to-back LPCG writes can be ignored by the LPCG register due to a HW bug. The writes need to be separated by at least 4 cycles of the gated clock.

The workaround is implemented as follows:
1. For clocks running greater than or equal to 24MHz, a read followed by the write will provide sufficient delay.
2. For clocks running below 24MHz, add a delay of 4 clock cylces after the write to the LPCG register.

---
 drivers/clk/imx/clk-lpcg-scu.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/clk/imx/clk-lpcg-scu.c +14 -0
index 1f0e44f921ae..6ee9d2caedf2 100644
@@ -6,6 +6,7 @@
 
 #include <linux/bits.h>
 #include <linux/clk-provider.h>
+#include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/slab.h>
@@ -38,6 +39,31 @@ struct clk_lpcg_scu {
 
 #define to_clk_lpcg_scu(_hw) container_of(_hw, struct clk_lpcg_scu, hw)
 
+/* e10858 -LPCG clock gating register synchronization errata */
+static void do_lpcg_workaround(u32 rate, void __iomem *reg, u32 val)
+{
+	writel(val, reg);
+
+	if (rate >= 24000000 || rate == 0) {
+		u32 reg1;
+
+		/*
+		 * The time taken to access the LPCG registers from the AP core
+		 * through the interconnect is longer than the minimum delay
+		 * of 4 clock cycles required by the errata.
+		 * Adding a readl will provide sufficient delay to prevent

drivers/clk/imx/clk-lpcg-scu.c struct clk_lpcg_scu { · line 64

Quoted 10 lines
drivers/clk/imx/clk-lpcg-scu.c +10 -0
+		 * back-to-back writes.
+		 */
+		reg1 = readl(reg);
+	} else {
+		/*
+		 * For clocks running below 24MHz, wait a minimum of
+		 * 4 clock cycles.
+		 */
+		ndelay(4 * (DIV_ROUND_UP(1000000000, rate)));
+	}

Just to make sure this is totally understood, if the lpcg consumer needs to two enables/disables in less than 4 multiplied by the clock period, the second enable/disable will be delayed.

If we're fine with this, then here is my R-b.

Quoted 27 lines
drivers/clk/imx/clk-lpcg-scu.c +5 -2
+}
+
 static int clk_lpcg_scu_enable(struct clk_hw *hw)
 {
 	struct clk_lpcg_scu *clk = to_clk_lpcg_scu(hw);
@@ -54,7 +80,8 @@ static int clk_lpcg_scu_enable(struct clk_hw *hw)
 		val |= CLK_GATE_SCU_LPCG_HW_SEL;
 
 	reg |= val << clk->bit_idx;
-	writel(reg, clk->reg);
+
+	do_lpcg_workaround(clk_hw_get_rate(hw), clk->reg, reg);
 
 	spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);
 
@@ -71,7 +98,7 @@ static void clk_lpcg_scu_disable(struct clk_hw *hw)
 
 	reg = readl_relaxed(clk->reg);
 	reg &= ~(CLK_GATE_SCU_LPCG_MASK << clk->bit_idx);
-	writel(reg, clk->reg);
+	do_lpcg_workaround(clk_hw_get_rate(hw), clk->reg, reg);
 
 	spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);
 }
Signature · 1 line
2.28.0
author reviewer
#2 lore raw
Quoted 57 lines

Subject: Re: [PATCH] clk: imx: lpcg-scu: SW workaround for errata (e10858)

Quoted 54 lines · On 20-09-08 17:14:47, [email protected] wrote:

From: Peng Fan <[email protected]>

Back-to-back LPCG writes can be ignored by the LPCG register due to a HW bug. The writes need to be separated by at least 4 cycles of the gated clock.

The workaround is implemented as follows:
1. For clocks running greater than or equal to 24MHz, a read followed by the write will provide sufficient delay.
2. For clocks running below 24MHz, add a delay of 4 clock cylces after the write to the LPCG register.

---
 drivers/clk/imx/clk-lpcg-scu.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/clk/imx/clk-lpcg-scu.c index 1f0e44f921ae..6ee9d2caedf2 100644

drivers/clk/imx/clk-lpcg-scu.c +20 -0
@@ -6,6 +6,7 @@
 
 #include <linux/bits.h>
 #include <linux/clk-provider.h>
+#include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/slab.h>
@@ -38,6 +39,31 @@ struct clk_lpcg_scu {
 
 #define to_clk_lpcg_scu(_hw) container_of(_hw, struct clk_lpcg_scu,
 hw)
 
+/* e10858 -LPCG clock gating register synchronization errata */
+static void do_lpcg_workaround(u32 rate, void __iomem *reg, u32 val)
+{
+	writel(val, reg);
+
+	if (rate >= 24000000 || rate == 0) {
+		u32 reg1;
+
+		/*
+		 * The time taken to access the LPCG registers from the AP core
+		 * through the interconnect is longer than the minimum delay
+		 * of 4 clock cycles required by the errata.
+		 * Adding a readl will provide sufficient delay to prevent
+		 * back-to-back writes.
+		 */
+		reg1 = readl(reg);
+	} else {
+		/*
+		 * For clocks running below 24MHz, wait a minimum of
Quoted 8 lines

drivers/clk/imx/clk-lpcg-scu.c struct clk_lpcg_scu { · line 64

Quoted 4 lines
drivers/clk/imx/clk-lpcg-scu.c +4 -0
+		 * 4 clock cycles.
+		 */
+		ndelay(4 * (DIV_ROUND_UP(1000000000, rate)));
+	}

Just to make sure this is totally understood, if the lpcg consumer needs to two enables/disables in less than 4 multiplied by the clock period, the second enable/disable will be delayed.

You surely wanna this following errata description.

Thanks,
Peng.

Quoted 26 lines

If we're fine with this, then here is my R-b.

Quoted 21 lines
drivers/clk/imx/clk-lpcg-scu.c +2 -0
+}
+
 static int clk_lpcg_scu_enable(struct clk_hw *hw)  {
 	struct clk_lpcg_scu *clk = to_clk_lpcg_scu(hw); @@ -54,7 +80,8 @@

static int clk_lpcg_scu_enable(struct clk_hw *hw)

drivers/clk/imx/clk-lpcg-scu.c +3 -2
 		val |= CLK_GATE_SCU_LPCG_HW_SEL;
 
 	reg |= val << clk->bit_idx;
-	writel(reg, clk->reg);
+
+	do_lpcg_workaround(clk_hw_get_rate(hw), clk->reg, reg);
 
 	spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);
@@ -71,7 +98,7 @@ static void clk_lpcg_scu_disable(struct clk_hw *hw)
 
 	reg = readl_relaxed(clk->reg);
 	reg &= ~(CLK_GATE_SCU_LPCG_MASK << clk->bit_idx);
-	writel(reg, clk->reg);
+	do_lpcg_workaround(clk_hw_get_rate(hw), clk->reg, reg);
 
Quoted 4 lines
Quoted 4 lines
drivers/clk/imx/clk-lpcg-scu.c +0 -1
 	spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);  }
--

2.28.0

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw
In reply to [email protected]
Thank you for the patch! Perhaps something to improve:

Hi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on shawnguo/for-next]
[also build test WARNING on v5.9-rc4 next-20200903]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/peng-fan-nxp-com/clk-imx-lpcg-scu-SW-workaround-for-errata-e10858/20200908-172251
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux.git for-next
config: arm64-allyesconfig (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

drivers/clk/imx/clk-lpcg-scu.c: In function 'do_lpcg_workaround':

>> drivers/clk/imx/clk-lpcg-scu.c:48:7: warning: variable 'reg1' set but not used [-Wunused-but-set-variable]
      48 |   u32 reg1;
         |       ^~~~

# https://github.com/0day-ci/linux/commit/8fdaeb349edafd1e64cac9b404a1625bdded0473
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review peng-fan-nxp-com/clk-imx-lpcg-scu-SW-workaround-for-errata-e10858/20200908-172251 git checkout 8fdaeb349edafd1e64cac9b404a1625bdded0473
vim +/reg1 +48 drivers/clk/imx/clk-lpcg-scu.c

    41	
    42	/* e10858 -LPCG clock gating register synchronization errata */
    43	static void do_lpcg_workaround(u32 rate, void __iomem *reg, u32 val)
    44	{
    45		writel(val, reg);
    46	
    47		if (rate >= 24000000 || rate == 0) {
  > 48			u32 reg1;
    49	
    50			/*
    51			 * The time taken to access the LPCG registers from the AP core
    52			 * through the interconnect is longer than the minimum delay
    53			 * of 4 clock cycles required by the errata.
    54			 * Adding a readl will provide sufficient delay to prevent
    55			 * back-to-back writes.
    56			 */
    57			reg1 = readl(reg);
    58		} else {
    59			/*
    60			 * For clocks running below 24MHz, wait a minimum of
    61			 * 4 clock cycles.
    62			 */
    63			ndelay(4 * (DIV_ROUND_UP(1000000000, rate)));
    64		}
    65	}
    66	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org