drivers/clk/rockchip/clk-cpu.c
Source file repositories/reference/linux-study-clean/drivers/clk/rockchip/clk-cpu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/rockchip/clk-cpu.c- Extension
.c- Size
- 16539 bytes
- Lines
- 564
- Domain
- Driver Families
- Bucket
- drivers/clk
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/of.hlinux/slab.hlinux/io.hlinux/clk.hlinux/clk-provider.hclk.h
Detected Declarations
struct rockchip_cpuclkfunction container_offunction rockchip_cpuclk_recalc_ratefunction rockchip_cpuclk_set_dividersfunction rockchip_cpuclk_set_pre_muxsfunction rockchip_cpuclk_set_post_muxsfunction rockchip_cpuclk_pre_rate_changefunction rockchip_cpuclk_post_rate_changefunction rockchip_cpuclk_notifier_cbfunction rockchip_cpuclk_multi_pll_pre_rate_changefunction rockchip_cpuclk_multi_pll_post_rate_changefunction rockchip_cpuclk_multi_pll_notifier_cb
Annotated Snippet
struct rockchip_cpuclk {
struct clk_hw hw;
struct clk *alt_parent;
void __iomem *reg_base;
struct notifier_block clk_nb;
unsigned int rate_count;
struct rockchip_cpuclk_rate_table *rate_table;
const struct rockchip_cpuclk_reg_data *reg_data;
spinlock_t *lock;
};
#define to_rockchip_cpuclk_hw(hw) container_of(hw, struct rockchip_cpuclk, hw)
#define to_rockchip_cpuclk_nb(nb) \
container_of(nb, struct rockchip_cpuclk, clk_nb)
static const struct rockchip_cpuclk_rate_table *rockchip_get_cpuclk_settings(
struct rockchip_cpuclk *cpuclk, unsigned long rate)
{
const struct rockchip_cpuclk_rate_table *rate_table =
cpuclk->rate_table;
int i;
for (i = 0; i < cpuclk->rate_count; i++) {
if (rate == rate_table[i].prate)
return &rate_table[i];
}
return NULL;
}
static unsigned long rockchip_cpuclk_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct rockchip_cpuclk *cpuclk = to_rockchip_cpuclk_hw(hw);
const struct rockchip_cpuclk_reg_data *reg_data = cpuclk->reg_data;
u32 clksel0 = readl_relaxed(cpuclk->reg_base + reg_data->core_reg[0]);
clksel0 >>= reg_data->div_core_shift[0];
clksel0 &= reg_data->div_core_mask[0];
return parent_rate / (clksel0 + 1);
}
static const struct clk_ops rockchip_cpuclk_ops = {
.recalc_rate = rockchip_cpuclk_recalc_rate,
};
static void rockchip_cpuclk_set_dividers(struct rockchip_cpuclk *cpuclk,
const struct rockchip_cpuclk_rate_table *rate)
{
int i;
/* alternate parent is active now. set the dividers */
for (i = 0; i < ARRAY_SIZE(rate->divs); i++) {
const struct rockchip_cpuclk_clksel *clksel = &rate->divs[i];
if (!clksel->reg)
continue;
pr_debug("%s: setting reg 0x%x to 0x%x\n",
__func__, clksel->reg, clksel->val);
writel(clksel->val, cpuclk->reg_base + clksel->reg);
}
}
static void rockchip_cpuclk_set_pre_muxs(struct rockchip_cpuclk *cpuclk,
const struct rockchip_cpuclk_rate_table *rate)
{
int i;
/* alternate parent is active now. set the pre_muxs */
for (i = 0; i < ARRAY_SIZE(rate->pre_muxs); i++) {
const struct rockchip_cpuclk_clksel *clksel = &rate->pre_muxs[i];
if (!clksel->reg)
break;
pr_debug("%s: setting reg 0x%x to 0x%x\n",
__func__, clksel->reg, clksel->val);
writel(clksel->val, cpuclk->reg_base + clksel->reg);
}
}
static void rockchip_cpuclk_set_post_muxs(struct rockchip_cpuclk *cpuclk,
const struct rockchip_cpuclk_rate_table *rate)
{
int i;
/* alternate parent is active now. set the muxs */
for (i = 0; i < ARRAY_SIZE(rate->post_muxs); i++) {
const struct rockchip_cpuclk_clksel *clksel = &rate->post_muxs[i];
Annotation
- Immediate include surface: `linux/of.h`, `linux/slab.h`, `linux/io.h`, `linux/clk.h`, `linux/clk-provider.h`, `clk.h`.
- Detected declarations: `struct rockchip_cpuclk`, `function container_of`, `function rockchip_cpuclk_recalc_rate`, `function rockchip_cpuclk_set_dividers`, `function rockchip_cpuclk_set_pre_muxs`, `function rockchip_cpuclk_set_post_muxs`, `function rockchip_cpuclk_pre_rate_change`, `function rockchip_cpuclk_post_rate_change`, `function rockchip_cpuclk_notifier_cb`, `function rockchip_cpuclk_multi_pll_pre_rate_change`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: source 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.