[PATCH v4 16/32] drm/probe-helper: add per-connector polling enable/disable

From: Luca Ceresoli

Date: Wed Nov 25 2026 - 12:53:27 EST


With the upcoming DRM bridge hotplug support, drm_connectors will be added
and removed at any time after initial card probing.

This means the existing calls to drm_kms_helper_poll_init() at probe time
will not enable HPD on connectors added later on (and potentially not start
the polling work), so late connectors cannot perform HPD polling.

Similarly, drm_kms_helper_poll_fini() cannot disable HPD for hot-unplugged
connectors without disabling it for other connectors.

Add drm_kms_helper_poll_enable_connector() and
drm_kms_helper_poll_disable_connector() to enable or disable HPD for a
single connector, and also arm the work when an enabled connector requests
polling and stop on disable it unless other connectors still need it.

Polling must still be initialized once per device with
drm_kms_helper_poll_init() and finally torn down with
drm_kms_helper_poll_fini().

Signed-off-by: Luca Ceresoli <luca.ceresoli@xxxxxxxxxxx>

---

New patch in v4
---
drivers/gpu/drm/drm_probe_helper.c | 92 ++++++++++++++++++++++++++++++++++++++
include/drm/drm_probe_helper.h | 2 +
2 files changed, 94 insertions(+)

diff --git a/drivers/gpu/drm/drm_probe_helper.c b/drivers/gpu/drm/drm_probe_helper.c
index 856b40fdaac4..e468971ab642 100644
--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -224,6 +224,14 @@ drm_connector_mode_valid(struct drm_connector *connector,
return ret;
}

+static void drm_kms_helper_disable_hpd_connector(struct drm_connector *connector)
+{
+ const struct drm_connector_helper_funcs *funcs = connector->helper_private;
+
+ if (funcs && funcs->disable_hpd)
+ funcs->disable_hpd(connector);
+}
+
static void drm_kms_helper_disable_hpd(struct drm_device *dev)
{
struct drm_connector *connector;
@@ -240,6 +248,16 @@ static void drm_kms_helper_disable_hpd(struct drm_device *dev)
drm_connector_list_iter_end(&conn_iter);
}

+static bool drm_kms_helper_enable_hpd_connector(struct drm_connector *connector)
+{
+ const struct drm_connector_helper_funcs *funcs = connector->helper_private;
+
+ if (funcs && funcs->enable_hpd)
+ funcs->enable_hpd(connector);
+
+ return (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT));
+}
+
static bool drm_kms_helper_enable_hpd(struct drm_device *dev)
{
bool poll = false;
@@ -316,6 +334,32 @@ void drm_kms_helper_poll_enable(struct drm_device *dev)
}
EXPORT_SYMBOL(drm_kms_helper_poll_enable);

+/**
+ * drm_kms_helper_poll_enable_connector - enable output polling for a connector
+ * @connector: the connector
+ *
+ * Enables output polling @connector and reschdules the polling work if
+ * needed. Intended for connectors which are added after initial probing.
+ *
+ * This must be called after polling has been initialized by
+ * drm_kms_helper_poll_init(). Safe to call while polling is already
+ * running.
+ */
+void drm_kms_helper_poll_enable_connector(struct drm_connector *connector)
+{
+ struct drm_device *dev = connector->dev;
+
+ if (drm_WARN_ON_ONCE(dev, !dev->mode_config.poll_enabled) || !drm_kms_helper_poll)
+ return;
+
+ if (drm_kms_helper_enable_hpd_connector(connector) ||
+ dev->mode_config.delayed_event)
+ reschedule_output_poll_work(dev);
+
+ dev->mode_config.poll_running = true;
+}
+EXPORT_SYMBOL(drm_kms_helper_poll_enable_connector);
+
/**
* drm_kms_helper_poll_reschedule - reschedule the output polling work
* @dev: drm_device
@@ -927,6 +971,54 @@ void drm_kms_helper_poll_disable(struct drm_device *dev)
}
EXPORT_SYMBOL(drm_kms_helper_poll_disable);

+static bool drm_kms_helper_has_other_connectors(struct drm_connector *connector)
+{
+ struct drm_device *dev = connector->dev;
+ struct drm_connector *curr;
+ struct drm_connector_list_iter conn_iter;
+ bool remaining = false;
+
+ drm_connector_list_iter_begin(dev, &conn_iter);
+ drm_for_each_connector_iter(curr, &conn_iter) {
+ if (curr != connector &&
+ curr->registration_state == DRM_CONNECTOR_REGISTERED) {
+ remaining = true;
+ break;
+ }
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ return remaining;
+}
+
+/**
+ * drm_kms_helper_poll_disable_connector - disable output polling for a connector
+ * @connector: the connector
+ *
+ * Disables output polling for @connector. If there are no other registered
+ * connectors, also disables the output poll work.
+ *
+ * Polling stays initialized; call drm_kms_helper_poll_fini() to tear it
+ * down. Does nothing if output polling is not initialized by
+ * drm_kms_helper_poll_init().
+ */
+void drm_kms_helper_poll_disable_connector(struct drm_connector *connector)
+{
+ struct drm_device *dev = connector->dev;
+
+ if (!dev->mode_config.poll_enabled)
+ return;
+
+ drm_kms_helper_disable_hpd_connector(connector);
+
+ if (dev->mode_config.poll_running &&
+ !drm_kms_helper_has_other_connectors(connector)) {
+ cancel_delayed_work_sync(&dev->mode_config.output_poll_work);
+ dev->mode_config.poll_running = false;
+ }
+}
+EXPORT_SYMBOL(drm_kms_helper_poll_disable_connector);
+
/**
* drm_kms_helper_poll_init - initialize and enable output polling
* @dev: drm_device
diff --git a/include/drm/drm_probe_helper.h b/include/drm/drm_probe_helper.h
index 840ae5f798c2..ae58c1b078fe 100644
--- a/include/drm/drm_probe_helper.h
+++ b/include/drm/drm_probe_helper.h
@@ -26,7 +26,9 @@ void drm_kms_helper_hotplug_event(struct drm_device *dev);
void drm_kms_helper_connector_hotplug_event(struct drm_connector *connector);

void drm_kms_helper_poll_disable(struct drm_device *dev);
+void drm_kms_helper_poll_disable_connector(struct drm_connector *connector);
void drm_kms_helper_poll_enable(struct drm_device *dev);
+void drm_kms_helper_poll_enable_connector(struct drm_connector *connector);
void drm_kms_helper_poll_reschedule(struct drm_device *dev);
bool drm_kms_helper_is_poll_worker(void);


--
2.56.1