drivers/rtc/rtc-tps6586x.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-tps6586x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-tps6586x.c- Extension
.c- Size
- 7924 bytes
- Lines
- 328
- 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/device.hlinux/err.hlinux/init.hlinux/irq.hlinux/kernel.hlinux/mfd/tps6586x.hlinux/module.hlinux/platform_device.hlinux/pm_runtime.hlinux/rtc.hlinux/slab.h
Detected Declarations
struct tps6586x_rtcfunction tps6586x_rtc_read_timefunction tps6586x_rtc_set_timefunction tps6586x_rtc_alarm_irq_enablefunction tps6586x_rtc_set_alarmfunction tps6586x_rtc_read_alarmfunction tps6586x_rtc_irqfunction tps6586x_rtc_probefunction tps6586x_rtc_removefunction tps6586x_rtc_suspendfunction tps6586x_rtc_resume
Annotated Snippet
struct tps6586x_rtc {
struct device *dev;
struct rtc_device *rtc;
int irq;
bool irq_en;
};
static inline struct device *to_tps6586x_dev(struct device *dev)
{
return dev->parent;
}
static int tps6586x_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct device *tps_dev = to_tps6586x_dev(dev);
unsigned long long ticks = 0;
time64_t seconds;
u8 buff[6];
int ret;
int i;
ret = tps6586x_reads(tps_dev, RTC_COUNT4_DUMMYREAD, sizeof(buff), buff);
if (ret < 0) {
dev_err(dev, "read counter failed with err %d\n", ret);
return ret;
}
for (i = 1; i < sizeof(buff); i++) {
ticks <<= 8;
ticks |= buff[i];
}
seconds = ticks >> 10;
rtc_time64_to_tm(seconds, tm);
return 0;
}
static int tps6586x_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct device *tps_dev = to_tps6586x_dev(dev);
unsigned long long ticks;
time64_t seconds;
u8 buff[5];
int ret;
seconds = rtc_tm_to_time64(tm);
ticks = (unsigned long long)seconds << 10;
buff[0] = (ticks >> 32) & 0xff;
buff[1] = (ticks >> 24) & 0xff;
buff[2] = (ticks >> 16) & 0xff;
buff[3] = (ticks >> 8) & 0xff;
buff[4] = ticks & 0xff;
/* Disable RTC before changing time */
ret = tps6586x_clr_bits(tps_dev, RTC_CTRL, RTC_ENABLE);
if (ret < 0) {
dev_err(dev, "failed to clear RTC_ENABLE\n");
return ret;
}
ret = tps6586x_writes(tps_dev, RTC_COUNT4, sizeof(buff), buff);
if (ret < 0) {
dev_err(dev, "failed to program new time\n");
return ret;
}
/* Enable RTC */
ret = tps6586x_set_bits(tps_dev, RTC_CTRL, RTC_ENABLE);
if (ret < 0) {
dev_err(dev, "failed to set RTC_ENABLE\n");
return ret;
}
return 0;
}
static int tps6586x_rtc_alarm_irq_enable(struct device *dev,
unsigned int enabled)
{
struct tps6586x_rtc *rtc = dev_get_drvdata(dev);
if (enabled && !rtc->irq_en) {
enable_irq(rtc->irq);
rtc->irq_en = true;
} else if (!enabled && rtc->irq_en) {
disable_irq(rtc->irq);
rtc->irq_en = false;
}
return 0;
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/init.h`, `linux/irq.h`, `linux/kernel.h`, `linux/mfd/tps6586x.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct tps6586x_rtc`, `function tps6586x_rtc_read_time`, `function tps6586x_rtc_set_time`, `function tps6586x_rtc_alarm_irq_enable`, `function tps6586x_rtc_set_alarm`, `function tps6586x_rtc_read_alarm`, `function tps6586x_rtc_irq`, `function tps6586x_rtc_probe`, `function tps6586x_rtc_remove`, `function tps6586x_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.