drivers/clocksource/timer-nxp-stm.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-nxp-stm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/timer-nxp-stm.c- Extension
.c- Size
- 13450 bytes
- Lines
- 497
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/clk.hlinux/clockchips.hlinux/cpuhotplug.hlinux/interrupt.hlinux/module.hlinux/of_irq.hlinux/platform_device.hlinux/sched_clock.hlinux/units.h
Detected Declarations
struct stm_timerfunction nxp_stm_read_sched_clockfunction nxp_stm_clocksource_getcntfunction nxp_stm_clocksource_setcntfunction nxp_stm_clocksource_readfunction nxp_stm_module_enablefunction nxp_stm_module_disablefunction nxp_stm_module_putfunction nxp_stm_module_getfunction nxp_stm_clocksource_enablefunction nxp_stm_clocksource_disablefunction nxp_stm_clocksource_suspendfunction nxp_stm_clocksource_resumefunction devm_clocksource_unregisterfunction nxp_stm_clocksource_initfunction nxp_stm_clockevent_read_counterfunction nxp_stm_clockevent_disablefunction nxp_stm_clockevent_enablefunction nxp_stm_clockevent_shutdownfunction nxp_stm_clockevent_set_next_eventfunction nxp_stm_clockevent_set_periodicfunction nxp_stm_clockevent_suspendfunction nxp_stm_clockevent_resumefunction nxp_stm_clockevent_per_cpu_initfunction nxp_stm_clockevent_starting_cpufunction nxp_stm_module_interruptfunction nxp_stm_timer_probe
Annotated Snippet
struct stm_timer {
void __iomem *base;
unsigned long rate;
unsigned long delta;
unsigned long counter;
struct clock_event_device ced;
struct clocksource cs;
atomic_t refcnt;
};
static DEFINE_PER_CPU(struct stm_timer *, stm_timers);
static struct stm_timer *stm_sched_clock;
/*
* Global structure for multiple STMs initialization
*/
static int stm_instances;
/*
* This global lock is used to prevent race conditions with the
* stm_instances in case the driver is using the ASYNC option
*/
static DEFINE_MUTEX(stm_instances_lock);
DEFINE_GUARD(stm_instances, struct mutex *, mutex_lock(_T), mutex_unlock(_T))
static struct stm_timer *cs_to_stm(struct clocksource *cs)
{
return container_of(cs, struct stm_timer, cs);
}
static struct stm_timer *ced_to_stm(struct clock_event_device *ced)
{
return container_of(ced, struct stm_timer, ced);
}
static u64 notrace nxp_stm_read_sched_clock(void)
{
return readl(STM_CNT(stm_sched_clock->base));
}
static u32 nxp_stm_clocksource_getcnt(struct stm_timer *stm_timer)
{
return readl(STM_CNT(stm_timer->base));
}
static void nxp_stm_clocksource_setcnt(struct stm_timer *stm_timer, u32 cnt)
{
writel(cnt, STM_CNT(stm_timer->base));
}
static u64 nxp_stm_clocksource_read(struct clocksource *cs)
{
struct stm_timer *stm_timer = cs_to_stm(cs);
return (u64)nxp_stm_clocksource_getcnt(stm_timer);
}
static void nxp_stm_module_enable(struct stm_timer *stm_timer)
{
u32 reg;
reg = readl(STM_CR(stm_timer->base));
reg |= STM_ENABLE_MASK;
writel(reg, STM_CR(stm_timer->base));
}
static void nxp_stm_module_disable(struct stm_timer *stm_timer)
{
u32 reg;
reg = readl(STM_CR(stm_timer->base));
reg &= ~STM_ENABLE_MASK;
writel(reg, STM_CR(stm_timer->base));
}
static void nxp_stm_module_put(struct stm_timer *stm_timer)
{
if (atomic_dec_and_test(&stm_timer->refcnt))
nxp_stm_module_disable(stm_timer);
}
static void nxp_stm_module_get(struct stm_timer *stm_timer)
{
if (atomic_inc_return(&stm_timer->refcnt) == 1)
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clockchips.h`, `linux/cpuhotplug.h`, `linux/interrupt.h`, `linux/module.h`, `linux/of_irq.h`, `linux/platform_device.h`, `linux/sched_clock.h`.
- Detected declarations: `struct stm_timer`, `function nxp_stm_read_sched_clock`, `function nxp_stm_clocksource_getcnt`, `function nxp_stm_clocksource_setcnt`, `function nxp_stm_clocksource_read`, `function nxp_stm_module_enable`, `function nxp_stm_module_disable`, `function nxp_stm_module_put`, `function nxp_stm_module_get`, `function nxp_stm_clocksource_enable`.
- Atlas domain: Driver Families / drivers/clocksource.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.