Commit f53199c0 authored by Gwendal Grignou's avatar Gwendal Grignou Committed by Jonathan Cameron

iio: cros_ec: Remove replacing error code with -EIO

Due to an API misread, error code can be different for -EIO when reading
a sysfs entry. Return the error reported by the cros_ec stack.

Check the proper error message (protocol error, not supported) is
reported when there is an error returned by the EC stack.
Signed-off-by: default avatarGwendal Grignou <gwendal@chromium.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent ed1f2e85
...@@ -33,6 +33,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, ...@@ -33,6 +33,7 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
struct cros_ec_sensors_core_state *state = iio_priv(indio_dev); struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent); struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent);
struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev); struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
int ret;
platform_set_drvdata(pdev, indio_dev); platform_set_drvdata(pdev, indio_dev);
...@@ -60,9 +61,10 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, ...@@ -60,9 +61,10 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
state->param.cmd = MOTIONSENSE_CMD_INFO; state->param.cmd = MOTIONSENSE_CMD_INFO;
state->param.info.sensor_num = sensor_platform->sensor_num; state->param.info.sensor_num = sensor_platform->sensor_num;
if (cros_ec_motion_send_host_cmd(state, 0)) { ret = cros_ec_motion_send_host_cmd(state, 0);
if (ret) {
dev_warn(dev, "Can not access sensor info\n"); dev_warn(dev, "Can not access sensor info\n");
return -EIO; return ret;
} }
state->type = state->resp->info.type; state->type = state->resp->info.type;
state->loc = state->resp->info.location; state->loc = state->resp->info.location;
...@@ -86,7 +88,7 @@ int cros_ec_motion_send_host_cmd(struct cros_ec_sensors_core_state *state, ...@@ -86,7 +88,7 @@ int cros_ec_motion_send_host_cmd(struct cros_ec_sensors_core_state *state,
ret = cros_ec_cmd_xfer_status(state->ec, state->msg); ret = cros_ec_cmd_xfer_status(state->ec, state->msg);
if (ret < 0) if (ret < 0)
return -EIO; return ret;
if (ret && if (ret &&
state->resp != (struct ec_response_motion_sense *)state->msg->data) state->resp != (struct ec_response_motion_sense *)state->msg->data)
...@@ -396,7 +398,7 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st, ...@@ -396,7 +398,7 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
int *val, int *val2, long mask) int *val, int *val2, long mask)
{ {
int ret = IIO_VAL_INT; int ret;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
...@@ -404,22 +406,27 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st, ...@@ -404,22 +406,27 @@ int cros_ec_sensors_core_read(struct cros_ec_sensors_core_state *st,
st->param.ec_rate.data = st->param.ec_rate.data =
EC_MOTION_SENSE_NO_VALUE; EC_MOTION_SENSE_NO_VALUE;
if (cros_ec_motion_send_host_cmd(st, 0)) ret = cros_ec_motion_send_host_cmd(st, 0);
ret = -EIO; if (ret)
else break;
*val = st->resp->ec_rate.ret; *val = st->resp->ec_rate.ret;
ret = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_FREQUENCY: case IIO_CHAN_INFO_FREQUENCY:
st->param.cmd = MOTIONSENSE_CMD_SENSOR_ODR; st->param.cmd = MOTIONSENSE_CMD_SENSOR_ODR;
st->param.sensor_odr.data = st->param.sensor_odr.data =
EC_MOTION_SENSE_NO_VALUE; EC_MOTION_SENSE_NO_VALUE;
if (cros_ec_motion_send_host_cmd(st, 0)) ret = cros_ec_motion_send_host_cmd(st, 0);
ret = -EIO; if (ret)
else break;
*val = st->resp->sensor_odr.ret; *val = st->resp->sensor_odr.ret;
ret = IIO_VAL_INT;
break; break;
default: default:
ret = -EINVAL;
break; break;
} }
...@@ -431,7 +438,7 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, ...@@ -431,7 +438,7 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
int val, int val2, long mask) int val, int val2, long mask)
{ {
int ret = 0; int ret;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_FREQUENCY: case IIO_CHAN_INFO_FREQUENCY:
...@@ -441,16 +448,15 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, ...@@ -441,16 +448,15 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st,
/* Always roundup, so caller gets at least what it asks for. */ /* Always roundup, so caller gets at least what it asks for. */
st->param.sensor_odr.roundup = 1; st->param.sensor_odr.roundup = 1;
if (cros_ec_motion_send_host_cmd(st, 0)) ret = cros_ec_motion_send_host_cmd(st, 0);
ret = -EIO;
break; break;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
st->param.cmd = MOTIONSENSE_CMD_EC_RATE; st->param.cmd = MOTIONSENSE_CMD_EC_RATE;
st->param.ec_rate.data = val; st->param.ec_rate.data = val;
if (cros_ec_motion_send_host_cmd(st, 0)) ret = cros_ec_motion_send_host_cmd(st, 0);
ret = -EIO; if (ret)
else break;
st->curr_sampl_freq = val; st->curr_sampl_freq = val;
break; break;
default: default:
......
...@@ -42,7 +42,7 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev, ...@@ -42,7 +42,7 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
struct cros_ec_light_prox_state *st = iio_priv(indio_dev); struct cros_ec_light_prox_state *st = iio_priv(indio_dev);
u16 data = 0; u16 data = 0;
s64 val64; s64 val64;
int ret = IIO_VAL_INT; int ret;
int idx = chan->scan_index; int idx = chan->scan_index;
mutex_lock(&st->core.cmd_lock); mutex_lock(&st->core.cmd_lock);
...@@ -50,23 +50,22 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev, ...@@ -50,23 +50,22 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
if (chan->type == IIO_PROXIMITY) { if (chan->type == IIO_PROXIMITY) {
if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, ret = cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
(s16 *)&data) < 0) { (s16 *)&data);
ret = -EIO; if (ret)
break; break;
}
*val = data; *val = data;
ret = IIO_VAL_INT;
} else { } else {
ret = -EINVAL; ret = -EINVAL;
} }
break; break;
case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_PROCESSED:
if (chan->type == IIO_LIGHT) { if (chan->type == IIO_LIGHT) {
if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, ret = cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
(s16 *)&data) < 0) { (s16 *)&data);
ret = -EIO; if (ret)
break; break;
}
/* /*
* The data coming from the light sensor is * The data coming from the light sensor is
* pre-processed and represents the ambient light * pre-processed and represents the ambient light
...@@ -82,16 +81,16 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev, ...@@ -82,16 +81,16 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET;
st->core.param.sensor_offset.flags = 0; st->core.param.sensor_offset.flags = 0;
if (cros_ec_motion_send_host_cmd(&st->core, 0)) { ret = cros_ec_motion_send_host_cmd(&st->core, 0);
ret = -EIO; if (ret)
break; break;
}
/* Save values */ /* Save values */
st->core.calib[0].offset = st->core.calib[0].offset =
st->core.resp->sensor_offset.offset[0]; st->core.resp->sensor_offset.offset[0];
*val = st->core.calib[idx].offset; *val = st->core.calib[idx].offset;
ret = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_CALIBSCALE: case IIO_CHAN_INFO_CALIBSCALE:
/* /*
...@@ -102,10 +101,9 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev, ...@@ -102,10 +101,9 @@ static int cros_ec_light_prox_read(struct iio_dev *indio_dev,
st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE; st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE;
if (cros_ec_motion_send_host_cmd(&st->core, 0)) { ret = cros_ec_motion_send_host_cmd(&st->core, 0);
ret = -EIO; if (ret)
break; break;
}
val64 = st->core.resp->sensor_range.ret; val64 = st->core.resp->sensor_range.ret;
*val = val64 >> 16; *val = val64 >> 16;
...@@ -128,7 +126,7 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev, ...@@ -128,7 +126,7 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev,
int val, int val2, long mask) int val, int val2, long mask)
{ {
struct cros_ec_light_prox_state *st = iio_priv(indio_dev); struct cros_ec_light_prox_state *st = iio_priv(indio_dev);
int ret = 0; int ret;
int idx = chan->scan_index; int idx = chan->scan_index;
mutex_lock(&st->core.cmd_lock); mutex_lock(&st->core.cmd_lock);
...@@ -143,14 +141,12 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev, ...@@ -143,14 +141,12 @@ static int cros_ec_light_prox_write(struct iio_dev *indio_dev,
st->core.calib[0].offset; st->core.calib[0].offset;
st->core.param.sensor_offset.temp = st->core.param.sensor_offset.temp =
EC_MOTION_SENSE_INVALID_CALIB_TEMP; EC_MOTION_SENSE_INVALID_CALIB_TEMP;
if (cros_ec_motion_send_host_cmd(&st->core, 0)) ret = cros_ec_motion_send_host_cmd(&st->core, 0);
ret = -EIO;
break; break;
case IIO_CHAN_INFO_CALIBSCALE: case IIO_CHAN_INFO_CALIBSCALE:
st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
st->core.param.sensor_range.data = (val << 16) | (val2 / 100); st->core.param.sensor_range.data = (val << 16) | (val2 / 100);
if (cros_ec_motion_send_host_cmd(&st->core, 0)) ret = cros_ec_motion_send_host_cmd(&st->core, 0);
ret = -EIO;
break; break;
default: default:
ret = cros_ec_sensors_core_write(&st->core, chan, val, val2, ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,
......
...@@ -39,26 +39,29 @@ static int cros_ec_baro_read(struct iio_dev *indio_dev, ...@@ -39,26 +39,29 @@ static int cros_ec_baro_read(struct iio_dev *indio_dev,
{ {
struct cros_ec_baro_state *st = iio_priv(indio_dev); struct cros_ec_baro_state *st = iio_priv(indio_dev);
u16 data = 0; u16 data = 0;
int ret = IIO_VAL_INT; int ret;
int idx = chan->scan_index; int idx = chan->scan_index;
mutex_lock(&st->core.cmd_lock); mutex_lock(&st->core.cmd_lock);
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, ret = cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
(s16 *)&data) < 0) (s16 *)&data);
ret = -EIO; if (ret)
break;
*val = data; *val = data;
ret = IIO_VAL_INT;
break; break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE; st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE;
if (cros_ec_motion_send_host_cmd(&st->core, 0)) { ret = cros_ec_motion_send_host_cmd(&st->core, 0);
ret = -EIO; if (ret)
break; break;
}
*val = st->core.resp->sensor_range.ret; *val = st->core.resp->sensor_range.ret;
/* scale * in_pressure_raw --> kPa */ /* scale * in_pressure_raw --> kPa */
......
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