drivers/rtc/rtc-brcmstb-waketimer.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-brcmstb-waketimer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-brcmstb-waketimer.c- Extension
.c- Size
- 10611 bytes
- Lines
- 433
- Domain
- Driver Families
- Bucket
- drivers/rtc
- 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/device.hlinux/err.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/irqreturn.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm.hlinux/reboot.hlinux/rtc.hlinux/stat.hlinux/suspend.h
Detected Declarations
struct brcmstb_waketmrstruct wktmr_timefunction brcmstb_waketmr_is_pendingfunction brcmstb_waketmr_clear_alarmfunction brcmstb_waketmr_set_alarmfunction brcmstb_waketmr_irqfunction brcmstb_alarm_irqfunction wktmr_readfunction brcmstb_waketmr_prepare_suspendfunction brcmstb_waketmr_rebootfunction brcmstb_waketmr_gettimefunction brcmstb_waketmr_settimefunction brcmstb_waketmr_getalarmfunction brcmstb_waketmr_alarm_enablefunction brcmstb_waketmr_setalarmfunction brcmstb_waketmr_probefunction brcmstb_waketmr_removefunction brcmstb_waketmr_suspendfunction brcmstb_waketmr_suspend_noirqfunction brcmstb_waketmr_resume
Annotated Snippet
struct brcmstb_waketmr {
struct rtc_device *rtc;
struct device *dev;
void __iomem *base;
unsigned int wake_irq;
unsigned int alarm_irq;
struct notifier_block reboot_notifier;
struct clk *clk;
u32 rate;
unsigned long rtc_alarm;
bool alarm_en;
bool alarm_expired;
};
#define BRCMSTB_WKTMR_EVENT 0x00
#define WKTMR_ALARM_EVENT BIT(0)
#define BRCMSTB_WKTMR_COUNTER 0x04
#define BRCMSTB_WKTMR_ALARM 0x08
#define BRCMSTB_WKTMR_PRESCALER 0x0C
#define BRCMSTB_WKTMR_PRESCALER_VAL 0x10
#define BRCMSTB_WKTMR_DEFAULT_FREQ 27000000
static inline bool brcmstb_waketmr_is_pending(struct brcmstb_waketmr *timer)
{
u32 reg;
reg = readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT);
return !!(reg & WKTMR_ALARM_EVENT);
}
static inline void brcmstb_waketmr_clear_alarm(struct brcmstb_waketmr *timer)
{
u32 reg;
if (timer->alarm_en && timer->alarm_irq)
disable_irq(timer->alarm_irq);
timer->alarm_en = false;
reg = readl_relaxed(timer->base + BRCMSTB_WKTMR_COUNTER);
writel_relaxed(reg - 1, timer->base + BRCMSTB_WKTMR_ALARM);
writel_relaxed(WKTMR_ALARM_EVENT, timer->base + BRCMSTB_WKTMR_EVENT);
(void)readl_relaxed(timer->base + BRCMSTB_WKTMR_EVENT);
if (timer->alarm_expired) {
timer->alarm_expired = false;
/* maintain call balance */
enable_irq(timer->alarm_irq);
}
}
static void brcmstb_waketmr_set_alarm(struct brcmstb_waketmr *timer,
unsigned int secs)
{
unsigned int now;
brcmstb_waketmr_clear_alarm(timer);
/* Make sure we are actually counting in seconds */
writel_relaxed(timer->rate, timer->base + BRCMSTB_WKTMR_PRESCALER);
writel_relaxed(secs, timer->base + BRCMSTB_WKTMR_ALARM);
now = readl_relaxed(timer->base + BRCMSTB_WKTMR_COUNTER);
while ((int)(secs - now) <= 0 &&
!brcmstb_waketmr_is_pending(timer)) {
secs = now + 1;
writel_relaxed(secs, timer->base + BRCMSTB_WKTMR_ALARM);
now = readl_relaxed(timer->base + BRCMSTB_WKTMR_COUNTER);
}
}
static irqreturn_t brcmstb_waketmr_irq(int irq, void *data)
{
struct brcmstb_waketmr *timer = data;
if (!timer->alarm_irq)
pm_wakeup_event(timer->dev, 0);
return IRQ_HANDLED;
}
static irqreturn_t brcmstb_alarm_irq(int irq, void *data)
{
struct brcmstb_waketmr *timer = data;
/* Ignore spurious interrupts */
if (!brcmstb_waketmr_is_pending(timer))
return IRQ_HANDLED;
if (timer->alarm_en) {
if (device_may_wakeup(timer->dev)) {
disable_irq_nosync(irq);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/device.h`, `linux/err.h`, `linux/init.h`, `linux/interrupt.h`, `linux/io.h`, `linux/irqreturn.h`, `linux/kernel.h`.
- Detected declarations: `struct brcmstb_waketmr`, `struct wktmr_time`, `function brcmstb_waketmr_is_pending`, `function brcmstb_waketmr_clear_alarm`, `function brcmstb_waketmr_set_alarm`, `function brcmstb_waketmr_irq`, `function brcmstb_alarm_irq`, `function wktmr_read`, `function brcmstb_waketmr_prepare_suspend`, `function brcmstb_waketmr_reboot`.
- Atlas domain: Driver Families / drivers/rtc.
- 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.