The RAW read selects its data register with a per-channel-type branch. Record each channel's data register in its .address field and read from there, so adding a channel does not grow the branch.
Suggested-by: Jonathan Cameron <[email protected]> Assisted-by: Claude:claude-fable-5 Signed-off-by: Jorijn van der Graaf <[email protected]> --- drivers/iio/light/stk3310.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 5b5b6812edc7..156888969366 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -184,6 +184,7 @@ static const struct iio_chan_spec_ext_info stk3310_ext_info[] = { static const struct iio_chan_spec stk3310_channels[] = { { .type = IIO_LIGHT, + .address = STK3310_REG_ALS_DATA_MSB, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | @@ -191,6 +192,7 @@ static const struct iio_chan_spec stk3310_channels[] = { }, { .type = IIO_PROXIMITY, + .address = STK3310_REG_PS_DATA_MSB, .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | @@ -370,25 +372,20 @@ static int stk3310_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { - u8 reg; __be16 buf; int ret; unsigned int index; struct stk3310_data *data = iio_priv(indio_dev); struct i2c_client *client = data->client; + struct regmap *map = data->regmap; if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY) return -EINVAL; switch (mask) { case IIO_CHAN_INFO_RAW: - if (chan->type == IIO_LIGHT) - reg = STK3310_REG_ALS_DATA_MSB; - else - reg = STK3310_REG_PS_DATA_MSB; - mutex_lock(&data->lock); - ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf)); + ret = regmap_bulk_read(map, chan->address, &buf, sizeof(buf)); if (ret < 0) { dev_err(&client->dev, "register read failed\n"); mutex_unlock(&data->lock); -- 2.55.0

