From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Lars-Peter Clausen <lars@metafoo.de>
Subject: Re: [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX()
Date: Fri, 23 Dec 2022 15:17:50 +0000 [thread overview]
Message-ID: <20221223151750.6cb55f12@jic23-huawei> (raw)
In-Reply-To: <20221214120202.4658-1-andriy.shevchenko@linux.intel.com>
On Wed, 14 Dec 2022 14:02:01 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> This makes the driver code slightly easier to read.
> While at it, use GENMASK() as well.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Hi Andy,
Patch looks good, but it got me thinking. Why not just flip this driver
over to using spi_write_then_read(). Would let us drop the DMA safety
protections and simplify the code + use a __be16 as the read buffer
and this would then be the slightly nicer aligned form.
Worth doing whilst you are here?
Jonathan
> ---
> drivers/iio/adc/ti-adc128s052.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> index fc09ee6bb174..7c4e8025861c 100644
> --- a/drivers/iio/adc/ti-adc128s052.c
> +++ b/drivers/iio/adc/ti-adc128s052.c
> @@ -9,6 +9,7 @@
> * https://www.ti.com/lit/ds/symlink/adc124s021.pdf
> */
>
> +#include <linux/bits.h>
> #include <linux/err.h>
> #include <linux/spi/spi.h>
> #include <linux/module.h>
> @@ -17,6 +18,8 @@
> #include <linux/property.h>
> #include <linux/regulator/consumer.h>
>
> +#include <asm/unaligned.h>
> +
> struct adc128_configuration {
> const struct iio_chan_spec *channels;
> u8 num_channels;
> @@ -33,6 +36,7 @@ struct adc128 {
>
> static int adc128_adc_conversion(struct adc128 *adc, u8 channel)
> {
> + u16 value;
> int ret;
>
> mutex_lock(&adc->lock);
> @@ -53,7 +57,8 @@ static int adc128_adc_conversion(struct adc128 *adc, u8 channel)
> if (ret < 0)
> return ret;
>
> - return ((adc->buffer[0] << 8 | adc->buffer[1]) & 0xFFF);
> + value = get_unaligned_be16(&adc->buffer);
> + return value & GENMASK(11, 0);
> }
>
> static int adc128_read_raw(struct iio_dev *indio_dev,
next prev parent reply other threads:[~2022-12-23 15:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 12:02 [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX() Andy Shevchenko
2022-12-14 12:02 ` [PATCH v1 2/2] iio: adc: ti-adc128s052: Sort headers Andy Shevchenko
2022-12-23 15:17 ` Jonathan Cameron [this message]
2022-12-28 10:08 ` [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX() Andy Shevchenko
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=20221223151750.6cb55f12@jic23-huawei \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.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