media: qcom: camss: Flag VFE-lites to support more VFEs
authorMatti Lehtimäki <matti.lehtimaki@gmail.com>
Thu, 23 Nov 2023 17:03:05 +0000 (17:03 +0000)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Thu, 7 Dec 2023 07:31:15 +0000 (08:31 +0100)
Some platforms such as SC7280 have three VFEs and two VFE-lites. Current
code has hard-coded two as the maximum number of VFEs. Remove the
hard-coded maximum number of VFEs to handle all possible combinations of
VFEs and VFE-lites.

Signed-off-by: Matti Lehtimäki <matti.lehtimaki@gmail.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202311200405.h6G4L9oe-lkp@intel.com
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/platform/qcom/camss/camss-vfe-480.c
drivers/media/platform/qcom/camss/camss-vfe.c
drivers/media/platform/qcom/camss/camss-vfe.h
drivers/media/platform/qcom/camss/camss.c
drivers/media/platform/qcom/camss/camss.h

index 4652e8b4cff5847f80684d0d91c806ba30c8312a..dc2735476c82315a0bb4520b9c18e323535459e5 100644 (file)
 #include "camss.h"
 #include "camss-vfe.h"
 
-/* VFE 2/3 are lite and have a different register layout */
-#define IS_LITE                (vfe->id >= 2 ? 1 : 0)
-
 #define VFE_HW_VERSION                 (0x00)
 
-#define VFE_GLOBAL_RESET_CMD           (IS_LITE ? 0x0c : 0x1c)
-#define            GLOBAL_RESET_HW_AND_REG     (IS_LITE ? BIT(1) : BIT(0))
+#define VFE_GLOBAL_RESET_CMD           (vfe_is_lite(vfe) ? 0x0c : 0x1c)
+#define            GLOBAL_RESET_HW_AND_REG     (vfe_is_lite(vfe) ? BIT(1) : BIT(0))
 
-#define VFE_REG_UPDATE_CMD             (IS_LITE ? 0x20 : 0x34)
+#define VFE_REG_UPDATE_CMD             (vfe_is_lite(vfe) ? 0x20 : 0x34)
 static inline int reg_update_rdi(struct vfe_device *vfe, int n)
 {
-       return IS_LITE ? BIT(n) : BIT(1 + (n));
+       return vfe_is_lite(vfe) ? BIT(n) : BIT(1 + (n));
 }
 
 #define            REG_UPDATE_RDI              reg_update_rdi
-#define VFE_IRQ_CMD                    (IS_LITE ? 0x24 : 0x38)
+#define VFE_IRQ_CMD                    (vfe_is_lite(vfe) ? 0x24 : 0x38)
 #define     IRQ_CMD_GLOBAL_CLEAR       BIT(0)
 
-#define VFE_IRQ_MASK(n)                        ((IS_LITE ? 0x28 : 0x3c) + (n) * 4)
-#define            IRQ_MASK_0_RESET_ACK        (IS_LITE ? BIT(17) : BIT(0))
-#define            IRQ_MASK_0_BUS_TOP_IRQ      (IS_LITE ? BIT(4) : BIT(7))
-#define VFE_IRQ_CLEAR(n)               ((IS_LITE ? 0x34 : 0x48) + (n) * 4)
-#define VFE_IRQ_STATUS(n)              ((IS_LITE ? 0x40 : 0x54) + (n) * 4)
+#define VFE_IRQ_MASK(n)                        ((vfe_is_lite(vfe) ? 0x28 : 0x3c) + (n) * 4)
+#define            IRQ_MASK_0_RESET_ACK        (vfe_is_lite(vfe) ? BIT(17) : BIT(0))
+#define            IRQ_MASK_0_BUS_TOP_IRQ      (vfe_is_lite(vfe) ? BIT(4) : BIT(7))
+#define VFE_IRQ_CLEAR(n)               ((vfe_is_lite(vfe) ? 0x34 : 0x48) + (n) * 4)
+#define VFE_IRQ_STATUS(n)              ((vfe_is_lite(vfe) ? 0x40 : 0x54) + (n) * 4)
 
-#define BUS_REG_BASE                   (IS_LITE ? 0x1a00 : 0xaa00)
+#define BUS_REG_BASE                   (vfe_is_lite(vfe) ? 0x1a00 : 0xaa00)
 
 #define VFE_BUS_WM_CGC_OVERRIDE                (BUS_REG_BASE + 0x08)
 #define                WM_CGC_OVERRIDE_ALL     (0x3FFFFFF)
