drivers/gpio/gpio-grgpio.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-grgpio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-grgpio.c- Extension
.c- Size
- 11163 bytes
- Lines
- 464
- Domain
- Driver Families
- Bucket
- drivers/gpio
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/err.hlinux/gpio/driver.hlinux/gpio/generic.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/irq.hlinux/irqdomain.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/slab.hlinux/spinlock.hlinux/string_choices.h
Detected Declarations
struct grgpio_uirqstruct grgpio_lirqstruct grgpio_privfunction grgpio_set_imaskfunction grgpio_to_irqfunction grgpio_irq_set_typefunction grgpio_irq_maskfunction grgpio_irq_unmaskfunction grgpio_irq_handlerfunction grgpio_irq_mapfunction grgpio_irq_unmapfunction grgpio_irq_domain_removefunction grgpio_probe
Annotated Snippet
struct grgpio_uirq {
atomic_t refcnt; /* Reference counter to manage requesting/freeing of uirq */
u8 uirq; /* Underlying irq of the gpio driver */
};
/*
* Structure for an irq of a gpio line handed out by this driver. The index is
* used to map to the corresponding underlying irq.
*/
struct grgpio_lirq {
s8 index; /* Index into struct grgpio_priv's uirqs, or -1 */
u8 irq; /* irq for the gpio line */
};
struct grgpio_priv {
struct gpio_generic_chip chip;
void __iomem *regs;
struct device *dev;
u32 imask; /* irq mask shadow register */
/*
* The grgpio core can have multiple "underlying" irqs. The gpio lines
* can be mapped to any one or none of these underlying irqs
* independently of each other. This driver sets up an irq domain and
* hands out separate irqs to each gpio line
*/
struct irq_domain *domain;
/*
* This array contains information on each underlying irq, each
* irq of the grgpio core itself.
*/
struct grgpio_uirq uirqs[GRGPIO_MAX_NGPIO];
/*
* This array contains information for each gpio line on the irqs
* obtains from this driver. An index value of -1 for a certain gpio
* line indicates that the line has no irq. Otherwise the index connects
* the irq to the underlying irq by pointing into the uirqs array.
*/
struct grgpio_lirq lirqs[GRGPIO_MAX_NGPIO];
};
static void grgpio_set_imask(struct grgpio_priv *priv, unsigned int offset,
int val)
{
if (val)
priv->imask |= BIT(offset);
else
priv->imask &= ~BIT(offset);
gpio_generic_write_reg(&priv->chip, priv->regs + GRGPIO_IMASK, priv->imask);
}
static int grgpio_to_irq(struct gpio_chip *gc, unsigned offset)
{
struct grgpio_priv *priv = gpiochip_get_data(gc);
if (offset >= gc->ngpio)
return -ENXIO;
if (priv->lirqs[offset].index < 0)
return -ENXIO;
return irq_create_mapping(priv->domain, offset);
}
/* -------------------- IRQ chip functions -------------------- */
static int grgpio_irq_set_type(struct irq_data *d, unsigned int type)
{
struct grgpio_priv *priv = irq_data_get_irq_chip_data(d);
u32 mask = BIT(d->hwirq);
u32 ipol;
u32 iedge;
u32 pol;
u32 edge;
switch (type) {
case IRQ_TYPE_LEVEL_LOW:
pol = 0;
edge = 0;
break;
case IRQ_TYPE_LEVEL_HIGH:
pol = mask;
edge = 0;
break;
case IRQ_TYPE_EDGE_FALLING:
pol = 0;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/err.h`, `linux/gpio/driver.h`, `linux/gpio/generic.h`, `linux/init.h`, `linux/interrupt.h`, `linux/io.h`, `linux/irq.h`.
- Detected declarations: `struct grgpio_uirq`, `struct grgpio_lirq`, `struct grgpio_priv`, `function grgpio_set_imask`, `function grgpio_to_irq`, `function grgpio_irq_set_type`, `function grgpio_irq_mask`, `function grgpio_irq_unmask`, `function grgpio_irq_handler`, `function grgpio_irq_map`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.