Skip to content

Commit

Permalink
drm/imx: imx-ldb: move initialization into probe
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Philipp Zabel committed Jan 4, 2021
1 parent bed00dd commit 8767f47
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions drivers/gpu/drm/imx/imx-ldb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 8767f47

Please sign in to comment.