drivers/gpio/gpio-mockup.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-mockup.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-mockup.c- Extension
.c- Size
- 16262 bytes
- Lines
- 648
- Domain
- Driver Families
- Bucket
- drivers/gpio
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cleanup.hlinux/debugfs.hlinux/device.hlinux/gpio/driver.hlinux/interrupt.hlinux/irq.hlinux/irq_sim.hlinux/irqdomain.hlinux/limits.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/seq_file.hlinux/slab.hlinux/string_helpers.hlinux/uaccess.h
Detected Declarations
struct gpio_mockup_line_statusstruct gpio_mockup_chipstruct gpio_mockup_dbgfs_privatefunction gpio_mockup_range_basefunction gpio_mockup_range_ngpiofunction __gpio_mockup_getfunction gpio_mockup_getfunction gpio_mockup_get_multiplefunction scoped_guardfunction __gpio_mockup_setfunction gpio_mockup_setfunction gpio_mockup_set_multiplefunction gpio_mockup_apply_pullfunction gpio_mockup_set_configfunction gpio_mockup_diroutfunction scoped_guardfunction gpio_mockup_dirinfunction gpio_mockup_get_directionfunction gpio_mockup_to_irqfunction gpio_mockup_requestfunction gpio_mockup_freefunction gpio_mockup_debugfs_readfunction gpio_mockup_debugfs_writefunction gpio_mockup_debugfs_openfunction gpio_mockup_debugfs_setupfunction gpio_mockup_debugfs_cleanupfunction gpio_mockup_dispose_mappingsfunction gpio_mockup_probefunction gpio_mockup_unregister_pdevsfunction gpio_mockup_register_chipfunction gpio_mockup_initfunction gpio_mockup_exitmodule init gpio_mockup_init
Annotated Snippet
static const struct file_operations gpio_mockup_debugfs_ops = {
.owner = THIS_MODULE,
.open = gpio_mockup_debugfs_open,
.read = gpio_mockup_debugfs_read,
.write = gpio_mockup_debugfs_write,
.release = single_release,
};
static void gpio_mockup_debugfs_setup(struct device *dev,
struct gpio_mockup_chip *chip)
{
struct gpio_mockup_dbgfs_private *priv;
struct gpio_chip *gc;
const char *devname;
char *name;
int i;
gc = &chip->gc;
/*
* There can only be a single GPIO device per platform device in
* gpio-mockup so using device_find_any_child() is OK.
*/
struct device *child __free(put_device) = device_find_any_child(dev);
if (!child)
return;
devname = dev_name(child);
chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir);
for (i = 0; i < gc->ngpio; i++) {
name = devm_kasprintf(dev, GFP_KERNEL, "%d", i);
if (!name)
return;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return;
priv->chip = chip;
priv->offset = i;
debugfs_create_file(name, 0600, chip->dbg_dir, priv,
&gpio_mockup_debugfs_ops);
}
}
static void gpio_mockup_debugfs_cleanup(void *data)
{
struct gpio_mockup_chip *chip = data;
debugfs_remove_recursive(chip->dbg_dir);
}
static void gpio_mockup_dispose_mappings(void *data)
{
struct gpio_mockup_chip *chip = data;
struct gpio_chip *gc = &chip->gc;
int i, irq;
for (i = 0; i < gc->ngpio; i++) {
irq = irq_find_mapping(chip->irq_sim_domain, i);
if (irq)
irq_dispose_mapping(irq);
}
}
static int gpio_mockup_probe(struct platform_device *pdev)
{
struct gpio_mockup_chip *chip;
struct gpio_chip *gc;
struct device *dev;
const char *name;
int rv, base, i;
u16 ngpio;
dev = &pdev->dev;
rv = device_property_read_u32(dev, "gpio-base", &base);
if (rv)
base = -1;
rv = device_property_read_u16(dev, "nr-gpios", &ngpio);
if (rv)
return rv;
rv = device_property_read_string(dev, "chip-label", &name);
if (rv)
name = dev_name(dev);
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/debugfs.h`, `linux/device.h`, `linux/gpio/driver.h`, `linux/interrupt.h`, `linux/irq.h`, `linux/irq_sim.h`, `linux/irqdomain.h`.
- Detected declarations: `struct gpio_mockup_line_status`, `struct gpio_mockup_chip`, `struct gpio_mockup_dbgfs_private`, `function gpio_mockup_range_base`, `function gpio_mockup_range_ngpio`, `function __gpio_mockup_get`, `function gpio_mockup_get`, `function gpio_mockup_get_multiple`, `function scoped_guard`, `function __gpio_mockup_set`.
- Atlas domain: Driver Families / drivers/gpio.
- 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.