mirror of
https://github.com/torvalds/linux.git
synced 2024-12-01 00:21:32 +00:00
iio: mpl3115: Use scan_type.shift and realbit in mpl3115_read_raw
When processing raw data using channel scan_type.shift as source of trust to shift data appropriately. When processing the temperature channel, use a 16bit big endian variable as buffer to increase conversion readability. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Link: https://lore.kernel.org/r/20211104082413.3681212-14-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
fb3e8bb478
commit
7721c73d80
@ -74,7 +74,6 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
|
|||||||
int *val, int *val2, long mask)
|
int *val, int *val2, long mask)
|
||||||
{
|
{
|
||||||
struct mpl3115_data *data = iio_priv(indio_dev);
|
struct mpl3115_data *data = iio_priv(indio_dev);
|
||||||
__be32 tmp = 0;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (mask) {
|
switch (mask) {
|
||||||
@ -84,7 +83,9 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (chan->type) {
|
switch (chan->type) {
|
||||||
case IIO_PRESSURE: /* in 0.25 pascal / LSB */
|
case IIO_PRESSURE: { /* in 0.25 pascal / LSB */
|
||||||
|
__be32 tmp = 0;
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
ret = mpl3115_request(data);
|
ret = mpl3115_request(data);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -96,10 +97,13 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
|
|||||||
mutex_unlock(&data->lock);
|
mutex_unlock(&data->lock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
*val = be32_to_cpu(tmp) >> 12;
|
*val = be32_to_cpu(tmp) >> chan->scan_type.shift;
|
||||||
ret = IIO_VAL_INT;
|
ret = IIO_VAL_INT;
|
||||||
break;
|
break;
|
||||||
case IIO_TEMP: /* in 0.0625 celsius / LSB */
|
}
|
||||||
|
case IIO_TEMP: { /* in 0.0625 celsius / LSB */
|
||||||
|
__be16 tmp;
|
||||||
|
|
||||||
mutex_lock(&data->lock);
|
mutex_lock(&data->lock);
|
||||||
ret = mpl3115_request(data);
|
ret = mpl3115_request(data);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -111,9 +115,11 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
|
|||||||
mutex_unlock(&data->lock);
|
mutex_unlock(&data->lock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
break;
|
break;
|
||||||
*val = sign_extend32(be32_to_cpu(tmp) >> 20, 11);
|
*val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift,
|
||||||
|
chan->scan_type.realbits - 1);
|
||||||
ret = IIO_VAL_INT;
|
ret = IIO_VAL_INT;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user