Re: [PATCH v2] iio:gyro:mpu3050 Treat otp value as a __le64 and use FIELD_GET() to break up

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Nov 29, 2020 at 7:47 PM Jonathan Cameron <jic23@xxxxxxxxxx> wrote:

> From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
>
> Inspired by Andy Shevchenko's proposal to use get_unaligned_leXX().
>
> The whole one time programable memory is treated as a single 64bit
> little endian value.  Thus we can avoid a lot of messy handling
> of fields overlapping byte boundaries by just loading and manipulating
> it as an __le64 converted to a u64.  That lets us just use FIELD_GET()
> and GENMASK() to extract the values desired.
>
> Note only build tested. We need to use GENMASK_ULL and %llX formatters
> to account for the larger types used in computing the various fields.
>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Cc: Linus Walleij <linus.walleij@xxxxxxxxxx>
> Link: https://lore.kernel.org/r/20201128185156.428327-1-jic23@xxxxxxxxxx
> ---
>
> Changes since v1:
> * Fix 32 bit builds by using GENMASK_ULL (thanks to Linus + Andy)

Easy to test since I'm playing with one of these right now!

Before:
[    2.677957] mpu3050-i2c 2-0068: found MPU-3050 part no: 6, version: 14
[    2.695905] mpu3050-i2c 2-0068: die ID: 05A1, wafer ID: 12, A lot
ID: 0000, W lot ID: 662, WP ID: 3, rev ID: 1A
After:
[    2.667944] mpu3050-i2c 2-0068: found MPU-3050 part no: 6, version: 14
[    2.686969] mpu3050-i2c 2-0068: die ID: 05A1, wafer ID: 12, A lot
ID: 0000, W lot ID: 662, WP ID: 3, rev ID: 1A

And works too.
Tested-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
Reviewed-by: Linus Walleij <linus.walleij@xxxxxxxxxx>

I used the same approach in the Yamaha driver and it looks good
there too.

Yours,
Linus Walleij



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux