Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp75433pxa; Thu, 13 Aug 2020 20:08:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrQ5fvhd9M/3TWqUigLvdtqMLPcOQBxqEN75UFXB6lmO22m7D1T+4Olc2/6xoZqiCduJnL X-Received: by 2002:a17:906:2490:: with SMTP id e16mr503982ejb.386.1597374531438; Thu, 13 Aug 2020 20:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597374531; cv=none; d=google.com; s=arc-20160816; b=Zbn+hdX6UJJM1hXOvpwjqDZokXP6AsZrSMYw+RHd9509Tempr9M37LkQ2A0Qg46zm2 fyBCZbP9ESwcPCamPNUxfCJaV7WYeAJshmwOJjUzD1/8BG/iJ7EE8qx6q2/nnnIK5ZSp JUzyAJ140JbX+VjD9HrVUhJBvBQfqyZWNCvoBhdU4bdyheXCSWJJuvggMSZHmARNG175 7pniTaBI7R5N2sGvlecwFvyq3c8LB51crWzbevcgde7AcGFQSR5oR9XnplNrmQR98Ki5 znaroOTxbysYznXWXCUOA+hagVCOoZTgHlhFWeZX/Ld5xom9sS8Dg5D7kAOL9odzgYf8 xbnQ== 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=ADP2aGUDRbAJ2fzGJ4u2MgmoEkak0G6DX7jqH1kdmdo=; b=zCFKXqyIIqHlMxQ7tLKWsz5fgVCPn7xRkfoPOmyMqfmyXcMm6WUDYfsLi4g4y0Meph MZWROSYwcpgDrfgo6X4fd9Tf9J4l6+uEhUWUQnOFGdgDCw3K8QrBACnF3wcoMMuQR1d2 PYpbrJQ6LrtmAUPTrDMBVOE35crLYub4wCKtkO3/s6UUtjMgWuFCFOgKJD7fOhZSBasS R7hTKq7aRRggm4PT0jqMcU7zJUoueK37tFreHy9ke+VKvGH5VizbW/E+g1x+loBWXuE8 TgYSEO43M5oJ/BV5wF+oXlaorRJkZENQAioIOvj2ozJDhOWSX4zuCxiN4kd9mSW0iT6E mVMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mRKdgiqs; 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 b35si4914024edf.41.2020.08.13.20.08.28; Thu, 13 Aug 2020 20:08:51 -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=mRKdgiqs; 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 S1726690AbgHNDFV (ORCPT + 99 others); Thu, 13 Aug 2020 23:05:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726576AbgHNDFV (ORCPT ); Thu, 13 Aug 2020 23:05:21 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D222C061757; Thu, 13 Aug 2020 20:05:21 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id mw10so3723931pjb.2; Thu, 13 Aug 2020 20:05:21 -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=ADP2aGUDRbAJ2fzGJ4u2MgmoEkak0G6DX7jqH1kdmdo=; b=mRKdgiqs07vkxxjTqsAjH/48JLLsLSlgnk86cInqgmM2qtR3OFBEIImGHr7cnPmOWo bH98bVfbHz3ZEmpoiSkgX9pCscgED2r5H7SKU6axAQ+5g/1HaYWSaeZDNB7FD5JlgFqw FCyLt6VkzxW+4yHrbJ6OnXWTV9DhrF5cJywLHuToFVjpjDhczNCqGlPBFMb3nF8baeFc ymKJu3V5r/awDaDY8pTojRjd/A1d2xyj2mea54AZcPG8E7TnSxzyThEaZu1Kdc0u4lTU Op3E/C/xuHu4X59/M3bqHHCS90P25Ox3E5j6axdMB7oWbIrBTDmi/TIC6Z5F16NrV7QM ihBg== 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=ADP2aGUDRbAJ2fzGJ4u2MgmoEkak0G6DX7jqH1kdmdo=; b=hPAqdLROZkdyFBRDbO2ITSk6zky1EVPkYQ2938qvjvUjfSMnrEKKCF2KB0/HTuTsp9 UTAxz0adzTB1FhFq60VIoZ86QbOd+62QFLaDzWQxN51KRPcpmDR+NpvPxcQZwIAEdbVD KFlbcU05RQqoDwI5ykzPgfzciJBFltKRvi+DC5vpuE1nlgaER2kdhTZCXqsaMEMrm0dr GBLfuaFJV+ypMTTjHDnCkntcyTQyldSlP9vasRy/TAbE3cQvlztNekMGLmboyJA51XPQ puqdGIugILetnuuKm+FkPdUSwbiZ/sRoMOtK2AV1A5dE+y2/pZ0h+wuwpFSuP5Pcu7SJ xzlQ== X-Gm-Message-State: AOAM531XGMmWlyOkN+IL6lFhwtfcdDc4ADgzqY1x3PwiilZiJjoPrB5b 5Qgu810tx2ER0yaYsjlOI1POPSda X-Received: by 2002:a17:902:30d:: with SMTP id 13mr563880pld.251.1597374320266; Thu, 13 Aug 2020 20:05:20 -0700 (PDT) Received: from sol.lan (106-69-161-64.dyn.iinet.net.au. [106.69.161.64]) by smtp.gmail.com with ESMTPSA id z3sm6522231pgk.49.2020.08.13.20.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 20:05:19 -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 v4 14/20] tools: gpio: port lsgpio to v2 uAPI Date: Fri, 14 Aug 2020 11:02:51 +0800 Message-Id: <20200814030257.135463-15-warthog618@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200814030257.135463-1-warthog618@gmail.com> References: <20200814030257.135463-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 lsgpio tool to the latest GPIO uAPI. Signed-off-by: Kent Gibson --- 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..deda38244026 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); + } } 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