Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1365591 > unrolled thread

[PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes

Started byIrina Tirdea <irina.tirdea@intel.com>
First post2016-03-28 19:20 +0200
Last post2016-03-29 14:40 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes Irina Tirdea <irina.tirdea@intel.com> - 2016-03-28 19:20 +0200
    Re: [PATCH 1/1] iio: accel: bmc150: fix endianness when reading  axes Peter Meerwald-Stadler <pmeerw@pmeerw.net> - 2016-03-28 19:50 +0200
      RE: [PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes "Tirdea, Irina" <irina.tirdea@intel.com> - 2016-03-29 14:40 +0200

#1365591 — [PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes

FromIrina Tirdea <irina.tirdea@intel.com>
Date2016-03-28 19:20 +0200
Subject[PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes
Message-ID<rhIZz-1I8-5@gated-at.bofh.it>
For big endian platforms, reading the axes will return
invalid values.

The device stores each axis value in a 16 bit little
endian register. The driver uses regmap_read_bulk to get
the axis value, resulting in a 16 bit little endian value.
This needs to be converted to cpu endianness to work
on big endian platforms.

Fix endianness for big endian platforms by converting
the values for the axes read from little endian to
cpu.

This is also partially fixed in commit b6fb9b6d6552 ("iio:
accel: bmc150: optimize transfers in trigger handler").

Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
---
 drivers/iio/accel/bmc150-accel-core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index c73331f7..5b64c3e 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -547,7 +547,7 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
 {
 	int ret;
 	int axis = chan->scan_index;
-	unsigned int raw_val;
+	__le16 raw_val;
 
 	mutex_lock(&data->mutex);
 	ret = bmc150_accel_set_power_state(data, true);
@@ -564,7 +564,7 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
 		mutex_unlock(&data->mutex);
 		return ret;
 	}
-	*val = sign_extend32(raw_val >> chan->scan_type.shift,
+	*val = sign_extend32(le16_to_cpu(raw_val) >> chan->scan_type.shift,
 			     chan->scan_type.realbits - 1);
 	ret = bmc150_accel_set_power_state(data, false);
 	mutex_unlock(&data->mutex);
@@ -988,6 +988,7 @@ static const struct iio_event_spec bmc150_accel_event = {
 		.realbits = (bits),					\
 		.storagebits = 16,					\
 		.shift = 16 - (bits),					\
+		.endianness = IIO_LE,					\
 	},								\
 	.event_spec = &bmc150_accel_event,				\
 	.num_event_specs = 1						\
-- 
1.9.1

[toc] | [next] | [standalone]


#1365611 — Re: [PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes

FromPeter Meerwald-Stadler <pmeerw@pmeerw.net>
Date2016-03-28 19:50 +0200
SubjectRe: [PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes
Message-ID<rhJsE-1VY-29@gated-at.bofh.it>
In reply to#1365591
On Mon, 28 Mar 2016, Irina Tirdea wrote:

> For big endian platforms, reading the axes will return
> invalid values.
> 
> The device stores each axis value in a 16 bit little
> endian register. The driver uses regmap_read_bulk to get
> the axis value, resulting in a 16 bit little endian value.
> This needs to be converted to cpu endianness to work
> on big endian platforms.
> 
> Fix endianness for big endian platforms by converting
> the values for the axes read from little endian to
> cpu.
> 
> This is also partially fixed in commit b6fb9b6d6552 ("iio:
> accel: bmc150: optimize transfers in trigger handler").

looks good

in bmc150_accel_get_axis() the call to regmap_bulk_read() could now pass 
sizeof(raw_val) instead of 2
 
> Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
> ---
>  drivers/iio/accel/bmc150-accel-core.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index c73331f7..5b64c3e 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -547,7 +547,7 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
>  {
>  	int ret;
>  	int axis = chan->scan_index;
> -	unsigned int raw_val;
> +	__le16 raw_val;
>  
>  	mutex_lock(&data->mutex);
>  	ret = bmc150_accel_set_power_state(data, true);
> @@ -564,7 +564,7 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
>  		mutex_unlock(&data->mutex);
>  		return ret;
>  	}
> -	*val = sign_extend32(raw_val >> chan->scan_type.shift,
> +	*val = sign_extend32(le16_to_cpu(raw_val) >> chan->scan_type.shift,
>  			     chan->scan_type.realbits - 1);
>  	ret = bmc150_accel_set_power_state(data, false);
>  	mutex_unlock(&data->mutex);
> @@ -988,6 +988,7 @@ static const struct iio_event_spec bmc150_accel_event = {
>  		.realbits = (bits),					\
>  		.storagebits = 16,					\
>  		.shift = 16 - (bits),					\
> +		.endianness = IIO_LE,					\
>  	},								\
>  	.event_spec = &bmc150_accel_event,				\
>  	.num_event_specs = 1						\
> 

-- 

Peter Meerwald-Stadler
+43-664-2444418 (mobile)

[toc] | [prev] | [next] | [standalone]


#1366224

From"Tirdea, Irina" <irina.tirdea@intel.com>
Date2016-03-29 14:40 +0200
Message-ID<ri169-6dv-7@gated-at.bofh.it>
In reply to#1365611

> -----Original Message-----
> From: linux-iio-owner@vger.kernel.org [mailto:linux-iio-owner@vger.kernel.org] On Behalf Of Peter Meerwald-Stadler
> Sent: 28 March, 2016 20:43
> To: Tirdea, Irina
> Cc: Jonathan Cameron; linux-iio@vger.kernel.org; linux-kernel@vger.kernel.org; Hartmut Knaack; Lars-Peter Clausen; Markus
> Pargmann
> Subject: Re: [PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes
> 
> On Mon, 28 Mar 2016, Irina Tirdea wrote:
> 
> > For big endian platforms, reading the axes will return
> > invalid values.
> >
> > The device stores each axis value in a 16 bit little
> > endian register. The driver uses regmap_read_bulk to get
> > the axis value, resulting in a 16 bit little endian value.
> > This needs to be converted to cpu endianness to work
> > on big endian platforms.
> >
> > Fix endianness for big endian platforms by converting
> > the values for the axes read from little endian to
> > cpu.
> >
> > This is also partially fixed in commit b6fb9b6d6552 ("iio:
> > accel: bmc150: optimize transfers in trigger handler").
> 
> looks good
> 
> in bmc150_accel_get_axis() the call to regmap_bulk_read() could now pass
> sizeof(raw_val) instead of 2
> 

Yes, that would look better. I'll send a new version with this change.

Thanks,
Irina

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web