2023-05-22 14:40:31

by Astrid Rost

[permalink] [raw]
Subject: [PATCH v4 0/7] iio: light: vcnl4000: Add features for vncl4040/4200

Add a more complete support for vncl4040 and vcnl4200, which allows to
change the distance of proximity detection and interrupt support for the
illuminance sensor.

Proximity functionality:
- Interrupt support (new on vcnl4200).

Proximity reduce the amount of interrupts:
- Adaptable integration time (new on vcnl4200) - the sampling rate
changes according to this value.
- Period - interrupt is asserted if the value is above or
below a certain threshold.

Proximity change the activity distance:
- Oversampling ratio - Amount of LED pulses per measured raw value.
- Calibration bias - LED current calibration of the sensor.

Illuminance functionality:
- Interrupt support.

Illuminance reduce the amount of interrupts:
- Adaptable integration time - the sampling rate and scale changes
according to this value.
- Period – interrupt is asserted if the value is above or
below a certain threshold.

changes v2:
- [PATCH v2 3/7] Fixed calculation of al_scale.
Fix the value of vcnl4040 according to the data-sheet.
Use div_u64 for the division.
scription for the branch

changes v3:
- [PATCH v3 1-3/7] Add differences between the chips as variables in
chip-spec.
- [PATCH v3 4/7] Changed commit message.
- [PATCH v3 5/7] Use period instead of debounce time. This causes some
calculations as the period is a time and the chip allows to set a certain
amount of measurements above/below the threshold, before throwing an
interrupt.
- [PATCH v3 6/7] Changed commit message.

changes v4:
- [PATCH v3 1-3/7] Fix setting correct als_it for vcnl4040.
- [PATCH v3 5/7] Use MICRO macro.
Fix values greater than 1 s for the proximity period.

Astrid Rost (7):
[PATCH v4 1/7] iio: light: vcnl4000: Add proximity irq for vcnl4200
[PATCH v4 2/7] iio: light: vcnl4000: Add proximity ps_it for vcnl4200
[PATCH v4 3/7] iio: light: vcnl4000: Add als_it for vcnl4040/4200
[PATCH v4 4/7] iio: light: vcnl4000: add illuminance irq vcnl4040/4200
[PATCH v4 5/7] iio: light: vcnl4000: Add period for vcnl4040/4200
[PATCH v4 6/7] iio: light: vcnl4000: Add oversampling_ratio for 4040/4200
[PATCH v4 7/7] iio: light: vcnl4000: Add calibration bias for 4040/4200

drivers/iio/light/vcnl4000.c | 721 +++++++++++++++++++++++++++++++----
1 file changed, 653 insertions(+), 68 deletions(-)

--
2.30.2



2023-05-22 14:40:32

by Astrid Rost

[permalink] [raw]
Subject: [PATCH v4 2/7] iio: light: vcnl4000: Add proximity ps_it for vcnl4200

Add ps_it attributes for vcnl4200 (similar to vcnl4040).
Add read/write attribute for proximity integration time.
Read attribute for available proximity integration times.
Change sampling rate depending on integration time.

Signed-off-by: Astrid Rost <[email protected]>
---
drivers/iio/light/vcnl4000.c | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 565b9c9ea470..086a493fb6e5 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -124,6 +124,15 @@ static const int vcnl4040_ps_it_times[][2] = {
{0, 800},
};

+static const int vcnl4200_ps_it_times[][2] = {
+ {0, 96},
+ {0, 144},
+ {0, 192},
+ {0, 384},
+ {0, 768},
+ {0, 864},
+};
+
#define VCNL4000_SLEEP_DELAY_MS 2000 /* before we enter pm_runtime_suspend */

