drivers/clk/imx/clk-pfd.c
Source file repositories/reference/linux-study-clean/drivers/clk/imx/clk-pfd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/imx/clk-pfd.c- Extension
.c- Size
- 3223 bytes
- Lines
- 160
- 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-provider.hlinux/export.hlinux/io.hlinux/slab.hlinux/err.hclk.h
Detected Declarations
struct clk_pfdfunction clk_pfd_enablefunction clk_pfd_disablefunction clk_pfd_recalc_ratefunction clk_pfd_determine_ratefunction clk_pfd_set_ratefunction clk_pfd_is_enabledexport imx_clk_hw_pfd
Annotated Snippet
struct clk_pfd {
struct clk_hw hw;
void __iomem *reg;
u8 idx;
};
#define to_clk_pfd(_hw) container_of(_hw, struct clk_pfd, hw)
#define SET 0x4
#define CLR 0x8
#define OTG 0xc
static int clk_pfd_enable(struct clk_hw *hw)
{
struct clk_pfd *pfd = to_clk_pfd(hw);
writel_relaxed(1 << ((pfd->idx + 1) * 8 - 1), pfd->reg + CLR);
return 0;
}
static void clk_pfd_disable(struct clk_hw *hw)
{
struct clk_pfd *pfd = to_clk_pfd(hw);
writel_relaxed(1 << ((pfd->idx + 1) * 8 - 1), pfd->reg + SET);
}
static unsigned long clk_pfd_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct clk_pfd *pfd = to_clk_pfd(hw);
u64 tmp = parent_rate;
u8 frac = (readl_relaxed(pfd->reg) >> (pfd->idx * 8)) & 0x3f;
tmp *= 18;
do_div(tmp, frac);
return tmp;
}
static int clk_pfd_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
u64 tmp = req->best_parent_rate;
u8 frac;
tmp = tmp * 18 + req->rate / 2;
do_div(tmp, req->rate);
frac = tmp;
if (frac < 12)
frac = 12;
else if (frac > 35)
frac = 35;
tmp = req->best_parent_rate;
tmp *= 18;
do_div(tmp, frac);
req->rate = tmp;
return 0;
}
static int clk_pfd_set_rate(struct clk_hw *hw, unsigned long rate,
unsigned long parent_rate)
{
struct clk_pfd *pfd = to_clk_pfd(hw);
u64 tmp = parent_rate;
u8 frac;
tmp = tmp * 18 + rate / 2;
do_div(tmp, rate);
frac = tmp;
if (frac < 12)
frac = 12;
else if (frac > 35)
frac = 35;
writel_relaxed(0x3f << (pfd->idx * 8), pfd->reg + CLR);
writel_relaxed(frac << (pfd->idx * 8), pfd->reg + SET);
return 0;
}
static int clk_pfd_is_enabled(struct clk_hw *hw)
{
struct clk_pfd *pfd = to_clk_pfd(hw);
if (readl_relaxed(pfd->reg) & (1 << ((pfd->idx + 1) * 8 - 1)))
return 0;
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/export.h`, `linux/io.h`, `linux/slab.h`, `linux/err.h`, `clk.h`.
- Detected declarations: `struct clk_pfd`, `function clk_pfd_enable`, `function clk_pfd_disable`, `function clk_pfd_recalc_rate`, `function clk_pfd_determine_rate`, `function clk_pfd_set_rate`, `function clk_pfd_is_enabled`, `export imx_clk_hw_pfd`.
- 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.