drivers/char/nsc_gpio.c
Source file repositories/reference/linux-study-clean/drivers/char/nsc_gpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/nsc_gpio.c- Extension
.c- Size
- 3353 bytes
- Lines
- 127
- Domain
- Driver Families
- Bucket
- drivers/char
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/module.hlinux/errno.hlinux/kernel.hlinux/init.hlinux/nsc_gpio.hlinux/platform_device.hlinux/uaccess.hasm/io.h
Detected Declarations
function Copyrightfunction nsc_gpio_writefunction nsc_gpio_readexport nsc_gpio_writeexport nsc_gpio_readexport nsc_gpio_dump
Annotated Snippet
switch (c) {
case '0':
amp->gpio_set(m, 0);
break;
case '1':
amp->gpio_set(m, 1);
break;
case 'O':
dev_dbg(dev, "GPIO%d output enabled\n", m);
amp->gpio_config(m, ~1, 1);
break;
case 'o':
dev_dbg(dev, "GPIO%d output disabled\n", m);
amp->gpio_config(m, ~1, 0);
break;
case 'T':
dev_dbg(dev, "GPIO%d output is push pull\n", m);
amp->gpio_config(m, ~2, 2);
break;
case 't':
dev_dbg(dev, "GPIO%d output is open drain\n", m);
amp->gpio_config(m, ~2, 0);
break;
case 'P':
dev_dbg(dev, "GPIO%d pull up enabled\n", m);
amp->gpio_config(m, ~4, 4);
break;
case 'p':
dev_dbg(dev, "GPIO%d pull up disabled\n", m);
amp->gpio_config(m, ~4, 0);
break;
case 'v':
/* View Current pin settings */
amp->gpio_dump(amp, m);
break;
case '\n':
/* end of settings string, do nothing */
break;
default:
dev_err(dev, "io%2d bad setting: chr<0x%2x>\n",
m, (int)c);
err++;
}
}
if (err)
return -EINVAL; /* full string handled, report error */
return len;
}
ssize_t nsc_gpio_read(struct file *file, char __user * buf,
size_t len, loff_t * ppos)
{
unsigned m = iminor(file_inode(file));
int value;
struct nsc_gpio_ops *amp = file->private_data;
value = amp->gpio_get(m);
if (put_user(value ? '1' : '0', buf))
return -EFAULT;
return 1;
}
/* common file-ops routines for both scx200_gpio and pc87360_gpio */
EXPORT_SYMBOL(nsc_gpio_write);
EXPORT_SYMBOL(nsc_gpio_read);
EXPORT_SYMBOL(nsc_gpio_dump);
MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
MODULE_DESCRIPTION("NatSemi GPIO Common Methods");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/fs.h`, `linux/module.h`, `linux/errno.h`, `linux/kernel.h`, `linux/init.h`, `linux/nsc_gpio.h`, `linux/platform_device.h`, `linux/uaccess.h`.
- Detected declarations: `function Copyright`, `function nsc_gpio_write`, `function nsc_gpio_read`, `export nsc_gpio_write`, `export nsc_gpio_read`, `export nsc_gpio_dump`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.