drivers/clk/nuvoton/clk-ma35d1-pll.c
Source file repositories/reference/linux-study-clean/drivers/clk/nuvoton/clk-ma35d1-pll.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/nuvoton/clk-ma35d1-pll.c- Extension
.c- Size
- 9558 bytes
- Lines
- 369
- 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/bitfield.hlinux/clk-provider.hlinux/container_of.hlinux/device.hlinux/io.hlinux/kernel.hlinux/math64.hlinux/slab.hlinux/units.hdt-bindings/clock/nuvoton,ma35d1-clk.hclk-ma35d1.h
Detected Declarations
struct ma35d1_clk_pllfunction ma35d1_calc_smic_pll_freqfunction ma35d1_calc_pll_freqfunction ma35d1_pll_find_closestfunction ma35d1_clk_pll_set_ratefunction ma35d1_clk_pll_recalc_ratefunction ma35d1_clk_pll_determine_ratefunction ma35d1_clk_pll_is_preparedfunction ma35d1_clk_pll_preparefunction ma35d1_clk_pll_unprepareexport ma35d1_reg_clk_pll
Annotated Snippet
struct ma35d1_clk_pll {
struct clk_hw hw;
u32 id;
u8 mode;
void __iomem *ctl0_base;
void __iomem *ctl1_base;
void __iomem *ctl2_base;
};
static inline struct ma35d1_clk_pll *to_ma35d1_clk_pll(struct clk_hw *_hw)
{
return container_of(_hw, struct ma35d1_clk_pll, hw);
}
static unsigned long ma35d1_calc_smic_pll_freq(u32 pll0_ctl0,
unsigned long parent_rate)
{
u32 m, n, p, outdiv;
u64 pll_freq;
if (pll0_ctl0 & SPLL0_CTL0_BP)
return parent_rate;
n = FIELD_GET(SPLL0_CTL0_FBDIV, pll0_ctl0);
m = FIELD_GET(SPLL0_CTL0_INDIV, pll0_ctl0);
p = FIELD_GET(SPLL0_CTL0_OUTDIV, pll0_ctl0);
outdiv = 1 << p;
pll_freq = (u64)parent_rate * n;
div_u64(pll_freq, m * outdiv);
return pll_freq;
}
static unsigned long ma35d1_calc_pll_freq(u8 mode, u32 *reg_ctl, unsigned long parent_rate)
{
unsigned long pll_freq, x;
u32 m, n, p;
if (reg_ctl[1] & PLL_CTL1_BP)
return parent_rate;
n = FIELD_GET(PLL_CTL0_FBDIV, reg_ctl[0]);
m = FIELD_GET(PLL_CTL0_INDIV, reg_ctl[0]);
p = FIELD_GET(PLL_CTL1_OUTDIV, reg_ctl[1]);
if (mode == PLL_MODE_INT) {
pll_freq = (u64)parent_rate * n;
div_u64(pll_freq, m * p);
} else {
x = FIELD_GET(PLL_CTL1_FRAC, reg_ctl[1]);
/* 2 decimal places floating to integer (ex. 1.23 to 123) */
n = n * 100 + ((x * 100) / FIELD_MAX(PLL_CTL1_FRAC));
pll_freq = div_u64(parent_rate * n, 100 * m * p);
}
return pll_freq;
}
static int ma35d1_pll_find_closest(struct ma35d1_clk_pll *pll, unsigned long rate,
unsigned long parent_rate, u32 *reg_ctl,
unsigned long *freq)
{
unsigned long min_diff = ULONG_MAX;
int fbdiv_min, fbdiv_max;
int p, m, n;
*freq = 0;
if (rate < PLL_FCLKO_MIN_FREQ || rate > PLL_FCLKO_MAX_FREQ)
return -EINVAL;
if (pll->mode == PLL_MODE_INT) {
fbdiv_min = FBDIV_MIN;
fbdiv_max = FBDIV_MAX;
} else {
fbdiv_min = FBDIV_FRAC_MIN;
fbdiv_max = FBDIV_FRAC_MAX;
}
for (m = INDIV_MIN; m <= INDIV_MAX; m++) {
for (n = fbdiv_min; n <= fbdiv_max; n++) {
for (p = OUTDIV_MIN; p <= OUTDIV_MAX; p++) {
unsigned long tmp, fout, fclk, diff;
tmp = div_u64(parent_rate, m);
if (tmp < PLL_FREF_M_MIN_FREQ ||
tmp > PLL_FREF_M_MAX_FREQ)
continue; /* constrain */
fclk = div_u64(parent_rate * n, m);
/* for 2 decimal places */
if (pll->mode != PLL_MODE_INT)
fclk = div_u64(fclk, 100);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk-provider.h`, `linux/container_of.h`, `linux/device.h`, `linux/io.h`, `linux/kernel.h`, `linux/math64.h`, `linux/slab.h`.
- Detected declarations: `struct ma35d1_clk_pll`, `function ma35d1_calc_smic_pll_freq`, `function ma35d1_calc_pll_freq`, `function ma35d1_pll_find_closest`, `function ma35d1_clk_pll_set_rate`, `function ma35d1_clk_pll_recalc_rate`, `function ma35d1_clk_pll_determine_rate`, `function ma35d1_clk_pll_is_prepared`, `function ma35d1_clk_pll_prepare`, `function ma35d1_clk_pll_unprepare`.
- 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.