drivers/rtc/rtc-ds1511.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ds1511.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ds1511.c- Extension
.c- Size
- 9466 bytes
- Lines
- 369
- 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/init.hlinux/kernel.hlinux/gfp.hlinux/delay.hlinux/interrupt.hlinux/rtc.hlinux/platform_device.hlinux/io.hlinux/module.h
Detected Declarations
struct ds1511_datafunction rtc_writefunction rtc_readfunction rtc_disable_updatefunction rtc_enable_updatefunction ds1511_rtc_set_timefunction ds1511_rtc_read_timefunction ds1511_rtc_alarm_enablefunction ds1511_rtc_set_alarmfunction ds1511_rtc_read_alarmfunction ds1511_interruptfunction ds1511_rtc_alarm_irq_enablefunction ds1511_nvram_readfunction ds1511_nvram_writefunction ds1511_rtc_probe
Annotated Snippet
struct ds1511_data {
struct rtc_device *rtc;
void __iomem *ioaddr; /* virtual base address */
int irq;
spinlock_t lock;
};
static DEFINE_SPINLOCK(ds1511_lock);
static __iomem char *ds1511_base;
static u32 reg_spacing = 1;
static void rtc_write(uint8_t val, uint32_t reg)
{
writeb(val, ds1511_base + (reg * reg_spacing));
}
static uint8_t rtc_read(uint32_t reg)
{
return readb(ds1511_base + (reg * reg_spacing));
}
static void rtc_disable_update(void)
{
rtc_write((rtc_read(DS1511_CONTROL_B) & ~DS1511_TE), DS1511_CONTROL_B);
}
static void rtc_enable_update(void)
{
rtc_write((rtc_read(DS1511_CONTROL_B) | DS1511_TE), DS1511_CONTROL_B);
}
static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
{
u8 mon, day, dow, hrs, min, sec, yrs, cen;
unsigned long flags;
yrs = rtc_tm->tm_year % 100;
cen = 19 + rtc_tm->tm_year / 100;
mon = rtc_tm->tm_mon + 1; /* tm_mon starts at zero */
day = rtc_tm->tm_mday;
dow = rtc_tm->tm_wday & 0x7; /* automatic BCD */
hrs = rtc_tm->tm_hour;
min = rtc_tm->tm_min;
sec = rtc_tm->tm_sec;
/*
* each register is a different number of valid bits
*/
sec = bin2bcd(sec) & 0x7f;
min = bin2bcd(min) & 0x7f;
hrs = bin2bcd(hrs) & 0x3f;
day = bin2bcd(day) & 0x3f;
mon = bin2bcd(mon) & 0x1f;
yrs = bin2bcd(yrs) & 0xff;
cen = bin2bcd(cen) & 0xff;
spin_lock_irqsave(&ds1511_lock, flags);
rtc_disable_update();
rtc_write(cen, DS1511_CENTURY);
rtc_write(yrs, DS1511_YEAR);
rtc_write((rtc_read(DS1511_MONTH) & 0xe0) | mon, DS1511_MONTH);
rtc_write(day, DS1511_DOM);
rtc_write(hrs, DS1511_HOUR);
rtc_write(min, DS1511_MIN);
rtc_write(sec, DS1511_SEC);
rtc_write(dow, DS1511_DOW);
rtc_enable_update();
spin_unlock_irqrestore(&ds1511_lock, flags);
return 0;
}
static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
{
unsigned int century;
unsigned long flags;
spin_lock_irqsave(&ds1511_lock, flags);
rtc_disable_update();
rtc_tm->tm_sec = rtc_read(DS1511_SEC) & 0x7f;
rtc_tm->tm_min = rtc_read(DS1511_MIN) & 0x7f;
rtc_tm->tm_hour = rtc_read(DS1511_HOUR) & 0x3f;
rtc_tm->tm_mday = rtc_read(DS1511_DOM) & 0x3f;
rtc_tm->tm_wday = rtc_read(DS1511_DOW) & 0x7;
rtc_tm->tm_mon = rtc_read(DS1511_MONTH) & 0x1f;
rtc_tm->tm_year = rtc_read(DS1511_YEAR) & 0x7f;
century = rtc_read(DS1511_CENTURY);
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/init.h`, `linux/kernel.h`, `linux/gfp.h`, `linux/delay.h`, `linux/interrupt.h`, `linux/rtc.h`, `linux/platform_device.h`.
- Detected declarations: `struct ds1511_data`, `function rtc_write`, `function rtc_read`, `function rtc_disable_update`, `function rtc_enable_update`, `function ds1511_rtc_set_time`, `function ds1511_rtc_read_time`, `function ds1511_rtc_alarm_enable`, `function ds1511_rtc_set_alarm`, `function ds1511_rtc_read_alarm`.
- 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.