drivers/clk/at91/clk-master.c
Source file repositories/reference/linux-study-clean/drivers/clk/at91/clk-master.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/at91/clk-master.c- Extension
.c- Size
- 23216 bytes
- Lines
- 886
- 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/clkdev.hlinux/clk.hlinux/clk/at91_pmc.hlinux/of.hlinux/mfd/syscon.hlinux/regmap.hpmc.h
Detected Declarations
struct clk_masterfunction clk_master_readyfunction clk_master_preparefunction clk_master_is_preparedfunction clk_master_div_recalc_ratefunction clk_master_div_save_contextfunction clk_master_div_restore_contextfunction clk_master_div_setfunction clk_master_div_recalc_rate_chgfunction clk_master_div_restore_context_chgfunction clk_master_div_notifier_fnfunction clk_sama7g5_master_best_difffunction clk_master_pres_recalc_ratefunction clk_master_pres_get_parentfunction clk_master_pres_save_contextfunction clk_master_pres_restore_contextfunction at91_clk_register_master_internalfunction at91_clk_register_master_presfunction at91_clk_register_master_divfunction clk_sama7g5_master_recalc_ratefunction clk_sama7g5_master_determine_ratefunction clk_sama7g5_master_get_parentfunction clk_sama7g5_master_set_parentfunction clk_sama7g5_master_setfunction clk_sama7g5_master_enablefunction clk_sama7g5_master_disablefunction clk_sama7g5_master_is_enabledfunction clk_sama7g5_master_set_ratefunction clk_sama7g5_master_save_contextfunction clk_sama7g5_master_restore_contextfunction at91_clk_sama7g5_register_master
Annotated Snippet
struct clk_master {
struct clk_hw hw;
struct regmap *regmap;
spinlock_t *lock;
const struct clk_master_layout *layout;
const struct clk_master_characteristics *characteristics;
struct at91_clk_pms pms;
u32 *mux_table;
u32 mckr;
int chg_pid;
u8 id;
u8 parent;
u8 div;
u32 safe_div;
};
/* MCK div reference to be used by notifier. */
static struct clk_master *master_div;
static inline bool clk_master_ready(struct clk_master *master)
{
unsigned int bit = master->id ? AT91_PMC_MCKXRDY : AT91_PMC_MCKRDY;
unsigned int status;
regmap_read(master->regmap, AT91_PMC_SR, &status);
return !!(status & bit);
}
static int clk_master_prepare(struct clk_hw *hw)
{
struct clk_master *master = to_clk_master(hw);
unsigned long flags;
spin_lock_irqsave(master->lock, flags);
while (!clk_master_ready(master))
cpu_relax();
spin_unlock_irqrestore(master->lock, flags);
return 0;
}
static int clk_master_is_prepared(struct clk_hw *hw)
{
struct clk_master *master = to_clk_master(hw);
unsigned long flags;
bool status;
spin_lock_irqsave(master->lock, flags);
status = clk_master_ready(master);
spin_unlock_irqrestore(master->lock, flags);
return status;
}
static unsigned long clk_master_div_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
u8 div;
unsigned long flags, rate = parent_rate;
struct clk_master *master = to_clk_master(hw);
const struct clk_master_layout *layout = master->layout;
const struct clk_master_characteristics *characteristics =
master->characteristics;
unsigned int mckr;
spin_lock_irqsave(master->lock, flags);
regmap_read(master->regmap, master->layout->offset, &mckr);
spin_unlock_irqrestore(master->lock, flags);
mckr &= layout->mask;
div = (mckr >> MASTER_DIV_SHIFT) & MASTER_DIV_MASK;
rate /= characteristics->divisors[div];
if (rate < characteristics->output.min)
pr_warn("master clk div is underclocked");
else if (rate > characteristics->output.max)
pr_warn("master clk div is overclocked");
return rate;
}
static int clk_master_div_save_context(struct clk_hw *hw)
{
struct clk_master *master = to_clk_master(hw);
struct clk_hw *parent_hw = clk_hw_get_parent(hw);
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/clkdev.h`, `linux/clk.h`, `linux/clk/at91_pmc.h`, `linux/of.h`, `linux/mfd/syscon.h`, `linux/regmap.h`, `pmc.h`.
- Detected declarations: `struct clk_master`, `function clk_master_ready`, `function clk_master_prepare`, `function clk_master_is_prepared`, `function clk_master_div_recalc_rate`, `function clk_master_div_save_context`, `function clk_master_div_restore_context`, `function clk_master_div_set`, `function clk_master_div_recalc_rate_chg`, `function clk_master_div_restore_context_chg`.
- 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.