drivers/gpio/gpio-sch.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-sch.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-sch.c- Extension
.c- Size
- 10217 bytes
- Lines
- 421
- 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.
- 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/acpi.hlinux/bitops.hlinux/errno.hlinux/gpio/driver.hlinux/io.hlinux/irq.hlinux/kernel.hlinux/module.hlinux/pci_ids.hlinux/platform_device.hlinux/types.h
Detected Declarations
struct sch_gpiofunction sch_gpio_offsetfunction sch_gpio_bitfunction sch_gpio_reg_getfunction sch_gpio_reg_setfunction sch_gpio_direction_infunction sch_gpio_getfunction sch_gpio_setfunction sch_gpio_direction_outfunction sch_gpio_get_directionfunction sch_irq_typefunction sch_irq_ackfunction sch_irq_mask_unmaskfunction sch_irq_maskfunction sch_irq_unmaskfunction sch_gpio_gpe_handlerfunction sch_gpio_remove_gpe_handlerfunction sch_gpio_install_gpe_handlerfunction sch_gpio_probe
Annotated Snippet
struct sch_gpio {
struct gpio_chip chip;
void __iomem *regs;
spinlock_t lock;
unsigned short resume_base;
/* GPE handling */
u32 gpe;
acpi_gpe_handler gpe_handler;
};
static unsigned int sch_gpio_offset(struct sch_gpio *sch, unsigned int gpio,
unsigned int reg)
{
unsigned int base = CORE_BANK_OFFSET;
if (gpio >= sch->resume_base) {
gpio -= sch->resume_base;
base = RESUME_BANK_OFFSET;
}
return base + reg + gpio / 8;
}
static unsigned int sch_gpio_bit(struct sch_gpio *sch, unsigned int gpio)
{
if (gpio >= sch->resume_base)
gpio -= sch->resume_base;
return gpio % 8;
}
static int sch_gpio_reg_get(struct sch_gpio *sch, unsigned int gpio, unsigned int reg)
{
unsigned short offset, bit;
u8 reg_val;
offset = sch_gpio_offset(sch, gpio, reg);
bit = sch_gpio_bit(sch, gpio);
reg_val = !!(ioread8(sch->regs + offset) & BIT(bit));
return reg_val;
}
static void sch_gpio_reg_set(struct sch_gpio *sch, unsigned int gpio, unsigned int reg,
int val)
{
unsigned short offset, bit;
u8 reg_val;
offset = sch_gpio_offset(sch, gpio, reg);
bit = sch_gpio_bit(sch, gpio);
reg_val = ioread8(sch->regs + offset);
if (val)
reg_val |= BIT(bit);
else
reg_val &= ~BIT(bit);
iowrite8(reg_val, sch->regs + offset);
}
static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned int gpio_num)
{
struct sch_gpio *sch = gpiochip_get_data(gc);
unsigned long flags;
spin_lock_irqsave(&sch->lock, flags);
sch_gpio_reg_set(sch, gpio_num, GIO, 1);
spin_unlock_irqrestore(&sch->lock, flags);
return 0;
}
static int sch_gpio_get(struct gpio_chip *gc, unsigned int gpio_num)
{
struct sch_gpio *sch = gpiochip_get_data(gc);
return sch_gpio_reg_get(sch, gpio_num, GLV);
}
static int sch_gpio_set(struct gpio_chip *gc, unsigned int gpio_num, int val)
{
struct sch_gpio *sch = gpiochip_get_data(gc);
unsigned long flags;
spin_lock_irqsave(&sch->lock, flags);
sch_gpio_reg_set(sch, gpio_num, GLV, val);
spin_unlock_irqrestore(&sch->lock, flags);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/bitops.h`, `linux/errno.h`, `linux/gpio/driver.h`, `linux/io.h`, `linux/irq.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct sch_gpio`, `function sch_gpio_offset`, `function sch_gpio_bit`, `function sch_gpio_reg_get`, `function sch_gpio_reg_set`, `function sch_gpio_direction_in`, `function sch_gpio_get`, `function sch_gpio_set`, `function sch_gpio_direction_out`, `function sch_gpio_get_direction`.
- 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.
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.