drivers/watchdog/ath79_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/ath79_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/ath79_wdt.c- Extension
.c- Size
- 7168 bytes
- Lines
- 323
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/delay.hlinux/errno.hlinux/fs.hlinux/io.hlinux/kernel.hlinux/miscdevice.hlinux/module.hlinux/moduleparam.hlinux/platform_device.hlinux/types.hlinux/watchdog.hlinux/clk.hlinux/err.hlinux/of.hlinux/of_platform.hlinux/uaccess.h
Detected Declarations
function ath79_wdt_wrfunction ath79_wdt_rrfunction ath79_wdt_keepalivefunction ath79_wdt_enablefunction ath79_wdt_disablefunction ath79_wdt_set_timeoutfunction ath79_wdt_openfunction ath79_wdt_releasefunction ath79_wdt_writefunction ath79_wdt_ioctlfunction ath79_wdt_probefunction ath79_wdt_removefunction ath79_wdt_shutdown
Annotated Snippet
static const struct file_operations ath79_wdt_fops = {
.owner = THIS_MODULE,
.write = ath79_wdt_write,
.unlocked_ioctl = ath79_wdt_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = ath79_wdt_open,
.release = ath79_wdt_release,
};
static struct miscdevice ath79_wdt_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &ath79_wdt_fops,
};
static int ath79_wdt_probe(struct platform_device *pdev)
{
u32 ctrl;
int err;
if (wdt_base)
return -EBUSY;
wdt_base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(wdt_base))
return PTR_ERR(wdt_base);
wdt_clk = devm_clk_get_enabled(&pdev->dev, "wdt");
if (IS_ERR(wdt_clk))
return PTR_ERR(wdt_clk);
wdt_freq = clk_get_rate(wdt_clk);
if (!wdt_freq)
return -EINVAL;
max_timeout = (0xfffffffful / wdt_freq);
if (timeout < 1 || timeout > max_timeout) {
timeout = max_timeout;
dev_info(&pdev->dev,
"timeout value must be 0 < timeout < %d, using %d\n",
max_timeout, timeout);
}
ctrl = ath79_wdt_rr(WDOG_REG_CTRL);
boot_status = (ctrl & WDOG_CTRL_LAST_RESET) ? WDIOF_CARDRESET : 0;
err = misc_register(&ath79_wdt_miscdev);
if (err) {
dev_err(&pdev->dev,
"unable to register misc device, err=%d\n", err);
return err;
}
return 0;
}
static void ath79_wdt_remove(struct platform_device *pdev)
{
misc_deregister(&ath79_wdt_miscdev);
}
static void ath79_wdt_shutdown(struct platform_device *pdev)
{
ath79_wdt_disable();
}
#ifdef CONFIG_OF
static const struct of_device_id ath79_wdt_match[] = {
{ .compatible = "qca,ar7130-wdt" },
{},
};
MODULE_DEVICE_TABLE(of, ath79_wdt_match);
#endif
static struct platform_driver ath79_wdt_driver = {
.probe = ath79_wdt_probe,
.remove = ath79_wdt_remove,
.shutdown = ath79_wdt_shutdown,
.driver = {
.name = DRIVER_NAME,
.of_match_table = of_match_ptr(ath79_wdt_match),
},
};
module_platform_driver(ath79_wdt_driver);
MODULE_DESCRIPTION("Atheros AR71XX/AR724X/AR913X hardware watchdog driver");
MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org");
MODULE_AUTHOR("Imre Kaloz <kaloz@openwrt.org");
MODULE_LICENSE("GPL v2");
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/delay.h`, `linux/errno.h`, `linux/fs.h`, `linux/io.h`, `linux/kernel.h`, `linux/miscdevice.h`, `linux/module.h`.
- Detected declarations: `function ath79_wdt_wr`, `function ath79_wdt_rr`, `function ath79_wdt_keepalive`, `function ath79_wdt_enable`, `function ath79_wdt_disable`, `function ath79_wdt_set_timeout`, `function ath79_wdt_open`, `function ath79_wdt_release`, `function ath79_wdt_write`, `function ath79_wdt_ioctl`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.