Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp699194pxk; Sun, 30 Aug 2020 20:28:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzHuUkx0f9ExNP81RyQl4b4dRTk1etfb4Rvw5Xb5eYRPC0sbZBVwHcJAkEXDfhMHwjDBAv X-Received: by 2002:a17:906:64c6:: with SMTP id p6mr9920407ejn.348.1598844515198; Sun, 30 Aug 2020 20:28:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598844515; cv=none; d=google.com; s=arc-20160816; b=xTBU/t1GLekyWsNNUGOccq4nY4bjUmtSzSqy5FLHPGJq7IWEIcelDYL8KOdFEHWs1E dwAPsOafeKV/bCrh8Ib0ugS5+FnZmBb36Ex/garQvyTJkzrugnvNiUsdbG2ag2j/Ecp6 joW5XuSOKZ44iuv+laMhpFvpa2l6/he7O2RLneMBectd9Ozs5Zfxl+7oX7aSXQPImzif lcRMVuuJxFy1mkHGxObZNvqmxaH5DM2AV/ycjr6dgfAXUTEXyi8l/R1/6G8ShQsR0zwY GxG+DWQemT/xT7rJY9pK9gt0MYxHnZPviS75JlpUH866OkjHp2HzQp1DIihI8O1R3J6L AnUQ== 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=wCXVG50Sj16ifnrQkN6hwZgEyiPZkd+OwdZIcGtEj3vVlE5pOKwFjpVdgftRyOpsOQ 57bNeldgaZ9Sx4VMrT8uE+5qBojAlr773r6CeAdJc8zhKSRI9YkTnw4QalOuCxEa1D9J ELAGaW8VM9BL+YXEHT8D2DfmRc1Xh6CFQhGVx+1UFo4ae6URXryyEhNb14kacyH35aue asJIgB+8FMa6N56faiymqMB96DQzrSk+qwkLIHIddEmXT8WP+B6Fm73onSiku/hKsRoU FMF7QkOW7rGcM8X9ADfZY4fcj9qwr4VBwgn+1Sh7VBIXxCVtajZJZfKhlMumBmeWPhtM KXsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fNR51BXs; 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 l6si223261ejg.212.2020.08.30.20.28.12; Sun, 30 Aug 2020 20:28:35 -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=fNR51BXs; 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 S1727793AbgHaDYk (ORCPT + 99 others); Sun, 30 Aug 2020 23:24:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726692AbgHaDY2 (ORCPT ); Sun, 30 Aug 2020 23:24:28 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E44C7C061573; Sun, 30 Aug 2020 20:24:26 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id n3so1626308pjq.1; Sun, 30 Aug 2020 20:24:26 -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=fNR51BXs2wMFok4ZVdqa0Nb4sUxcciAu7rCZjasq3W0Sefg6Bh8K7c6FdhDbQwV86C mNzafYKQ4t2+UqDAt++gPHY+bJpVkff/E/TEwouJIFYxfXqplXxGeis/DfY/e8vIjSVL lg5Y5/0YEtxnmGbZRjljI7fK1EPaHwp9+cYQDYDcfp9+jcdy3lGimxrpBVBGsO3GVqul +wv599UgeenMXUUOhcDU8fhLLRubvLTt/R4a4Ku9ITyKPshuOgAg1qFwhVWbH6I/4+6i qHrJ6yfqS/ZS9Nc/RqTe4Kkfv+Ok5wfcb8MewXNOvY4H0ZAEnXHOvyOWZf/iWNunBjkY rAPg== 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=DHhUh08ywwLX0Cy6nQl0dI97DixvwFBP6ggf8eOs1X7V2UYyQRqkbcmCzScSr2PMZJ QlZooOMh19DiYH+JkBkLxp8sr8XAE2t/4Drm7MHy8BuJdwpJpJbZQwZGuQ5GiGtld5Ca CwZvuYDSPJbOg5/I4TWrmu0uR+Dggs4x14KbFWjBsSOjMZCJ79SkUPiownv5xS14DFfB IuCxkOJhLz8zDB3pCozZZ4/nDYfIn7+VXOSfCHFJA6BxW0URWZherdFQHpd4XBzqiSPI lUG1LrVbS4SiXv4wvE58KJYR/lbY+2haO+bleq7yU1DkK0n7bj1D8FWoBRoaOM73iIXe yblg== X-Gm-Message-State: AOAM5328+HBsC1tjGT/jWWSsaMEXjXss/JYuEDjc+NcTRc3cdY9i2E/Q zRfQx9ZuldxV5K+Qsj8F/JZM3cnmsDc= X-Received: by 2002:a17:902:8eca:: with SMTP id x10mr7174067plo.129.1598844262972; Sun, 30 Aug 2020 20:24:22 -0700 (PDT) Received: from sol.lan (106-69-184-100.dyn.iinet.net.au. [106.69.184.100]) by smtp.gmail.com with ESMTPSA id z17sm6095733pfq.38.2020.08.30.20.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 20:24:22 -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 v6 18/20] tools: gpio: port gpio-event-mon to v2 uAPI Date: Mon, 31 Aug 2020 11:20:04 +0800 Message-Id: <20200831032006.1019978-19-warthog618@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200831032006.1019978-1-warthog618@gmail.com> References: <20200831032006.1019978-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