drivers/gpio/gpiolib-sysfs.c
Source file repositories/reference/linux-study-clean/drivers/gpio/gpiolib-sysfs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpio/gpiolib-sysfs.c- Extension
.c- Size
- 28410 bytes
- Lines
- 1110
- 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.
- 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/bitops.hlinux/cleanup.hlinux/device.hlinux/init.hlinux/interrupt.hlinux/kdev_t.hlinux/kstrtox.hlinux/list.hlinux/mutex.hlinux/printk.hlinux/slab.hlinux/string.hlinux/srcu.hlinux/sysfs.hlinux/types.hlinux/gpio/consumer.hlinux/gpio/driver.huapi/linux/gpio.hgpiolib.hgpiolib-sysfs.h
Detected Declarations
struct kernfs_nodestruct gpiod_datastruct gpiodev_datafunction specifiedfunction scoped_guardfunction direction_storefunction value_showfunction value_storefunction gpio_sysfs_irqfunction gpio_sysfs_request_irqfunction gpio_sysfs_free_irqfunction edge_showfunction edge_storefunction gpio_sysfs_set_active_lowfunction active_low_showfunction active_low_storefunction gpio_is_visiblefunction base_showfunction label_showfunction ngpio_showfunction export_gpio_descfunction unexport_gpio_descfunction do_chip_export_storefunction chip_export_storefunction chip_unexport_storefunction export_storefunction unexport_storefunction match_gdevfunction gdev_get_datafunction gpiod_attr_initfunction directionfunction match_exportfunction gpiod_export_linkfunction gpiod_unexport_unlockedfunction list_for_each_entryfunction gpiod_freefunction gpiochip_sysfs_registerfunction gpiochip_sysfs_unregisterfunction gpiofind_sysfs_registerfunction gpiolib_sysfs_initexport gpiod_exportexport gpiod_export_linkexport gpiod_unexport
Annotated Snippet
struct gpiod_data {
struct list_head list;
struct gpio_desc *desc;
struct device *dev;
struct mutex mutex;
#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY)
struct kernfs_node *value_kn;
int irq;
unsigned char irq_flags;
#endif /* CONFIG_GPIO_SYSFS_LEGACY */
bool direction_can_change;
struct kobject *parent;
struct device_attribute dir_attr;
struct device_attribute val_attr;
#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY)
struct device_attribute edge_attr;
struct device_attribute active_low_attr;
struct attribute *class_attrs[GPIO_SYSFS_LINE_CLASS_ATTR_SIZE];
struct attribute_group class_attr_group;
const struct attribute_group *class_attr_groups[2];
#endif /* CONFIG_GPIO_SYSFS_LEGACY */
struct attribute *chip_attrs[GPIO_SYSFS_LINE_CHIP_ATTR_SIZE];
struct attribute_group chip_attr_group;
const struct attribute_group *chip_attr_groups[2];
};
struct gpiodev_data {
struct list_head exported_lines;
struct gpio_device *gdev;
struct device *cdev_id; /* Class device by GPIO device ID */
#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY)
struct device *cdev_base; /* Class device by GPIO base */
#endif /* CONFIG_GPIO_SYSFS_LEGACY */
};
/*
* Lock to serialise gpiod export and unexport, and prevent re-export of
* gpiod whose chip is being unregistered.
*/
static DEFINE_MUTEX(sysfs_lock);
/*
* /sys/class/gpio/gpioN... only for GPIOs that are exported
* /direction
* * MAY BE OMITTED if kernel won't allow direction changes
* * is read/write as "in" or "out"
* * may also be written as "high" or "low", initializing
* output value as specified ("out" implies "low")
* /value
* * always readable, subject to hardware behavior
* * may be writable, as zero/nonzero
* /edge
* * configures behavior of poll(2) on /value
* * available only if pin can generate IRQs on input
* * is read/write as "none", "falling", "rising", or "both"
* /active_low
* * configures polarity of /value
* * is read/write as zero/nonzero
* * also affects existing and subsequent "falling" and "rising"
* /edge configuration
*/
static ssize_t direction_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct gpiod_data *data = container_of(attr, struct gpiod_data,
dir_attr);
struct gpio_desc *desc = data->desc;
int value;
scoped_guard(mutex, &data->mutex) {
gpiod_get_direction(desc);
value = !!test_bit(GPIOD_FLAG_IS_OUT, &desc->flags);
}
return sysfs_emit(buf, "%s\n", value ? "out" : "in");
}
static ssize_t direction_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t size)
{
struct gpiod_data *data = container_of(attr, struct gpiod_data,
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/cleanup.h`, `linux/device.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kdev_t.h`, `linux/kstrtox.h`, `linux/list.h`.
- Detected declarations: `struct kernfs_node`, `struct gpiod_data`, `struct gpiodev_data`, `function specified`, `function scoped_guard`, `function direction_store`, `function value_show`, `function value_store`, `function gpio_sysfs_irq`, `function gpio_sysfs_request_irq`.
- Atlas domain: Driver Families / drivers/gpio.
- Implementation status: integration implementation candidate.
- 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.