drivers/rtc/rtc-spear.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-spear.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-spear.c- Extension
.c- Size
- 12746 bytes
- Lines
- 493
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bcd.hlinux/clk.hlinux/delay.hlinux/init.hlinux/io.hlinux/irq.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/rtc.hlinux/slab.hlinux/spinlock.h
Detected Declarations
struct spear_rtc_configfunction spear_rtc_clear_interruptfunction spear_rtc_enable_interruptfunction spear_rtc_disable_interruptfunction is_write_completefunction rtc_wait_not_busyfunction spear_rtc_irqfunction tm2bcdfunction bcd2tmfunction spear_rtc_read_timefunction spear_rtc_set_timefunction spear_rtc_read_alarmfunction spear_rtc_set_alarmfunction spear_alarm_irq_enablefunction spear_rtc_probefunction spear_rtc_removefunction spear_rtc_suspendfunction spear_rtc_resumefunction spear_rtc_shutdown
Annotated Snippet
struct spear_rtc_config {
struct rtc_device *rtc;
struct clk *clk;
spinlock_t lock;
void __iomem *ioaddr;
unsigned int irq_wake;
};
static inline void spear_rtc_clear_interrupt(struct spear_rtc_config *config)
{
unsigned int val;
unsigned long flags;
spin_lock_irqsave(&config->lock, flags);
val = readl(config->ioaddr + STATUS_REG);
val |= RTC_INT_MASK;
writel(val, config->ioaddr + STATUS_REG);
spin_unlock_irqrestore(&config->lock, flags);
}
static inline void spear_rtc_enable_interrupt(struct spear_rtc_config *config)
{
unsigned int val;
val = readl(config->ioaddr + CTRL_REG);
if (!(val & INT_ENABLE)) {
spear_rtc_clear_interrupt(config);
val |= INT_ENABLE;
writel(val, config->ioaddr + CTRL_REG);
}
}
static inline void spear_rtc_disable_interrupt(struct spear_rtc_config *config)
{
unsigned int val;
val = readl(config->ioaddr + CTRL_REG);
if (val & INT_ENABLE) {
val &= ~INT_ENABLE;
writel(val, config->ioaddr + CTRL_REG);
}
}
static inline int is_write_complete(struct spear_rtc_config *config)
{
int ret = 0;
unsigned long flags;
spin_lock_irqsave(&config->lock, flags);
if ((readl(config->ioaddr + STATUS_REG)) & STATUS_FAIL)
ret = -EIO;
spin_unlock_irqrestore(&config->lock, flags);
return ret;
}
static void rtc_wait_not_busy(struct spear_rtc_config *config)
{
int status, count = 0;
unsigned long flags;
/* Assuming BUSY may stay active for 80 msec) */
for (count = 0; count < 80; count++) {
spin_lock_irqsave(&config->lock, flags);
status = readl(config->ioaddr + STATUS_REG);
spin_unlock_irqrestore(&config->lock, flags);
if ((status & STATUS_BUSY) == 0)
break;
/* check status busy, after each msec */
msleep(1);
}
}
static irqreturn_t spear_rtc_irq(int irq, void *dev_id)
{
struct spear_rtc_config *config = dev_id;
unsigned long events = 0;
unsigned int irq_data;
spin_lock(&config->lock);
irq_data = readl(config->ioaddr + STATUS_REG);
spin_unlock(&config->lock);
if ((irq_data & RTC_INT_MASK)) {
spear_rtc_clear_interrupt(config);
events = RTC_IRQF | RTC_AF;
rtc_update_irq(config->rtc, 1, events);
return IRQ_HANDLED;
} else
return IRQ_NONE;
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/clk.h`, `linux/delay.h`, `linux/init.h`, `linux/io.h`, `linux/irq.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct spear_rtc_config`, `function spear_rtc_clear_interrupt`, `function spear_rtc_enable_interrupt`, `function spear_rtc_disable_interrupt`, `function is_write_complete`, `function rtc_wait_not_busy`, `function spear_rtc_irq`, `function tm2bcd`, `function bcd2tm`, `function spear_rtc_read_time`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.