Skip to content

Commit

Permalink
drivers: clk: stm32: fix stm32mp13 clock gates initialization
Browse files Browse the repository at this point in the history
Correct STM32MP13 clock gates initialization regarding the enable
reference counting. The fixed commit introduced side effect where
clock gates with a disable init state overflow the gate refcount to -1
and clock gates with a enable init state take a refcount that is never
released.

For this purpose, add stm32_gate_set_init_state() function in
stm32 clock core driver for STM32MP13 gate clocks initialization
expects to set some clock gate hardware state (enabled or disabled)
before any refcount is considered.

Fixes: 2b028a2 ("clk: implement multi-gate management at core level")
Signed-off-by: Etienne Carriere <[email protected]>
  • Loading branch information
etienne-lms committed Oct 3, 2024
1 parent 718cc2b commit ae24289
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions core/drivers/clk/clk-stm32-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ static void stm32_gate_endisable(uint16_t gate_id, bool enable)
}
}

void stm32_gate_set_init_state(uint16_t gate_id, bool enable)
{
struct clk_stm32_priv __maybe_unused *priv = clk_stm32_get_priv();

assert(!priv->gate_cpt[gate_id]);
stm32_gate_endisable(gate_id, enable);
}

void stm32_gate_disable(uint16_t gate_id)
{
struct clk_stm32_priv *priv = clk_stm32_get_priv();
Expand Down
7 changes: 7 additions & 0 deletions core/drivers/clk/clk-stm32-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ TEE_Result stm32_gate_wait_ready(uint16_t gate_id, bool ready_on);
TEE_Result stm32_gate_rdy_enable(uint16_t gate_id);
TEE_Result stm32_gate_rdy_disable(uint16_t gate_id);

/*
* Set gate to an enable or disable state without updating its
* refcount. This is exclusively intended to be used during initialization
* where refcount value are 0.
*/
void stm32_gate_set_init_state(uint16_t gate_id, bool enable);

size_t stm32_mux_get_parent(uint32_t mux_id);
TEE_Result stm32_mux_set_parent(uint16_t pid, uint8_t sel);

Expand Down
5 changes: 1 addition & 4 deletions core/drivers/clk/clk-stm32mp13.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,7 @@ static int stm32_clk_configure_clk(struct clk_stm32_priv *priv __maybe_unused,
if (stm32_mux_set_parent(mux, sel))
return -1;

if (enable)
stm32_gate_enable(gate);
else
stm32_gate_disable(gate);
stm32_gate_set_init_state(gate, enable);

return 0;
}
Expand Down

0 comments on commit ae24289

Please sign in to comment.