drivers/gpio/gpio-pca9570.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpio-pca9570.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpio-pca9570.c- Extension
.c- Size
- 4529 bytes
- Lines
- 194
- 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/bits.hlinux/cleanup.hlinux/device/devres.hlinux/errno.hlinux/gpio/driver.hlinux/i2c.hlinux/module.hlinux/mutex.hlinux/property.hlinux/types.h
Detected Declarations
struct pca9570_chip_datastruct pca9570function pca9570_readfunction pca9570_writefunction pca9570_get_directionfunction pca9570_getfunction pca9570_setfunction pca9570_probe
Annotated Snippet
struct pca9570_chip_data {
u16 ngpio;
u32 command;
};
/**
* struct pca9570 - GPIO driver data
* @chip: GPIO controller chip
* @chip_data: GPIO controller platform data
* @lock: Protects write sequences
* @out: Buffer for device register
*/
struct pca9570 {
struct gpio_chip chip;
const struct pca9570_chip_data *chip_data;
struct mutex lock;
u8 out;
};
static int pca9570_read(struct pca9570 *gpio, u8 *value)
{
struct i2c_client *client = to_i2c_client(gpio->chip.parent);
int ret;
if (gpio->chip_data->command != 0)
ret = i2c_smbus_read_byte_data(client, gpio->chip_data->command);
else
ret = i2c_smbus_read_byte(client);
if (ret < 0)
return ret;
*value = ret;
return 0;
}
static int pca9570_write(struct pca9570 *gpio, u8 value)
{
struct i2c_client *client = to_i2c_client(gpio->chip.parent);
if (gpio->chip_data->command != 0)
return i2c_smbus_write_byte_data(client, gpio->chip_data->command, value);
return i2c_smbus_write_byte(client, value);
}
static int pca9570_get_direction(struct gpio_chip *chip,
unsigned offset)
{
/* This device always output */
return GPIO_LINE_DIRECTION_OUT;
}
static int pca9570_get(struct gpio_chip *chip, unsigned offset)
{
struct pca9570 *gpio = gpiochip_get_data(chip);
u8 buffer;
int ret;
ret = pca9570_read(gpio, &buffer);
if (ret)
return ret;
return !!(buffer & BIT(offset));
}
static int pca9570_set(struct gpio_chip *chip, unsigned int offset, int value)
{
struct pca9570 *gpio = gpiochip_get_data(chip);
u8 buffer;
int ret;
guard(mutex)(&gpio->lock);
buffer = gpio->out;
if (value)
buffer |= BIT(offset);
else
buffer &= ~BIT(offset);
ret = pca9570_write(gpio, buffer);
if (ret)
return ret;
gpio->out = buffer;
return 0;
}
static int pca9570_probe(struct i2c_client *client)
Annotation
- Immediate include surface: `linux/bits.h`, `linux/cleanup.h`, `linux/device/devres.h`, `linux/errno.h`, `linux/gpio/driver.h`, `linux/i2c.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct pca9570_chip_data`, `struct pca9570`, `function pca9570_read`, `function pca9570_write`, `function pca9570_get_direction`, `function pca9570_get`, `function pca9570_set`, `function pca9570_probe`.
- 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.