drivers/gpio/gpio-kempld.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-kempld.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-kempld.c- Extension
.c- Size
- 12015 bytes
- Lines
- 467
- 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/init.hlinux/kernel.hlinux/module.hlinux/bitops.hlinux/errno.hlinux/interrupt.hlinux/platform_device.hlinux/gpio/driver.hlinux/mfd/kempld.h
Detected Declarations
struct kempld_gpio_datafunction kempld_gpio_bitopfunction kempld_gpio_get_bitfunction kempld_gpio_getfunction kempld_gpio_get_multiplefunction kempld_gpio_setfunction kempld_gpio_set_multiplefunction kempld_gpio_direction_inputfunction kempld_gpio_direction_outputfunction kempld_gpio_get_directionfunction kempld_gpio_pincountfunction kempld_irq_maskfunction kempld_irq_unmaskfunction kempld_irq_set_typefunction kempld_irq_bus_lockfunction kempld_irq_bus_sync_unlockfunction kempld_gpio_irq_handlerfunction for_each_set_bitfunction kempld_gpio_irq_initfunction kempld_gpio_probe
Annotated Snippet
struct kempld_gpio_data {
struct gpio_chip chip;
struct kempld_device_data *pld;
u8 out_lvl_reg;
struct mutex irq_lock;
u16 ien;
u16 evt_low_high;
u16 evt_lvl_edge;
};
/*
* Set or clear GPIO bit
* kempld_get_mutex must be called prior to calling this function.
*/
static void kempld_gpio_bitop(struct kempld_device_data *pld,
u8 reg, unsigned int bit, bool val)
{
u8 status;
status = kempld_read8(pld, reg + (bit / 8));
if (val)
status |= KEMPLD_GPIO_MASK(bit);
else
status &= ~KEMPLD_GPIO_MASK(bit);
kempld_write8(pld, reg + (bit / 8), status);
}
static int kempld_gpio_get_bit(struct kempld_device_data *pld,
u8 reg, unsigned int bit)
{
u8 status;
kempld_get_mutex(pld);
status = kempld_read8(pld, reg + (bit / 8));
kempld_release_mutex(pld);
return !!(status & KEMPLD_GPIO_MASK(bit));
}
static int kempld_gpio_get(struct gpio_chip *chip, unsigned offset)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
return !!kempld_gpio_get_bit(pld, KEMPLD_GPIO_LVL, offset);
}
static int kempld_gpio_get_multiple(struct gpio_chip *chip, unsigned long *mask,
unsigned long *bits)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
u8 reg = KEMPLD_GPIO_LVL;
unsigned int shift;
bits[0] &= ~mask[0];
kempld_get_mutex(pld);
/* Try to reduce to a single 8 bits access if possible */
for (shift = 0; shift < gpio->chip.ngpio; shift += 8, reg++) {
unsigned long msk = (mask[0] >> shift) & 0xff;
if (!msk)
continue;
bits[0] |= (kempld_read8(pld, reg) & msk) << shift;
}
kempld_release_mutex(pld);
return 0;
}
static int kempld_gpio_set(struct gpio_chip *chip, unsigned int offset,
int value)
{
struct kempld_gpio_data *gpio = gpiochip_get_data(chip);
struct kempld_device_data *pld = gpio->pld;
kempld_get_mutex(pld);
kempld_gpio_bitop(pld, gpio->out_lvl_reg, offset, value);
kempld_release_mutex(pld);
return 0;
}
static int kempld_gpio_set_multiple(struct gpio_chip *chip,
unsigned long *mask, unsigned long *bits)
Annotation
- Immediate include surface: `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/bitops.h`, `linux/errno.h`, `linux/interrupt.h`, `linux/platform_device.h`, `linux/gpio/driver.h`.
- Detected declarations: `struct kempld_gpio_data`, `function kempld_gpio_bitop`, `function kempld_gpio_get_bit`, `function kempld_gpio_get`, `function kempld_gpio_get_multiple`, `function kempld_gpio_set`, `function kempld_gpio_set_multiple`, `function kempld_gpio_direction_input`, `function kempld_gpio_direction_output`, `function kempld_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.
- 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.