Commit 2be17b68 authored by Astrid Rost's avatar Astrid Rost Committed by Jonathan Cameron

iio: light: vcnl4000: Check type with switch case

Check IIO_PROXIMITY  with switch case in order to make it easier
to add further types like light.
Add check for IIO_EV_INFO_VALUE for writing rising or falling events.
Signed-off-by: default avatarAstrid Rost <astrid.rost@axis.com>
Link: https://lore.kernel.org/r/20230613135025.2596641-4-astrid.rost@axis.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent e55c96da
...@@ -600,9 +600,13 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev, ...@@ -600,9 +600,13 @@ static int vcnl4000_read_raw(struct iio_dev *indio_dev,
*val2 = data->al_scale; *val2 = data->al_scale;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_INT_TIME: case IIO_CHAN_INFO_INT_TIME:
if (chan->type != IIO_PROXIMITY) switch (chan->type) {
return -EINVAL; case IIO_PROXIMITY:
ret = vcnl4040_read_ps_it(data, val, val2); ret = vcnl4040_read_ps_it(data, val, val2);
break;
default:
return -EINVAL;
}
if (ret < 0) if (ret < 0)
return ret; return ret;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
...@@ -621,12 +625,15 @@ static int vcnl4040_write_raw(struct iio_dev *indio_dev, ...@@ -621,12 +625,15 @@ static int vcnl4040_write_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_INT_TIME: case IIO_CHAN_INFO_INT_TIME:
if (val != 0) if (val != 0)
return -EINVAL; return -EINVAL;
if (chan->type != IIO_PROXIMITY) switch (chan->type) {
return -EINVAL; case IIO_PROXIMITY:
return vcnl4040_write_ps_it(data, val2); return vcnl4040_write_ps_it(data, val2);
default: default:
return -EINVAL; return -EINVAL;
} }
default:
return -EINVAL;
}
} }
static int vcnl4040_read_avail(struct iio_dev *indio_dev, static int vcnl4040_read_avail(struct iio_dev *indio_dev,
...@@ -638,9 +645,15 @@ static int vcnl4040_read_avail(struct iio_dev *indio_dev, ...@@ -638,9 +645,15 @@ static int vcnl4040_read_avail(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_INT_TIME: case IIO_CHAN_INFO_INT_TIME:
switch (chan->type) {
case IIO_PROXIMITY:
*vals = (int *)(*data->chip_spec->ps_it_times); *vals = (int *)(*data->chip_spec->ps_it_times);
*type = IIO_VAL_INT_PLUS_MICRO;
*length = 2 * data->chip_spec->num_ps_it_times; *length = 2 * data->chip_spec->num_ps_it_times;
break;
default:
return -EINVAL;
}
*type = IIO_VAL_INT_PLUS_MICRO;
return IIO_AVAIL_LIST; return IIO_AVAIL_LIST;
default: default:
return -EINVAL; return -EINVAL;
...@@ -836,24 +849,34 @@ static int vcnl4040_read_event(struct iio_dev *indio_dev, ...@@ -836,24 +849,34 @@ static int vcnl4040_read_event(struct iio_dev *indio_dev,
int ret; int ret;
struct vcnl4000_data *data = iio_priv(indio_dev); struct vcnl4000_data *data = iio_priv(indio_dev);
switch (chan->type) {
case IIO_PROXIMITY:
switch (info) {
case IIO_EV_INFO_VALUE:
switch (dir) { switch (dir) {
case IIO_EV_DIR_RISING: case IIO_EV_DIR_RISING:
ret = i2c_smbus_read_word_data(data->client, ret = i2c_smbus_read_word_data(data->client,
VCNL4040_PS_THDH_LM); VCNL4040_PS_THDH_LM);
if (ret < 0) break;
return ret;
*val = ret;
return IIO_VAL_INT;
case IIO_EV_DIR_FALLING: case IIO_EV_DIR_FALLING:
ret = i2c_smbus_read_word_data(data->client, ret = i2c_smbus_read_word_data(data->client,
VCNL4040_PS_THDL_LM); VCNL4040_PS_THDL_LM);
break;
default:
return -EINVAL;
}
break;
default:
return -EINVAL;
}
break;
default:
return -EINVAL;
}
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = ret; *val = ret;
return IIO_VAL_INT; return IIO_VAL_INT;
default:
return -EINVAL;
}
} }
static int vcnl4040_write_event(struct iio_dev *indio_dev, static int vcnl4040_write_event(struct iio_dev *indio_dev,
...@@ -866,22 +889,35 @@ static int vcnl4040_write_event(struct iio_dev *indio_dev, ...@@ -866,22 +889,35 @@ static int vcnl4040_write_event(struct iio_dev *indio_dev,
int ret; int ret;
struct vcnl4000_data *data = iio_priv(indio_dev); struct vcnl4000_data *data = iio_priv(indio_dev);
switch (chan->type) {
case IIO_PROXIMITY:
switch (info) {
case IIO_EV_INFO_VALUE:
switch (dir) { switch (dir) {
case IIO_EV_DIR_RISING: case IIO_EV_DIR_RISING:
ret = i2c_smbus_write_word_data(data->client, ret = i2c_smbus_write_word_data(data->client,
VCNL4040_PS_THDH_LM, val); VCNL4040_PS_THDH_LM,
if (ret < 0) val);
return ret; break;
return IIO_VAL_INT;
case IIO_EV_DIR_FALLING: case IIO_EV_DIR_FALLING:
ret = i2c_smbus_write_word_data(data->client, ret = i2c_smbus_write_word_data(data->client,
VCNL4040_PS_THDL_LM, val); VCNL4040_PS_THDL_LM,
if (ret < 0) val);
return ret; break;
return IIO_VAL_INT; default:
return -EINVAL;
}
break;
default: default:
return -EINVAL; return -EINVAL;
} }
break;
default:
return -EINVAL;
}
if (ret < 0)
return ret;
return IIO_VAL_INT;
} }
static bool vcnl4010_is_thr_enabled(struct vcnl4000_data *data) static bool vcnl4010_is_thr_enabled(struct vcnl4000_data *data)
...@@ -974,6 +1010,8 @@ static int vcnl4040_read_event_config(struct iio_dev *indio_dev, ...@@ -974,6 +1010,8 @@ static int vcnl4040_read_event_config(struct iio_dev *indio_dev,
int ret; int ret;
struct vcnl4000_data *data = iio_priv(indio_dev); struct vcnl4000_data *data = iio_priv(indio_dev);
switch (chan->type) {
case IIO_PROXIMITY:
ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -983,6 +1021,9 @@ static int vcnl4040_read_event_config(struct iio_dev *indio_dev, ...@@ -983,6 +1021,9 @@ static int vcnl4040_read_event_config(struct iio_dev *indio_dev,
return (dir == IIO_EV_DIR_RISING) ? return (dir == IIO_EV_DIR_RISING) ?
FIELD_GET(VCNL4040_PS_IF_AWAY, ret) : FIELD_GET(VCNL4040_PS_IF_AWAY, ret) :
FIELD_GET(VCNL4040_PS_IF_CLOSE, ret); FIELD_GET(VCNL4040_PS_IF_CLOSE, ret);
default:
return -EINVAL;
}
} }
static int vcnl4040_write_event_config(struct iio_dev *indio_dev, static int vcnl4040_write_event_config(struct iio_dev *indio_dev,
...@@ -990,12 +1031,14 @@ static int vcnl4040_write_event_config(struct iio_dev *indio_dev, ...@@ -990,12 +1031,14 @@ static int vcnl4040_write_event_config(struct iio_dev *indio_dev,
enum iio_event_type type, enum iio_event_type type,
enum iio_event_direction dir, int state) enum iio_event_direction dir, int state)
{ {
int ret; int ret = -EINVAL;
u16 val, mask; u16 val, mask;
struct vcnl4000_data *data = iio_priv(indio_dev); struct vcnl4000_data *data = iio_priv(indio_dev);
mutex_lock(&data->vcnl4000_lock); mutex_lock(&data->vcnl4000_lock);
switch (chan->type) {
case IIO_PROXIMITY:
ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1); ret = i2c_smbus_read_word_data(data->client, VCNL4200_PS_CONF1);
if (ret < 0) if (ret < 0)
goto out; goto out;
...@@ -1008,7 +1051,12 @@ static int vcnl4040_write_event_config(struct iio_dev *indio_dev, ...@@ -1008,7 +1051,12 @@ static int vcnl4040_write_event_config(struct iio_dev *indio_dev,
val = state ? (ret | mask) : (ret & ~mask); val = state ? (ret | mask) : (ret & ~mask);
data->ps_int = FIELD_GET(VCNL4040_PS_CONF2_PS_INT, val); data->ps_int = FIELD_GET(VCNL4040_PS_CONF2_PS_INT, val);
ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1, val); ret = i2c_smbus_write_word_data(data->client, VCNL4200_PS_CONF1,
val);
break;
default:
break;
}
out: out:
mutex_unlock(&data->vcnl4000_lock); mutex_unlock(&data->vcnl4000_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment