drivers/clk/sophgo/clk-sg2042-pll.c
Source file repositories/reference/linux-study-clean/drivers/clk/sophgo/clk-sg2042-pll.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/sophgo/clk-sg2042-pll.c- Extension
.c- Size
- 15160 bytes
- Lines
- 560
- 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/array_size.hlinux/bitfield.hlinux/bits.hlinux/clk-provider.hlinux/io.hlinux/iopoll.hlinux/platform_device.hasm/div64.hdt-bindings/clock/sophgo,sg2042-pll.hclk-sg2042.h
Detected Declarations
struct sg2042_pll_clockstruct sg2042_pll_ctrlfunction sg2042_pll_ctrl_encodefunction sg2042_pll_ctrl_decodefunction sg2042_pll_enablefunction sg2042_pll_recalc_ratefunction sg2042_pll_get_postdiv_1_2function sg2042_get_pll_ctl_settingfunction sg2042_clk_pll_recalc_ratefunction sg2042_clk_pll_determine_ratefunction sg2042_clk_pll_set_ratefunction sg2042_clk_register_pllsfunction sg2042_init_clkdatafunction sg2042_pll_probe
Annotated Snippet
struct sg2042_pll_clock {
struct clk_hw hw;
unsigned int id;
void __iomem *base;
/* protect register access */
spinlock_t *lock;
u32 offset_ctrl;
u8 shift_status_lock;
u8 shift_status_updating;
u8 shift_enable;
};
#define to_sg2042_pll_clk(_hw) container_of(_hw, struct sg2042_pll_clock, hw)
#define KHZ 1000UL
#define MHZ (KHZ * KHZ)
#define REFDIV_MIN 1
#define REFDIV_MAX 63
#define FBDIV_MIN 16
#define FBDIV_MAX 320
#define PLL_FREF_SG2042 (25 * MHZ)
#define PLL_FOUTPOSTDIV_MIN (16 * MHZ)
#define PLL_FOUTPOSTDIV_MAX (3200 * MHZ)
#define PLL_FOUTVCO_MIN (800 * MHZ)
#define PLL_FOUTVCO_MAX (3200 * MHZ)
struct sg2042_pll_ctrl {
unsigned long freq;
unsigned int fbdiv;
unsigned int postdiv1;
unsigned int postdiv2;
unsigned int refdiv;
};
#define PLLCTRL_FBDIV_MASK GENMASK(27, 16)
#define PLLCTRL_POSTDIV2_MASK GENMASK(14, 12)
#define PLLCTRL_POSTDIV1_MASK GENMASK(10, 8)
#define PLLCTRL_REFDIV_MASK GENMASK(5, 0)
static inline u32 sg2042_pll_ctrl_encode(struct sg2042_pll_ctrl *ctrl)
{
return FIELD_PREP(PLLCTRL_FBDIV_MASK, ctrl->fbdiv) |
FIELD_PREP(PLLCTRL_POSTDIV2_MASK, ctrl->postdiv2) |
FIELD_PREP(PLLCTRL_POSTDIV1_MASK, ctrl->postdiv1) |
FIELD_PREP(PLLCTRL_REFDIV_MASK, ctrl->refdiv);
}
static inline void sg2042_pll_ctrl_decode(unsigned int reg_value,
struct sg2042_pll_ctrl *ctrl)
{
ctrl->fbdiv = FIELD_GET(PLLCTRL_FBDIV_MASK, reg_value);
ctrl->refdiv = FIELD_GET(PLLCTRL_REFDIV_MASK, reg_value);
ctrl->postdiv1 = FIELD_GET(PLLCTRL_POSTDIV1_MASK, reg_value);
ctrl->postdiv2 = FIELD_GET(PLLCTRL_POSTDIV2_MASK, reg_value);
}
static inline void sg2042_pll_enable(struct sg2042_pll_clock *pll, bool en)
{
u32 value;
if (en) {
/* wait pll lock */
if (readl_poll_timeout_atomic(pll->base + R_PLL_STAT,
value,
((value >> pll->shift_status_lock) & 0x1),
0,
100000))
pr_warn("%s not locked\n", pll->hw.init->name);
/* wait pll updating */
if (readl_poll_timeout_atomic(pll->base + R_PLL_STAT,
value,
!((value >> pll->shift_status_updating) & 0x1),
0,
100000))
pr_warn("%s still updating\n", pll->hw.init->name);
/* enable pll */
value = readl(pll->base + R_PLL_CLKEN_CONTROL);
writel(value | (1 << pll->shift_enable), pll->base + R_PLL_CLKEN_CONTROL);
} else {
/* disable pll */
value = readl(pll->base + R_PLL_CLKEN_CONTROL);
writel(value & (~(1 << pll->shift_enable)), pll->base + R_PLL_CLKEN_CONTROL);
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bitfield.h`, `linux/bits.h`, `linux/clk-provider.h`, `linux/io.h`, `linux/iopoll.h`, `linux/platform_device.h`, `asm/div64.h`.
- Detected declarations: `struct sg2042_pll_clock`, `struct sg2042_pll_ctrl`, `function sg2042_pll_ctrl_encode`, `function sg2042_pll_ctrl_decode`, `function sg2042_pll_enable`, `function sg2042_pll_recalc_rate`, `function sg2042_pll_get_postdiv_1_2`, `function sg2042_get_pll_ctl_setting`, `function sg2042_clk_pll_recalc_rate`, `function sg2042_clk_pll_determine_rate`.
- 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.