drivers/rtc/rtc-tps6594.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-tps6594.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-tps6594.c- Extension
.c- Size
- 13074 bytes
- Lines
- 506
- 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/errno.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/limits.hlinux/math64.hlinux/module.hlinux/platform_device.hlinux/mod_devicetable.hlinux/property.hlinux/rtc.hlinux/types.hlinux/units.hlinux/mfd/tps6594.h
Detected Declarations
struct tps6594_rtcfunction tps6594_rtc_alarm_irq_enablefunction tps6594_rtc_shadow_timestampfunction tps6594_rtc_read_timefunction tps6594_rtc_set_timefunction tps6594_rtc_read_alarmfunction tps6594_rtc_set_alarmfunction tps6594_rtc_set_calibrationfunction tps6594_rtc_get_calibrationfunction tps6594_rtc_read_offsetfunction tps6594_rtc_set_offsetfunction tps6594_rtc_interruptfunction tps6594_rtc_probefunction tps6594_rtc_resumefunction tps6594_rtc_suspend
Annotated Snippet
struct tps6594_rtc {
struct rtc_device *rtc_dev;
int irq;
};
static int tps6594_rtc_alarm_irq_enable(struct device *dev,
unsigned int enabled)
{
struct tps6594 *tps = dev_get_drvdata(dev->parent);
u8 val;
val = enabled ? TPS6594_BIT_IT_ALARM : 0;
return regmap_update_bits(tps->regmap, TPS6594_REG_RTC_INTERRUPTS,
TPS6594_BIT_IT_ALARM, val);
}
/* Pulse GET_TIME field of RTC_CTRL_1 to store a timestamp in shadow registers. */
static int tps6594_rtc_shadow_timestamp(struct device *dev, struct tps6594 *tps)
{
int ret;
/*
* Set GET_TIME to 0. Next time we set GET_TIME to 1 we will be sure to store
* an up-to-date timestamp.
*/
ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
TPS6594_BIT_GET_TIME);
if (ret < 0)
return ret;
/*
* Copy content of RTC registers to shadow registers or latches to read
* a coherent timestamp.
*/
return regmap_set_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
TPS6594_BIT_GET_TIME);
}
static int tps6594_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
unsigned char rtc_data[NUM_TIME_REGS];
struct tps6594 *tps = dev_get_drvdata(dev->parent);
int ret;
// Check if RTC is running.
ret = regmap_test_bits(tps->regmap, TPS6594_REG_RTC_STATUS,
TPS6594_BIT_RUN);
if (ret < 0)
return ret;
if (ret == 0)
return -EINVAL;
ret = tps6594_rtc_shadow_timestamp(dev, tps);
if (ret < 0)
return ret;
// Read shadowed RTC registers.
ret = regmap_bulk_read(tps->regmap, TPS6594_REG_RTC_SECONDS, rtc_data,
NUM_TIME_REGS);
if (ret < 0)
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;
tm->tm_wday = bcd2bin(rtc_data[6]);
return 0;
}
static int tps6594_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
unsigned char rtc_data[NUM_TIME_REGS];
struct tps6594 *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);
rtc_data[6] = bin2bcd(tm->tm_wday);
// Stop RTC while updating the RTC time registers.
ret = regmap_clear_bits(tps->regmap, TPS6594_REG_RTC_CTRL_1,
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/errno.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/limits.h`, `linux/math64.h`, `linux/module.h`.
- Detected declarations: `struct tps6594_rtc`, `function tps6594_rtc_alarm_irq_enable`, `function tps6594_rtc_shadow_timestamp`, `function tps6594_rtc_read_time`, `function tps6594_rtc_set_time`, `function tps6594_rtc_read_alarm`, `function tps6594_rtc_set_alarm`, `function tps6594_rtc_set_calibration`, `function tps6594_rtc_get_calibration`, `function tps6594_rtc_read_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.