drivers/gpio/gpio-adnp.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-adnp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-adnp.c- Extension
.c- Size
- 12210 bytes
- Lines
- 528
- 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/cleanup.hlinux/gpio/driver.hlinux/i2c.hlinux/interrupt.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/property.hlinux/seq_file.hlinux/slab.h
Detected Declarations
struct adnpfunction adnp_readfunction adnp_writefunction adnp_gpio_getfunction __adnp_gpio_setfunction adnp_gpio_setfunction adnp_gpio_direction_inputfunction adnp_gpio_direction_outputfunction adnp_gpio_dbg_showfunction scoped_guardfunction adnp_irqfunction for_each_set_bitfunction adnp_irq_maskfunction adnp_irq_unmaskfunction adnp_irq_set_typefunction adnp_irq_bus_lockfunction adnp_irq_bus_unlockfunction scoped_guardfunction adnp_irq_setupfunction adnp_gpio_setupfunction adnp_i2c_probe
Annotated Snippet
struct adnp {
struct i2c_client *client;
struct gpio_chip gpio;
unsigned int reg_shift;
struct mutex i2c_lock;
struct mutex irq_lock;
u8 *irq_enable;
u8 *irq_level;
u8 *irq_rise;
u8 *irq_fall;
u8 *irq_high;
u8 *irq_low;
};
static int adnp_read(struct adnp *adnp, unsigned offset, uint8_t *value)
{
int err;
err = i2c_smbus_read_byte_data(adnp->client, offset);
if (err < 0) {
dev_err(adnp->gpio.parent, "%s failed: %d\n",
"i2c_smbus_read_byte_data()", err);
return err;
}
*value = err;
return 0;
}
static int adnp_write(struct adnp *adnp, unsigned offset, uint8_t value)
{
int err;
err = i2c_smbus_write_byte_data(adnp->client, offset, value);
if (err < 0) {
dev_err(adnp->gpio.parent, "%s failed: %d\n",
"i2c_smbus_write_byte_data()", err);
return err;
}
return 0;
}
static int adnp_gpio_get(struct gpio_chip *chip, unsigned offset)
{
struct adnp *adnp = gpiochip_get_data(chip);
unsigned int reg = offset >> adnp->reg_shift;
unsigned int pos = offset & 7;
u8 value;
int err;
err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &value);
if (err < 0)
return err;
return (value & BIT(pos)) ? 1 : 0;
}
static int __adnp_gpio_set(struct adnp *adnp, unsigned int offset, int value)
{
unsigned int reg = offset >> adnp->reg_shift;
unsigned int pos = offset & 7;
int err;
u8 val;
err = adnp_read(adnp, GPIO_PLR(adnp) + reg, &val);
if (err < 0)
return err;
if (value)
val |= BIT(pos);
else
val &= ~BIT(pos);
return adnp_write(adnp, GPIO_PLR(adnp) + reg, val);
}
static int adnp_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
{
struct adnp *adnp = gpiochip_get_data(chip);
guard(mutex)(&adnp->i2c_lock);
return __adnp_gpio_set(adnp, offset, value);
}
static int adnp_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
{
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/gpio/driver.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/property.h`.
- Detected declarations: `struct adnp`, `function adnp_read`, `function adnp_write`, `function adnp_gpio_get`, `function __adnp_gpio_set`, `function adnp_gpio_set`, `function adnp_gpio_direction_input`, `function adnp_gpio_direction_output`, `function adnp_gpio_dbg_show`, `function scoped_guard`.
- 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.