[PATCH v2 1/2] clk: stm32: add support for a parent table in the muxes

Gabriel Fernandez gabriel.fernandez at foss.st.com
Wed Dec 2 07:54:24 PST 2026


Some muxes have values of their selector field that are reserved and
must not be selected, so the parent index can't always be taken as the
register value.

struct stm32_mux_cfg already has a table member that is not used by the
muxes. Use it to translate between the parent index and the value of the
selector field with clk_mux_val_to_index() and clk_mux_index_to_val(), as
the generic clk-mux does. The table must have one entry per parent. When
no table is provided, the behavior is unchanged.

A value read from the hardware that is not in the table is reported as an
out of range index, so the clock is seen as an orphan by the framework.

Signed-off-by: Gabriel Fernandez <gabriel.fernandez at foss.st.com>
---
 drivers/clk/stm32/clk-stm32-core.c | 11 ++++++-----
 drivers/clk/stm32/clk-stm32-core.h |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/stm32/clk-stm32-core.c b/drivers/clk/stm32/clk-stm32-core.c
index edabc160a6f2..0c0a847d0e65 100644
--- a/drivers/clk/stm32/clk-stm32-core.c
+++ b/drivers/clk/stm32/clk-stm32-core.c
@@ -98,7 +98,7 @@ int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
 	return 0;
 }
 
-static u8 stm32_mux_get_parent(void __iomem *base,
+static u8 stm32_mux_get_parent(struct clk_hw *hw, void __iomem *base,
 			       struct clk_stm32_clock_data *data,
 			       u16 mux_id)
 {
@@ -109,7 +109,7 @@ static u8 stm32_mux_get_parent(void __iomem *base,
 	val = readl(base + mux->offset) >> mux->shift;
 	val &= mask;
 
-	return val;
+	return clk_mux_val_to_index(hw, mux->table, 0, val);
 }
 
 static int stm32_mux_set_parent(void __iomem *base,
@@ -120,7 +120,7 @@ static int stm32_mux_set_parent(void __iomem *base,
 
 	u32 mask = BIT(mux->width) - 1;
 	u32 reg = readl(base + mux->offset);
-	u32 val = index << mux->shift;
+	u32 val = clk_mux_index_to_val(mux->table, 0, index) << mux->shift;
 
 	reg &= ~(mask << mux->shift);
 	reg |= val;
@@ -259,7 +259,7 @@ static u8 clk_stm32_mux_get_parent(struct clk_hw *hw)
 {
 	struct clk_stm32_mux *mux = to_clk_stm32_mux(hw);
 
-	return stm32_mux_get_parent(mux->base, mux->clock_data, mux->mux_id);
+	return stm32_mux_get_parent(hw, mux->base, mux->clock_data, mux->mux_id);
 }
 
 static int clk_stm32_mux_set_parent(struct clk_hw *hw, u8 index)
@@ -459,7 +459,8 @@ static u8 clk_stm32_composite_get_parent(struct clk_hw *hw)
 {
 	struct clk_stm32_composite *composite = to_clk_stm32_composite(hw);
 
-	return stm32_mux_get_parent(composite->base, composite->clock_data, composite->mux_id);
+	return stm32_mux_get_parent(hw, composite->base, composite->clock_data,
+				    composite->mux_id);
 }
 
 static int clk_stm32_composite_set_parent(struct clk_hw *hw, u8 index)
diff --git a/drivers/clk/stm32/clk-stm32-core.h b/drivers/clk/stm32/clk-stm32-core.h
index 4be103710e12..813d7e874f82 100644
--- a/drivers/clk/stm32/clk-stm32-core.h
+++ b/drivers/clk/stm32/clk-stm32-core.h
@@ -13,7 +13,7 @@ struct stm32_mux_cfg {
 	u8	shift;
 	u8	width;
 	u8	flags;
-	u32	*table;
+	const u32 *table;
 	u8	ready;
 };
 

-- 
2.43.0




More information about the linux-arm-kernel mailing list