[PATCH RFC 1/3] media: qcom: camss: vfe: gen3: Describe the register layout with a struct

From: Wenmeng Liu

Date: Thu Dec 03 2026 - 05:34:56 EST


VFE 690 and VFE 780 only differ in the bus register layout, the RDI write
master client IDs, the address units and the downscaler configuration.
Describe them with a struct vfe_gen3_cfg referenced from the VFE
resources instead of checking the CAMSS version.

Signed-off-by: Wenmeng Liu <wenmeng.liu@xxxxxxxxxxxxxxxx>
---
drivers/media/platform/qcom/camss/camss-vfe-gen3.c | 101 +++++++++++++--------
drivers/media/platform/qcom/camss/camss-vfe.h | 6 ++
drivers/media/platform/qcom/camss/camss.c | 17 ++++
3 files changed, 84 insertions(+), 40 deletions(-)

diff --git a/drivers/media/platform/qcom/camss/camss-vfe-gen3.c b/drivers/media/platform/qcom/camss/camss-vfe-gen3.c
index 22579617def78457d057e5ba413ae481843a18ad..afbef045ed91b11277895b5a38e0f2576a77b33f 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-gen3.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-gen3.c
@@ -12,26 +12,36 @@
#include "camss.h"
#include "camss-vfe.h"

-#define IS_VFE_690(vfe) \
- ((vfe->camss->res->version == CAMSS_8775P) \
- || (vfe->camss->res->version == CAMSS_8300))
-
-#define BUS_REG_BASE_690 \
- (vfe_is_lite(vfe) ? 0x480 : 0x400)
-#define BUS_REG_BASE_780 \
- (vfe_is_lite(vfe) ? 0x200 : 0xC00)
+/**
+ * struct vfe_gen3_cfg - VFE register layout
+ * @bus_base_full: bus register base on a full VFE
+ * @bus_base_lite: bus register base on a VFE lite
+ * @test_bus_ctrl: offset of the WM test bus control register from the bus base
+ * @wm_base: offset of the first WM register block from the bus base
+ * @rdi_wm_full: WM client ID of RDI0 on a full VFE, it is 0 on a VFE lite
+ * @addr_shift: right shift applied to the image address and frame increment
+ * @disable_ds: disable the DS4 and DS16 downscalers
+ */
+struct vfe_gen3_cfg {
+ u32 bus_base_full;
+ u32 bus_base_lite;
+ u32 test_bus_ctrl;
+ u32 wm_base;
+ u8 rdi_wm_full;
+ u8 addr_shift;
+ bool disable_ds;
+};
+
+#define GEN3_CFG (vfe->res->gen3_cfg)
+
#define BUS_REG_BASE \
- (IS_VFE_690(vfe) ? BUS_REG_BASE_690 : BUS_REG_BASE_780)
+ (vfe_is_lite(vfe) ? GEN3_CFG->bus_base_lite : GEN3_CFG->bus_base_full)

#define VFE_TOP_CORE_CFG (0x24)
#define VFE_DISABLE_DSCALING_DS4 BIT(21)
#define VFE_DISABLE_DSCALING_DS16 BIT(22)

-#define VFE_BUS_WM_TEST_BUS_CTRL_690 (BUS_REG_BASE + 0xFC)
-#define VFE_BUS_WM_TEST_BUS_CTRL_780 (BUS_REG_BASE + 0xDC)
-#define VFE_BUS_WM_TEST_BUS_CTRL \
- (IS_VFE_690(vfe) ? VFE_BUS_WM_TEST_BUS_CTRL_690 \
- : VFE_BUS_WM_TEST_BUS_CTRL_780)
+#define VFE_BUS_WM_TEST_BUS_CTRL (BUS_REG_BASE + GEN3_CFG->test_bus_ctrl)
/*
* Bus client mapping:
*
@@ -43,32 +53,31 @@
* VFE_690 : 0 = RDI0, 1 = RDI1, 2 = RDI2, 3 = RDI3, 4 = RDI4, 5 = RDI5
* VFE_780 : 0 = RDI0, 1 = RDI1, 2 = RDI2, 3 = RDI3, 4 = RDI4
*/
-#define RDI_WM_690(n) ((vfe_is_lite(vfe) ? 0x0 : 0x10) + (n))
-#define RDI_WM_780(n) ((vfe_is_lite(vfe) ? 0x0 : 0x17) + (n))
-#define RDI_WM(n) (IS_VFE_690(vfe) ? RDI_WM_690(n) : RDI_WM_780(n))
+#define RDI_WM(n) ((vfe_is_lite(vfe) ? 0x0 : GEN3_CFG->rdi_wm_full) + (n))

