Re: [PATCH 2/2] iio: veml3235: fix scale to conform to ABI

From: Matti Vaittinen
Date: Sun Dec 22 2024 - 08:43:35 EST


On 20/12/2024 21:28, Javier Carrasco wrote:
The current scale is not ABI-compliant as it is just the sensor gain
instead of the value that acts as a multiplier to be applied to the raw
value (there is no offset).

Use the iio-gts helpers to obtain the proper scale values according to
the gain and integration time to match the resolution tables from the
datasheet.

Fixes: c5a23f80c164 ("iio: light: add support for veml3235")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@xxxxxxxxx>
---

...

+static const struct iio_itime_sel_mul veml3235_it_sel[] = {
+ GAIN_SCALE_ITIME_US(50000, 0, 1),
+ GAIN_SCALE_ITIME_US(100000, 1, 2),
+ GAIN_SCALE_ITIME_US(200000, 2, 4),
+ GAIN_SCALE_ITIME_US(400000, 3, 8),
+ GAIN_SCALE_ITIME_US(800000, 4, 16),
};
-static const int veml3235_scale_vals[] = { 1, 2, 4, 8 };
+/*
+ * The MSB (DG) doubles the value of the rest of the field, which leads to
+ * two possible combinations to obtain gain = 2 and gain = 4. The gain
+ * handlding can be simplified by restricting DG = 1 to the only gain that
+ * really requires it, gain = 8. Note that "X10" is a reserved value.

Just a question - do you ensure there is no "invalid" register values? I think Jonathan has prefered doing this by writing known initialization values at probe.

I *think* the GTS should survive cases where multiple bit patterns can be used to represent same gain/time - but I don't remember this for sure.

I didn't have the time to do a proper thorough review - sorry. Still, what I browsed quickly looked good :) Thanks!

Yours,
-- Matti