Skip to content

Commit

Permalink
drivers: clk: clk-stm32mp13: don't gate/ungate oscillators not wired
Browse files Browse the repository at this point in the history
If an oscillator is not wired we shouldn't gate it to avoid a panic.
For example the external LSE oscillator may not be supported on a board
in which case node named clk-lse is disabled in the board DTS file.

Signed-off-by: Etienne Carriere <etienne.carriere@foss.st.com>
Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
  • Loading branch information
etienne-lms committed Feb 1, 2024
1 parent 66979db commit 41931f0
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions core/drivers/clk/clk-stm32mp13.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ static int stm32_clk_parse_fdt_all_oscillator(const void *fdt,
fdt_err = clk_stm32_parse_oscillator_fdt(fdt, osc_node,
osc_data->name, osci);
if (fdt_err < 0)
panic();
osci->freq = 0;
}

return 0;
Expand Down Expand Up @@ -1970,11 +1970,50 @@ const struct clk_ops ck_timer_ops = {
}

/* Oscillator clocks */
static STM32_GATE_READY(ck_hsi, NULL, 0, GATE_HSI);
static STM32_GATE_READY(ck_hse, NULL, 0, GATE_HSE);
static STM32_GATE_READY(ck_csi, NULL, 0, GATE_CSI);
static STM32_GATE_READY(ck_lsi, NULL, 0, GATE_LSI);
static STM32_GATE_READY(ck_lse, NULL, 0, GATE_LSE);

static TEE_Result clk_stm32_oscillator_enable(struct clk *clk)
{
struct clk_stm32_gate_cfg *cfg = clk->priv;

if (clk->rate == 0U)
return TEE_SUCCESS;

return stm32_gate_rdy_enable(cfg->gate_id);
}

static void clk_stm32_oscillator_disable(struct clk *clk)
{
struct clk_stm32_gate_cfg *cfg = clk->priv;

if (clk->rate == 0U)
return;

if (stm32_gate_rdy_disable(cfg->gate_id))
panic();
}

static const struct clk_ops clk_stm32_oscillator_ops = {
.enable = clk_stm32_oscillator_enable,
.disable = clk_stm32_oscillator_disable,
};

#define STM32_OSCILLATOR(_name, _parent, _flags, _gate_id)\
struct clk _name = {\
.ops = &clk_stm32_oscillator_ops,\
.priv = &(struct clk_stm32_gate_cfg) {\
.gate_id = (_gate_id),\
},\
.name = #_name,\
.flags = (_flags),\
.num_parents = 1,\
.parents = { _parent },\
}

static STM32_OSCILLATOR(ck_hsi, NULL, 0, GATE_HSI);
static STM32_OSCILLATOR(ck_hse, NULL, 0, GATE_HSE);
static STM32_OSCILLATOR(ck_csi, NULL, 0, GATE_CSI);
static STM32_OSCILLATOR(ck_lsi, NULL, 0, GATE_LSI);
static STM32_OSCILLATOR(ck_lse, NULL, 0, GATE_LSE);

static STM32_FIXED_FACTOR(ck_i2sckin, NULL, 0, 1, 1);
static STM32_FIXED_FACTOR(ck_hse_div2, &ck_hse, 0, 1, 2);
Expand Down

0 comments on commit 41931f0

Please sign in to comment.