Skip to contentSkip to conversation

drm/bridge: connector: Support the colorspace property for HDMI

RFC PATCH In review Jan Claußen 2 participants 3 messages Oct 11 – Oct 13

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 drm/bridge: connector: Support the colorspace property for HDMI

Bridge connectors for HDMI do not expose the colorspace property, so userspace cannot signal the colorimetry (e.g. BT.2020 for HDR). KWin requires the property before it offers the HDR toggle.

Attach the property for HDMI bridge connectors, next to the other HDMI properties set up by drmm_connector_hdmi_init().

Force a modeset when the property changes so the new colorimetry reaches the sink, as vc4 does in its connector atomic_check.

After toggling HDR on, modetest shows that the correct BT.2020 color space is loaded. After toggling it off, it loads the default color space again.

Tested in KDE Plasma 6.7.5 on a Radxa Rock 5B (RK3588) with an LG OLED55B87LC.

---
 .../gpu/drm/display/drm_bridge_connector.c    | 25 ++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +22 -3
index 81f3e26f6fdf..885094cc6ddf 100644
@@ -414,11 +414,24 @@ static int drm_bridge_connector_atomic_check(struct drm_connector *connector,
 {
 	struct drm_bridge_connector *bridge_connector =
 		to_drm_bridge_connector(connector);
+	struct drm_connector_state *old_state =
+		drm_atomic_get_old_connector_state(state, connector);
+	struct drm_connector_state *new_state =
+		drm_atomic_get_new_connector_state(state, connector);
+	struct drm_crtc_state *crtc_state;
 
-	if (bridge_connector->bridge_hdmi)
-		return drm_atomic_helper_connector_hdmi_check(connector, state);
+	if (!bridge_connector->bridge_hdmi)
+		return 0;
 
-	return 0;
+	if (new_state->crtc && old_state->colorspace != new_state->colorspace) {
+		crtc_state = drm_atomic_get_crtc_state(state, new_state->crtc);
+		if (IS_ERR(crtc_state))
+			return PTR_ERR(crtc_state);
+
+		crtc_state->mode_changed = true;
+	}
+
+	return drm_atomic_helper_connector_hdmi_check(connector, state);
 }
 
 static const struct drm_connector_helper_funcs drm_bridge_connector_helper_funcs = {
@@ -1079,6 +1092,12 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 					       connector_type, ddc);
 		if (ret)
 			return ERR_PTR(ret);
+
+		ret = drm_mode_create_hdmi_colorspace_property(connector, 0);
+		if (ret)
+			return ERR_PTR(ret);
+
+		drm_connector_attach_colorspace_property(connector);
 	} else {
 		ret = drmm_connector_init(drm, connector,
 					  &drm_bridge_connector_funcs,
Signature · 8 lines
Changes in v2:
* Only look up the CRTC state when the connector has a CRTC
* Only apply the check to HDMI bridge connectors
* Move declarations to the top of the function

v1: https://lore.kernel.org/all/[email protected]

2.56.0
maintainer
#1 lore raw
Quoted 56 lines · Jan Claußen

Bridge connectors for HDMI do not expose the colorspace property, so userspace cannot signal the colorimetry (e.g. BT.2020 for HDR). KWin requires the property before it offers the HDR toggle.

Attach the property for HDMI bridge connectors, next to the other HDMI properties set up by drmm_connector_hdmi_init().

Force a modeset when the property changes so the new colorimetry reaches the sink, as vc4 does in its connector atomic_check.

After toggling HDR on, modetest shows that the correct BT.2020 color space is loaded. After toggling it off, it loads the default color space again.

Tested in KDE Plasma 6.7.5 on a Radxa Rock 5B (RK3588) with an LG OLED55B87LC.

---
 .../gpu/drm/display/drm_bridge_connector.c    | 25 ++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +16 -3
index 81f3e26f6fdf..885094cc6ddf 100644
@@ -414,11 +414,24 @@ static int drm_bridge_connector_atomic_check(struct drm_connector *connector,
 {
 	struct drm_bridge_connector *bridge_connector =
 		to_drm_bridge_connector(connector);
+	struct drm_connector_state *old_state =
+		drm_atomic_get_old_connector_state(state, connector);
+	struct drm_connector_state *new_state =
+		drm_atomic_get_new_connector_state(state, connector);
+	struct drm_crtc_state *crtc_state;
 
-	if (bridge_connector->bridge_hdmi)
-		return drm_atomic_helper_connector_hdmi_check(connector, state);
+	if (!bridge_connector->bridge_hdmi)
+		return 0;
 
-	return 0;
+	if (new_state->crtc && old_state->colorspace != new_state->colorspace) {
+		crtc_state = drm_atomic_get_crtc_state(state, new_state->crtc);
+		if (IS_ERR(crtc_state))
+			return PTR_ERR(crtc_state);
+
+		crtc_state->mode_changed = true;
+	}
+
+	return drm_atomic_helper_connector_hdmi_check(connector, state);
 }
 
 static const struct drm_connector_helper_funcs drm_bridge_connector_helper_funcs = {

drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 1096

Quoted 5 lines
drivers/gpu/drm/display/drm_bridge_connector.c +2 -0
@@ -1079,6 +1092,12 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 					       connector_type, ddc);
 		if (ret)
 			return ERR_PTR(ret);
+
+		ret = drm_mode_create_hdmi_colorspace_property(connector, 0);

This should come from drivers, you can't expect every driver to support every HDMI colorspace.

drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 1100

Quoted 4 lines
drivers/gpu/drm/display/drm_bridge_connector.c +4 -0
+		if (ret)
+			return ERR_PTR(ret);
+
+		drm_connector_attach_colorspace_property(connector);

Most importantly, all that work should be in the HDMI helpers, it's an HDMI feature just like, say, max bpc

Maxime

#2 lore raw

Hi Maxime,

this is where I put it before. The colorspace check could definitely land in the HDMI helper. Attaching the colorspace property should only happen once though. Should I move this back in the dw_hdmi_qp-rockchip.c? Jan

Quoted 75 lines · Maxime Ripard
Quoted 56 lines · Jan Claußen

Bridge connectors for HDMI do not expose the colorspace property, so userspace cannot signal the colorimetry (e.g. BT.2020 for HDR). KWin requires the property before it offers the HDR toggle.

Attach the property for HDMI bridge connectors, next to the other HDMI properties set up by drmm_connector_hdmi_init().

Force a modeset when the property changes so the new colorimetry reaches the sink, as vc4 does in its connector atomic_check.

After toggling HDR on, modetest shows that the correct BT.2020 color space is loaded. After toggling it off, it loads the default color space again.

Tested in KDE Plasma 6.7.5 on a Radxa Rock 5B (RK3588) with an LG OLED55B87LC.

---
.../gpu/drm/display/drm_bridge_connector.c | 25 ++++++++++++++++---

1 file changed, 22 insertions(+), 3 deletions(-)
drivers/gpu/drm/display/drm_bridge_connector.c +0 -0
index 81f3e26f6fdf..885094cc6ddf 100644
@@ -414,11 +414,24 @@ static int drm_bridge_connector_atomic_check(struct drm_connector *connector,
 {

struct drm_bridge_connector *bridge_connector = to_drm_bridge_connector(connector);
+ struct drm_connector_state *old_state =
+ drm_atomic_get_old_connector_state(state, connector);
+ struct drm_connector_state *new_state =
+ drm_atomic_get_new_connector_state(state, connector);
+ struct drm_crtc_state *crtc_state;

- if (bridge_connector->bridge_hdmi)
- return drm_atomic_helper_connector_hdmi_check(connector, state);
+ if (!bridge_connector->bridge_hdmi)
+ return 0;

- return 0;
+ if (new_state->crtc && old_state->colorspace != new_state->colorspace) {
+ crtc_state = drm_atomic_get_crtc_state(state, new_state->crtc);
+ if (IS_ERR(crtc_state))
+ return PTR_ERR(crtc_state);

drivers/gpu/drm/display/drm_bridge_connector.c +5 -0
+
+ crtc_state->mode_changed = true;
+ }
+
+ return drm_atomic_helper_connector_hdmi_check(connector, state);

}

static const struct drm_connector_helper_funcs drm_bridge_connector_helper_funcs = {

drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 1096

Quoted 5 lines
drivers/gpu/drm/display/drm_bridge_connector.c +2 -0
@@ -1079,6 +1092,12 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm,
 connector_type, ddc);
 if (ret)
 return ERR_PTR(ret);
+
+ ret = drm_mode_create_hdmi_colorspace_property(connector, 0);

This should come from drivers, you can't expect every driver to support every HDMI colorspace.

drivers/gpu/drm/display/drm_bridge_connector.c struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, · line 1100

Quoted 4 lines
drivers/gpu/drm/display/drm_bridge_connector.c +4 -0
+ if (ret)
+ return ERR_PTR(ret);
+
+ drm_connector_attach_colorspace_property(connector);

Most importantly, all that work should be in the HDMI helpers, it's an HDMI feature just like, say, max bpc

Maxime