drivers/rtc/rtc-m41t80.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-m41t80.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-m41t80.c- Extension
.c- Size
- 27450 bytes
- Lines
- 1045
- Domain
- Driver Families
- Bucket
- drivers/rtc
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/clk-provider.hlinux/i2c.hlinux/init.hlinux/kernel.hlinux/module.hlinux/of.hlinux/rtc.hlinux/slab.hlinux/mutex.hlinux/string.hlinux/delay.hlinux/fs.hlinux/ioctl.hlinux/miscdevice.hlinux/reboot.hlinux/watchdog.h
Detected Declarations
struct m41t80_datafunction m41t80_handle_irqfunction m41t80_rtc_read_timefunction m41t80_rtc_set_timefunction m41t80_rtc_procfunction m41t80_alarm_irq_enablefunction m41t80_set_alarmfunction m41t80_read_alarmfunction m41t80_suspendfunction m41t80_resumefunction m41t80_decode_freqfunction m41t80_get_freqfunction m41t80_sqw_recalc_ratefunction m41t80_sqw_determine_ratefunction m41t80_sqw_set_ratefunction m41t80_sqw_controlfunction m41t80_sqw_preparefunction m41t80_sqw_unpreparefunction m41t80_sqw_is_preparedfunction wdt_pingfunction wdt_disablefunction wdt_writefunction wdt_readfunction wdt_ioctlfunction wdt_unlocked_ioctlfunction wdt_openfunction wdt_releasefunction wdt_notify_sysfunction m41t80_probefunction m41t80_remove
Annotated Snippet
static const struct file_operations wdt_fops = {
.owner = THIS_MODULE,
.read = wdt_read,
.unlocked_ioctl = wdt_unlocked_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.write = wdt_write,
.open = wdt_open,
.release = wdt_release,
};
static struct miscdevice wdt_dev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &wdt_fops,
};
/*
* The WDT card needs to learn about soft shutdowns in order to
* turn the timebomb registers off.
*/
static struct notifier_block wdt_notifier = {
.notifier_call = wdt_notify_sys,
};
#endif /* CONFIG_RTC_DRV_M41T80_WDT */
/*
*****************************************************************************
*
* Driver Interface
*
*****************************************************************************
*/
static int m41t80_probe(struct i2c_client *client)
{
struct i2c_adapter *adapter = client->adapter;
int rc = 0;
struct rtc_time tm;
struct m41t80_data *m41t80_data = NULL;
bool wakeup_source = false;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK |
I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_err(&adapter->dev, "doesn't support I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK\n");
return -ENODEV;
}
m41t80_data = devm_kzalloc(&client->dev, sizeof(*m41t80_data),
GFP_KERNEL);
if (!m41t80_data)
return -ENOMEM;
m41t80_data->client = client;
m41t80_data->features = (unsigned long)i2c_get_match_data(client);
i2c_set_clientdata(client, m41t80_data);
m41t80_data->rtc = devm_rtc_allocate_device(&client->dev);
if (IS_ERR(m41t80_data->rtc))
return PTR_ERR(m41t80_data->rtc);
wakeup_source = device_property_read_bool(&client->dev, "wakeup-source");
if (client->irq > 0) {
unsigned long irqflags = IRQF_TRIGGER_LOW;
if (dev_fwnode(&client->dev))
irqflags = 0;
rc = devm_request_threaded_irq(&client->dev, client->irq,
NULL, m41t80_handle_irq,
irqflags | IRQF_ONESHOT,
"m41t80", client);
if (rc) {
dev_warn(&client->dev, "unable to request IRQ, alarms disabled\n");
client->irq = 0;
wakeup_source = false;
}
}
if (client->irq > 0 || wakeup_source)
device_init_wakeup(&client->dev, true);
else
clear_bit(RTC_FEATURE_ALARM, m41t80_data->rtc->features);
m41t80_data->rtc->ops = &m41t80_rtc_ops;
m41t80_data->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
m41t80_data->rtc->range_max = RTC_TIMESTAMP_END_2099;
if (client->irq <= 0)
clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, m41t80_data->rtc->features);
/* Make sure HT (Halt Update) bit is cleared */
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/clk-provider.h`, `linux/i2c.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/rtc.h`.
- Detected declarations: `struct m41t80_data`, `function m41t80_handle_irq`, `function m41t80_rtc_read_time`, `function m41t80_rtc_set_time`, `function m41t80_rtc_proc`, `function m41t80_alarm_irq_enable`, `function m41t80_set_alarm`, `function m41t80_read_alarm`, `function m41t80_suspend`, `function m41t80_resume`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.