Commit 8208ed93 authored by Archit Taneja's avatar Archit Taneja Committed by Rob Clark

drm/msm: Centralize connector registration/unregistration

Move the drm_connector registration from the encoder(HDMI/DSI etc) drivers
to the msm platform driver. This will simplify the task of ensuring that
the connectors are registered only after the drm_device itself is
registered.

The connectors' destroy ops are made to use kzalloc instead of
devm_kzalloc to ensure that that the connectors can be successfully
unregistered when the msm driver module is removed. The memory for the
connectors is unallocated when drm_mode_config_cleanup() is called
during either during an error or during driver remove.
Signed-off-by: default avatarArchit Taneja <architt@codeaurora.org>
Signed-off-by: default avatarRob Clark <robdclark@gmail.com>
parent c899f935
...@@ -198,9 +198,13 @@ static enum drm_connector_status dsi_mgr_connector_detect( ...@@ -198,9 +198,13 @@ static enum drm_connector_status dsi_mgr_connector_detect(
static void dsi_mgr_connector_destroy(struct drm_connector *connector) static void dsi_mgr_connector_destroy(struct drm_connector *connector)
{ {
struct dsi_connector *dsi_connector = to_dsi_connector(connector);
DBG(""); DBG("");
drm_connector_unregister(connector);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
kfree(dsi_connector);
} }
static void dsi_dual_connector_fix_modes(struct drm_connector *connector) static void dsi_dual_connector_fix_modes(struct drm_connector *connector)
...@@ -538,12 +542,9 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id) ...@@ -538,12 +542,9 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id)
struct dsi_connector *dsi_connector; struct dsi_connector *dsi_connector;
int ret, i; int ret, i;
dsi_connector = devm_kzalloc(msm_dsi->dev->dev, dsi_connector = kzalloc(sizeof(*dsi_connector), GFP_KERNEL);
sizeof(*dsi_connector), GFP_KERNEL); if (!dsi_connector)
if (!dsi_connector) { return ERR_PTR(-ENOMEM);
ret = -ENOMEM;
goto fail;
}
dsi_connector->id = id; dsi_connector->id = id;
...@@ -552,7 +553,7 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id) ...@@ -552,7 +553,7 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id)
ret = drm_connector_init(msm_dsi->dev, connector, ret = drm_connector_init(msm_dsi->dev, connector,
&dsi_mgr_connector_funcs, DRM_MODE_CONNECTOR_DSI); &dsi_mgr_connector_funcs, DRM_MODE_CONNECTOR_DSI);
if (ret) if (ret)
goto fail; return ERR_PTR(ret);
drm_connector_helper_add(connector, &dsi_mgr_conn_helper_funcs); drm_connector_helper_add(connector, &dsi_mgr_conn_helper_funcs);
...@@ -565,21 +566,11 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id) ...@@ -565,21 +566,11 @@ struct drm_connector *msm_dsi_manager_connector_init(u8 id)
connector->interlace_allowed = 0; connector->interlace_allowed = 0;
connector->doublescan_allowed = 0; connector->doublescan_allowed = 0;
ret = drm_connector_register(connector);
if (ret)
goto fail;
for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) for (i = 0; i < MSM_DSI_ENCODER_NUM; i++)
drm_mode_connector_attach_encoder(connector, drm_mode_connector_attach_encoder(connector,
msm_dsi->encoders[i]); msm_dsi->encoders[i]);
return connector; return connector;
fail:
if (connector)
dsi_mgr_connector_destroy(connector);
return ERR_PTR(ret);
} }
/* initialize bridge */ /* initialize bridge */
......
...@@ -37,7 +37,7 @@ static void edp_connector_destroy(struct drm_connector *connector) ...@@ -37,7 +37,7 @@ static void edp_connector_destroy(struct drm_connector *connector)
struct edp_connector *edp_connector = to_edp_connector(connector); struct edp_connector *edp_connector = to_edp_connector(connector);
DBG(""); DBG("");
drm_connector_unregister(connector);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
kfree(edp_connector); kfree(edp_connector);
...@@ -124,10 +124,8 @@ struct drm_connector *msm_edp_connector_init(struct msm_edp *edp) ...@@ -124,10 +124,8 @@ struct drm_connector *msm_edp_connector_init(struct msm_edp *edp)
int ret; int ret;
edp_connector = kzalloc(sizeof(*edp_connector), GFP_KERNEL); edp_connector = kzalloc(sizeof(*edp_connector), GFP_KERNEL);
if (!edp_connector) { if (!edp_connector)
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto fail;
}
edp_connector->edp = edp; edp_connector->edp = edp;
...@@ -136,7 +134,7 @@ struct drm_connector *msm_edp_connector_init(struct msm_edp *edp) ...@@ -136,7 +134,7 @@ struct drm_connector *msm_edp_connector_init(struct msm_edp *edp)
ret = drm_connector_init(edp->dev, connector, &edp_connector_funcs, ret = drm_connector_init(edp->dev, connector, &edp_connector_funcs,
DRM_MODE_CONNECTOR_eDP); DRM_MODE_CONNECTOR_eDP);
if (ret) if (ret)
goto fail; return ERR_PTR(ret);
drm_connector_helper_add(connector, &edp_connector_helper_funcs); drm_connector_helper_add(connector, &edp_connector_helper_funcs);
...@@ -147,17 +145,7 @@ struct drm_connector *msm_edp_connector_init(struct msm_edp *edp) ...@@ -147,17 +145,7 @@ struct drm_connector *msm_edp_connector_init(struct msm_edp *edp)
connector->interlace_allowed = false; connector->interlace_allowed = false;
connector->doublescan_allowed = false; connector->doublescan_allowed = false;
ret = drm_connector_register(connector);
if (ret)
goto fail;
drm_mode_connector_attach_encoder(connector, edp->encoder); drm_mode_connector_attach_encoder(connector, edp->encoder);
return connector; return connector;
fail:
if (connector)
edp_connector_destroy(connector);
return ERR_PTR(ret);
} }
...@@ -346,7 +346,6 @@ static void hdmi_connector_destroy(struct drm_connector *connector) ...@@ -346,7 +346,6 @@ static void hdmi_connector_destroy(struct drm_connector *connector)
hdp_disable(hdmi_connector); hdp_disable(hdmi_connector);
drm_connector_unregister(connector);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
kfree(hdmi_connector); kfree(hdmi_connector);
...@@ -438,10 +437,8 @@ struct drm_connector *msm_hdmi_connector_init(struct hdmi *hdmi) ...@@ -438,10 +437,8 @@ struct drm_connector *msm_hdmi_connector_init(struct hdmi *hdmi)
int ret; int ret;
hdmi_connector = kzalloc(sizeof(*hdmi_connector), GFP_KERNEL); hdmi_connector = kzalloc(sizeof(*hdmi_connector), GFP_KERNEL);
if (!hdmi_connector) { if (!hdmi_connector)
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto fail;
}
hdmi_connector->hdmi = hdmi; hdmi_connector->hdmi = hdmi;
INIT_WORK(&hdmi_connector->hpd_work, msm_hdmi_hotplug_work); INIT_WORK(&hdmi_connector->hpd_work, msm_hdmi_hotplug_work);
...@@ -458,21 +455,13 @@ struct drm_connector *msm_hdmi_connector_init(struct hdmi *hdmi) ...@@ -458,21 +455,13 @@ struct drm_connector *msm_hdmi_connector_init(struct hdmi *hdmi)
connector->interlace_allowed = 0; connector->interlace_allowed = 0;
connector->doublescan_allowed = 0; connector->doublescan_allowed = 0;
drm_connector_register(connector);
ret = hpd_enable(hdmi_connector); ret = hpd_enable(hdmi_connector);
if (ret) { if (ret) {
dev_err(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret); dev_err(&hdmi->pdev->dev, "failed to enable HPD: %d\n", ret);
goto fail; return ERR_PTR(ret);
} }
drm_mode_connector_attach_encoder(connector, hdmi->encoder); drm_mode_connector_attach_encoder(connector, hdmi->encoder);
return connector; return connector;
fail:
if (connector)
hdmi_connector_destroy(connector);
return ERR_PTR(ret);
} }
...@@ -48,7 +48,6 @@ static void mdp4_lvds_connector_destroy(struct drm_connector *connector) ...@@ -48,7 +48,6 @@ static void mdp4_lvds_connector_destroy(struct drm_connector *connector)
struct mdp4_lvds_connector *mdp4_lvds_connector = struct mdp4_lvds_connector *mdp4_lvds_connector =
to_mdp4_lvds_connector(connector); to_mdp4_lvds_connector(connector);
drm_connector_unregister(connector);
drm_connector_cleanup(connector); drm_connector_cleanup(connector);
kfree(mdp4_lvds_connector); kfree(mdp4_lvds_connector);
...@@ -121,13 +120,10 @@ struct drm_connector *mdp4_lvds_connector_init(struct drm_device *dev, ...@@ -121,13 +120,10 @@ struct drm_connector *mdp4_lvds_connector_init(struct drm_device *dev,
{ {
struct drm_connector *connector = NULL; struct drm_connector *connector = NULL;
struct mdp4_lvds_connector *mdp4_lvds_connector; struct mdp4_lvds_connector *mdp4_lvds_connector;
int ret;
mdp4_lvds_connector = kzalloc(sizeof(*mdp4_lvds_connector), GFP_KERNEL); mdp4_lvds_connector = kzalloc(sizeof(*mdp4_lvds_connector), GFP_KERNEL);
if (!mdp4_lvds_connector) { if (!mdp4_lvds_connector)
ret = -ENOMEM; return ERR_PTR(-ENOMEM);
goto fail;
}
mdp4_lvds_connector->encoder = encoder; mdp4_lvds_connector->encoder = encoder;
mdp4_lvds_connector->panel_node = panel_node; mdp4_lvds_connector->panel_node = panel_node;
...@@ -143,15 +139,7 @@ struct drm_connector *mdp4_lvds_connector_init(struct drm_device *dev, ...@@ -143,15 +139,7 @@ struct drm_connector *mdp4_lvds_connector_init(struct drm_device *dev,
connector->interlace_allowed = 0; connector->interlace_allowed = 0;
connector->doublescan_allowed = 0; connector->doublescan_allowed = 0;
drm_connector_register(connector);
drm_mode_connector_attach_encoder(connector, encoder); drm_mode_connector_attach_encoder(connector, encoder);
return connector; return connector;
fail:
if (connector)
mdp4_lvds_connector_destroy(connector);
return ERR_PTR(ret);
} }
...@@ -199,6 +199,8 @@ static int msm_unload(struct drm_device *dev) ...@@ -199,6 +199,8 @@ static int msm_unload(struct drm_device *dev)
drm_kms_helper_poll_fini(dev); drm_kms_helper_poll_fini(dev);
drm_connector_unregister_all(dev);
#ifdef CONFIG_DRM_FBDEV_EMULATION #ifdef CONFIG_DRM_FBDEV_EMULATION
if (fbdev && priv->fbdev) if (fbdev && priv->fbdev)
msm_fbdev_free(dev); msm_fbdev_free(dev);
...@@ -414,6 +416,12 @@ static int msm_load(struct drm_device *dev, unsigned long flags) ...@@ -414,6 +416,12 @@ static int msm_load(struct drm_device *dev, unsigned long flags)
goto fail; goto fail;
} }
ret = drm_connector_register_all(dev);
if (ret) {
dev_err(dev->dev, "failed to register connectors\n");
goto fail;
}
drm_mode_config_reset(dev); drm_mode_config_reset(dev);
#ifdef CONFIG_DRM_FBDEV_EMULATION #ifdef CONFIG_DRM_FBDEV_EMULATION
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment