Skip to content

Commit ffa2d04

Browse files
Gabriel-Fernandzbebarino
authored andcommitted
clk: stm32mp13: add multi mux function
Some RCC muxes can manages two output clocks with same register. Signed-off-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com> Link: https://lore.kernel.org/r/20220516070600.7692-11-gabriel.fernandez@foss.st.com Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent bfad377 commit ffa2d04

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,16 @@ static int clk_stm32_composite_set_parent(struct clk_hw *hw, u8 index)
472472

473473
spin_unlock_irqrestore(composite->lock, flags);
474474

475+
if (composite->clock_data->is_multi_mux) {
476+
struct clk_hw *other_mux_hw = composite->clock_data->is_multi_mux(hw);
477+
478+
if (other_mux_hw) {
479+
struct clk_hw *hwp = clk_hw_get_parent_by_index(hw, index);
480+
481+
clk_hw_reparent(other_mux_hw, hwp);
482+
}
483+
}
484+
475485
return 0;
476486
}
477487

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct clk_stm32_clock_data {
6161
const struct stm32_gate_cfg *gates;
6262
const struct stm32_mux_cfg *muxes;
6363
const struct stm32_div_cfg *dividers;
64+
struct clk_hw *(*is_multi_mux)(struct clk_hw *hw);
6465
};
6566

6667
struct stm32_rcc_match_data {
@@ -72,6 +73,7 @@ struct stm32_rcc_match_data {
7273
u32 clear_offset;
7374
int (*check_security)(void __iomem *base,
7475
const struct clock_config *cfg);
76+
int (*multi_mux)(void __iomem *base, const struct clock_config *cfg);
7577
};
7678

7779
int stm32_rcc_reset_init(struct device *dev, const struct of_device_id *match,

drivers/clk/stm32/clk-stm32mp13.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,13 +1469,43 @@ static int stm32mp13_clock_is_provided_by_secure(void __iomem *base,
14691469
return 0;
14701470
}
14711471

1472+
struct multi_mux {
1473+
struct clk_hw *hw1;
1474+
struct clk_hw *hw2;
1475+
};
1476+
1477+
static struct multi_mux *stm32_mp13_multi_mux[MUX_NB] = {
1478+
[MUX_SPI23] = &(struct multi_mux){ &spi2_k.hw, &spi3_k.hw },
1479+
[MUX_I2C12] = &(struct multi_mux){ &i2c1_k.hw, &i2c2_k.hw },
1480+
[MUX_LPTIM45] = &(struct multi_mux){ &lptim4_k.hw, &lptim5_k.hw },
1481+
[MUX_UART35] = &(struct multi_mux){ &usart3_k.hw, &uart5_k.hw },
1482+
[MUX_UART78] = &(struct multi_mux){ &uart7_k.hw, &uart8_k.hw },
1483+
[MUX_SAI1] = &(struct multi_mux){ &sai1_k.hw, &adfsdm_k.hw },
1484+
};
1485+
1486+
static struct clk_hw *stm32mp13_is_multi_mux(struct clk_hw *hw)
1487+
{
1488+
struct clk_stm32_composite *composite = to_clk_stm32_composite(hw);
1489+
struct multi_mux *mmux = stm32_mp13_multi_mux[composite->mux_id];
1490+
1491+
if (mmux) {
1492+
if (!(mmux->hw1 == hw))
1493+
return mmux->hw1;
1494+
else
1495+
return mmux->hw2;
1496+
}
1497+
1498+
return NULL;
1499+
}
1500+
14721501
static u16 stm32mp13_cpt_gate[GATE_NB];
14731502

14741503
static struct clk_stm32_clock_data stm32mp13_clock_data = {
14751504
.gate_cpt = stm32mp13_cpt_gate,
14761505
.gates = stm32mp13_gates,
14771506
.muxes = stm32mp13_muxes,
14781507
.dividers = stm32mp13_dividers,
1508+
.is_multi_mux = stm32mp13_is_multi_mux,
14791509
};
14801510

14811511
static const struct stm32_rcc_match_data stm32mp13_data = {

0 commit comments

Comments
 (0)