drivers/clk/sunxi-ng/ccu_nm.c
Source file repositories/reference/linux-study-clean/drivers/clk/sunxi-ng/ccu_nm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/sunxi-ng/ccu_nm.c- Extension
.c- Size
- 5953 bytes
- Lines
- 241
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk-provider.hlinux/io.hccu_frac.hccu_gate.hccu_nm.h
Detected Declarations
struct _ccu_nmfunction ccu_nm_calc_ratefunction ccu_nm_find_bestfunction ccu_nm_disablefunction ccu_nm_enablefunction ccu_nm_is_enabledfunction ccu_nm_recalc_ratefunction ccu_nm_determine_ratefunction ccu_nm_set_rate
Annotated Snippet
struct _ccu_nm {
unsigned long n, min_n, max_n;
unsigned long m, min_m, max_m;
};
static unsigned long ccu_nm_calc_rate(unsigned long parent,
unsigned long n, unsigned long m)
{
u64 rate = parent;
rate *= n;
do_div(rate, m);
return rate;
}
static unsigned long ccu_nm_find_best(struct ccu_common *common, unsigned long parent,
unsigned long rate, struct _ccu_nm *nm)
{
unsigned long best_rate = 0;
unsigned long best_n = 0, best_m = 0;
unsigned long _n, _m;
for (_n = nm->min_n; _n <= nm->max_n; _n++) {
for (_m = nm->min_m; _m <= nm->max_m; _m++) {
unsigned long tmp_rate = ccu_nm_calc_rate(parent,
_n, _m);
if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) {
best_rate = tmp_rate;
best_n = _n;
best_m = _m;
}
}
}
nm->n = best_n;
nm->m = best_m;
return best_rate;
}
static void ccu_nm_disable(struct clk_hw *hw)
{
struct ccu_nm *nm = hw_to_ccu_nm(hw);
return ccu_gate_helper_disable(&nm->common, nm->enable);
}
static int ccu_nm_enable(struct clk_hw *hw)
{
struct ccu_nm *nm = hw_to_ccu_nm(hw);
return ccu_gate_helper_enable(&nm->common, nm->enable);
}
static int ccu_nm_is_enabled(struct clk_hw *hw)
{
struct ccu_nm *nm = hw_to_ccu_nm(hw);
return ccu_gate_helper_is_enabled(&nm->common, nm->enable);
}
static unsigned long ccu_nm_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct ccu_nm *nm = hw_to_ccu_nm(hw);
unsigned long rate;
unsigned long n, m;
u32 reg;
if (ccu_frac_helper_is_enabled(&nm->common, &nm->frac)) {
rate = ccu_frac_helper_read_rate(&nm->common, &nm->frac);
if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV)
rate /= nm->fixed_post_div;
return rate;
}
reg = readl(nm->common.base + nm->common.reg);
n = reg >> nm->n.shift;
n &= (1 << nm->n.width) - 1;
n += nm->n.offset;
if (!n)
n++;
m = reg >> nm->m.shift;
m &= (1 << nm->m.width) - 1;
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/io.h`, `ccu_frac.h`, `ccu_gate.h`, `ccu_nm.h`.
- Detected declarations: `struct _ccu_nm`, `function ccu_nm_calc_rate`, `function ccu_nm_find_best`, `function ccu_nm_disable`, `function ccu_nm_enable`, `function ccu_nm_is_enabled`, `function ccu_nm_recalc_rate`, `function ccu_nm_determine_rate`, `function ccu_nm_set_rate`.
- Atlas domain: Driver Families / drivers/clk.
- Implementation status: integration 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.