media: v4l: cci: Add macros to obtain register width and address
authorSakari Ailus <sakari.ailus@linux.intel.com>
Tue, 7 Nov 2023 15:42:40 +0000 (17:42 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 4 Dec 2023 10:21:46 +0000 (11:21 +0100)
Add CCI_REG_WIDTH() macro to obtain register width in bits and similarly,
CCI_REG_WIDTH_BYTES() to obtain it in bytes.

Also add CCI_REG_ADDR() macro to obtain the address of a register.

Use both macros in v4l2-cci.c, too.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/v4l2-core/v4l2-cci.c
include/media/v4l2-cci.h

index bc2dbec019b04c95e63621c694b0abd7b1063b68..3179160abde301050ff7aa30a50d2e2ded07dd9e 100644 (file)
@@ -25,8 +25,8 @@ int cci_read(struct regmap *map, u32 reg, u64 *val, int *err)
        if (err && *err)
                return *err;
 
-       len = FIELD_GET(CCI_REG_WIDTH_MASK, reg);
-       reg = FIELD_GET(CCI_REG_ADDR_MASK, reg);
+       len = CCI_REG_WIDTH_BYTES(reg);
+       reg = CCI_REG_ADDR(reg);
 
        ret = regmap_bulk_read(map, reg, buf, len);
        if (ret) {
@@ -75,8 +75,8 @@ int cci_write(struct regmap *map, u32 reg, u64 val, int *err)
        if (err && *err)
                return *err;
 
-       len = FIELD_GET(CCI_REG_WIDTH_MASK, reg);
-       reg = FIELD_GET(CCI_REG_ADDR_MASK, reg);
+       len = CCI_REG_WIDTH_BYTES(reg);
+       reg = CCI_REG_ADDR(reg);
 
        switch (len) {
        case 1:
index ee469f03e4406e85c28d71586080ff7e32ee637d..406772a4e32ec1065439a11b508a73c21c99353f 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef _V4L2_CCI_H
 #define _V4L2_CCI_H
 
+#include <linux/bitfield.h>
 #include <linux/bits.h>
 #include <linux/types.h>
 
@@ -39,6 +40,10 @@ struct cci_reg_sequence {
 #define CCI_REG_PRIVATE_SHIFT          28U
 #define CCI_REG_PRIVATE_MASK           GENMASK(31U, CCI_REG_PRIVATE_SHIFT)
 
+#define CCI_REG_WIDTH_BYTES(x)         FIELD_GET(CCI_REG_WIDTH_MASK, x)
+#define CCI_REG_WIDTH(x)               (CCI_REG_WIDTH_BYTES(x) << 3)
+#define CCI_REG_ADDR(x)                        FIELD_GET(CCI_REG_ADDR_MASK, x)
+
 #define CCI_REG8(x)                    ((1 << CCI_REG_WIDTH_SHIFT) | (x))
 #define CCI_REG16(x)                   ((2 << CCI_REG_WIDTH_SHIFT) | (x))
 #define CCI_REG24(x)                   ((3 << CCI_REG_WIDTH_SHIFT) | (x))