Skip to content

Commit ab09c6c

Browse files
javiercarrascocruzjic23
authored andcommitted
iio: light: as73211: fix channel handling in only-color triggered buffer
The channel index is off by one unit if AS73211_SCAN_MASK_ALL is not set (optimized path for color channel readings), and it must be shifted instead of leaving an empty channel for the temperature when it is off. Once the channel index is fixed, the uninitialized channel must be set to zero to avoid pushing uninitialized data. Add available_scan_masks for all channels and only-color channels to let the IIO core demux and repack the enabled channels. Cc: [email protected] Fixes: 403e558 ("iio: light: as73211: New driver") Tested-by: Christian Eggers <[email protected]> Signed-off-by: Javier Carrasco <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent c969c1e commit ab09c6c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

drivers/iio/light/as73211.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ struct as73211_data {
177177
BIT(AS73211_SCAN_INDEX_TEMP) | \
178178
AS73211_SCAN_MASK_COLOR)
179179

180+
static const unsigned long as73211_scan_masks[] = {
181+
AS73211_SCAN_MASK_COLOR,
182+
AS73211_SCAN_MASK_ALL,
183+
0
184+
};
185+
180186
static const struct iio_chan_spec as73211_channels[] = {
181187
{
182188
.type = IIO_TEMP,
@@ -672,19 +678,28 @@ static irqreturn_t as73211_trigger_handler(int irq __always_unused, void *p)
672678

673679
/* AS73211 starts reading at address 2 */
674680
ret = i2c_master_recv(data->client,
675-
(char *)&scan.chan[1], 3 * sizeof(scan.chan[1]));
681+
(char *)&scan.chan[0], 3 * sizeof(scan.chan[0]));
676682
if (ret < 0)
677683
goto done;
684+
685+
/* Avoid pushing uninitialized data */
686+
scan.chan[3] = 0;
678687
}
679688

680689
if (data_result) {
681690
/*
682691
* Saturate all channels (in case of overflows). Temperature channel
683692
* is not affected by overflows.
684693
*/
685-
scan.chan[1] = cpu_to_le16(U16_MAX);
686-
scan.chan[2] = cpu_to_le16(U16_MAX);
687-
scan.chan[3] = cpu_to_le16(U16_MAX);
694+
if (*indio_dev->active_scan_mask == AS73211_SCAN_MASK_ALL) {
695+
scan.chan[1] = cpu_to_le16(U16_MAX);
696+
scan.chan[2] = cpu_to_le16(U16_MAX);
697+
scan.chan[3] = cpu_to_le16(U16_MAX);
698+
} else {
699+
scan.chan[0] = cpu_to_le16(U16_MAX);
700+
scan.chan[1] = cpu_to_le16(U16_MAX);
701+
scan.chan[2] = cpu_to_le16(U16_MAX);
702+
}
688703
}
689704

690705
iio_push_to_buffers_with_timestamp(indio_dev, &scan, iio_get_time_ns(indio_dev));
@@ -758,6 +773,7 @@ static int as73211_probe(struct i2c_client *client)
758773
indio_dev->channels = data->spec_dev->channels;
759774
indio_dev->num_channels = data->spec_dev->num_channels;
760775
indio_dev->modes = INDIO_DIRECT_MODE;
776+
indio_dev->available_scan_masks = as73211_scan_masks;
761777

762778
ret = i2c_smbus_read_byte_data(data->client, AS73211_REG_OSR);
763779
if (ret < 0)

0 commit comments

Comments
 (0)