drivers/clocksource/renesas-ostm.c
Source file repositories/reference/linux-study-clean/drivers/clocksource/renesas-ostm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clocksource/renesas-ostm.c- Extension
.c- Size
- 5711 bytes
- Lines
- 248
- 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/platform_device.hlinux/reset.hlinux/sched_clock.hlinux/slab.htimer-of.h
Detected Declarations
function ostm_timer_stopfunction ostm_init_clksrcfunction ostm_read_sched_clockfunction ostm_init_sched_clockfunction ostm_clock_event_nextfunction ostm_shutdownfunction ostm_set_periodicfunction ostm_set_oneshotfunction ostm_timer_interruptfunction ostm_init_clkevtfunction ostm_initfunction ostm_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Renesas Timer Support - OSTM
*
* Copyright (C) 2017 Renesas Electronics America, Inc.
* Copyright (C) 2017 Chris Brandt
*/
#include <linux/clk.h>
#include <linux/clockchips.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/reset.h>
#include <linux/sched_clock.h>
#include <linux/slab.h>
#include "timer-of.h"
/*
* The OSTM contains independent channels.
* The first OSTM channel probed will be set up as a free running
* clocksource. Additionally we will use this clocksource for the system
* schedule timer sched_clock().
*
* The second (or more) channel probed will be set up as an interrupt
* driven clock event.
*/
static void __iomem *system_clock; /* For sched_clock() */
/* OSTM REGISTERS */
#define OSTM_CMP 0x000 /* RW,32 */
#define OSTM_CNT 0x004 /* R,32 */
#define OSTM_TE 0x010 /* R,8 */
#define OSTM_TS 0x014 /* W,8 */
#define OSTM_TT 0x018 /* W,8 */
#define OSTM_CTL 0x020 /* RW,8 */
#define TE 0x01
#define TS 0x01
#define TT 0x01
#define CTL_PERIODIC 0x00
#define CTL_ONESHOT 0x02
#define CTL_FREERUN 0x02
static void ostm_timer_stop(struct timer_of *to)
{
if (readb(timer_of_base(to) + OSTM_TE) & TE) {
writeb(TT, timer_of_base(to) + OSTM_TT);
/*
* Read back the register simply to confirm the write operation
* has completed since I/O writes can sometimes get queued by
* the bus architecture.
*/
while (readb(timer_of_base(to) + OSTM_TE) & TE)
;
}
}
static int __init ostm_init_clksrc(struct timer_of *to)
{
ostm_timer_stop(to);
writel(0, timer_of_base(to) + OSTM_CMP);
writeb(CTL_FREERUN, timer_of_base(to) + OSTM_CTL);
writeb(TS, timer_of_base(to) + OSTM_TS);
return clocksource_mmio_init(timer_of_base(to) + OSTM_CNT,
to->np->full_name, timer_of_rate(to), 300,
32, clocksource_mmio_readl_up);
}
static u64 notrace ostm_read_sched_clock(void)
{
return readl(system_clock);
}
static void __init ostm_init_sched_clock(struct timer_of *to)
{
system_clock = timer_of_base(to) + OSTM_CNT;
sched_clock_register(ostm_read_sched_clock, 32, timer_of_rate(to));
}
static int ostm_clock_event_next(unsigned long delta,
struct clock_event_device *ced)
{
struct timer_of *to = to_timer_of(ced);
ostm_timer_stop(to);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clockchips.h`, `linux/interrupt.h`, `linux/platform_device.h`, `linux/reset.h`, `linux/sched_clock.h`, `linux/slab.h`, `timer-of.h`.
- Detected declarations: `function ostm_timer_stop`, `function ostm_init_clksrc`, `function ostm_read_sched_clock`, `function ostm_init_sched_clock`, `function ostm_clock_event_next`, `function ostm_shutdown`, `function ostm_set_periodic`, `function ostm_set_oneshot`, `function ostm_timer_interrupt`, `function ostm_init_clkevt`.
- 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.