drivers/rtc/rtc-ds1307.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ds1307.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ds1307.c- Extension
.c- Size
- 51336 bytes
- Lines
- 2039
- 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/i2c.hlinux/init.hlinux/kstrtox.hlinux/mod_devicetable.hlinux/module.hlinux/property.hlinux/rtc/ds1307.hlinux/rtc.hlinux/slab.hlinux/string.hlinux/hwmon.hlinux/hwmon-sysfs.hlinux/clk-provider.hlinux/regmap.hlinux/watchdog.h
Detected Declarations
struct ds1307struct chip_descenum ds_typefunction ds1307_get_timefunction ds1307_set_timefunction ds1337_read_alarmfunction ds1337_set_alarmfunction ds1307_alarm_irq_enablefunction do_trickle_setup_ds1339function do_trickle_setup_rx8130function rx8130_irqfunction rx8130_read_alarmfunction rx8130_set_alarmfunction rx8130_alarm_irq_enablefunction mcp794xx_irqfunction mcp794xx_read_alarmfunction mcp794xx_alm_weekdayfunction mcp794xx_set_alarmfunction mcp794xx_alarm_irq_enablefunction m41txx_rtc_read_offsetfunction m41txx_rtc_set_offsetfunction ds1388_wdt_startfunction ds1388_wdt_stopfunction ds1388_wdt_pingfunction ds1388_wdt_set_timeoutfunction ds1307_irqfunction frequency_test_storefunction frequency_test_showfunction ds1307_add_frequency_testfunction ds1307_nvram_readfunction ds1307_nvram_writefunction ds1307_trickle_initfunction ds3231_hwmon_read_tempfunction ds3231_hwmon_show_tempfunction ds1307_hwmon_registerfunction ds1307_hwmon_registerfunction ds1337_write_controlfunction ds3231_clk_sqw_recalc_ratefunction ds3231_clk_sqw_determine_ratefunction ds3231_clk_sqw_set_ratefunction ds3231_clk_sqw_preparefunction ds3231_clk_sqw_unpreparefunction ds3231_clk_sqw_is_preparedfunction ds3231_clk_32khz_recalc_ratefunction ds3231_clk_32khz_controlfunction ds3231_clk_32khz_preparefunction ds3231_clk_32khz_unpreparefunction ds3231_clk_32khz_is_prepared
Annotated Snippet
struct ds1307 {
enum ds_type type;
struct device *dev;
struct regmap *regmap;
const char *name;
struct rtc_device *rtc;
#ifdef CONFIG_COMMON_CLK
struct clk_hw clks[2];
#endif
};
struct chip_desc {
unsigned alarm:1;
u16 nvram_offset;
u16 nvram_size;
u8 offset; /* register's offset */
u8 century_reg;
u8 century_enable_bit;
u8 century_bit;
u8 bbsqi_bit;
irq_handler_t irq_handler;
const struct rtc_class_ops *rtc_ops;
u16 trickle_charger_reg;
u8 (*do_trickle_setup)(struct ds1307 *, u32,
bool);
/* Does the RTC require trickle-resistor-ohms to select the value of
* the resistor between Vcc and Vbackup?
*/
bool requires_trickle_resistor;
/* Some RTC's batteries and supercaps were charged by default, others
* allow charging but were not configured previously to do so.
* Remember this behavior to stay backwards compatible.
*/
bool charge_default;
};
static const struct chip_desc chips[last_ds_type];
static int ds1307_get_time(struct device *dev, struct rtc_time *t)
{
struct ds1307 *ds1307 = dev_get_drvdata(dev);
int tmp, ret;
const struct chip_desc *chip = &chips[ds1307->type];
u8 regs[7];
if (ds1307->type == rx_8130) {
unsigned int regflag;
ret = regmap_read(ds1307->regmap, RX8130_REG_FLAG, ®flag);
if (ret) {
dev_err(dev, "%s error %d\n", "read", ret);
return ret;
}
if (regflag & RX8130_REG_FLAG_VLF) {
dev_warn_once(dev, "oscillator failed, set time!\n");
return -EINVAL;
}
}
/* read the RTC date and time registers all at once */
ret = regmap_bulk_read(ds1307->regmap, chip->offset, regs,
sizeof(regs));
if (ret) {
dev_err(dev, "%s error %d\n", "read", ret);
return ret;
}
dev_dbg(dev, "%s: %7ph\n", "read", regs);
/* if oscillator fail bit is set, no data can be trusted */
if (ds1307->type == m41t0 &&
regs[DS1307_REG_MIN] & M41T0_BIT_OF) {
dev_warn_once(dev, "oscillator failed, set time!\n");
return -EINVAL;
} else if (ds1307->type == mcp794xx &&
!(regs[DS1307_REG_WDAY] & MCP794XX_BIT_OSCRUN)) {
dev_warn_once(dev, "oscillator failed, set time!\n");
return -EINVAL;
}
tmp = regs[DS1307_REG_SECS];
switch (ds1307->type) {
case ds_1307:
case m41t0:
case m41t00:
case m41t11:
if (tmp & DS1307_BIT_CH)
return -EINVAL;
break;
case ds_1308:
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/i2c.h`, `linux/init.h`, `linux/kstrtox.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/property.h`, `linux/rtc/ds1307.h`.
- Detected declarations: `struct ds1307`, `struct chip_desc`, `enum ds_type`, `function ds1307_get_time`, `function ds1307_set_time`, `function ds1337_read_alarm`, `function ds1337_set_alarm`, `function ds1307_alarm_irq_enable`, `function do_trickle_setup_ds1339`, `function do_trickle_setup_rx8130`.
- 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.