diff options
author | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2021-03-14 18:14:50 +0000 |
---|---|---|
committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2021-04-07 08:36:35 +0100 |
commit | 0c4c4a868ab4af5886d070379b5964d1e0835c19 (patch) | |
tree | 3525ff3a5ae7bd62da97093afbd23f673bd1fe76 /drivers/staging/iio | |
parent | 1a17e7cbbffaac98ac62bf0fa5b6eb2f65fb5ade (diff) |
staging:iio:cdc:ad7150: Refactor event parameter update
Original code was ordered in a fairly unituitive fashion with
the non adaptive threshold handling returning from the switch
statement, whilst the adapative path did the actual writes outside
the switch. Make it more readable by bringing everything within
the switch statement cases and reducing scope of local variables
as appropriate.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20210314181511.531414-4-jic23@kernel.org
Diffstat (limited to 'drivers/staging/iio')
-rw-r--r-- | drivers/staging/iio/cdc/ad7150.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 4dac4aaec0cf..d6a7bfd94f1c 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -163,9 +163,6 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, enum iio_event_type type, enum iio_event_direction dir) { - int ret; - u16 value; - u8 sens, timeout; struct ad7150_chip_info *chip = iio_priv(indio_dev); int rising = (dir == IIO_EV_DIR_RISING); u64 event_code; @@ -177,26 +174,31 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, switch (type) { /* Note completely different from the adaptive versions */ - case IIO_EV_TYPE_THRESH: - value = chip->threshold[rising][chan]; + case IIO_EV_TYPE_THRESH: { + u16 value = chip->threshold[rising][chan]; return i2c_smbus_write_word_swapped(chip->client, ad7150_addresses[chan][3], value); - case IIO_EV_TYPE_THRESH_ADAPTIVE: + } + case IIO_EV_TYPE_THRESH_ADAPTIVE: { + int ret; + u8 sens, timeout; + sens = chip->thresh_sensitivity[rising][chan]; + ret = i2c_smbus_write_byte_data(chip->client, + ad7150_addresses[chan][4], + sens); + if (ret) + return ret; + timeout = chip->thresh_timeout[rising][chan]; - break; + return i2c_smbus_write_byte_data(chip->client, + ad7150_addresses[chan][5], + timeout); + } default: return -EINVAL; } - ret = i2c_smbus_write_byte_data(chip->client, - ad7150_addresses[chan][4], - sens); - if (ret) - return ret; - return i2c_smbus_write_byte_data(chip->client, - ad7150_addresses[chan][5], - timeout); } static int ad7150_write_event_config(struct iio_dev *indio_dev, |