drivers/clk/imx/clk-cpu.c
Source file repositories/reference/linux-study-clean/drivers/clk/imx/clk-cpu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/imx/clk-cpu.c- Extension
.c- Size
- 2210 bytes
- Lines
- 111
- 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.hlinux/clk-provider.hlinux/export.hlinux/slab.hclk.h
Detected Declarations
struct clk_cpufunction clk_cpu_recalc_ratefunction clk_cpu_determine_ratefunction clk_cpu_set_rateexport imx_clk_hw_cpu
Annotated Snippet
struct clk_cpu {
struct clk_hw hw;
struct clk *div;
struct clk *mux;
struct clk *pll;
struct clk *step;
};
static inline struct clk_cpu *to_clk_cpu(struct clk_hw *hw)
{
return container_of(hw, struct clk_cpu, hw);
}
static unsigned long clk_cpu_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct clk_cpu *cpu = to_clk_cpu(hw);
return clk_get_rate(cpu->div);
}
static int clk_cpu_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct clk_cpu *cpu = to_clk_cpu(hw);
req->rate = clk_round_rate(cpu->pll, req->rate);
return 0;
}
static int clk_cpu_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct clk_cpu *cpu = to_clk_cpu(hw);
int ret;
/* switch to PLL bypass clock */
ret = clk_set_parent(cpu->mux, cpu->step);
if (ret)
return ret;
/* reprogram PLL */
ret = clk_set_rate(cpu->pll, rate);
if (ret) {
clk_set_parent(cpu->mux, cpu->pll);
return ret;
}
/* switch back to PLL clock */
clk_set_parent(cpu->mux, cpu->pll);
/* Ensure the divider is what we expect */
clk_set_rate(cpu->div, rate);
return 0;
}
static const struct clk_ops clk_cpu_ops = {
.recalc_rate = clk_cpu_recalc_rate,
.determine_rate = clk_cpu_determine_rate,
.set_rate = clk_cpu_set_rate,
};
struct clk_hw *imx_clk_hw_cpu(const char *name, const char *parent_name,
struct clk *div, struct clk *mux, struct clk *pll,
struct clk *step)
{
struct clk_cpu *cpu;
struct clk_hw *hw;
struct clk_init_data init;
int ret;
cpu = kzalloc_obj(*cpu);
if (!cpu)
return ERR_PTR(-ENOMEM);
cpu->div = div;
cpu->mux = mux;
cpu->pll = pll;
cpu->step = step;
init.name = name;
init.ops = &clk_cpu_ops;
init.flags = CLK_IS_CRITICAL;
init.parent_names = &parent_name;
init.num_parents = 1;
cpu->hw.init = &init;
hw = &cpu->hw;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/export.h`, `linux/slab.h`, `clk.h`.
- Detected declarations: `struct clk_cpu`, `function clk_cpu_recalc_rate`, `function clk_cpu_determine_rate`, `function clk_cpu_set_rate`, `export imx_clk_hw_cpu`.
- 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.