[PATCH v11 07/12] drm/panel: add connector luminance forwarding
From: Mario Limonciello (AMD)
Date: Tue Nov 03 2026 - 17:46:06 EST
From: Mario Limonciello <mario.limonciello@xxxxxxx>
Add helpers that expose a panel backlight through the connector
LUMINANCE property and forward connector updates to the backlight
backend.
Hook the helpers into panel bridges that create their own connector.
Panels consumed directly, or by a panel bridge attached with
DRM_BRIDGE_ATTACH_NO_CONNECTOR, remain unchanged. Turning the backlight
on and off is left to drm_panel_enable() and drm_panel_disable(), which
already honour self refresh.
The panel backlight remains the hardware backend and keeps its
/sys/class/backlight device, which is owned by the backlight driver.
Signed-off-by: Mario Limonciello <mario.limonciello@xxxxxxx>
---
v11:
* Don't remove drm_panel.h stubs (rebase artifact, Sashiko)
* Use drm_connector_to_panel() rather than an invalid panel_bridge
container_of() (Sashiko)
* Clean up the connector if attaching the property fails (Sashiko)
* Drop .disable_luminance and program the committed level before
drm_panel_enable() (Sashiko)
* Don't attach the property when the panel bridge is attached after the
device is registered, which would WARN
* Update brightness under the backlight ops_lock
v10:
* Split panel support out of the combined panel and bridge patch
* Limit integration to panel bridges that own their connector
---
drivers/gpu/drm/drm_panel.c | 93 +++++++++++++++++++++++++++++++++++++++++++++
include/drm/drm_panel.h | 4 ++
2 files changed, 97 insertions(+)
diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index 74c96da45b7a5..bbd0e14401c18 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -64,9 +64,18 @@ static int panel_bridge_connector_get_modes(struct drm_connector *connector)
return drm_panel_get_modes(panel, connector);
}
+static void
+panel_bridge_connector_set_luminance(const struct drm_connector_state *conn_state)
+{
+ struct drm_panel *panel = drm_connector_to_panel(conn_state->connector);
+
+ drm_panel_set_luminance(panel, conn_state->luminance);
+}
+
static const struct drm_connector_helper_funcs
panel_bridge_connector_helper_funcs = {
.get_modes = panel_bridge_connector_get_modes,
+ .set_luminance = panel_bridge_connector_set_luminance,
};
static const struct drm_connector_funcs panel_bridge_connector_funcs = {
@@ -101,6 +110,12 @@ static int panel_bridge_attach(struct drm_bridge *bridge,
drm_panel_bridge_set_orientation(connector, bridge);
+ ret = drm_panel_attach_luminance_property(panel, connector);
+ if (ret) {
+ drm_connector_cleanup(connector);
+ return ret;
+ }
+
drm_connector_attach_encoder(connector, encoder);
if (bridge->dev->registered) {
@@ -169,6 +184,19 @@ static void panel_bridge_atomic_enable(struct drm_bridge *bridge,
if (old_crtc_state && old_crtc_state->self_refresh_active)
return;
+ /*
+ * Program the committed luminance before drm_panel_enable() turns the
+ * backlight on, so the panel does not light up at a stale level.
+ */
+ if (panel->connector.luminance_property) {
+ const struct drm_connector_state *conn_state =
+ drm_atomic_get_new_connector_state(atomic_state,
+ &panel->connector);
+
+ if (conn_state)
+ drm_panel_set_luminance(panel, conn_state->luminance);
+ }
+
drm_panel_enable(panel);
}
@@ -873,6 +901,71 @@ void drm_panel_disable(struct drm_panel *panel)
}
EXPORT_SYMBOL(drm_panel_disable);
+/**
+ * drm_panel_attach_luminance_property - expose a panel backlight through DRM
+ * @panel: panel whose backlight is controlled
+ * @connector: connector on which to expose the property
+ *
+ * The backlight class device remains the internal hardware backend. When the
+ * luminance UAPI is enabled, userspace controls that backend through the DRM
+ * connector property instead.
+ *
+ * Return: 0 on success or a negative error code
+ */
+int drm_panel_attach_luminance_property(struct drm_panel *panel,
+ struct drm_connector *connector)
+{
+ struct backlight_device *backlight;
+
+ if (!IS_ENABLED(CONFIG_DRM_LUMINANCE) || !panel)
+ return 0;
+
+ backlight = panel->backlight;
+ if (!backlight)
+ return 0;
+
+ /* Properties can't be created once the device is visible to userspace */
+ if (connector->dev->registered) {
+ drm_dbg_kms(connector->dev,
+ "[CONNECTOR:%d:%s] registered, not exposing luminance\n",
+ connector->base.id, connector->name);
+ return 0;
+ }
+
+ return drm_connector_attach_luminance_property(connector, 0,
+ backlight->props.max_brightness,
+ backlight->props.brightness);
+}
+EXPORT_SYMBOL(drm_panel_attach_luminance_property);
+
+/**
+ * drm_panel_set_luminance - set a panel backlight's relative luminance
+ * @panel: panel whose backlight is controlled
+ * @luminance: relative luminance level
+ *
+ * Updates the backlight brightness without changing its power state, under
+ * the same lock as brightness changes made through sysfs. Turning
+ * the backlight on and off is left to drm_panel_enable() and
+ * drm_panel_disable(), so a level set while the panel is disabled is applied
+ * when the panel is enabled again.
+ */
+void drm_panel_set_luminance(struct drm_panel *panel, unsigned int luminance)
+{
+ struct backlight_device *backlight;
+
+ if (!panel || !panel->backlight)
+ return;
+
+ backlight = panel->backlight;
+ guard(mutex)(&backlight->ops_lock);
+ if (!backlight->ops || luminance > backlight->props.max_brightness)
+ return;
+
+ backlight->props.brightness = luminance;
+ backlight_update_status(backlight);
+}
+EXPORT_SYMBOL(drm_panel_set_luminance);
+
/**
* drm_panel_get_modes - probe the available display modes of a panel
* @panel: DRM panel
diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
index 58113ea7d63a0..233d30dd2e182 100644
--- a/include/drm/drm_panel.h
+++ b/include/drm/drm_panel.h
@@ -342,6 +342,10 @@ void drm_panel_unprepare(struct drm_panel *panel);
void drm_panel_enable(struct drm_panel *panel);
void drm_panel_disable(struct drm_panel *panel);
+int drm_panel_attach_luminance_property(struct drm_panel *panel,
+ struct drm_connector *connector);
+void drm_panel_set_luminance(struct drm_panel *panel, unsigned int luminance);
+
int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector);
#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL)
--
2.53.0