From patchwork Tue Dec 7 09:34:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1564581 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=ywb/DmW9; 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 4J7Zrs4KM9z9s3q for ; Tue, 7 Dec 2021 20:34:53 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234064AbhLGJiW (ORCPT ); Tue, 7 Dec 2021 04:38:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233954AbhLGJhx (ORCPT ); Tue, 7 Dec 2021 04:37:53 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2568C061D60 for ; Tue, 7 Dec 2021 01:34:22 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id t18so4236343wrg.11 for ; Tue, 07 Dec 2021 01:34:22 -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=ywb/DmW9k6t7O2nSfBss1kAD/tJ2j9LcPL3LXT5/Ycmw3gSdTmnwizCmIq0pFx1Puw TRNtvD6lB/dgAsNSyxOoYTfNK/WYMBbZZh4phWFmCDiRdfquO2Yij4B2M7Bnsh3lIcuU +rVdt52t+mh/EVjJ7KsDTUbdn4ITAFvWkirLg/VQ2Qo27FceSNxsMIBw1yVw1RMRRgbv wg1+GjLy8JT8L5ug2VqX9XbVasorxa6carY6e08QRVrWneCr1XDCbkVl/asxha/lkQlg URsmFGZencZN48okTTt7dNI8pTZdogdZ+F/rM80IJz7tRq4Ntd/8llvhoPiB7wXSsT8s p8NQ== 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=qXkvIcO61Pwgo6icBo3+5ExD64CNLq86Dwbf4YlHGHjDQyGp14fBI3wZtmX8vmVmTl KnK93N75OH/9wWlLPzL2Lv9YnP6/tJvwX4sERX8FZ80GjJGdTUzRaHtK/R5DhIyjzYy9 y5W8+TsnLwz4xuQ86w808jdneF8uPKwebTfJK+mirOMAEVB0OcYTQEomw8Ii4dyq0VJe n4OXdNuJI8fTxnW86D0sPZbM+ApSprtLiVaFGY3NI8idMSI15yOttoAvda3PUPPL4FKI VS80fkMfdKBFfD/pQ+U656SIa9hQAHoeWaDvlv/eAoSgbmWKV5NEfCqV0yV0q2vUmZGs KBNQ== X-Gm-Message-State: AOAM533/m7Taj/xM+yJInNsHMxzCvJ8rUJXWk74+qtJ28QUIp1vvLKWK NA2lKRULZo6TZtHa+y751jpiSw== X-Google-Smtp-Source: ABdhPJwH8GOKljrwzOPGSQTb4LlbveMpYEF876ncfAs3wgLia74zk2iGOPhFf/x0ELT9pvQPTmp3zw== X-Received: by 2002:a5d:4a85:: with SMTP id o5mr49389284wrq.109.1638869661378; Tue, 07 Dec 2021 01:34:21 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id k13sm13783291wri.6.2021.12.07.01.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 01:34:21 -0800 (PST) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Shuah Khan , Geert Uytterhoeven , Viresh Kumar Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v13 6/7] selftests: gpio: add a helper for reading GPIO line names Date: Tue, 7 Dec 2021 10:34:11 +0100 Message-Id: <20211207093412.27833-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211207093412.27833-1-brgl@bgdev.pl> References: <20211207093412.27833-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 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; +}