[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241121-ad7606_add_iio_backend_software_mode-v1-9-8a693a5e3fa9@baylibre.com>
Date: Thu, 21 Nov 2024 10:18:31 +0000
From: Guillaume Stols <gstols@...libre.com>
To: Lars-Peter Clausen <lars@...afoo.de>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Jonathan Cameron <jic23@...nel.org>, Nuno Sa <nuno.sa@...log.com>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@...wei.com>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
Michael Hennerich <michael.hennerich@...log.com>,
devicetree@...r.kernel.org, dlechner@...libre.com, jstephan@...libre.com,
aardelean@...libre.com, adureghello@...libre.com,
Guillaume Stols <gstols@...libre.com>
Subject: [PATCH 9/9] iio: adc: ad7606: Add support for writing registers
when using backend
Adds the logic for effectively enabling the software mode for the
iio-backend, i.e enabling the software mode channel configuration and
implementing the register writing functions.
Signed-off-by: Guillaume Stols <gstols@...libre.com>
---
drivers/iio/adc/ad7606.h | 15 ++++++++++++
drivers/iio/adc/ad7606_par.c | 58 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ad7606.h b/drivers/iio/adc/ad7606.h
index 74896d9f1929..a54dc110839f 100644
--- a/drivers/iio/adc/ad7606.h
+++ b/drivers/iio/adc/ad7606.h
@@ -96,6 +96,21 @@
BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
0, 0, 16)
+#define AD7606_BI_SW_CHANNEL(num) \
+ AD760X_CHANNEL(num, \
+ /* mask separate */ \
+ BIT(IIO_CHAN_INFO_SCALE), \
+ /* mask type */ \
+ 0, \
+ /* mask all */ \
+ BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
+ /* mask separate available */ \
+ BIT(IIO_CHAN_INFO_SCALE), \
+ /* mask all available */ \
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
+ 16)
+
struct ad7606_state;
typedef int (*ad7606_scale_setup_cb_t)(struct iio_dev *indio_dev,
diff --git a/drivers/iio/adc/ad7606_par.c b/drivers/iio/adc/ad7606_par.c
index a25182a3daa7..0c1177f436f3 100644
--- a/drivers/iio/adc/ad7606_par.c
+++ b/drivers/iio/adc/ad7606_par.c
@@ -13,12 +13,14 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/property.h>
+#include <linux/pwm.h>
#include <linux/types.h>
#include <linux/iio/backend.h>
#include <linux/iio/iio.h>
#include "ad7606.h"
+#include "ad7606_bi.h"
static const struct iio_chan_spec ad7606b_bi_channels[] = {
AD7606_BI_CHANNEL(0),
@@ -31,6 +33,17 @@ static const struct iio_chan_spec ad7606b_bi_channels[] = {
AD7606_BI_CHANNEL(7),
};
+static const struct iio_chan_spec ad7606b_bi_sw_channels[] = {
+ AD7606_BI_SW_CHANNEL(0),
+ AD7606_BI_SW_CHANNEL(1),
+ AD7606_BI_SW_CHANNEL(2),
+ AD7606_BI_SW_CHANNEL(3),
+ AD7606_BI_SW_CHANNEL(4),
+ AD7606_BI_SW_CHANNEL(5),
+ AD7606_BI_SW_CHANNEL(6),
+ AD7606_BI_SW_CHANNEL(7),
+};
+
static int ad7606_bi_update_scan_mode(struct iio_dev *indio_dev, const unsigned long *scan_mask)
{
struct ad7606_state *st = iio_priv(indio_dev);
@@ -70,7 +83,7 @@ static int ad7606_bi_setup_iio_backend(struct device *dev, struct iio_dev *indio
if (ret)
return ret;
- ret = devm_iio_backend_enable(dev, st->back);
+ ret = devm_iio_backend_enable(st->dev, st->back);
if (ret)
return ret;
@@ -86,9 +99,52 @@ static int ad7606_bi_setup_iio_backend(struct device *dev, struct iio_dev *indio
return 0;
}
+static int ad7606_bi_reg_read(struct iio_dev *indio_dev, unsigned int addr)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+ int val, ret;
+ struct ad7606_platform_data *pdata = st->dev->platform_data;
+
+ iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
+ ret = pdata->bus_reg_read(st->back,
+ addr,
+ &val);
+ }
+ if (ret < 0)
+ return ret;
+
+ return val;
+}
+
+static int ad7606_bi_reg_write(struct iio_dev *indio_dev,
+ unsigned int addr,
+ unsigned int val)
+{
+ struct ad7606_state *st = iio_priv(indio_dev);
+ struct ad7606_platform_data *pdata = st->dev->platform_data;
+ int ret;
+
+ iio_device_claim_direct_scoped(return -EBUSY, indio_dev) {
+ ret = pdata->bus_reg_write(st->back,
+ addr,
+ val);
+ }
+ return ret;
+}
+
+static int ad7606_bi_sw_mode_config(struct iio_dev *indio_dev)
+{
+ indio_dev->channels = ad7606b_bi_sw_channels;
+
+ return 0;
+}
+
static const struct ad7606_bus_ops ad7606_bi_bops = {
.iio_backend_config = ad7606_bi_setup_iio_backend,
.update_scan_mode = ad7606_bi_update_scan_mode,
+ .reg_read = ad7606_bi_reg_read,
+ .reg_write = ad7606_bi_reg_write,
+ .sw_mode_config = ad7606_bi_sw_mode_config,
};
static int ad7606_par16_read_block(struct device *dev,
--
2.34.1
Powered by blists - more mailing lists