devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Veenstra <davidjulianveenstra@gmail.com>
Cc: devel@driverdev.osuosl.org, devicetree@vger.kernel.org,
	lars@metafoo.de, Michael.Hennerich@analog.com,
	linux-iio@vger.kernel.org, robh+dt@kernel.org, pmeerw@pmeerw.net,
	knaack.h@gmx.de, daniel.baluta@nxp.com
Subject: Re: [PATCH v3 2/9] staging: iio: ad2s1200: Improve readability with be16_to_cpup
Date: Sat, 28 Apr 2018 18:12:31 +0100	[thread overview]
Message-ID: <20180428181231.1548a82e@archlinux> (raw)
In-Reply-To: <8e171d819a0916d7a4870bf70cfeada8ba9ebdc6.1524432236.git.davidjulianveenstra@gmail.com>

On Mon, 23 Apr 2018 00:03:03 +0200
David Veenstra <davidjulianveenstra@gmail.com> wrote:

> The manual states that the data is contained in the upper 12 bits
> of the 16 bits read by spi. The code that extracts these 12 bits
> is correct for both be and le machines, but this is not clear
> from a first glance.
> 
> To improve readability the relevant expressions are replaced
> with equivalent expressions that use be16_to_cpup.
> 
> Signed-off-by: David Veenstra <davidjulianveenstra@gmail.com>
Looks good to me.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
> Changes in v3:
>  - change type of rx to __be16.
>  - remove unneeded variable vel.
>  - remove unneeded type cast to s16 (patch line 79).
> 
>  drivers/staging/iio/resolver/ad2s1200.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/staging/iio/resolver/ad2s1200.c b/drivers/staging/iio/resolver/ad2s1200.c
> index 17d65cb437fd..998f458dc1bd 100644
> --- a/drivers/staging/iio/resolver/ad2s1200.c
> +++ b/drivers/staging/iio/resolver/ad2s1200.c
> @@ -47,7 +47,7 @@ struct ad2s1200_state {
>  	struct spi_device *sdev;
>  	int sample;
>  	int rdvel;
> -	u8 rx[2] ____cacheline_aligned;
> +	__be16 rx ____cacheline_aligned;
>  };
>  
>  static int ad2s1200_read_raw(struct iio_dev *indio_dev,
> @@ -58,7 +58,6 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev,
>  {
>  	struct ad2s1200_state *st = iio_priv(indio_dev);
>  	int ret = 0;
> -	s16 vel;
>  
>  	mutex_lock(&st->lock);
>  	gpio_set_value(st->sample, 0);
> @@ -68,7 +67,7 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev,
>  	gpio_set_value(st->sample, 1);
>  	gpio_set_value(st->rdvel, !!(chan->type == IIO_ANGL));
>  
> -	ret = spi_read(st->sdev, st->rx, 2);
> +	ret = spi_read(st->sdev, &st->rx, 2);
>  	if (ret < 0) {
>  		mutex_unlock(&st->lock);
>  		return ret;
> @@ -76,12 +75,10 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev,
>  
>  	switch (chan->type) {
>  	case IIO_ANGL:
> -		*val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
> +		*val = be16_to_cpup(&st->rx) >> 4;
>  		break;
>  	case IIO_ANGL_VEL:
> -		vel = (((s16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4);
> -		vel = sign_extend32(vel, 11);
> -		*val = vel;
> +		*val = sign_extend32(be16_to_cpup(&st->rx) >> 4, 11);
>  		break;
>  	default:
>  		mutex_unlock(&st->lock);

  reply	other threads:[~2018-04-28 17:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-22 22:02 [PATCH v3 0/9] staging: iio: ad2s1200: Driver clean up David Veenstra
2018-04-22 22:02 ` [PATCH v3 1/9] staging: iio: ad2s1200: Add kernel docs to driver state David Veenstra
2018-04-28 17:11   ` Jonathan Cameron
2018-05-18 12:57     ` David Julian Veenstra
2018-04-22 22:03 ` [PATCH v3 2/9] staging: iio: ad2s1200: Improve readability with be16_to_cpup David Veenstra
2018-04-28 17:12   ` Jonathan Cameron [this message]
2018-04-22 22:03 ` [PATCH v3 3/9] staging: iio: ad2s1200: Replace legacy gpio API with modern API David Veenstra
2018-04-28 17:17   ` Jonathan Cameron
2018-04-22 22:03 ` [PATCH v3 4/9] staging: iio: ad2s1200: Replace platform data with dt bindings David Veenstra
2018-04-28 17:20   ` Jonathan Cameron
2018-04-22 22:03 ` [PATCH v3 5/9] staging: iio: ad2s1200: Add documentation for device tree binding David Veenstra
2018-04-27 14:48   ` Rob Herring
2018-04-28 15:27     ` Jonathan Cameron
2018-05-18 13:00       ` David Julian Veenstra
2018-04-27 14:49   ` Rob Herring
2018-04-22 22:03 ` [PATCH v3 6/9] staging: iio: ad2s1200: Add scaling factor for angular velocity channel David Veenstra
2018-04-28 17:23   ` Jonathan Cameron
2018-04-28 17:35     ` Jonathan Cameron
2018-05-18 13:10       ` David Julian Veenstra
2018-04-22 22:04 ` [PATCH v3 7/9] staging: iio: Documentation: Add missing sysfs docs for angle channel David Veenstra
2018-04-28 17:36   ` Jonathan Cameron
2018-04-22 22:04 ` [PATCH v3 8/9] staging: iio: ad2s1200: Add scaling factor " David Veenstra
2018-04-28 17:37   ` Jonathan Cameron
2018-04-22 22:04 ` [PATCH v3 9/9] staging: iio: ad2s1200: Move driver out of staging David Veenstra
2018-04-28 17:46   ` Jonathan Cameron
2018-05-18 13:17     ` David Julian Veenstra

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=20180428181231.1548a82e@archlinux \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=daniel.baluta@nxp.com \
    --cc=davidjulianveenstra@gmail.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=devicetree@vger.kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).