Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2668775pxk; Sun, 27 Sep 2020 17:33:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPtHRnSGqCkt4mDTT2byzGubPb/aDuNu3alFenKR50W/eUu078hztIbo8gOoFs8c9b+kuC X-Received: by 2002:aa7:c1c3:: with SMTP id d3mr13257749edp.228.1601253230125; Sun, 27 Sep 2020 17:33:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601253230; cv=none; d=google.com; s=arc-20160816; b=nLAfqH04zpV3WQzSdgPTOKt1+Ed3bzyc/QbJWebxmsmZj6fsa6+uhqsxqAAPeqPDKm xbkf/LdaOpemW+v4JFcysxwXtQQT204pCapF7aBrdUqKb1w3Q2Wt51qIQCKlmKDcn6K/ mReS2HkKJaRS+VRhnsOmFoeDnsunpgp7WfANsBU+q4MY179gXuoCnCFS37aTtF2JpBP6 1SYnn4hiO2W3GWo6Foui6mql5IEtQnOFnqmt7pREhOEj5yi9lBhTvdHY1cINQWE0K6hG QuS99Meu8o+HvLzBeZKQqEOAgicDJv8HH+4LpcAVx2ckRE/wRmBO4JK5kuYOIqLw5sDR 69yQ== 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=Ys6wqSQYuQoXYJfJn/Rp0bUM9O0PtZUuVhMhadizOSw=; b=Rp8NqT+dlM7RRejHyEA1YVpPOzpIGivX7CL54pyV3o8luix1e3CnpsCW7FK3mxWBPD sbZ48MFAUcqHPDFlQHhaY9VPCZScDZxWrnYGW8MJTJFXzvNSK8jUuEY4mreKjB43S59S Xs007kSpfg8fos4RFTcuQdvtwz5eg8bHqdjYyjO4b2F5HSdyLdkgHkNELm78oVktW0BQ WsnmbZV8Znz2A2YApGS+1ZkG/Y4fIyrXWxsi2/GPRSGNjU1HbRVW7XIPzGbxh99BHjcH sGEj04mBu9SX+t+8fMMmIkvRBTl1MR1gA3buOxBIUu2htL04uupsE4btp6daiPwnJ8o3 Qw2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Yy9gkOH+; 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 g23si7041653edv.304.2020.09.27.17.33.27; Sun, 27 Sep 2020 17:33:50 -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=Yy9gkOH+; 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 S1726721AbgI1Ab2 (ORCPT + 99 others); Sun, 27 Sep 2020 20:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726387AbgI1Ab2 (ORCPT ); Sun, 27 Sep 2020 20:31:28 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 565CEC0613CE; Sun, 27 Sep 2020 17:31:28 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id k13so7782709pfg.1; Sun, 27 Sep 2020 17:31:28 -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=Ys6wqSQYuQoXYJfJn/Rp0bUM9O0PtZUuVhMhadizOSw=; b=Yy9gkOH+K0pXLd6dtmxD+1HGK/QC5Z5JL18LOqnq2QHgB+dFfMv34JS8laS3rP52jn s9Xh9fpMz+xfGrw2SEXpO8+w8wZHeiHCqEIhzuXnwEqa5RqawLhB6XR33OIhdnn/Ctdl TWUpNCV6+glqmQtoEv+HbaNrgsNd3/+RyTRRwv1FV6iznvvpTDuM90wp8H6DjnUlwXOi sZsXkyvWx2abLRHw7G4ELki8mLtC8JfPdDvDTGS14roqaliNS0ADqPA6TMRSDBN3EUbJ KOs1Dws7TUMz5xC6pNv8hUiGGObLI+hQdKzqpe3WDItTEkiRh7+0f6oD8d0WfqeBPwPm zViQ== 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=Ys6wqSQYuQoXYJfJn/Rp0bUM9O0PtZUuVhMhadizOSw=; b=pcp9cZL72br2Iiir3onRvtIPT4FcqgOfZsrBD6GoaYUDZsR9yEtl1hKGFOm5/qgmPD MpALQOjIHm+3qHwaw/wEgMj/bjE7yWoTSeKH3peJ2TIXrS//LBz8kXfGQXw4GKALS7AV G5hp0HDJsshOSKGRH1unVoN9TNDdtjZoIyxKnze43sUbjZsN8XwT//r9fh+YuOFAfmzn bSHccb3gZCpG6GgCsZk8kHw5SKQxvD2YKmpIC/1ASShu5rJPpNTW4tyojzl5scItte2l dykXHbJkE9enNiK7jX2xuCQMMfuscwsbpgiv67i0kiHM1BOpMfWlyXs9VauhCaKnw20u aGvw== X-Gm-Message-State: AOAM531f/0W4IQfruKS6EpqbvC9VvvfM3fZ8v4Udj/kYydR16Ufw38B5 MW961lN7/bQ5WYTil1hkei/f4dtBnAiqxQ== X-Received: by 2002:a62:8c88:0:b029:13e:d13d:a08b with SMTP id m130-20020a628c880000b029013ed13da08bmr8824851pfd.34.1601253087516; Sun, 27 Sep 2020 17:31:27 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 17:31:26 -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 14/20] tools: gpio: port lsgpio to v2 uAPI Date: Mon, 28 Sep 2020 08:28:01 +0800 Message-Id: <20200928002807.12146-15-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 lsgpio tool to the latest GPIO uAPI. Signed-off-by: Kent Gibson Reviewed-by: Andy Shevchenko --- tools/gpio/lsgpio.c | 60 ++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/tools/gpio/lsgpio.c b/tools/gpio/lsgpio.c index b08d7a5e779b..5a05a454d0c9 100644 --- a/tools/gpio/lsgpio.c +++ b/tools/gpio/lsgpio.c @@ -25,57 +25,73 @@ struct gpio_flag { char *name; - unsigned long mask; + unsigned long long mask; }; struct gpio_flag flagnames[] = { { - .name = "kernel", - .mask = GPIOLINE_FLAG_KERNEL, + .name = "used", + .mask = GPIO_V2_LINE_FLAG_USED, + }, + { + .name = "input", + .mask = GPIO_V2_LINE_FLAG_INPUT, }, { .name = "output", - .mask = GPIOLINE_FLAG_IS_OUT, + .mask = GPIO_V2_LINE_FLAG_OUTPUT, }, { .name = "active-low", - .mask = GPIOLINE_FLAG_ACTIVE_LOW, + .mask = GPIO_V2_LINE_FLAG_ACTIVE_LOW, }, { .name = "open-drain", - .mask = GPIOLINE_FLAG_OPEN_DRAIN, + .mask = GPIO_V2_LINE_FLAG_OPEN_DRAIN, }, { .name = "open-source", - .mask = GPIOLINE_FLAG_OPEN_SOURCE, + .mask = GPIO_V2_LINE_FLAG_OPEN_SOURCE, }, { .name = "pull-up", - .mask = GPIOLINE_FLAG_BIAS_PULL_UP, + .mask = GPIO_V2_LINE_FLAG_BIAS_PULL_UP, }, { .name = "pull-down", - .mask = GPIOLINE_FLAG_BIAS_PULL_DOWN, + .mask = GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN, }, { .name = "bias-disabled", - .mask = GPIOLINE_FLAG_BIAS_DISABLE, + .mask = GPIO_V2_LINE_FLAG_BIAS_DISABLED, }, }; -void print_flags(unsigned long flags) +static void print_attributes(struct gpio_v2_line_info *info) { int i; - int printed = 0; + const char *field_format = "%s"; for (i = 0; i < ARRAY_SIZE(flagnames); i++) { - if (flags & flagnames[i].mask) { - if (printed) - fprintf(stdout, " "); - fprintf(stdout, "%s", flagnames[i].name); - printed++; + if (info->flags & flagnames[i].mask) { + fprintf(stdout, field_format, flagnames[i].name); + field_format = ", %s"; } } + + if ((info->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) && + (info->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING)) + fprintf(stdout, field_format, "both-edges"); + else if (info->flags & GPIO_V2_LINE_FLAG_EDGE_RISING) + fprintf(stdout, field_format, "rising-edge"); + else if (info->flags & GPIO_V2_LINE_FLAG_EDGE_FALLING) + fprintf(stdout, field_format, "falling-edge"); + + for (i = 0; i < info->num_attrs; i++) { + if (info->attrs[i].id == GPIO_V2_LINE_ATTR_ID_DEBOUNCE) + fprintf(stdout, ", debounce_period=%dusec", + info->attrs[0].debounce_period_us); + } } int list_device(const char *device_name) @@ -109,18 +125,18 @@ int list_device(const char *device_name) /* Loop over the lines and print info */ for (i = 0; i < cinfo.lines; i++) { - struct gpioline_info linfo; + struct gpio_v2_line_info linfo; memset(&linfo, 0, sizeof(linfo)); - linfo.line_offset = i; + linfo.offset = i; - ret = ioctl(fd, GPIO_GET_LINEINFO_IOCTL, &linfo); + ret = ioctl(fd, GPIO_V2_GET_LINEINFO_IOCTL, &linfo); if (ret == -1) { ret = -errno; perror("Failed to issue LINEINFO IOCTL\n"); goto exit_close_error; } - fprintf(stdout, "\tline %2d:", linfo.line_offset); + fprintf(stdout, "\tline %2d:", linfo.offset); if (linfo.name[0]) fprintf(stdout, " \"%s\"", linfo.name); else @@ -131,7 +147,7 @@ int list_device(const char *device_name) fprintf(stdout, " unused"); if (linfo.flags) { fprintf(stdout, " ["); - print_flags(linfo.flags); + print_attributes(&linfo); fprintf(stdout, "]"); } fprintf(stdout, "\n"); -- 2.28.0