drivers/rtc/rtc-digicolor.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-digicolor.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-digicolor.c- Extension
.c- Size
- 5281 bytes
- Lines
- 225
- 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/io.hlinux/iopoll.hlinux/delay.hlinux/module.hlinux/platform_device.hlinux/rtc.hlinux/of.h
Detected Declarations
struct dc_rtcfunction dc_rtc_cmdsfunction dc_rtc_readfunction dc_rtc_writefunction dc_rtc_read_timefunction dc_rtc_set_timefunction dc_rtc_read_alarmfunction dc_rtc_set_alarmfunction dc_rtc_alarm_irq_enablefunction dc_rtc_irqfunction dc_rtc_probe
Annotated Snippet
struct dc_rtc {
struct rtc_device *rtc_dev;
void __iomem *regs;
};
static int dc_rtc_cmds(struct dc_rtc *rtc, const u8 *cmds, int len)
{
u8 val;
int i, ret;
for (i = 0; i < len; i++) {
writeb_relaxed((cmds[i] & DC_RTC_CMD_MASK) | DC_RTC_GO_BUSY,
rtc->regs + DC_RTC_CONTROL);
ret = readb_relaxed_poll_timeout(
rtc->regs + DC_RTC_CONTROL, val,
!(val & DC_RTC_GO_BUSY), CMD_DELAY_US, CMD_TIMEOUT_US);
if (ret < 0)
return ret;
}
return 0;
}
static int dc_rtc_read(struct dc_rtc *rtc, unsigned long *val)
{
static const u8 read_cmds[] = {CMD_READ, CMD_NOP};
u32 reference, time1, time2;
int ret;
ret = dc_rtc_cmds(rtc, read_cmds, ARRAY_SIZE(read_cmds));
if (ret < 0)
return ret;
reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
time1 = readl_relaxed(rtc->regs + DC_RTC_TIME);
/* Read twice to ensure consistency */
while (1) {
time2 = readl_relaxed(rtc->regs + DC_RTC_TIME);
if (time1 == time2)
break;
time1 = time2;
}
*val = reference + time1;
return 0;
}
static int dc_rtc_write(struct dc_rtc *rtc, u32 val)
{
static const u8 write_cmds[] = {CMD_WRITE, CMD_NOP, CMD_RESET, CMD_NOP};
writel_relaxed(val, rtc->regs + DC_RTC_REFERENCE);
return dc_rtc_cmds(rtc, write_cmds, ARRAY_SIZE(write_cmds));
}
static int dc_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct dc_rtc *rtc = dev_get_drvdata(dev);
unsigned long now;
int ret;
ret = dc_rtc_read(rtc, &now);
if (ret < 0)
return ret;
rtc_time64_to_tm(now, tm);
return 0;
}
static int dc_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct dc_rtc *rtc = dev_get_drvdata(dev);
return dc_rtc_write(rtc, rtc_tm_to_time64(tm));
}
static int dc_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{
struct dc_rtc *rtc = dev_get_drvdata(dev);
u32 alarm_reg, reference;
unsigned long now;
int ret;
alarm_reg = readl_relaxed(rtc->regs + DC_RTC_ALARM);
reference = readl_relaxed(rtc->regs + DC_RTC_REFERENCE);
rtc_time64_to_tm(reference + alarm_reg, &alarm->time);
ret = dc_rtc_read(rtc, &now);
if (ret < 0)
return ret;
Annotation
- Immediate include surface: `linux/io.h`, `linux/iopoll.h`, `linux/delay.h`, `linux/module.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/of.h`.
- Detected declarations: `struct dc_rtc`, `function dc_rtc_cmds`, `function dc_rtc_read`, `function dc_rtc_write`, `function dc_rtc_read_time`, `function dc_rtc_set_time`, `function dc_rtc_read_alarm`, `function dc_rtc_set_alarm`, `function dc_rtc_alarm_irq_enable`, `function dc_rtc_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.