linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX()
@ 2022-12-14 12:02 Andy Shevchenko
  2022-12-14 12:02 ` [PATCH v1 2/2] iio: adc: ti-adc128s052: Sort headers Andy Shevchenko
  2022-12-23 15:17 ` [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX() Jonathan Cameron
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2022-12-14 12:02 UTC (permalink / raw)
  To: Andy Shevchenko, linux-iio, linux-kernel
  Cc: Jonathan Cameron, Lars-Peter Clausen

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>
---
 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,
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v1 2/2] iio: adc: ti-adc128s052: Sort headers
  2022-12-14 12:02 [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX() Andy Shevchenko
@ 2022-12-14 12:02 ` Andy Shevchenko
  2022-12-23 15:17 ` [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX() Jonathan Cameron
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2022-12-14 12:02 UTC (permalink / raw)
  To: Andy Shevchenko, linux-iio, linux-kernel
  Cc: Jonathan Cameron, Lars-Peter Clausen

Sort the headers in alphabetic order in order to ease
the maintenance for this part.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/adc/ti-adc128s052.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
index 7c4e8025861c..a003264ca835 100644
--- a/drivers/iio/adc/ti-adc128s052.c
+++ b/drivers/iio/adc/ti-adc128s052.c
@@ -11,12 +11,12 @@
 
 #include <linux/bits.h>
 #include <linux/err.h>
-#include <linux/spi/spi.h>
-#include <linux/module.h>
-#include <linux/mod_devicetable.h>
 #include <linux/iio/iio.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
 #include <linux/property.h>
 #include <linux/regulator/consumer.h>
+#include <linux/spi/spi.h>
 
 #include <asm/unaligned.h>
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX()
  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
  2022-12-28 10:08   ` Andy Shevchenko
  1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2022-12-23 15:17 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-iio, linux-kernel, Lars-Peter Clausen

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,


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX()
  2022-12-23 15:17 ` [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX() Jonathan Cameron
@ 2022-12-28 10:08   ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2022-12-28 10:08 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, linux-kernel, Lars-Peter Clausen

On Fri, Dec 23, 2022 at 03:17:50PM +0000, Jonathan Cameron wrote:
> 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?

OK, I will consider when I have time for this.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-28 10:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v1 1/2] iio: adc: ti-adc128s052: Use get_unaligned_beXX() Jonathan Cameron
2022-12-28 10:08   ` Andy Shevchenko

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).