drivers/clocksource/timer-sp804.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-sp804.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/timer-sp804.c- Extension
.c- Size
- 9616 bytes
- Lines
- 419
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/clocksource.hlinux/clockchips.hlinux/err.hlinux/interrupt.hlinux/irq.hlinux/io.hlinux/of.hlinux/of_address.hlinux/of_clk.hlinux/of_irq.hlinux/sched_clock.hlinux/delay.htimer-sp.h
Detected Declarations
function sp804_get_clock_ratefunction sp804_clkevt_getfunction sp804_readfunction sp804_read_delay_timer_readfunction sp804_register_delay_timerfunction sp804_register_delay_timerfunction sp804_timer_interruptfunction evt_timer_shutdownfunction sp804_shutdownfunction sp804_set_periodicfunction sp804_set_next_eventfunction sp804_clockevents_initfunction sp804_clkevt_initfunction sp804_of_initfunction arm_sp804_of_initfunction hisi_sp804_of_initfunction integrator_cp_of_init
Annotated Snippet
static inline void sp804_register_delay_timer(struct sp804_clkevt *clk, int freq) {}
#endif
static int __init sp804_clocksource_and_sched_clock_init(void __iomem *base,
const char *name,
struct clk *clk,
int use_sched_clock)
{
long rate;
struct sp804_clkevt *clkevt;
rate = sp804_get_clock_rate(clk, name);
if (rate < 0)
return -EINVAL;
clkevt = sp804_clkevt_get(base);
writel(0, clkevt->ctrl);
writel(0xffffffff, clkevt->load);
writel(0xffffffff, clkevt->value);
if (clkevt->width == 64) {
writel(0xffffffff, clkevt->load_h);
writel(0xffffffff, clkevt->value_h);
}
writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
clkevt->ctrl);
clocksource_mmio_init(clkevt->value, name,
rate, 200, 32, clocksource_mmio_readl_down);
sp804_register_delay_timer(clkevt, rate);
if (use_sched_clock) {
sched_clkevt = clkevt;
sched_clock_register(sp804_read, 32, rate);
}
return 0;
}
static struct sp804_clkevt *common_clkevt;
/*
* IRQ handler for the timer
*/
static irqreturn_t sp804_timer_interrupt(int irq, void *dev_id)
{
struct clock_event_device *evt = dev_id;
/* clear the interrupt */
writel(1, common_clkevt->intclr);
evt->event_handler(evt);
return IRQ_HANDLED;
}
static inline void evt_timer_shutdown(struct clock_event_device *evt)
{
writel(0, common_clkevt->ctrl);
}
static int sp804_shutdown(struct clock_event_device *evt)
{
evt_timer_shutdown(evt);
return 0;
}
static int sp804_set_periodic(struct clock_event_device *evt)
{
unsigned long ctrl = TIMER_CTRL_32BIT | TIMER_CTRL_IE |
TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE;
evt_timer_shutdown(evt);
writel(common_clkevt->reload, common_clkevt->load);
writel(ctrl, common_clkevt->ctrl);
return 0;
}
static int sp804_set_next_event(unsigned long next,
struct clock_event_device *evt)
{
unsigned long ctrl = TIMER_CTRL_32BIT | TIMER_CTRL_IE |
TIMER_CTRL_ONESHOT | TIMER_CTRL_ENABLE;
writel(next, common_clkevt->load);
writel(ctrl, common_clkevt->ctrl);
return 0;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clocksource.h`, `linux/clockchips.h`, `linux/err.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/io.h`, `linux/of.h`.
- Detected declarations: `function sp804_get_clock_rate`, `function sp804_clkevt_get`, `function sp804_read`, `function sp804_read_delay_timer_read`, `function sp804_register_delay_timer`, `function sp804_register_delay_timer`, `function sp804_timer_interrupt`, `function evt_timer_shutdown`, `function sp804_shutdown`, `function sp804_set_periodic`.
- 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.