drivers/clk/mxs/clk-frac.c
Source file repositories/reference/linux-study-clean/drivers/clk/mxs/clk-frac.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/mxs/clk-frac.c- Extension
.c- Size
- 2998 bytes
- Lines
- 141
- 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_fracfunction clk_frac_recalc_ratefunction clk_frac_determine_ratefunction clk_frac_set_rate
Annotated Snippet
struct clk_frac {
struct clk_hw hw;
void __iomem *reg;
u8 shift;
u8 width;
u8 busy;
};
#define to_clk_frac(_hw) container_of(_hw, struct clk_frac, hw)
static unsigned long clk_frac_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct clk_frac *frac = to_clk_frac(hw);
u32 div;
u64 tmp_rate;
div = readl_relaxed(frac->reg) >> frac->shift;
div &= (1 << frac->width) - 1;
tmp_rate = (u64)parent_rate * div;
return tmp_rate >> frac->width;
}
static int clk_frac_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct clk_frac *frac = to_clk_frac(hw);
unsigned long parent_rate = req->best_parent_rate;
u32 div;
u64 tmp, tmp_rate, result;
if (req->rate > parent_rate)
return -EINVAL;
tmp = req->rate;
tmp <<= frac->width;
do_div(tmp, parent_rate);
div = tmp;
if (!div)
return -EINVAL;
tmp_rate = (u64)parent_rate * div;
result = tmp_rate >> frac->width;
if ((result << frac->width) < tmp_rate)
result += 1;
req->rate = result;
return 0;
}
static int clk_frac_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct clk_frac *frac = to_clk_frac(hw);
unsigned long flags;
u32 div, val;
u64 tmp;
if (rate > parent_rate)
return -EINVAL;
tmp = rate;
tmp <<= frac->width;
do_div(tmp, parent_rate);
div = tmp;
if (!div)
return -EINVAL;
spin_lock_irqsave(&mxs_lock, flags);
val = readl_relaxed(frac->reg);
val &= ~(((1 << frac->width) - 1) << frac->shift);
val |= div << frac->shift;
writel_relaxed(val, frac->reg);
spin_unlock_irqrestore(&mxs_lock, flags);
return mxs_clk_wait(frac->reg, frac->busy);
}
static const struct clk_ops clk_frac_ops = {
.recalc_rate = clk_frac_recalc_rate,
.determine_rate = clk_frac_determine_rate,
.set_rate = clk_frac_set_rate,
};
struct clk *mxs_clk_frac(const char *name, const char *parent_name,
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/err.h`, `linux/io.h`, `linux/slab.h`, `clk.h`.
- Detected declarations: `struct clk_frac`, `function clk_frac_recalc_rate`, `function clk_frac_determine_rate`, `function clk_frac_set_rate`.
- 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.