drivers/rtc/rtc-st-lpc.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-st-lpc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-st-lpc.c- Extension
.c- Size
- 7542 bytes
- Lines
- 315
- 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/clk.hlinux/delay.hlinux/init.hlinux/io.hlinux/irq.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_irq.hlinux/platform_device.hlinux/rtc.hdt-bindings/mfd/st-lpc.h
Detected Declarations
struct st_rtcfunction st_rtc_set_hw_alarmfunction st_rtc_handlerfunction st_rtc_read_timefunction st_rtc_set_timefunction st_rtc_read_alarmfunction st_rtc_alarm_irq_enablefunction st_rtc_set_alarmfunction st_rtc_probefunction st_rtc_suspendfunction st_rtc_resume
Annotated Snippet
struct st_rtc {
struct rtc_device *rtc_dev;
struct rtc_wkalrm alarm;
struct clk *clk;
unsigned long clkrate;
void __iomem *ioaddr;
bool irq_enabled:1;
spinlock_t lock;
short irq;
};
static void st_rtc_set_hw_alarm(struct st_rtc *rtc,
unsigned long msb, unsigned long lsb)
{
unsigned long flags;
spin_lock_irqsave(&rtc->lock, flags);
writel_relaxed(1, rtc->ioaddr + LPC_WDT_OFF);
writel_relaxed(msb, rtc->ioaddr + LPC_LPA_MSB_OFF);
writel_relaxed(lsb, rtc->ioaddr + LPC_LPA_LSB_OFF);
writel_relaxed(1, rtc->ioaddr + LPC_LPA_START_OFF);
writel_relaxed(0, rtc->ioaddr + LPC_WDT_OFF);
spin_unlock_irqrestore(&rtc->lock, flags);
}
static irqreturn_t st_rtc_handler(int this_irq, void *data)
{
struct st_rtc *rtc = (struct st_rtc *)data;
rtc_update_irq(rtc->rtc_dev, 1, RTC_AF);
return IRQ_HANDLED;
}
static int st_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
unsigned long lpt_lsb, lpt_msb;
unsigned long long lpt;
unsigned long flags;
spin_lock_irqsave(&rtc->lock, flags);
do {
lpt_msb = readl_relaxed(rtc->ioaddr + LPC_LPT_MSB_OFF);
lpt_lsb = readl_relaxed(rtc->ioaddr + LPC_LPT_LSB_OFF);
} while (readl_relaxed(rtc->ioaddr + LPC_LPT_MSB_OFF) != lpt_msb);
spin_unlock_irqrestore(&rtc->lock, flags);
lpt = ((unsigned long long)lpt_msb << 32) | lpt_lsb;
do_div(lpt, rtc->clkrate);
rtc_time64_to_tm(lpt, tm);
return 0;
}
static int st_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
unsigned long long lpt, secs;
unsigned long flags;
secs = rtc_tm_to_time64(tm);
lpt = (unsigned long long)secs * rtc->clkrate;
spin_lock_irqsave(&rtc->lock, flags);
writel_relaxed(lpt >> 32, rtc->ioaddr + LPC_LPT_MSB_OFF);
writel_relaxed(lpt, rtc->ioaddr + LPC_LPT_LSB_OFF);
writel_relaxed(1, rtc->ioaddr + LPC_LPT_START_OFF);
spin_unlock_irqrestore(&rtc->lock, flags);
return 0;
}
static int st_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
{
struct st_rtc *rtc = dev_get_drvdata(dev);
unsigned long flags;
spin_lock_irqsave(&rtc->lock, flags);
memcpy(wkalrm, &rtc->alarm, sizeof(struct rtc_wkalrm));
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/init.h`, `linux/io.h`, `linux/irq.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct st_rtc`, `function st_rtc_set_hw_alarm`, `function st_rtc_handler`, `function st_rtc_read_time`, `function st_rtc_set_time`, `function st_rtc_read_alarm`, `function st_rtc_alarm_irq_enable`, `function st_rtc_set_alarm`, `function st_rtc_probe`, `function st_rtc_suspend`.
- 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.