drivers/clk/imx/clk-fixup-div.c
Source file repositories/reference/linux-study-clean/drivers/clk/imx/clk-fixup-div.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/imx/clk-fixup-div.c- Extension
.c- Size
- 3076 bytes
- Lines
- 128
- 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/clk-provider.hlinux/err.hlinux/io.hlinux/slab.hclk.h
Detected Declarations
struct clk_fixup_divfunction clk_fixup_div_recalc_ratefunction clk_fixup_div_determine_ratefunction clk_fixup_div_set_ratefunction void
Annotated Snippet
struct clk_fixup_div {
struct clk_divider divider;
const struct clk_ops *ops;
void (*fixup)(u32 *val);
};
static inline struct clk_fixup_div *to_clk_fixup_div(struct clk_hw *hw)
{
struct clk_divider *divider = to_clk_divider(hw);
return container_of(divider, struct clk_fixup_div, divider);
}
static unsigned long clk_fixup_div_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct clk_fixup_div *fixup_div = to_clk_fixup_div(hw);
return fixup_div->ops->recalc_rate(&fixup_div->divider.hw, parent_rate);
}
static int clk_fixup_div_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct clk_fixup_div *fixup_div = to_clk_fixup_div(hw);
return fixup_div->ops->determine_rate(&fixup_div->divider.hw, req);
}
static int clk_fixup_div_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct clk_fixup_div *fixup_div = to_clk_fixup_div(hw);
struct clk_divider *div = to_clk_divider(hw);
unsigned int divider, value;
unsigned long flags;
u32 val;
divider = parent_rate / rate;
/* Zero based divider */
value = divider - 1;
if (value > div_mask(div))
value = div_mask(div);
spin_lock_irqsave(div->lock, flags);
val = readl(div->reg);
val &= ~(div_mask(div) << div->shift);
val |= value << div->shift;
fixup_div->fixup(&val);
writel(val, div->reg);
spin_unlock_irqrestore(div->lock, flags);
return 0;
}
static const struct clk_ops clk_fixup_div_ops = {
.recalc_rate = clk_fixup_div_recalc_rate,
.determine_rate = clk_fixup_div_determine_rate,
.set_rate = clk_fixup_div_set_rate,
};
struct clk_hw *imx_clk_hw_fixup_divider(const char *name, const char *parent,
void __iomem *reg, u8 shift, u8 width,
void (*fixup)(u32 *val))
{
struct clk_fixup_div *fixup_div;
struct clk_hw *hw;
struct clk_init_data init;
int ret;
if (!fixup)
return ERR_PTR(-EINVAL);
fixup_div = kzalloc_obj(*fixup_div);
if (!fixup_div)
return ERR_PTR(-ENOMEM);
init.name = name;
init.ops = &clk_fixup_div_ops;
init.flags = CLK_SET_RATE_PARENT;
init.parent_names = parent ? &parent : NULL;
init.num_parents = parent ? 1 : 0;
fixup_div->divider.reg = reg;
fixup_div->divider.shift = shift;
fixup_div->divider.width = width;
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/err.h`, `linux/io.h`, `linux/slab.h`, `clk.h`.
- Detected declarations: `struct clk_fixup_div`, `function clk_fixup_div_recalc_rate`, `function clk_fixup_div_determine_rate`, `function clk_fixup_div_set_rate`, `function void`.
- 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.