Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1320538pxb; Thu, 4 Mar 2021 08:26:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3QTVyQ/QLltrsZdqOeKCMKX3N24LbJtvMhM1+9mFwyegVk1HCXpnhL5v531QSCBxrqYjW X-Received: by 2002:a17:906:22d2:: with SMTP id q18mr5166296eja.437.1614875195203; Thu, 04 Mar 2021 08:26:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614875195; cv=none; d=google.com; s=arc-20160816; b=hWms4mY59i4hW9VFJJBroZzC58sQWDwCJuQt0eljyPHkdI0HgqdGnK3WjOk0+CP806 k+CkKjW94TAnHn9utnRPRwLxjWpTkwrNZ9m+BNSXG3K55WObxSpk4T0TeewSgJoZWlZK PsACd9w/g8SDUi/xtRE0yJMohSOggs/etmw9Ox8WbJpnpy1IiU9t+ZaRfayBm0HMsLfN Dpmk8/7wBF9Am8ZvtuB/orLRROMfWwH1c+Z5M9E3qaUxP8vlR5RA9sN91nR73lqipYt3 TkgReeM73UbZXcQPku4Vgtl0HjDzWBUpQX63zYhy52ygRPaHNThTuZsdy+XCqCqfaxlp 87wA== 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=5N+MBnaBVQGCO/pRFImYa4+XMDd5iqbeG7mNtUIosOw=; b=jjUZd3z7rvy/bgMzDTWNquBLkj6dCewqvdkm9Ro0OAXvfHOX6FGbrUoGUvV+StddSc Qi+EOcmCv0ZaCHGetpSbuZGpOQ/6/+oBbNZrnlMipwUMeNMhuXKWLQqChL9MlVl+oOIa 6ghUnk1SmYPIA2DSF7U5ruEZlNwjUfNgAlfEiMX/CA08VfgQaU7ABv/I+ufxch3x9zFy hASXW6gb0pXSKEAd9wnQEyEzACqVW3Ck7vVvxpXW1f5x6ZRHYF2dHyi0fB1ORUqV1u80 mrSLCdxnzWgQ8yujG9aQUcrvUIOu6OibNVJkTtqhXKVJgrLYiC5WCMKZrjOR/DPvVNmo Xokg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=gHpN5klU; 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 v2si14890411ejg.251.2021.03.04.08.26.12; Thu, 04 Mar 2021 08:26:35 -0800 (PST) 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=gHpN5klU; 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 S238688AbhCDKcc (ORCPT + 99 others); Thu, 4 Mar 2021 05:32:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238669AbhCDKcJ (ORCPT ); Thu, 4 Mar 2021 05:32:09 -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 E684CC0613F0 for ; Thu, 4 Mar 2021 02:30:15 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id o2so8608349wme.5 for ; Thu, 04 Mar 2021 02:30:15 -0800 (PST) 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=5N+MBnaBVQGCO/pRFImYa4+XMDd5iqbeG7mNtUIosOw=; b=gHpN5klU7JQxNonCvCtMPp1igK591qAoysgQeeGZdcjlrws6Bp58/0R1uU1wAPHPEh 12xujkbkBQ1YDhyNQPmjh9HvqXy+74U4WRbaRhbKa/j9spySctNtmDhDu2ssrfIUj2sX NNcV2f1gfs1RyJR9h3pwB8jqsghUh/THuhF8/V6pvQO+adFFB9wQ25RF4xdFJueJOYtq HraM02Ebds+0qONLE4N8lxu770LXGqZWtdZ5uY5sYZeAy/ces5SNSbDE+OHklyyXD1UA a9vtBKQ6eclmRKm/jQ03RWVL4TTkp1ptuaxrpRJLn306h6FWQRxDlvPetAhRxdpL3FDn OGzw== 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=5N+MBnaBVQGCO/pRFImYa4+XMDd5iqbeG7mNtUIosOw=; b=B2Bd5rotn97qiAtkNqgAN20DYd+EAUqx0ATD8NiVZEQAFHB1yUjMP12vIO+mhgx1i7 9FORpJ6+KkOeMHHViS7azskFtYOCOPxwHpTUrZG4PZY2SjuSgPvQQo23oJeOnM+4WSWd jgMN4AmPyiRg7fjtCVHAkSXau/Yr3CJnV0btDJ7KmhLUVEH71CbLACrKrYZitipXOJCm VG1AaNlOjw+YGfqeEZvtBPrY7cZgHnr7dnukuOhEWY3PahQZUuGZY7FRqPN0hoN63ueB VFU2/veCtQBo/1M5cA8VVXQsKYHhVy7vp4xL/MzuXtTan4KbmqBP+NvlkQLkZ0if2iCj J1yQ== X-Gm-Message-State: AOAM5337+VdW3Quf6RsP0yUV5Z60gkCGIjPgPndxYsp6e71P0ehKfBvZ UCSeZ19O+UZqOGxoEvnVpoAHAw== X-Received: by 2002:a05:600c:3550:: with SMTP id i16mr3222940wmq.170.1614853814702; Thu, 04 Mar 2021 02:30:14 -0800 (PST) Received: from debian-brgl.home (amarseille-656-1-4-167.w90-8.abo.wanadoo.fr. [90.8.158.167]) by smtp.gmail.com with ESMTPSA id f7sm35501854wre.78.2021.03.04.02.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 02:30:14 -0800 (PST) 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 Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 10/12] selftests: gpio: provide a helper for reading chip info Date: Thu, 4 Mar 2021 11:24:50 +0100 Message-Id: <20210304102452.21726-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210304102452.21726-1-brgl@bgdev.pl> References: <20210304102452.21726-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.29.1