drivers/watchdog/airoha_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/airoha_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/airoha_wdt.c- Extension
.c- Size
- 5773 bytes
- Lines
- 217
- 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/kernel.hlinux/module.hlinux/moduleparam.hlinux/types.hlinux/bitfield.hlinux/clk.hlinux/io.hlinux/math.hlinux/of.hlinux/platform_device.hlinux/watchdog.h
Detected Declarations
struct airoha_wdt_descfunction airoha_wdt_startfunction airoha_wdt_stopfunction airoha_wdt_pingfunction airoha_wdt_set_timeoutfunction airoha_wdt_get_timeleftfunction airoha_wdt_probefunction airoha_wdt_suspendfunction airoha_wdt_resume
Annotated Snippet
struct airoha_wdt_desc {
struct watchdog_device wdog_dev;
unsigned int wdt_freq;
void __iomem *base;
};
#define WDT_HEARTBEAT 24
static int heartbeat = WDT_HEARTBEAT;
module_param(heartbeat, int, 0);
MODULE_PARM_DESC(heartbeat, "Watchdog heartbeats in seconds. (default="
__MODULE_STRING(WDT_HEARTBEAT) ")");
static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
static int airoha_wdt_start(struct watchdog_device *wdog_dev)
{
struct airoha_wdt_desc *airoha_wdt = watchdog_get_drvdata(wdog_dev);
u32 val;
val = readl(airoha_wdt->base + TIMER_CTRL);
val |= (WDT_TIMER_ENABLE | WDT_ENABLE | WDT_TIMER_INTERRUPT);
writel(val, airoha_wdt->base + TIMER_CTRL);
val = wdog_dev->timeout * airoha_wdt->wdt_freq;
writel(val, airoha_wdt->base + WDT_TIMER_LOAD_VALUE);
return 0;
}
static int airoha_wdt_stop(struct watchdog_device *wdog_dev)
{
struct airoha_wdt_desc *airoha_wdt = watchdog_get_drvdata(wdog_dev);
u32 val;
val = readl(airoha_wdt->base + TIMER_CTRL);
val &= (~WDT_ENABLE & ~WDT_TIMER_ENABLE);
writel(val, airoha_wdt->base + TIMER_CTRL);
return 0;
}
static int airoha_wdt_ping(struct watchdog_device *wdog_dev)
{
struct airoha_wdt_desc *airoha_wdt = watchdog_get_drvdata(wdog_dev);
u32 val;
val = readl(airoha_wdt->base + WDT_RELOAD);
val |= WDT_RLD;
writel(val, airoha_wdt->base + WDT_RELOAD);
return 0;
}
static int airoha_wdt_set_timeout(struct watchdog_device *wdog_dev, unsigned int timeout)
{
wdog_dev->timeout = timeout;
if (watchdog_active(wdog_dev)) {
airoha_wdt_stop(wdog_dev);
return airoha_wdt_start(wdog_dev);
}
return 0;
}
static unsigned int airoha_wdt_get_timeleft(struct watchdog_device *wdog_dev)
{
struct airoha_wdt_desc *airoha_wdt = watchdog_get_drvdata(wdog_dev);
u32 val;
val = readl(airoha_wdt->base + WDT_TIMER_CUR_VALUE);
return DIV_ROUND_UP(val, airoha_wdt->wdt_freq);
}
static const struct watchdog_info airoha_wdt_info = {
.options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
.identity = "Airoha Watchdog",
};
static const struct watchdog_ops airoha_wdt_ops = {
.owner = THIS_MODULE,
.start = airoha_wdt_start,
.stop = airoha_wdt_stop,
.ping = airoha_wdt_ping,
.set_timeout = airoha_wdt_set_timeout,
.get_timeleft = airoha_wdt_get_timeleft,
};
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/bitfield.h`, `linux/clk.h`, `linux/io.h`, `linux/math.h`.
- Detected declarations: `struct airoha_wdt_desc`, `function airoha_wdt_start`, `function airoha_wdt_stop`, `function airoha_wdt_ping`, `function airoha_wdt_set_timeout`, `function airoha_wdt_get_timeleft`, `function airoha_wdt_probe`, `function airoha_wdt_suspend`, `function airoha_wdt_resume`.
- 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.