enum vcnl4000_device_ids {
@@ -166,6 +175,8 @@ struct vcnl4000_chip_spec {
irqreturn_t (*irq_thread)(int irq, void *priv);
irqreturn_t (*trig_buffer_func)(int irq, void *priv);
u8 int_reg;
+ const int(*ps_it_times)[][2];
+ const int num_ps_it_times;
};

static const struct i2c_device_id vcnl4000_id[] = {
@@ -508,11 +519,11 @@ static int vcnl4040_read_ps_it(struct vcnl4000_data *data, int *val, int *val2)

ret = FIELD_GET(VCNL4040_PS_CONF2_PS_IT, ret);

- if (ret >= ARRAY_SIZE(vcnl4040_ps_it_times))
+ if (ret >= data->chip_spec->num_ps_it_times)
return -EINVAL;

- *val = vcnl4040_ps_it_times[ret][0];
- *val2 = vcnl4040_ps_it_times[ret][1];
+ *val = (*data->chip_spec->ps_it_times)[ret][0];
+ *val2 = (*data->chip_spec->ps_it_times)[ret][1];

return 0;
}
@@ -523,8 +534,8 @@ static ssize_t vcnl4040_write_ps_it(struct vcnl4000_data *data, int val)
int ret, index = -1;
u16 regval;

- for (i = 0; i < ARRAY_SIZE(vcnl4040_ps_it_times); i++) {
- if (val == vcnl4040_ps_it_times[i][1]) {
+ for (i = 0; i < data->chip_spec->num_ps_it_times; i++) {
+ if (val == (*data->chip_spec->ps_it_times)[i][1]) {
index = i;
break;
}
@@ -533,6 +544,8 @@ static ssize_t vcnl4040_write_ps_it(struct vcnl4000_data *data, int val)
if (index < 0)
return -EINVAL;

+ data->vcnl4200_ps.sampling_rate = ktime_set(0, val * 60000);
+
mutex_lock(&data->vcnl4000_lock);

ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
@@ -620,11 +633,13 @@ static int vcnl4040_read_avail(struct iio_dev *indio_dev,
const int **vals, int *type, int *length,
long mask)
{
+ struct vcnl4000_data *data = iio_priv(indio_dev);
+
switch (mask) {
case IIO_CHAN_INFO_INT_TIME:
- *vals = (int *)vcnl4040_ps_it_times;
+ *vals = (int *)(*data->chip_spec->ps_it_times);
*type = IIO_VAL_INT_PLUS_MICRO;
- *length = 2 * ARRAY_SIZE(vcnl4040_ps_it_times);
+ *length = 2 * data->chip_spec->num_ps_it_times;
return IIO_AVAIL_LIST;
default:
return -EINVAL;
@@ -1317,6 +1332,8 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
.info = &vcnl4040_info,
.irq_thread = vcnl4040_irq_thread,
.int_reg = VCNL4040_INT_FLAGS,
+ .ps_it_times = &vcnl4040_ps_it_times,
+ .num_ps_it_times = ARRAY_SIZE(vcnl4040_ps_it_times),
},
[VCNL4200] = {
.prod = "VCNL4200",
@@ -1329,6 +1346,8 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
.info = &vcnl4040_info,
.irq_thread = vcnl4040_irq_thread,
.int_reg = VCNL4200_INT_FLAGS,
+ .ps_it_times = &vcnl4200_ps_it_times,
+ .num_ps_it_times = ARRAY_SIZE(vcnl4200_ps_it_times),
},
};

--
2.30.2


2023-05-22 14:48:50

by Astrid Rost

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

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.

Signed-off-by: Astrid Rost <[email protected]>
---
drivers/iio/light/vcnl4000.c | 84 ++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 4fd4d4ef5990..67d5d0e14bcd 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -61,6 +61,7 @@

#define VCNL4200_AL_CONF 0x00 /* Ambient light configuration */
#define VCNL4200_PS_CONF1 0x03 /* Proximity configuration */
+#define VCNL4200_PS_CONF3 0x04 /* Proximity configuration */
#define VCNL4040_PS_THDL_LM 0x06 /* Proximity threshold low */
#define VCNL4040_PS_THDH_LM 0x07 /* Proximity threshold high */
#define VCNL4040_ALS_THDL_LM 0x02 /* Ambient light threshold low */
@@ -90,6 +91,7 @@
#define VCNL4040_PS_CONF2_PS_IT GENMASK(3, 1) /* Proximity integration time */
#define VCNL4040_CONF1_PS_PERS GENMASK(5, 4) /* Proximity interrupt persistence setting */
#define VCNL4040_PS_CONF2_PS_INT GENMASK(9, 8) /* Proximity interrupt mode */
+#define VCNL4040_PS_CONF3_MPS GENMASK(6, 5) /* Proximity multi pulse number */
#define VCNL4040_PS_IF_AWAY BIT(8) /* Proximity event cross low threshold */
#define VCNL4040_PS_IF_CLOSE BIT(9) /* Proximity event cross high threshold */
#define VCNL4040_ALS_RISING BIT(12) /* Ambient Light cross high threshold */
@@ -157,6 +159,7 @@ static const int vcnl4200_als_it_times[][2] = {
};
static const int vcnl4040_als_persistence[] = {1, 2, 4, 8};
static const int vcnl4040_ps_persistence[] = {1, 2, 3, 4};
+static const int vcnl4040_ps_oversampling_ratio[] = {1, 2, 4, 8};

#define VCNL4000_SLEEP_DELAY_MS 2000 /* before we enter pm_runtime_suspend */

@@ -778,6 +781,56 @@ static ssize_t vcnl4040_write_ps_period(struct vcnl4000_data *data, int val, int
return ret;
}

+static ssize_t vcnl4040_read_ps_oversampling_ratio(struct vcnl4000_data *data, int *val)
+{
+ int ret;
+
+ ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF3);
+ if (ret < 0)
+ return ret;
+
+ ret = FIELD_GET(VCNL4040_PS_CONF3_MPS, ret);
+
+ if (ret >= ARRAY_SIZE(vcnl4040_ps_oversampling_ratio))
+ return -EINVAL;
+
+ *val = vcnl4040_ps_oversampling_ratio[ret];
+
+ return ret;
+}
+
+static ssize_t vcnl4040_write_ps_oversampling_ratio(struct vcnl4000_data *data, int val)
+{
+ unsigned int i;
+ int ret, index = -1;
+ 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:
+ mutex_unlock(&data->vcnl4000_lock);
+ return ret;
+}
+
static int vcnl4000_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
@@ -828,6 +881,17 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
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;
+ }
+
default:
return -EINVAL;
}
@@ -851,6 +915,13 @@ static int vcnl4040_write_raw(struct iio_dev *indio_dev,
default:
return -EINVAL;
}
+ case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+ switch (chan->type) {
+ case IIO_PROXIMITY:
+ return vcnl4040_write_ps_oversampling_ratio(data, val);
+ default:
+ return -EINVAL;
+ }
default:
return -EINVAL;
}
@@ -880,6 +951,16 @@ static int vcnl4040_read_avail(struct iio_dev *indio_dev,
}
*type = IIO_VAL_INT_PLUS_MICRO;
return IIO_AVAIL_LIST;
+ case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
+ switch (chan->type) {
+ case IIO_PROXIMITY:
+ *vals = (int *)vcnl4040_ps_oversampling_ratio;
+ *length = ARRAY_SIZE(vcnl4040_ps_oversampling_ratio);
+ *type = IIO_VAL_INT;
+ return IIO_AVAIL_LIST;
+ default:
+ return -EINVAL;
+ }
default:
return -EINVAL;
}
@@ -1648,6 +1729,9 @@ static const struct iio_chan_spec vcnl4040_channels[] = {
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
BIT(IIO_CHAN_INFO_INT_TIME),
.info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME),
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
+ .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME) |
+ BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
.ext_info = vcnl4000_ext_info,
.event_spec = vcnl4040_event_spec,
.num_event_specs = ARRAY_SIZE(vcnl4040_event_spec),
--
2.30.2


