drivers/gpio/gpio-mt7621.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-mt7621.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-mt7621.c- Extension
.c- Size
- 12232 bytes
- Lines
- 502
- 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.
- 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/err.hlinux/gpio/driver.hlinux/gpio/generic.hlinux/interrupt.hlinux/io.hlinux/module.hlinux/platform_device.h
Detected Declarations
struct mtk_gcstruct mtkfunction mt7621_gpio_gc_to_privfunction to_mediatek_gpiofunction mtk_gpio_w32function mtk_gpio_r32function mt7621_gpio_irq_bank_handlerfunction mt7621_gpio_irq_handlerfunction mt7621_gpio_hwirq_to_offsetfunction mediatek_gpio_irq_unmaskfunction mediatek_gpio_irq_maskfunction scoped_guardfunction mediatek_gpio_irq_typefunction mt7621_gpio_irq_reqresfunction mt7621_gpio_irq_relresfunction mediatek_gpio_xlatefunction mt7621_gpio_removefunction mt7621_gpio_hwirq_to_bankfunction mt7621_gpio_irq_mapfunction mt7621_gpio_irq_unmapfunction mt7621_gpio_irq_setupfunction mt7621_gpio_to_irqfunction mediatek_gpio_bank_probefunction mediatek_gpio_probe
Annotated Snippet
struct mtk_gc {
struct gpio_generic_chip chip;
struct mtk *parent_priv;
int bank;
u32 rising;
u32 falling;
u32 hlevel;
u32 llevel;
};
/**
* struct mtk - state container for
* data of the platform driver. It is 3
* separate gpio-chip having an IRQ
* linear domain shared for all of them
* @pdev: platform device instance
* @base: memory base address
* @irq_domain: IRQ linear domain shared across the three gpio chips
* @gpio_irq: irq number from the device tree
* @num_gpios: total number of gpio pins on the three gpio chips
* @gc_map: array of the gpio chips
*/
struct mtk {
struct platform_device *pdev;
void __iomem *base;
struct irq_domain *irq_domain;
int gpio_irq;
int num_gpios;
struct mtk_gc gc_map[MTK_BANK_CNT];
};
static inline struct mtk *
mt7621_gpio_gc_to_priv(struct gpio_chip *gc)
{
struct mtk_gc *bank = gpiochip_get_data(gc);
return bank->parent_priv;
}
static inline struct mtk_gc *
to_mediatek_gpio(struct gpio_chip *chip)
{
struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(chip);
return container_of(gen_gc, struct mtk_gc, chip);
}
static inline void
mtk_gpio_w32(struct mtk_gc *rg, u32 offset, u32 val)
{
struct gpio_chip *gc = &rg->chip.gc;
struct mtk *mtk = mt7621_gpio_gc_to_priv(gc);
offset = (rg->bank * GPIO_BANK_STRIDE) + offset;
gpio_generic_write_reg(&rg->chip, mtk->base + offset, val);
}
static inline u32
mtk_gpio_r32(struct mtk_gc *rg, u32 offset)
{
struct gpio_chip *gc = &rg->chip.gc;
struct mtk *mtk = mt7621_gpio_gc_to_priv(gc);
offset = (rg->bank * GPIO_BANK_STRIDE) + offset;
return gpio_generic_read_reg(&rg->chip, mtk->base + offset);
}
static void
mt7621_gpio_irq_bank_handler(struct mtk_gc *bank)
{
struct mtk *priv = bank->parent_priv;
struct irq_domain *domain = priv->irq_domain;
int hwbase = bank->chip.gc.offset;
unsigned long pending;
unsigned int offset;
pending = mtk_gpio_r32(bank, GPIO_REG_STAT);
if (!pending)
return;
mtk_gpio_w32(bank, GPIO_REG_STAT, pending);
for_each_set_bit(offset, &pending, MTK_BANK_WIDTH)
generic_handle_domain_irq(domain, hwbase + offset);
}
static void
mt7621_gpio_irq_handler(struct irq_desc *desc)
{
struct mtk *priv = irq_desc_get_handler_data(desc);
Annotation
- Immediate include surface: `linux/err.h`, `linux/gpio/driver.h`, `linux/gpio/generic.h`, `linux/interrupt.h`, `linux/io.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct mtk_gc`, `struct mtk`, `function mt7621_gpio_gc_to_priv`, `function to_mediatek_gpio`, `function mtk_gpio_w32`, `function mtk_gpio_r32`, `function mt7621_gpio_irq_bank_handler`, `function mt7621_gpio_irq_handler`, `function mt7621_gpio_hwirq_to_offset`, `function mediatek_gpio_irq_unmask`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: source 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.