Skip to content

Commit d47b9b8

Browse files
M-Vaittinenjic23
authored andcommitted
iio: light: bu27034: Fix scale format
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 <[email protected]> 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 <[email protected]>
1 parent 6bc471b commit d47b9b8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

drivers/iio/light/rohm-bu27034.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ static int bu27034_set_scale(struct bu27034_data *data, int chan,
575575
return -EINVAL;
576576

577577
if (chan == BU27034_CHAN_ALS) {
578-
if (val == 0 && val2 == 1000)
578+
if (val == 0 && val2 == 1000000)
579579
return 0;
580580

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

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

625625
/* Can we provide requested scale with this time? */
626626
ret = iio_gts_find_gain_sel_for_scale_using_time(
627-
&data->gts, new_time_sel, val, val2 * 1000,
627+
&data->gts, new_time_sel, val, val2,
628628
&gain_sel);
629629
if (ret)
630630
continue;
@@ -1217,6 +1217,21 @@ static int bu27034_read_raw(struct iio_dev *idev,
12171217
}
12181218
}
12191219

1220+
static int bu27034_write_raw_get_fmt(struct iio_dev *indio_dev,
1221+
struct iio_chan_spec const *chan,
1222+
long mask)
1223+
{
1224+
1225+
switch (mask) {
1226+
case IIO_CHAN_INFO_SCALE:
1227+
return IIO_VAL_INT_PLUS_NANO;
1228+
case IIO_CHAN_INFO_INT_TIME:
1229+
return IIO_VAL_INT_PLUS_MICRO;
1230+
default:
1231+
return -EINVAL;
1232+
}
1233+
}
1234+
12201235
static int bu27034_write_raw(struct iio_dev *idev,
12211236
struct iio_chan_spec const *chan,
12221237
int val, int val2, long mask)
@@ -1267,6 +1282,7 @@ static int bu27034_read_avail(struct iio_dev *idev,
12671282
static const struct iio_info bu27034_info = {
12681283
.read_raw = &bu27034_read_raw,
12691284
.write_raw = &bu27034_write_raw,
1285+
.write_raw_get_fmt = &bu27034_write_raw_get_fmt,
12701286
.read_avail = &bu27034_read_avail,
12711287
};
12721288

0 commit comments

Comments
 (0)