drm/imx: imx-ldb: move initialization into probe
authorPhilipp Zabel <p.zabel@pengutronix.de>
Thu, 10 Dec 2020 15:38:34 +0000 (16:38 +0100)
committerPhilipp Zabel <p.zabel@pengutronix.de>
Mon, 4 Jan 2021 11:59:33 +0000 (12:59 +0100)
Parts of the initialization that do not require the drm device can be
done once during probe instead of possibly multiple times during bind.
The bind function only creates the encoders.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/imx/imx-ldb.c

index 288a81f134fefcce345acce8534914033308da96..c3639cc32ddfbfadd7ac4fb0654a07dabb7b28c5 100644 (file)
@@ -415,6 +415,9 @@ static int imx_ldb_register(struct drm_device *drm,
        struct drm_encoder *encoder = &imx_ldb_ch->encoder;
        int ret;
 
+       memset(connector, 0, sizeof(*connector));
+       memset(encoder, 0, sizeof(*encoder));
+
        ret = imx_drm_encoder_parse_of(drm, encoder, imx_ldb_ch->child);
        if (ret)
                return ret;
@@ -559,17 +562,42 @@ static int imx_ldb_panel_ddc(struct device *dev,
 static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
 {
        struct drm_device *drm = data;
+       struct imx_ldb *imx_ldb = dev_get_drvdata(dev);
+       int ret;
+       int i;
+
+       for (i = 0; i < 2; i++) {
+               struct imx_ldb_channel *channel = &imx_ldb->channel[i];
+
+               if (!channel->ldb)
+                       break;
+
+               ret = imx_ldb_register(drm, channel);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static const struct component_ops imx_ldb_ops = {
+       .bind   = imx_ldb_bind,
+};
+
+static int imx_ldb_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
        struct device_node *np = dev->of_node;
-       const struct of_device_id *of_id =
-                       of_match_device(imx_ldb_dt_ids, dev);
+       const struct of_device_id *of_id = of_match_device(imx_ldb_dt_ids, dev);
        struct device_node *child;
        struct imx_ldb *imx_ldb;
        int dual;
        int ret;
        int i;
 
-       imx_ldb = dev_get_drvdata(dev);
-       memset(imx_ldb, 0, sizeof(*imx_ldb));
+       imx_ldb = devm_kzalloc(dev, sizeof(*imx_ldb), GFP_KERNEL);
+       if (!imx_ldb)
+               return -ENOMEM;
 
        imx_ldb->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
        if (IS_ERR(imx_ldb->regmap)) {
@@ -669,25 +697,20 @@ static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
                }
                channel->bus_format = bus_format;
                channel->child = child;
-
-               ret = imx_ldb_register(drm, channel);
-               if (ret) {
-                       channel->child = NULL;
-                       goto free_child;
-               }
        }
 
-       return 0;
+       platform_set_drvdata(pdev, imx_ldb);
+
+       return component_add(&pdev->dev, &imx_ldb_ops);
 
 free_child:
        of_node_put(child);
        return ret;
 }
 
-static void imx_ldb_unbind(struct device *dev, struct device *master,
-       void *data)
+static int imx_ldb_remove(struct platform_device *pdev)
 {
-       struct imx_ldb *imx_ldb = dev_get_drvdata(dev);
+       struct imx_ldb *imx_ldb = platform_get_drvdata(pdev);
        int i;
 
        for (i = 0; i < 2; i++) {
@@ -696,28 +719,7 @@ static void imx_ldb_unbind(struct device *dev, struct device *master,
                kfree(channel->edid);
                i2c_put_adapter(channel->ddc);
        }
-}
-
-static const struct component_ops imx_ldb_ops = {
-       .bind   = imx_ldb_bind,
-       .unbind = imx_ldb_unbind,
-};
 
-static int imx_ldb_probe(struct platform_device *pdev)
-{
-       struct imx_ldb *imx_ldb;
-
-       imx_ldb = devm_kzalloc(&pdev->dev, sizeof(*imx_ldb), GFP_KERNEL);
-       if (!imx_ldb)
-               return -ENOMEM;
-
-       platform_set_drvdata(pdev, imx_ldb);
-
-       return component_add(&pdev->dev, &imx_ldb_ops);
-}
-
-static int imx_ldb_remove(struct platform_device *pdev)
-{
        component_del(&pdev->dev, &imx_ldb_ops);
        return 0;
 }