Introduce struct dc_lb_subdev_match_data which describes the differences
between i.MX8QXP and i.MX95, which in this case link ID mapping as well
as address space offsets, and pass it as OF match data into the driver, so
the driver can use the match data to correctly select pixel data routing.
This is a preparatory patch for i.MX95 addition. No functional change.

Signed-off-by: Marek Vasut <marek.va...@mailbox.org>
---
Cc: Abel Vesa <abelv...@kernel.org>
Cc: Conor Dooley <conor...@kernel.org>
Cc: Fabio Estevam <feste...@gmail.com>
Cc: Krzysztof Kozlowski <krzk...@kernel.org>
Cc: Laurent Pinchart <laurent.pinch...@ideasonboard.com>
Cc: Liu Ying <victor....@nxp.com>
Cc: Lucas Stach <l.st...@pengutronix.de>
Cc: Peng Fan <peng....@nxp.com>
Cc: Pengutronix Kernel Team <ker...@pengutronix.de>
Cc: Rob Herring <r...@kernel.org>
Cc: Shawn Guo <shawn...@kernel.org>
Cc: Thomas Zimmermann <tzimmerm...@suse.de>
Cc: devicet...@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Cc: i...@lists.linux.dev
Cc: linux-arm-ker...@lists.infradead.org
Cc: linux-...@vger.kernel.org
---
 drivers/gpu/drm/imx/dc/dc-lb.c | 42 ++++++++++++++++++++++++++--------
 drivers/gpu/drm/imx/dc/dc-pe.h |  3 +++
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/imx/dc/dc-lb.c b/drivers/gpu/drm/imx/dc/dc-lb.c
index 619353456743c..ba9183b244ab3 100644
--- a/drivers/gpu/drm/imx/dc/dc-lb.c
+++ b/drivers/gpu/drm/imx/dc/dc-lb.c
@@ -56,6 +56,14 @@
 #define  YPOS_MASK                             GENMASK(31, 16)
 #define  YPOS(x)                               FIELD_PREP(YPOS_MASK, (x))
 