2023-05-22 14:51:33

by Astrid Rost

[permalink] [raw]
Subject: [PATCH v4 1/7] iio: light: vcnl4000: Add proximity irq for vcnl4200

Add proximity interrupt support for vcnl4200 (similar to vcnl4040).
Add support to configure proximity sensor interrupts and threshold
limits. If an interrupt is detected an event will be pushed to the
event interface.

Signed-off-by: Astrid Rost <[email protected]>
---
drivers/iio/light/vcnl4000.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/light/vcnl4000.c b/drivers/iio/light/vcnl4000.c
index 56d3963d3d66..565b9c9ea470 100644
--- a/drivers/iio/light/vcnl4000.c
+++ b/drivers/iio/light/vcnl4000.c
@@ -65,6 +65,7 @@
#define VCNL4200_PS_DATA 0x08 /* Proximity data */
#define VCNL4200_AL_DATA 0x09 /* Ambient light data */
#define VCNL4040_INT_FLAGS 0x0b /* Interrupt register */
+#define VCNL4200_INT_FLAGS 0x0d /* Interrupt register */
#define VCNL4200_DEV_ID 0x0e /* Device ID, slave address and version */

#define VCNL4040_DEV_ID 0x0c /* Device ID and version */
@@ -164,6 +165,7 @@ struct vcnl4000_chip_spec {
int (*set_power_state)(struct vcnl4000_data *data, bool on);
irqreturn_t (*irq_thread)(int irq, void *priv);
irqreturn_t (*trig_buffer_func)(int irq, void *priv);
+ u8 int_reg;
};

