drivers/clk/stm32/clk-stm32-core.c
Source file repositories/reference/linux-study-clean/drivers/clk/stm32/clk-stm32-core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/stm32/clk-stm32-core.c- Extension
.c- Size
- 17741 bytes
- Lines
- 697
- 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/clk.hlinux/delay.hlinux/device.hlinux/err.hlinux/io.hlinux/of.hlinux/of_address.hlinux/slab.hlinux/spinlock.hclk-stm32-core.hreset-stm32.h
Detected Declarations
function stm32_rcc_clock_initfunction stm32_rcc_initfunction stm32_mux_get_parentfunction stm32_mux_set_parentfunction stm32_gate_endisablefunction stm32_gate_disable_unusedfunction stm32_gate_is_enabledfunction _get_table_divfunction _get_divfunction stm32_divider_get_ratefunction stm32_divider_set_ratefunction clk_stm32_mux_get_parentfunction clk_stm32_mux_set_parentfunction clk_stm32_gate_endisablefunction clk_stm32_gate_enablefunction clk_stm32_gate_disablefunction clk_stm32_gate_is_enabledfunction clk_stm32_gate_disable_unusedfunction clk_stm32_divider_set_ratefunction clk_stm32_divider_determine_ratefunction clk_stm32_divider_recalc_ratefunction clk_stm32_composite_set_ratefunction clk_stm32_composite_recalc_ratefunction clk_stm32_composite_determine_ratefunction clk_stm32_composite_get_parentfunction clk_stm32_composite_set_parentfunction clk_stm32_composite_is_enabledfunction clk_stm32_has_safe_muxfunction clk_stm32_set_safe_position_muxfunction clk_stm32_safe_restore_position_muxfunction clk_stm32_composite_gate_endisablefunction clk_stm32_composite_gate_enablefunction clk_stm32_composite_gate_disablefunction clk_stm32_composite_disable_unused
Annotated Snippet
if (IS_ERR(hw)) {
dev_err(dev, "Can't register clk %d: %ld\n", n,
PTR_ERR(hw));
return PTR_ERR(hw);
}
if (cfg_clock->id != NO_ID)
hws[cfg_clock->id] = hw;
}
return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_data);
}
int stm32_rcc_init(struct device *dev, const struct of_device_id *match_data,
void __iomem *base)
{
const struct stm32_rcc_match_data *rcc_match_data;
const struct of_device_id *match;
int err;
match = of_match_node(match_data, dev_of_node(dev));
if (!match) {
dev_err(dev, "match data not found\n");
return -ENODEV;
}
rcc_match_data = match->data;
/* RCC Reset Configuration */
err = stm32_rcc_reset_init(dev, rcc_match_data->reset_data, base);
if (err) {
pr_err("stm32 reset failed to initialize\n");
return err;
}
/* RCC Clock Configuration */
err = stm32_rcc_clock_init(dev, match, base);
if (err) {
pr_err("stm32 clock failed to initialize\n");
return err;
}
return 0;
}
static u8 stm32_mux_get_parent(void __iomem *base,
struct clk_stm32_clock_data *data,
u16 mux_id)
{
const struct stm32_mux_cfg *mux = &data->muxes[mux_id];
u32 mask = BIT(mux->width) - 1;
u32 val;
val = readl(base + mux->offset) >> mux->shift;
val &= mask;
return val;
}
static int stm32_mux_set_parent(void __iomem *base,
struct clk_stm32_clock_data *data,
u16 mux_id, u8 index)
{
const struct stm32_mux_cfg *mux = &data->muxes[mux_id];
u32 mask = BIT(mux->width) - 1;
u32 reg = readl(base + mux->offset);
u32 val = index << mux->shift;
reg &= ~(mask << mux->shift);
reg |= val;
writel(reg, base + mux->offset);
return 0;
}
static void stm32_gate_endisable(void __iomem *base,
struct clk_stm32_clock_data *data,
u16 gate_id, int enable)
{
const struct stm32_gate_cfg *gate = &data->gates[gate_id];
void __iomem *addr = base + gate->offset;
if (enable) {
if (data->gate_cpt[gate_id]++ > 0)
return;
if (gate->set_clr != 0)
writel(BIT(gate->bit_idx), addr);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/err.h`, `linux/io.h`, `linux/of.h`, `linux/of_address.h`, `linux/slab.h`.
- Detected declarations: `function stm32_rcc_clock_init`, `function stm32_rcc_init`, `function stm32_mux_get_parent`, `function stm32_mux_set_parent`, `function stm32_gate_endisable`, `function stm32_gate_disable_unused`, `function stm32_gate_is_enabled`, `function _get_table_div`, `function _get_div`, `function stm32_divider_get_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.