+struct dc_lb_subdev_match_data {
+       const enum dc_link_id           *pri_sels;
+       const enum dc_link_id           *sec_sels;
+       const enum dc_link_id           first_lb;
+       unsigned int                    last_cf;
+       const struct dc_subdev_info     *info;
+};
+
 enum dc_lb_blend_func {
        DC_LAYERBLEND_BLEND_ZERO,
        DC_LAYERBLEND_BLEND_ONE,
@@ -119,7 +127,7 @@ static const struct regmap_config dc_lb_cfg_regmap_config = 
{
        .max_register = POSITION,
 };
 
-static const enum dc_link_id prim_sels[] = {
+static const enum dc_link_id prim_sels_imx8qxp[] = {
        /* common options */
        LINK_ID_NONE,
        LINK_ID_CONSTFRAME0,
@@ -137,12 +145,22 @@ static const enum dc_link_id prim_sels[] = {
        LINK_ID_LAYERBLEND1_MX8QXP,
        LINK_ID_LAYERBLEND2_MX8QXP,
        LINK_ID_LAYERBLEND3_MX8QXP,
+       LINK_ID_LAST
 };
 
-static const enum dc_link_id sec_sels[] = {
+static const enum dc_link_id sec_sels_imx8qxp[] = {
        LINK_ID_NONE,
        LINK_ID_FETCHWARP2,
        LINK_ID_FETCHLAYER0,
+       LINK_ID_LAST
+};
+
+static const struct dc_lb_subdev_match_data dc_lb_match_data_imx8qxp = {
+       .pri_sels = prim_sels_imx8qxp,
+       .sec_sels = sec_sels_imx8qxp,
+       .first_lb = LINK_ID_LAYERBLEND0_MX8QXP,
+       .last_cf = 5,
+       .info = dc_lb_info_imx8qxp,
 };
 
 enum dc_link_id dc_lb_get_link_id(struct dc_lb *lb)
@@ -152,11 +170,10 @@ enum dc_link_id dc_lb_get_link_id(struct dc_lb *lb)
 
 void dc_lb_pec_dynamic_prim_sel(struct dc_lb *lb, enum dc_link_id prim)
 {
-       int fixed_sels_num = ARRAY_SIZE(prim_sels) - 4;
        int i;
 
-       for (i = 0; i < fixed_sels_num + lb->id; i++) {
-               if (prim_sels[i] == prim) {
+       for (i = 0; i < lb->last_cf + lb->id; i++) {
+               if (lb->pri_sels[i] == prim) {
                        regmap_write_bits(lb->reg_pec, PIXENGCFG_DYNAMIC,
                                          PIXENGCFG_DYNAMIC_PRIM_SEL_MASK,
                                          PIXENGCFG_DYNAMIC_PRIM_SEL(prim));
@@ -169,10 +186,10 @@ void dc_lb_pec_dynamic_prim_sel(struct dc_lb *lb, enum 
dc_link_id prim)
 
 void dc_lb_pec_dynamic_sec_sel(struct dc_lb *lb, enum dc_link_id sec)
 {
-       int i;
+       int i = 0;
 
-       for (i = 0; i < ARRAY_SIZE(sec_sels); i++) {
-               if (sec_sels[i] == sec) {
+       while (lb->sec_sels[i] != LINK_ID_LAST) {
+               if (lb->sec_sels[i++] == sec) {
                        regmap_write_bits(lb->reg_pec, PIXENGCFG_DYNAMIC,
                                          PIXENGCFG_DYNAMIC_SEC_SEL_MASK,
                                          PIXENGCFG_DYNAMIC_SEC_SEL(sec));
@@ -245,6 +262,8 @@ void dc_lb_init(struct dc_lb *lb)
 
 static int dc_lb_bind(struct device *dev, struct device *master, void *data)
 {
+       const struct dc_lb_subdev_match_data *dc_lb_match_data = 
device_get_match_data(dev);
+       const struct dc_subdev_info *dc_lb_info = dc_lb_match_data->info;
        struct platform_device *pdev = to_platform_device(dev);
        struct dc_drm_device *dc_drm = data;
        struct resource *res_pec;
@@ -281,7 +300,10 @@ static int dc_lb_bind(struct device *dev, struct device 
*master, void *data)
        }
 
        lb->dev = dev;
-       lb->link = LINK_ID_LAYERBLEND0_MX8QXP + lb->id;
+       lb->link = dc_lb_match_data->first_lb + lb->id;
+       lb->pri_sels = dc_lb_match_data->pri_sels;
+       lb->sec_sels = dc_lb_match_data->sec_sels;
+       lb->last_cf = dc_lb_match_data->last_cf;
 
        dc_drm->lb[lb->id] = lb;
 
@@ -310,7 +332,7 @@ static void dc_lb_remove(struct platform_device *pdev)
 }
 
 static const struct of_device_id dc_lb_dt_ids[] = {
-       { .compatible = "fsl,imx8qxp-dc-layerblend" },
+       { .compatible = "fsl,imx8qxp-dc-layerblend", .data = 
&dc_lb_match_data_imx8qxp },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, dc_lb_dt_ids);
diff --git a/drivers/gpu/drm/imx/dc/dc-pe.h b/drivers/gpu/drm/imx/dc/dc-pe.h
index 7928f947b0cef..492d193127bc1 100644
--- a/drivers/gpu/drm/imx/dc/dc-pe.h
+++ b/drivers/gpu/drm/imx/dc/dc-pe.h
@@ -65,6 +65,9 @@ struct dc_lb {
        struct regmap *reg_cfg;
        int id;
        enum dc_link_id link;
+       const enum dc_link_id *pri_sels;
+       const enum dc_link_id *sec_sels;
+       unsigned int last_cf;
 };
 
 struct dc_pe {
-- 
2.51.0

Reply via email to