Re: [PATCH v4 6/7] iio: light: vcnl4000: Add oversampling_ratio for 4040/4200

From: andy . shevchenko
Date: Mon May 29 2023 - 01:22:53 EST


Mon, May 22, 2023 at 04:26:20PM +0200, Astrid Rost kirjoitti:
> Add the proximity multi pulse (PS_MPS) as oversampling_ratio.
> Instead of one single pulse per every defined time frame,
> one can program 2, 4, or even 8 pulses. This leads to a
> longer IRED on-time for each proximity measurement value, which
> also results in a higher detection range.
>
> Add read/write attribute for proximity oversampling-ratio and read
> attribute for available oversampling-ratio.
> This is supported for vcnl4040 and vcnl4200.

...

> +static ssize_t vcnl4040_write_ps_oversampling_ratio(struct vcnl4000_data *data, int val)
> +{
> + unsigned int i;
> + int ret, index = -1;

Either i or index is redundant.

> + u16 regval;
> +
> + for (i = 0; i < ARRAY_SIZE(vcnl4040_ps_oversampling_ratio); i++) {
> + if (val == vcnl4040_ps_oversampling_ratio[i]) {
> + index = i;
> + break;
> + }
> + }
> +
> + if (index < 0)
> + return -EINVAL;
> +
> + mutex_lock(&data->vcnl4000_lock);
> +
> + ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3);
> + if (ret < 0)
> + goto out;
> +
> + regval = (ret & ~VCNL4040_PS_CONF3_MPS) |
> + FIELD_PREP(VCNL4040_PS_CONF3_MPS, index);
> + ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF3,
> + regval);
> +
> +out:

out_unlock:

> + mutex_unlock(&data->vcnl4000_lock);
> + return ret;
> +}

...

> if (ret < 0)
> return ret;
> return IIO_VAL_INT_PLUS_MICRO;
> + case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
> + switch (chan->type) {
> + case IIO_PROXIMITY:
> + ret = vcnl4040_read_ps_oversampling_ratio(data, val);
> + if (ret < 0)
> + return ret;
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }

> +

This is inconsistent blank line.

> default:
> return -EINVAL;
> }

--
With Best Regards,
Andy Shevchenko