15 #include <linux/module.h>
16 #include <linux/slab.h>
30 #define to_clk_mux(_hw) container_of(_hw, struct clk_mux, hw)
32 static u8 clk_mux_get_parent(
struct clk_hw *
hw)
44 val =
readl(mux->reg) >> mux->shift;
45 val &= (1 << mux->width) - 1;
47 if (val && (mux->flags & CLK_MUX_INDEX_BIT))
50 if (val && (mux->flags & CLK_MUX_INDEX_ONE))
59 static int clk_mux_set_parent(
struct clk_hw *
hw,
u8 index)
63 unsigned long flags = 0;
65 if (mux->flags & CLK_MUX_INDEX_BIT)
66 index = (1 <<
ffs(index));
68 if (mux->flags & CLK_MUX_INDEX_ONE)
74 val =
readl(mux->reg);
75 val &= ~(((1 << mux->width) - 1) << mux->shift);
76 val |= index << mux->shift;
80 spin_unlock_irqrestore(mux->lock, flags);
86 .get_parent = clk_mux_get_parent,
87 .set_parent = clk_mux_set_parent,
92 const char **parent_names,
u8 num_parents,
unsigned long flags,
98 struct clk_init_data init;
101 mux = kzalloc(
sizeof(
struct clk_mux),
GFP_KERNEL);
103 pr_err(
"%s: could not allocate mux clk\n", __func__);
109 init.flags = flags | CLK_IS_BASIC;
110 init.parent_names = parent_names;
111 init.num_parents = num_parents;
117 mux->flags = clk_mux_flags;
119 mux->hw.init = &
init;