drivers/clk/mediatek/clk-gate.c
Source file repositories/reference/linux-study-clean/drivers/clk/mediatek/clk-gate.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/mediatek/clk-gate.c- Extension
.c- Size
- 7403 bytes
- Lines
- 337
- 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.
- 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-provider.hlinux/dev_printk.hlinux/mfd/syscon.hlinux/module.hlinux/printk.hlinux/regmap.hlinux/slab.hlinux/types.hclk-mtk.hclk-gate.h
Detected Declarations
struct mtk_clk_gatefunction mtk_get_clockgatingfunction mtk_cg_bit_is_clearedfunction mtk_cg_bit_is_setfunction mtk_cg_set_bitfunction mtk_cg_clr_bitfunction mtk_cg_set_bit_no_setclrfunction mtk_cg_clr_bit_no_setclrfunction mtk_cg_enablefunction mtk_cg_disablefunction mtk_cg_enable_invfunction mtk_cg_disable_invfunction mtk_cg_hwv_set_enfunction mtk_cg_hwv_enablefunction mtk_cg_hwv_disablefunction mtk_cg_enable_no_setclrfunction mtk_cg_disable_no_setclrfunction mtk_cg_enable_inv_no_setclrfunction mtk_cg_disable_inv_no_setclrfunction mtk_cg_uses_hwvfunction mtk_clk_unregister_gatefunction mtk_clk_register_gatesfunction mtk_clk_unregister_gatesexport mtk_clk_gate_ops_setclrexport mtk_clk_gate_ops_setclr_invexport mtk_clk_gate_hwv_ops_setclrexport mtk_clk_gate_hwv_ops_setclr_invexport mtk_clk_gate_ops_no_setclrexport mtk_clk_gate_ops_no_setclr_invexport mtk_clk_register_gatesexport mtk_clk_unregister_gates
Annotated Snippet
struct mtk_clk_gate {
struct clk_hw hw;
struct regmap *regmap;
struct regmap *regmap_hwv;
const struct mtk_gate *gate;
};
static inline struct mtk_clk_gate *to_mtk_clk_gate(struct clk_hw *hw)
{
return container_of(hw, struct mtk_clk_gate, hw);
}
static u32 mtk_get_clockgating(struct clk_hw *hw)
{
struct mtk_clk_gate *cg = to_mtk_clk_gate(hw);
u32 val;
regmap_read(cg->regmap, cg->gate->regs->sta_ofs, &val);
return val & BIT(cg->gate->shift);
}
static int mtk_cg_bit_is_cleared(struct clk_hw *hw)
{
return mtk_get_clockgating(hw) == 0;
}
static int mtk_cg_bit_is_set(struct clk_hw *hw)
{
return mtk_get_clockgating(hw) != 0;
}
static void mtk_cg_set_bit(struct clk_hw *hw)
{
struct mtk_clk_gate *cg = to_mtk_clk_gate(hw);
regmap_write(cg->regmap, cg->gate->regs->set_ofs, BIT(cg->gate->shift));
}
static void mtk_cg_clr_bit(struct clk_hw *hw)
{
struct mtk_clk_gate *cg = to_mtk_clk_gate(hw);
regmap_write(cg->regmap, cg->gate->regs->clr_ofs, BIT(cg->gate->shift));
}
static void mtk_cg_set_bit_no_setclr(struct clk_hw *hw)
{
struct mtk_clk_gate *cg = to_mtk_clk_gate(hw);
regmap_set_bits(cg->regmap, cg->gate->regs->sta_ofs,
BIT(cg->gate->shift));
}
static void mtk_cg_clr_bit_no_setclr(struct clk_hw *hw)
{
struct mtk_clk_gate *cg = to_mtk_clk_gate(hw);
regmap_clear_bits(cg->regmap, cg->gate->regs->sta_ofs,
BIT(cg->gate->shift));
}
static int mtk_cg_enable(struct clk_hw *hw)
{
mtk_cg_clr_bit(hw);
return 0;
}
static void mtk_cg_disable(struct clk_hw *hw)
{
mtk_cg_set_bit(hw);
}
static int mtk_cg_enable_inv(struct clk_hw *hw)
{
mtk_cg_set_bit(hw);
return 0;
}
static void mtk_cg_disable_inv(struct clk_hw *hw)
{
mtk_cg_clr_bit(hw);
}
static int mtk_cg_hwv_set_en(struct clk_hw *hw, bool enable)
{
struct mtk_clk_gate *cg = to_mtk_clk_gate(hw);
u32 val;
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/dev_printk.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/printk.h`, `linux/regmap.h`, `linux/slab.h`, `linux/types.h`.
- Detected declarations: `struct mtk_clk_gate`, `function mtk_get_clockgating`, `function mtk_cg_bit_is_cleared`, `function mtk_cg_bit_is_set`, `function mtk_cg_set_bit`, `function mtk_cg_clr_bit`, `function mtk_cg_set_bit_no_setclr`, `function mtk_cg_clr_bit_no_setclr`, `function mtk_cg_enable`, `function mtk_cg_disable`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: integration implementation candidate.
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.