drivers/char/nwbutton.c

Source file repositories/reference/linux-study-clean/drivers/char/nwbutton.c

File Facts

System
Linux kernel
Corpus path
drivers/char/nwbutton.c
Extension
.c
Size
8157 bytes
Lines
249
Domain
Driver Families
Bucket
drivers/char
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 button_fops = {
	.owner		= THIS_MODULE,
	.read		= button_read,
	.llseek		= noop_llseek,
};

/* 
 * This structure is the misc device structure, which specifies the minor
 * device number (158 in this case), the name of the device (for /proc/misc),
 * and the address of the above file operations structure.
 */

static struct miscdevice button_misc_device = {
	BUTTON_MINOR,
	"nwbutton",
	&button_fops,
};

/*
 * This function is called to initialise the driver, either from misc.c at
 * bootup if the driver is compiled into the kernel, or from init_module
 * below at module insert time. It attempts to register the device node
 * and the IRQ and fails with a warning message if either fails, though
 * neither ever should because the device number and IRQ are unique to
 * this driver.
 */

static int __init nwbutton_init(void)
{
	if (!machine_is_netwinder())
		return -ENODEV;

	printk (KERN_INFO "NetWinder Button Driver Version %s (C) Alex Holden "
			"<alex@linuxhacker.org> 1998.\n", VERSION);

	if (misc_register (&button_misc_device)) {
		printk (KERN_WARNING "nwbutton: Couldn't register device 10, "
				"%d.\n", BUTTON_MINOR);
		return -EBUSY;
	}

	if (request_irq (IRQ_NETWINDER_BUTTON, button_handler, 0,
			"nwbutton", NULL)) {
		printk (KERN_WARNING "nwbutton: IRQ %d is not free.\n",
				IRQ_NETWINDER_BUTTON);
		misc_deregister (&button_misc_device);
		return -EIO;
	}
	return 0;
}

static void __exit nwbutton_exit (void) 
{
	free_irq (IRQ_NETWINDER_BUTTON, NULL);
	misc_deregister (&button_misc_device);
}


MODULE_AUTHOR("Alex Holden");
MODULE_DESCRIPTION("NetWinder button driver");
MODULE_LICENSE("GPL");

module_init(nwbutton_init);
module_exit(nwbutton_exit);

Annotation

Implementation Notes