drivers/rtc/rtc-pcf8523.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-pcf8523.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-pcf8523.c- Extension
.c- Size
- 12497 bytes
- Lines
- 524
- 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 user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/bitfield.hlinux/i2c.hlinux/module.hlinux/regmap.hlinux/rtc.hlinux/of.hlinux/pm_wakeirq.h
Detected Declarations
struct pcf8523function pcf8523_load_capacitancefunction pcf8523_irqfunction pcf8523_rtc_read_timefunction pcf8523_rtc_set_timefunction pcf8523_rtc_read_alarmfunction pcf8523_irq_enablefunction pcf8523_rtc_set_alarmfunction pcf8523_param_getfunction pcf8523_param_setfunction pcf8523_rtc_ioctlfunction pcf8523_rtc_read_offsetfunction pcf8523_rtc_set_offsetfunction pcf8523_suspendfunction pcf8523_resumefunction pcf8523_probe
Annotated Snippet
struct pcf8523 {
struct rtc_device *rtc;
struct regmap *regmap;
};
static int pcf8523_load_capacitance(struct pcf8523 *pcf8523, struct device_node *node)
{
u32 load, value = 0;
load = 12500;
of_property_read_u32(node, "quartz-load-femtofarads", &load);
switch (load) {
default:
dev_warn(&pcf8523->rtc->dev, "Unknown quartz-load-femtofarads value: %d. Assuming 12500",
load);
fallthrough;
case 12500:
value = PCF8523_CONTROL1_CAP_SEL;
break;
case 7000:
break;
}
return regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL1,
PCF8523_CONTROL1_CAP_SEL, value);
}
static irqreturn_t pcf8523_irq(int irq, void *dev_id)
{
struct pcf8523 *pcf8523 = dev_id;
u32 value;
int err;
err = regmap_read(pcf8523->regmap, PCF8523_REG_CONTROL2, &value);
if (err < 0)
return IRQ_HANDLED;
if (value & PCF8523_CONTROL2_AF) {
value &= ~PCF8523_CONTROL2_AF;
regmap_write(pcf8523->regmap, PCF8523_REG_CONTROL2, value);
rtc_update_irq(pcf8523->rtc, 1, RTC_IRQF | RTC_AF);
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static int pcf8523_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct pcf8523 *pcf8523 = dev_get_drvdata(dev);
u8 regs[10];
int err;
err = regmap_bulk_read(pcf8523->regmap, PCF8523_REG_CONTROL1, regs,
sizeof(regs));
if (err < 0)
return err;
if ((regs[0] & PCF8523_CONTROL1_STOP) || (regs[3] & PCF8523_SECONDS_OS))
return -EINVAL;
tm->tm_sec = bcd2bin(regs[3] & 0x7f);
tm->tm_min = bcd2bin(regs[4] & 0x7f);
tm->tm_hour = bcd2bin(regs[5] & 0x3f);
tm->tm_mday = bcd2bin(regs[6] & 0x3f);
tm->tm_wday = regs[7] & 0x7;
tm->tm_mon = bcd2bin(regs[8] & 0x1f) - 1;
tm->tm_year = bcd2bin(regs[9]) + 100;
return 0;
}
static int pcf8523_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct pcf8523 *pcf8523 = dev_get_drvdata(dev);
u8 regs[7];
int err;
err = regmap_update_bits(pcf8523->regmap, PCF8523_REG_CONTROL1,
PCF8523_CONTROL1_STOP, PCF8523_CONTROL1_STOP);
if (err < 0)
return err;
/* This will purposely overwrite PCF8523_SECONDS_OS */
regs[0] = bin2bcd(tm->tm_sec);
regs[1] = bin2bcd(tm->tm_min);
regs[2] = bin2bcd(tm->tm_hour);
regs[3] = bin2bcd(tm->tm_mday);
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/bitfield.h`, `linux/i2c.h`, `linux/module.h`, `linux/regmap.h`, `linux/rtc.h`, `linux/of.h`, `linux/pm_wakeirq.h`.
- Detected declarations: `struct pcf8523`, `function pcf8523_load_capacitance`, `function pcf8523_irq`, `function pcf8523_rtc_read_time`, `function pcf8523_rtc_set_time`, `function pcf8523_rtc_read_alarm`, `function pcf8523_irq_enable`, `function pcf8523_rtc_set_alarm`, `function pcf8523_param_get`, `function pcf8523_param_set`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.