drivers/watchdog/rti_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/rti_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/rti_wdt.c- Extension
.c- Size
- 10365 bytes
- Lines
- 423
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- 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.
- 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/device.hlinux/err.hlinux/io.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/moduleparam.hlinux/of.hlinux/of_reserved_mem.hlinux/platform_device.hlinux/pm_runtime.hlinux/types.hlinux/watchdog.h
Detected Declarations
struct rti_wdt_datastruct rti_wdt_devicefunction rti_wdt_startfunction rti_wdt_pingfunction rti_wdt_setup_hw_hbfunction rti_wdt_get_timeleft_msfunction rti_wdt_get_timeleftfunction rti_wdt_probefunction rti_wdt_remove
Annotated Snippet
struct rti_wdt_data {
bool nmi;
};
/*
* struct to hold data for each WDT device
* @base - base io address of WD device
* @freq - source clock frequency of WDT
* @wdd - hold watchdog device as is in WDT core
* @nmi - Set if this WDT instance supports generating NMI
*/
struct rti_wdt_device {
void __iomem *base;
unsigned long freq;
struct watchdog_device wdd;
bool nmi;
};
static int rti_wdt_start(struct watchdog_device *wdd)
{
u32 timer_margin;
struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
u8 reaction;
int ret;
ret = pm_runtime_resume_and_get(wdd->parent);
if (ret)
return ret;
/* set timeout period */
timer_margin = (u64)wdd->timeout * wdt->freq;
timer_margin >>= WDT_PRELOAD_SHIFT;
if (timer_margin > WDT_PRELOAD_MAX)
timer_margin = WDT_PRELOAD_MAX;
writel_relaxed(timer_margin, wdt->base + RTIDWDPRLD);
/*
* RTI only supports a windowed mode, where the watchdog can only
* be petted during the open window; not too early or not too late.
* The HW configuration options only allow for the open window size
* to be 50% or less than that; we obviouly want to configure the open
* window as large as possible so we select the 50% option.
*/
wdd->min_hw_heartbeat_ms = 520 * wdd->timeout + MAX_HW_ERROR;
/* When WDT expires, generate NMI or reset if NMI not supported */
if (wdt->nmi)
reaction = RTIWWDRXN_NMI;
else
reaction = RTIWWDRXN_RST;
writel_relaxed(reaction, wdt->base + RTIWWDRXCTRL);
/* Open window size 50%; this is the largest window size available */
writel_relaxed(RTIWWDSIZE_50P, wdt->base + RTIWWDSIZECTRL);
readl_relaxed(wdt->base + RTIWWDSIZECTRL);
/* enable watchdog */
writel_relaxed(WDENABLE_KEY, wdt->base + RTIDWDCTRL);
return 0;
}
static int rti_wdt_ping(struct watchdog_device *wdd)
{
struct rti_wdt_device *wdt = watchdog_get_drvdata(wdd);
/* put watchdog in service state */
writel_relaxed(WDKEY_SEQ0, wdt->base + RTIWDKEY);
/* put watchdog in active state */
writel_relaxed(WDKEY_SEQ1, wdt->base + RTIWDKEY);
return 0;
}
static int rti_wdt_setup_hw_hb(struct watchdog_device *wdd, u32 wsize)
{
/*
* RTI only supports a windowed mode, where the watchdog can only
* be petted during the open window; not too early or not too late.
* The HW configuration options only allow for the open window size
* to be 50% or less than that.
* To avoid any glitches, we accommodate 2% + max hardware error
* safety margin.
*/
switch (wsize) {
case RTIWWDSIZE_50P:
/* 50% open window => 52% min heartbeat */
wdd->min_hw_heartbeat_ms = 520 * heartbeat + MAX_HW_ERROR;
break;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/device.h`, `linux/err.h`, `linux/io.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/moduleparam.h`.
- Detected declarations: `struct rti_wdt_data`, `struct rti_wdt_device`, `function rti_wdt_start`, `function rti_wdt_ping`, `function rti_wdt_setup_hw_hb`, `function rti_wdt_get_timeleft_ms`, `function rti_wdt_get_timeleft`, `function rti_wdt_probe`, `function rti_wdt_remove`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: source implementation candidate.
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.