lkml.org 
[lkml]   [2020]   [Feb]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] iio: afe: rescale: Implement write_raw
Date
Implement write_raw by converting the value if writing the scale, or
just calling the managed channel driver's write_raw otherwise.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
drivers/iio/afe/iio-rescale.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
index 95802d9ee25e..a48f6af9316d 100644
--- a/drivers/iio/afe/iio-rescale.c
+++ b/drivers/iio/afe/iio-rescale.c
@@ -35,6 +35,27 @@ struct rescale {
int *scale_data;
};

+static int rescale_write_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int val, int val2, long mask)
+{
+ struct rescale *rescale = iio_priv(indio_dev);
+ unsigned long long tmp;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_SCALE:
+ tmp = val * 1000000000LL;
+ do_div(tmp, rescale->numerator);
+ tmp *= rescale->denominator;
+ do_div(tmp, 1000000000LL);
+ return iio_write_channel_attribute(rescale->source, tmp, 0,
+ IIO_CHAN_INFO_SCALE);
+ default:
+ return iio_write_channel_attribute(rescale->source,
+ val, val2, mask);
+ }
+}
+
static int rescale_convert(struct rescale *rescale, int type,
const int val, const int val2,
int *val_out, int *val2_out)
@@ -110,6 +131,7 @@ static int rescale_read_avail(struct iio_dev *indio_dev,
}

static const struct iio_info rescale_info = {
+ .write_raw = rescale_write_raw,
.read_raw = rescale_read_raw,
.read_avail = rescale_read_avail,
};
--
2.25.0
\
 
 \ /
  Last update: 2020-02-10 23:55    [W:0.067 / U:0.696 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site