drivers/rtc/rtc-meson-vrtc.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-meson-vrtc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-meson-vrtc.c- Extension
.c- Size
- 3530 bytes
- Lines
- 151
- 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.
- 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/platform_device.hlinux/rtc.hlinux/io.hlinux/of.hlinux/time64.h
Detected Declarations
struct meson_vrtc_datafunction meson_vrtc_read_timefunction meson_vrtc_set_wakeup_timefunction meson_vrtc_set_alarmfunction meson_vrtc_alarm_irq_enablefunction meson_vrtc_probefunction meson_vrtc_suspendfunction meson_vrtc_resume
Annotated Snippet
struct meson_vrtc_data {
void __iomem *io_alarm;
unsigned long alarm_time;
bool enabled;
};
static int meson_vrtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct timespec64 time;
dev_dbg(dev, "%s\n", __func__);
ktime_get_real_ts64(&time);
rtc_time64_to_tm(time.tv_sec, tm);
return 0;
}
static void meson_vrtc_set_wakeup_time(struct meson_vrtc_data *vrtc,
unsigned long time)
{
writel_relaxed(time, vrtc->io_alarm);
}
static int meson_vrtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{
struct meson_vrtc_data *vrtc = dev_get_drvdata(dev);
dev_dbg(dev, "%s: alarm->enabled=%d\n", __func__, alarm->enabled);
if (alarm->enabled)
vrtc->alarm_time = rtc_tm_to_time64(&alarm->time);
else
vrtc->alarm_time = 0;
return 0;
}
static int meson_vrtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
{
struct meson_vrtc_data *vrtc = dev_get_drvdata(dev);
vrtc->enabled = enabled;
return 0;
}
static const struct rtc_class_ops meson_vrtc_ops = {
.read_time = meson_vrtc_read_time,
.set_alarm = meson_vrtc_set_alarm,
.alarm_irq_enable = meson_vrtc_alarm_irq_enable,
};
static int meson_vrtc_probe(struct platform_device *pdev)
{
struct meson_vrtc_data *vrtc;
struct rtc_device *rtc;
vrtc = devm_kzalloc(&pdev->dev, sizeof(*vrtc), GFP_KERNEL);
if (!vrtc)
return -ENOMEM;
vrtc->io_alarm = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(vrtc->io_alarm))
return PTR_ERR(vrtc->io_alarm);
device_init_wakeup(&pdev->dev, true);
platform_set_drvdata(pdev, vrtc);
rtc = devm_rtc_allocate_device(&pdev->dev);
if (IS_ERR(rtc))
return PTR_ERR(rtc);
rtc->ops = &meson_vrtc_ops;
return devm_rtc_register_device(rtc);
}
static int __maybe_unused meson_vrtc_suspend(struct device *dev)
{
struct meson_vrtc_data *vrtc = dev_get_drvdata(dev);
dev_dbg(dev, "%s\n", __func__);
if (vrtc->alarm_time) {
unsigned long local_time;
long alarm_secs;
struct timespec64 time;
ktime_get_real_ts64(&time);
local_time = time.tv_sec;
dev_dbg(dev, "alarm_time = %lus, local_time=%lus\n",
vrtc->alarm_time, local_time);
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/io.h`, `linux/of.h`, `linux/time64.h`.
- Detected declarations: `struct meson_vrtc_data`, `function meson_vrtc_read_time`, `function meson_vrtc_set_wakeup_time`, `function meson_vrtc_set_alarm`, `function meson_vrtc_alarm_irq_enable`, `function meson_vrtc_probe`, `function meson_vrtc_suspend`, `function meson_vrtc_resume`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
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.