From patchwork Wed Nov 24 11:42:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 517280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02AAAC433FE for ; Wed, 24 Nov 2021 11:43:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241726AbhKXLqR (ORCPT ); Wed, 24 Nov 2021 06:46:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241730AbhKXLqO (ORCPT ); Wed, 24 Nov 2021 06:46:14 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1539DC061714 for ; Wed, 24 Nov 2021 03:43:05 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id b12so3674281wrh.4 for ; Wed, 24 Nov 2021 03:43:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sS1opnsxYro85V5S3ivgztdl1gAyjYFuzaHv2So6/ZM=; b=ukqZb6Df8wk2BR7+RB3VNpoAiHEzybZ5wK7naDQW1uDkTqo/5SeXbH0bluZIgIK/y5 yHsVSJeCbWnimbjYDhksjDQEBETXtrudYf0Rluz5BIrua02DG0wrDv9v6qVpB07EQFCC HgiJtMXCKAQ5FxV2r15Xq9wFWV38uVKAktJ1CK9RmcskvqAZ+0FuM60ay0BS/7jXJBOn rO1P/jEIRTtoJMiz2A6DC2x4WA0BO7bGQ8JcfNtz3m7tf3lFrvS0HdQsK8u0wJAMcJfG 0FB6mmWh1sJJ54bScBM79u8uhThDWiNoGbBfp8GfZA7XVvBMoQICjkcAUX1X9Igd0FJ0 81jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sS1opnsxYro85V5S3ivgztdl1gAyjYFuzaHv2So6/ZM=; b=56J52e6nD7vwG7J8hoCB3FZumilkJVKWYlpnc4G8r5zT/QelWRBQqFr+5otybQVgnt elr/axjWT8sf6XibjQNsi7c7i4NwMno3K7Ac70CuhzgJzpB3sI8hMKLUF+Dx9Gq9xORE MjQ9fuIpNBWKIHABtg4SLOcX6bkXKqrstHbIh3VXzJ/qybeXJ46TZOzj3Hf16zQG4Ra+ wTc+9YvZDK0MxD9+nA6lR90RFINAznA1HFmLsPd8nJtRyPMYKm4F56QLE2Hh8ModQJgB vaBU/Lc72WNAeqO2Ps9+schb0Nj3GXtQSQUEFrMcktr9TxFkecgUOkpJv4SrlvU7fzRu BfEA== X-Gm-Message-State: AOAM530E0ZBk70wPAkm9HzOfuy8IyuP5Yst/LW62kPgZCWbxuG0xqdCK 5R+6tDF4jzzbY7jxf2gpy8zZ+A== X-Google-Smtp-Source: ABdhPJxKAZZnUDjolRDhLnzjAWh38EBmKg2rTlNyfnvjqE+5got5d7PmwHEdZRTCcGycM0SHq37agg== X-Received: by 2002:adf:f88f:: with SMTP id u15mr15957633wrp.18.1637754182346; Wed, 24 Nov 2021 03:43:02 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id s63sm5165173wme.22.2021.11.24.03.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 03:43:01 -0800 (PST) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Shuah Khan , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v10 1/5] gpiolib: provide gpiod_remove_hogs() Date: Wed, 24 Nov 2021 12:42:53 +0100 Message-Id: <20211124114257.19878-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211124114257.19878-1-brgl@bgdev.pl> References: <20211124114257.19878-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Currently all users of gpiod_add_hogs() call it only once at system init so there never was any need for a mechanism allowing to remove them. Now the upcoming gpio-sim will need to tear down chips with hogged lines so provide a function that allows to remove hogs. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 11 +++++++++++ include/linux/gpio/machine.h | 2 ++ 2 files changed, 13 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index abfbf546d159..22b98a590a88 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3540,6 +3540,17 @@ void gpiod_add_hogs(struct gpiod_hog *hogs) } EXPORT_SYMBOL_GPL(gpiod_add_hogs); +void gpiod_remove_hogs(struct gpiod_hog *hogs) +{ + struct gpiod_hog *hog; + + mutex_lock(&gpio_machine_hogs_mutex); + for (hog = &hogs[0]; hog->chip_label; hog++) + list_del(&hog->list); + mutex_unlock(&gpio_machine_hogs_mutex); +} +EXPORT_SYMBOL_GPL(gpiod_remove_hogs); + static struct gpiod_lookup_table *gpiod_find_lookup_table(struct device *dev) { const char *dev_id = dev ? dev_name(dev) : NULL; diff --git a/include/linux/gpio/machine.h b/include/linux/gpio/machine.h index d755e529c1e3..2647dd10b541 100644 --- a/include/linux/gpio/machine.h +++ b/include/linux/gpio/machine.h @@ -100,6 +100,7 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table); void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n); void gpiod_remove_lookup_table(struct gpiod_lookup_table *table); void gpiod_add_hogs(struct gpiod_hog *hogs); +void gpiod_remove_hogs(struct gpiod_hog *hogs); #else /* ! CONFIG_GPIOLIB */ static inline void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {} @@ -108,6 +109,7 @@ void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {} static inline void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {} static inline void gpiod_add_hogs(struct gpiod_hog *hogs) {} +static inline void gpiod_remove_hogs(struct gpiod_hog *hogs) {} #endif /* CONFIG_GPIOLIB */ #endif /* __LINUX_GPIO_MACHINE_H */ From patchwork Wed Nov 24 11:42:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 517279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7F8BC433EF for ; Wed, 24 Nov 2021 11:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241795AbhKXLq2 (ORCPT ); Wed, 24 Nov 2021 06:46:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241740AbhKXLqQ (ORCPT ); Wed, 24 Nov 2021 06:46:16 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 834D4C061748 for ; Wed, 24 Nov 2021 03:43:06 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id n33-20020a05600c502100b0032fb900951eso5120601wmr.4 for ; Wed, 24 Nov 2021 03:43:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2GWUpkiuXSzN66GVjCDh6suML+iAta4LGHtIvVqjGEk=; b=T+cTkrxv6yKl5R3DPzBZ5rm1juxysossHr8SGa9Egn+4js1aCjh/mq5jUVmTtYcgOa oBnOojqP/FqUb+TjQU0NiNcsgmHXlrwLnMI3fc/niQN58rVllNEQr2MmUbUyrflMpE2t 4p5iloXEX4Ily3XkMU0H55NejDjRn7+ce7Tx698Y7wJ5+3buzCuOnIvyM9wvvl3jPlJW o3rJ/oJ9z2uzxq2DIU6CUH8ZRfpAkKtUy7uI4ve2hRFND5rSkCWudW7KNCGTTMwzguYG d1Q0hqCHgd4Ebt2xUBCuDTlFlq81tQ8A+s/uS9LFm8WdcSbs4IozjJAxMxwfY5HoWiIz 4UKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2GWUpkiuXSzN66GVjCDh6suML+iAta4LGHtIvVqjGEk=; b=DFxFpfiWWMtwnSc1ZNqgsO46BXdJ6Z9wPx979DU2jnDT5HtsRVVOnGwEVv5fdFFqMN uKFFOw/b4T10tOUAQOa9YSTswzMfdDIIoA8IkOMdz1l72SkIMKYMVON0c4SN7xrm1f2B c2y4bG3kLwjD+iVGc8TtH8nzrOvhfZgBCpcOy/SjguWXXnBoWN+120PSt/R85MDc3LUW 7DCe9UjaLa5ml0JjfPeMqGI2mlSn2wrrmAtmeXUvgFE2rFTDPU7rh0Xzmci5/OH24IhZ 4hZVVP1H+oD2Nctj99RzVk2VxAC8sRBPijI7L1a5BgT4d49zTT+oi6uyRFHlYLRewrZl g0NQ== X-Gm-Message-State: AOAM5315dQlQH3Nm9S+hpnMQcCwf8TEW2ZhE/v9l1KGyDLvmh0MZCkyz iHEdxoc+Bgg8EhSiw56VVQFfqw== X-Google-Smtp-Source: ABdhPJyzuZxOeKbqLPfgN1DtJnd990r+dnzV69Kaaz8MyitgmqoBQ+cgJzwpjO86kM+SAUTfZ+SzOw== X-Received: by 2002:a7b:c756:: with SMTP id w22mr14900744wmk.34.1637754185100; Wed, 24 Nov 2021 03:43:05 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id s63sm5165173wme.22.2021.11.24.03.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 03:43:04 -0800 (PST) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Shuah Khan , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v10 3/5] selftests: gpio: provide a helper for reading chip info Date: Wed, 24 Nov 2021 12:42:55 +0100 Message-Id: <20211124114257.19878-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211124114257.19878-1-brgl@bgdev.pl> References: <20211124114257.19878-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 d7b312b44a62..a40b818c394e 100644 --- a/tools/testing/selftests/gpio/Makefile +++ b/tools/testing/selftests/gpio/Makefile @@ -2,7 +2,7 @@ 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 CFLAGS += -O2 -g -Wall -I../../../../usr/include/ 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..8f2d2e23e9f6 --- /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; +} From patchwork Wed Nov 24 11:42:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 517278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAE26C433EF for ; Wed, 24 Nov 2021 11:43:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241776AbhKXLqd (ORCPT ); Wed, 24 Nov 2021 06:46:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229923AbhKXLqR (ORCPT ); Wed, 24 Nov 2021 06:46:17 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 535BFC061758 for ; Wed, 24 Nov 2021 03:43:07 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id r8so3641120wra.7 for ; Wed, 24 Nov 2021 03:43:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sdC8L7KcajeuYgRxRzq/BDd9/Try3NuMaNKMjlQg9Bs=; b=JfQHaBeQHSrZ3rQZiqWsi9BL8YK2+nptrMjPCQoT0ouSL81Mp1dyq4OivxwIBmf/05 3m8nxt7MF1vEs9/Ew9m41Z4QJWjU75i1qWcefzNze5JdYdApVfenwAOIuVg4GLSR1W3D blgqLXRG7Wiw5/Q7VMDR7hJfyD+6Wbxr22bQYXzCPDr4nW/YiBMFtw1YeRJyzEq6iPb+ F1h2nZ7yXL64w4FPboiT3CdlUpvfw2YanraWyvO3NXkZV/dfs4xg5uwQuTHU+UdHqmyi ynLhKp6+ZMUrbfVx+qE6fy8MvCm3HC7wi9hnShE+GzM4iNeqSvm87oT/5n/I1B+1HB5P MktQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sdC8L7KcajeuYgRxRzq/BDd9/Try3NuMaNKMjlQg9Bs=; b=kOiEZbLaFrRWmAJbIH5JNdRmGAjknaq+6sHFNuRsLVy6uMLe1zcwcMyZ6oClqSQsW6 G5WgqXKxb7C7ry9P7v4wNYA9w2WKnHrzHgL/D9dpldVRIl+0MtwTtDJkmlUTWZ1UdZvE nlQ6KijImcCJxqb3JNK8+qtTR7XkL1IOcoXzDgRukOuCbCmOLEe1lEqjI/xVL6X067Am vGy9UYpKi85K7PNvdz4tbK62LonoWpRjMQi9zRPb9AUN6UG8TzlfiMaw2pu6DOmKPd6l jVgVJH7NleJhXDcNspr+/UGFH7EtslMsnW2fVOL6Cca++yeTEkgGLTjY7XEhTM2vb09L iCKw== X-Gm-Message-State: AOAM530U8CYYOuurAZR15qcsXPp5qsOVau1He69Cp7DsqaNGIpB3QT61 EQj9e70w1J1eRbKzMIvoyC/6yg== X-Google-Smtp-Source: ABdhPJxyPOtabszFxtmqMNt8tHaetSgoIQ7WYcSaBCCT9+/X2ptg2utUgV4syQmIjoYP6E73dul3Kw== X-Received: by 2002:a5d:6e82:: with SMTP id k2mr18242939wrz.147.1637754185908; Wed, 24 Nov 2021 03:43:05 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id s63sm5165173wme.22.2021.11.24.03.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Nov 2021 03:43:05 -0800 (PST) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Shuah Khan , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v10 4/5] selftests: gpio: add a helper for reading GPIO line names Date: Wed, 24 Nov 2021 12:42:56 +0100 Message-Id: <20211124114257.19878-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211124114257.19878-1-brgl@bgdev.pl> References: <20211124114257.19878-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add a simple program that allows to read GPIO line names from the 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-line-name.c | 55 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/gpio/gpio-line-name.c diff --git a/tools/testing/selftests/gpio/.gitignore b/tools/testing/selftests/gpio/.gitignore index 4ea4f58dab1a..ededb077a3a6 100644 --- a/tools/testing/selftests/gpio/.gitignore +++ b/tools/testing/selftests/gpio/.gitignore @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only gpio-mockup-cdev gpio-chip-info +gpio-line-name diff --git a/tools/testing/selftests/gpio/Makefile b/tools/testing/selftests/gpio/Makefile index a40b818c394e..293aa9749408 100644 --- a/tools/testing/selftests/gpio/Makefile +++ b/tools/testing/selftests/gpio/Makefile @@ -2,7 +2,7 @@ TEST_PROGS := gpio-mockup.sh TEST_FILES := gpio-mockup-sysfs.sh -TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name CFLAGS += -O2 -g -Wall -I../../../../usr/include/ include ../lib.mk diff --git a/tools/testing/selftests/gpio/gpio-line-name.c b/tools/testing/selftests/gpio/gpio-line-name.c new file mode 100644 index 000000000000..e635cfadbded --- /dev/null +++ b/tools/testing/selftests/gpio/gpio-line-name.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * GPIO character device helper for reading line names. + * + * Copyright (C) 2021 Bartosz Golaszewski + */ + +#include +#include +#include +#include +#include +#include +#include + +static void print_usage(void) +{ + printf("usage:\n"); + printf(" gpio-line-name \n"); +} + +int main(int argc, char **argv) +{ + struct gpio_v2_line_info info; + int fd, ret; + char *endp; + + 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)); + info.offset = strtoul(argv[2], &endp, 10); + if (*endp != '\0') { + print_usage(); + return EXIT_FAILURE; + } + + ret = ioctl(fd, GPIO_V2_GET_LINEINFO_IOCTL, &info); + if (ret) { + perror("line info ioctl failed"); + return EXIT_FAILURE; + } + + printf("%s\n", info.name); + + return EXIT_SUCCESS; +}