Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3626375pxa; Sun, 9 Aug 2020 06:29:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqeR6KYf6AKo7oWse2t17wFN6te+1lrP+lgjEPxe8Fqj0vH5TXZS8+ZWyBW74pzSU5TDlV X-Received: by 2002:a17:906:12d8:: with SMTP id l24mr5900572ejb.260.1596979783742; Sun, 09 Aug 2020 06:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596979783; cv=none; d=google.com; s=arc-20160816; b=q/6Eg5u2NFKvvPc/a+ZZZG4QEjurnvuNTe8dGrPtYNqg3yHS3QCXXLrZJcn83sGXfv HlQJ6aq6oxgsADsxXCvDY9iL/W9HyybckZ/nvH0hntvJn6nB4oLliB9ZVg51zEVrnLWu fBuh4N0RFms/GK1ZqRa7ONXqHL18gOa8hN1AVeT7ZSA0rwlT1aAaZpjktqL5AMQlUf7C bvJ3qxpi/0K7oilxXcAWIq8F7DaPC6Z2jWMFU0hqPGhsX8ncK41B3PVa0XqhsxEHOfl9 6z1J2sCc9XbH3sntvGpmsOt1NERb08ZZApqv79ezegRUYg7o8qLCn7wiaos6h8nJI4TW Y2aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NHFesHMh8urOzDGLF3BG3WK3USIsA8bYlNdGJPsk5Ng=; b=x9pVn2n4KgUUvLNs4I5PaDcuOJ94c42ME/XfelIs7CwD/jKYTsoqSWvfYTiNXyD7B9 44+ChZ9yIjirHc9a9WGMmuD/zNPnjQbe8JMa34ZOAWWUP3unZiMPrn8s8at+QGAfZNAn wJoYgVIDB6OOMPYcfDFkjZW/b87BCkg2VcLrkftJoLsF13ao4uo+9z+kdXx/uVm5SVXs wRkN3glUkBRM+V9XCkSN6TawvVKVMkNGS8CvQsmQa2EEKNkCkppI5k2ITsMAZMbouNpo vZENvZAXcy3wPyN6CLCCuwebU2IQP40dpJSe0quenjCNf1eOCiMGW5puhCetuju6ROqc GC3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HUR0M0HF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qw20si9021000ejb.371.2020.08.09.06.29.20; Sun, 09 Aug 2020 06:29:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HUR0M0HF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbgHIN17 (ORCPT + 99 others); Sun, 9 Aug 2020 09:27:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbgHIN16 (ORCPT ); Sun, 9 Aug 2020 09:27:58 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECE4FC061756; Sun, 9 Aug 2020 06:27:57 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id d19so3444142pgl.10; Sun, 09 Aug 2020 06:27:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NHFesHMh8urOzDGLF3BG3WK3USIsA8bYlNdGJPsk5Ng=; b=HUR0M0HF+VqWVTiAcJl6wS/ocDQrZQ+qRlo+JSLwGVMrJCIoWufnfFs2SzBuNxNkoI CtBDErmabcOXxhmMn4s/yGZEAwS9kLpxRqCblDQKOchdrJ/7ObvahluiUoClKWZHxBfZ LJEDk9QUNBi0tRyKJZs5zNg0ioosRfzaGOgTx3lKVx0NvdDJboWbMlzuC2NGM5h9mggi VwnAoUsZj0VZsWxoe0auViA8RMCQMxG7tMIZjfrpeB8jjaHwUIt/FUGiAqEn4CxCsdIP e/repdos03uXZX2F6hFVRQWWuxPZ0OmJohxwMTE1Dfjzzh+9QAFktalXuebtdzEgolx2 J7Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NHFesHMh8urOzDGLF3BG3WK3USIsA8bYlNdGJPsk5Ng=; b=O2QOe01YBINo2m7DdP2KyegLGJ3azBejbHOVKPskeGIeGN+SYRzvSjYeQxJpRAPSYk it/MH6FgQRaB8fm5gZdtWwYX7w+V8R8aMGamA/8YoQpMlRceS3VWS2m9vi3vg/H9bU3G clpDj/lF+j/yeuLUr/lZAaFHXvpfWhPwR0jBY7V4o5tOKX5Ok6Qp7PdReSssVWy1DDWY RRjC08QZTGFbVMOzMpvmlW7txcDy6SSUe04IBG7H4wDS3Xm0ooe7rpbvImnROtY+sVN3 PqQOhXVYJ2TjetzF7HzAPs4TrVMqmRYP1KO0xPx+uIQPIpe6cNB85yZQ09gequLwaL9o qNEQ== X-Gm-Message-State: AOAM530/0D3YR6a0o8AYcMHU6c5OX5Ccr6d38yQBNcmyGFg+5PNMi824 FvkeMB0FUZiz1h20v61Y1eSJSOjy X-Received: by 2002:a62:8105:: with SMTP id t5mr21520333pfd.94.1596979676270; Sun, 09 Aug 2020 06:27:56 -0700 (PDT) Received: from sol.lan (106-69-185-93.dyn.iinet.net.au. [106.69.185.93]) by smtp.gmail.com with ESMTPSA id j10sm9127414pff.171.2020.08.09.06.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2020 06:27:55 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH v3 16/18] tools: gpio: port gpio-event-mon to v2 uAPI Date: Sun, 9 Aug 2020 21:25:27 +0800 Message-Id: <20200809132529.264312-17-warthog618@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200809132529.264312-1-warthog618@gmail.com> References: <20200809132529.264312-1-warthog618@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Port the gpio-event-mon tool to the latest GPIO uAPI. Signed-off-by: Kent Gibson --- tools/gpio/gpio-event-mon.c | 91 +++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c index 1a303a81aeef..d6a831200c18 100644 --- a/tools/gpio/gpio-event-mon.c +++ b/tools/gpio/gpio-event-mon.c @@ -23,17 +23,16 @@ #include #include #include +#include "gpio-utils.h" int monitor_device(const char *device_name, unsigned int line, - uint32_t handleflags, - uint32_t eventflags, + struct gpio_v2_line_config *config, unsigned int loops) { - struct gpioevent_request req; - struct gpiohandle_data data; + struct gpio_v2_line_values values; char *chrdev_name; - int fd; + int cfd, lfd; int ret; int i = 0; @@ -41,44 +40,39 @@ int monitor_device(const char *device_name, if (ret < 0) return -ENOMEM; - fd = open(chrdev_name, 0); - if (fd == -1) { + cfd = open(chrdev_name, 0); + if (cfd == -1) { ret = -errno; fprintf(stderr, "Failed to open %s\n", chrdev_name); goto exit_free_name; } - req.lineoffset = line; - req.handleflags = handleflags; - req.eventflags = eventflags; - strcpy(req.consumer_label, "gpio-event-mon"); - - ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, &req); - if (ret == -1) { - ret = -errno; - fprintf(stderr, "Failed to issue GET EVENT " - "IOCTL (%d)\n", - ret); - goto exit_close_error; - } + ret = gpiotools_request_line(device_name, &line, 1, config, + "gpio-event-mon"); + if (ret < 0) + goto exit_device_close; + else + lfd = ret; /* Read initial states */ - ret = ioctl(req.fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); - if (ret == -1) { - ret = -errno; - fprintf(stderr, "Failed to issue GPIOHANDLE GET LINE " - "VALUES IOCTL (%d)\n", + values.mask = 1; + values.bits = 0; + ret = gpiotools_get_values(lfd, &values); + if (ret < 0) { + fprintf(stderr, + "Failed to issue GPIO LINE GET VALUES IOCTL (%d)\n", ret); - goto exit_close_error; + goto exit_line_close; } fprintf(stdout, "Monitoring line %d on %s\n", line, device_name); - fprintf(stdout, "Initial line value: %d\n", data.values[0]); + fprintf(stdout, "Initial line value: %d\n", + gpiotools_test_bit(values.bits, 0)); while (1) { - struct gpioevent_data event; + struct gpio_v2_line_event event; - ret = read(req.fd, &event, sizeof(event)); + ret = read(lfd, &event, sizeof(event)); if (ret == -1) { if (errno == -EAGAIN) { fprintf(stderr, "nothing available\n"); @@ -96,12 +90,14 @@ int monitor_device(const char *device_name, ret = -EIO; break; } - fprintf(stdout, "GPIO EVENT %llu: ", event.timestamp); + fprintf(stdout, "GPIO EVENT at %llu on line %d (%d|%d) ", + event.timestamp, event.offset, event.line_seqno, + event.seqno); switch (event.id) { - case GPIOEVENT_EVENT_RISING_EDGE: + case GPIO_V2_LINE_EVENT_RISING_EDGE: fprintf(stdout, "rising edge"); break; - case GPIOEVENT_EVENT_FALLING_EDGE: + case GPIO_V2_LINE_EVENT_FALLING_EDGE: fprintf(stdout, "falling edge"); break; default: @@ -114,8 +110,11 @@ int monitor_device(const char *device_name, break; } -exit_close_error: - if (close(fd) == -1) +exit_line_close: + if (close(lfd) == -1) + perror("Failed to close line file"); +exit_device_close: + if (close(cfd) == -1) perror("Failed to close GPIO character device file"); exit_free_name: free(chrdev_name); @@ -140,15 +139,20 @@ void print_usage(void) ); } +#define EDGE_FLAGS \ + (GPIO_V2_LINE_FLAG_EDGE_RISING | \ + GPIO_V2_LINE_FLAG_EDGE_FALLING) + int main(int argc, char **argv) { const char *device_name = NULL; unsigned int line = -1; unsigned int loops = 0; - uint32_t handleflags = GPIOHANDLE_REQUEST_INPUT; - uint32_t eventflags = 0; + struct gpio_v2_line_config config; int c; + memset(&config, 0, sizeof(config)); + config.flags = GPIO_V2_LINE_FLAG_INPUT; while ((c = getopt(argc, argv, "c:n:o:dsrf?")) != -1) { switch (c) { case 'c': @@ -161,16 +165,16 @@ int main(int argc, char **argv) line = strtoul(optarg, NULL, 10); break; case 'd': - handleflags |= GPIOHANDLE_REQUEST_OPEN_DRAIN; + config.flags |= GPIO_V2_LINE_FLAG_OPEN_DRAIN; break; case 's': - handleflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE; + config.flags |= GPIO_V2_LINE_FLAG_OPEN_SOURCE; break; case 'r': - eventflags |= GPIOEVENT_REQUEST_RISING_EDGE; + config.flags |= GPIO_V2_LINE_FLAG_EDGE_RISING; break; case 'f': - eventflags |= GPIOEVENT_REQUEST_FALLING_EDGE; + config.flags |= GPIO_V2_LINE_FLAG_EDGE_FALLING; break; case '?': print_usage(); @@ -182,11 +186,10 @@ int main(int argc, char **argv) print_usage(); return -1; } - if (!eventflags) { + if (!(config.flags & EDGE_FLAGS)) { printf("No flags specified, listening on both rising and " "falling edges\n"); - eventflags = GPIOEVENT_REQUEST_BOTH_EDGES; + config.flags |= EDGE_FLAGS; } - return monitor_device(device_name, line, handleflags, - eventflags, loops); + return monitor_device(device_name, line, &config, loops); } -- 2.28.0