drivers/clocksource/timer-stm32-lp.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-stm32-lp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/timer-stm32-lp.c- Extension
.c- Size
- 8181 bytes
- Lines
- 293
- Domain
- Driver Families
- Bucket
- drivers/clocksource
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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.hlinux/clockchips.hlinux/interrupt.hlinux/mfd/stm32-lptimer.hlinux/module.hlinux/of_address.hlinux/of_irq.hlinux/platform_device.hlinux/pm_wakeirq.h
Detected Declarations
struct stm32_lp_privatefunction to_privfunction stm32_clkevent_lp_shutdownfunction stm32mp25_clkevent_lp_set_evtfunction stm32_clkevent_lp_set_evtfunction stm32_clkevent_lp_set_timerfunction stm32_clkevent_lp_set_next_eventfunction stm32_clkevent_lp_set_periodicfunction stm32_clkevent_lp_set_oneshotfunction stm32_clkevent_lp_irq_handlerfunction stm32_clkevent_lp_set_prescalerfunction stm32_clkevent_lp_suspendfunction stm32_clkevent_lp_resumefunction stm32_clkevent_lp_initfunction stm32_clkevent_lp_probe
Annotated Snippet
struct stm32_lp_private {
struct regmap *reg;
struct clock_event_device clkevt;
unsigned long period;
u32 psc;
struct device *dev;
struct clk *clk;
u32 version;
};
static struct stm32_lp_private*
to_priv(struct clock_event_device *clkevt)
{
return container_of(clkevt, struct stm32_lp_private, clkevt);
}
static int stm32_clkevent_lp_shutdown(struct clock_event_device *clkevt)
{
struct stm32_lp_private *priv = to_priv(clkevt);
regmap_write(priv->reg, STM32_LPTIM_CR, 0);
regmap_write(priv->reg, STM32_LPTIM_IER, 0);
/* clear pending flags */
regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_ARRMCF);
return 0;
}
static int stm32mp25_clkevent_lp_set_evt(struct stm32_lp_private *priv, unsigned long evt)
{
int ret;
u32 val;
regmap_read(priv->reg, STM32_LPTIM_CR, &val);
if (!FIELD_GET(STM32_LPTIM_ENABLE, val)) {
/* Enable LPTIMER to be able to write into IER and ARR registers */
regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
/*
* After setting the ENABLE bit, a delay of two counter clock cycles is needed
* before the LPTIM is actually enabled. For 32KHz rate, this makes approximately
* 62.5 micro-seconds, round it up.
*/
udelay(63);
}
/* set next event counter */
regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
/* enable ARR interrupt */
regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE);
/* Poll DIEROK and ARROK to ensure register access has completed */
ret = regmap_read_poll_timeout_atomic(priv->reg, STM32_LPTIM_ISR, val,
(val & STM32_LPTIM_DIEROK_ARROK) ==
STM32_LPTIM_DIEROK_ARROK,
10, 500);
if (ret) {
dev_err(priv->dev, "access to LPTIM timed out\n");
/* Disable LPTIMER */
regmap_write(priv->reg, STM32_LPTIM_CR, 0);
return ret;
}
/* Clear DIEROK and ARROK flags */
regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_DIEROKCF_ARROKCF);
return 0;
}
static void stm32_clkevent_lp_set_evt(struct stm32_lp_private *priv, unsigned long evt)
{
/* disable LPTIMER to be able to write into IER register*/
regmap_write(priv->reg, STM32_LPTIM_CR, 0);
/* enable ARR interrupt */
regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE);
/* enable LPTIMER to be able to write into ARR register */
regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE);
/* set next event counter */
regmap_write(priv->reg, STM32_LPTIM_ARR, evt);
}
static int stm32_clkevent_lp_set_timer(unsigned long evt,
struct clock_event_device *clkevt,
int is_periodic)
{
struct stm32_lp_private *priv = to_priv(clkevt);
int ret;
if (priv->version == STM32_LPTIM_VERR_23) {
ret = stm32mp25_clkevent_lp_set_evt(priv, evt);
if (ret)
return ret;
} else {
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/clockchips.h`, `linux/interrupt.h`, `linux/mfd/stm32-lptimer.h`, `linux/module.h`, `linux/of_address.h`, `linux/of_irq.h`.
- Detected declarations: `struct stm32_lp_private`, `function to_priv`, `function stm32_clkevent_lp_shutdown`, `function stm32mp25_clkevent_lp_set_evt`, `function stm32_clkevent_lp_set_evt`, `function stm32_clkevent_lp_set_timer`, `function stm32_clkevent_lp_set_next_event`, `function stm32_clkevent_lp_set_periodic`, `function stm32_clkevent_lp_set_oneshot`, `function stm32_clkevent_lp_irq_handler`.
- Atlas domain: Driver Families / drivers/clocksource.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.