Skip to content

Commit 096649c

Browse files
M-Vaittinenjic23
authored andcommitted
iio: light: bu27008: 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. Fixes: 41ff93d ("iio: light: ROHM BU27008 color sensor") Signed-off-by: Matti Vaittinen <[email protected]> Link: https://lore.kernel.org/r/e4778b74cde41431f77bc8dd88ec18605da0b400.1686648422.git.mazziesaccount@gmail.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d47b9b8 commit 096649c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/iio/light/rohm-bu27008.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ static int bu27008_try_find_new_time_gain(struct bu27008_data *data, int val,
633633
for (i = 0; i < data->gts.num_itime; i++) {
634634
new_time_sel = data->gts.itime_table[i].sel;
635635
ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts,
636-
new_time_sel, val, val2 * 1000, gain_sel);
636+
new_time_sel, val, val2, gain_sel);
637637
if (!ret)
638638
break;
639639
}
@@ -662,7 +662,7 @@ static int bu27008_set_scale(struct bu27008_data *data,
662662
goto unlock_out;
663663

664664
ret = iio_gts_find_gain_sel_for_scale_using_time(&data->gts, time_sel,
665-
val, val2 * 1000, &gain_sel);
665+
val, val2, &gain_sel);
666666
if (ret) {
667667
ret = bu27008_try_find_new_time_gain(data, val, val2, &gain_sel);
668668
if (ret)
@@ -677,6 +677,21 @@ static int bu27008_set_scale(struct bu27008_data *data,
677677
return ret;
678678
}
679679

680+
static int bu27008_write_raw_get_fmt(struct iio_dev *indio_dev,
681+
struct iio_chan_spec const *chan,
682+
long mask)
683+
{
684+
685+
switch (mask) {
686+
case IIO_CHAN_INFO_SCALE:
687+
return IIO_VAL_INT_PLUS_NANO;
688+
case IIO_CHAN_INFO_INT_TIME:
689+
return IIO_VAL_INT_PLUS_MICRO;
690+
default:
691+
return -EINVAL;
692+
}
693+
}
694+
680695
static int bu27008_write_raw(struct iio_dev *idev,
681696
struct iio_chan_spec const *chan,
682697
int val, int val2, long mask)
@@ -756,6 +771,7 @@ static int bu27008_update_scan_mode(struct iio_dev *idev,
756771
static const struct iio_info bu27008_info = {
757772
.read_raw = &bu27008_read_raw,
758773
.write_raw = &bu27008_write_raw,
774+
.write_raw_get_fmt = &bu27008_write_raw_get_fmt,
759775
.read_avail = &bu27008_read_avail,
760776
.update_scan_mode = bu27008_update_scan_mode,
761777
.validate_trigger = iio_validate_own_trigger,

0 commit comments

Comments
 (0)