drivers/rtc/rtc-pic32.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-pic32.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-pic32.c- Extension
.c- Size
- 9766 bytes
- Lines
- 382
- 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/init.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/io.hlinux/slab.hlinux/clk.hlinux/rtc.hlinux/bcd.hlinux/platform_data/pic32.h
Detected Declarations
struct pic32_rtc_devfunction pic32_rtc_alarm_clk_enablefunction pic32_rtc_alarmirqfunction pic32_rtc_setaiefunction pic32_rtc_setfreqfunction pic32_rtc_gettimefunction pic32_rtc_settimefunction pic32_rtc_getalarmfunction pic32_rtc_setalarmfunction pic32_rtc_procfunction pic32_rtc_enablefunction pic32_rtc_removefunction pic32_rtc_probe
Annotated Snippet
struct pic32_rtc_dev {
struct rtc_device *rtc;
void __iomem *reg_base;
struct clk *clk;
spinlock_t alarm_lock;
int alarm_irq;
bool alarm_clk_enabled;
};
static void pic32_rtc_alarm_clk_enable(struct pic32_rtc_dev *pdata,
bool enable)
{
unsigned long flags;
spin_lock_irqsave(&pdata->alarm_lock, flags);
if (enable) {
if (!pdata->alarm_clk_enabled) {
clk_enable(pdata->clk);
pdata->alarm_clk_enabled = true;
}
} else {
if (pdata->alarm_clk_enabled) {
clk_disable(pdata->clk);
pdata->alarm_clk_enabled = false;
}
}
spin_unlock_irqrestore(&pdata->alarm_lock, flags);
}
static irqreturn_t pic32_rtc_alarmirq(int irq, void *id)
{
struct pic32_rtc_dev *pdata = (struct pic32_rtc_dev *)id;
clk_enable(pdata->clk);
rtc_update_irq(pdata->rtc, 1, RTC_AF | RTC_IRQF);
clk_disable(pdata->clk);
pic32_rtc_alarm_clk_enable(pdata, false);
return IRQ_HANDLED;
}
static int pic32_rtc_setaie(struct device *dev, unsigned int enabled)
{
struct pic32_rtc_dev *pdata = dev_get_drvdata(dev);
void __iomem *base = pdata->reg_base;
clk_enable(pdata->clk);
writel(PIC32_RTCALRM_ALRMEN,
base + (enabled ? PIC32_SET(PIC32_RTCALRM) :
PIC32_CLR(PIC32_RTCALRM)));
clk_disable(pdata->clk);
pic32_rtc_alarm_clk_enable(pdata, enabled);
return 0;
}
static int pic32_rtc_setfreq(struct device *dev, int freq)
{
struct pic32_rtc_dev *pdata = dev_get_drvdata(dev);
void __iomem *base = pdata->reg_base;
clk_enable(pdata->clk);
writel(PIC32_RTCALRM_AMASK, base + PIC32_CLR(PIC32_RTCALRM));
writel(freq << 8, base + PIC32_SET(PIC32_RTCALRM));
writel(PIC32_RTCALRM_CHIME, base + PIC32_SET(PIC32_RTCALRM));
clk_disable(pdata->clk);
return 0;
}
static int pic32_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
{
struct pic32_rtc_dev *pdata = dev_get_drvdata(dev);
void __iomem *base = pdata->reg_base;
unsigned int tries = 0;
clk_enable(pdata->clk);
do {
rtc_tm->tm_hour = readb(base + PIC32_RTCHOUR);
rtc_tm->tm_min = readb(base + PIC32_RTCMIN);
rtc_tm->tm_mon = readb(base + PIC32_RTCMON);
rtc_tm->tm_mday = readb(base + PIC32_RTCDAY);
rtc_tm->tm_year = readb(base + PIC32_RTCYEAR);
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/io.h`, `linux/slab.h`, `linux/clk.h`, `linux/rtc.h`.
- Detected declarations: `struct pic32_rtc_dev`, `function pic32_rtc_alarm_clk_enable`, `function pic32_rtc_alarmirq`, `function pic32_rtc_setaie`, `function pic32_rtc_setfreq`, `function pic32_rtc_gettime`, `function pic32_rtc_settime`, `function pic32_rtc_getalarm`, `function pic32_rtc_setalarm`, `function pic32_rtc_proc`.
- 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.