tools/gpio/lsgpio.c
Source file repositories/reference/linux-study-clean/tools/gpio/lsgpio.c
File Facts
- System
- Linux kernel
- Corpus path
tools/gpio/lsgpio.c- Extension
.c- Size
- 4611 bytes
- Lines
- 226
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
unistd.hstdlib.hstdbool.hstdio.hdirent.herrno.hstring.hpoll.hfcntl.hgetopt.hsys/ioctl.hlinux/gpio.hgpio-utils.h
Detected Declarations
struct gpio_flagfunction print_attributesfunction list_devicefunction print_usagefunction main
Annotated Snippet
struct gpio_flag {
char *name;
unsigned long long mask;
};
struct gpio_flag flagnames[] = {
{
.name = "used",
.mask = GPIO_V2_LINE_FLAG_USED,
},
{
.name = "input",
.mask = GPIO_V2_LINE_FLAG_INPUT,
},
{
.name = "output",
.mask = GPIO_V2_LINE_FLAG_OUTPUT,
},
{
.name = "active-low",
.mask = GPIO_V2_LINE_FLAG_ACTIVE_LOW,
},
{
.name = "open-drain",
.mask = GPIO_V2_LINE_FLAG_OPEN_DRAIN,
},
{
.name = "open-source",
.mask = GPIO_V2_LINE_FLAG_OPEN_SOURCE,
},
{
.name = "pull-up",
.mask = GPIO_V2_LINE_FLAG_BIAS_PULL_UP,
},
{
.name = "pull-down",
.mask = GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN,
},
{
.name = "bias-disabled",
.mask = GPIO_V2_LINE_FLAG_BIAS_DISABLED,
},
{
.name = "clock-realtime",
.mask = GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME,
},
};
static void print_attributes(struct gpio_v2_line_info *info)
{
int i;
const char *field_format = "%s";
for (i = 0; i < ARRAY_SIZE(flagnames); i++) {
if (info->flags & flagnames[i].mask) {
fprintf(stdout, field_format, flagnames[i].name);
field_format = ", %s";
}
}
if ((info->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) &&
(info->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING))
fprintf(stdout, field_format, "both-edges");
else if (info->flags & GPIO_V2_LINE_FLAG_EDGE_RISING)
fprintf(stdout, field_format, "rising-edge");
else if (info->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING)
fprintf(stdout, field_format, "falling-edge");
for (i = 0; i < info->num_attrs; i++) {
if (info->attrs[i].id == GPIO_V2_LINE_ATTR_ID_DEBOUNCE)
fprintf(stdout, ", debounce_period=%dusec",
info->attrs[i].debounce_period_us);
}
}
int list_device(const char *device_name)
{
struct gpiochip_info cinfo;
char *chrdev_name;
int fd;
int ret;
int i;
ret = asprintf(&chrdev_name, "/dev/%s", device_name);
if (ret < 0)
return -ENOMEM;
fd = open(chrdev_name, 0);
if (fd == -1) {
ret = -errno;
Annotation
- Immediate include surface: `unistd.h`, `stdlib.h`, `stdbool.h`, `stdio.h`, `dirent.h`, `errno.h`, `string.h`, `poll.h`.
- Detected declarations: `struct gpio_flag`, `function print_attributes`, `function list_device`, `function print_usage`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.