drivers/rtc/rtc-rc5t583.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-rc5t583.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-rc5t583.c- Extension
.c- Size
- 8177 bytes
- Lines
- 313
- 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/kernel.hlinux/errno.hlinux/init.hlinux/module.hlinux/types.hlinux/rtc.hlinux/bcd.hlinux/platform_device.hlinux/interrupt.hlinux/mfd/rc5t583.h
Detected Declarations
struct rc5t583_rtcfunction rc5t583_rtc_alarm_irq_enablefunction rc5t583_rtc_read_timefunction rc5t583_rtc_set_timefunction rc5t583_rtc_read_alarmfunction rc5t583_rtc_set_alarmfunction rc5t583_rtc_interruptfunction rc5t583_rtc_probefunction rc5t583_rtc_removefunction rc5t583_rtc_suspendfunction rc5t583_rtc_resume
Annotated Snippet
struct rc5t583_rtc {
struct rtc_device *rtc;
/* To store the list of enabled interrupts, during system suspend */
u32 irqen;
};
/* Total number of RTC registers needed to set time*/
#define NUM_TIME_REGS (RC5T583_RTC_YEAR - RC5T583_RTC_SEC + 1)
/* Total number of RTC registers needed to set Y-Alarm*/
#define NUM_YAL_REGS (RC5T583_RTC_AY_YEAR - RC5T583_RTC_AY_MIN + 1)
/* Set Y-Alarm interrupt */
#define SET_YAL BIT(5)
/* Get Y-Alarm interrupt status*/
#define GET_YAL_STATUS BIT(3)
static int rc5t583_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
{
struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
u8 val;
/* Set Y-Alarm, based on 'enabled' */
val = enabled ? SET_YAL : 0;
return regmap_update_bits(rc5t583->regmap, RC5T583_RTC_CTL1, SET_YAL,
val);
}
/*
* Gets current rc5t583 RTC time and date parameters.
*
* The RTC's time/alarm representation is not what gmtime(3) requires
* Linux to use:
*
* - Months are 1..12 vs Linux 0-11
* - Years are 0..99 vs Linux 1900..N (we assume 21st century)
*/
static int rc5t583_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
u8 rtc_data[NUM_TIME_REGS];
int ret;
ret = regmap_bulk_read(rc5t583->regmap, RC5T583_RTC_SEC, rtc_data,
NUM_TIME_REGS);
if (ret < 0) {
dev_err(dev, "RTC read time failed with err:%d\n", ret);
return ret;
}
tm->tm_sec = bcd2bin(rtc_data[0]);
tm->tm_min = bcd2bin(rtc_data[1]);
tm->tm_hour = bcd2bin(rtc_data[2]);
tm->tm_wday = bcd2bin(rtc_data[3]);
tm->tm_mday = bcd2bin(rtc_data[4]);
tm->tm_mon = bcd2bin(rtc_data[5]) - 1;
tm->tm_year = bcd2bin(rtc_data[6]) + 100;
return ret;
}
static int rc5t583_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
unsigned char rtc_data[NUM_TIME_REGS];
int ret;
rtc_data[0] = bin2bcd(tm->tm_sec);
rtc_data[1] = bin2bcd(tm->tm_min);
rtc_data[2] = bin2bcd(tm->tm_hour);
rtc_data[3] = bin2bcd(tm->tm_wday);
rtc_data[4] = bin2bcd(tm->tm_mday);
rtc_data[5] = bin2bcd(tm->tm_mon + 1);
rtc_data[6] = bin2bcd(tm->tm_year - 100);
ret = regmap_bulk_write(rc5t583->regmap, RC5T583_RTC_SEC, rtc_data,
NUM_TIME_REGS);
if (ret < 0) {
dev_err(dev, "RTC set time failed with error %d\n", ret);
return ret;
}
return ret;
}
static int rc5t583_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
{
struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/init.h`, `linux/module.h`, `linux/types.h`, `linux/rtc.h`, `linux/bcd.h`, `linux/platform_device.h`.
- Detected declarations: `struct rc5t583_rtc`, `function rc5t583_rtc_alarm_irq_enable`, `function rc5t583_rtc_read_time`, `function rc5t583_rtc_set_time`, `function rc5t583_rtc_read_alarm`, `function rc5t583_rtc_set_alarm`, `function rc5t583_rtc_interrupt`, `function rc5t583_rtc_probe`, `function rc5t583_rtc_remove`, `function rc5t583_rtc_suspend`.
- 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.