@@ -49,13 +46,13 @@ static inline int reg_update_rdi(struct vfe_device *vfe, int n)
 #define VFE_BUS_IRQ_MASK(n)            (BUS_REG_BASE + 0x18 + (n) * 4)
 static inline int bus_irq_mask_0_rdi_rup(struct vfe_device *vfe, int n)
 {
-       return IS_LITE ? BIT(n) : BIT(3 + (n));
+       return vfe_is_lite(vfe) ? BIT(n) : BIT(3 + (n));
 }
 
 #define     BUS_IRQ_MASK_0_RDI_RUP     bus_irq_mask_0_rdi_rup
 static inline int bus_irq_mask_0_comp_done(struct vfe_device *vfe, int n)
 {
-       return IS_LITE ? BIT(4 + (n)) : BIT(6 + (n));
+       return vfe_is_lite(vfe) ? BIT(4 + (n)) : BIT(6 + (n));
 }
 
 #define     BUS_IRQ_MASK_0_COMP_DONE   bus_irq_mask_0_comp_done
@@ -90,8 +87,8 @@ static inline int bus_irq_mask_0_comp_done(struct vfe_device *vfe, int n)
 /* for titan 480, each bus client is hardcoded to a specific path
  * and each bus client is part of a hardcoded "comp group"
  */
-#define RDI_WM(n)                      ((IS_LITE ? 0 : 23) + (n))
-#define RDI_COMP_GROUP(n)              ((IS_LITE ? 0 : 11) + (n))
+#define RDI_WM(n)                      ((vfe_is_lite(vfe) ? 0 : 23) + (n))
+#define RDI_COMP_GROUP(n)              ((vfe_is_lite(vfe) ? 0 : 11) + (n))
 
 #define MAX_VFE_OUTPUT_LINES   4
 
index b2f91c00acafd9b24f408f70b766f97cdf31e2dc..2062be668f49d8a11a6016fd7de9994eb998ee65 100644 (file)
@@ -1737,3 +1737,8 @@ void msm_vfe_unregister_entities(struct vfe_device *vfe)
                media_entity_cleanup(&sd->entity);
        }
 }
+
+bool vfe_is_lite(struct vfe_device *vfe)
+{
+       return vfe->camss->res->vfe_res[vfe->id].is_lite;
+}
index cdbe59d8d437edd60b8c37c7389426012a6fe8ec..0572c9b08e112760fafc4a3503cb7b10f38bb3a8 100644 (file)
@@ -226,4 +226,14 @@ extern const struct vfe_hw_ops vfe_ops_480;
 int vfe_get(struct vfe_device *vfe);
 void vfe_put(struct vfe_device *vfe);
 
+/*
+ * vfe_is_lite - Return if VFE is VFE lite.
+ * @vfe: VFE Device
+ *
+ * Some VFE lites have a different register layout.
+ *
+ * Return whether VFE is VFE lite
+ */
+bool vfe_is_lite(struct vfe_device *vfe);
+
 #endif /* QC_MSM_CAMSS_VFE_H */
index 8de0e9e8d34b1f3648bc55fb94ea9abc29e7a9a8..cdb9254cd8b463c1bb5da53152a8213c0a2dec6d 100644 (file)
@@ -706,6 +706,7 @@ static const struct camss_subdev_resources vfe_res_845[] = {
                                { 384000000 } },
                .reg = { "vfe_lite" },
                .interrupt = { "vfe_lite" },
+               .is_lite = true,
                .line_num = 4,
                .ops = &vfe_ops_170
        }
@@ -886,6 +887,7 @@ static const struct camss_subdev_resources vfe_res_8250[] = {
                                { 0 } },
                .reg = { "vfe_lite0" },
                .interrupt = { "vfe_lite0" },
+               .is_lite = true,
                .line_num = 4,
                .ops = &vfe_ops_480
        },
@@ -905,6 +907,7 @@ static const struct camss_subdev_resources vfe_res_8250[] = {
                                { 0 } },
                .reg = { "vfe_lite1" },
                .interrupt = { "vfe_lite1" },
+               .is_lite = true,
                .line_num = 4,
                .ops = &vfe_ops_480
        },
@@ -1204,7 +1207,7 @@ static int camss_init_subdevices(struct camss *camss)
        }
 
        /* note: SM8250 requires VFE to be initialized before CSID */
