drivers/watchdog/smsc37b787_wdt.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/smsc37b787_wdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/smsc37b787_wdt.c- Extension
.c- Size
- 15273 bytes
- Lines
- 615
- 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/miscdevice.hlinux/watchdog.hlinux/delay.hlinux/fs.hlinux/ioport.hlinux/notifier.hlinux/reboot.hlinux/init.hlinux/spinlock.hlinux/io.hlinux/uaccess.h
Detected Declarations
function open_io_configfunction close_io_configfunction select_io_devicefunction write_io_crfunction read_io_crfunction gpio_bit12function gpio_bit13function wdt_timer_unitsfunction wdt_timeout_valuefunction wdt_timer_conffunction wdt_timer_ctrlfunction wb_smsc_wdt_initializefunction wb_smsc_wdt_shutdownfunction wb_smsc_wdt_set_timeoutfunction wb_smsc_wdt_get_timeoutfunction wb_smsc_wdt_disablefunction wb_smsc_wdt_enablefunction wb_smsc_wdt_reset_timerfunction wb_smsc_wdt_statusfunction wb_smsc_wdt_openfunction wb_smsc_wdt_releasefunction wb_smsc_wdt_writefunction wb_smsc_wdt_ioctlfunction wb_smsc_wdt_notify_sysfunction wb_smsc_wdt_initfunction wb_smsc_wdt_exitmodule init wb_smsc_wdt_init
Annotated Snippet
static const struct file_operations wb_smsc_wdt_fops = {
.owner = THIS_MODULE,
.write = wb_smsc_wdt_write,
.unlocked_ioctl = wb_smsc_wdt_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = wb_smsc_wdt_open,
.release = wb_smsc_wdt_release,
};
static struct notifier_block wb_smsc_wdt_notifier = {
.notifier_call = wb_smsc_wdt_notify_sys,
};
static struct miscdevice wb_smsc_wdt_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &wb_smsc_wdt_fops,
};
/* -- Module init functions -------------------------------------*/
/* module's "constructor" */
static int __init wb_smsc_wdt_init(void)
{
int ret;
pr_info("SMsC 37B787 watchdog component driver "
VERSION " initialising...\n");
if (!request_region(IOPORT, IOPORT_SIZE, "SMsC 37B787 watchdog")) {
pr_err("Unable to register IO port %#x\n", IOPORT);
ret = -EBUSY;
goto out_pnp;
}
/* set new maximum, if it's too big */
if (timeout > MAX_TIMEOUT)
timeout = MAX_TIMEOUT;
/* init the watchdog timer */
wb_smsc_wdt_initialize();
ret = register_reboot_notifier(&wb_smsc_wdt_notifier);
if (ret) {
pr_err("Unable to register reboot notifier err = %d\n", ret);
goto out_io;
}
ret = misc_register(&wb_smsc_wdt_miscdev);
if (ret) {
pr_err("Unable to register miscdev on minor %d\n",
WATCHDOG_MINOR);
goto out_rbt;
}
/* output info */
pr_info("Timeout set to %d %s\n",
timeout, (unit == UNIT_SECOND) ? "second(s)" : "minute(s)");
pr_info("Watchdog initialized and sleeping (nowayout=%d)...\n",
nowayout);
out_clean:
return ret;
out_rbt:
unregister_reboot_notifier(&wb_smsc_wdt_notifier);
out_io:
release_region(IOPORT, IOPORT_SIZE);
out_pnp:
goto out_clean;
}
/* module's "destructor" */
static void __exit wb_smsc_wdt_exit(void)
{
/* Stop the timer before we leave */
if (!nowayout) {
wb_smsc_wdt_shutdown();
pr_info("Watchdog disabled\n");
}
misc_deregister(&wb_smsc_wdt_miscdev);
unregister_reboot_notifier(&wb_smsc_wdt_notifier);
release_region(IOPORT, IOPORT_SIZE);
pr_info("SMsC 37B787 watchdog component driver removed\n");
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/miscdevice.h`, `linux/watchdog.h`, `linux/delay.h`, `linux/fs.h`, `linux/ioport.h`.
- Detected declarations: `function open_io_config`, `function close_io_config`, `function select_io_device`, `function write_io_cr`, `function read_io_cr`, `function gpio_bit12`, `function gpio_bit13`, `function wdt_timer_units`, `function wdt_timeout_value`, `function wdt_timer_conf`.
- 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.