media: i2c: imx290: Make use of get_unaligned_le24(), put_unaligned_le24()
PATCH 1/1 media: i2c: imx290: Make use of get_unaligned_le24(), put_unaligned_le24()
Since we have a proper endianness converters for LE 24-bit data use them. While at it, format the code using switch-cases as it's done for the rest of the endianness handlers.
--- drivers/media/i2c/imx290.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/i2c/imx290.c +7 -2
@@ -16,6 +16,9 @@#include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> + +#include <asm/unaligned.h> +#include <media/media-entity.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h>
@@ -466,18 +469,20 @@ static int __always_unused imx290_read(struct imx290 *imx290, u32 addr, u32 *valreturn ret; } - *value = (data[2 ] <<16 ) | (data[1 ] <<8 ) | data[0 ]; + *value =get_unaligned_le24 (data);return 0 ; }static int imx290_write (struct imx290 *imx290,u32 addr,u32 value,int *err) { -u8 data[3 ] = { value &0xff , (value >>8 ) &0xff , value >>16 }; +u8 data[3 ];int ret;if (err && *err)return *err; +put_unaligned_le24 (value, data); + ret =regmap_raw_write (imx290->regmap, addr &IMX290_REG_ADDR_MASK , data, (addr >>IMX290_REG_SIZE_SHIFT ) &3 );if (ret <0 ) {
Signature · 1 line
2.39.1
Hi Andy,
Thank you for the patch.
Quoted 3 lines · Andy Shevchenko
Since we have a proper endianness converters for LE 24-bit data use them. While at it, format the code using switch-cases as it's done for the rest of the endianness handlers.
I don't see any new switch-case :-)
The rest looks fine.
Quoted 42 lines
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/media/i2c/imx290.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/media/i2c/imx290.c +7
-2@@ -16,6 +16,9 @@#include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> + +#include <asm/unaligned.h> +#include <media/media-entity.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> @@ -466,18 +469,20 @@ static int __always_unused imx290_read(struct imx290 *imx290, u32 addr, u32 *valreturn ret; } - *value = (data[2 ] <<16 ) | (data[1 ] <<8 ) | data[0 ]; + *value =get_unaligned_le24 (data);return 0 ; }static int imx290_write (struct imx290 *imx290,u32 addr,u32 value,int *err) { -u8 data[3 ] = { value &0xff , (value >>8 ) &0xff , value >>16 }; +u8 data[3 ];int ret;if (err && *err)return *err; +put_unaligned_le24 (value, data); + ret =regmap_raw_write (imx290->regmap, addr &IMX290_REG_ADDR_MASK , data, (addr >>IMX290_REG_SIZE_SHIFT ) &3 );if (ret <0 ) {
Signature · 3 lines
Regards, Laurent Pinchart
From: Andy Shevchenko
Quoted 37 lines
Sent: 08 February 2023 11:30
Since we have a proper endianness converters for LE 24-bit data use them. While at it, format the code using switch-cases as it's done for the rest of the endianness handlers.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/media/i2c/imx290.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/media/i2c/imx290.c +4
-2@@ -16,6 +16,9 @@#include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> + +#include <asm/unaligned.h> +#include <media/media-entity.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> @@ -466,18 +469,20 @@ static int __always_unused imx290_read(struct imx290 *imx290, u32 addr, u32 *valreturn ret; } - *value = (data[2 ] <<16 ) | (data[1 ] <<8 ) | data[0 ]; + *value =get_unaligned_le24 (data);return 0 ; }static int imx290_write (struct imx290 *imx290,u32 addr,u32 value,int *err) { -u8 data[3 ] = { value &0xff , (value >>8 ) &0xff , value >>16 };
drivers/media/i2c/imx290.c static int __always_unused imx290_read(struct imx290 *imx290, u32 addr, u32 *val · line 487
Quoted 10 lines
drivers/media/i2c/imx290.c +3
-0+u8 data[3 ];int ret;if (err && *err)return *err; +put_unaligned_le24 (value, data); + ret =regmap_raw_write (imx290->regmap, addr &IMX290_REG_ADDR_MASK , data, (addr >>IMX290_REG_SIZE_SHIFT ) &3 );
Why not just use an le32, htole32() and take the address of the low byte?
Anything doing put/get on a 24bit value is pretty much required to do byte accesses anyway.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)