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.
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/sched/signal.hlinux/interrupt.hlinux/time.hlinux/timer.hlinux/fs.hlinux/miscdevice.hlinux/string.hlinux/errno.hlinux/init.hlinux/uaccess.hasm/irq.hasm/mach-types.hnwbutton.h
Detected Declarations
function button_add_callbackfunction firstfunction pointerfunction upfunction pressedfunction button_readfunction nwbutton_initfunction nwbutton_exitmodule init nwbutton_init
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
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/sched/signal.h`, `linux/interrupt.h`, `linux/time.h`, `linux/timer.h`, `linux/fs.h`, `linux/miscdevice.h`.
- Detected declarations: `function button_add_callback`, `function first`, `function pointer`, `function up`, `function pressed`, `function button_read`, `function nwbutton_init`, `function nwbutton_exit`, `module init nwbutton_init`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.