drivers/clk/mediatek/clk-mux.c
Source file repositories/reference/linux-study-clean/drivers/clk/mediatek/clk-mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/mediatek/clk-mux.c- Extension
.c- Size
- 10845 bytes
- Lines
- 443
- Domain
- Driver Families
- Bucket
- drivers/clk
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/clk-provider.hlinux/compiler_types.hlinux/container_of.hlinux/dev_printk.hlinux/err.hlinux/mfd/syscon.hlinux/module.hlinux/regmap.hlinux/spinlock.hlinux/slab.hclk-mtk.hclk-mux.h
Detected Declarations
struct mtk_clk_muxfunction mtk_clk_mux_fenc_enable_setclrfunction mtk_clk_mux_enable_setclrfunction mtk_clk_mux_disable_setclrfunction mtk_clk_mux_fenc_is_enabledfunction mtk_clk_mux_is_enabledfunction mtk_clk_mux_hwv_fenc_enablefunction mtk_clk_mux_hwv_disablefunction mtk_clk_mux_get_parentfunction mtk_clk_mux_set_parent_setclr_lockfunction mtk_clk_mux_determine_ratefunction mtk_clk_mux_uses_hwvfunction mtk_clk_unregister_muxfunction mtk_clk_register_muxesfunction mtk_clk_unregister_muxesfunction mtk_clk_mux_notifier_cbfunction devm_mtk_clk_mux_notifier_registerexport mtk_mux_clr_set_upd_opsexport mtk_mux_gate_clr_set_upd_opsexport mtk_mux_gate_fenc_clr_set_upd_opsexport mtk_mux_gate_hwv_fenc_clr_set_upd_opsexport mtk_clk_register_muxesexport mtk_clk_unregister_muxesexport devm_mtk_clk_mux_notifier_register
Annotated Snippet
struct mtk_clk_mux {
struct clk_hw hw;
struct regmap *regmap;
struct regmap *regmap_hwv;
const struct mtk_mux *data;
spinlock_t *lock;
bool reparent;
};
static inline struct mtk_clk_mux *to_mtk_clk_mux(struct clk_hw *hw)
{
return container_of(hw, struct mtk_clk_mux, hw);
}
static int mtk_clk_mux_fenc_enable_setclr(struct clk_hw *hw)
{
struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
unsigned long flags;
u32 val;
int ret;
if (mux->lock)
spin_lock_irqsave(mux->lock, flags);
else
__acquire(mux->lock);
regmap_write(mux->regmap, mux->data->clr_ofs,
BIT(mux->data->gate_shift));
ret = regmap_read_poll_timeout_atomic(mux->regmap, mux->data->fenc_sta_mon_ofs,
val, val & BIT(mux->data->fenc_shift), 1,
MTK_WAIT_FENC_DONE_US);
if (mux->lock)
spin_unlock_irqrestore(mux->lock, flags);
else
__release(mux->lock);
return ret;
}
static int mtk_clk_mux_enable_setclr(struct clk_hw *hw)
{
struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
unsigned long flags = 0;
if (mux->lock)
spin_lock_irqsave(mux->lock, flags);
else
__acquire(mux->lock);
regmap_write(mux->regmap, mux->data->clr_ofs,
BIT(mux->data->gate_shift));
/*
* If the parent has been changed when the clock was disabled, it will
* not be effective yet. Set the update bit to ensure the mux gets
* updated.
*/
if (mux->reparent && mux->data->upd_shift >= 0) {
regmap_write(mux->regmap, mux->data->upd_ofs,
BIT(mux->data->upd_shift));
mux->reparent = false;
}
if (mux->lock)
spin_unlock_irqrestore(mux->lock, flags);
else
__release(mux->lock);
return 0;
}
static void mtk_clk_mux_disable_setclr(struct clk_hw *hw)
{
struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
regmap_write(mux->regmap, mux->data->set_ofs,
BIT(mux->data->gate_shift));
}
static int mtk_clk_mux_fenc_is_enabled(struct clk_hw *hw)
{
struct mtk_clk_mux *mux = to_mtk_clk_mux(hw);
u32 val;
regmap_read(mux->regmap, mux->data->fenc_sta_mon_ofs, &val);
return !!(val & BIT(mux->data->fenc_shift));
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/compiler_types.h`, `linux/container_of.h`, `linux/dev_printk.h`, `linux/err.h`, `linux/mfd/syscon.h`, `linux/module.h`.
- Detected declarations: `struct mtk_clk_mux`, `function mtk_clk_mux_fenc_enable_setclr`, `function mtk_clk_mux_enable_setclr`, `function mtk_clk_mux_disable_setclr`, `function mtk_clk_mux_fenc_is_enabled`, `function mtk_clk_mux_is_enabled`, `function mtk_clk_mux_hwv_fenc_enable`, `function mtk_clk_mux_hwv_disable`, `function mtk_clk_mux_get_parent`, `function mtk_clk_mux_set_parent_setclr_lock`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.