drivers/rtc/rtc-wm831x.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-wm831x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-wm831x.c- Extension
.c- Size
- 12600 bytes
- Lines
- 476
- 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/kernel.hlinux/time.hlinux/rtc.hlinux/slab.hlinux/bcd.hlinux/interrupt.hlinux/ioctl.hlinux/completion.hlinux/mfd/wm831x/core.hlinux/delay.hlinux/platform_device.hlinux/random.h
Detected Declarations
struct wm831x_rtcfunction wm831x_rtc_add_randomnessfunction wm831x_rtc_readtimefunction wm831x_rtc_settimefunction wm831x_rtc_readalarmfunction wm831x_rtc_stop_alarmfunction wm831x_rtc_start_alarmfunction wm831x_rtc_setalarmfunction wm831x_rtc_alarm_irq_enablefunction wm831x_alm_irqfunction wm831x_rtc_suspendfunction wm831x_rtc_resumefunction wm831x_rtc_freezefunction wm831x_rtc_probe
Annotated Snippet
struct wm831x_rtc {
struct wm831x *wm831x;
struct rtc_device *rtc;
unsigned int alarm_enabled:1;
};
static void wm831x_rtc_add_randomness(struct wm831x *wm831x)
{
int ret;
u16 reg;
/*
* The write counter contains a pseudo-random number which is
* regenerated every time we set the RTC so it should be a
* useful per-system source of entropy.
*/
ret = wm831x_reg_read(wm831x, WM831X_RTC_WRITE_COUNTER);
if (ret >= 0) {
reg = ret;
add_device_randomness(®, sizeof(reg));
} else {
dev_warn(wm831x->dev, "Failed to read RTC write counter: %d\n",
ret);
}
}
/*
* Read current time and date in RTC
*/
static int wm831x_rtc_readtime(struct device *dev, struct rtc_time *tm)
{
struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
struct wm831x *wm831x = wm831x_rtc->wm831x;
u16 time1[2], time2[2];
int ret;
int count = 0;
/* Has the RTC been programmed? */
ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL);
if (ret < 0) {
dev_err(dev, "Failed to read RTC control: %d\n", ret);
return ret;
}
if (!(ret & WM831X_RTC_VALID)) {
dev_dbg(dev, "RTC not yet configured\n");
return -EINVAL;
}
/* Read twice to make sure we don't read a corrupt, partially
* incremented, value.
*/
do {
ret = wm831x_bulk_read(wm831x, WM831X_RTC_TIME_1,
2, time1);
if (ret != 0)
continue;
ret = wm831x_bulk_read(wm831x, WM831X_RTC_TIME_1,
2, time2);
if (ret != 0)
continue;
if (memcmp(time1, time2, sizeof(time1)) == 0) {
u32 time = (time1[0] << 16) | time1[1];
rtc_time64_to_tm(time, tm);
return 0;
}
} while (++count < WM831X_GET_TIME_RETRIES);
dev_err(dev, "Timed out reading current time\n");
return -EIO;
}
/*
* Set current time and date in RTC
*/
static int wm831x_rtc_settime(struct device *dev, struct rtc_time *tm)
{
struct wm831x_rtc *wm831x_rtc = dev_get_drvdata(dev);
struct wm831x *wm831x = wm831x_rtc->wm831x;
struct rtc_time new_tm;
unsigned long time, new_time;
int ret;
int count = 0;
time = rtc_tm_to_time64(tm);
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/time.h`, `linux/rtc.h`, `linux/slab.h`, `linux/bcd.h`, `linux/interrupt.h`, `linux/ioctl.h`.
- Detected declarations: `struct wm831x_rtc`, `function wm831x_rtc_add_randomness`, `function wm831x_rtc_readtime`, `function wm831x_rtc_settime`, `function wm831x_rtc_readalarm`, `function wm831x_rtc_stop_alarm`, `function wm831x_rtc_start_alarm`, `function wm831x_rtc_setalarm`, `function wm831x_rtc_alarm_irq_enable`, `function wm831x_alm_irq`.
- 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.