On Sun, 16 Feb 2025 16:47:52 +0200 Svyatoslav Ryhel <clamor95@xxxxxxxxx> wrote: > нд, 16 лют. 2025 р. о 16:44 Jonathan Cameron <jic23@xxxxxxxxxx> пише: > > > > > > > > > + > > > > > +static int al3000a_read_raw(struct iio_dev *indio_dev, > > > > > + struct iio_chan_spec const *chan, int *val, > > > > > + int *val2, long mask) > > > > > +{ > > > > > + struct al3000a_data *data = iio_priv(indio_dev); > > > > > + int ret, gain; > > > > > + > > > > > + switch (mask) { > > > > > + case IIO_CHAN_INFO_RAW: > > > > > + ret = regmap_read(data->regmap, AL3000A_REG_DATA, &gain); > > > > > + if (ret < 0) > > > > > + return ret; > > > > > + > > > > > + *val = lux_table[gain & AL3000A_GAIN_MASK]; > > > > > > > > Why did you chosen to do post-processing in the RAW channel instead > > > > doing it in INFO_SCALE (same as al3010 does)? > > > > > > > > > > From my observation INFO_SCALE will just perform multiplication of RAW > > > to SCALE. In this case values which are read are not actual raw values > > > of illumination. Next is my assumption (since there is no datasheet), > > > but values obtained from register are similar to values from adc > > > thermal sensors, they need be converted via reference table to get > > > actual data. > > > > Please add a comment somewhere here to say that we don't know the > > relationship of these values to illuminance hence providing > > _RAW and _SCALE would not be helpful. > > > > We do know relationship of these values to illuminance thanks to > conversion table provided. Then convention is treat them not as IIO_LIGHT but as IIO_INTENSITY which is unit free. IIO_LIGHT is only for when we know the value we are providing to userspace is illuminance and measured in Lux. Jonathan > > > > > > > > Except this, LGTM. > > > > > > > > Documentation and DT patch: > > > > > > > > Reviewed-by: David Heidelberg <david@xxxxxxx> > > > > > + > > > > > + return IIO_VAL_INT; > > > > > + case IIO_CHAN_INFO_SCALE: > > > > > + *val = 1; > > > > > + > > > > Don't do this. The above lack of known relationship has to be > > expressed by not providing the _scale attribute. > > > > > > > + return IIO_VAL_INT; > > > > > + default: > > > > > + return -EINVAL; > > > > > + } > > > > > +} > > > > > + > > > > > +static const struct iio_info al3000a_info = { > > > > > + .read_raw = al3000a_read_raw, > > > > > +}; > > > >