drivers/rtc/rtc-tps65910.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-tps65910.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-tps65910.c- Extension
.c- Size
- 12239 bytes
- Lines
- 471
- 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/math64.hlinux/property.hlinux/platform_device.hlinux/interrupt.hlinux/mfd/tps65910.h
Detected Declarations
struct tps65910_rtcfunction tps65910_rtc_alarm_irq_enablefunction tps65910_rtc_read_timefunction tps65910_rtc_set_timefunction tps65910_rtc_read_alarmfunction tps65910_rtc_set_alarmfunction tps65910_rtc_set_calibrationfunction tps65910_rtc_get_calibrationfunction tps65910_read_offsetfunction tps65910_set_offsetfunction tps65910_rtc_interruptfunction tps65910_rtc_probefunction tps65910_rtc_suspendfunction tps65910_rtc_resume
Annotated Snippet
struct tps65910_rtc {
struct rtc_device *rtc;
int irq;
};
/* Total number of RTC registers needed to set time*/
#define NUM_TIME_REGS (TPS65910_YEARS - TPS65910_SECONDS + 1)
/* Total number of RTC registers needed to set compensation registers */
#define NUM_COMP_REGS (TPS65910_RTC_COMP_MSB - TPS65910_RTC_COMP_LSB + 1)
/* Min and max values supported with 'offset' interface (swapped sign) */
#define MIN_OFFSET (-277761)
#define MAX_OFFSET (277778)
/* Number of ticks per hour */
#define TICKS_PER_HOUR (32768 * 3600)
/* Multiplier for ppb conversions */
#define PPB_MULT (1000000000LL)
static int tps65910_rtc_alarm_irq_enable(struct device *dev,
unsigned int enabled)
{
struct tps65910 *tps = dev_get_drvdata(dev->parent);
u8 val = 0;
if (enabled)
val = TPS65910_RTC_INTERRUPTS_IT_ALARM;
return regmap_write(tps->regmap, TPS65910_RTC_INTERRUPTS, val);
}
/*
* Gets current tps65910 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 tps65910_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
unsigned char rtc_data[NUM_TIME_REGS];
struct tps65910 *tps = dev_get_drvdata(dev->parent);
int ret;
/* Copy RTC counting registers to static registers or latches */
ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
TPS65910_RTC_CTRL_GET_TIME, TPS65910_RTC_CTRL_GET_TIME);
if (ret < 0) {
dev_err(dev, "RTC CTRL reg update failed with err:%d\n", ret);
return ret;
}
ret = regmap_bulk_read(tps->regmap, TPS65910_SECONDS, rtc_data,
NUM_TIME_REGS);
if (ret < 0) {
dev_err(dev, "reading from RTC 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_mday = bcd2bin(rtc_data[3]);
tm->tm_mon = bcd2bin(rtc_data[4]) - 1;
tm->tm_year = bcd2bin(rtc_data[5]) + 100;
return ret;
}
static int tps65910_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
unsigned char rtc_data[NUM_TIME_REGS];
struct tps65910 *tps = dev_get_drvdata(dev->parent);
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_mday);
rtc_data[4] = bin2bcd(tm->tm_mon + 1);
rtc_data[5] = bin2bcd(tm->tm_year - 100);
/* Stop RTC while updating the RTC time registers */
ret = regmap_update_bits(tps->regmap, TPS65910_RTC_CTRL,
TPS65910_RTC_CTRL_STOP_RTC, 0);
if (ret < 0) {
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/math64.h`.
- Detected declarations: `struct tps65910_rtc`, `function tps65910_rtc_alarm_irq_enable`, `function tps65910_rtc_read_time`, `function tps65910_rtc_set_time`, `function tps65910_rtc_read_alarm`, `function tps65910_rtc_set_alarm`, `function tps65910_rtc_set_calibration`, `function tps65910_rtc_get_calibration`, `function tps65910_read_offset`, `function tps65910_set_offset`.
- 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.