Skip to content

Commit

Permalink
iio: light: bu27034: Fix scale format
Browse files Browse the repository at this point in the history
commit d47b9b8 upstream.

The driver is expecting accuracy of NANOs for intensity scale in
raw_write. The IIO core is however defaulting to MICROs. This leads the
raw-write of smallest scales to never succeed as correct selector(s) are
not found.

Fix this by implementing the .write_raw_get_fmt callback to use NANO
accuracy for writes of IIO_CHAN_INFO_SCALE.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Fixes: e52afbd ("iio: light: ROHM BU27034 Ambient Light Sensor")
Link: https://lore.kernel.org/r/5369117315cf05b88cf0ccb87373fd77190f6ca2.1686648422.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
M-Vaittinen authored and gregkh committed Aug 16, 2023
1 parent a4b34cc commit 8e744d4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions drivers/iio/light/rohm-bu27034.c
Expand Up @@ -575,7 +575,7 @@ static int bu27034_set_scale(struct bu27034_data *data, int chan,
return -EINVAL;

if (chan == BU27034_CHAN_ALS) {
if (val == 0 && val2 == 1000)
if (val == 0 && val2 == 1000000)
return 0;

return -EINVAL;
Expand All @@ -587,7 +587,7 @@ static int bu27034_set_scale(struct bu27034_data *data, int chan,
goto unlock_out;

ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts, time_sel,
val, val2 * 1000, &gain_sel);
val, val2, &gain_sel);
if (ret) {
/*
* Could not support scale with given time. Need to change time.
Expand Down Expand Up @@ -624,7 +624,7 @@ static int bu27034_set_scale(struct bu27034_data *data, int chan,

/* Can we provide requested scale with this time? */
ret = iio_gts_find_gain_sel_for_scale_using_time(
&data->gts, new_time_sel, val, val2 * 1000,
&data->gts, new_time_sel, val, val2,
&gain_sel);
if (ret)
continue;
Expand Down Expand Up @@ -1217,6 +1217,21 @@ static int bu27034_read_raw(struct iio_dev *idev,
}
}

static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
long mask)
{

switch (mask) {
case IIO_CHAN_INFO_SCALE:
return IIO_VAL_INT_PLUS_NANO;
case IIO_CHAN_INFO_INT_TIME:
return IIO_VAL_INT_PLUS_MICRO;
default:
return -EINVAL;
}
}

static int bu27034_write_raw(struct iio_dev *idev,
struct iio_chan_spec const *chan,
int val, int val2, long mask)
Expand Down Expand Up @@ -1267,6 +1282,7 @@ static int bu27034_read_avail(struct iio_dev *idev,
static const struct iio_info bu27034_info = {
.read_raw = &bu27034_read_raw,
.write_raw = &bu27034_write_raw,
.write_raw_get_fmt = &bu27034_write_raw_get_fmt,
.read_avail = &bu27034_read_avail,
};

Expand Down

0 comments on commit 8e744d4

Please sign in to comment.