Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2668996pxk; Sun, 27 Sep 2020 17:34:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6XAkJs1X8SRf8g1Iz+/0rxOxTvf/cQBn5vTb70ZitWIeLibRZ8fk+X0kmQY4lNIXCEcr9 X-Received: by 2002:aa7:ca46:: with SMTP id j6mr12891670edt.155.1601253266327; Sun, 27 Sep 2020 17:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601253266; cv=none; d=google.com; s=arc-20160816; b=SxT5fqAL59VIvWT8r4IY/zYSBZxow+mz1rMWtWWvVlPW6cX+8ZuKfEnm8oNVMq9koJ BGGDQrewZhYw2Eqycxy1c6hncINzC3uXNHecDnQGrD6M76fdlvov5+E+UB0aGJISVL9E 6pd0xj0svIrJ28vQiTLS8jcd4hgv3Z/xzpE/EA6FoFtEnH+ht/kNiGwyT4EVy1IlQTmx SwEN/2Xq4ekZPEVU1lGsExZykZaQ/wSH/YTrjl9aMRXynEDackuHDLEv6SyovBPbl61z U68C0OnfRRBZ7ShAQZS2o61/GqJ1I3jRgaQ3sMZb8Q53/PCpbdolFmm3l5XMQ0PmxfsX r5RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6GGRqqsz5wRVNByVt8NrnlXsZyXGJptYx7CCapwCwqk=; b=Zy7daglDmn0JdVACPLgQt0SMpwgGQwcFWIwnVcWBChkQGRmUqY6xUxrXso5bfJBJta ZaLzGlWPC4ZfQUVPU+0FZXQZJefsBaITXk/hreX7rFNmrmrbz3SDkJL1jqsDPbxchscU j7HWD+xSGdJBzvt9ht7sG//8VZLkyEl/7dkTejuOfVEbK6eHNqB5vioOAYh2E86Gs9CQ S+MPnHvNBXvnlFbMW2EoWei0cZHr6RckFMkUKouiGvqvqofGSiDtSREmjNQZnV2CzuvU 3eS52gz45ZY6tQSKtALsaNsR1RQHFigdCaDBPyMmYOx6N34qTO7VFMNxvngT6kumJcdI veSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QXLjzW44; 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 p22si6921208edq.579.2020.09.27.17.34.04; Sun, 27 Sep 2020 17:34:26 -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=QXLjzW44; 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 S1726572AbgI1AcE (ORCPT + 99 others); Sun, 27 Sep 2020 20:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726328AbgI1AcE (ORCPT ); Sun, 27 Sep 2020 20:32:04 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17813C0613CE; Sun, 27 Sep 2020 17:32:04 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id b124so7735082pfg.13; Sun, 27 Sep 2020 17:32:04 -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=6GGRqqsz5wRVNByVt8NrnlXsZyXGJptYx7CCapwCwqk=; b=QXLjzW44CSWRKrbWbrzCAoMNG00RHtYJmSKeBQougut9ZoQZskxR3fSt2D+eE1ObKN BFpnglTL0mLcHugfgs2xrKWeyd3AAYMJP/m3lhziEiQAXSb+q5f1ukvQsMLetWkwNFaJ IOVJiPo+7yBYqSCaQFgH/a5lJgwZTSOA5NAxofANwFB90E7nlqpwQwnrHmYu3Yy+Njv4 5rXCWW7LRHap9+4iJThtC/lcdxzbSD6NrlYECWTVgFhUNr7s1w8t8NF4TH4xT4/YKC+R k3YuksdSUB/ca6n80WgrgFyHR+adBGvrFYXzIF+JBl8WSyrKkBKQbMljOwI1OGnr4IUF JwJQ== 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=6GGRqqsz5wRVNByVt8NrnlXsZyXGJptYx7CCapwCwqk=; b=J235b6KpafBPHjY+ibsLmU9qTch+dNxbxuFSYvlGFRC23e5xnim9BZLbBjjhF4BArM N1iFHzX9eSRaW5qPDCRRz16IfyRC6Yv3U0bfowXHKdEvBT4IMxg2w+hUVO2A4GIM+yUX Ix+soYtWMZJE+1jPdZ3z/CHD1GGMtZ/OD90lUAinJehePOTiNzWuNxjCvfS1a2hXEWRb v/sUYkabD3V/gF4InUbdrJlHaW5qjO96V6GMULYjyJgGPy/XiIObbJAiSXOTFU8uqPM1 kQs16+tyLUAZL5syxZmTx5eXVOzfBI343gQP0/EUgY5KXjT7hNb0UDHbUDRT7l59QZOz ElJA== X-Gm-Message-State: AOAM530+GBQwHQQWOqD956hbJlWiEdienr4pHsn/s2I/FzDf1A89dYvo HHxcmaIhY2vS7qeIhcaYl5FJHx384hADyw== X-Received: by 2002:a63:4c46:: with SMTP id m6mr6936216pgl.127.1601253123233; Sun, 27 Sep 2020 17:32:03 -0700 (PDT) Received: from sol.lan (106-69-171-132.dyn.iinet.net.au. [106.69.171.132]) by smtp.gmail.com with ESMTPSA id o20sm8443783pgh.63.2020.09.27.17.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 17:32:02 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org, andy.shevchenko@gmail.com, arnd@arndb.de Cc: Kent Gibson Subject: [PATCH v10 18/20] tools: gpio: port gpio-event-mon to v2 uAPI Date: Mon, 28 Sep 2020 08:28:05 +0800 Message-Id: <20200928002807.12146-19-warthog618@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200928002807.12146-1-warthog618@gmail.com> References: <20200928002807.12146-1-warthog618@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Andy Shevchenko --- 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..b230af889f26 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_ns, 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