-       for (i = 0; i < camss->vfe_total_num; i++) {
+       for (i = 0; i < camss->res->vfe_num; i++) {
                ret = msm_vfe_subdev_init(camss, &camss->vfe[i],
                                          &res->vfe_res[i], i);
                if (ret < 0) {
@@ -1276,7 +1279,7 @@ static int camss_register_entities(struct camss *camss)
                goto err_reg_ispif;
        }
 
-       for (i = 0; i < camss->vfe_total_num; i++) {
+       for (i = 0; i < camss->res->vfe_num; i++) {
                ret = msm_vfe_register_entities(&camss->vfe[i],
                                                &camss->v4l2_dev);
                if (ret < 0) {
@@ -1348,7 +1351,7 @@ static int camss_register_entities(struct camss *camss)
                                }
        } else {
                for (i = 0; i < camss->res->csid_num; i++)
-                       for (k = 0; k < camss->vfe_total_num; k++)
+                       for (k = 0; k < camss->res->vfe_num; k++)
                                for (j = 0; j < camss->vfe[k].line_num; j++) {
                                        struct v4l2_subdev *csid = &camss->csid[i].subdev;
                                        struct v4l2_subdev *vfe = &camss->vfe[k].line[j].subdev;
@@ -1372,7 +1375,7 @@ static int camss_register_entities(struct camss *camss)
        return 0;
 
 err_link:
-       i = camss->vfe_total_num;
+       i = camss->res->vfe_num;
 err_reg_vfe:
        for (i--; i >= 0; i--)
                msm_vfe_unregister_entities(&camss->vfe[i]);
@@ -1411,7 +1414,7 @@ static void camss_unregister_entities(struct camss *camss)
 
        msm_ispif_unregister_entities(camss->ispif);
 
-       for (i = 0; i < camss->vfe_total_num; i++)
+       for (i = 0; i < camss->res->vfe_num; i++)
                msm_vfe_unregister_entities(&camss->vfe[i]);
 }
 
@@ -1509,7 +1512,7 @@ static int camss_configure_pd(struct camss *camss)
                return 0;
 
        /* count the # of VFEs which have flagged power-domain */
-       for (vfepd_num = i = 0; i < camss->vfe_total_num; i++) {
+       for (vfepd_num = i = 0; i < camss->res->vfe_num; i++) {
                if (res->vfe_res[i].has_pd)
                        vfepd_num++;
        }
@@ -1587,7 +1590,7 @@ static void camss_genpd_subdevice_cleanup(struct camss *camss)
 {
        int i;
 
-       for (i = 0; i < camss->vfe_total_num; i++)
+       for (i = 0; i < camss->res->vfe_num; i++)
                msm_vfe_genpd_cleanup(&camss->vfe[i]);
 }
 
@@ -1644,8 +1647,7 @@ static int camss_probe(struct platform_device *pdev)
                        return -ENOMEM;
        }
 
-       camss->vfe_total_num = camss->res->vfe_num + camss->res->vfe_lite_num;
-       camss->vfe = devm_kcalloc(dev, camss->vfe_total_num,
+       camss->vfe = devm_kcalloc(dev, camss->res->vfe_num,
                                  sizeof(*camss->vfe), GFP_KERNEL);
        if (!camss->vfe)
                return -ENOMEM;
@@ -1803,8 +1805,7 @@ static const struct camss_resources sdm845_resources = {
        .vfe_res = vfe_res_845,
        .csiphy_num = ARRAY_SIZE(csiphy_res_845),
        .csid_num = ARRAY_SIZE(csid_res_845),
-       .vfe_num = 2,
-       .vfe_lite_num = 1,
+       .vfe_num = ARRAY_SIZE(vfe_res_845),
 };
 
 static const struct camss_resources sm8250_resources = {
@@ -1816,8 +1817,7 @@ static const struct camss_resources sm8250_resources = {
        .icc_path_num = ARRAY_SIZE(icc_res_sm8250),
        .csiphy_num = ARRAY_SIZE(csiphy_res_8250),
        .csid_num = ARRAY_SIZE(csid_res_8250),
-       .vfe_num = 2,
-       .vfe_lite_num = 2,
+       .vfe_num = ARRAY_SIZE(vfe_res_8250),
 };
 
 static const struct of_device_id camss_dt_match[] = {
index cd8186fe1797b34c68f714079e2ac8ad75302941..a0c2dcc779f05c14a382195c8dbc1ac80a1c146b 100644 (file)
@@ -51,6 +51,7 @@ struct camss_subdev_resources {
        char *pd_name;
        u8 line_num;
        bool has_pd;
+       bool is_lite;
        const void *ops;
 };
 
@@ -95,7 +96,6 @@ struct camss_resources {
        const unsigned int csiphy_num;
        const unsigned int csid_num;
        const unsigned int vfe_num;
-       const unsigned int vfe_lite_num;
 };
 
 struct camss {
@@ -113,7 +113,6 @@ struct camss {
        struct device_link *genpd_link;
        struct icc_path *icc_path[ICC_SM8250_COUNT];
        const struct camss_resources *res;
-       unsigned int vfe_total_num;
 };
 
 struct camss_camera_interface {