All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX()
@ 2020-10-26 17:53 Andy Shevchenko
  2020-10-28 13:24 ` Linus Walleij
  2020-10-29 15:04 ` Jonathan Cameron
  0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2020-10-26 17:53 UTC (permalink / raw)
  To: Jonathan Cameron, linux-iio, Lars-Peter Clausen, Peter Meerwald-Stadler
  Cc: Andy Shevchenko, Linus Walleij

This makes the driver code slightly easier to read.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/gyro/mpu3050-core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index 00e58060968c..42b6ccb13568 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -827,15 +827,15 @@ static int mpu3050_hw_init(struct mpu3050 *mpu3050)
 		 "die ID: %04X, wafer ID: %02X, A lot ID: %04X, "
 		 "W lot ID: %03X, WP ID: %01X, rev ID: %02X\n",
 		 /* Die ID, bits 0-12 */
-		 (otp[1] << 8 | otp[0]) & 0x1fff,
+		 get_unaligned_le16(&otp[0]) & GENMASK(12, 0),
 		 /* Wafer ID, bits 13-17 */
-		 ((otp[2] << 8 | otp[1]) & 0x03e0) >> 5,
+		 (get_unaligned_le16(&otp[1]) & GENMASK(9, 5)) >> 5,
 		 /* A lot ID, bits 18-33 */
-		 ((otp[4] << 16 | otp[3] << 8 | otp[2]) & 0x3fffc) >> 2,
+		 (get_unaligned_le24(&otp[2]) & GENMASK(17, 2)) >> 2,
 		 /* W lot ID, bits 34-45 */
-		 ((otp[5] << 8 | otp[4]) & 0x3ffc) >> 2,
+		 (get_unaligned_le16(&otp[4]) & GENMASK(13, 2)) >> 2,
 		 /* WP ID, bits 47-49 */
-		 ((otp[6] << 8 | otp[5]) & 0x0380) >> 7,
+		 (get_unaligned_le16(&otp[5]) & GENMASK(9, 7)) >> 7,
 		 /* rev ID, bits 50-55 */
 		 otp[6] >> 2);
 
-- 
2.28.0


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

