1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/kernel.h>
15#include <linux/bitops.h>
16#include <linux/regmap.h>
17#include <linux/export.h>
18
19#include "clk-regmap-mux.h"
20
21static inline struct clk_regmap_mux *to_clk_regmap_mux(struct clk_hw *hw)
22{
23 return container_of(to_clk_regmap(hw), struct clk_regmap_mux, clkr);
24}
25
26static u8 mux_get_parent(struct clk_hw *hw)
27{
28 struct clk_regmap_mux *mux = to_clk_regmap_mux(hw);
29 struct clk_regmap *clkr = to_clk_regmap(hw);
30 unsigned int mask = GENMASK(mux->width - 1, 0);
31 unsigned int val;
32
33 regmap_read(clkr->regmap, mux->reg, &val);
34
35 val >>= mux->shift;
36 val &= mask;
37
38 return val;
39}
40
41static int mux_set_parent(struct clk_hw *hw, u8 index)
42{
43 struct clk_regmap_mux *mux = to_clk_regmap_mux(hw);
44 struct clk_regmap *clkr = to_clk_regmap(hw);
45 unsigned int mask = GENMASK(mux->width + mux->shift - 1, mux->shift);
46 unsigned int val;
47
48 val = index;
49 val <<= mux->shift;
50
51 return regmap_update_bits(clkr->regmap, mux->reg, mask, val);
52}
53
54const struct clk_ops clk_regmap_mux_closest_ops = {
55 .get_parent = mux_get_parent,
56 .set_parent = mux_set_parent,
57 .determine_rate = __clk_mux_determine_rate_closest,
58};
59EXPORT_SYMBOL_GPL(clk_regmap_mux_closest_ops);
60