Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * gpio-event-mon - monitor GPIO line events from userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2016 Linus Walleij
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Usage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	gpio-event-mon -n <device-name> -o <offset>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <stdbool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <dirent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <getopt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <sys/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include "gpio-utils.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) int monitor_device(const char *device_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		   unsigned int *lines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		   unsigned int num_lines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		   struct gpio_v2_line_config *config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		   unsigned int loops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct gpio_v2_line_values values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	char *chrdev_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int cfd, lfd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	ret = asprintf(&chrdev_name, "/dev/%s", device_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	cfd = open(chrdev_name, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (cfd == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		ret = -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		fprintf(stderr, "Failed to open %s\n", chrdev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		goto exit_free_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ret = gpiotools_request_line(device_name, lines, num_lines, config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				     "gpio-event-mon");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		goto exit_device_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		lfd = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	/* Read initial states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	values.mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	values.bits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	for (i = 0; i < num_lines; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		gpiotools_set_bit(&values.mask, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	ret = gpiotools_get_values(lfd, &values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		fprintf(stderr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			"Failed to issue GPIO LINE GET VALUES IOCTL (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		goto exit_line_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (num_lines == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		fprintf(stdout, "Monitoring line %d on %s\n", lines[0], device_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		fprintf(stdout, "Initial line value: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			gpiotools_test_bit(values.bits, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		fprintf(stdout, "Monitoring lines %d", lines[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		for (i = 1; i < num_lines - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			fprintf(stdout, ", %d", lines[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		fprintf(stdout, " and %d on %s\n", lines[i], device_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		fprintf(stdout, "Initial line values: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			gpiotools_test_bit(values.bits, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		for (i = 1; i < num_lines - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			fprintf(stdout, ", %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 				gpiotools_test_bit(values.bits, i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		fprintf(stdout, " and %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			gpiotools_test_bit(values.bits, i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		struct gpio_v2_line_event event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		ret = read(lfd, &event, sizeof(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		if (ret == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			if (errno == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 				fprintf(stderr, "nothing available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				ret = -errno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				fprintf(stderr, "Failed to read event (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 					ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (ret != sizeof(event)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			fprintf(stderr, "Reading event failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		fprintf(stdout, "GPIO EVENT at %" PRIu64 " on line %d (%d|%d) ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			(uint64_t)event.timestamp_ns, event.offset, event.line_seqno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			event.seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		switch (event.id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		case GPIO_V2_LINE_EVENT_RISING_EDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			fprintf(stdout, "rising edge");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		case GPIO_V2_LINE_EVENT_FALLING_EDGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			fprintf(stdout, "falling edge");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			fprintf(stdout, "unknown event");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		fprintf(stdout, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if (i == loops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) exit_line_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (close(lfd) == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		perror("Failed to close line file");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) exit_device_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (close(cfd) == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		perror("Failed to close GPIO character device file");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) exit_free_name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	free(chrdev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) void print_usage(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	fprintf(stderr, "Usage: gpio-event-mon [options]...\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		"Listen to events on GPIO lines, 0->1 1->0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		"  -n <name>  Listen on GPIOs on a named device (must be stated)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		"  -o <n>     Offset of line to monitor (may be repeated)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		"  -d         Set line as open drain\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		"  -s         Set line as open source\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		"  -r         Listen for rising edges\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		"  -f         Listen for falling edges\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		"  -b <n>     Debounce the line with period n microseconds\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		" [-c <n>]    Do <n> loops (optional, infinite loop if not stated)\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		"  -?         This helptext\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		"\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		"Example:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		"gpio-event-mon -n gpiochip0 -o 4 -r -f -b 10000\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #define EDGE_FLAGS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	(GPIO_V2_LINE_FLAG_EDGE_RISING | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 GPIO_V2_LINE_FLAG_EDGE_FALLING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	const char *device_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	unsigned int lines[GPIO_V2_LINES_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned int num_lines = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	unsigned int loops = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct gpio_v2_line_config config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int c, attr, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	unsigned long debounce_period_us = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	memset(&config, 0, sizeof(config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	config.flags = GPIO_V2_LINE_FLAG_INPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	while ((c = getopt(argc, argv, "c:n:o:b:dsrf?")) != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		switch (c) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		case 'c':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			loops = strtoul(optarg, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		case 'n':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			device_name = optarg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		case 'o':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			if (num_lines >= GPIO_V2_LINES_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				print_usage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			lines[num_lines] = strtoul(optarg, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			num_lines++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		case 'b':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			debounce_period_us = strtoul(optarg, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		case 'd':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			config.flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		case 's':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			config.flags |= GPIO_V2_LINE_FLAG_OPEN_SOURCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		case 'r':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			config.flags |= GPIO_V2_LINE_FLAG_EDGE_RISING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		case 'f':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			config.flags |= GPIO_V2_LINE_FLAG_EDGE_FALLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		case '?':
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			print_usage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (debounce_period_us) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		attr = config.num_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		config.num_attrs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		for (i = 0; i < num_lines; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			gpiotools_set_bit(&config.attrs[attr].mask, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		config.attrs[attr].attr.id = GPIO_V2_LINE_ATTR_ID_DEBOUNCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		config.attrs[attr].attr.debounce_period_us = debounce_period_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (!device_name || num_lines == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		print_usage();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (!(config.flags & EDGE_FLAGS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		printf("No flags specified, listening on both rising and "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		       "falling edges\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		config.flags |= EDGE_FLAGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return monitor_device(device_name, lines, num_lines, &config, loops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }