drivers/rtc/rtc-ds1305.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ds1305.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ds1305.c- Extension
.c- Size
- 19956 bytes
- Lines
- 748
- 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/kernel.hlinux/init.hlinux/bcd.hlinux/slab.hlinux/rtc.hlinux/workqueue.hlinux/spi/spi.hlinux/spi/ds1305.hlinux/module.h
Detected Declarations
struct ds1305function softwarefunction hour2bcdfunction ds1305_alarm_irq_enablefunction ds1305_get_timefunction ds1305_set_timefunction ds1305_get_alarmfunction ds1305_set_alarmfunction ds1305_procfunction ds1305_workfunction ds1305_irqfunction msg_initfunction ds1305_nvram_readfunction ds1305_nvram_writefunction ds1305_probefunction modesfunction ds1305_remove
Annotated Snippet
struct ds1305 {
struct spi_device *spi;
struct rtc_device *rtc;
struct work_struct work;
unsigned long flags;
#define FLAG_EXITING 0
bool hr12;
u8 ctrl[DS1305_CONTROL_LEN];
};
/*----------------------------------------------------------------------*/
/*
* Utilities ... tolerate 12-hour AM/PM notation in case of non-Linux
* software (like a bootloader) which may require it.
*/
static unsigned bcd2hour(u8 bcd)
{
if (bcd & DS1305_HR_12) {
unsigned hour = 0;
bcd &= ~DS1305_HR_12;
if (bcd & DS1305_HR_PM) {
hour = 12;
bcd &= ~DS1305_HR_PM;
}
hour += bcd2bin(bcd);
return hour - 1;
}
return bcd2bin(bcd);
}
static u8 hour2bcd(bool hr12, int hour)
{
if (hr12) {
hour++;
if (hour <= 12)
return DS1305_HR_12 | bin2bcd(hour);
hour -= 12;
return DS1305_HR_12 | DS1305_HR_PM | bin2bcd(hour);
}
return bin2bcd(hour);
}
/*----------------------------------------------------------------------*/
/*
* Interface to RTC framework
*/
static int ds1305_alarm_irq_enable(struct device *dev, unsigned int enabled)
{
struct ds1305 *ds1305 = dev_get_drvdata(dev);
u8 buf[2];
long err = -EINVAL;
buf[0] = DS1305_WRITE | DS1305_CONTROL;
buf[1] = ds1305->ctrl[0];
if (enabled) {
if (ds1305->ctrl[0] & DS1305_AEI0)
goto done;
buf[1] |= DS1305_AEI0;
} else {
if (!(buf[1] & DS1305_AEI0))
goto done;
buf[1] &= ~DS1305_AEI0;
}
err = spi_write_then_read(ds1305->spi, buf, sizeof(buf), NULL, 0);
if (err >= 0)
ds1305->ctrl[0] = buf[1];
done:
return err;
}
/*
* Get/set of date and time is pretty normal.
*/
static int ds1305_get_time(struct device *dev, struct rtc_time *time)
{
struct ds1305 *ds1305 = dev_get_drvdata(dev);
u8 addr = DS1305_SEC;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/bcd.h`, `linux/slab.h`, `linux/rtc.h`, `linux/workqueue.h`, `linux/spi/spi.h`, `linux/spi/ds1305.h`.
- Detected declarations: `struct ds1305`, `function software`, `function hour2bcd`, `function ds1305_alarm_irq_enable`, `function ds1305_get_time`, `function ds1305_set_time`, `function ds1305_get_alarm`, `function ds1305_set_alarm`, `function ds1305_proc`, `function ds1305_work`.
- 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.