drivers/watchdog/mtx-1_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/mtx-1_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/mtx-1_wdt.c- Extension
.c- Size
- 5891 bytes
- Lines
- 246
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/moduleparam.hlinux/types.hlinux/errno.hlinux/miscdevice.hlinux/fs.hlinux/ioport.hlinux/timer.hlinux/completion.hlinux/jiffies.hlinux/watchdog.hlinux/platform_device.hlinux/io.hlinux/uaccess.hlinux/gpio/consumer.h
Detected Declarations
function mtx1_wdt_triggerfunction mtx1_wdt_resetfunction mtx1_wdt_startfunction mtx1_wdt_stopfunction mtx1_wdt_openfunction mtx1_wdt_releasefunction mtx1_wdt_ioctlfunction mtx1_wdt_writefunction mtx1_wdt_probefunction mtx1_wdt_remove
Annotated Snippet
static const struct file_operations mtx1_wdt_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = mtx1_wdt_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = mtx1_wdt_open,
.write = mtx1_wdt_write,
.release = mtx1_wdt_release,
};
static struct miscdevice mtx1_wdt_misc = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &mtx1_wdt_fops,
};
static int mtx1_wdt_probe(struct platform_device *pdev)
{
int ret;
mtx1_wdt_device.gpiod = devm_gpiod_get(&pdev->dev,
NULL, GPIOD_OUT_HIGH);
if (IS_ERR(mtx1_wdt_device.gpiod)) {
dev_err(&pdev->dev, "failed to request gpio");
return PTR_ERR(mtx1_wdt_device.gpiod);
}
spin_lock_init(&mtx1_wdt_device.lock);
init_completion(&mtx1_wdt_device.stop);
mtx1_wdt_device.queue = 0;
clear_bit(0, &mtx1_wdt_device.inuse);
timer_setup(&mtx1_wdt_device.timer, mtx1_wdt_trigger, 0);
mtx1_wdt_device.default_ticks = ticks;
ret = misc_register(&mtx1_wdt_misc);
if (ret < 0) {
dev_err(&pdev->dev, "failed to register\n");
return ret;
}
mtx1_wdt_start();
dev_info(&pdev->dev, "MTX-1 Watchdog driver\n");
return 0;
}
static void mtx1_wdt_remove(struct platform_device *pdev)
{
/* FIXME: do we need to lock this test ? */
if (mtx1_wdt_device.queue) {
mtx1_wdt_device.queue = 0;
wait_for_completion(&mtx1_wdt_device.stop);
}
misc_deregister(&mtx1_wdt_misc);
}
static struct platform_driver mtx1_wdt_driver = {
.probe = mtx1_wdt_probe,
.remove = mtx1_wdt_remove,
.driver.name = "mtx1-wdt",
};
module_platform_driver(mtx1_wdt_driver);
MODULE_AUTHOR("Michael Stickel, Florian Fainelli");
MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:mtx1-wdt");
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/errno.h`, `linux/miscdevice.h`, `linux/fs.h`, `linux/ioport.h`, `linux/timer.h`.
- Detected declarations: `function mtx1_wdt_trigger`, `function mtx1_wdt_reset`, `function mtx1_wdt_start`, `function mtx1_wdt_stop`, `function mtx1_wdt_open`, `function mtx1_wdt_release`, `function mtx1_wdt_ioctl`, `function mtx1_wdt_write`, `function mtx1_wdt_probe`, `function mtx1_wdt_remove`.
- 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.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.