drivers/clk/clk-loongson2.c
Source file repositories/reference/linux-study-clean/drivers/clk/clk-loongson2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/clk-loongson2.c- Extension
.c- Size
- 16290 bytes
- Lines
- 461
- 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/err.hlinux/init.hlinux/clk-provider.hlinux/slab.hlinux/module.hlinux/platform_device.hlinux/io-64-nonatomic-lo-hi.hdt-bindings/clock/loongson,ls2k-clk.h
Detected Declarations
struct loongson2_clk_providerstruct loongson2_clk_datastruct loongson2_clk_board_infoenum loongson2_clk_typefunction loongson2_rate_partfunction loongson2_pll_recalc_ratefunction loongson2_freqscale_recalc_ratefunction loongson2_clk_probe
Annotated Snippet
struct loongson2_clk_provider {
void __iomem *base;
struct device *dev;
spinlock_t clk_lock; /* protect access to DIV registers */
/* Must be last --ends in a flexible-array member. */
struct clk_hw_onecell_data clk_data;
};
struct loongson2_clk_data {
struct clk_hw hw;
void __iomem *reg;
u8 div_shift;
u8 div_width;
u8 mult_shift;
u8 mult_width;
u8 bit_idx;
};
struct loongson2_clk_board_info {
u8 id;
enum loongson2_clk_type type;
const char *name;
const char *parent_name;
unsigned long fixed_rate;
unsigned long flags;
u8 reg_offset;
u8 div_shift;
u8 div_width;
u8 mult_shift;
u8 mult_width;
u8 bit_idx;
};
#define CLK_DIV(_id, _name, _pname, _offset, _dshift, _dwidth) \
{ \
.id = _id, \
.type = CLK_TYPE_DIVIDER, \
.name = _name, \
.parent_name = _pname, \
.reg_offset = _offset, \
.div_shift = _dshift, \
.div_width = _dwidth, \
}
#define CLK_PLL(_id, _name, _offset, _mshift, _mwidth, \
_dshift, _dwidth) \
{ \
.id = _id, \
.type = CLK_TYPE_PLL, \
.name = _name, \
.parent_name = NULL, \
.reg_offset = _offset, \
.mult_shift = _mshift, \
.mult_width = _mwidth, \
.div_shift = _dshift, \
.div_width = _dwidth, \
}
#define CLK_SCALE(_id, _name, _pname, _offset, \
_dshift, _dwidth) \
{ \
.id = _id, \
.type = CLK_TYPE_SCALE, \
.name = _name, \
.parent_name = _pname, \
.reg_offset = _offset, \
.div_shift = _dshift, \
.div_width = _dwidth, \
}
#define CLK_SCALE_MODE(_id, _name, _pname, _offset, \
_dshift, _dwidth, _midx) \
{ \
.id = _id, \
.type = CLK_TYPE_SCALE, \
.name = _name, \
.parent_name = _pname, \
.reg_offset = _offset, \
.div_shift = _dshift, \
.div_width = _dwidth, \
.bit_idx = _midx + 1, \
}
#define CLK_GATE(_id, _name, _pname, _offset, _bidx) \
{ \
.id = _id, \
.type = CLK_TYPE_GATE, \
.name = _name, \
.parent_name = _pname, \
Annotation
- Immediate include surface: `linux/err.h`, `linux/init.h`, `linux/clk-provider.h`, `linux/slab.h`, `linux/module.h`, `linux/platform_device.h`, `linux/io-64-nonatomic-lo-hi.h`, `dt-bindings/clock/loongson,ls2k-clk.h`.
- Detected declarations: `struct loongson2_clk_provider`, `struct loongson2_clk_data`, `struct loongson2_clk_board_info`, `enum loongson2_clk_type`, `function loongson2_rate_part`, `function loongson2_pll_recalc_rate`, `function loongson2_freqscale_recalc_rate`, `function loongson2_clk_probe`.
- 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.