mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH v2 1/2] aiodev: add helper for getting a value by its channel name
Date: Thu,  4 Apr 2024 13:15:26 +0200	[thread overview]
Message-ID: <20240404111527.2083308-1-s.hauer@pengutronix.de> (raw)

It's a common pattern to get an aiochannel by name and the value
afterwards. Add a helper for this pattern.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/aiodev/core.c | 12 ++++++++++++
 include/aiodev.h      |  9 +++++++++
 2 files changed, 21 insertions(+)

diff --git a/drivers/aiodev/core.c b/drivers/aiodev/core.c
index 1fbb7b9188..5bdc4d83d4 100644
--- a/drivers/aiodev/core.c
+++ b/drivers/aiodev/core.c
@@ -73,6 +73,18 @@ int aiochannel_get_value(struct aiochannel *aiochan, int *value)
 }
 EXPORT_SYMBOL(aiochannel_get_value);
 
+int aiochannel_name_get_value(const char *chname, int *value)
+{
+	struct aiochannel *aio;
+
+	aio = aiochannel_by_name(chname);
+	if (IS_ERR(aio))
+		return PTR_ERR(aio);
+
+	return aiochannel_get_value(aio, value);
+}
+EXPORT_SYMBOL(aiochannel_name_get_value);
+
 int aiochannel_get_index(struct aiochannel *aiochan)
 {
 	return aiochan->index;
diff --git a/include/aiodev.h b/include/aiodev.h
index 56bd2da9f5..fb0807ad42 100644
--- a/include/aiodev.h
+++ b/include/aiodev.h
@@ -47,4 +47,13 @@ static inline const char *aiochannel_get_unit(struct aiochannel *aiochan)
 extern struct list_head aiodevices;
 #define for_each_aiodevice(aiodevice) list_for_each_entry(aiodevice, &aiodevices, list)
 
+#ifdef CONFIG_AIODEV
+int aiochannel_name_get_value(const char *chname, int *value);
+#else
+static inline int aiochannel_name_get_value(const char *chname, int *value)
+{
+	return -EOPNOTSUPP;
+}
+#endif
+
 #endif
-- 
2.39.2




             reply	other threads:[~2024-04-04 11:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-04 11:15 Sascha Hauer [this message]
2024-04-04 11:15 ` [PATCH v2 2/2] arm: boards: Add support for protonic-mecsbc board Sascha Hauer
2024-04-05 10:16 ` [PATCH v2 1/2] aiodev: add helper for getting a value by its channel name Sascha Hauer

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=20240404111527.2083308-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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