drivers/rtc/rtc-ds1374.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ds1374.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ds1374.c- Extension
.c- Size
- 14485 bytes
- Lines
- 585
- 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/kernel.hlinux/module.hlinux/interrupt.hlinux/i2c.hlinux/rtc.hlinux/bcd.hlinux/workqueue.hlinux/slab.hlinux/pm.hlinux/fs.hlinux/ioctl.hlinux/miscdevice.hlinux/reboot.hlinux/watchdog.h
Detected Declarations
struct ds1374function ds1374_read_rtcfunction ds1374_write_rtcfunction ds1374_check_rtc_statusfunction ds1374_read_timefunction ds1374_set_timefunction ds1374_read_alarmfunction ds1374_set_alarmfunction ds1374_irqfunction ds1374_workfunction ds1374_alarm_irq_enablefunction ds1374_wdt_settimeoutfunction ds1374_wdt_startfunction ds1374_wdt_stopfunction ds1374_probefunction ds1374_removefunction ds1374_suspendfunction ds1374_resume
Annotated Snippet
struct ds1374 {
struct i2c_client *client;
struct rtc_device *rtc;
struct work_struct work;
#ifdef CONFIG_RTC_DRV_DS1374_WDT
struct watchdog_device wdt;
#endif
/* The mutex protects alarm operations, and prevents a race
* between the enable_irq() in the workqueue and the free_irq()
* in the remove function.
*/
struct mutex mutex;
int exiting;
};
static struct i2c_driver ds1374_driver;
static int ds1374_read_rtc(struct i2c_client *client, u32 *time,
int reg, int nbytes)
{
u8 buf[4];
int ret;
int i;
if (WARN_ON(nbytes > 4))
return -EINVAL;
ret = i2c_smbus_read_i2c_block_data(client, reg, nbytes, buf);
if (ret < 0)
return ret;
if (ret < nbytes)
return -EIO;
for (i = nbytes - 1, *time = 0; i >= 0; i--)
*time = (*time << 8) | buf[i];
return 0;
}
static int ds1374_write_rtc(struct i2c_client *client, u32 time,
int reg, int nbytes)
{
u8 buf[4];
int i;
if (nbytes > 4) {
WARN_ON(1);
return -EINVAL;
}
for (i = 0; i < nbytes; i++) {
buf[i] = time & 0xff;
time >>= 8;
}
return i2c_smbus_write_i2c_block_data(client, reg, nbytes, buf);
}
static int ds1374_check_rtc_status(struct i2c_client *client)
{
int ret = 0;
int control, stat;
stat = i2c_smbus_read_byte_data(client, DS1374_REG_SR);
if (stat < 0)
return stat;
if (stat & DS1374_REG_SR_OSF)
dev_warn(&client->dev,
"oscillator discontinuity flagged, time unreliable\n");
stat &= ~(DS1374_REG_SR_OSF | DS1374_REG_SR_AF);
ret = i2c_smbus_write_byte_data(client, DS1374_REG_SR, stat);
if (ret < 0)
return ret;
/* If the alarm is pending, clear it before requesting
* the interrupt, so an interrupt event isn't reported
* before everything is initialized.
*/
control = i2c_smbus_read_byte_data(client, DS1374_REG_CR);
if (control < 0)
return control;
control &= ~(DS1374_REG_CR_WACE | DS1374_REG_CR_AIE);
return i2c_smbus_write_byte_data(client, DS1374_REG_CR, control);
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/interrupt.h`, `linux/i2c.h`, `linux/rtc.h`, `linux/bcd.h`, `linux/workqueue.h`, `linux/slab.h`.
- Detected declarations: `struct ds1374`, `function ds1374_read_rtc`, `function ds1374_write_rtc`, `function ds1374_check_rtc_status`, `function ds1374_read_time`, `function ds1374_set_time`, `function ds1374_read_alarm`, `function ds1374_set_alarm`, `function ds1374_irq`, `function ds1374_work`.
- 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.