drivers/rtc/rtc-ds1685.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ds1685.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ds1685.c- Extension
.c- Size
- 41974 bytes
- Lines
- 1441
- Domain
- Driver Families
- Bucket
- drivers/rtc
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/delay.hlinux/io.hlinux/module.hlinux/platform_device.hlinux/rtc.hlinux/workqueue.hlinux/rtc/ds1685.hlinux/proc_fs.h
Detected Declarations
function Copyrightfunction ds1685_writefunction ds1685_indirect_readfunction ds1685_indirect_writefunction ds1685_rtc_bcd2binfunction ds1685_rtc_bin2bcdfunction ds1685_rtc_check_mdayfunction ds1685_rtc_switch_to_bank0function ds1685_rtc_switch_to_bank1function ds1685_rtc_begin_data_accessfunction ds1685_rtc_end_data_accessfunction ds1685_rtc_get_ssnfunction ds1685_rtc_read_timefunction ds1685_rtc_set_timefunction ds1685_rtc_read_alarmfunction ds1685_rtc_set_alarmfunction ds1685_rtc_alarm_irq_enablefunction ds1685_rtc_extended_irqfunction ds1685_rtc_irq_handlerfunction ds1685_rtc_procfunction ds1685_nvram_readfunction ds1685_nvram_writefunction ds1685_rtc_sysfs_battery_showfunction ds1685_rtc_sysfs_auxbatt_showfunction ds1685_rtc_sysfs_serial_showfunction ds1685_rtc_probefunction ds1685_rtc_removefunction ds1685_rtc_poweroffexport ds1685_rtc_poweroff
Annotated Snippet
if (likely(ctrlc & RTC_CTRL_B_PAU_MASK)) {
events = RTC_IRQF;
/* Check for a periodic interrupt. */
if ((ctrlb & RTC_CTRL_B_PIE) &&
(ctrlc & RTC_CTRL_C_PF)) {
events |= RTC_PF;
num_irqs++;
}
/* Check for an alarm interrupt. */
if ((ctrlb & RTC_CTRL_B_AIE) &&
(ctrlc & RTC_CTRL_C_AF)) {
events |= RTC_AF;
num_irqs++;
}
/* Check for an update interrupt. */
if ((ctrlb & RTC_CTRL_B_UIE) &&
(ctrlc & RTC_CTRL_C_UF)) {
events |= RTC_UF;
num_irqs++;
}
} else {
/*
* One of the "extended" interrupts was received that
* is not recognized by the RTC core.
*/
ds1685_rtc_extended_irq(rtc, pdev);
}
}
rtc_update_irq(rtc->dev, num_irqs, events);
rtc_unlock(rtc->dev);
return events ? IRQ_HANDLED : IRQ_NONE;
}
/* ----------------------------------------------------------------------- */
/* ----------------------------------------------------------------------- */
/* ProcFS interface */
#ifdef CONFIG_PROC_FS
#define NUM_REGS 6 /* Num of control registers. */
#define NUM_BITS 8 /* Num bits per register. */
#define NUM_SPACES 4 /* Num spaces between each bit. */
/*
* Periodic Interrupt Rates.
*/
static const char *ds1685_rtc_pirq_rate[16] = {
"none", "3.90625ms", "7.8125ms", "0.122070ms", "0.244141ms",
"0.488281ms", "0.9765625ms", "1.953125ms", "3.90625ms", "7.8125ms",
"15.625ms", "31.25ms", "62.5ms", "125ms", "250ms", "500ms"
};
/*
* Square-Wave Output Frequencies.
*/
static const char *ds1685_rtc_sqw_freq[16] = {
"none", "256Hz", "128Hz", "8192Hz", "4096Hz", "2048Hz", "1024Hz",
"512Hz", "256Hz", "128Hz", "64Hz", "32Hz", "16Hz", "8Hz", "4Hz", "2Hz"
};
/**
* ds1685_rtc_proc - procfs access function.
* @dev: pointer to device structure.
* @seq: pointer to seq_file structure.
*/
static int
ds1685_rtc_proc(struct device *dev, struct seq_file *seq)
{
struct ds1685_priv *rtc = dev_get_drvdata(dev);
u8 ctrla, ctrlb, ctrld, ctrl4a, ctrl4b, ssn[8];
char *model;
/* Read all the relevant data from the control registers. */
ds1685_rtc_switch_to_bank1(rtc);
ds1685_rtc_get_ssn(rtc, ssn);
ctrla = rtc->read(rtc, RTC_CTRL_A);
ctrlb = rtc->read(rtc, RTC_CTRL_B);
ctrld = rtc->read(rtc, RTC_CTRL_D);
ctrl4a = rtc->read(rtc, RTC_EXT_CTRL_4A);
ctrl4b = rtc->read(rtc, RTC_EXT_CTRL_4B);
ds1685_rtc_switch_to_bank0(rtc);
/* Determine the RTC model. */
switch (ssn[0]) {
case RTC_MODEL_DS1685:
model = "DS1685/DS1687\0";
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/delay.h`, `linux/io.h`, `linux/module.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/workqueue.h`, `linux/rtc/ds1685.h`.
- Detected declarations: `function Copyright`, `function ds1685_write`, `function ds1685_indirect_read`, `function ds1685_indirect_write`, `function ds1685_rtc_bcd2bin`, `function ds1685_rtc_bin2bcd`, `function ds1685_rtc_check_mday`, `function ds1685_rtc_switch_to_bank0`, `function ds1685_rtc_switch_to_bank1`, `function ds1685_rtc_begin_data_access`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: integration 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.