drivers/clk/at91/clk-main.c
Source file repositories/reference/linux-study-clean/drivers/clk/at91/clk-main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/at91/clk-main.c- Extension
.c- Size
- 13707 bytes
- Lines
- 597
- 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.
- 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/clkdev.hlinux/clk/at91_pmc.hlinux/delay.hlinux/mfd/syscon.hlinux/regmap.hpmc.h
Detected Declarations
struct clk_main_oscstruct clk_main_rc_oscstruct clk_rm9200_mainstruct clk_sam9x5_mainfunction clk_main_osc_readyfunction clk_main_osc_preparefunction clk_main_osc_unpreparefunction clk_main_osc_is_preparedfunction clk_main_osc_save_contextfunction clk_main_osc_restore_contextfunction at91_clk_register_main_oscfunction clk_main_rc_osc_readyfunction clk_main_rc_osc_preparefunction clk_main_rc_osc_unpreparefunction clk_main_rc_osc_is_preparedfunction clk_main_rc_osc_recalc_ratefunction clk_main_rc_osc_recalc_accuracyfunction clk_main_rc_osc_save_contextfunction clk_main_rc_osc_restore_contextfunction at91_clk_register_main_rc_oscfunction clk_main_probe_frequencyfunction clk_main_recalc_ratefunction clk_rm9200_main_preparefunction clk_rm9200_main_is_preparedfunction clk_rm9200_main_recalc_ratefunction at91_clk_register_rm9200_mainfunction clk_sam9x5_main_readyfunction clk_sam9x5_main_preparefunction clk_sam9x5_main_is_preparedfunction clk_sam9x5_main_recalc_ratefunction clk_sam9x5_main_set_parentfunction clk_sam9x5_main_get_parentfunction clk_sam9x5_main_save_contextfunction clk_sam9x5_main_restore_contextfunction at91_clk_register_sam9x5_main
Annotated Snippet
struct clk_main_osc {
struct clk_hw hw;
struct regmap *regmap;
struct at91_clk_pms pms;
};
#define to_clk_main_osc(hw) container_of(hw, struct clk_main_osc, hw)
struct clk_main_rc_osc {
struct clk_hw hw;
struct regmap *regmap;
unsigned long frequency;
unsigned long accuracy;
struct at91_clk_pms pms;
};
#define to_clk_main_rc_osc(hw) container_of(hw, struct clk_main_rc_osc, hw)
struct clk_rm9200_main {
struct clk_hw hw;
struct regmap *regmap;
};
#define to_clk_rm9200_main(hw) container_of(hw, struct clk_rm9200_main, hw)
struct clk_sam9x5_main {
struct clk_hw hw;
struct regmap *regmap;
struct at91_clk_pms pms;
u8 parent;
};
#define to_clk_sam9x5_main(hw) container_of(hw, struct clk_sam9x5_main, hw)
static inline bool clk_main_osc_ready(struct regmap *regmap)
{
unsigned int status;
regmap_read(regmap, AT91_PMC_SR, &status);
return status & AT91_PMC_MOSCS;
}
static int clk_main_osc_prepare(struct clk_hw *hw)
{
struct clk_main_osc *osc = to_clk_main_osc(hw);
struct regmap *regmap = osc->regmap;
u32 tmp;
regmap_read(regmap, AT91_CKGR_MOR, &tmp);
tmp &= ~MOR_KEY_MASK;
if (tmp & AT91_PMC_OSCBYPASS)
return 0;
if (!(tmp & AT91_PMC_MOSCEN)) {
tmp |= AT91_PMC_MOSCEN | AT91_PMC_KEY;
regmap_write(regmap, AT91_CKGR_MOR, tmp);
}
while (!clk_main_osc_ready(regmap))
cpu_relax();
return 0;
}
static void clk_main_osc_unprepare(struct clk_hw *hw)
{
struct clk_main_osc *osc = to_clk_main_osc(hw);
struct regmap *regmap = osc->regmap;
u32 tmp;
regmap_read(regmap, AT91_CKGR_MOR, &tmp);
if (tmp & AT91_PMC_OSCBYPASS)
return;
if (!(tmp & AT91_PMC_MOSCEN))
return;
tmp &= ~(AT91_PMC_KEY | AT91_PMC_MOSCEN);
regmap_write(regmap, AT91_CKGR_MOR, tmp | AT91_PMC_KEY);
}
static int clk_main_osc_is_prepared(struct clk_hw *hw)
{
struct clk_main_osc *osc = to_clk_main_osc(hw);
struct regmap *regmap = osc->regmap;
u32 tmp, status;
regmap_read(regmap, AT91_CKGR_MOR, &tmp);
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/clkdev.h`, `linux/clk/at91_pmc.h`, `linux/delay.h`, `linux/mfd/syscon.h`, `linux/regmap.h`, `pmc.h`.
- Detected declarations: `struct clk_main_osc`, `struct clk_main_rc_osc`, `struct clk_rm9200_main`, `struct clk_sam9x5_main`, `function clk_main_osc_ready`, `function clk_main_osc_prepare`, `function clk_main_osc_unprepare`, `function clk_main_osc_is_prepared`, `function clk_main_osc_save_context`, `function clk_main_osc_restore_context`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: source 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.