Skip to contentSkip to conversation

clk: aspeed: Prevent reset if clock is enabled

PATCH Superseded Eddie James 3 participants 5 messages Mar 7, 2018 – Mar 8, 2018

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: aspeed: Prevent reset if clock is enabled

According to the Aspeed specification, the reset and enable sequence should be done when the clock is stopped. The specification doesn't define behavior if the reset is done while the clock is enabled.

Quoted 1 line

From testing on the AST2500, the LPC Controller has problems if the

clock is reset while enabled.

Therefore, check whether the clock is enabled or not before performing the reset and enable sequence in the Aspeed clock driver.

---
 drivers/clk/clk-aspeed.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/clk/clk-aspeed.c +6 -0
index 9f7f931..a13054d 100644
@@ -212,6 +212,12 @@ static int aspeed_clk_enable(struct clk_hw *hw)
 	u32 clk = BIT(gate->clock_idx);
 	u32 rst = BIT(gate->reset_idx);
 	u32 enval;
+	u32 reg;
+
+	/* Only reset/enable/unreset if clock is stopped */
+	regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
+	if (!(reg & clk))
+		return 0;
 
 	spin_lock_irqsave(gate->lock, flags);
 
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw

Hi Eddie,

Quoted 20 lines · Eddie James

According to the Aspeed specification, the reset and enable sequence should be done when the clock is stopped. The specification doesn't define behavior if the reset is done while the clock is enabled.

From testing on the AST2500, the LPC Controller has problems if the clock is reset while enabled.

Therefore, check whether the clock is enabled or not before performing the reset and enable sequence in the Aspeed clock driver.

---
 drivers/clk/clk-aspeed.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/clk/clk-aspeed.c +0 -0
index 9f7f931..a13054d 100644

drivers/clk/clk-aspeed.c static int aspeed_clk_enable(struct clk_hw *hw) · line 220

Quoted 9 lines
drivers/clk/clk-aspeed.c +6 -0
@@ -212,6 +212,12 @@ static int aspeed_clk_enable(struct clk_hw *hw)
        u32 clk = BIT(gate->clock_idx);
        u32 rst = BIT(gate->reset_idx);
        u32 enval;
+       u32 reg;
+
+       /* Only reset/enable/unreset if clock is stopped */
+       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
+       if (!(reg & clk))
+               return 0;

This doesn't generalise to all of the clocks, as some clocks use set to disable. Perhaps we could do something like this:

       /* Only reset/enable/unreset if clock is stopped. The LPC clock
on ast2500 has issues otherwise */
       enval = (gate->flags & CLK_GATE_SET_TO_DISABLE) ? 0 : clk;
       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
       if ((reg & clk) == enval) {
               spin_unlock_irqrestore(gate->lock, flags);
               return 0;
       }

I think we should also do this operation under the lock.

Please cc Ryan Chen <[email protected]> so he can confirm that this workaround is valid, and credit Lei who spent a lot of time investigating this issue. Perhaps "Root-caused-by".

Cheers,

Joel

maintainer
#2 lore raw
Quoted 36 lines · Joel Stanley

Hi Eddie,

Quoted 20 lines · Eddie James

According to the Aspeed specification, the reset and enable sequence should be done when the clock is stopped. The specification doesn't define behavior if the reset is done while the clock is enabled.

From testing on the AST2500, the LPC Controller has problems if the clock is reset while enabled.

Therefore, check whether the clock is enabled or not before performing the reset and enable sequence in the Aspeed clock driver.

---
 drivers/clk/clk-aspeed.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/clk/clk-aspeed.c +0 -0
index 9f7f931..a13054d 100644

drivers/clk/clk-aspeed.c static int aspeed_clk_enable(struct clk_hw *hw) · line 220

Quoted 9 lines
drivers/clk/clk-aspeed.c +6 -0
@@ -212,6 +212,12 @@ static int aspeed_clk_enable(struct clk_hw *hw)
        u32 clk = BIT(gate->clock_idx);
        u32 rst = BIT(gate->reset_idx);
        u32 enval;
+       u32 reg;
+
+       /* Only reset/enable/unreset if clock is stopped */
+       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
+       if (!(reg & clk))
+               return 0;

This doesn't generalise to all of the clocks, as some clocks use set to disable. Perhaps we could do something like this:

Quoted 2 lines
       /* Only reset/enable/unreset if clock is stopped. The LPC clock

on ast2500 has issues otherwise */

We've seen this on both the ast2400 and ast2500, so if you do take my suggestion perhaps just say "The LPC clock has issues otherwise".

Quoted 16 lines
       enval = (gate->flags & CLK_GATE_SET_TO_DISABLE) ? 0 : clk;
       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
       if ((reg & clk) == enval) {
               spin_unlock_irqrestore(gate->lock, flags);
               return 0;
       }

I think we should also do this operation under the lock.

Please cc Ryan Chen <[email protected]> so he can confirm that this workaround is valid, and credit Lei who spent a lot of time investigating this issue. Perhaps "Root-caused-by".

Cheers,

Joel

#3 lore raw
In reply to Joel Stanley
Quoted 17 lines · Joel Stanley

drivers/clk/clk-aspeed.c static int aspeed_clk_enable(struct clk_hw *hw) · line 220

Quoted 4 lines
drivers/clk/clk-aspeed.c +4 -0
+       /* Only reset/enable/unreset if clock is stopped */
+       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
+       if (!(reg & clk))
+               return 0;

This doesn't generalise to all of the clocks, as some clocks use set to disable. Perhaps we could do something like this:

       /* Only reset/enable/unreset if clock is stopped. The LPC clock
on ast2500 has issues otherwise */
       enval = (gate->flags & CLK_GATE_SET_TO_DISABLE) ? 0 : clk;
       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
       if ((reg & clk) == enval) {
               spin_unlock_irqrestore(gate->lock, flags);
               return 0;
       }
Quoted 6 lines

I think we should also do this operation under the lock.

Please cc Ryan Chen <[email protected]> so he can confirm that this workaround is valid, and credit Lei who spent a lot of time investigating this issue. Perhaps "Root-caused-by".

The code has aspeed_clk_is_enabled() already, why not just:

    if (aspeed_clk_is_enabled(hw))
        return 0;
maintainer
#4 lore raw
Quoted 25 lines · Lei YU
Quoted 17 lines · Joel Stanley

drivers/clk/clk-aspeed.c static int aspeed_clk_enable(struct clk_hw *hw) · line 220

Quoted 4 lines
drivers/clk/clk-aspeed.c +4 -0
+       /* Only reset/enable/unreset if clock is stopped */
+       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
+       if (!(reg & clk))
+               return 0;

This doesn't generalise to all of the clocks, as some clocks use set to disable. Perhaps we could do something like this:

       /* Only reset/enable/unreset if clock is stopped. The LPC clock
on ast2500 has issues otherwise */
       enval = (gate->flags & CLK_GATE_SET_TO_DISABLE) ? 0 : clk;
       regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, &reg);
       if ((reg & clk) == enval) {
               spin_unlock_irqrestore(gate->lock, flags);
               return 0;
       }
Quoted 6 lines

I think we should also do this operation under the lock.

Please cc Ryan Chen <[email protected]> so he can confirm that this workaround is valid, and credit Lei who spent a lot of time investigating this issue. Perhaps "Root-caused-by".

Quoted 4 lines

The code has aspeed_clk_is_enabled() already, why not just:

    if (aspeed_clk_is_enabled(hw))
        return 0;

Good suggestion.

We should also fix up aspeed_clk_is_enabled() for clocks that have CLK_GATE_SET_TO_DISABLE set.

Cheers,

Joel