Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / clk / qcom / clk-regmap-mux.c
blobb2d00b4519634614d2b6e1dfd6e1f648440e0321
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
4 */
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);
23 unsigned int val;
25 regmap_read(clkr->regmap, mux->reg, &val);
27 val >>= mux->shift;
28 val &= mask;
30 if (mux->parent_map)
31 return qcom_find_src_index(hw, mux->parent_map, val);
33 return 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);
41 unsigned int val;
43 if (mux->parent_map)
44 index = mux->parent_map[index].cfg;
46 val = index;
47 val <<= mux->shift;
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);