From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDAF1C433EF for ; Fri, 8 Oct 2021 08:18:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6E7461038 for ; Fri, 8 Oct 2021 08:18:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234364AbhJHIT4 (ORCPT ); Fri, 8 Oct 2021 04:19:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233823AbhJHITp (ORCPT ); Fri, 8 Oct 2021 04:19:45 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6054AC061766 for ; Fri, 8 Oct 2021 01:17:50 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id r10so27144883wra.12 for ; Fri, 08 Oct 2021 01:17:50 -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=RRLokZD/JzyOrQQERF9ZVv3TJYiF2A/gea/eW+3tWFo=; b=Oti/1/AxoJNyVgcDKym+is0D+kccGWhwTNBeX9bxjPQSNONvqmDYiLOD5Oez8LBAWX v/bV8klnRwH35TWQlSsm+jmg9IhEHURNccQ86STSg1C0WHkX2N4EzZGaBd+BXRkCGcRP lbQkwlR7GZnNWmh1dZ0nt5LfI/Fa9tebZaVPD84daEDlIucNZtc0S1L9YV/yuYKlXsBP qzo0YiRCBbH9MXiKp2wAXlLsa8i4bp2dCug7SRkPzB8UNeK4IWqIdKBfhneUUzy+lq9Q 5+NzAJ+/zb7sK0ZXm6xDEA9X8BFZ3RhdWZTzeJZd4Eqp2W9VBrp00HLe8wzD4mwfuGnu m24A== 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=RRLokZD/JzyOrQQERF9ZVv3TJYiF2A/gea/eW+3tWFo=; b=SFIhukYXZ9f9LkUZqFOHwWN5z8ku/tCL32Wl1yTVnKQgAMtuwsa7I6XYIPWiAjI5AV T65b9j2jwAOJBYOsQASHb9c3sZurjX592LXEGM4jQlSxVzCWRWBZdHbBAD0o1NcjGfg1 4780s72rcF43piK3up2GT5p738viPglrS6zhmOadbgHIyWfB5XkhUnjwog114AVKOtyD 9vx1qkE+Jvh54vo0Z0NMUyfrQWpdLPnEODYqm5JG1RHo7QJnY7WJi9SOH6AaZEzlQabl FUmFp9gMYwlLF0dznrfbCgzPwZ1OlyLhVr51+miDIX4L5QAz4H+Yb3C7wCmjEYi20lnM Cx/Q== X-Gm-Message-State: AOAM530Qvbw9myi+wImOWJHUxWQDGqUcCmQEPZdtncnX3rs2V+iQEJbk /b0tjfsKGGQ8a1JSsIdZXaiElA== X-Google-Smtp-Source: ABdhPJyaFynlO5iLIOCrxTcP/NINtKd7/P0E6lhkCd7ZO1InRR6QWYnSdyPrUjkGBAM5NpfFjzPXkA== X-Received: by 2002:a05:6000:144e:: with SMTP id v14mr2273926wrx.228.1633681068681; Fri, 08 Oct 2021 01:17:48 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id i3sm1759530wrn.34.2021.10.08.01.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 01:17:48 -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 , 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 v7 6/8] selftests: gpio: provide a helper for reading chip info Date: Fri, 8 Oct 2021 10:17:37 +0200 Message-Id: <20211008081739.26807-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211008081739.26807-1-brgl@bgdev.pl> References: <20211008081739.26807-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-gpio@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 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