Rework dc_subdev_get_id() to drop ARRAY_SIZE() use and use empty trailing
entry in each ID look up array instead. This allows passing of those arrays
around as OF match data, which will be useful when using this pipeline on
i.MX95, which has different address-to-ID mapping.

Signed-off-by: Marek Vasut <[email protected]>
---
Cc: Abel Vesa <[email protected]>
Cc: Conor Dooley <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Liu Ying <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Thomas Zimmermann <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
---
 drivers/gpu/drm/imx/dc/dc-cf.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-db.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-de.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-drv.h | 8 +++++---
 drivers/gpu/drm/imx/dc/dc-ed.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-fg.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-fl.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-fw.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-lb.c  | 3 ++-
 drivers/gpu/drm/imx/dc/dc-tc.c  | 3 ++-
 10 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/imx/dc/dc-cf.c b/drivers/gpu/drm/imx/dc/dc-cf.c
index 2f077161e9126..846705534546a 100644
--- a/drivers/gpu/drm/imx/dc/dc-cf.c
+++ b/drivers/gpu/drm/imx/dc/dc-cf.c
@@ -29,6 +29,7 @@ static const struct dc_subdev_info dc_cf_info[] = {
        { .reg_start = 0x561809e0, .id = 1, },
        { .reg_start = 0x561809a0, .id = 4, },
        { .reg_start = 0x56180a20, .id = 5, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_cf_regmap_ranges[] = {
@@ -106,7 +107,7 @@ static int dc_cf_bind(struct device *dev, struct device 
*master, void *data)
        if (IS_ERR(cf->reg_cfg))
                return PTR_ERR(cf->reg_cfg);
 
-       id = dc_subdev_get_id(dc_cf_info, ARRAY_SIZE(dc_cf_info), res_pec);
+       id = dc_subdev_get_id(dc_cf_info, res_pec);
        if (id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", id);
                return id;
diff --git a/drivers/gpu/drm/imx/dc/dc-db.c b/drivers/gpu/drm/imx/dc/dc-db.c
index 789942d1c446d..3958a2c4ec934 100644
--- a/drivers/gpu/drm/imx/dc/dc-db.c
+++ b/drivers/gpu/drm/imx/dc/dc-db.c
@@ -74,6 +74,7 @@ enum dc_db_shadow_sel {
 static const struct dc_subdev_info dc_db_info[] = {
        { .reg_start = 0x4b6a0000, .id = 0, },
        { .reg_start = 0x4b720000, .id = 1, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_db_regmap_ranges[] = {
@@ -176,7 +177,7 @@ static int dc_db_bind(struct device *dev, struct device 
*master, void *data)
        if (IS_ERR(db->reg_cfg))
                return PTR_ERR(db->reg_cfg);
 
-       db->id = dc_subdev_get_id(dc_db_info, ARRAY_SIZE(dc_db_info), res_cfg);
+       db->id = dc_subdev_get_id(dc_db_info, res_cfg);
        if (db->id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", db->id);
                return db->id;
diff --git a/drivers/gpu/drm/imx/dc/dc-de.c b/drivers/gpu/drm/imx/dc/dc-de.c
index 23b0cea68d325..81334c0088219 100644
--- a/drivers/gpu/drm/imx/dc/dc-de.c
+++ b/drivers/gpu/drm/imx/dc/dc-de.c
@@ -21,6 +21,7 @@
 static const struct dc_subdev_info dc_de_info[] = {
        { .reg_start = 0x5618b400, .id = 0, },
        { .reg_start = 0x5618b420, .id = 1, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_de_regmap_ranges[] = {
@@ -90,7 +91,7 @@ static int dc_de_bind(struct device *dev, struct device 
*master, void *data)
        if (ret)
                return ret;
 
-       id = dc_subdev_get_id(dc_de_info, ARRAY_SIZE(dc_de_info), res_top);
+       id = dc_subdev_get_id(dc_de_info, res_top);
        if (id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", id);
                return id;
diff --git a/drivers/gpu/drm/imx/dc/dc-drv.h b/drivers/gpu/drm/imx/dc/dc-drv.h
index 17ce2d748262b..a7ad17680a9b2 100644
--- a/drivers/gpu/drm/imx/dc/dc-drv.h
+++ b/drivers/gpu/drm/imx/dc/dc-drv.h
@@ -85,16 +85,18 @@ extern struct platform_driver dc_pe_driver;
 extern struct platform_driver dc_tc_driver;
 
 static inline int dc_subdev_get_id(const struct dc_subdev_info *info,
-                                  int info_cnt, struct resource *res)
+                                  struct resource *res)
 {
-       int i;
+       int i = 0;
 
        if (!res)
                return -EINVAL;
 
-       for (i = 0; i < info_cnt; i++)
+       while (info[i].reg_start) {
                if (info[i].reg_start == res->start)
                        return info[i].id;
+               i++;
+       }
 
        return -EINVAL;
 }
diff --git a/drivers/gpu/drm/imx/dc/dc-ed.c b/drivers/gpu/drm/imx/dc/dc-ed.c
index 86ecc22d0a554..a63c387a4c023 100644
--- a/drivers/gpu/drm/imx/dc/dc-ed.c
+++ b/drivers/gpu/drm/imx/dc/dc-ed.c
@@ -40,6 +40,7 @@ static const struct dc_subdev_info dc_ed_info[] = {
        { .reg_start = 0x56180a00, .id = 1, },
        { .reg_start = 0x561809c0, .id = 4, },
        { .reg_start = 0x56180a40, .id = 5, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_ed_pec_regmap_write_ranges[] = {
@@ -226,7 +227,7 @@ static int dc_ed_bind(struct device *dev, struct device 
*master, void *data)
 
        ed->dev = dev;
 
-       id = dc_subdev_get_id(dc_ed_info, ARRAY_SIZE(dc_ed_info), res_pec);
+       id = dc_subdev_get_id(dc_ed_info, res_pec);
        if (id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", id);
                return id;
diff --git a/drivers/gpu/drm/imx/dc/dc-fg.c b/drivers/gpu/drm/imx/dc/dc-fg.c
index 7f6c1852bf724..5fadd67aa911b 100644
--- a/drivers/gpu/drm/imx/dc/dc-fg.c
+++ b/drivers/gpu/drm/imx/dc/dc-fg.c
@@ -92,6 +92,7 @@ enum dc_fg_dm {
 static const struct dc_subdev_info dc_fg_info[] = {
        { .reg_start = 0x5618b800, .id = 0, },
        { .reg_start = 0x5618d400, .id = 1, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_fg_regmap_write_ranges[] = {
@@ -326,7 +327,7 @@ static int dc_fg_bind(struct device *dev, struct device 
*master, void *data)
                return dev_err_probe(dev, PTR_ERR(fg->clk_disp),
                                     "failed to get display clock\n");
 
-       id = dc_subdev_get_id(dc_fg_info, ARRAY_SIZE(dc_fg_info), res);
+       id = dc_subdev_get_id(dc_fg_info, res);
        if (id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", id);
                return id;
diff --git a/drivers/gpu/drm/imx/dc/dc-fl.c b/drivers/gpu/drm/imx/dc/dc-fl.c
index 3ce24c72aa13e..d4e746f8c4297 100644
--- a/drivers/gpu/drm/imx/dc/dc-fl.c
+++ b/drivers/gpu/drm/imx/dc/dc-fl.c
@@ -33,6 +33,7 @@ struct dc_fl {
 
 static const struct dc_subdev_info dc_fl_info[] = {
        { .reg_start = 0x56180ac0, .id = 0, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_fl_regmap_ranges[] = {
@@ -120,7 +121,7 @@ static int dc_fl_bind(struct device *dev, struct device 
*master, void *data)
        if (IS_ERR(fu->reg_cfg))
                return PTR_ERR(fu->reg_cfg);
 
-       id = dc_subdev_get_id(dc_fl_info, ARRAY_SIZE(dc_fl_info), res_pec);
+       id = dc_subdev_get_id(dc_fl_info, res_pec);
        if (id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", id);
                return id;
diff --git a/drivers/gpu/drm/imx/dc/dc-fw.c b/drivers/gpu/drm/imx/dc/dc-fw.c
index acb2d4d9e2ecd..c1131b7b17c2f 100644
--- a/drivers/gpu/drm/imx/dc/dc-fw.c
+++ b/drivers/gpu/drm/imx/dc/dc-fw.c
@@ -35,6 +35,7 @@ struct dc_fw {
 
 static const struct dc_subdev_info dc_fw_info[] = {
        { .reg_start = 0x56180a60, .id = 2, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_fw_pec_regmap_access_ranges[] = {
@@ -157,7 +158,7 @@ static int dc_fw_bind(struct device *dev, struct device 
*master, void *data)
        if (IS_ERR(fu->reg_cfg))
                return PTR_ERR(fu->reg_cfg);
 
-       id = dc_subdev_get_id(dc_fw_info, ARRAY_SIZE(dc_fw_info), res_pec);
+       id = dc_subdev_get_id(dc_fw_info, res_pec);
        if (id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", id);
                return id;
diff --git a/drivers/gpu/drm/imx/dc/dc-lb.c b/drivers/gpu/drm/imx/dc/dc-lb.c
index 38f966625d382..34ea61c2de87d 100644
--- a/drivers/gpu/drm/imx/dc/dc-lb.c
+++ b/drivers/gpu/drm/imx/dc/dc-lb.c
@@ -76,6 +76,7 @@ static const struct dc_subdev_info dc_lb_info[] = {
        { .reg_start = 0x56180bc0, .id = 1, },
        { .reg_start = 0x56180be0, .id = 2, },
        { .reg_start = 0x56180c00, .id = 3, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_lb_pec_regmap_access_ranges[] = {
@@ -273,7 +274,7 @@ static int dc_lb_bind(struct device *dev, struct device 
*master, void *data)
        if (IS_ERR(lb->reg_cfg))
                return PTR_ERR(lb->reg_cfg);
 
-       lb->id = dc_subdev_get_id(dc_lb_info, ARRAY_SIZE(dc_lb_info), res_pec);
+       lb->id = dc_subdev_get_id(dc_lb_info, res_pec);
        if (lb->id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", lb->id);
                return lb->id;
diff --git a/drivers/gpu/drm/imx/dc/dc-tc.c b/drivers/gpu/drm/imx/dc/dc-tc.c
index 0bfd381b2cea1..f44b68c0a5e6d 100644
--- a/drivers/gpu/drm/imx/dc/dc-tc.c
+++ b/drivers/gpu/drm/imx/dc/dc-tc.c
@@ -28,6 +28,7 @@
 static const struct dc_subdev_info dc_tc_info[] = {
        { .reg_start = 0x5618c800, .id = 0, },
        { .reg_start = 0x5618e400, .id = 1, },
+       { /* sentinel */ },
 };
 
 static const struct regmap_range dc_tc_regmap_ranges[] = {
@@ -91,7 +92,7 @@ static int dc_tc_bind(struct device *dev, struct device 
*master, void *data)
        if (IS_ERR(tc->reg))
                return PTR_ERR(tc->reg);
 
-       id = dc_subdev_get_id(dc_tc_info, ARRAY_SIZE(dc_tc_info), res);
+       id = dc_subdev_get_id(dc_tc_info, res);
        if (id < 0) {
                dev_err(dev, "failed to get instance number: %d\n", id);
                return id;
-- 
2.51.0

Reply via email to