drivers/gpio/gpiolib-shared.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpiolib-shared.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpiolib-shared.c- Extension
.c- Size
- 20288 bytes
- Lines
- 803
- Domain
- Driver Families
- Bucket
- drivers/gpio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/auxiliary_bus.hlinux/cleanup.hlinux/device.hlinux/fwnode.hlinux/gpio/consumer.hlinux/gpio/machine.hlinux/idr.hlinux/kref.hlinux/list.hlinux/lockdep.hlinux/module.hlinux/mutex.hlinux/of.hlinux/overflow.hlinux/printk.hlinux/property.hlinux/slab.hlinux/string.hgpiolib.hgpiolib-shared.h
Detected Declarations
struct gpio_shared_refstruct gpio_shared_entryfunction gpio_shared_find_entryfunction list_for_each_entryfunction gpio_shared_setup_reset_proxyfunction list_for_each_entryfunction gpio_shared_of_node_ignorefunction gpio_shared_of_traversefunction for_each_property_of_nodefunction for_each_child_of_node_scopedfunction gpio_shared_of_scanfunction gpio_shared_of_scanfunction gpio_shared_adev_releasefunction gpio_shared_dev_is_reset_gpiofunction gpio_shared_dev_is_reset_gpiofunction gpio_shared_add_proxy_lookupfunction list_for_each_entryfunction gpio_shared_remove_adevfunction gpiochip_setup_sharedfunction list_for_each_entryfunction scoped_guardfunction list_for_each_entryfunction gpio_device_teardown_sharedfunction list_for_each_entryfunction list_for_each_entryfunction gpio_shared_releasefunction gpiod_shared_putfunction gpiod_shared_desc_createfunction scoped_guardfunction gpio_shared_drop_reffunction gpio_shared_drop_entryfunction gpio_shared_initfunction list_for_each_entry_safefunction gpio_shared_entry_is_really_sharedfunction gpio_shared_free_exclusivefunction list_for_each_entry_safefunction gpio_shared_initexport devm_gpiod_shared_get
Annotated Snippet
struct gpio_shared_ref {
struct list_head list;
/* Firmware node associated with this GPIO's consumer. */
struct fwnode_handle *fwnode;
/* GPIO flags this consumer uses for the request. */
enum gpiod_flags flags;
char *con_id;
int dev_id;
/* Protects the auxiliary device struct and the lookup table. */
struct mutex lock;
struct lock_class_key lock_key;
struct auxiliary_device adev;
struct gpiod_lookup_table *lookup;
bool is_reset_gpio;
};
/* Represents a single GPIO pin. */
struct gpio_shared_entry {
struct list_head list;
/* Firmware node associated with the GPIO controller. */
struct fwnode_handle *fwnode;
/* Hardware offset of the GPIO within its chip. */
unsigned int offset;
/* Index in the property value array. */
size_t index;
/* Synchronizes the modification of shared_desc and offset. */
struct mutex lock;
struct gpio_shared_desc *shared_desc;
struct kref ref;
struct list_head refs;
};
static LIST_HEAD(gpio_shared_list);
static DEFINE_IDA(gpio_shared_ida);
#if IS_ENABLED(CONFIG_OF)
static struct gpio_shared_entry *
gpio_shared_find_entry(struct fwnode_handle *controller_node,
unsigned int offset)
{
struct gpio_shared_entry *entry;
list_for_each_entry(entry, &gpio_shared_list, list) {
if (entry->fwnode == controller_node && entry->offset == offset)
return entry;
}
return NULL;
}
static struct gpio_shared_ref *gpio_shared_make_ref(struct fwnode_handle *fwnode,
const char *con_id,
enum gpiod_flags flags)
{
char *con_id_cpy __free(kfree) = NULL;
struct gpio_shared_ref *ref __free(kfree) = kzalloc_obj(*ref);
if (!ref)
return NULL;
if (con_id) {
con_id_cpy = kstrdup(con_id, GFP_KERNEL);
if (!con_id_cpy)
return NULL;
}
ref->dev_id = ida_alloc(&gpio_shared_ida, GFP_KERNEL);
if (ref->dev_id < 0)
return NULL;
ref->flags = flags;
ref->con_id = no_free_ptr(con_id_cpy);
ref->fwnode = fwnode;
lockdep_register_key(&ref->lock_key);
mutex_init_with_key(&ref->lock, &ref->lock_key);
return no_free_ptr(ref);
}
static int gpio_shared_setup_reset_proxy(struct gpio_shared_entry *entry,
enum gpiod_flags flags)
{
struct gpio_shared_ref *ref;
list_for_each_entry(ref, &entry->refs, list) {
if (ref->is_reset_gpio)
/* Already set-up. */
return 0;
}
Annotation
- Immediate include surface: `linux/auxiliary_bus.h`, `linux/cleanup.h`, `linux/device.h`, `linux/fwnode.h`, `linux/gpio/consumer.h`, `linux/gpio/machine.h`, `linux/idr.h`, `linux/kref.h`.
- Detected declarations: `struct gpio_shared_ref`, `struct gpio_shared_entry`, `function gpio_shared_find_entry`, `function list_for_each_entry`, `function gpio_shared_setup_reset_proxy`, `function list_for_each_entry`, `function gpio_shared_of_node_ignore`, `function gpio_shared_of_traverse`, `function for_each_property_of_node`, `function for_each_child_of_node_scoped`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: integration 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.