drivers/rtc/rtc-ds1216.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ds1216.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ds1216.c- Extension
.c- Size
- 3859 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.
- 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/platform_device.hlinux/bcd.hlinux/slab.h
Detected Declarations
struct ds1216_regsstruct ds1216_privfunction ds1216_readfunction ds1216_writefunction ds1216_switch_ds_to_clockfunction ds1216_rtc_read_timefunction ds1216_rtc_set_timefunction ds1216_rtc_probe
Annotated Snippet
struct ds1216_regs {
u8 tsec;
u8 sec;
u8 min;
u8 hour;
u8 wday;
u8 mday;
u8 month;
u8 year;
};
#define DS1216_HOUR_1224 (1 << 7)
#define DS1216_HOUR_AMPM (1 << 5)
struct ds1216_priv {
struct rtc_device *rtc;
void __iomem *ioaddr;
};
static const u8 magic[] = {
0xc5, 0x3a, 0xa3, 0x5c, 0xc5, 0x3a, 0xa3, 0x5c
};
/*
* Read the 64 bit we'd like to have - It a series
* of 64 bits showing up in the LSB of the base register.
*
*/
static void ds1216_read(u8 __iomem *ioaddr, u8 *buf)
{
unsigned char c;
int i, j;
for (i = 0; i < 8; i++) {
c = 0;
for (j = 0; j < 8; j++)
c |= (readb(ioaddr) & 0x1) << j;
buf[i] = c;
}
}
static void ds1216_write(u8 __iomem *ioaddr, const u8 *buf)
{
unsigned char c;
int i, j;
for (i = 0; i < 8; i++) {
c = buf[i];
for (j = 0; j < 8; j++) {
writeb(c, ioaddr);
c = c >> 1;
}
}
}
static void ds1216_switch_ds_to_clock(u8 __iomem *ioaddr)
{
/* Reset magic pointer */
readb(ioaddr);
/* Write 64 bit magic to DS1216 */
ds1216_write(ioaddr, magic);
}
static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct ds1216_priv *priv = dev_get_drvdata(dev);
struct ds1216_regs regs;
ds1216_switch_ds_to_clock(priv->ioaddr);
ds1216_read(priv->ioaddr, (u8 *)®s);
tm->tm_sec = bcd2bin(regs.sec);
tm->tm_min = bcd2bin(regs.min);
if (regs.hour & DS1216_HOUR_1224) {
/* AM/PM mode */
tm->tm_hour = bcd2bin(regs.hour & 0x1f);
if (regs.hour & DS1216_HOUR_AMPM)
tm->tm_hour += 12;
} else
tm->tm_hour = bcd2bin(regs.hour & 0x3f);
tm->tm_wday = (regs.wday & 7) - 1;
tm->tm_mday = bcd2bin(regs.mday & 0x3f);
tm->tm_mon = bcd2bin(regs.month & 0x1f);
tm->tm_year = bcd2bin(regs.year);
if (tm->tm_year < 70)
tm->tm_year += 100;
return 0;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/rtc.h`, `linux/platform_device.h`, `linux/bcd.h`, `linux/slab.h`.
- Detected declarations: `struct ds1216_regs`, `struct ds1216_priv`, `function ds1216_read`, `function ds1216_write`, `function ds1216_switch_ds_to_clock`, `function ds1216_rtc_read_time`, `function ds1216_rtc_set_time`, `function ds1216_rtc_probe`.
- 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.