openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Joel Stanley <joel@jms.id.au>
To: Bartosz Golaszewski <brgl@bgdev.pl>, linux-gpio@vger.kernel.org
Cc: Andrew Jeffery <andrew@aj.id.au>,
	openbmc@lists.ozlabs.org, Zev Weiss <zweiss@equinix.com>
Subject: [libgpiod PATCH 2/7] tools: Add line name to offset lookup helper
Date: Thu,  3 Feb 2022 14:51:29 +1030	[thread overview]
Message-ID: <20220203042134.68425-3-joel@jms.id.au> (raw)
In-Reply-To: <20220203042134.68425-1-joel@jms.id.au>

line_names_to_offsets to be used by tools that support --by-name.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 tools/tools-common.c | 22 ++++++++++++++++++++++
 tools/tools-common.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/tools/tools-common.c b/tools/tools-common.c
index c83e68a2c1e4..958933ed6d51 100644
--- a/tools/tools-common.c
+++ b/tools/tools-common.c
@@ -204,3 +204,25 @@ struct gpiod_chip *chip_by_line_name(const char *name)
 	return NULL;
 }
 
+int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
+			  unsigned int *offsets, int num_lines)
+{
+	int i;
+
+	for (i = 0; i < num_lines; i++) {
+		const char *line_name = lines[i];
+		int offset;
+
+		offset = gpiod_chip_find_line(chip, line_name);
+
+		if (offset < 0) {
+			die("chip '%s' does not contain line '%s'",
+					gpiod_chip_get_name(chip),
+					line_name);
+		}
+
+		offsets[i] = offset;
+	}
+
+	return 0;
+}
diff --git a/tools/tools-common.h b/tools/tools-common.h
index 5ed37dc05885..7affea436a60 100644
--- a/tools/tools-common.h
+++ b/tools/tools-common.h
@@ -32,5 +32,7 @@ int chip_dir_filter(const struct dirent *entry);
 struct gpiod_chip *chip_open_by_name(const char *name);
 struct gpiod_chip *chip_open_lookup(const char *device);
 struct gpiod_chip *chip_by_line_name(const char *name);
+int line_names_to_offsets(struct gpiod_chip *chip, char **lines,
+			  unsigned int *offsets, int num_lines);
 
 #endif /* __GPIOD_TOOLS_COMMON_H__ */
-- 
2.34.1


  parent reply	other threads:[~2022-02-03  4:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03  4:21 [libgpiod PATCH 0/7] tools: Add by-name support Joel Stanley
2022-02-03  4:21 ` [libgpiod PATCH 1/7] tools: Clean up scandir memory allocations Joel Stanley
2022-02-08 11:21   ` Bartosz Golaszewski
2022-02-03  4:21 ` Joel Stanley [this message]
2022-02-03  4:21 ` [libgpiod PATCH 3/7] tools: Add value support to line name lookup Joel Stanley
2022-02-03  8:37   ` Zev Weiss
2022-02-03  4:21 ` [libgpiod PATCH 4/7] tools: gpioget: Add by-name support Joel Stanley
2022-02-03  8:37   ` Zev Weiss
2022-02-03  4:21 ` [libgpiod PATCH 5/7] tools: gpioset: " Joel Stanley
2022-02-03  8:37   ` Zev Weiss
2022-02-03  4:21 ` [libgpiod PATCH 6/7] gpio-tools-test: Add gpioset --by-name tests Joel Stanley
2022-02-03  4:21 ` [libgpiod PATCH 7/7] gpio-tools-test: Add gpioget " Joel Stanley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220203042134.68425-3-joel@jms.id.au \
    --to=joel@jms.id.au \
    --cc=andrew@aj.id.au \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@vger.kernel.org \
    --cc=openbmc@lists.ozlabs.org \
    --cc=zweiss@equinix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).