From: Chris Morgan <macroalpha82@gmail.com>
To: linux-pm@vger.kernel.org
Cc: linux-iio@vger.kernel.org, andre.przywara@arm.com,
lee@kernel.org, wens@csie.org, sre@kernel.org, lars@metafoo.de,
jic23@kernel.org, Chris Morgan <macromorgan@hotmail.com>
Subject: [PATCH 1/2] iio: core: Add devm_ API for iio_channel_get_sys
Date: Tue, 10 Dec 2024 16:48:58 -0600 [thread overview]
Message-ID: <20241210224859.58917-2-macroalpha82@gmail.com> (raw)
In-Reply-To: <20241210224859.58917-1-macroalpha82@gmail.com>
From: Chris Morgan <macromorgan@hotmail.com>
Some kernel drivers use the IIO framework to get voltage and current
data via ADC or IIO HW driver. This is complicated by the fact that
the consumer of this data is not a child of the IIO HW which current
helpers depend on being the case.
Add resource managed version (devm_*) of the APIs so that the client
driver can call by name alone for the iio channel.
Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
drivers/iio/inkern.c | 18 ++++++++++++++++++
include/linux/iio/consumer.h | 20 ++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 136b225b6bc8..5df9e272743f 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -418,6 +418,24 @@ struct iio_channel *devm_iio_channel_get(struct device *dev,
}
EXPORT_SYMBOL_GPL(devm_iio_channel_get);
+struct iio_channel *devm_iio_channel_get_sys(struct device *dev,
+ const char *channel_name)
+{
+ struct iio_channel *channel;
+ int ret;
+
+ channel = iio_channel_get_sys(NULL, channel_name);
+ if (IS_ERR(channel))
+ return channel;
+
+ ret = devm_add_action_or_reset(dev, devm_iio_channel_free, channel);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return channel;
+}
+EXPORT_SYMBOL_GPL(devm_iio_channel_get_sys);
+
struct iio_channel *devm_fwnode_iio_channel_get_by_name(struct device *dev,
struct fwnode_handle *fwnode,
const char *channel_name)
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
index 333d1d8ccb37..bde075b5fb65 100644
--- a/include/linux/iio/consumer.h
+++ b/include/linux/iio/consumer.h
@@ -64,6 +64,26 @@ void iio_channel_release(struct iio_channel *chan);
*/
struct iio_channel *devm_iio_channel_get(struct device *dev,
const char *consumer_channel);
+
+/**
+ * devm_iio_channel_get_sys() - Resource managed version of
+ iio_channel_get_sys().
+ * @dev: Pointer to consumer device. Device name must match
+ * the name of the device as provided in the iio_map
+ * with which the desired provider to consumer mapping
+ * was registered.
+ * @consumer_channel: Unique name to identify the channel on the consumer
+ * side. This typically describes the channels use within
+ * the consumer. E.g. 'battery_voltage'
+ *
+ * Returns a pointer to negative errno if it is not able to get the iio channel
+ * otherwise returns valid pointer for iio channel.
+ *
+ * The allocated iio channel is automatically released when the device is
+ * unbound.
+ */
+struct iio_channel *devm_iio_channel_get_sys(struct device *dev,
+ const char *consumer_channel);
/**
* iio_channel_get_all() - get all channels associated with a client
* @dev: Pointer to consumer device.
--
2.43.0
next prev parent reply other threads:[~2024-12-10 22:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 22:48 [PATCH 0/2] Fix Regression with AXP20X for 6.13-rc1 Chris Morgan
2024-12-10 22:48 ` Chris Morgan [this message]
2024-12-10 22:48 ` [PATCH 2/2] power: supply: axp20x: Use devm_iio_channel_get_sys() for iio chans Chris Morgan
2024-12-11 21:58 ` [PATCH 0/2] Fix Regression with AXP20X for 6.13-rc1 Jonathan Cameron
2024-12-11 22:06 ` Jonathan Cameron
2024-12-16 18:01 ` Chris Morgan
2024-12-16 18:04 ` Chen-Yu Tsai
2025-03-04 18:18 ` Chris Morgan
2025-03-04 23:29 ` Jonathan Cameron
2025-03-06 2:19 ` Chris Morgan
2025-03-08 17:11 ` Jonathan Cameron
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=20241210224859.58917-2-macroalpha82@gmail.com \
--to=macroalpha82@gmail.com \
--cc=andre.przywara@arm.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=lee@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=macromorgan@hotmail.com \
--cc=sre@kernel.org \
--cc=wens@csie.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