diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2024-04-04 13:15:26 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2024-04-05 12:15:58 +0200 |
commit | e268186d8051163a7406fb4cf58f06349665e830 (patch) | |
tree | ff416c75a883507b0993a8e5d7aa0d881521cae4 | |
parent | c1bb8f33009e69f2c83d5963278bcf26d88cf819 (diff) | |
download | barebox-e268186d8051.tar.gz barebox-e268186d8051.tar.xz |
aiodev: add helper for getting a value by its channel name
It's a common pattern to get an aiochannel by name and the value
afterwards. Add a helper for this pattern.
Link: https://lore.barebox.org/20240404111527.2083308-1-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/aiodev/core.c | 12 | ||||
-rw-r--r-- | include/aiodev.h | 9 |
2 files changed, 21 insertions, 0 deletions
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 |