drivers/rtc/rtc-as3722.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-as3722.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-as3722.c- Extension
.c- Size
- 6730 bytes
- Lines
- 253
- 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/bcd.hlinux/completion.hlinux/delay.hlinux/interrupt.hlinux/ioctl.hlinux/kernel.hlinux/module.hlinux/mfd/as3722.hlinux/platform_device.hlinux/rtc.hlinux/time.h
Detected Declarations
struct as3722_rtcfunction as3722_time_to_regfunction as3722_reg_to_timefunction as3722_rtc_read_timefunction as3722_rtc_set_timefunction as3722_rtc_alarm_irq_enablefunction as3722_rtc_read_alarmfunction as3722_rtc_set_alarmfunction as3722_alarm_irqfunction as3722_rtc_probefunction as3722_rtc_suspendfunction as3722_rtc_resume
Annotated Snippet
struct as3722_rtc {
struct rtc_device *rtc;
struct device *dev;
struct as3722 *as3722;
int alarm_irq;
bool irq_enable;
};
static void as3722_time_to_reg(u8 *rbuff, struct rtc_time *tm)
{
rbuff[0] = bin2bcd(tm->tm_sec);
rbuff[1] = bin2bcd(tm->tm_min);
rbuff[2] = bin2bcd(tm->tm_hour);
rbuff[3] = bin2bcd(tm->tm_mday);
rbuff[4] = bin2bcd(tm->tm_mon + 1);
rbuff[5] = bin2bcd(tm->tm_year - (AS3722_RTC_START_YEAR - 1900));
}
static void as3722_reg_to_time(u8 *rbuff, struct rtc_time *tm)
{
tm->tm_sec = bcd2bin(rbuff[0] & 0x7F);
tm->tm_min = bcd2bin(rbuff[1] & 0x7F);
tm->tm_hour = bcd2bin(rbuff[2] & 0x3F);
tm->tm_mday = bcd2bin(rbuff[3] & 0x3F);
tm->tm_mon = bcd2bin(rbuff[4] & 0x1F) - 1;
tm->tm_year = (AS3722_RTC_START_YEAR - 1900) + bcd2bin(rbuff[5] & 0x7F);
return;
}
static int as3722_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
struct as3722 *as3722 = as3722_rtc->as3722;
u8 as_time_array[6];
int ret;
ret = as3722_block_read(as3722, AS3722_RTC_SECOND_REG,
6, as_time_array);
if (ret < 0) {
dev_err(dev, "RTC_SECOND reg block read failed %d\n", ret);
return ret;
}
as3722_reg_to_time(as_time_array, tm);
return 0;
}
static int as3722_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
struct as3722 *as3722 = as3722_rtc->as3722;
u8 as_time_array[6];
int ret;
if (tm->tm_year < (AS3722_RTC_START_YEAR - 1900))
return -EINVAL;
as3722_time_to_reg(as_time_array, tm);
ret = as3722_block_write(as3722, AS3722_RTC_SECOND_REG, 6,
as_time_array);
if (ret < 0)
dev_err(dev, "RTC_SECOND reg block write failed %d\n", ret);
return ret;
}
static int as3722_rtc_alarm_irq_enable(struct device *dev,
unsigned int enabled)
{
struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
if (enabled && !as3722_rtc->irq_enable) {
enable_irq(as3722_rtc->alarm_irq);
as3722_rtc->irq_enable = true;
} else if (!enabled && as3722_rtc->irq_enable) {
disable_irq(as3722_rtc->alarm_irq);
as3722_rtc->irq_enable = false;
}
return 0;
}
static int as3722_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
struct as3722 *as3722 = as3722_rtc->as3722;
u8 as_time_array[6];
int ret;
ret = as3722_block_read(as3722, AS3722_RTC_ALARM_SECOND_REG, 6,
as_time_array);
if (ret < 0) {
dev_err(dev, "RTC_ALARM_SECOND block read failed %d\n", ret);
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/completion.h`, `linux/delay.h`, `linux/interrupt.h`, `linux/ioctl.h`, `linux/kernel.h`, `linux/module.h`, `linux/mfd/as3722.h`.
- Detected declarations: `struct as3722_rtc`, `function as3722_time_to_reg`, `function as3722_reg_to_time`, `function as3722_rtc_read_time`, `function as3722_rtc_set_time`, `function as3722_rtc_alarm_irq_enable`, `function as3722_rtc_read_alarm`, `function as3722_rtc_set_alarm`, `function as3722_alarm_irq`, `function as3722_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.