drivers/rtc/rtc-rzn1.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-rzn1.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-rzn1.c- Extension
.c- Size
- 13384 bytes
- Lines
- 519
- 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/init.hlinux/iopoll.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/pm_runtime.hlinux/rtc.hlinux/spinlock.h
Detected Declarations
struct rzn1_rtcfunction rzn1_rtc_get_time_snapshotfunction rzn1_rtc_read_timefunction rzn1_rtc_set_timefunction rzn1_rtc_alarm_irqfunction rzn1_rtc_1s_irqfunction rzn1_rtc_alarm_irq_enablefunction rzn1_rtc_read_alarmfunction rzn1_rtc_set_alarmfunction rzn1_rtc_read_offsetfunction rzn1_rtc_set_offsetfunction rzn1_rtc_probefunction rzn1_rtc_remove
Annotated Snippet
struct rzn1_rtc {
struct rtc_device *rtcdev;
void __iomem *base;
/*
* Protects access to RZN1_RTC_CTL1 reg. rtc_lock with threaded_irqs
* would introduce race conditions when switching interrupts because
* of potential sleeps
*/
spinlock_t ctl1_access_lock;
struct rtc_time tm_alarm;
};
static void rzn1_rtc_get_time_snapshot(struct rzn1_rtc *rtc, struct rtc_time *tm)
{
u32 val;
val = readl(rtc->base + RZN1_RTC_TIMEC);
tm->tm_sec = bcd2bin(val);
tm->tm_min = bcd2bin(val >> RZN1_RTC_TIME_MIN_SHIFT);
tm->tm_hour = bcd2bin(val >> RZN1_RTC_TIME_HOUR_SHIFT);
val = readl(rtc->base + RZN1_RTC_CALC);
tm->tm_wday = val & 0x0f;
tm->tm_mday = bcd2bin(val >> RZN1_RTC_CAL_DAY_SHIFT);
tm->tm_mon = bcd2bin(val >> RZN1_RTC_CAL_MON_SHIFT) - 1;
tm->tm_year = bcd2bin(val >> RZN1_RTC_CAL_YEAR_SHIFT) + 100;
}
static int rzn1_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct rzn1_rtc *rtc = dev_get_drvdata(dev);
u32 val, secs;
/*
* The RTC was not started or is stopped and thus does not carry the
* proper time/date.
*/
val = readl(rtc->base + RZN1_RTC_CTL2);
if (val & RZN1_RTC_CTL2_STOPPED)
return -EINVAL;
rzn1_rtc_get_time_snapshot(rtc, tm);
secs = readl(rtc->base + RZN1_RTC_SECC);
if (tm->tm_sec != bcd2bin(secs))
rzn1_rtc_get_time_snapshot(rtc, tm);
return 0;
}
static int rzn1_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct rzn1_rtc *rtc = dev_get_drvdata(dev);
u32 val;
int ret;
val = readl(rtc->base + RZN1_RTC_CTL2);
if (!(val & RZN1_RTC_CTL2_STOPPED)) {
/* Hold the counter if it was counting up */
writel(RZN1_RTC_CTL2_WAIT, rtc->base + RZN1_RTC_CTL2);
/* Wait for the counter to stop: two 32k clock cycles */
usleep_range(61, 100);
ret = readl_poll_timeout(rtc->base + RZN1_RTC_CTL2, val,
val & RZN1_RTC_CTL2_WST, 0, 100);
if (ret)
return ret;
}
val = bin2bcd(tm->tm_sec);
val |= bin2bcd(tm->tm_min) << RZN1_RTC_TIME_MIN_SHIFT;
val |= bin2bcd(tm->tm_hour) << RZN1_RTC_TIME_HOUR_SHIFT;
writel(val, rtc->base + RZN1_RTC_TIME);
val = tm->tm_wday;
val |= bin2bcd(tm->tm_mday) << RZN1_RTC_CAL_DAY_SHIFT;
val |= bin2bcd(tm->tm_mon + 1) << RZN1_RTC_CAL_MON_SHIFT;
val |= bin2bcd(tm->tm_year - 100) << RZN1_RTC_CAL_YEAR_SHIFT;
writel(val, rtc->base + RZN1_RTC_CAL);
writel(0, rtc->base + RZN1_RTC_CTL2);
return 0;
}
static irqreturn_t rzn1_rtc_alarm_irq(int irq, void *dev_id)
{
struct rzn1_rtc *rtc = dev_id;
u32 ctl1, set_irq_bits = 0;
if (rtc->tm_alarm.tm_sec == 0)
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/clk.h`, `linux/init.h`, `linux/iopoll.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/pm_runtime.h`.
- Detected declarations: `struct rzn1_rtc`, `function rzn1_rtc_get_time_snapshot`, `function rzn1_rtc_read_time`, `function rzn1_rtc_set_time`, `function rzn1_rtc_alarm_irq`, `function rzn1_rtc_1s_irq`, `function rzn1_rtc_alarm_irq_enable`, `function rzn1_rtc_read_alarm`, `function rzn1_rtc_set_alarm`, `function rzn1_rtc_read_offset`.
- 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.