1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
6 #include <linux/kernel.h>
7 #include <linux/bitops.h>
8 #include <linux/regmap.h>
9 #include <linux/export.h>
11 #include "clk-regmap-mux.h"
13 static inline struct clk_regmap_mux
*to_clk_regmap_mux(struct clk_hw
*hw
)
15 return container_of(to_clk_regmap(hw
), struct clk_regmap_mux
, clkr
);
18 static u8
mux_get_parent(struct clk_hw
*hw
)
20 struct clk_regmap_mux
*mux
= to_clk_regmap_mux(hw
);
21 struct clk_regmap
*clkr
= to_clk_regmap(hw
);
22 unsigned int mask
= GENMASK(mux
->width
- 1, 0);
25 regmap_read(clkr
->regmap
, mux
->reg
, &val
);
31 return qcom_find_src_index(hw
, mux
->parent_map
, val
);
36 static int mux_set_parent(struct clk_hw
*hw
, u8 index
)
38 struct clk_regmap_mux
*mux
= to_clk_regmap_mux(hw
);
39 struct clk_regmap
*clkr
= to_clk_regmap(hw
);
40 unsigned int mask
= GENMASK(mux
->width
+ mux
->shift
- 1, mux
->shift
);
44 index
= mux
->parent_map
[index
].cfg
;
49 return regmap_update_bits(clkr
->regmap
, mux
->reg
, mask
, val
);
52 const struct clk_ops clk_regmap_mux_closest_ops
= {
53 .get_parent
= mux_get_parent
,
54 .set_parent
= mux_set_parent
,
55 .determine_rate
= __clk_mux_determine_rate_closest
,
57 EXPORT_SYMBOL_GPL(clk_regmap_mux_closest_ops
);