mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
To: Irina Tirdea <irina.tirdea@intel.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Markus Pargmann <mpa@pengutronix.de>
Subject: Re: [PATCH 1/1] iio: accel: bmc150: fix endianness when reading axes
Date: Mon, 28 Mar 2016 19:42:56 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1603281937390.4312@pmeerw.net> (raw)
In-Reply-To: <1459185141-18319-1-git-send-email-irina.tirdea@intel.com>

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)

  reply	other threads:[~2016-03-28 17:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-28 17:12 Irina Tirdea
2016-03-28 17:42 ` Peter Meerwald-Stadler [this message]
2016-03-29 12:31   ` Tirdea, Irina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.02.1603281937390.4312@pmeerw.net \
    --to=pmeerw@pmeerw.net \
    --cc=irina.tirdea@intel.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpa@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®