drivers/rtc/rtc-tegra.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-tegra.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-tegra.c- Extension
.c- Size
- 10769 bytes
- Lines
- 404
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/clk.hlinux/delay.hlinux/init.hlinux/io.hlinux/irq.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/pm.hlinux/rtc.hlinux/slab.h
Detected Declarations
struct tegra_rtc_infofunction clocksfunction updatefunction tegra_rtc_read_timefunction tegra_rtc_set_timefunction tegra_rtc_read_alarmfunction tegra_rtc_alarm_irq_enablefunction tegra_rtc_set_alarmfunction tegra_rtc_procfunction tegra_rtc_irq_handlerfunction tegra_rtc_probefunction tegra_rtc_suspendfunction tegra_rtc_resumefunction tegra_rtc_shutdown
Annotated Snippet
struct tegra_rtc_info {
struct platform_device *pdev;
struct rtc_device *rtc;
void __iomem *base; /* NULL if not initialized */
struct clk *clk;
int irq; /* alarm and periodic IRQ */
spinlock_t lock;
};
/*
* RTC hardware is busy when it is updating its values over AHB once every
* eight 32 kHz clocks (~250 us). Outside of these updates the CPU is free to
* write. CPU is always free to read.
*/
static inline u32 tegra_rtc_check_busy(struct tegra_rtc_info *info)
{
return readl(info->base + TEGRA_RTC_REG_BUSY) & 1;
}
/*
* Wait for hardware to be ready for writing. This function tries to maximize
* the amount of time before the next update. It does this by waiting for the
* RTC to become busy with its periodic update, then returning once the RTC
* first becomes not busy.
*
* This periodic update (where the seconds and milliseconds are copied to the
* AHB side) occurs every eight 32 kHz clocks (~250 us). The behavior of this
* function allows us to make some assumptions without introducing a race,
* because 250 us is plenty of time to read/write a value.
*/
static int tegra_rtc_wait_while_busy(struct device *dev)
{
struct tegra_rtc_info *info = dev_get_drvdata(dev);
int retries = 500; /* ~490 us is the worst case, ~250 us is best */
/*
* First wait for the RTC to become busy. This is when it posts its
* updated seconds+msec registers to AHB side.
*/
while (tegra_rtc_check_busy(info)) {
if (!retries--)
goto retry_failed;
udelay(1);
}
/* now we have about 250 us to manipulate registers */
return 0;
retry_failed:
dev_err(dev, "write failed: retry count exceeded\n");
return -ETIMEDOUT;
}
static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct tegra_rtc_info *info = dev_get_drvdata(dev);
unsigned long flags;
u32 sec;
/*
* RTC hardware copies seconds to shadow seconds when a read of
* milliseconds occurs. use a lock to keep other threads out.
*/
spin_lock_irqsave(&info->lock, flags);
readl(info->base + TEGRA_RTC_REG_MILLI_SECONDS);
sec = readl(info->base + TEGRA_RTC_REG_SHADOW_SECONDS);
spin_unlock_irqrestore(&info->lock, flags);
rtc_time64_to_tm(sec, tm);
dev_vdbg(dev, "time read as %u, %ptR\n", sec, tm);
return 0;
}
static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct tegra_rtc_info *info = dev_get_drvdata(dev);
u32 sec;
int ret;
/* convert tm to seconds */
sec = rtc_tm_to_time64(tm);
dev_vdbg(dev, "time set to %u, %ptR\n", sec, tm);
/* seconds only written if wait succeeded */
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/init.h`, `linux/io.h`, `linux/irq.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct tegra_rtc_info`, `function clocks`, `function update`, `function tegra_rtc_read_time`, `function tegra_rtc_set_time`, `function tegra_rtc_read_alarm`, `function tegra_rtc_alarm_irq_enable`, `function tegra_rtc_set_alarm`, `function tegra_rtc_proc`, `function tegra_rtc_irq_handler`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.