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

Brian Masney masneyb at kernel.org
Tue Dec 1 08:49:24 PST 2026


Hi Gabriel,

> 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, as the generic clk-mux does. 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,
> and setting a parent index not in the table is refused.
> 
> Signed-off-by: Gabriel Fernandez <gabriel.fernandez at foss.st.com>
> ---
>  drivers/clk/stm32/clk-stm32-core.c | 35 +++++++++++++++++++++++++++++------
>  drivers/clk/stm32/clk-stm32-core.h |  3 ++-
>  2 files changed, 31 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/clk/stm32/clk-stm32-core.c b/drivers/clk/stm32/clk-stm32-core.c
> index e921c25a929c..2e42ff17ad3d 100644
> --- a/drivers/clk/stm32/clk-stm32-core.c
> +++ b/drivers/clk/stm32/clk-stm32-core.c
> @@ -9,6 +9,7 @@
>  #include <linux/device.h>
>  #include <linux/err.h>
>  #include <linux/io.h>
> +#include <linux/limits.h>
>  #include <linux/of.h>
>  #include <linux/of_address.h>
>  #include <linux/slab.h>
> @@ -105,11 +106,20 @@ static u8 stm32_mux_get_parent(void __iomem *base,
>  	const struct stm32_mux_cfg *mux = &data->muxes[mux_id];
>  	u32 mask = BIT(mux->width) - 1;
>  	u32 val;
> +	int i;
>  
>  	val = readl(base + mux->offset) >> mux->shift;
>  	val &= mask;
>  
> -	return val;
> +	if (!mux->table)
> +		return val;
> +
> +	for (i = 0; i < mux->num_table; i++)
> +		if (mux->table[i] == val)
> +			return i;
> +
> +	/* u8 return type: report an invalid index (>= num_parents) */
> +	return U8_MAX;

You can probably simplify this with clk_mux_val_to_index(). You should
be able to also drop the num_table field.

Brian

-- 
Brian Masney <masneyb at kernel.org>



More information about the linux-arm-kernel mailing list