drivers/clk/mvebu/dove-divider.c
Source file repositories/reference/linux-study-clean/drivers/clk/mvebu/dove-divider.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/mvebu/dove-divider.c- Extension
.c- Size
- 5896 bytes
- Lines
- 263
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk-provider.hlinux/delay.hlinux/io.hlinux/kernel.hlinux/of.hlinux/of_address.hdove-divider.h
Detected Declarations
struct dove_clkfunction dove_load_dividerfunction dove_get_dividerfunction dove_calc_dividerfunction dove_recalc_ratefunction dove_determine_ratefunction dove_set_clockfunction dove_divider_initfunction dove_divider_clk_init
Annotated Snippet
struct dove_clk {
const char *name;
struct clk_hw hw;
void __iomem *base;
spinlock_t *lock;
u8 div_bit_start;
u8 div_bit_end;
u8 div_bit_load;
u8 div_bit_size;
u32 *divider_table;
};
enum {
DIV_CTRL0 = 0,
DIV_CTRL1 = 4,
DIV_CTRL1_N_RESET_MASK = BIT(10),
};
#define to_dove_clk(hw) container_of(hw, struct dove_clk, hw)
static void dove_load_divider(void __iomem *base, u32 val, u32 mask, u32 load)
{
u32 v;
v = readl_relaxed(base + DIV_CTRL1) | DIV_CTRL1_N_RESET_MASK;
writel_relaxed(v, base + DIV_CTRL1);
v = (readl_relaxed(base + DIV_CTRL0) & ~(mask | load)) | val;
writel_relaxed(v, base + DIV_CTRL0);
writel_relaxed(v | load, base + DIV_CTRL0);
ndelay(250);
writel_relaxed(v, base + DIV_CTRL0);
}
static unsigned int dove_get_divider(struct dove_clk *dc)
{
unsigned int divider;
u32 val;
val = readl_relaxed(dc->base + DIV_CTRL0);
val >>= dc->div_bit_start;
divider = val & ~(~0 << dc->div_bit_size);
if (dc->divider_table)
divider = dc->divider_table[divider];
return divider;
}
static int dove_calc_divider(const struct dove_clk *dc, unsigned long rate,
unsigned long parent_rate, bool set)
{
unsigned int divider, max;
divider = DIV_ROUND_CLOSEST(parent_rate, rate);
if (dc->divider_table) {
unsigned int i;
for (i = 0; dc->divider_table[i]; i++)
if (divider == dc->divider_table[i]) {
divider = i;
break;
}
if (!dc->divider_table[i])
return -EINVAL;
} else {
max = 1 << dc->div_bit_size;
if (set && (divider == 0 || divider >= max))
return -EINVAL;
if (divider >= max)
divider = max - 1;
else if (divider == 0)
divider = 1;
}
return divider;
}
static unsigned long dove_recalc_rate(struct clk_hw *hw, unsigned long parent)
{
struct dove_clk *dc = to_dove_clk(hw);
unsigned int divider = dove_get_divider(dc);
unsigned long rate = DIV_ROUND_CLOSEST(parent, divider);
pr_debug("%s(): %s divider=%u parent=%lu rate=%lu\n",
__func__, dc->name, divider, parent, rate);
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/delay.h`, `linux/io.h`, `linux/kernel.h`, `linux/of.h`, `linux/of_address.h`, `dove-divider.h`.
- Detected declarations: `struct dove_clk`, `function dove_load_divider`, `function dove_get_divider`, `function dove_calc_divider`, `function dove_recalc_rate`, `function dove_determine_rate`, `function dove_set_clock`, `function dove_divider_init`, `function dove_divider_clk_init`.
- 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.