#define VFE_BUS_WM_CGC_OVERRIDE (BUS_REG_BASE + 0x08)
#define WM_CGC_OVERRIDE_ALL (0x7FFFFFF)

-#define VFE_BUS_WM_CFG(n) (BUS_REG_BASE + 0x200 + (n) * 0x100)
+#define VFE_BUS_WM(n) (BUS_REG_BASE + GEN3_CFG->wm_base + (n) * 0x100)
+#define VFE_BUS_WM_CFG(n) VFE_BUS_WM(n)
#define WM_CFG_EN BIT(0)
#define WM_VIR_FRM_EN BIT(1)
#define WM_CFG_MODE BIT(16)
-#define VFE_BUS_WM_IMAGE_ADDR(n) (BUS_REG_BASE + 0x204 + (n) * 0x100)
-#define VFE_BUS_WM_FRAME_INCR(n) (BUS_REG_BASE + 0x208 + (n) * 0x100)
-#define VFE_BUS_WM_IMAGE_CFG_0(n) (BUS_REG_BASE + 0x20c + (n) * 0x100)
+#define VFE_BUS_WM_IMAGE_ADDR(n) (VFE_BUS_WM(n) + 0x04)
+#define VFE_BUS_WM_FRAME_INCR(n) (VFE_BUS_WM(n) + 0x08)
+#define VFE_BUS_WM_IMAGE_CFG_0(n) (VFE_BUS_WM(n) + 0x0c)
#define WM_IMAGE_CFG_0_DEFAULT_WIDTH (0xFFFF)
-#define VFE_BUS_WM_IMAGE_CFG_2(n) (BUS_REG_BASE + 0x214 + (n) * 0x100)
+#define VFE_BUS_WM_IMAGE_CFG_2(n) (VFE_BUS_WM(n) + 0x14)
#define WM_IMAGE_CFG_2_DEFAULT_STRIDE (0xFFFF)
-#define VFE_BUS_WM_PACKER_CFG(n) (BUS_REG_BASE + 0x218 + (n) * 0x100)
+#define VFE_BUS_WM_PACKER_CFG(n) (VFE_BUS_WM(n) + 0x18)

-#define VFE_BUS_WM_IRQ_SUBSAMPLE_PERIOD(n) (BUS_REG_BASE + 0x230 + (n) * 0x100)
-#define VFE_BUS_WM_IRQ_SUBSAMPLE_PATTERN(n) (BUS_REG_BASE + 0x234 + (n) * 0x100)
-#define VFE_BUS_WM_FRAMEDROP_PERIOD(n) (BUS_REG_BASE + 0x238 + (n) * 0x100)
-#define VFE_BUS_WM_FRAMEDROP_PATTERN(n) (BUS_REG_BASE + 0x23c + (n) * 0x100)
+#define VFE_BUS_WM_IRQ_SUBSAMPLE_PERIOD(n) (VFE_BUS_WM(n) + 0x30)
+#define VFE_BUS_WM_IRQ_SUBSAMPLE_PATTERN(n) (VFE_BUS_WM(n) + 0x34)
+#define VFE_BUS_WM_FRAMEDROP_PERIOD(n) (VFE_BUS_WM(n) + 0x38)
+#define VFE_BUS_WM_FRAMEDROP_PATTERN(n) (VFE_BUS_WM(n) + 0x3c)

