[RFC,05/13] drm/connector: hdmi: Add output BPC to the connector state

Message ID 20230814-kms-hdmi-connector-state-v1-5-048054df3654@kernel.org
State New
Headers
Series drm/connector: Create HDMI Connector infrastructure |

Commit Message

Maxime Ripard Aug. 14, 2023, 1:56 p.m. UTC
  We'll add automatic selection of the output BPC in a following patch,
but let's add it to the HDMI connector state already.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/drm_hdmi_connector.c | 21 +++++++++++++++++++--
 include/drm/drm_connector.h          | 13 ++++++++++++-
 2 files changed, 31 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/gpu/drm/drm_hdmi_connector.c b/drivers/gpu/drm/drm_hdmi_connector.c
index 1fe3f3ebf719..6d5535e613c6 100644
--- a/drivers/gpu/drm/drm_hdmi_connector.c
+++ b/drivers/gpu/drm/drm_hdmi_connector.c
@@ -26,6 +26,9 @@  void __drm_atomic_helper_hdmi_connector_reset(struct drm_hdmi_connector *hdmi_co
 
 	__drm_atomic_helper_connector_reset(connector, &new_hdmi_state->base);
 
+	new_hdmi_state->base.max_bpc = 8;
+	new_hdmi_state->base.max_requested_bpc = 8;
+	new_hdmi_state->output_bpc = 8;
 	new_hdmi_state->broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO;
 }
 EXPORT_SYMBOL(__drm_atomic_helper_hdmi_connector_reset);
@@ -78,6 +81,7 @@  __drm_atomic_helper_hdmi_connector_duplicate_state(struct drm_hdmi_connector *hd
 	struct drm_hdmi_connector_state *old_hdmi_state =
 		connector_state_to_hdmi_connector_state(old_state);
 
+	new_hdmi_state->output_bpc = old_hdmi_state->output_bpc;
 	new_hdmi_state->broadcast_rgb = old_hdmi_state->broadcast_rgb;
 	__drm_atomic_helper_connector_duplicate_state(connector, &new_hdmi_state->base);
 }
@@ -254,7 +258,8 @@  int drm_atomic_helper_hdmi_connector_atomic_check(struct drm_connector *connecto
 	struct drm_hdmi_connector_state *new_hdmi_state =
 		connector_state_to_hdmi_connector_state(new_state);
 
-	if (old_hdmi_state->broadcast_rgb != new_hdmi_state->broadcast_rgb) {
+	if (old_hdmi_state->broadcast_rgb != new_hdmi_state->broadcast_rgb ||
+	    old_hdmi_state->output_bpc != new_hdmi_state->output_bpc) {
 		struct drm_crtc *crtc = new_state->crtc;
 		struct drm_crtc_state *crtc_state;
 
@@ -339,6 +344,7 @@  void drm_atomic_helper_hdmi_connector_print_state(struct drm_printer *p,
 
 	drm_printf(p, "\tbroadcast_rgb=%s\n",
 		   drm_hdmi_connector_get_broadcast_rgb_name(hdmi_state->broadcast_rgb));
+	drm_printf(p, "\toutput_bpc=%u\n", hdmi_state->output_bpc);
 }
 EXPORT_SYMBOL(drm_atomic_helper_hdmi_connector_print_state);
 
@@ -348,6 +354,7 @@  EXPORT_SYMBOL(drm_atomic_helper_hdmi_connector_print_state);
  * @hdmi_connector: A pointer to the HDMI connector to init
  * @connector_type: user visible type of the connector
  * @ddc: optional pointer to the associated ddc adapter
+ * @max_bpc: Maximum bits per char the HDMI connector supports
  *
  * Initialises a preallocated HDMI connector. Connectors can be
  * subclassed as part of driver connector objects.
@@ -364,7 +371,8 @@  int drmm_hdmi_connector_init(struct drm_device *dev,
 			     struct drm_hdmi_connector *hdmi_connector,
 			     const struct drm_connector_funcs *funcs,
 			     int connector_type,
-			     struct i2c_adapter *ddc)
+			     struct i2c_adapter *ddc,
+			     unsigned int max_bpc)
 {
 	struct drm_connector *connector = &hdmi_connector->base;
 	struct drm_property *prop;
@@ -393,6 +401,15 @@  int drmm_hdmi_connector_init(struct drm_device *dev,
 	drm_object_attach_property(&connector->base, prop,
 				   DRM_HDMI_BROADCAST_RGB_AUTO);
 
+	if (max_bpc) {
+		if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12))
+			return -EINVAL;
+
+		drm_connector_attach_hdr_output_metadata_property(connector);
+		drm_connector_attach_max_bpc_property(connector, 8, max_bpc);
+		hdmi_connector->max_bpc = max_bpc;
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL(drmm_hdmi_connector_init);
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index dff95e6e2b48..353aa8e5a117 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -2075,6 +2075,11 @@  struct drm_hdmi_connector_state {
 	 */
 	struct drm_connector_state base;
 
+	/**
+	 * @output_bpc: Bits per character to output.
+	 */
+	unsigned int output_bpc;
+
 	/**
 	 * @broadcast_rgb: Connector property to pass the Broadcast RGB
 	 * selection value.
@@ -2121,6 +2126,11 @@  struct drm_hdmi_connector {
 	 */
 	struct drm_connector base;
 
+	/**
+	 * @max_bpc: Maximum bits per character the connector supports.
+	 */
+	unsigned int max_bpc;
+
 	/**
 	 * @broadcast_rgb_property: Connector property to set the
 	 * Broadcast RGB selection to output with.
@@ -2135,7 +2145,8 @@  int drmm_hdmi_connector_init(struct drm_device *dev,
 			     struct drm_hdmi_connector *hdmi_connector,
 			     const struct drm_connector_funcs *funcs,
 			     int connector_type,
-			     struct i2c_adapter *ddc);
+			     struct i2c_adapter *ddc,
+			     unsigned int max_bpc);
 
 /**
  * struct drm_tile_group - Tile group metadata