From: Maxime Ripard <mripard@kernel.org>
To: Luca Ceresoli <luca.ceresoli@bootlin.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>,
Simona Vetter <simona@ffwll.ch>,
Andrzej Hajda <andrzej.hajda@intel.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Inki Dae <inki.dae@samsung.com>,
Jagan Teki <jagan@amarulasolutions.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Jessica Zhang <jesszhan0024@gmail.com>,
Douglas Anderson <dianders@chromium.org>,
Marek Vasut <marex@denx.de>, Stefan Agner <stefan@agner.ch>,
Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Javier Martinez Canillas <javierm@redhat.com>,
Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>,
Hui Pu <Hui.Pu@gehealthcare.com>,
Ian Ray <ian.ray@gehealthcare.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug
Date: Tue, 1 Dec 2026 17:06:00 +0100 [thread overview]
Message-ID: <aw7m_cP9NsaKr2Vq@houat> (raw)
In-Reply-To: <20261125-drm-bridge-hotplug-v4-31-822722850492@bootlin.com>
[-- Attachment #1: Type: text/plain, Size: 11170 bytes --]
On Wed, Nov 25, 2026 at 06:50:44PM +0100, Luca Ceresoli wrote:
> Add a new helper to support cards implementing hotpluggable drm_bridges.
>
> drmm_hotplug_helper_init() registers to get notified of relevant events and
> react by creating a bridge (if the pipeline is complete in the hardware)
> and destroying it on bridge removal.
>
> Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
>
> ---
>
> Changes in v3:
> - Do not require the first bridge is non-hotpluggable
> - Support non-DSI bridges too
> - Add callback to report connector add/remove
> - Do not store the drm_device pointer, get it from the encoder
> - use new v3 notifier API name
>
> Changes in v2:
> - Add callback to report connector addition/removal
> - Sanity-check drmm_hotplug_helper_init() parameters
> - Reformat kdoc comment
> ---
> MAINTAINERS | 8 +
> drivers/gpu/drm/display/Kconfig | 7 +
> drivers/gpu/drm/display/Makefile | 2 +
> drivers/gpu/drm/display/drm_hotplug_helper.c | 325 +++++++++++++++++++++++++++
> include/drm/drm_hotplug_helper.h | 30 +++
> 5 files changed, 372 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a5e2bf15e59f..18ecb7bb39f4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8219,6 +8219,14 @@ F: Documentation/devicetree/bindings/npu/rockchip,rk3588-rknn-core.yaml
> F: drivers/accel/rocket/
> F: include/uapi/drm/rocket_accel.h
>
> +DRM BRIDGE HOTPLUG HELPER
> +M: Luca Ceresoli <luca.ceresoli@bootlin.com>
> +S: Maintained
> +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
> +F: Documentation/devicetree/bindings/display/bridge/
> +F: drivers/gpu/drm/display/drm_hotplug_helper.c
> +F: include/drm/drm_hotplug_helper.h
> +
I don't think we want to add a new maintainer entry for each new file we
create under drivers/gpu/drm.
> DRM COMPUTE ACCELERATORS DRIVERS AND FRAMEWORK
> M: Oded Gabbay <ogabbay@kernel.org>
> L: dri-devel@lists.freedesktop.org
> diff --git a/drivers/gpu/drm/display/Kconfig b/drivers/gpu/drm/display/Kconfig
> index df09cf9a8ca1..e086e2fd08a4 100644
> --- a/drivers/gpu/drm/display/Kconfig
> +++ b/drivers/gpu/drm/display/Kconfig
> @@ -22,6 +22,13 @@ config DRM_BRIDGE_CONNECTOR
> help
> DRM connector implementation terminating DRM bridge chains.
>
> +config DRM_HOTPLUG_HELPER
> + bool
> + depends on OF
> + select DRM_BRIDGE_CONNECTOR
> + help
> + Helper code to implement a card supporting hotpluggable bridges.
> +
> config DRM_DISPLAY_DP_AUX_CEC
> bool "Enable DisplayPort CEC-Tunneling-over-AUX HDMI support"
> select DRM_DISPLAY_DP_HELPER
> diff --git a/drivers/gpu/drm/display/Makefile b/drivers/gpu/drm/display/Makefile
> index 0ff4a1ad0222..ce6dbd65833b 100644
> --- a/drivers/gpu/drm/display/Makefile
> +++ b/drivers/gpu/drm/display/Makefile
> @@ -5,6 +5,8 @@ obj-$(CONFIG_DRM_DISPLAY_DP_AUX_BUS) += drm_dp_aux_bus.o
> drm_display_helper-y := drm_display_helper_mod.o
> drm_display_helper-$(CONFIG_DRM_BRIDGE_CONNECTOR) += \
> drm_bridge_connector.o
> +drm_display_helper-$(CONFIG_DRM_HOTPLUG_HELPER) += \
> + drm_hotplug_helper.o
> drm_display_helper-$(CONFIG_DRM_DISPLAY_DP_HELPER) += \
> drm_dp_dual_mode_helper.o \
> drm_dp_helper.o \
> diff --git a/drivers/gpu/drm/display/drm_hotplug_helper.c b/drivers/gpu/drm/display/drm_hotplug_helper.c
> new file mode 100644
> index 000000000000..ea32bdb0af8f
> --- /dev/null
> +++ b/drivers/gpu/drm/display/drm_hotplug_helper.c
> @@ -0,0 +1,325 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2026 GE HealthCare
> + * Author: Luca Ceresoli <luca.ceresoli@bootlin.com>
> + */
> +
> +#include <linux/of.h>
> +#include <linux/of_graph.h>
> +
> +#include <drm/drm_bridge.h>
> +#include <drm/drm_bridge_connector.h>
> +#include <drm/drm_hotplug_event_notifier.h>
> +#include <drm/drm_hotplug_helper.h>
> +#include <drm/drm_managed.h>
> +#include <drm/drm_print.h>
> +
> +struct drm_hotplug_helper {
> + /**
> + * @encoder: The encoder at the start of the bridges chain
> + */
> + struct drm_encoder *encoder;
> + /**
> + * @event_cb: Callback to report connector addition/removal
> + */
> + drm_hotplug_helper_event_cb event_cb;
> + /**
> + * @drm_event_nb: Notifier to receive DRM hotplug-related events
> + */
> + struct notifier_block drm_event_nb;
> + /**
> + * @connector: The drm_connector added/removed on plug/unplug
> + */
> + struct drm_connector *connector;
> + /**
> + * @event_mutex: Protect entry points (init, fini, event notifier)
> + * from concurrent attach and connector creation or destruction
> + */
> + struct mutex event_mutex;
> + /**
> + * @first_bridge_ep: Device tree node of the encoder endpoint
> + * connected to the first bridge
> + */
> + struct device_node *first_bridge_ep;
> +};
> +
> +/*
> + * True if the encoder bridge chain is complete, i.e. the last bridge in
> + * the chain is the last bridge expected in the hardware (e.g. a panel).
> + */
> +static bool drm_hotplug_helper_bridge_chain_is_complete(struct drm_hotplug_helper *hotplug_helper)
> +{
> + struct drm_bridge *last_bridge __free(drm_bridge_put) =
> + drm_bridge_chain_get_last_bridge(hotplug_helper->encoder);
> + struct drm_device *drm = hotplug_helper->encoder->dev;
> +
> + /* We expect at least one bridge */
> + if (!last_bridge) {
> + drm_dbg_driver(drm, "no bridges in pipeline (yet)\n");
> + return false;
> + }
> +
> + struct drm_bridge *next_bridge __free(drm_bridge_put) =
> + drm_bridge_get_next(last_bridge);
> +
> + /* No next bridge expected, pipeline is complete */
> + if (!next_bridge) {
> + drm_dbg_driver(drm, "pipeline complete\n");
> + return true;
> + }
> +
> + /* Next bridge expected but not there now, pipeline incomplete */
> + if (next_bridge == ERR_PTR(-ENODEV)) {
> + drm_dbg_driver(drm, "pipeline not (yet) complete\n");
> + return false;
> + }
I'd drop these yet. We don't know if it ever will be here, so I think
it's more confusing than anything.
> + /* Unexpected error */
> + if (IS_ERR(next_bridge))
> + drm_warn(drm, "%s error %pe\n", __func__, next_bridge);
> +
> + /* next_bridge is valid, but not (yet|anymore) in chain */
> + return false;
> +}
> +
> +/**
> + * drm_hotplug_helper_connector_add - add the drm_connector
> + * @hotplug_helper: drm_hotplug_helper to add the drm_connector to
> + *
> + * Returns 0 on success or a negative error otherwise.
> + */
> +static int drm_hotplug_helper_connector_add(struct drm_hotplug_helper *hotplug_helper)
> +{
> + struct drm_device *drm = hotplug_helper->encoder->dev;
> + struct drm_connector *connector;
> +
> + if (drm_WARN_ON(drm, hotplug_helper->connector))
> + return -EBUSY;
> +
> + connector = drm_bridge_connector_dynamic_add(drm, hotplug_helper->encoder);
> + if (IS_ERR(connector))
> + return PTR_ERR(connector);
> +
> + hotplug_helper->connector = connector;
> + hotplug_helper->event_cb(DRM_HOTPLUG_HELPER_CONNECTOR_ADDED, connector);
> +
> + dev_dbg(drm->dev, "added bridge connector\n");
> +
> + return 0;
> +}
> +
> +/*
> + * Removes the connector, which must be present.
> + *
> + * Must be called with the hotplug_helper->event_mutex locked.
> + */
> +static void drm_hotplug_helper_connector_remove(struct drm_hotplug_helper *hotplug_helper)
> +{
> + struct drm_device *drm = hotplug_helper->encoder->dev;
> +
> + if (drm_WARN_ON(drm, !hotplug_helper->connector))
> + return;
> +
> + dev_dbg(drm->dev, "removing bridge connector\n");
> +
> + hotplug_helper->event_cb(DRM_HOTPLUG_HELPER_CONNECTOR_REMOVING, hotplug_helper->connector);
> + drm_bridge_connector_dynamic_remove(hotplug_helper->connector);
> + hotplug_helper->connector = NULL;
> +}
> +
> +/*
> + * Propagate the attach chain and possibly add a drm_bridge_connector after
> + * a new drm_bridge is hot-plugged.
> + *
> + * The connector is added only if the pipeline is now complete. This could
> + * not be the case for various reasons:
> + *
> + * - the new bridge is just unrelated to our encoder
> + * - the new bridge is not the next one in the pipeline
> + * - the new bridge is the next in the pipeline but the pipeline is not yet
> + * complete
> + *
> + * All these cases are normal, not an error.
> + *
> + * Must be called with the hotplug_helper->event_mutex locked.
> + */
> +static void drm_hotplug_helper_try_complete(struct drm_hotplug_helper *hotplug_helper)
> +{
> + struct device *dev = hotplug_helper->encoder->dev->dev;
> + int err;
> +
> + WARN_ON(!mutex_is_locked(&hotplug_helper->event_mutex));
> +
> + /*
> + * drm_connector already present, the new bridge must be for
> + * another card
> + */
> + if (hotplug_helper->connector)
> + return;
> +
> + struct drm_bridge *last_bridge __free(drm_bridge_put) =
> + drm_bridge_chain_get_last_bridge(hotplug_helper->encoder);
> +
> + if (last_bridge) {
> + /*
> + * Some bridge(s) already in the chain, propagate the
> + * attach call chain from the current chain tail to newly
> + * hotplugged bridge(s)
> + */
> + dev_dbg(dev, "propagate attach after %ps\n", last_bridge->funcs);
> +
> + err = last_bridge->funcs->attach(last_bridge, hotplug_helper->encoder,
> + DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> + if (err)
> + return;
> + } else {
> + /* Bridge chain still empty, find first bridge and attach */
> +
> + const struct device_node *first_bridge_node __free(device_node) =
> + of_graph_get_remote_port_parent(hotplug_helper->first_bridge_ep);
> + if (!of_device_is_available(first_bridge_node))
> + return;
> +
> + struct drm_bridge *first_bridge __free(drm_bridge_put) =
> + of_drm_find_and_get_bridge(first_bridge_node);
> + if (!first_bridge)
> + return;
> +
> + dev_dbg(dev, "attach chain starting at %ps\n", first_bridge->funcs);
> +
> + err = drm_bridge_attach(hotplug_helper->encoder, first_bridge, NULL,
> + DRM_BRIDGE_ATTACH_NO_CONNECTOR);
> + if (err)
> + return;
> + }
> +
> + /* Add the connector if the encoder chain is now complete */
> + if (drm_hotplug_helper_bridge_chain_is_complete(hotplug_helper))
> + drm_hotplug_helper_connector_add(hotplug_helper);
> +}
> +
> +static int drm_hotplug_helper_handle_event(struct notifier_block *nb,
> + unsigned long event, void *data)
> +{
> + struct drm_hotplug_helper *hotplug_helper =
> + container_of(nb, struct drm_hotplug_helper, drm_event_nb);
> + struct device *dev = hotplug_helper->encoder->dev->dev;
> +
> + guard(mutex)(&hotplug_helper->event_mutex);
> +
> + dev_dbg(dev, "received event %lu\n", event);
> +
> + switch (event) {
> + case DRM_BRIDGE_ADDED:
> + case DRM_MIPI_DSI_ATTACHED:
> + /*
> + * A bridges hot-plugged, try adding the
> + * drm_bridge_connector
> + */
> + drm_hotplug_helper_try_complete(hotplug_helper);
> + break;
I'm still not quite sure why we need to special-case MIPI-DSI here. If
the bridge is added, then who cares about the bus it's using?
Maxime
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 273 bytes --]
next prev parent reply other threads:[~2026-12-01 16:06 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 17:50 [PATCH v4 00/32] drm bridge hotplug Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 01/32] drm/display: hdmi-cec-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-12-01 10:20 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 02/32] drm/display: hdmi-cec-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:08 ` sashiko-bot
2026-12-01 10:21 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 03/32] drm/display: hdmi-cec-notifier-helper: use drmm_ prefix for drmm action Luca Ceresoli
2026-12-01 10:21 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 04/32] drm/display: hdmi-cec-notifier-helper: add non-drmm API variant Luca Ceresoli
2026-11-25 18:07 ` sashiko-bot
2026-12-01 10:22 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 05/32] drm/connector: split drmm_connector_hdmi_init() in 3 parts Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 06/32] drm/connector: add drm_connector_hdmi_dynamic_init() Luca Ceresoli
2026-11-25 18:10 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 07/32] drm/display: bridge-connector: split allocation code from initialization code Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 08/32] drm/display: bridge-connector: hoist error management to common code Luca Ceresoli
2026-11-25 18:03 ` sashiko-bot
2026-12-01 10:30 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 09/32] drm/display: bridge-connector: use a dynamic connector Luca Ceresoli
2026-11-25 18:21 ` sashiko-bot
2026-11-26 1:15 ` kernel test robot
2026-11-25 17:50 ` [PATCH v4 10/32] drm/display: bridge-connector: add APIs to add/remove the connector dynamically Luca Ceresoli
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 11/32] drm/bridge: constify of_drm_find_and_get_bridge() device_node parameter Luca Ceresoli
2026-11-25 17:59 ` sashiko-bot
2026-12-01 10:30 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 12/32] drm/bridge: initialize chain_node list head on allocation Luca Ceresoli
2026-12-01 10:31 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 13/32] drm/bridge: initialize chain_node list head on detach and attach errors Luca Ceresoli
2026-12-01 10:31 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 14/32] drm/bridge: ti-sn65dsi86: protect device resources on unplug Luca Ceresoli
2026-11-25 18:16 ` sashiko-bot
2026-12-01 10:23 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 15/32] drm/atomic: drm_atomic_private_obj_fini: protect private_obj removal from list Luca Ceresoli
2026-11-25 18:12 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable Luca Ceresoli
2026-11-25 18:10 ` sashiko-bot
2026-12-01 10:32 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 17/32] drm: event-notifier: add mechanism to notify about hotplug events Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 18/32] drm/bridge: notify about added and detached bridges Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 19/32] drm/mipi-dsi: notify about DSI attach Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 20/32] drm/bridge: add drm_bridge_get_next() and supporting func Luca Ceresoli
2026-12-01 10:40 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 21/32] drm/panel: implement .get_next_bridge Luca Ceresoli
2026-12-01 10:36 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 22/32] drm/bridge: display-connector: " Luca Ceresoli
2026-12-01 10:41 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 23/32] drm/bridge: ti-sn65dsi83: " Luca Ceresoli
2026-11-25 18:14 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 24/32] drm/bridge: ti-sn65dsi86: " Luca Ceresoli
2026-11-25 18:18 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 25/32] drm/bridge: samsung-dsim: " Luca Ceresoli
2026-11-25 18:15 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 26/32] drm/bridge: add drm_bridge_detach_from() Luca Ceresoli
2026-11-25 18:15 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 27/32] drm/atomic: add drm_atomic_shutdown_encoder() Luca Ceresoli
2026-12-01 15:19 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 28/32] drm/tests: atomic: add tests for drm_atomic_shutdown_encoder() Luca Ceresoli
2026-11-25 17:50 ` [PATCH v4 29/32] drm/bridge: clear bridge->encoder on detach Luca Ceresoli
2026-12-01 15:24 ` Maxime Ripard
2026-11-25 17:50 ` [PATCH v4 30/32] drm/bridge: shutdown encoder and detach downstream bridges on bridge unplug Luca Ceresoli
2026-11-25 18:28 ` sashiko-bot
2026-11-25 17:50 ` [PATCH v4 31/32] drm: drm_hotplug_helper: new helper to implement bridge hotplug Luca Ceresoli
2026-11-25 18:30 ` sashiko-bot
2026-12-01 16:06 ` Maxime Ripard [this message]
2026-11-25 17:50 ` [PATCH v4 32/32] drm/mxsfb/lcdif: enable " Luca Ceresoli
2026-11-25 18:31 ` sashiko-bot
2026-11-26 3:23 ` kernel test robot
2026-11-26 5:12 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aw7m_cP9NsaKr2Vq@houat \
--to=mripard@kernel.org \
--cc=Frank.Li@nxp.com \
--cc=Hui.Pu@gehealthcare.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=dianders@chromium.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=festevam@gmail.com \
--cc=ian.ray@gehealthcare.com \
--cc=imx@lists.linux.dev \
--cc=inki.dae@samsung.com \
--cc=jagan@amarulasolutions.com \
--cc=javierm@redhat.com \
--cc=jernej.skrabec@gmail.com \
--cc=jesszhan0024@gmail.com \
--cc=jonas@kwiboo.se \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=m.szyprowski@samsung.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=marex@denx.de \
--cc=neil.armstrong@linaro.org \
--cc=rfoss@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=simona@ffwll.ch \
--cc=stefan@agner.ch \
--cc=thomas.petazzoni@bootlin.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.