From: Javier Carrasco <javier.carrasco.cruz@gmail.com>
To: Christian Eggers <ceggers@arri.de>,
Jonathan Cameron <jic23@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Javier Carrasco <javier.carrasco.cruz@gmail.com>
Subject: [PATCH v2 1/3] iio: light: as73211: use IIO_VAL_FRACTIONAL for intensity scales
Date: Wed, 03 Jan 2024 13:08:51 +0100 [thread overview]
Message-ID: <20240103-as7331-v2-1-6f0ad05e0482@gmail.com> (raw)
In-Reply-To: <20240103-as7331-v2-0-6f0ad05e0482@gmail.com>
The scale values associated to the light channels are calculated as a
division that can be better expressed as an IIO_VAL_FRACTIONAL type
instead of the current IIO_VAL_INT.
Note that the constant values used for the calculation were scaled up to
work with integers, turning the nW/cm^2 units from the datasheet into
nW/m^2, which would not be necessary with the IIO_VAL_FRACTIONAL type.
But to avoid issues from current users of the driver, the units must be
kept.
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/iio/light/as73211.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c
index ec97a3a46839..b4c6f389a292 100644
--- a/drivers/iio/light/as73211.c
+++ b/drivers/iio/light/as73211.c
@@ -356,25 +356,24 @@ static int as73211_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec cons
return IIO_VAL_INT_PLUS_MICRO;
case IIO_INTENSITY: {
- unsigned int scale;
switch (chan->channel2) {
case IIO_MOD_X:
- scale = AS73211_SCALE_X;
+ *val = AS73211_SCALE_X;
break;
case IIO_MOD_Y:
- scale = AS73211_SCALE_Y;
+ *val = AS73211_SCALE_Y;
break;
case IIO_MOD_Z:
- scale = AS73211_SCALE_Z;
+ *val = AS73211_SCALE_Z;
break;
default:
return -EINVAL;
}
- scale /= as73211_gain(data);
- scale /= as73211_integration_time_1024cyc(data);
- *val = scale;
- return IIO_VAL_INT;
+ *val2 = as73211_integration_time_1024cyc(data) *
+ as73211_gain(data);
+
+ return IIO_VAL_FRACTIONAL;
default:
return -EINVAL;
--
2.39.2
next prev parent reply other threads:[~2024-01-03 12:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-03 12:08 [PATCH v2 0/3] iio: light: add support for AMS AS7331 Javier Carrasco
2024-01-03 12:08 ` Javier Carrasco [this message]
2024-01-03 12:08 ` [PATCH v2 2/3] dt-bindings: iio: light: as73211: add support for as7331 Javier Carrasco
2024-01-03 12:08 ` [PATCH v2 3/3] " Javier Carrasco
2024-01-12 9:47 ` Christian Eggers
2024-01-13 15:15 ` Jonathan Cameron
2024-01-07 15:58 ` [PATCH v2 0/3] iio: light: add support for AMS AS7331 Jonathan Cameron
2024-01-07 17:34 ` Javier Carrasco
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=20240103-as7331-v2-1-6f0ad05e0482@gmail.com \
--to=javier.carrasco.cruz@gmail.com \
--cc=ceggers@arri.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.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;
as well as URLs for NNTP newsgroup(s).