staging:iio:cdc:ad7150: use swapped reads/writes for i2c rather than open coding

Reduces boilerplate and chances of getting the error handling wrong.
No functional change.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: Barry Song <song.bao.hua@hisilicon>
Link: https://lore.kernel.org/r/20210314181511.531414-2-jic23@kernel.org
This commit is contained in:
Jonathan Cameron 2021-03-14 18:14:48 +00:00
parent a71654af0a
commit add538f4be

View File

@ -109,18 +109,20 @@ static int ad7150_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
ret = i2c_smbus_read_word_data(chip->client, ret = i2c_smbus_read_word_swapped(chip->client,
ad7150_addresses[channel][0]); ad7150_addresses[channel][0]);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = swab16(ret); *val = ret;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_AVERAGE_RAW: case IIO_CHAN_INFO_AVERAGE_RAW:
ret = i2c_smbus_read_word_data(chip->client, ret = i2c_smbus_read_word_swapped(chip->client,
ad7150_addresses[channel][1]); ad7150_addresses[channel][1]);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = swab16(ret); *val = ret;
return IIO_VAL_INT; return IIO_VAL_INT;
default: default:
return -EINVAL; return -EINVAL;
@ -188,9 +190,9 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev,
/* Note completely different from the adaptive versions */ /* Note completely different from the adaptive versions */
case IIO_EV_TYPE_THRESH: case IIO_EV_TYPE_THRESH:
value = chip->threshold[rising][chan]; value = chip->threshold[rising][chan];
return i2c_smbus_write_word_data(chip->client, return i2c_smbus_write_word_swapped(chip->client,
ad7150_addresses[chan][3], ad7150_addresses[chan][3],
swab16(value)); value);
case IIO_EV_TYPE_MAG_ADAPTIVE: case IIO_EV_TYPE_MAG_ADAPTIVE:
sens = chip->mag_sensitivity[rising][chan]; sens = chip->mag_sensitivity[rising][chan];
timeout = chip->mag_timeout[rising][chan]; timeout = chip->mag_timeout[rising][chan];