drivers/gpio/gpiolib-devres.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpiolib-devres.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpiolib-devres.c- Extension
.c- Size
- 11459 bytes
- Lines
- 370
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device/devres.hlinux/err.hlinux/export.hlinux/gfp.hlinux/types.hlinux/gpio/consumer.hgpiolib.h
Detected Declarations
struct fwnode_handlestruct lock_class_keyfunction devm_gpiod_releasefunction devm_gpiod_release_arrayfunction gpiod_getfunction gpiod_get_optionalfunction gpiod_get_indexfunction IS_ERRfunction gpiod_get_index_optionalfunction gpiod_get_arrayfunction gpiod_get_array_optionalfunction devm_gpiod_getfunction devm_gpiod_unhingefunction devm_gpiod_get_arrayfunction devm_gpio_chip_releasefunction devm_gpiochip_add_data_with_keyexport devm_gpiod_getexport devm_gpiod_get_optionalexport devm_gpiod_get_indexexport devm_fwnode_gpiod_get_indexexport devm_gpiod_get_index_optionalexport devm_gpiod_get_arrayexport devm_gpiod_get_array_optionalexport devm_gpiod_putexport devm_gpiod_unhingeexport devm_gpiod_put_arrayexport devm_gpiochip_add_data_with_key
Annotated Snippet
#include <linux/device/devres.h>
#include <linux/err.h>
#include <linux/export.h>
#include <linux/gfp.h>
#include <linux/types.h>
#include <linux/gpio/consumer.h>
#include "gpiolib.h"
struct fwnode_handle;
struct lock_class_key;
static void devm_gpiod_release(void *desc)
{
gpiod_put(desc);
}
static void devm_gpiod_release_array(void *descs)
{
gpiod_put_array(descs);
}
/**
* devm_gpiod_get - Resource-managed gpiod_get()
* @dev: GPIO consumer
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* Managed gpiod_get(). GPIO descriptors returned from this function are
* automatically disposed on driver detach. See gpiod_get() for detailed
* information about behavior and return values.
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, %-ENOENT if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO.
*/
struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
const char *con_id,
enum gpiod_flags flags)
{
return devm_gpiod_get_index(dev, con_id, 0, flags);
}
EXPORT_SYMBOL_GPL(devm_gpiod_get);
/**
* devm_gpiod_get_optional - Resource-managed gpiod_get_optional()
* @dev: GPIO consumer
* @con_id: function within the GPIO consumer
* @flags: optional GPIO initialization flags
*
* Managed gpiod_get_optional(). GPIO descriptors returned from this function
* are automatically disposed on driver detach. See gpiod_get_optional() for
* detailed information about behavior and return values.
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, NULL if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO.
*/
struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
const char *con_id,
enum gpiod_flags flags)
{
return devm_gpiod_get_index_optional(dev, con_id, 0, flags);
}
EXPORT_SYMBOL_GPL(devm_gpiod_get_optional);
/**
* devm_gpiod_get_index - Resource-managed gpiod_get_index()
* @dev: GPIO consumer
* @con_id: function within the GPIO consumer
* @idx: index of the GPIO to obtain in the consumer
* @flags: optional GPIO initialization flags
*
* Managed gpiod_get_index(). GPIO descriptors returned from this function are
* automatically disposed on driver detach. See gpiod_get_index() for detailed
* information about behavior and return values.
*
* Returns:
* The GPIO descriptor corresponding to the function @con_id of device
* dev, %-ENOENT if no GPIO has been assigned to the requested function, or
* another IS_ERR() code if an error occurred while trying to acquire the GPIO.
*/
struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
const char *con_id,
unsigned int idx,
enum gpiod_flags flags)
{
Annotation
- Immediate include surface: `linux/device/devres.h`, `linux/err.h`, `linux/export.h`, `linux/gfp.h`, `linux/types.h`, `linux/gpio/consumer.h`, `gpiolib.h`.
- Detected declarations: `struct fwnode_handle`, `struct lock_class_key`, `function devm_gpiod_release`, `function devm_gpiod_release_array`, `function gpiod_get`, `function gpiod_get_optional`, `function gpiod_get_index`, `function IS_ERR`, `function gpiod_get_index_optional`, `function gpiod_get_array`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: integration 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.