static const struct i2c_device_id vcnl4000_id[] = {
@@ -1005,7 +1007,7 @@ static irqreturn_t vcnl4040_irq_thread(int irq, void *p)
struct vcnl4000_data *data = iio_priv(indio_dev);
int ret;

- ret = i2c_smbus_read_word_data(data->client, VCNL4040_INT_FLAGS);
+ ret = i2c_smbus_read_word_data(data->client, data->chip_spec->int_reg);
if (ret < 0)
return IRQ_HANDLED;

@@ -1314,6 +1316,7 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
.num_channels = ARRAY_SIZE(vcnl4040_channels),
.info = &vcnl4040_info,
.irq_thread = vcnl4040_irq_thread,
+ .int_reg = VCNL4040_INT_FLAGS,
},
[VCNL4200] = {
.prod = "VCNL4200",
@@ -1321,9 +1324,11 @@ static const struct vcnl4000_chip_spec vcnl4000_chip_spec_cfg[] = {
.measure_light = vcnl4200_measure_light,
.measure_proximity = vcnl4200_measure_proximity,
.set_power_state = vcnl4200_set_power_state,
- .channels = vcnl4000_channels,
+ .channels = vcnl4040_channels,
.num_channels = ARRAY_SIZE(vcnl4000_channels),
- .info = &vcnl4000_info,
+ .info = &vcnl4040_info,
+ .irq_thread = vcnl4040_irq_thread,
+ .int_reg = VCNL4200_INT_FLAGS,
},
};

--
2.30.2


2023-05-28 18:57:16

by Jonathan Cameron

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

On Mon, 22 May 2023 16:26:20 +0200
Astrid Rost <[email protected]> wrote:

> 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.
>
> Signed-off-by: Astrid Rost <[email protected]>

I applied the series and did a build test which showed me...

> @@ -1648,6 +1729,9 @@ static const struct iio_chan_spec vcnl4040_channels[] = {
> .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> BIT(IIO_CHAN_INFO_INT_TIME),
> .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME),
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
> + .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME) |
> + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
Guessing a rebase went wrong?

I thought about just fixing this up by dropping the duplication, but given
I'm not 100% sure nothing else was affected, I'll leave it to you to fix up
and check for any other related issues for a v5.

Jonathan

> .ext_info = vcnl4000_ext_info,
> .event_spec = vcnl4040_event_spec,
> .num_event_specs = ARRAY_SIZE(vcnl4040_event_spec),


2023-05-28 19:05:09

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v4 0/7] iio: light: vcnl4000: Add features for vncl4040/4200

On Mon, 22 May 2023 16:26:14 +0200
Astrid Rost <[email protected]> wrote:

> Add a more complete support for vncl4040 and vcnl4200, which allows to
> change the distance of proximity detection and interrupt support for the
> illuminance sensor.

