From: Paul Cercueil <paul@crapouillou.net>
To: Peter Rosin <peda@axentia.se>, Jonathan Cameron <jic23@kernel.org>
Cc: od@zcrc.me, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Paul Cercueil <paul@crapouillou.net>
Subject: [PATCH 2/2] iio: afe: rescale: Implement write_raw
Date: Mon, 10 Feb 2020 19:54:38 -0300 [thread overview]
Message-ID: <20200210225438.112660-2-paul@crapouillou.net> (raw)
In-Reply-To: <20200210225438.112660-1-paul@crapouillou.net>
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
next prev parent reply other threads:[~2020-02-10 22:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-10 22:54 [PATCH 1/2] iio: afe: rescale: Add support for converting scale avail table Paul Cercueil
2020-02-10 22:54 ` Paul Cercueil [this message]
2020-02-15 18:32 ` [PATCH 2/2] iio: afe: rescale: Implement write_raw Jonathan Cameron
2020-07-20 23:16 ` Paul Cercueil
2020-07-26 12:41 ` Jonathan Cameron
2020-07-27 9:16 ` Peter Rosin
2020-07-27 9:22 ` [PATCH 1/2] iio: afe: rescale: Add support for converting scale avail table Peter Rosin
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=20200210225438.112660-2-paul@crapouillou.net \
--to=paul@crapouillou.net \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=od@zcrc.me \
--cc=peda@axentia.se \
/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;
as well as URLs for NNTP newsgroup(s).