drivers/clocksource/timer-pistachio.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/timer-pistachio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/timer-pistachio.c- Extension
.c- Size
- 5606 bytes
- Lines
- 217
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/clocksource.hlinux/clockchips.hlinux/delay.hlinux/err.hlinux/init.hlinux/spinlock.hlinux/mfd/syscon.hlinux/of.hlinux/of_address.hlinux/platform_device.hlinux/regmap.hlinux/sched_clock.hlinux/time.h
Detected Declarations
struct pistachio_clocksourcefunction gpt_readlfunction gpt_writelfunction pistachio_clocksource_read_cyclesfunction pistachio_read_sched_clockfunction pistachio_clksrc_set_modefunction pistachio_clksrc_enablefunction pistachio_clksrc_disablefunction pistachio_clocksource_enablefunction pistachio_clocksource_disablefunction pistachio_clksrc_of_init
Annotated Snippet
struct pistachio_clocksource {
void __iomem *base;
raw_spinlock_t lock;
struct clocksource cs;
};
static struct pistachio_clocksource pcs_gpt;
#define to_pistachio_clocksource(cs) \
container_of(cs, struct pistachio_clocksource, cs)
static inline u32 gpt_readl(void __iomem *base, u32 offset, u32 gpt_id)
{
return readl(base + 0x20 * gpt_id + offset);
}
static inline void gpt_writel(void __iomem *base, u32 value, u32 offset,
u32 gpt_id)
{
writel(value, base + 0x20 * gpt_id + offset);
}
static u64 notrace
pistachio_clocksource_read_cycles(struct clocksource *cs)
{
struct pistachio_clocksource *pcs = to_pistachio_clocksource(cs);
__maybe_unused u32 overflow;
u32 counter;
unsigned long flags;
/*
* The counter value is only refreshed after the overflow value is read.
* And they must be read in strict order, hence raw spin lock added.
*/
raw_spin_lock_irqsave(&pcs->lock, flags);
overflow = gpt_readl(pcs->base, TIMER_CURRENT_OVERFLOW_VALUE, 0);
counter = gpt_readl(pcs->base, TIMER_CURRENT_VALUE, 0);
raw_spin_unlock_irqrestore(&pcs->lock, flags);
return (u64)~counter;
}
static u64 notrace pistachio_read_sched_clock(void)
{
return pistachio_clocksource_read_cycles(&pcs_gpt.cs);
}
static void pistachio_clksrc_set_mode(struct clocksource *cs, int timeridx,
int enable)
{
struct pistachio_clocksource *pcs = to_pistachio_clocksource(cs);
u32 val;
val = gpt_readl(pcs->base, TIMER_CFG, timeridx);
if (enable)
val |= TIMER_ME_LOCAL;
else
val &= ~TIMER_ME_LOCAL;
gpt_writel(pcs->base, val, TIMER_CFG, timeridx);
}
static void pistachio_clksrc_enable(struct clocksource *cs, int timeridx)
{
struct pistachio_clocksource *pcs = to_pistachio_clocksource(cs);
/* Disable GPT local before loading reload value */
pistachio_clksrc_set_mode(cs, timeridx, false);
gpt_writel(pcs->base, RELOAD_VALUE, TIMER_RELOAD_VALUE, timeridx);
pistachio_clksrc_set_mode(cs, timeridx, true);
}
static void pistachio_clksrc_disable(struct clocksource *cs, int timeridx)
{
/* Disable GPT local */
pistachio_clksrc_set_mode(cs, timeridx, false);
}
static int pistachio_clocksource_enable(struct clocksource *cs)
{
pistachio_clksrc_enable(cs, 0);
return 0;
}
static void pistachio_clocksource_disable(struct clocksource *cs)
{
pistachio_clksrc_disable(cs, 0);
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clocksource.h`, `linux/clockchips.h`, `linux/delay.h`, `linux/err.h`, `linux/init.h`, `linux/spinlock.h`, `linux/mfd/syscon.h`.
- Detected declarations: `struct pistachio_clocksource`, `function gpt_readl`, `function gpt_writel`, `function pistachio_clocksource_read_cycles`, `function pistachio_read_sched_clock`, `function pistachio_clksrc_set_mode`, `function pistachio_clksrc_enable`, `function pistachio_clksrc_disable`, `function pistachio_clocksource_enable`, `function pistachio_clocksource_disable`.
- 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.
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.