iio:gyro:mpu3050 Treat otp value as a __le64 and use FIELD_GET() to break up
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 29 Nov 2020 18:44:59 +0000 (18:44 +0000)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 3 Dec 2020 19:40:29 +0000 (19:40 +0000)
commit26aec6e1b714f954b22bc7ad3239b6c0e917c90f
tree98b2d72174f32338501443248458403e64ede7d8
parent1e405bc2512f80a903ddd6ba8740cee885238d7f
iio:gyro:mpu3050 Treat otp value as a __le64 and use FIELD_GET() to break up

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@huawei.com>
Tested-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20201128185156.428327-1-jic23@kernel.org
Link: https://lore.kernel.org/r/20201129184459.647538-1-jic23@kernel.org
drivers/iio/gyro/mpu3050-core.c