iio: ti-ads1015: Remove shift variable ads1015_read_raw
authorGwendal Grignou <gwendal@chromium.org>
Thu, 4 Nov 2021 08:24:11 +0000 (01:24 -0700)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 17 Nov 2021 17:51:43 +0000 (17:51 +0000)
By using scan_type.realbits when processing raw data,
we use scan_type.shit only once, thus we don't need to define a local
variable for it anymore.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Link: https://lore.kernel.org/r/20211104082413.3681212-12-gwendal@chromium.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ti-ads1015.c

index b0352e91ac1653f54ef78efa783636175ed1652d..b92d4cd1b8238b2b0d032143cafc729f4a21a0ce 100644 (file)
@@ -464,9 +464,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
 
        mutex_lock(&data->lock);
        switch (mask) {
-       case IIO_CHAN_INFO_RAW: {
-               int shift = chan->scan_type.shift;
-
+       case IIO_CHAN_INFO_RAW:
                ret = iio_device_claim_direct_mode(indio_dev);
                if (ret)
                        break;
@@ -487,7 +485,8 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
                        goto release_direct;
                }
 
-               *val = sign_extend32(*val >> shift, 15 - shift);
+               *val = sign_extend32(*val >> chan->scan_type.shift,
+                                    chan->scan_type.realbits - 1);
 
                ret = ads1015_set_power_state(data, false);
                if (ret < 0)
@@ -497,7 +496,6 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
 release_direct:
                iio_device_release_direct_mode(indio_dev);
                break;
-       }
        case IIO_CHAN_INFO_SCALE:
                idx = data->channel_data[chan->address].pga;
                *val = ads1015_fullscale_range[idx];