1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2022, Linaro Ltd.
6 #include <linux/clk-provider.h>
7 #include <linux/bitfield.h>
8 #include <linux/regmap.h>
9 #include <linux/export.h>
11 #include "clk-regmap.h"
12 #include "clk-regmap-phy-mux.h"
14 #define PHY_MUX_MASK GENMASK(1, 0)
15 #define PHY_MUX_PHY_SRC 0
16 #define PHY_MUX_REF_SRC 2
18 static inline struct clk_regmap_phy_mux *to_clk_regmap_phy_mux(struct clk_regmap *clkr)
20 return container_of(clkr, struct clk_regmap_phy_mux, clkr);
23 static int phy_mux_is_enabled(struct clk_hw *hw)
25 struct clk_regmap *clkr = to_clk_regmap(hw);
26 struct clk_regmap_phy_mux *phy_mux = to_clk_regmap_phy_mux(clkr);
29 regmap_read(clkr->regmap, phy_mux->reg, &val);
30 val = FIELD_GET(PHY_MUX_MASK, val);
32 WARN_ON(val != PHY_MUX_PHY_SRC && val != PHY_MUX_REF_SRC);
34 return val == PHY_MUX_PHY_SRC;
37 static int phy_mux_enable(struct clk_hw *hw)
39 struct clk_regmap *clkr = to_clk_regmap(hw);
40 struct clk_regmap_phy_mux *phy_mux = to_clk_regmap_phy_mux(clkr);
42 return regmap_update_bits(clkr->regmap, phy_mux->reg,
44 FIELD_PREP(PHY_MUX_MASK, PHY_MUX_PHY_SRC));
47 static void phy_mux_disable(struct clk_hw *hw)
49 struct clk_regmap *clkr = to_clk_regmap(hw);
50 struct clk_regmap_phy_mux *phy_mux = to_clk_regmap_phy_mux(clkr);
52 regmap_update_bits(clkr->regmap, phy_mux->reg,
54 FIELD_PREP(PHY_MUX_MASK, PHY_MUX_REF_SRC));
57 const struct clk_ops clk_regmap_phy_mux_ops = {
58 .enable = phy_mux_enable,
59 .disable = phy_mux_disable,
60 .is_enabled = phy_mux_is_enabled,
62 EXPORT_SYMBOL_GPL(clk_regmap_phy_mux_ops);