Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3136878pxf; Mon, 15 Mar 2021 02:18:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf1GJxg9pbZis/cYWaQvHdorH+OfeqUIX/Vhghoe3QgPYxJN6Fqn1aphtB9xRbUjVwvxA5 X-Received: by 2002:a05:6402:181a:: with SMTP id g26mr28741946edy.225.1615799901934; Mon, 15 Mar 2021 02:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615799901; cv=none; d=google.com; s=arc-20160816; b=jNdNSJTfh2E94HVE9cYnR56iDDgd5obASvuhTX52lN2VTmp4LrOlm1tPDUkNyreV0C r+quNe/+eo+ETkMCv0njcG0weSSMClGoQaQ6i6bPE8QL2+dBHoZPJmRe7IeiL+lU+3oJ ugMzrS/8+vyrryMrJYqqd3UVY2oOO0zGoDi+EDXM6astp5tcbB82D9XwyWopKL0q5I3f 9hMoJ3cPfqLPH/DJpNI6VL1BScnBgyWg2FY/5YFGta3m/AH0ieB7HN8jBQzXNCOnP9Vk jpBZEikyOhbH9pJBcFsjYzGoW7bN1LIJSVKp8w4cZBm2dhO96pNTJ8gmm3IZ9KLVzV4i NHqQ== 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=aInBliwrC9dHKGFsbWV5Kx8fY6sxq6tzoBmO7q92930=; b=QB4FweGVt13yQSffnUzgnqFMjjGlT8KrscIjZzrLRxySaEKwY4jdDBCxcTC68dH9Ub ei04nmhAeDQ7fPZEcpoD2pJqHh4w0Ykxj7+xQA4A6bC58gbil1GSZxQ25/0mefhWnxk3 8nTCFvSIvoEXpQskAiT/2u7nEJPIZlXoyEL55AgbXOCiTxwyV9VGjqcGSIhUQvQPEt7R EGXP+TszR/ftUhjFjdBuBUw+U9HRpMy170W+MnFkKfDuUDzeEB99KB4pMzJzDH1IphSd B6Mjp2m2vxP6E1DMtGkqxTwIN0PsHrcBuvyllE63xDJe7+hkf8/nzefQ6y2oHNJ8zX5o 6mQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="SV7lh/y4"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lu7si10489069ejb.27.2021.03.15.02.17.59; Mon, 15 Mar 2021 02:18:21 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="SV7lh/y4"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbhCOJOo (ORCPT + 99 others); Mon, 15 Mar 2021 05:14:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbhCOJOV (ORCPT ); Mon, 15 Mar 2021 05:14:21 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 227A7C0613D8 for ; Mon, 15 Mar 2021 02:14:20 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so18991690wmi.3 for ; Mon, 15 Mar 2021 02:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aInBliwrC9dHKGFsbWV5Kx8fY6sxq6tzoBmO7q92930=; b=SV7lh/y43e26RRrPn+oAiAANr1HwfGFqwXIUJ3gGvEE7qVlA9xm/nRgUkZvfFeT5J1 h2XyXh+cttDEYXFHmMbx+mWK+mMU2sqdnHZhpH9AHx51oTu2arazwxvL/eBiOUJR30ti UdTZnzvGVbprBD0Of4kCYvar3xWGCkttSYOpmJDHFQ6xnpo1kLsHJnS5FJE8E4B9/AGG 31C8D69oRcIMDvvOEK/QSxyf5RAnDUvIvCV/bdvlkvlBVFR9MlBZPt83ibglfPT1KnH7 B0SylZFrdOS/njB49WkwW56i/Zd2cvKDgpEXRb05d5nRkkRNBTzgF4ZMZYQM6eWrogCp vf8Q== 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=aInBliwrC9dHKGFsbWV5Kx8fY6sxq6tzoBmO7q92930=; b=QJ5M/aLvUIdGp9kOuU9rcLGkvjXylLFS+DyYWNde6YQxrzfrMEwl6Gh1htdE3yOxXJ 3jDCBybcU7ehJhvlYOXttCW2rglbc3zwuURrH4br/BCvj9DhiLsTfHovp/5FMJGl82gt qD322VzyoZFXLAuqDqfEonBelWF4U3bOuxQCML9E9N+wcehjgDa02I0j2nc9Psv7TacX 3hYxlk/QCyQnBZUJYSDXyKT3P43IxxBYpsQfKgMqBRJ/g+wkpZwjGXiq1mn6gAEqbsEK hucFO3LkXivodWNDP2rgXKaUY+/aujH0PzfCrmNSW+UlRg4IXJH2oRbH1XhSz2OjymXl qk0g== X-Gm-Message-State: AOAM5302YXtMGM8YhgmkmdBvnfLRkyjHM7Ck1uh/uTl5lFrH2Ybx6bjA akexV1Edyt5NksrBRNsEGTYKDw== X-Received: by 2002:a1c:5416:: with SMTP id i22mr25017102wmb.146.1615799659587; Mon, 15 Mar 2021 02:14:19 -0700 (PDT) Received: from debian-brgl.home (lfbn-nic-1-149-6.w2-15.abo.wanadoo.fr. [2.15.231.6]) by smtp.gmail.com with ESMTPSA id z3sm17978822wrw.96.2021.03.15.02.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 02:14:19 -0700 (PDT) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig , Shuah Khan , Linus Walleij , Andy Shevchenko , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Geert Uytterhoeven , Kent Gibson , Jonathan Corbet , Greg Kroah-Hartman Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v5 09/11] selftests: gpio: provide a helper for reading chip info Date: Mon, 15 Mar 2021 10:13:58 +0100 Message-Id: <20210315091400.13772-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210315091400.13772-1-brgl@bgdev.pl> References: <20210315091400.13772-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski Add a simple program that allows to retrieve chip properties from the GPIO character device. This will be used in gpio-sim selftests. Signed-off-by: Bartosz Golaszewski --- tools/testing/selftests/gpio/.gitignore | 1 + tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/gpio-chip-info.c | 57 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/gpio/gpio-chip-info.c diff --git a/tools/testing/selftests/gpio/.gitignore b/tools/testing/selftests/gpio/.gitignore index a4969f7ee020..4ea4f58dab1a 100644 --- a/tools/testing/selftests/gpio/.gitignore +++ b/tools/testing/selftests/gpio/.gitignore @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only gpio-mockup-cdev +gpio-chip-info diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile index 39f2bbe8dd3d..84b48547f94c 100644 --- a/tools/testing/selftests/gpio/Makefile +++ b/tools/testing/selftests/gpio/Makefile @@ -2,6 +2,6 @@ TEST_PROGS := gpio-mockup.sh TEST_FILES := gpio-mockup-sysfs.sh -TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info include ../lib.mk diff --git a/tools/testing/selftests/gpio/gpio-chip-info.c b/tools/testing/selftests/gpio/gpio-chip-info.c new file mode 100644 index 000000000000..4d26fa7c254a --- /dev/null +++ b/tools/testing/selftests/gpio/gpio-chip-info.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * GPIO character device helper for reading chip information. + * + * Copyright (C) 2021 Bartosz Golaszewski + */ + +#include +#include +#include +#include +#include +#include +#include + +static void print_usage(void) +{ + printf("usage:\n"); + printf(" gpio-chip-info [name|label|num-lines]\n"); +} + +int main(int argc, char **argv) +{ + struct gpiochip_info info; + int fd, ret; + + if (argc !=3) { + print_usage(); + return EXIT_FAILURE; + } + + fd = open(argv[1], O_RDWR); + if (fd < 0) { + perror("unable to open the GPIO chip"); + return EXIT_FAILURE; + } + + memset(&info, 0, sizeof(info)); + ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &info); + if (ret) { + perror("chip info ioctl failed"); + return EXIT_FAILURE; + } + + if (strcmp(argv[2], "name") == 0) { + printf("%s\n", info.name); + } else if (strcmp(argv[2], "label") == 0) { + printf("%s\n", info.label); + } else if (strcmp(argv[2], "num-lines") == 0) { + printf("%u\n", info.lines); + } else { + fprintf(stderr, "unknown command: %s\n", argv[2]); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} -- 2.30.1