drivers/watchdog/acquirewdt.c

Source file repositories/reference/linux-study-clean/drivers/watchdog/acquirewdt.c

File Facts

System
Linux kernel
Corpus path
drivers/watchdog/acquirewdt.c
Extension
.c
Size
8470 bytes
Lines
329
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations acq_fops = {
	.owner		= THIS_MODULE,
	.write		= acq_write,
	.unlocked_ioctl	= acq_ioctl,
	.compat_ioctl	= compat_ptr_ioctl,
	.open		= acq_open,
	.release	= acq_close,
};

static struct miscdevice acq_miscdev = {
	.minor	= WATCHDOG_MINOR,
	.name	= "watchdog",
	.fops	= &acq_fops,
};

/*
 *	Init & exit routines
 */

static int __init acq_probe(struct platform_device *dev)
{
	int ret;

	if (wdt_stop != wdt_start) {
		if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
			pr_err("I/O address 0x%04x already in use\n", wdt_stop);
			ret = -EIO;
			goto out;
		}
	}

	if (!request_region(wdt_start, 1, WATCHDOG_NAME)) {
		pr_err("I/O address 0x%04x already in use\n", wdt_start);
		ret = -EIO;
		goto unreg_stop;
	}
	ret = misc_register(&acq_miscdev);
	if (ret != 0) {
		pr_err("cannot register miscdev on minor=%d (err=%d)\n",
		       WATCHDOG_MINOR, ret);
		goto unreg_regions;
	}
	pr_info("initialized. (nowayout=%d)\n", nowayout);

	return 0;
unreg_regions:
	release_region(wdt_start, 1);
unreg_stop:
	if (wdt_stop != wdt_start)
		release_region(wdt_stop, 1);
out:
	return ret;
}

static void acq_remove(struct platform_device *dev)
{
	misc_deregister(&acq_miscdev);
	release_region(wdt_start, 1);
	if (wdt_stop != wdt_start)
		release_region(wdt_stop, 1);
}

static void acq_shutdown(struct platform_device *dev)
{
	/* Turn the WDT off if we have a soft shutdown */
	acq_stop();
}

static struct platform_driver acquirewdt_driver = {
	.remove		= acq_remove,
	.shutdown	= acq_shutdown,
	.driver		= {
		.name	= DRV_NAME,
	},
};

static int __init acq_init(void)
{
	int err;

	pr_info("WDT driver for Acquire single board computer initialising\n");

	acq_platform_device = platform_device_register_simple(DRV_NAME,
								-1, NULL, 0);
	if (IS_ERR(acq_platform_device))
		return PTR_ERR(acq_platform_device);

	err = platform_driver_probe(&acquirewdt_driver, acq_probe);
	if (err)
		goto unreg_platform_device;

Annotation

Implementation Notes