drivers/gpio/gpiolib.h
Source file repositories/reference/linux-study-clean/drivers/gpio/gpiolib.h
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpiolib.h- Extension
.h- Size
- 10912 bytes
- Lines
- 311
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cdev.hlinux/device.hlinux/err.hlinux/gpio/consumer.hlinux/gpio/driver.hlinux/module.hlinux/notifier.hlinux/spinlock.hlinux/string.hlinux/srcu.hlinux/workqueue.h
Detected Declarations
struct fwnode_handlestruct gpio_devicestruct gpio_arraystruct gpio_desc_labelstruct gpio_descstruct gpio_chip_guardfunction gpiod_request_user
Annotated Snippet
struct gpio_device {
struct device dev;
struct cdev chrdev;
int id;
struct module *owner;
struct gpio_chip __rcu *chip;
struct gpio_desc *descs;
unsigned long *valid_mask;
struct srcu_struct desc_srcu;
unsigned int base;
u16 ngpio;
bool can_sleep;
const char *label;
void *data;
struct list_head list;
struct raw_notifier_head line_state_notifier;
rwlock_t line_state_lock;
struct workqueue_struct *line_state_wq;
struct blocking_notifier_head device_notifier;
struct srcu_struct srcu;
#ifdef CONFIG_PINCTRL
/*
* If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
* describe the actual pin range which they serve in an SoC. This
* information would be used by pinctrl subsystem to configure
* corresponding pins for gpio usage.
*/
struct list_head pin_ranges;
#endif
};
static inline struct gpio_device *to_gpio_device(struct device *dev)
{
return container_of(dev, struct gpio_device, dev);
}
/* GPIO suffixes used for ACPI and device tree lookup */
extern const char *const gpio_suffixes[];
#define for_each_gpio_property_name(propname, con_id) \
for (const char * const *__suffixes = gpio_suffixes; \
*__suffixes && ({ \
const char *__gs = *__suffixes; \
\
if (con_id) \
snprintf(propname, sizeof(propname), "%s-%s", con_id, __gs); \
else \
strscpy(propname, __gs); \
1; \
}); \
__suffixes++)
/**
* struct gpio_array - Opaque descriptor for a structure of GPIO array attributes
*
* @desc: Array of pointers to the GPIO descriptors
* @size: Number of elements in desc
* @gdev: Parent GPIO device
* @get_mask: Get mask used in fastpath
* @set_mask: Set mask used in fastpath
* @invert_mask: Invert mask used in fastpath
*
* This structure is attached to struct gpiod_descs obtained from
* gpiod_get_array() and can be passed back to get/set array functions in order
* to activate fast processing path if applicable.
*/
struct gpio_array {
struct gpio_desc **desc;
unsigned int size;
struct gpio_device *gdev;
unsigned long *get_mask;
unsigned long *set_mask;
unsigned long invert_mask[];
};
#define for_each_gpio_desc(gc, desc) \
for (unsigned int __i = 0; \
__i < gc->ngpio && (desc = gpiochip_get_desc(gc, __i)); \
__i++) \
#define for_each_gpio_desc_with_flag(gc, desc, flag) \
for_each_gpio_desc(gc, desc) \
if (!test_bit(flag, &desc->flags)) {} else
int gpiod_get_array_value_complex(bool raw, bool can_sleep,
unsigned int array_size,
struct gpio_desc **desc_array,
struct gpio_array *array_info,
unsigned long *value_bitmap);
Annotation
- Immediate include surface: `linux/cdev.h`, `linux/device.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/gpio/driver.h`, `linux/module.h`, `linux/notifier.h`, `linux/spinlock.h`.
- Detected declarations: `struct fwnode_handle`, `struct gpio_device`, `struct gpio_array`, `struct gpio_desc_label`, `struct gpio_desc`, `struct gpio_chip_guard`, `function gpiod_request_user`.
- 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.