drivers/gpio/gpio-mmio.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-mmio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-mmio.c- Extension
.c- Size
- 22399 bytes
- Lines
- 840
- Domain
- Driver Families
- Bucket
- drivers/gpio
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bitops.hlinux/cleanup.hlinux/err.hlinux/io.hlinux/ioport.hlinux/limits.hlinux/log2.hlinux/mod_devicetable.hlinux/module.hlinux/pinctrl/consumer.hlinux/platform_device.hlinux/property.hlinux/spinlock.hlinux/types.hlinux/gpio/driver.hlinux/gpio/generic.hgpiolib.h
Detected Declarations
function gpio_mmio_write8function gpio_mmio_read8function gpio_mmio_write16function gpio_mmio_read16function gpio_mmio_write32function gpio_mmio_read32function gpio_mmio_write64function gpio_mmio_read64function gpio_mmio_write16befunction gpio_mmio_read16befunction gpio_mmio_write32befunction gpio_mmio_read32befunction gpio_mmio_line2maskfunction gpio_mmio_get_setfunction gpio_mmio_get_set_multiplefunction gpio_mmio_getfunction gpio_mmio_get_multiplefunction gpio_mmio_get_multiple_befunction gpio_mmio_set_nonefunction gpio_mmio_setfunction gpio_mmio_set_with_clearfunction gpio_mmio_set_setfunction gpio_mmio_multiple_get_masksfunction for_each_set_bitfunction gpio_mmio_set_multiple_single_regfunction gpio_mmio_set_multiplefunction gpio_mmio_set_multiple_setfunction gpio_mmio_set_multiple_with_clearfunction gpio_mmio_dir_returnfunction gpio_mmio_dir_in_errfunction gpio_mmio_simple_dir_infunction gpio_mmio_dir_out_errfunction gpio_mmio_simple_dir_outfunction gpio_mmio_dir_infunction scoped_guardfunction gpio_mmio_get_dirfunction gpio_mmio_dir_outfunction gpio_mmio_dir_out_dir_firstfunction gpio_mmio_dir_out_val_firstfunction gpio_mmio_setup_accessorsfunction gpio_mmio_setup_iofunction gpio_mmio_setup_directionfunction gpio_mmio_requestfunction gpio_generic_chip_initfunction gpio_mmio_pdev_probeexport gpio_generic_chip_init
Annotated Snippet
if (byte_be) {
chip->read_reg = gpio_mmio_read16be;
chip->write_reg = gpio_mmio_write16be;
} else {
chip->read_reg = gpio_mmio_read16;
chip->write_reg = gpio_mmio_write16;
}
break;
case 32:
if (byte_be) {
chip->read_reg = gpio_mmio_read32be;
chip->write_reg = gpio_mmio_write32be;
} else {
chip->read_reg = gpio_mmio_read32;
chip->write_reg = gpio_mmio_write32;
}
break;
#if BITS_PER_LONG >= 64
case 64:
if (byte_be) {
dev_err(dev,
"64 bit big endian byte order unsupported\n");
return -EINVAL;
} else {
chip->read_reg = gpio_mmio_read64;
chip->write_reg = gpio_mmio_write64;
}
break;
#endif /* BITS_PER_LONG >= 64 */
default:
dev_err(dev, "unsupported data width %u bits\n", chip->bits);
return -EINVAL;
}
return 0;
}
/*
* Create the device and allocate the resources. For setting GPIO's there are
* three supported configurations:
*
* - single input/output register resource (named "dat").
* - set/clear pair (named "set" and "clr").
* - single output register resource and single input resource ("set" and
* dat").
*
* For the single output register, this drives a 1 by setting a bit and a zero
* by clearing a bit. For the set clr pair, this drives a 1 by setting a bit
* in the set register and clears it by setting a bit in the clear register.
* The configuration is detected by which resources are present.
*
* For setting the GPIO direction, there are three supported configurations:
*
* - simple bidirection GPIO that requires no configuration.
* - an output direction register (named "dirout") where a 1 bit
* indicates the GPIO is an output.
* - an input direction register (named "dirin") where a 1 bit indicates
* the GPIO is an input.
*/
static int gpio_mmio_setup_io(struct gpio_generic_chip *chip,
const struct gpio_generic_chip_config *cfg)
{
struct gpio_chip *gc = &chip->gc;
chip->reg_dat = cfg->dat;
if (!chip->reg_dat)
return -EINVAL;
if (cfg->set && cfg->clr) {
chip->reg_set = cfg->set;
chip->reg_clr = cfg->clr;
gc->set = gpio_mmio_set_with_clear;
gc->set_multiple = gpio_mmio_set_multiple_with_clear;
} else if (cfg->set && !cfg->clr) {
chip->reg_set = cfg->set;
gc->set = gpio_mmio_set_set;
gc->set_multiple = gpio_mmio_set_multiple_set;
} else if (cfg->flags & GPIO_GENERIC_NO_OUTPUT) {
gc->set = gpio_mmio_set_none;
gc->set_multiple = NULL;
} else {
gc->set = gpio_mmio_set;
gc->set_multiple = gpio_mmio_set_multiple;
}
if (!(cfg->flags & GPIO_GENERIC_UNREADABLE_REG_SET) &&
(cfg->flags & GPIO_GENERIC_READ_OUTPUT_REG_SET)) {
gc->get = gpio_mmio_get_set;
if (!chip->be_bits)
gc->get_multiple = gpio_mmio_get_set_multiple;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/cleanup.h`, `linux/err.h`, `linux/io.h`, `linux/ioport.h`, `linux/limits.h`, `linux/log2.h`, `linux/mod_devicetable.h`.
- Detected declarations: `function gpio_mmio_write8`, `function gpio_mmio_read8`, `function gpio_mmio_write16`, `function gpio_mmio_read16`, `function gpio_mmio_write32`, `function gpio_mmio_read32`, `function gpio_mmio_write64`, `function gpio_mmio_read64`, `function gpio_mmio_write16be`, `function gpio_mmio_read16be`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.