drivers/clocksource/timer-davinci.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-davinci.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/timer-davinci.c- Extension
.c- Size
- 10230 bytes
- Lines
- 385
- 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/interrupt.hlinux/kernel.hlinux/of_address.hlinux/of_irq.hlinux/sched_clock.hclocksource/timer-davinci.h
Detected Declarations
struct davinci_clockeventfunction to_davinci_clockeventfunction davinci_clockevent_readfunction davinci_clockevent_writefunction davinci_tim12_shutdownfunction davinci_tim12_set_oneshotfunction davinci_clockevent_shutdownfunction davinci_clockevent_set_oneshotfunction davinci_clockevent_set_next_event_stdfunction davinci_clockevent_set_next_event_cmpfunction davinci_timer_irq_timerfunction davinci_timer_read_sched_clockfunction davinci_clocksource_readfunction davinci_clocksource_init_tim34function davinci_clocksource_init_tim12function davinci_timer_initfunction davinci_timer_registerfunction of_davinci_timer_register
Annotated Snippet
struct davinci_clockevent {
struct clock_event_device dev;
void __iomem *base;
unsigned int cmp_off;
};
/*
* This must be globally accessible by davinci_timer_read_sched_clock(), so
* let's keep it here.
*/
static struct {
struct clocksource dev;
void __iomem *base;
unsigned int tim_off;
} davinci_clocksource;
static struct davinci_clockevent *
to_davinci_clockevent(struct clock_event_device *clockevent)
{
return container_of(clockevent, struct davinci_clockevent, dev);
}
static unsigned int
davinci_clockevent_read(struct davinci_clockevent *clockevent,
unsigned int reg)
{
return readl_relaxed(clockevent->base + reg);
}
static void davinci_clockevent_write(struct davinci_clockevent *clockevent,
unsigned int reg, unsigned int val)
{
writel_relaxed(val, clockevent->base + reg);
}
static void davinci_tim12_shutdown(void __iomem *base)
{
unsigned int tcr;
tcr = DAVINCI_TIMER_ENAMODE_DISABLED <<
DAVINCI_TIMER_ENAMODE_SHIFT_TIM12;
/*
* This function is only ever called if we're using both timer
* halves. In this case TIM34 runs in periodic mode and we must
* not modify it.
*/
tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
}
static void davinci_tim12_set_oneshot(void __iomem *base)
{
unsigned int tcr;
tcr = DAVINCI_TIMER_ENAMODE_ONESHOT <<
DAVINCI_TIMER_ENAMODE_SHIFT_TIM12;
/* Same as above. */
tcr |= DAVINCI_TIMER_ENAMODE_PERIODIC <<
DAVINCI_TIMER_ENAMODE_SHIFT_TIM34;
writel_relaxed(tcr, base + DAVINCI_TIMER_REG_TCR);
}
static int davinci_clockevent_shutdown(struct clock_event_device *dev)
{
struct davinci_clockevent *clockevent;
clockevent = to_davinci_clockevent(dev);
davinci_tim12_shutdown(clockevent->base);
return 0;
}
static int davinci_clockevent_set_oneshot(struct clock_event_device *dev)
{
struct davinci_clockevent *clockevent = to_davinci_clockevent(dev);
davinci_clockevent_write(clockevent, DAVINCI_TIMER_REG_TIM12, 0x0);
davinci_tim12_set_oneshot(clockevent->base);
return 0;
}
static int
davinci_clockevent_set_next_event_std(unsigned long cycles,
struct clock_event_device *dev)
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clockchips.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/of_address.h`, `linux/of_irq.h`, `linux/sched_clock.h`, `clocksource/timer-davinci.h`.
- Detected declarations: `struct davinci_clockevent`, `function to_davinci_clockevent`, `function davinci_clockevent_read`, `function davinci_clockevent_write`, `function davinci_tim12_shutdown`, `function davinci_tim12_set_oneshot`, `function davinci_clockevent_shutdown`, `function davinci_clockevent_set_oneshot`, `function davinci_clockevent_set_next_event_std`, `function davinci_clockevent_set_next_event_cmp`.
- 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.