From patchwork Tue Oct 19 14:49:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1543363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20210112.gappssmtp.com header.i=@bgdev-pl.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=w6uHQL5v; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4HYc9D1bFjz9sPf for ; Wed, 20 Oct 2021 01:50:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229930AbhJSOwT (ORCPT ); Tue, 19 Oct 2021 10:52:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232993AbhJSOv7 (ORCPT ); Tue, 19 Oct 2021 10:51:59 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7D65C061778 for ; Tue, 19 Oct 2021 07:49:27 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id n7-20020a05600c4f8700b00323023159e1so3010428wmq.2 for ; Tue, 19 Oct 2021 07:49:27 -0700 (PDT) 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=1XGPFAB413i4NSgL53tMC4PneOe4C16/1HV5Loq6Wys=; b=w6uHQL5vqQCji9G+ri4M9Q+I8/ekCJHK+jxn2lWYC0Vi5KIJzR2yUA75KLlPCT9HFW C/k8UvbNj9chJVGD5Z5c/GJzM3EDpCE5bGudA/v7G+vCky3HUjS21R2WogfOBH3fmYGD toAlVgAgCa5qWcI6fdHx+PBtlUytpSHaGnqU/oDKzsK8bCGBexFDgoHTyaIrPr2jDsWu CNfma84raWM1gPjDW46oZ2qiRJTUZ71CfyeVpsDKl7znRgWbX6MQgjrSibRjWLHEvh5P BSJ/eHw19ULjg43dXXQACHfAzfdx0K6ePWmm5RQ/3Iuvzzcym94BTR0APaGrQREEXoEO cT4Q== 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=1XGPFAB413i4NSgL53tMC4PneOe4C16/1HV5Loq6Wys=; b=z+Jn7Hh6ekxJraQgXrMozbj8NItDGV5HXPWWOtyDUVPT6tfsgw+16s4m2EMOfEYPM7 8+vSVeUPpavR3F4gKYXrRt4vpOnnYCsLewQNsV7OtGGfZjpF1/FpIWj+cchwS/zd95Mc mrobZ9h2KInWG/g4iVDKLuJI3XnzYBNo0fUJGo7pkSpSwVhlYHrG654uZgCRl47sEgC6 o4SDDqoNteaisnq2NSu97gAHOgh5Obt0lcsM8DFVJNqgjglgqpf7BKDuRAHyPWgZoCFr C4KOX3lKh9hz8lF7w/T0pD/VgMTe7mUlrsfbkiL1ixJVs0wHNVD01b7c9Qu8+usG62TO 0S4A== X-Gm-Message-State: AOAM533n0qPhsK/S+Y+oCXwnXbOPoir8KwHjLramaIhJr/GCHjmJgwHQ AaVeWpMlQQkjTIe0H9IQZzxNUA== X-Google-Smtp-Source: ABdhPJwCw/E836aCH+H3r4OCPKcANKqHPiQnM9sryLL8Ntef1GEXSRKYAzlVpxR8T75DV9Pvou25EA== X-Received: by 2002:a05:600c:b43:: with SMTP id k3mr6478367wmr.142.1634654966505; Tue, 19 Oct 2021 07:49:26 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id j1sm16212752wrd.28.2021.10.19.07.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Oct 2021 07:49:26 -0700 (PDT) From: Bartosz Golaszewski To: Joel Becker , Christoph Hellwig , Shuah Khan , Linus Walleij , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , Geert Uytterhoeven , Kent Gibson , Jonathan Corbet , Greg Kroah-Hartman , Al Viro , Jack Winch , Viresh Kumar Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v8 7/8] selftests: gpio: add a helper for reading GPIO line names Date: Tue, 19 Oct 2021 16:49:08 +0200 Message-Id: <20211019144909.21959-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211019144909.21959-1-brgl@bgdev.pl> References: <20211019144909.21959-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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 84b48547f94c..d7d8f1985d99 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 gpio-chip-info +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name 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..a52e75bc37ba --- /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; +}