Lines Matching +full:mux +full:-

1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/clk-provider.h>
18 #include "clk-mux.h"
35 struct mtk_clk_mux *mux = to_mtk_clk_mux(hw); in mtk_clk_mux_enable_setclr() local
38 if (mux->lock) in mtk_clk_mux_enable_setclr()
39 spin_lock_irqsave(mux->lock, flags); in mtk_clk_mux_enable_setclr()
41 __acquire(mux->lock); in mtk_clk_mux_enable_setclr()
43 regmap_write(mux->regmap, mux->data->clr_ofs, in mtk_clk_mux_enable_setclr()
44 BIT(mux->data->gate_shift)); in mtk_clk_mux_enable_setclr()
48 * not be effective yet. Set the update bit to ensure the mux gets in mtk_clk_mux_enable_setclr()
51 if (mux->reparent && mux->data->upd_shift >= 0) { in mtk_clk_mux_enable_setclr()
52 regmap_write(mux->regmap, mux->data->upd_ofs, in mtk_clk_mux_enable_setclr()
53 BIT(mux->data->upd_shift)); in mtk_clk_mux_enable_setclr()
54 mux->reparent = false; in mtk_clk_mux_enable_setclr()
57 if (mux->lock) in mtk_clk_mux_enable_setclr()
58 spin_unlock_irqrestore(mux->lock, flags); in mtk_clk_mux_enable_setclr()
60 __release(mux->lock); in mtk_clk_mux_enable_setclr()
67 struct mtk_clk_mux *mux = to_mtk_clk_mux(hw); in mtk_clk_mux_disable_setclr() local
69 regmap_write(mux->regmap, mux->data->set_ofs, in mtk_clk_mux_disable_setclr()
70 BIT(mux->data->gate_shift)); in mtk_clk_mux_disable_setclr()
75 struct mtk_clk_mux *mux = to_mtk_clk_mux(hw); in mtk_clk_mux_is_enabled() local
78 regmap_read(mux->regmap, mux->data->mux_ofs, &val); in mtk_clk_mux_is_enabled()
80 return (val & BIT(mux->data->gate_shift)) == 0; in mtk_clk_mux_is_enabled()
85 struct mtk_clk_mux *mux = to_mtk_clk_mux(hw); in mtk_clk_mux_get_parent() local
86 u32 mask = GENMASK(mux->data->mux_width - 1, 0); in mtk_clk_mux_get_parent()
89 regmap_read(mux->regmap, mux->data->mux_ofs, &val); in mtk_clk_mux_get_parent()
90 val = (val >> mux->data->mux_shift) & mask; in mtk_clk_mux_get_parent()
97 struct mtk_clk_mux *mux = to_mtk_clk_mux(hw); in mtk_clk_mux_set_parent_setclr_lock() local
98 u32 mask = GENMASK(mux->data->mux_width - 1, 0); in mtk_clk_mux_set_parent_setclr_lock()
102 if (mux->lock) in mtk_clk_mux_set_parent_setclr_lock()
103 spin_lock_irqsave(mux->lock, flags); in mtk_clk_mux_set_parent_setclr_lock()
105 __acquire(mux->lock); in mtk_clk_mux_set_parent_setclr_lock()
107 regmap_read(mux->regmap, mux->data->mux_ofs, &orig); in mtk_clk_mux_set_parent_setclr_lock()
108 val = (orig & ~(mask << mux->data->mux_shift)) in mtk_clk_mux_set_parent_setclr_lock()
109 | (index << mux->data->mux_shift); in mtk_clk_mux_set_parent_setclr_lock()
112 regmap_write(mux->regmap, mux->data->clr_ofs, in mtk_clk_mux_set_parent_setclr_lock()
113 mask << mux->data->mux_shift); in mtk_clk_mux_set_parent_setclr_lock()
114 regmap_write(mux->regmap, mux->data->set_ofs, in mtk_clk_mux_set_parent_setclr_lock()
115 index << mux->data->mux_shift); in mtk_clk_mux_set_parent_setclr_lock()
117 if (mux->data->upd_shift >= 0) { in mtk_clk_mux_set_parent_setclr_lock()
118 regmap_write(mux->regmap, mux->data->upd_ofs, in mtk_clk_mux_set_parent_setclr_lock()
119 BIT(mux->data->upd_shift)); in mtk_clk_mux_set_parent_setclr_lock()
120 mux->reparent = true; in mtk_clk_mux_set_parent_setclr_lock()
124 if (mux->lock) in mtk_clk_mux_set_parent_setclr_lock()
125 spin_unlock_irqrestore(mux->lock, flags); in mtk_clk_mux_set_parent_setclr_lock()
127 __release(mux->lock); in mtk_clk_mux_set_parent_setclr_lock()
135 struct mtk_clk_mux *mux = to_mtk_clk_mux(hw); in mtk_clk_mux_determine_rate() local
137 return clk_mux_determine_rate_flags(hw, req, mux->data->flags); in mtk_clk_mux_determine_rate()
158 const struct mtk_mux *mux, in mtk_clk_register_mux() argument
168 return ERR_PTR(-ENOMEM); in mtk_clk_register_mux()
170 init.name = mux->name; in mtk_clk_register_mux()
171 init.flags = mux->flags; in mtk_clk_register_mux()
172 init.parent_names = mux->parent_names; in mtk_clk_register_mux()
173 init.num_parents = mux->num_parents; in mtk_clk_register_mux()
174 init.ops = mux->ops; in mtk_clk_register_mux()
176 clk_mux->regmap = regmap; in mtk_clk_register_mux()
177 clk_mux->data = mux; in mtk_clk_register_mux()
178 clk_mux->lock = lock; in mtk_clk_register_mux()
179 clk_mux->hw.init = &init; in mtk_clk_register_mux()
181 ret = clk_hw_register(dev, &clk_mux->hw); in mtk_clk_register_mux()
187 return &clk_mux->hw; in mtk_clk_register_mux()
192 struct mtk_clk_mux *mux; in mtk_clk_unregister_mux() local
196 mux = to_mtk_clk_mux(hw); in mtk_clk_unregister_mux()
199 kfree(mux); in mtk_clk_unregister_mux()
219 const struct mtk_mux *mux = &muxes[i]; in mtk_clk_register_muxes() local
221 if (!IS_ERR_OR_NULL(clk_data->hws[mux->id])) { in mtk_clk_register_muxes()
223 node, mux->id); in mtk_clk_register_muxes()
227 hw = mtk_clk_register_mux(dev, mux, regmap, lock); in mtk_clk_register_muxes()
230 pr_err("Failed to register clk %s: %pe\n", mux->name, in mtk_clk_register_muxes()
235 clk_data->hws[mux->id] = hw; in mtk_clk_register_muxes()
241 while (--i >= 0) { in mtk_clk_register_muxes()
242 const struct mtk_mux *mux = &muxes[i]; in mtk_clk_register_muxes() local
244 if (IS_ERR_OR_NULL(clk_data->hws[mux->id])) in mtk_clk_register_muxes()
247 mtk_clk_unregister_mux(clk_data->hws[mux->id]); in mtk_clk_register_muxes()
248 clk_data->hws[mux->id] = ERR_PTR(-ENOENT); in mtk_clk_register_muxes()
263 for (i = num; i > 0; i--) { in mtk_clk_unregister_muxes()
264 const struct mtk_mux *mux = &muxes[i - 1]; in mtk_clk_unregister_muxes() local
266 if (IS_ERR_OR_NULL(clk_data->hws[mux->id])) in mtk_clk_unregister_muxes()
269 mtk_clk_unregister_mux(clk_data->hws[mux->id]); in mtk_clk_unregister_muxes()
270 clk_data->hws[mux->id] = ERR_PTR(-ENOENT); in mtk_clk_unregister_muxes()
285 struct clk_hw *hw = __clk_get_hw(data->clk); in mtk_clk_mux_notifier_cb()
291 mux_nb->original_index = mux_nb->ops->get_parent(hw); in mtk_clk_mux_notifier_cb()
292 ret = mux_nb->ops->set_parent(hw, mux_nb->bypass_index); in mtk_clk_mux_notifier_cb()
296 ret = mux_nb->ops->set_parent(hw, mux_nb->original_index); in mtk_clk_mux_notifier_cb()
306 mux_nb->nb.notifier_call = mtk_clk_mux_notifier_cb; in devm_mtk_clk_mux_notifier_register()
308 return devm_clk_notifier_register(dev, clk, &mux_nb->nb); in devm_mtk_clk_mux_notifier_register()