summaryrefslogtreecommitdiffstats
path: root/drivers/iio/light
diff options
context:
space:
mode:
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>2024-01-03 13:08:51 +0100
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-01-22 19:58:44 +0100
commit8745465e884c06736aafc6c0e7344ac3a3c7df94 (patch)
tree9683eb5b7c4a04e4582f9b41bff0cfed31a42e0a /drivers/iio/light
parentLinux 6.8-rc1 (diff)
downloadlinux-8745465e884c06736aafc6c0e7344ac3a3c7df94.tar.xz
linux-8745465e884c06736aafc6c0e7344ac3a3c7df94.zip
iio: light: as73211: use IIO_VAL_FRACTIONAL for intensity scales
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> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/light')
-rw-r--r--drivers/iio/light/as73211.c15
1 files 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;