drivers/char/scx200_gpio.c
Source file repositories/reference/linux-study-clean/drivers/char/scx200_gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/scx200_gpio.c- Extension
.c- Size
- 3148 bytes
- Lines
- 133
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/fs.hlinux/module.hlinux/errno.hlinux/kernel.hlinux/init.hlinux/platform_device.hlinux/uaccess.hasm/io.hlinux/types.hlinux/cdev.hlinux/scx200_gpio.hlinux/nsc_gpio.h
Detected Declarations
function scx200_gpio_openfunction scx200_gpio_releasefunction scx200_gpio_initfunction scx200_gpio_cleanupmodule init scx200_gpio_initexport scx200_gpio_ops
Annotated Snippet
static const struct file_operations scx200_gpio_fileops = {
.owner = THIS_MODULE,
.write = nsc_gpio_write,
.read = nsc_gpio_read,
.open = scx200_gpio_open,
.release = scx200_gpio_release,
};
static struct cdev scx200_gpio_cdev; /* use 1 cdev for all pins */
static int __init scx200_gpio_init(void)
{
int rc;
dev_t devid;
if (!scx200_gpio_present()) {
printk(KERN_ERR DRVNAME ": no SCx200 gpio present\n");
return -ENODEV;
}
/* support dev_dbg() with pdev->dev */
pdev = platform_device_alloc(DRVNAME, 0);
if (!pdev)
return -ENOMEM;
rc = platform_device_add(pdev);
if (rc)
goto undo_malloc;
/* nsc_gpio uses dev_dbg(), so needs this */
scx200_gpio_ops.dev = &pdev->dev;
if (major) {
devid = MKDEV(major, 0);
rc = register_chrdev_region(devid, MAX_PINS, "scx200_gpio");
} else {
rc = alloc_chrdev_region(&devid, 0, MAX_PINS, "scx200_gpio");
major = MAJOR(devid);
}
if (rc < 0) {
dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
goto undo_platform_device_add;
}
cdev_init(&scx200_gpio_cdev, &scx200_gpio_fileops);
cdev_add(&scx200_gpio_cdev, devid, MAX_PINS);
return 0; /* succeed */
undo_platform_device_add:
platform_device_del(pdev);
undo_malloc:
platform_device_put(pdev);
return rc;
}
static void __exit scx200_gpio_cleanup(void)
{
cdev_del(&scx200_gpio_cdev);
/* cdev_put(&scx200_gpio_cdev); */
unregister_chrdev_region(MKDEV(major, 0), MAX_PINS);
platform_device_unregister(pdev);
}
module_init(scx200_gpio_init);
module_exit(scx200_gpio_cleanup);
Annotation
- Immediate include surface: `linux/device.h`, `linux/fs.h`, `linux/module.h`, `linux/errno.h`, `linux/kernel.h`, `linux/init.h`, `linux/platform_device.h`, `linux/uaccess.h`.
- Detected declarations: `function scx200_gpio_open`, `function scx200_gpio_release`, `function scx200_gpio_init`, `function scx200_gpio_cleanup`, `module init scx200_gpio_init`, `export scx200_gpio_ops`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern implementation candidate.
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.