Something odd going on (superficially looks like a rebase mistake in patch 6)

CHECK drivers/iio/amplifiers/ad8366.c
In file included from ./include/linux/bits.h:6,
from ./include/linux/bitops.h:6,
from ./include/linux/kernel.h:22,
from ./arch/x86/include/asm/percpu.h:27,
from ./arch/x86/include/asm/current.h:10,
from ./arch/x86/include/asm/processor.h:17,
from ./arch/x86/include/asm/timex.h:5,
from ./include/linux/timex.h:67,
from ./include/linux/time32.h:13,
from ./include/linux/time.h:60,
from ./include/linux/stat.h:19,
from ./include/linux/module.h:13,
from drivers/iio/light/vcnl4000.c:21:
./include/vdso/bits.h:7:33: warning: initialized field overwritten [-Woverride-init]
7 | #define BIT(nr) (UL(1) << (nr))
| ^
drivers/iio/light/vcnl4000.c:1824:49: note: in expansion of macro ‘BIT’
1824 | .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME) |
| ^~~
./include/vdso/bits.h:7:33: note: (near initialization for ‘vcnl4040_channels[1].info_mask_separate_available’)
7 | #define BIT(nr) (UL(1) << (nr))
| ^
drivers/iio/light/vcnl4000.c:1824:49: note: in expansion of macro ‘BIT’
1824 | .info_mask_separate_available = BIT(IIO_CHAN_INFO_INT_TIME) |
| ^~~


>
> Proximity functionality:
> - Interrupt support (new on vcnl4200).
>
> Proximity reduce the amount of interrupts:
> - Adaptable integration time (new on vcnl4200) - the sampling rate
> changes according to this value.
> - Period - interrupt is asserted if the value is above or
> below a certain threshold.
>
> Proximity change the activity distance:
> - Oversampling ratio - Amount of LED pulses per measured raw value.
> - Calibration bias - LED current calibration of the sensor.
>
> Illuminance functionality:
> - Interrupt support.
>
> Illuminance reduce the amount of interrupts:
> - Adaptable integration time - the sampling rate and scale changes
> according to this value.
> - Period – interrupt is asserted if the value is above or
> below a certain threshold.
>
> changes v2:
> - [PATCH v2 3/7] Fixed calculation of al_scale.
> Fix the value of vcnl4040 according to the data-sheet.
> Use div_u64 for the division.
> scription for the branch
>
> changes v3:
> - [PATCH v3 1-3/7] Add differences between the chips as variables in
> chip-spec.
> - [PATCH v3 4/7] Changed commit message.
> - [PATCH v3 5/7] Use period instead of debounce time. This causes some
> calculations as the period is a time and the chip allows to set a certain
> amount of measurements above/below the threshold, before throwing an
> interrupt.
> - [PATCH v3 6/7] Changed commit message.
>
> changes v4:
> - [PATCH v3 1-3/7] Fix setting correct als_it for vcnl4040.
> - [PATCH v3 5/7] Use MICRO macro.
> Fix values greater than 1 s for the proximity period.
>
> Astrid Rost (7):
> [PATCH v4 1/7] iio: light: vcnl4000: Add proximity irq for vcnl4200
> [PATCH v4 2/7] iio: light: vcnl4000: Add proximity ps_it for vcnl4200
> [PATCH v4 3/7] iio: light: vcnl4000: Add als_it for vcnl4040/4200
> [PATCH v4 4/7] iio: light: vcnl4000: add illuminance irq vcnl4040/4200
> [PATCH v4 5/7] iio: light: vcnl4000: Add period for vcnl4040/4200
> [PATCH v4 6/7] iio: light: vcnl4000: Add oversampling_ratio for 4040/4200
> [PATCH v4 7/7] iio: light: vcnl4000: Add calibration bias for 4040/4200
>
> drivers/iio/light/vcnl4000.c | 721 +++++++++++++++++++++++++++++++----
> 1 file changed, 653 insertions(+), 68 deletions(-)
>


2023-05-29 06:13:44

by Andy Shevchenko

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

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