drivers/clk/sophgo/clk-sg2042-clkgen.c
Source file repositories/reference/linux-study-clean/drivers/clk/sophgo/clk-sg2042-clkgen.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/sophgo/clk-sg2042-clkgen.c- Extension
.c- Size
- 37294 bytes
- Lines
- 1149
- 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/bits.hlinux/clk.hlinux/clk-provider.hlinux/io.hlinux/platform_device.hasm/div64.hdt-bindings/clock/sophgo,sg2042-clkgen.hclk-sg2042.h
Detected Declarations
struct sg2042_divider_clockstruct sg2042_gate_clockstruct sg2042_mux_clockfunction sg2042_clk_divider_recalc_ratefunction sg2042_clk_divider_determine_ratefunction sg2042_clk_divider_set_ratefunction sg2042_clk_register_divsfunction sg2042_clk_register_gatesfunction sg2042_clk_register_gates_fwfunction sg2042_mux_notifier_cbfunction sg2042_clk_register_muxsfunction sg2042_init_clkdatafunction sg2042_clkgen_probe
Annotated Snippet
struct sg2042_divider_clock {
struct clk_hw hw;
unsigned int id;
void __iomem *reg;
/* protect register access */
spinlock_t *lock;
u32 offset_ctrl;
u8 shift;
u8 width;
u8 div_flags;
u32 initval;
};
#define to_sg2042_clk_divider(_hw) \
container_of(_hw, struct sg2042_divider_clock, hw)
/**
* struct sg2042_gate_clock - Gate clock
* @hw: clk_hw for initialization
* @id: used to map clk_onecell_data
* @offset_enable: offset of gate enable registers
* @bit_idx: which bit in the register controls gating of this clock
*/
struct sg2042_gate_clock {
struct clk_hw hw;
unsigned int id;
u32 offset_enable;
u8 bit_idx;
};
/**
* struct sg2042_mux_clock - Mux clock
* @hw: clk_hw for initialization
* @id: used to map clk_onecell_data
* @offset_select: offset of mux selection registers
* **NOTE**: MUX registers are ALL in CLOCK!
* @shift: shift of "Clock Select" in mux selection register
* @width: width of "Clock Select" in mux selection register
* @clk_nb: used for notification
* @original_index: set by notifier callback
*/
struct sg2042_mux_clock {
struct clk_hw hw;
unsigned int id;
u32 offset_select;
u8 shift;
u8 width;
struct notifier_block clk_nb;
u8 original_index;
};
#define to_sg2042_mux_nb(_nb) container_of(_nb, struct sg2042_mux_clock, clk_nb)
static unsigned long sg2042_clk_divider_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct sg2042_divider_clock *divider = to_sg2042_clk_divider(hw);
unsigned long ret_rate;
u32 val;
if (!(readl(divider->reg) & BIT(SHIFT_DIV_FACTOR_SEL))) {
val = divider->initval;
} else {
val = readl(divider->reg) >> divider->shift;
val &= clk_div_mask(divider->width);
}
ret_rate = divider_recalc_rate(hw, parent_rate, val, NULL,
divider->div_flags, divider->width);
pr_debug("--> %s: divider_recalc_rate: ret_rate = %ld\n",
clk_hw_get_name(hw), ret_rate);
return ret_rate;
}
static int sg2042_clk_divider_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct sg2042_divider_clock *divider = to_sg2042_clk_divider(hw);
u32 bestdiv;
/* if read only, just return current value */
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bits.h`, `linux/clk.h`, `linux/clk-provider.h`, `linux/io.h`, `linux/platform_device.h`, `asm/div64.h`, `dt-bindings/clock/sophgo,sg2042-clkgen.h`.
- Detected declarations: `struct sg2042_divider_clock`, `struct sg2042_gate_clock`, `struct sg2042_mux_clock`, `function sg2042_clk_divider_recalc_rate`, `function sg2042_clk_divider_determine_rate`, `function sg2042_clk_divider_set_rate`, `function sg2042_clk_register_divs`, `function sg2042_clk_register_gates`, `function sg2042_clk_register_gates_fw`, `function sg2042_mux_notifier_cb`.
- 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.