drivers: stm32mp1 clocks: prevent crash on always on clocks

Oscillators and PLLs are not gated on stm32mp_clk_enable/disable()
calls. This change prevents functions to panic when called for such
always-on clocks. Gating these clocks is out of the scope of
this change.

Change-Id: Ie730553dea480b529de942446176db9119587832
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
This commit is contained in:
Etienne Carriere 2019-12-08 08:21:44 +01:00
parent 016af0064d
commit 35848200b9
1 changed files with 42 additions and 3 deletions

View File

@ -1029,12 +1029,41 @@ unsigned int stm32mp1_clk_get_refcount(unsigned long id)
return gate_refcounts[i];
}
/* Oscillators and PLLs are not gated at runtime */
static bool clock_is_always_on(unsigned long id)
{
switch (id) {
case CK_HSE:
case CK_CSI:
case CK_LSI:
case CK_LSE:
case CK_HSI:
case CK_HSE_DIV2:
case PLL1_Q:
case PLL1_R:
case PLL2_P:
case PLL2_Q:
case PLL2_R:
case PLL3_P:
case PLL3_Q:
case PLL3_R:
return true;
default:
return false;
}
}
void __stm32mp1_clk_enable(unsigned long id, bool secure)
{
const struct stm32mp1_clk_gate *gate;
int i = stm32mp1_clk_get_gated_id(id);
int i;
unsigned int *refcnt;
if (clock_is_always_on(id)) {
return;
}
i = stm32mp1_clk_get_gated_id(id);
if (i < 0) {
ERROR("Clock %d can't be enabled\n", (uint32_t)id);
panic();
@ -1055,9 +1084,14 @@ void __stm32mp1_clk_enable(unsigned long id, bool secure)
void __stm32mp1_clk_disable(unsigned long id, bool secure)
{
const struct stm32mp1_clk_gate *gate;
int i = stm32mp1_clk_get_gated_id(id);
int i;
unsigned int *refcnt;
if (clock_is_always_on(id)) {
return;
}
i = stm32mp1_clk_get_gated_id(id);
if (i < 0) {
ERROR("Clock %d can't be disabled\n", (uint32_t)id);
panic();
@ -1087,8 +1121,13 @@ void stm32mp_clk_disable(unsigned long id)
bool stm32mp_clk_is_enabled(unsigned long id)
{
int i = stm32mp1_clk_get_gated_id(id);
int i;
if (clock_is_always_on(id)) {
return true;
}
i = stm32mp1_clk_get_gated_id(id);
if (i < 0) {
panic();
}