drivers/rtc/rtc-max8998.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-max8998.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-max8998.c- Extension
.c- Size
- 7756 bytes
- Lines
- 322
- 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/module.hlinux/i2c.hlinux/slab.hlinux/bcd.hlinux/irqdomain.hlinux/rtc.hlinux/platform_device.hlinux/mfd/max8998.hlinux/mfd/max8998-private.hlinux/delay.h
Detected Declarations
struct max8998_rtc_infofunction max8998_data_to_tmfunction max8998_tm_to_datafunction max8998_rtc_read_timefunction max8998_rtc_set_timefunction max8998_rtc_read_alarmfunction max8998_rtc_stop_alarmfunction max8998_rtc_start_alarmfunction max8998_rtc_set_alarmfunction max8998_rtc_alarm_irq_enablefunction max8998_rtc_alarm_irqfunction max8998_rtc_probe
Annotated Snippet
struct max8998_rtc_info {
struct device *dev;
struct max8998_dev *max8998;
struct i2c_client *rtc;
struct rtc_device *rtc_dev;
int irq;
bool lp3974_bug_workaround;
};
static void max8998_data_to_tm(u8 *data, struct rtc_time *tm)
{
tm->tm_sec = bcd2bin(data[RTC_SEC]);
tm->tm_min = bcd2bin(data[RTC_MIN]);
if (data[RTC_HOUR] & HOUR_12) {
tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x1f);
if (data[RTC_HOUR] & HOUR_PM)
tm->tm_hour += 12;
} else
tm->tm_hour = bcd2bin(data[RTC_HOUR] & 0x3f);
tm->tm_wday = data[RTC_WEEKDAY] & 0x07;
tm->tm_mday = bcd2bin(data[RTC_DATE]);
tm->tm_mon = bcd2bin(data[RTC_MONTH]);
tm->tm_year = bcd2bin(data[RTC_YEAR1]) + bcd2bin(data[RTC_YEAR2]) * 100;
tm->tm_year -= 1900;
}
static void max8998_tm_to_data(struct rtc_time *tm, u8 *data)
{
data[RTC_SEC] = bin2bcd(tm->tm_sec);
data[RTC_MIN] = bin2bcd(tm->tm_min);
data[RTC_HOUR] = bin2bcd(tm->tm_hour);
data[RTC_WEEKDAY] = tm->tm_wday;
data[RTC_DATE] = bin2bcd(tm->tm_mday);
data[RTC_MONTH] = bin2bcd(tm->tm_mon);
data[RTC_YEAR1] = bin2bcd(tm->tm_year % 100);
data[RTC_YEAR2] = bin2bcd((tm->tm_year + 1900) / 100);
}
static int max8998_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct max8998_rtc_info *info = dev_get_drvdata(dev);
u8 data[8];
int ret;
ret = max8998_bulk_read(info->rtc, MAX8998_RTC_SEC, 8, data);
if (ret < 0)
return ret;
max8998_data_to_tm(data, tm);
return 0;
}
static int max8998_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct max8998_rtc_info *info = dev_get_drvdata(dev);
u8 data[8];
int ret;
max8998_tm_to_data(tm, data);
ret = max8998_bulk_write(info->rtc, MAX8998_RTC_SEC, 8, data);
if (info->lp3974_bug_workaround)
msleep(2000);
return ret;
}
static int max8998_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct max8998_rtc_info *info = dev_get_drvdata(dev);
u8 data[8];
u8 val;
int ret;
ret = max8998_bulk_read(info->rtc, MAX8998_ALARM0_SEC, 8, data);
if (ret < 0)
return ret;
max8998_data_to_tm(data, &alrm->time);
ret = max8998_read_reg(info->rtc, MAX8998_ALARM0_CONF, &val);
if (ret < 0)
return ret;
alrm->enabled = !!val;
ret = max8998_read_reg(info->rtc, MAX8998_RTC_STATUS, &val);
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/slab.h`, `linux/bcd.h`, `linux/irqdomain.h`, `linux/rtc.h`, `linux/platform_device.h`, `linux/mfd/max8998.h`.
- Detected declarations: `struct max8998_rtc_info`, `function max8998_data_to_tm`, `function max8998_tm_to_data`, `function max8998_rtc_read_time`, `function max8998_rtc_set_time`, `function max8998_rtc_read_alarm`, `function max8998_rtc_stop_alarm`, `function max8998_rtc_start_alarm`, `function max8998_rtc_set_alarm`, `function max8998_rtc_alarm_irq_enable`.
- 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.