drivers/watchdog/sbc7240_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/sbc7240_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/sbc7240_wdt.c- Extension
.c- Size
- 6652 bytes
- Lines
- 302
- 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/fs.hlinux/init.hlinux/ioport.hlinux/jiffies.hlinux/module.hlinux/moduleparam.hlinux/miscdevice.hlinux/notifier.hlinux/reboot.hlinux/types.hlinux/watchdog.hlinux/io.hlinux/uaccess.hlinux/atomic.h
Detected Declarations
function wdt_disablefunction wdt_enablefunction wdt_set_timeoutfunction wdt_keepalivefunction fop_writefunction fop_openfunction fop_closefunction fop_ioctlfunction wdt_notify_sysfunction sbc7240_wdt_unloadfunction sbc7240_wdt_initmodule init sbc7240_wdt_init
Annotated Snippet
static const struct file_operations wdt_fops = {
.owner = THIS_MODULE,
.write = fop_write,
.open = fop_open,
.release = fop_close,
.unlocked_ioctl = fop_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static struct miscdevice wdt_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &wdt_fops,
};
/*
* Notifier for system down
*/
static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
void *unused)
{
if (code == SYS_DOWN || code == SYS_HALT)
wdt_disable();
return NOTIFY_DONE;
}
static struct notifier_block wdt_notifier = {
.notifier_call = wdt_notify_sys,
};
static void __exit sbc7240_wdt_unload(void)
{
pr_info("Removing watchdog\n");
misc_deregister(&wdt_miscdev);
unregister_reboot_notifier(&wdt_notifier);
release_region(SBC7240_ENABLE_PORT, 1);
}
static int __init sbc7240_wdt_init(void)
{
int rc = -EBUSY;
if (!request_region(SBC7240_ENABLE_PORT, 1, "SBC7240 WDT")) {
pr_err("I/O address 0x%04x already in use\n",
SBC7240_ENABLE_PORT);
rc = -EIO;
goto err_out;
}
/* The IO port 0x043 used to disable the watchdog
* is already claimed by the system timer, so we
* can't request_region() it ...*/
if (timeout < 1 || timeout > SBC7240_MAX_TIMEOUT) {
timeout = SBC7240_TIMEOUT;
pr_info("timeout value must be 1<=x<=%d, using %d\n",
SBC7240_MAX_TIMEOUT, timeout);
}
wdt_set_timeout(timeout);
wdt_disable();
rc = register_reboot_notifier(&wdt_notifier);
if (rc) {
pr_err("cannot register reboot notifier (err=%d)\n", rc);
goto err_out_region;
}
rc = misc_register(&wdt_miscdev);
if (rc) {
pr_err("cannot register miscdev on minor=%d (err=%d)\n",
wdt_miscdev.minor, rc);
goto err_out_reboot_notifier;
}
pr_info("Watchdog driver for SBC7240 initialised (nowayout=%d)\n",
nowayout);
return 0;
err_out_reboot_notifier:
unregister_reboot_notifier(&wdt_notifier);
err_out_region:
release_region(SBC7240_ENABLE_PORT, 1);
err_out:
return rc;
}
module_init(sbc7240_wdt_init);
Annotation
- Immediate include surface: `linux/fs.h`, `linux/init.h`, `linux/ioport.h`, `linux/jiffies.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/miscdevice.h`, `linux/notifier.h`.
- Detected declarations: `function wdt_disable`, `function wdt_enable`, `function wdt_set_timeout`, `function wdt_keepalive`, `function fop_write`, `function fop_open`, `function fop_close`, `function fop_ioctl`, `function wdt_notify_sys`, `function sbc7240_wdt_unload`.
- 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.