drivers/rtc/rtc-pl030.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-pl030.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-pl030.c- Extension
.c- Size
- 3573 bytes
- Lines
- 175
- 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/module.hlinux/rtc.hlinux/init.hlinux/interrupt.hlinux/amba/bus.hlinux/io.hlinux/slab.h
Detected Declarations
struct pl030_rtcfunction pl030_interruptfunction pl030_read_alarmfunction pl030_set_alarmfunction pl030_read_timefunction pl030_set_timefunction pl030_probefunction pl030_remove
Annotated Snippet
struct pl030_rtc {
void __iomem *base;
};
static irqreturn_t pl030_interrupt(int irq, void *dev_id)
{
struct pl030_rtc *rtc = dev_id;
writel(0, rtc->base + RTC_EOI);
return IRQ_HANDLED;
}
static int pl030_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);
rtc_time64_to_tm(readl(rtc->base + RTC_MR), &alrm->time);
return 0;
}
static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);
writel(rtc_tm_to_time64(&alrm->time), rtc->base + RTC_MR);
return 0;
}
static int pl030_read_time(struct device *dev, struct rtc_time *tm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);
rtc_time64_to_tm(readl(rtc->base + RTC_DR), tm);
return 0;
}
/*
* Set the RTC time. Unfortunately, we can't accurately set
* the point at which the counter updates.
*
* Also, since RTC_LR is transferred to RTC_CR on next rising
* edge of the 1Hz clock, we must write the time one second
* in advance.
*/
static int pl030_set_time(struct device *dev, struct rtc_time *tm)
{
struct pl030_rtc *rtc = dev_get_drvdata(dev);
writel(rtc_tm_to_time64(tm) + 1, rtc->base + RTC_LR);
return 0;
}
static const struct rtc_class_ops pl030_ops = {
.read_time = pl030_read_time,
.set_time = pl030_set_time,
.read_alarm = pl030_read_alarm,
.set_alarm = pl030_set_alarm,
};
static int pl030_probe(struct amba_device *dev, const struct amba_id *id)
{
struct pl030_rtc *rtc;
int ret;
struct rtc_device *rtc_dev;
ret = amba_request_regions(dev, NULL);
if (ret)
goto err_req;
rtc = devm_kzalloc(&dev->dev, sizeof(*rtc), GFP_KERNEL);
if (!rtc) {
ret = -ENOMEM;
goto err_rtc;
}
rtc_dev = devm_rtc_allocate_device(&dev->dev);
if (IS_ERR(rtc_dev)) {
ret = PTR_ERR(rtc_dev);
goto err_rtc;
}
rtc_dev->ops = &pl030_ops;
rtc_dev->range_max = U32_MAX;
rtc->base = ioremap(dev->res.start, resource_size(&dev->res));
if (!rtc->base) {
ret = -ENOMEM;
goto err_rtc;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/rtc.h`, `linux/init.h`, `linux/interrupt.h`, `linux/amba/bus.h`, `linux/io.h`, `linux/slab.h`.
- Detected declarations: `struct pl030_rtc`, `function pl030_interrupt`, `function pl030_read_alarm`, `function pl030_set_alarm`, `function pl030_read_time`, `function pl030_set_time`, `function pl030_probe`, `function pl030_remove`.
- 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.