Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: light: ltrf216a: Add raw attribute

Add IIO_CHAN_INFO_RAW to the mask to be able to read raw values
from the light sensor.

The userspace code for brightness control in steam deck uses the
in_illuminance_input value through sysfs and multiplies it
with a constant stored in BIOS at factory calibration time.

The downstream driver for LTRF216A that we have been using
has incorrect formula for LUX calculation which we corrected
in the upstreamed driver.

Now to be able to use the upstreamed driver, we need to add some
magic in userspace so that the brightness control works like before
even with the updated LUX formula.

Hence, we need the raw data to calculate a constant that can be
added in userspace code.

Downstream driver LUX formula :-
(greendata*8*LTRF216A_WIN_FAC) / (data->als_gain_fac*data->int_time_fac*10)

Upstreamed driver LUX formula :-
(greendata*45*LTRF216A_WIN_FAC) / (data->als_gain_fac*data->int_time_fac)

greendata is the ALS_DATA which we would like to get through sysfs using
the raw attribute.

Signed-off-by: Shreeya Patel <shreeya.patel@collabora.com>
Link: https://lore.kernel.org/r/20220812100424.529425-1-shreeya.patel@collabora.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Shreeya Patel and committed by
Jonathan Cameron
f5ffeca5 c682c963

+13
+13
drivers/iio/light/ltrf216a.c
··· 93 93 { 94 94 .type = IIO_LIGHT, 95 95 .info_mask_separate = 96 + BIT(IIO_CHAN_INFO_RAW) | 96 97 BIT(IIO_CHAN_INFO_PROCESSED) | 97 98 BIT(IIO_CHAN_INFO_INT_TIME), 98 99 .info_mask_separate_available = ··· 260 259 int ret; 261 260 262 261 switch (mask) { 262 + case IIO_CHAN_INFO_RAW: 263 + ret = ltrf216a_set_power_state(data, true); 264 + if (ret) 265 + return ret; 266 + mutex_lock(&data->lock); 267 + ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0); 268 + mutex_unlock(&data->lock); 269 + ltrf216a_set_power_state(data, false); 270 + if (ret < 0) 271 + return ret; 272 + *val = ret; 273 + return IIO_VAL_INT; 263 274 case IIO_CHAN_INFO_PROCESSED: 264 275 mutex_lock(&data->lock); 265 276 ret = ltrf216a_get_lux(data);