drivers/watchdog/dw_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/dw_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/dw_wdt.c- Extension
.c- Size
- 19274 bytes
- Lines
- 702
- 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.
- 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/bitops.hlinux/clk.hlinux/debugfs.hlinux/delay.hlinux/err.hlinux/interrupt.hlinux/io.hlinux/kernel.hlinux/limits.hlinux/module.hlinux/moduleparam.hlinux/of.hlinux/platform_device.hlinux/pm.hlinux/reset.hlinux/watchdog.h
Detected Declarations
struct dw_wdt_timeoutstruct dw_wdtenum dw_wdt_rmodfunction dw_wdt_is_enabledfunction dw_wdt_update_modefunction dw_wdt_find_best_topfunction dw_wdt_get_min_timeoutfunction dw_wdt_get_max_timeout_msfunction dw_wdt_get_timeoutfunction dw_wdt_pingfunction dw_wdt_set_timeoutfunction dw_wdt_set_pretimeoutfunction dw_wdt_arm_system_resetfunction dw_wdt_startfunction dw_wdt_stopfunction dw_wdt_restartfunction dw_wdt_get_timeleftfunction dw_wdt_irqfunction dw_wdt_suspendfunction dw_wdt_resumefunction dw_wdt_handle_topsfunction dw_wdt_init_timeoutsfunction dw_wdt_dbgfs_initfunction dw_wdt_dbgfs_clearfunction dw_wdt_dbgfs_initfunction dw_wdt_drv_remove
Annotated Snippet
struct dw_wdt_timeout {
u32 top_val;
unsigned int sec;
unsigned int msec;
};
struct dw_wdt {
void __iomem *regs;
struct clk *clk;
struct clk *pclk;
unsigned long rate;
enum dw_wdt_rmod rmod;
struct dw_wdt_timeout timeouts[DW_WDT_NUM_TOPS];
struct watchdog_device wdd;
struct reset_control *rst;
/* Save/restore */
u32 control;
u32 timeout;
#ifdef CONFIG_DEBUG_FS
struct dentry *dbgfs_dir;
#endif
};
#define to_dw_wdt(wdd) container_of(wdd, struct dw_wdt, wdd)
static inline int dw_wdt_is_enabled(struct dw_wdt *dw_wdt)
{
return readl(dw_wdt->regs + WDOG_CONTROL_REG_OFFSET) &
WDOG_CONTROL_REG_WDT_EN_MASK;
}
static void dw_wdt_update_mode(struct dw_wdt *dw_wdt, enum dw_wdt_rmod rmod)
{
u32 val;
val = readl(dw_wdt->regs + WDOG_CONTROL_REG_OFFSET);
if (rmod == DW_WDT_RMOD_IRQ)
val |= WDOG_CONTROL_REG_RESP_MODE_MASK;
else
val &= ~WDOG_CONTROL_REG_RESP_MODE_MASK;
writel(val, dw_wdt->regs + WDOG_CONTROL_REG_OFFSET);
dw_wdt->rmod = rmod;
}
static unsigned int dw_wdt_find_best_top(struct dw_wdt *dw_wdt,
unsigned int timeout, u32 *top_val)
{
int idx;
/*
* Find a TOP with timeout greater or equal to the requested number.
* Note we'll select a TOP with maximum timeout if the requested
* timeout couldn't be reached.
*/
for (idx = 0; idx < DW_WDT_NUM_TOPS; ++idx) {
if (dw_wdt->timeouts[idx].sec >= timeout)
break;
}
if (idx == DW_WDT_NUM_TOPS)
--idx;
*top_val = dw_wdt->timeouts[idx].top_val;
return dw_wdt->timeouts[idx].sec;
}
static unsigned int dw_wdt_get_min_timeout(struct dw_wdt *dw_wdt)
{
int idx;
/*
* We'll find a timeout greater or equal to one second anyway because
* the driver probe would have failed if there was none.
*/
for (idx = 0; idx < DW_WDT_NUM_TOPS; ++idx) {
if (dw_wdt->timeouts[idx].sec)
break;
}
return dw_wdt->timeouts[idx].sec;
}
static unsigned int dw_wdt_get_max_timeout_ms(struct dw_wdt *dw_wdt)
{
struct dw_wdt_timeout *timeout = &dw_wdt->timeouts[DW_WDT_NUM_TOPS - 1];
u64 msec;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/clk.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/err.h`, `linux/interrupt.h`, `linux/io.h`, `linux/kernel.h`.
- Detected declarations: `struct dw_wdt_timeout`, `struct dw_wdt`, `enum dw_wdt_rmod`, `function dw_wdt_is_enabled`, `function dw_wdt_update_mode`, `function dw_wdt_find_best_top`, `function dw_wdt_get_min_timeout`, `function dw_wdt_get_max_timeout_ms`, `function dw_wdt_get_timeout`, `function dw_wdt_ping`.
- Atlas domain: Driver Families / drivers/watchdog.
- 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.