Message ID | 20211101071822.522178-3-gwendal@chromium.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | iio: Use scan_type shift and realbits when processing raw data | expand |
On Mon, 1 Nov 2021 00:18:20 -0700 Gwendal Grignou <gwendal@chromium.org> wrote: > 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 Possibly Freudian typo.. > variable for it anymore. > > Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Otherwise looks fine to me and works for both realbits = 16, shift = 0 realbits = 12, shift = 4 Jonathan > --- > drivers/iio/adc/ti-ads1015.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c > index b0352e91ac165..b92d4cd1b8238 100644 > --- a/drivers/iio/adc/ti-ads1015.c > +++ b/drivers/iio/adc/ti-ads1015.c > @@ -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];
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c index b0352e91ac165..b92d4cd1b8238 100644 --- a/drivers/iio/adc/ti-ads1015.c +++ b/drivers/iio/adc/ti-ads1015.c @@ -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];
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> --- drivers/iio/adc/ti-ads1015.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)