drivers/rtc/rtc-mc13xxx.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-mc13xxx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-mc13xxx.c- Extension
.c- Size
- 7822 bytes
- Lines
- 351
- 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/mfd/mc13xxx.hlinux/platform_device.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/slab.hlinux/rtc.h
Detected Declarations
struct mc13xxx_rtcfunction mc13xxx_rtc_irq_enable_unlockedfunction mc13xxx_rtc_alarm_irq_enablefunction mc13xxx_rtc_read_timefunction mc13xxx_rtc_set_timefunction mc13xxx_rtc_read_alarmfunction mc13xxx_rtc_set_alarmfunction mc13xxx_rtc_alarm_handlerfunction mc13xxx_rtc_reset_handlerfunction mc13xxx_rtc_probefunction mc13xxx_rtc_remove
Annotated Snippet
struct mc13xxx_rtc {
struct rtc_device *rtc;
struct mc13xxx *mc13xxx;
int valid;
};
static int mc13xxx_rtc_irq_enable_unlocked(struct device *dev,
unsigned int enabled, int irq)
{
struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
int (*func)(struct mc13xxx *mc13xxx, int irq);
if (!priv->valid)
return -ENODATA;
func = enabled ? mc13xxx_irq_unmask : mc13xxx_irq_mask;
return func(priv->mc13xxx, irq);
}
static int mc13xxx_rtc_alarm_irq_enable(struct device *dev,
unsigned int enabled)
{
struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
int ret;
mc13xxx_lock(priv->mc13xxx);
ret = mc13xxx_rtc_irq_enable_unlocked(dev, enabled, MC13XXX_IRQ_TODA);
mc13xxx_unlock(priv->mc13xxx);
return ret;
}
static int mc13xxx_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
unsigned int seconds, days1, days2;
if (!priv->valid)
return -ENODATA;
do {
int ret;
ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCDAY, &days1);
if (ret)
return ret;
ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCTOD, &seconds);
if (ret)
return ret;
ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCDAY, &days2);
if (ret)
return ret;
} while (days1 != days2);
rtc_time64_to_tm((time64_t)days1 * SEC_PER_DAY + seconds, tm);
return 0;
}
static int mc13xxx_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct mc13xxx_rtc *priv = dev_get_drvdata(dev);
unsigned int seconds, days;
unsigned int alarmseconds;
int ret;
days = div_s64_rem(rtc_tm_to_time64(tm), SEC_PER_DAY, &seconds);
mc13xxx_lock(priv->mc13xxx);
/*
* temporarily invalidate alarm to prevent triggering it when the day is
* already updated while the time isn't yet.
*/
ret = mc13xxx_reg_read(priv->mc13xxx, MC13XXX_RTCTODA, &alarmseconds);
if (unlikely(ret))
goto out;
if (alarmseconds < SEC_PER_DAY) {
ret = mc13xxx_reg_write(priv->mc13xxx,
MC13XXX_RTCTODA, 0x1ffff);
if (unlikely(ret))
goto out;
}
/*
Annotation
- Immediate include surface: `linux/mfd/mc13xxx.h`, `linux/platform_device.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/slab.h`, `linux/rtc.h`.
- Detected declarations: `struct mc13xxx_rtc`, `function mc13xxx_rtc_irq_enable_unlocked`, `function mc13xxx_rtc_alarm_irq_enable`, `function mc13xxx_rtc_read_time`, `function mc13xxx_rtc_set_time`, `function mc13xxx_rtc_read_alarm`, `function mc13xxx_rtc_set_alarm`, `function mc13xxx_rtc_alarm_handler`, `function mc13xxx_rtc_reset_handler`, `function mc13xxx_rtc_probe`.
- 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.