* Re: [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX()
  2020-10-26 17:53 [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX() Andy Shevchenko
@ 2020-10-28 13:24 ` Linus Walleij
  2020-10-29 15:04 ` Jonathan Cameron
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2020-10-28 13:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, linux-iio, Lars-Peter Clausen, Peter Meerwald-Stadler

On Mon, Oct 26, 2020 at 6:53 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> This makes the driver code slightly easier to read.
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Oh, neat bitting!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX()
  2020-10-26 17:53 [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX() Andy Shevchenko
  2020-10-28 13:24 ` Linus Walleij
@ 2020-10-29 15:04 ` Jonathan Cameron
  2020-10-29 17:10   ` Andy Shevchenko
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2020-10-29 15:04 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: linux-iio, Lars-Peter Clausen, Peter Meerwald-Stadler, Linus Walleij

On Mon, 26 Oct 2020 19:53:40 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> This makes the driver code slightly easier to read.
> 
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

What you have is good, but could we do better?

Why not use an __le64 to grab the whole thing, convert it to a local
cpu endian u64 then use FIELD_GET or similar to pull out the right bits.
Would be fairly self documenting as well which is always nice.

Or am I missing something?

Jonathan


> ---
>  drivers/iio/gyro/mpu3050-core.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
> index 00e58060968c..42b6ccb13568 100644
> --- a/drivers/iio/gyro/mpu3050-core.c
> +++ b/drivers/iio/gyro/mpu3050-core.c
> @@ -827,15 +827,15 @@ static int mpu3050_hw_init(struct mpu3050 *mpu3050)
>  		 "die ID: %04X, wafer ID: %02X, A lot ID: %04X, "
>  		 "W lot ID: %03X, WP ID: %01X, rev ID: %02X\n",
>  		 /* Die ID, bits 0-12 */
> -		 (otp[1] << 8 | otp[0]) & 0x1fff,
> +		 get_unaligned_le16(&otp[0]) & GENMASK(12, 0),
>  		 /* Wafer ID, bits 13-17 */
> -		 ((otp[2] << 8 | otp[1]) & 0x03e0) >> 5,
> +		 (get_unaligned_le16(&otp[1]) & GENMASK(9, 5)) >> 5,
>  		 /* A lot ID, bits 18-33 */
> -		 ((otp[4] << 16 | otp[3] << 8 | otp[2]) & 0x3fffc) >> 2,
> +		 (get_unaligned_le24(&otp[2]) & GENMASK(17, 2)) >> 2,
>  		 /* W lot ID, bits 34-45 */
> -		 ((otp[5] << 8 | otp[4]) & 0x3ffc) >> 2,
> +		 (get_unaligned_le16(&otp[4]) & GENMASK(13, 2)) >> 2,
>  		 /* WP ID, bits 47-49 */
> -		 ((otp[6] << 8 | otp[5]) & 0x0380) >> 7,
> +		 (get_unaligned_le16(&otp[5]) & GENMASK(9, 7)) >> 7,
>  		 /* rev ID, bits 50-55 */
>  		 otp[6] >> 2);
>  


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

* Re: [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX()
  2020-10-29 15:04 ` Jonathan Cameron
@ 2020-10-29 17:10   ` Andy Shevchenko
  2020-11-05 14:23     ` Linus Walleij
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2020-10-29 17:10 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Andy Shevchenko, linux-iio, Lars-Peter Clausen,
	Peter Meerwald-Stadler, Linus Walleij

On Thu, Oct 29, 2020 at 5:05 PM Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Mon, 26 Oct 2020 19:53:40 +0200
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>
> > This makes the driver code slightly easier to read.
> >
> > Cc: Linus Walleij <linus.walleij@linaro.org>
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> What you have is good, but could we do better?
>
> Why not use an __le64 to grab the whole thing, convert it to a local
> cpu endian u64 then use FIELD_GET or similar to pull out the right bits.
> Would be fairly self documenting as well which is always nice.
>
> Or am I missing something?

My laziness. I shared this as a leftover from a big series of
converting a lot of drivers to get_unligned_.eXX(). If you consider
this is not good enough, just don't apply (no hard feelings :-) I will
drop it from my local branches.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX()
  2020-10-29 17:10   ` Andy Shevchenko
@ 2020-11-05 14:23     ` Linus Walleij
  2020-11-05 15:07       ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Linus Walleij @ 2020-11-05 14:23 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Jonathan Cameron, Andy Shevchenko, linux-iio, Lars-Peter Clausen,
	Peter Meerwald-Stadler

On Thu, Oct 29, 2020 at 6:10 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Thu, Oct 29, 2020 at 5:05 PM Jonathan Cameron <jic23@kernel.org> wrote:
> >
> > On Mon, 26 Oct 2020 19:53:40 +0200
> > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> >
> > > This makes the driver code slightly easier to read.
> > >
> > > Cc: Linus Walleij <linus.walleij@linaro.org>
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > What you have is good, but could we do better?
> >
> > Why not use an __le64 to grab the whole thing, convert it to a local
> > cpu endian u64 then use FIELD_GET or similar to pull out the right bits.
> > Would be fairly self documenting as well which is always nice.
> >
> > Or am I missing something?
>
> My laziness. I shared this as a leftover from a big series of
> converting a lot of drivers to get_unligned_.eXX(). If you consider
> this is not good enough, just don't apply (no hard feelings :-) I will
> drop it from my local branches.

I would suggest to apply it anyways because the kernel will look
better after than before this patch.

Possibly Jonathan could just slip in a TODO comment for this?

Yours,
Linus Walleij

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

* Re: [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX()
  2020-11-05 14:23     ` Linus Walleij
@ 2020-11-05 15:07       ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2020-11-05 15:07 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Jonathan Cameron, linux-iio, Lars-Peter Clausen, Peter Meerwald-Stadler

On Thu, Nov 05, 2020 at 03:23:07PM +0100, Linus Walleij wrote:
> On Thu, Oct 29, 2020 at 6:10 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Thu, Oct 29, 2020 at 5:05 PM Jonathan Cameron <jic23@kernel.org> wrote:
> > >
> > > On Mon, 26 Oct 2020 19:53:40 +0200
> > > Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > > This makes the driver code slightly easier to read.
> > > >
> > > > Cc: Linus Walleij <linus.walleij@linaro.org>
> > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > >
> > > What you have is good, but could we do better?
> > >
> > > Why not use an __le64 to grab the whole thing, convert it to a local
> > > cpu endian u64 then use FIELD_GET or similar to pull out the right bits.
> > > Would be fairly self documenting as well which is always nice.
> > >
> > > Or am I missing something?
> >
> > My laziness. I shared this as a leftover from a big series of
> > converting a lot of drivers to get_unligned_.eXX(). If you consider
> > this is not good enough, just don't apply (no hard feelings :-) I will
> > drop it from my local branches.
> 
> I would suggest to apply it anyways because the kernel will look
> better after than before this patch.
> 
> Possibly Jonathan could just slip in a TODO comment for this?

Sorry, I have already dropped, but if you convince Jonathan to apply, I agree
on whatever you propose (TODO comment as I see). I think patchwork or lore
still keeps a track of this.

-- 
With Best Regards,
Andy Shevchenko



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

end of thread, other threads:[~2020-11-05 15:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 17:53 [PATCH v1] iio: gyro: mpu3050: Use get_unaligned_leXX() Andy Shevchenko
2020-10-28 13:24 ` Linus Walleij
2020-10-29 15:04 ` Jonathan Cameron
2020-10-29 17:10   ` Andy Shevchenko
2020-11-05 14:23     ` Linus Walleij
2020-11-05 15:07       ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.