-#define VFE_BUS_WM_MMU_PREFETCH_CFG(n) (BUS_REG_BASE + 0x260 + (n) * 0x100)
-#define VFE_BUS_WM_MMU_PREFETCH_MAX_OFFSET(n) (BUS_REG_BASE + 0x264 + (n) * 0x100)
+#define VFE_BUS_WM_MMU_PREFETCH_CFG(n) (VFE_BUS_WM(n) + 0x60)
+#define VFE_BUS_WM_MMU_PREFETCH_MAX_OFFSET(n) (VFE_BUS_WM(n) + 0x64)

static void vfe_wm_start(struct vfe_device *vfe, u8 wm, struct vfe_line *line)
{
@@ -82,12 +91,8 @@ static void vfe_wm_start(struct vfe_device *vfe, u8 wm, struct vfe_line *line)

writel(0x0, vfe->base + VFE_BUS_WM_TEST_BUS_CTRL);

- if (IS_VFE_690(vfe))
- writel(ALIGN(pix->plane_fmt[0].bytesperline, 16) * pix->height,
- vfe->base + VFE_BUS_WM_FRAME_INCR(wm));
- else
- writel(ALIGN(pix->plane_fmt[0].bytesperline, 16) * pix->height >> 8,
- vfe->base + VFE_BUS_WM_FRAME_INCR(wm));
+ writel(ALIGN(pix->plane_fmt[0].bytesperline, 16) * pix->height >>
+ GEN3_CFG->addr_shift, vfe->base + VFE_BUS_WM_FRAME_INCR(wm));

writel((WM_IMAGE_CFG_0_DEFAULT_WIDTH & 0xFFFF),
vfe->base + VFE_BUS_WM_IMAGE_CFG_0(wm));
@@ -96,7 +101,7 @@ static void vfe_wm_start(struct vfe_device *vfe, u8 wm, struct vfe_line *line)
writel(0, vfe->base + VFE_BUS_WM_PACKER_CFG(wm));

/* TOP CORE CFG */
- if (IS_VFE_690(vfe))
+ if (GEN3_CFG->disable_ds)
writel(VFE_DISABLE_DSCALING_DS4 | VFE_DISABLE_DSCALING_DS16,
vfe->base + VFE_TOP_CORE_CFG);

@@ -123,10 +128,7 @@ static void vfe_wm_update(struct vfe_device *vfe, u8 wm, u32 addr,
{
wm = RDI_WM(wm);

- if (IS_VFE_690(vfe))
- writel(addr, vfe->base + VFE_BUS_WM_IMAGE_ADDR(wm));
- else
- writel((addr >> 8), vfe->base + VFE_BUS_WM_IMAGE_ADDR(wm));
+ writel(addr >> GEN3_CFG->addr_shift, vfe->base + VFE_BUS_WM_IMAGE_ADDR(wm));

dev_dbg(vfe->camss->dev, "wm:%d, image buf addr:0x%x\n",
wm, addr);
@@ -174,6 +176,25 @@ static int vfe_halt(struct vfe_device *vfe)
return 0;
}

+const struct vfe_gen3_cfg vfe_gen3_cfg_690 = {
+ .bus_base_full = 0x400,
+ .bus_base_lite = 0x480,
+ .test_bus_ctrl = 0xFC,
+ .wm_base = 0x200,
+ .rdi_wm_full = 0x10,
+ .addr_shift = 0,
+ .disable_ds = true,
+};
+
+const struct vfe_gen3_cfg vfe_gen3_cfg_780 = {
+ .bus_base_full = 0xC00,
+ .bus_base_lite = 0x200,
+ .test_bus_ctrl = 0xDC,
+ .wm_base = 0x200,
+ .rdi_wm_full = 0x17,
+ .addr_shift = 8,
+};
+
const struct vfe_hw_ops vfe_ops_gen3 = {
.global_reset = vfe_global_reset,
.hw_version = vfe_hw_version,
diff --git a/drivers/media/platform/qcom/camss/camss-vfe.h b/drivers/media/platform/qcom/camss/camss-vfe.h
index c37526caf9a6fc052c3f4ab4215e635167f6da95..159a7c4f5ceb3b57f26a0e03e515776a158a7b7c 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe.h
+++ b/drivers/media/platform/qcom/camss/camss-vfe.h
@@ -98,6 +98,7 @@ struct vfe_line {
};

struct vfe_device;
+struct vfe_gen3_cfg;

struct vfe_hw_ops {
void (*addr_update)(struct vfe_device *vfe, enum vfe_line_id line_id);
@@ -143,6 +144,8 @@ struct vfe_subdev_resources {
bool has_vbif;
char *vbif_name;
const struct vfe_hw_ops *hw_ops;
+ /* VFE gen3 and later register layout */
+ const struct vfe_gen3_cfg *gen3_cfg;
const struct camss_formats *formats_rdi;
const struct camss_formats *formats_pix;
};
@@ -255,6 +258,9 @@ extern const struct vfe_hw_ops vfe_ops_680;
extern const struct vfe_hw_ops vfe_ops_1080;
extern const struct vfe_hw_ops vfe_ops_gen3;

+extern const struct vfe_gen3_cfg vfe_gen3_cfg_690;
+extern const struct vfe_gen3_cfg vfe_gen3_cfg_780;
+
int vfe_get(struct vfe_device *vfe);
void vfe_put(struct vfe_device *vfe);

diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c
index 3a5b7c665d3a913e06489e985348b38af97c2f39..7df72ed72959fcf08041d9ff990a98e334d2440d 100644
--- a/drivers/media/platform/qcom/camss/camss.c
+++ b/drivers/media/platform/qcom/camss/camss.c
@@ -3560,6 +3560,7 @@ static const struct camss_subdev_resources vfe_res_8550[] = {
.has_pd = true,
.pd_name = "ife0",
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -3584,6 +3585,7 @@ static const struct camss_subdev_resources vfe_res_8550[] = {
.has_pd = true,
.pd_name = "ife1",
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -3608,6 +3610,7 @@ static const struct camss_subdev_resources vfe_res_8550[] = {
.has_pd = true,
.pd_name = "ife2",
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -3629,6 +3632,7 @@ static const struct camss_subdev_resources vfe_res_8550[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -3650,6 +3654,7 @@ static const struct camss_subdev_resources vfe_res_8550[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -3936,6 +3941,7 @@ static const struct camss_subdev_resources vfe_res_sm8650[] = {
.has_pd = true,
.pd_name = "ife0",
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
},
@@ -3963,6 +3969,7 @@ static const struct camss_subdev_resources vfe_res_sm8650[] = {
.has_pd = true,
.pd_name = "ife1",
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
},
@@ -3990,6 +3997,7 @@ static const struct camss_subdev_resources vfe_res_sm8650[] = {
.has_pd = true,
.pd_name = "ife2",
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
},
@@ -4015,6 +4023,7 @@ static const struct camss_subdev_resources vfe_res_sm8650[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
},
@@ -4040,6 +4049,7 @@ static const struct camss_subdev_resources vfe_res_sm8650[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_780,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
},
@@ -4352,6 +4362,7 @@ static const struct camss_subdev_resources vfe_res_8775p[] = {
.has_pd = false,
.pd_name = NULL,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_690,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -4380,6 +4391,7 @@ static const struct camss_subdev_resources vfe_res_8775p[] = {
.has_pd = false,
.pd_name = NULL,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_690,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -4406,6 +4418,7 @@ static const struct camss_subdev_resources vfe_res_8775p[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_690,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -4432,6 +4445,7 @@ static const struct camss_subdev_resources vfe_res_8775p[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_690,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -4458,6 +4472,7 @@ static const struct camss_subdev_resources vfe_res_8775p[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_690,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -4484,6 +4499,7 @@ static const struct camss_subdev_resources vfe_res_8775p[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_690,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}
@@ -4510,6 +4526,7 @@ static const struct camss_subdev_resources vfe_res_8775p[] = {
.line_num = 4,
.is_lite = true,
.hw_ops = &vfe_ops_gen3,
+ .gen3_cfg = &vfe_gen3_cfg_690,
.formats_rdi = &vfe_formats_rdi_845,
.formats_pix = &vfe_formats_pix_845
}

--
2.34.1