drivers/gpio/gpio-brcmstb.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-brcmstb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-brcmstb.c- Extension
.c- Size
- 21962 bytes
- Lines
- 810
- 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.
- 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/gpio/driver.hlinux/gpio/generic.hlinux/of.hlinux/module.hlinux/irqdomain.hlinux/irqchip/chained_irq.hlinux/interrupt.hlinux/platform_device.hlinux/string_choices.h
Detected Declarations
struct brcmstb_gpio_bankstruct brcmstb_gpio_privenum gio_reg_indexfunction brcmstb_gpio_gc_to_privfunction __brcmstb_gpio_get_active_irqsfunction brcmstb_gpio_get_active_irqsfunction brcmstb_gpio_hwirq_to_offsetfunction __brcmstb_gpio_set_imaskfunction brcmstb_gpio_set_imaskfunction brcmstb_gpio_to_irqfunction brcmstb_gpio_irq_maskfunction brcmstb_gpio_irq_mask_ackfunction brcmstb_gpio_irq_unmaskfunction brcmstb_gpio_irq_ackfunction brcmstb_gpio_irq_set_typefunction brcmstb_gpio_priv_set_wakefunction brcmstb_gpio_irq_set_wakefunction brcmstb_gpio_wake_irq_handlerfunction brcmstb_gpio_irq_bank_handlerfunction for_each_set_bitfunction brcmstb_gpio_irq_handlerfunction list_for_each_entryfunction brcmstb_gpio_irq_mapfunction brcmstb_gpio_irq_unmapfunction brcmstb_gpio_sanity_check_banksfunction brcmstb_gpio_removefunction brcmstb_gpio_of_xlatefunction brcmstb_gpio_irq_setupfunction brcmstb_gpio_bank_savefunction brcmstb_gpio_quiescefunction list_for_each_entryfunction brcmstb_gpio_shutdownfunction brcmstb_gpio_bank_restorefunction brcmstb_gpio_suspendfunction brcmstb_gpio_suspend_noirqfunction brcmstb_gpio_resumefunction brcmstb_gpio_probefunction of_property_for_each_u32
Annotated Snippet
struct brcmstb_gpio_bank {
struct list_head node;
int id;
struct gpio_generic_chip chip;
struct brcmstb_gpio_priv *parent_priv;
u32 width;
u32 wake_active;
u32 saved_regs[GIO_REG_STAT]; /* Don't save and restore GIO_REG_STAT */
};
struct brcmstb_gpio_priv {
struct list_head bank_list;
void __iomem *reg_base;
struct platform_device *pdev;
struct irq_domain *irq_domain;
struct irq_chip irq_chip;
int parent_irq;
int num_gpios;
int parent_wake_irq;
bool suspended;
};
#define MAX_GPIO_PER_BANK 32
#define GPIO_BANK(gpio) ((gpio) >> 5)
/* assumes MAX_GPIO_PER_BANK is a multiple of 2 */
#define GPIO_BIT(gpio) ((gpio) & (MAX_GPIO_PER_BANK - 1))
static inline struct brcmstb_gpio_priv *
brcmstb_gpio_gc_to_priv(struct gpio_chip *gc)
{
struct brcmstb_gpio_bank *bank = gpiochip_get_data(gc);
return bank->parent_priv;
}
static unsigned long
__brcmstb_gpio_get_active_irqs(struct brcmstb_gpio_bank *bank)
{
void __iomem *reg_base = bank->parent_priv->reg_base;
return gpio_generic_read_reg(&bank->chip, reg_base + GIO_STAT(bank->id)) &
gpio_generic_read_reg(&bank->chip, reg_base + GIO_MASK(bank->id));
}
static unsigned long
brcmstb_gpio_get_active_irqs(struct brcmstb_gpio_bank *bank)
{
unsigned long status;
guard(gpio_generic_lock_irqsave)(&bank->chip);
status = __brcmstb_gpio_get_active_irqs(bank);
return status;
}
static int brcmstb_gpio_hwirq_to_offset(irq_hw_number_t hwirq,
struct brcmstb_gpio_bank *bank)
{
return hwirq - bank->chip.gc.offset;
}
static void __brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank,
irq_hw_number_t hwirq, bool enable)
{
struct brcmstb_gpio_priv *priv = bank->parent_priv;
u32 mask = BIT(brcmstb_gpio_hwirq_to_offset(hwirq, bank));
u32 imask;
imask = gpio_generic_read_reg(&bank->chip,
priv->reg_base + GIO_MASK(bank->id));
if (enable)
imask |= mask;
else
imask &= ~mask;
gpio_generic_write_reg(&bank->chip,
priv->reg_base + GIO_MASK(bank->id), imask);
}
static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank,
irq_hw_number_t hwirq, bool enable)
{
guard(gpio_generic_lock_irqsave)(&bank->chip);
__brcmstb_gpio_set_imask(bank, hwirq, enable);
}
static int brcmstb_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
{
struct brcmstb_gpio_priv *priv = brcmstb_gpio_gc_to_priv(gc);
/* gc_offset is relative to this gpio_chip; want real offset */
int hwirq = offset + gc->offset;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/gpio/driver.h`, `linux/gpio/generic.h`, `linux/of.h`, `linux/module.h`, `linux/irqdomain.h`, `linux/irqchip/chained_irq.h`, `linux/interrupt.h`.
- Detected declarations: `struct brcmstb_gpio_bank`, `struct brcmstb_gpio_priv`, `enum gio_reg_index`, `function brcmstb_gpio_gc_to_priv`, `function __brcmstb_gpio_get_active_irqs`, `function brcmstb_gpio_get_active_irqs`, `function brcmstb_gpio_hwirq_to_offset`, `function __brcmstb_gpio_set_imask`, `function brcmstb_gpio_set_imask`, `function brcmstb_gpio_to_irq`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: source implementation candidate.
- 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.