LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andreas Kemnade <andreas@kemnade.info>
To: jic23@kernel.org, lars@metafoo.de, sre@kernel.org,
	andreas@kemnade.info, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	letux-kernel@openphoenux.org
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: [PATCH v3 1/2] iio: adc: rn5t618: Add iio map
Date: Mon, 12 Jul 2021 23:21:10 +0200	[thread overview]
Message-ID: <20210712212111.18896-2-andreas@kemnade.info> (raw)
In-Reply-To: <20210712212111.18896-1-andreas@kemnade.info>

Add iio map to allow power driver to read out values as a consumer.
This approach does not block later addition of devicetree support
which would be helpful if there is an in-kernel consumer for AIN0/1.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
Changes in v3:
- none

Changes in v2:
- provide consumer mapping via iio_map instead of devicetree

 drivers/iio/adc/rn5t618-adc.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/iio/adc/rn5t618-adc.c b/drivers/iio/adc/rn5t618-adc.c
index 7010c4276947..c56fccb2c8e1 100644
--- a/drivers/iio/adc/rn5t618-adc.c
+++ b/drivers/iio/adc/rn5t618-adc.c
@@ -16,6 +16,8 @@
 #include <linux/completion.h>
 #include <linux/regmap.h>
 #include <linux/iio/iio.h>
+#include <linux/iio/driver.h>
+#include <linux/iio/machine.h>
 #include <linux/slab.h>
 
 #define RN5T618_ADC_CONVERSION_TIMEOUT   (msecs_to_jiffies(500))
@@ -189,6 +191,19 @@ static const struct iio_chan_spec rn5t618_adc_iio_channels[] = {
 	RN5T618_ADC_CHANNEL(AIN0, IIO_VOLTAGE, "AIN0")
 };
 
+static struct iio_map rn5t618_maps[] = {
+	IIO_MAP("VADP", "rn5t618-power", "vadp"),
+	IIO_MAP("VUSB", "rn5t618-power", "vusb"),
+	{ /* sentinel */ }
+};
+
+static void unregister_map(void *data)
+{
+	struct iio_dev *iio_dev = (struct iio_dev *) data;
+
+	iio_map_array_unregister(iio_dev);
+}
+
 static int rn5t618_adc_probe(struct platform_device *pdev)
 {
 	int ret;
@@ -239,6 +254,14 @@ static int rn5t618_adc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = iio_map_array_register(iio_dev, rn5t618_maps);
+	if (ret < 0)
+		return ret;
+
+	ret = devm_add_action_or_reset(adc->dev, unregister_map, iio_dev);
+	if (ret < 0)
+		return ret;
+
 	return devm_iio_device_register(adc->dev, iio_dev);
 }
 
-- 
2.30.2


  reply	other threads:[~2021-07-12 21:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12 21:21 [PATCH v3 0/2] mfd: rn5t618: Extend ADC support Andreas Kemnade
2021-07-12 21:21 ` Andreas Kemnade [this message]
2021-07-12 21:21 ` [PATCH v3 2/2] power: supply: rn5t618: Add voltage_now property Andreas Kemnade
2021-07-13  8:27 ` [PATCH v3 0/2] mfd: rn5t618: Extend ADC support Lee Jones
2021-07-17 17:08   ` Jonathan Cameron
2021-08-13 16:00 ` Sebastian Reichel

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=20210712212111.18896-2-andreas@kemnade.info \
    --to=andreas@kemnade.info \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=letux-kernel@openphoenux.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    --subject='Re: [PATCH v3 1/2] iio: adc: rn5t618: Add iio map' \
    /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

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).