drivers/clocksource/timer-sun5i.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-sun5i.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/timer-sun5i.c- Extension
.c- Size
- 9883 bytes
- Lines
- 380
- 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/clk.hlinux/clockchips.hlinux/clocksource.hlinux/delay.hlinux/interrupt.hlinux/irq.hlinux/irqreturn.hlinux/reset.hlinux/slab.hlinux/platform_device.h
Detected Declarations
struct sunxi_timer_quirksstruct sun5i_timerfunction sun5i_clkevt_syncfunction sun5i_clkevt_time_stopfunction sun5i_clkevt_time_setupfunction sun5i_clkevt_time_startfunction sun5i_clkevt_shutdownfunction sun5i_clkevt_set_oneshotfunction sun5i_clkevt_set_periodicfunction sun5i_clkevt_next_eventfunction sun5i_timer_interruptfunction sun5i_clksrc_readfunction sun5i_rate_cbfunction sun5i_setup_clocksourcefunction sun5i_setup_clockeventfunction sun5i_timer_probefunction sun5i_timer_remove
Annotated Snippet
struct sunxi_timer_quirks {
u32 from_ctl_base_offset;
};
struct sun5i_timer {
void __iomem *base;
struct clk *clk;
struct notifier_block clk_rate_cb;
u32 ticks_per_jiffy;
struct clocksource clksrc;
struct clock_event_device clkevt;
const struct sunxi_timer_quirks *quirks;
};
#define nb_to_sun5i_timer(x) \
container_of(x, struct sun5i_timer, clk_rate_cb)
#define clksrc_to_sun5i_timer(x) \
container_of(x, struct sun5i_timer, clksrc)
#define clkevt_to_sun5i_timer(x) \
container_of(x, struct sun5i_timer, clkevt)
/*
* When we disable a timer, we need to wait at least for 2 cycles of
* the timer source clock. We will use for that the clocksource timer
* that is already setup and runs at the same frequency than the other
* timers, and we never will be disabled.
*/
static void sun5i_clkevt_sync(struct sun5i_timer *ce)
{
u32 offset = ce->quirks->from_ctl_base_offset;
u32 old = readl(ce->base + TIMER_CNTVAL_LO_REG(1, offset));
while ((old - readl(ce->base + TIMER_CNTVAL_LO_REG(1, offset))) <
TIMER_SYNC_TICKS)
cpu_relax();
}
static void sun5i_clkevt_time_stop(struct sun5i_timer *ce, u8 timer)
{
u32 offset = ce->quirks->from_ctl_base_offset;
u32 val = readl(ce->base + TIMER_CTL_REG(timer, offset));
writel(val & ~TIMER_CTL_ENABLE,
ce->base + TIMER_CTL_REG(timer, offset));
sun5i_clkevt_sync(ce);
}
static void sun5i_clkevt_time_setup(struct sun5i_timer *ce, u8 timer, u32 delay)
{
u32 offset = ce->quirks->from_ctl_base_offset;
writel(delay, ce->base + TIMER_INTVAL_LO_REG(timer, offset));
}
static void sun5i_clkevt_time_start(struct sun5i_timer *ce, u8 timer, bool periodic)
{
u32 offset = ce->quirks->from_ctl_base_offset;
u32 val = readl(ce->base + TIMER_CTL_REG(timer, offset));
if (periodic)
val &= ~TIMER_CTL_ONESHOT;
else
val |= TIMER_CTL_ONESHOT;
writel(val | TIMER_CTL_ENABLE | TIMER_CTL_RELOAD,
ce->base + TIMER_CTL_REG(timer, offset));
}
static int sun5i_clkevt_shutdown(struct clock_event_device *clkevt)
{
struct sun5i_timer *ce = clkevt_to_sun5i_timer(clkevt);
sun5i_clkevt_time_stop(ce, 0);
return 0;
}
static int sun5i_clkevt_set_oneshot(struct clock_event_device *clkevt)
{
struct sun5i_timer *ce = clkevt_to_sun5i_timer(clkevt);
sun5i_clkevt_time_stop(ce, 0);
sun5i_clkevt_time_start(ce, 0, false);
return 0;
}
static int sun5i_clkevt_set_periodic(struct clock_event_device *clkevt)
{
struct sun5i_timer *ce = clkevt_to_sun5i_timer(clkevt);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clockchips.h`, `linux/clocksource.h`, `linux/delay.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/irqreturn.h`, `linux/reset.h`.
- Detected declarations: `struct sunxi_timer_quirks`, `struct sun5i_timer`, `function sun5i_clkevt_sync`, `function sun5i_clkevt_time_stop`, `function sun5i_clkevt_time_setup`, `function sun5i_clkevt_time_start`, `function sun5i_clkevt_shutdown`, `function sun5i_clkevt_set_oneshot`, `function sun5i_clkevt_set_periodic`, `function sun5i_clkevt_next_event`.
- 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.