Switch to the new drm_hotplug_helper() to handle bridge hotplugging: * use the new drm_hotplug_helper to handle hotplug, including finding the first bridge and attaching the bridge chain * use the connector add/remove callback to enable/disable HPD on added/removed connectors * move drm_kms_helper_poll_init() before creating the drm_hotplug_helper so that HPD polling is initialized before connectors can be hotplugged
Signed-off-by: Luca Ceresoli <[email protected]> --- Changes in v4: - fix UAF when hot-plugged connectors implement HPD by using the new per-connector HPD enable/disable API Changes in v3: - Adapt to the v3 version of the drm_hotplug_helper, which also handles HPD Changes in v2: - Use the hotplug helper callback to enable HPD on the hotplugged connector --- drivers/gpu/drm/mxsfb/Kconfig | 2 +- drivers/gpu/drm/mxsfb/lcdif_drv.c | 42 +++++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/mxsfb/Kconfig b/drivers/gpu/drm/mxsfb/Kconfig index 31db7a824a93..ada9a9334ea4 100644 --- a/drivers/gpu/drm/mxsfb/Kconfig +++ b/drivers/gpu/drm/mxsfb/Kconfig @@ -34,7 +34,7 @@ config DRM_IMX_LCDIF select DRM_PANEL select DRM_PANEL_BRIDGE select DRM_DISPLAY_HELPER - select DRM_BRIDGE_CONNECTOR + select DRM_HOTPLUG_HELPER help Choose this option if you have an LCDIFv3 LCD controller. Those devices are found in various i.MX SoC (i.MX8MP, diff --git a/drivers/gpu/drm/mxsfb/lcdif_drv.c b/drivers/gpu/drm/mxsfb/lcdif_drv.c index 2be5a76e936f..591653b39310 100644 --- a/drivers/gpu/drm/mxsfb/lcdif_drv.c +++ b/drivers/gpu/drm/mxsfb/lcdif_drv.c @@ -18,7 +18,7 @@ #include <drm/clients/drm_client_setup.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_bridge.h> -#include <drm/drm_bridge_connector.h> +#include <drm/drm_hotplug_helper.h> #include <drm/drm_drv.h> #include <drm/drm_encoder.h> #include <drm/drm_fbdev_dma.h> @@ -44,6 +44,19 @@ static const struct drm_mode_config_helper_funcs lcdif_mode_config_helpers = { .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, }; +static void lcdif_hotplug_event(enum drm_hotplug_helper_event event, + struct drm_connector *connector) +{ + switch (event) { + case DRM_HOTPLUG_HELPER_CONNECTOR_ADDED: + drm_kms_helper_poll_enable_connector(connector); + break; + case DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING: + drm_kms_helper_poll_disable_connector(connector); + break; + } +} + static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif) { struct device *dev = lcdif->drm->dev; @@ -53,9 +66,8 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif) struct device_node *remote __free(device_node) = of_graph_get_remote_port_parent(ep); struct of_endpoint of_ep; - struct drm_bridge *bridge; struct drm_encoder *encoder; - struct drm_connector *connector; + struct drm_hotplug_helper *hotplug_helper; int ret; if (!of_device_is_available(remote)) @@ -65,12 +77,6 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif) if (ret < 0) return dev_err_probe(dev, ret, "Failed to parse endpoint %pOF\n", ep); - bridge = devm_drm_of_get_bridge(dev, dev->of_node, 0, of_ep.id); - if (IS_ERR(bridge)) - return dev_err_probe(dev, PTR_ERR(bridge), - "Failed to get bridge for endpoint%u\n", - of_ep.id); - encoder = drmm_plain_encoder_alloc(lcdif->drm, NULL, DRM_MODE_ENCODER_NONE, NULL); if (IS_ERR(encoder)) @@ -80,16 +86,10 @@ static int lcdif_attach_bridge(struct lcdif_drm_private *lcdif) encoder->possible_crtcs = drm_crtc_mask(&lcdif->crtc); - ret = drm_bridge_attach(encoder, bridge, NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR); - if (ret) - return dev_err_probe(dev, ret, - "Failed to attach bridge for endpoint%u\n", - of_ep.id); - - connector = drm_bridge_connector_init(lcdif->drm, encoder); - if (IS_ERR(connector)) - return dev_err_probe(dev, PTR_ERR(connector), - "Failed to init bridge_connector for endpoint%u\n", + hotplug_helper = drmm_hotplug_helper_init(encoder, lcdif_hotplug_event, ep); + if (IS_ERR(hotplug_helper)) + return dev_err_probe(dev, PTR_ERR(hotplug_helper), + "Failed to init hotplug_helper for endpoint%u\n", of_ep.id); } @@ -176,6 +176,8 @@ static int lcdif_load(struct drm_device *drm) /* Start with vertical blanking interrupt reporting disabled. */ drm_crtc_vblank_off(&lcdif->crtc); + drm_kms_helper_poll_init(drm); + ret = lcdif_attach_bridge(lcdif); if (ret) return ret; @@ -203,8 +205,6 @@ static int lcdif_load(struct drm_device *drm) return ret; } - drm_kms_helper_poll_init(drm); - drm_helper_hpd_irq_event(drm); pm_runtime_enable(drm->dev); -- 2.56.1
