Lines Matching +full:gpio +full:- +full:config

1 // SPDX-License-Identifier: GPL-2.0-only
3 * gpio-event-mon - monitor GPIO line events from userspace
8 * gpio-event-mon -n <device-name> -o <offset>
25 #include <linux/gpio.h>
26 #include "gpio-utils.h"
31 struct gpio_v2_line_config *config, in monitor_device() argument
42 return -ENOMEM; in monitor_device()
45 if (cfd == -1) { in monitor_device()
46 ret = -errno; in monitor_device()
51 ret = gpiotools_request_line(device_name, lines, num_lines, config, in monitor_device()
52 "gpio-event-mon"); in monitor_device()
66 "Failed to issue GPIO LINE GET VALUES IOCTL (%d)\n", in monitor_device()
77 for (i = 1; i < num_lines - 1; i++) in monitor_device()
82 for (i = 1; i < num_lines - 1; i++) in monitor_device()
94 if (ret == -1) { in monitor_device()
95 if (errno == -EAGAIN) { in monitor_device()
99 ret = -errno; in monitor_device()
108 ret = -EIO; in monitor_device()
111 fprintf(stdout, "GPIO EVENT at %" PRIu64 " on line %d (%d|%d) ", in monitor_device()
132 if (close(lfd) == -1) in monitor_device()
135 if (close(cfd) == -1) in monitor_device()
136 perror("Failed to close GPIO character device file"); in monitor_device()
144 fprintf(stderr, "Usage: gpio-event-mon [options]...\n" in print_usage()
145 "Listen to events on GPIO lines, 0->1 1->0\n" in print_usage()
146 " -n <name> Listen on GPIOs on a named device (must be stated)\n" in print_usage()
147 " -o <n> Offset of line to monitor (may be repeated)\n" in print_usage()
148 " -d Set line as open drain\n" in print_usage()
149 " -s Set line as open source\n" in print_usage()
150 " -r Listen for rising edges\n" in print_usage()
151 " -f Listen for falling edges\n" in print_usage()
152 " -w Report the wall-clock time for events\n" in print_usage()
153 " -t Report the hardware timestamp for events\n" in print_usage()
154 " -b <n> Debounce the line with period n microseconds\n" in print_usage()
155 " [-c <n>] Do <n> loops (optional, infinite loop if not stated)\n" in print_usage()
156 " -? This helptext\n" in print_usage()
159 "gpio-event-mon -n gpiochip0 -o 4 -r -f -b 10000\n" in print_usage()
173 struct gpio_v2_line_config config; in main() local
177 memset(&config, 0, sizeof(config)); in main()
178 config.flags = GPIO_V2_LINE_FLAG_INPUT; in main()
179 while ((c = getopt(argc, argv, "c:n:o:b:dsrfwt?")) != -1) { in main()
190 return -1; in main()
199 config.flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN; in main()
202 config.flags |= GPIO_V2_LINE_FLAG_OPEN_SOURCE; in main()
205 config.flags |= GPIO_V2_LINE_FLAG_EDGE_RISING; in main()
208 config.flags |= GPIO_V2_LINE_FLAG_EDGE_FALLING; in main()
211 config.flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME; in main()
214 config.flags |= GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE; in main()
218 return -1; in main()
223 attr = config.num_attrs; in main()
224 config.num_attrs++; in main()
226 gpiotools_set_bit(&config.attrs[attr].mask, i); in main()
227 config.attrs[attr].attr.id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE; in main()
228 config.attrs[attr].attr.debounce_period_us = debounce_period_us; in main()
233 return -1; in main()
235 if (!(config.flags & EDGE_FLAGS)) { in main()
238 config.flags |= EDGE_FLAGS; in main()
240 return monitor_device(device_name, lines, num_lines, &config, loops); in main()