Skip to content

Commit 83ce035

Browse files
Gabriel-Fernandzbebarino
authored andcommitted
clk: stm32mp13: add safe mux management
Some muxes need to set a the safe position when clock is off. Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com> Link: https://lore.kernel.org/r/20220516070600.7692-12-gabriel.fernandez@foss.st.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent ffa2d04 commit 83ce035

3 files changed

Lines changed: 62 additions & 4 deletions

File tree

drivers/clk/stm32/clk-stm32-core.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,54 @@ static int clk_stm32_composite_is_enabled(struct clk_hw *hw)
495495
return stm32_gate_is_enabled(composite->base, composite->clock_data, composite->gate_id);
496496
}
497497

498+
#define MUX_SAFE_POSITION 0
499+
500+
static int clk_stm32_has_safe_mux(struct clk_hw *hw)
501+
{
502+
struct clk_stm32_composite *composite = to_clk_stm32_composite(hw);
503+
const struct stm32_mux_cfg *mux = &composite->clock_data->muxes[composite->mux_id];
504+
505+
return !!(mux->flags & MUX_SAFE);
506+
}
507+
508+
static void clk_stm32_set_safe_position_mux(struct clk_hw *hw)
509+
{
510+
struct clk_stm32_composite *composite = to_clk_stm32_composite(hw);
511+
512+
if (!clk_stm32_composite_is_enabled(hw)) {
513+
unsigned long flags = 0;
514+
515+
if (composite->clock_data->is_multi_mux) {
516+
struct clk_hw *other_mux_hw = NULL;
517+
518+
other_mux_hw = composite->clock_data->is_multi_mux(hw);
519+
520+
if (!other_mux_hw || clk_stm32_composite_is_enabled(other_mux_hw))
521+
return;
522+
}
523+
524+
spin_lock_irqsave(composite->lock, flags);
525+
526+
stm32_mux_set_parent(composite->base, composite->clock_data,
527+
composite->mux_id, MUX_SAFE_POSITION);
528+
529+
spin_unlock_irqrestore(composite->lock, flags);
530+
}
531+
}
532+
533+
static void clk_stm32_safe_restore_position_mux(struct clk_hw *hw)
534+
{
535+
struct clk_stm32_composite *composite = to_clk_stm32_composite(hw);
536+
int sel = clk_hw_get_parent_index(hw);
537+
unsigned long flags = 0;
538+
539+
spin_lock_irqsave(composite->lock, flags);
540+
541+
stm32_mux_set_parent(composite->base, composite->clock_data, composite->mux_id, sel);
542+
543+
spin_unlock_irqrestore(composite->lock, flags);
544+
}
545+
498546
static void clk_stm32_composite_gate_endisable(struct clk_hw *hw, int enable)
499547
{
500548
struct clk_stm32_composite *composite = to_clk_stm32_composite(hw);
@@ -516,6 +564,9 @@ static int clk_stm32_composite_gate_enable(struct clk_hw *hw)
516564

517565
clk_stm32_composite_gate_endisable(hw, 1);
518566

567+
if (composite->mux_id != NO_STM32_MUX && clk_stm32_has_safe_mux(hw))
568+
clk_stm32_safe_restore_position_mux(hw);
569+
519570
return 0;
520571
}
521572

@@ -527,6 +578,9 @@ static void clk_stm32_composite_gate_disable(struct clk_hw *hw)
527578
return;
528579

529580
clk_stm32_composite_gate_endisable(hw, 0);
581+
582+
if (composite->mux_id != NO_STM32_MUX && clk_stm32_has_safe_mux(hw))
583+
clk_stm32_set_safe_position_mux(hw);
530584
}
531585

532586
static void clk_stm32_composite_disable_unused(struct clk_hw *hw)

drivers/clk/stm32/clk-stm32-core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
8484

8585
/* MUX define */
8686
#define MUX_NO_RDY 0xFF
87+
#define MUX_SAFE BIT(7)
8788

8889
/* DIV define */
8990
#define DIV_NO_RDY 0xFF

drivers/clk/stm32/clk-stm32mp13.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ enum enum_mux_cfg {
359359
#define CFG_MUX(_id, _offset, _shift, _witdh)\
360360
_CFG_MUX(_id, _offset, _shift, _witdh, MUX_NO_RDY, 0)
361361

362+
#define CFG_MUX_SAFE(_id, _offset, _shift, _witdh)\
363+
_CFG_MUX(_id, _offset, _shift, _witdh, MUX_NO_RDY, MUX_SAFE)
364+
362365
static const struct stm32_mux_cfg stm32mp13_muxes[] = {
363366
CFG_MUX(MUX_I2C12, RCC_I2C12CKSELR, 0, 3),
364367
CFG_MUX(MUX_LPTIM45, RCC_LPTIM45CKSELR, 0, 3),
@@ -394,10 +397,10 @@ static const struct stm32_mux_cfg stm32mp13_muxes[] = {
394397
CFG_MUX(MUX_UART6, RCC_UART6CKSELR, 0, 3),
395398
CFG_MUX(MUX_USBO, RCC_USBCKSELR, 4, 1),
396399
CFG_MUX(MUX_USBPHY, RCC_USBCKSELR, 0, 2),
397-
CFG_MUX(MUX_FMC, RCC_FMCCKSELR, 0, 2),
398-
CFG_MUX(MUX_QSPI, RCC_QSPICKSELR, 0, 2),
399-
CFG_MUX(MUX_SDMMC1, RCC_SDMMC12CKSELR, 0, 3),
400-
CFG_MUX(MUX_SDMMC2, RCC_SDMMC12CKSELR, 3, 3),
400+
CFG_MUX_SAFE(MUX_FMC, RCC_FMCCKSELR, 0, 2),
401+
CFG_MUX_SAFE(MUX_QSPI, RCC_QSPICKSELR, 0, 2),
402+
CFG_MUX_SAFE(MUX_SDMMC1, RCC_SDMMC12CKSELR, 0, 3),
403+
CFG_MUX_SAFE(MUX_SDMMC2, RCC_SDMMC12CKSELR, 3, 3),
401404
};
402405

403406
struct clk_stm32_securiy {

0 commit comments

Comments
 (0)