drivers/rtc/rtc-sunxi.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-sunxi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-sunxi.c- Extension
.c- Size
- 12796 bytes
- Lines
- 487
- 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/delay.hlinux/err.hlinux/fs.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/rtc.hlinux/types.h
Detected Declarations
struct sunxi_rtc_data_yearstruct sunxi_rtc_devfunction sunxi_rtc_alarmirqfunction sunxi_rtc_setaiefunction sunxi_rtc_getalarmfunction sunxi_rtc_gettimefunction sunxi_rtc_setalarmfunction sunxi_rtc_waitfunction sunxi_rtc_settimefunction sunxi_rtc_alarm_irq_enablefunction sunxi_rtc_probe
Annotated Snippet
struct sunxi_rtc_data_year {
unsigned int min; /* min year allowed */
unsigned int max; /* max year allowed */
unsigned int mask; /* mask for the year field */
unsigned char leap_shift; /* bit shift to get the leap year */
};
static const struct sunxi_rtc_data_year data_year_param[] = {
[0] = {
.min = 2010,
.max = 2073,
.mask = 0x3f,
.leap_shift = 22,
},
[1] = {
.min = 1970,
.max = 2225,
.mask = 0xff,
.leap_shift = 24,
},
};
struct sunxi_rtc_dev {
struct rtc_device *rtc;
struct device *dev;
const struct sunxi_rtc_data_year *data_year;
void __iomem *base;
int irq;
};
static irqreturn_t sunxi_rtc_alarmirq(int irq, void *id)
{
struct sunxi_rtc_dev *chip = (struct sunxi_rtc_dev *) id;
u32 val;
val = readl(chip->base + SUNXI_ALRM_IRQ_STA);
if (val & SUNXI_ALRM_IRQ_STA_CNT_IRQ_PEND) {
val |= SUNXI_ALRM_IRQ_STA_CNT_IRQ_PEND;
writel(val, chip->base + SUNXI_ALRM_IRQ_STA);
rtc_update_irq(chip->rtc, 1, RTC_AF | RTC_IRQF);
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static void sunxi_rtc_setaie(unsigned int to, struct sunxi_rtc_dev *chip)
{
u32 alrm_val = 0;
u32 alrm_irq_val = 0;
if (to) {
alrm_val = readl(chip->base + SUNXI_ALRM_EN);
alrm_val |= SUNXI_ALRM_EN_CNT_EN;
alrm_irq_val = readl(chip->base + SUNXI_ALRM_IRQ_EN);
alrm_irq_val |= SUNXI_ALRM_IRQ_EN_CNT_IRQ_EN;
} else {
writel(SUNXI_ALRM_IRQ_STA_CNT_IRQ_PEND,
chip->base + SUNXI_ALRM_IRQ_STA);
}
writel(alrm_val, chip->base + SUNXI_ALRM_EN);
writel(alrm_irq_val, chip->base + SUNXI_ALRM_IRQ_EN);
}
static int sunxi_rtc_getalarm(struct device *dev, struct rtc_wkalrm *wkalrm)
{
struct sunxi_rtc_dev *chip = dev_get_drvdata(dev);
struct rtc_time *alrm_tm = &wkalrm->time;
u32 alrm;
u32 alrm_en;
u32 date;
alrm = readl(chip->base + SUNXI_ALRM_DHMS);
date = readl(chip->base + SUNXI_RTC_YMD);
alrm_tm->tm_sec = SUNXI_ALRM_GET_SEC_VALUE(alrm);
alrm_tm->tm_min = SUNXI_ALRM_GET_MIN_VALUE(alrm);
alrm_tm->tm_hour = SUNXI_ALRM_GET_HOUR_VALUE(alrm);
alrm_tm->tm_mday = SUNXI_DATE_GET_DAY_VALUE(date);
alrm_tm->tm_mon = SUNXI_DATE_GET_MON_VALUE(date);
alrm_tm->tm_year = SUNXI_DATE_GET_YEAR_VALUE(date,
chip->data_year->mask);
alrm_tm->tm_mon -= 1;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/err.h`, `linux/fs.h`, `linux/init.h`, `linux/interrupt.h`, `linux/io.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct sunxi_rtc_data_year`, `struct sunxi_rtc_dev`, `function sunxi_rtc_alarmirq`, `function sunxi_rtc_setaie`, `function sunxi_rtc_getalarm`, `function sunxi_rtc_gettime`, `function sunxi_rtc_setalarm`, `function sunxi_rtc_wait`, `function sunxi_rtc_settime`, `function sunxi_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.