[RFC 08/11] drm/bridge: synopsys: dw-hdmi: add 420 mode format negociation

From: Neil Armstrong
Date: Tue Aug 20 2019 - 04:41:40 EST


Add special negociation case for 420 HDMI2.0 format.

In this case the DW-HDMI CSC cannot handle 420 data, and must be
in passthrought, thus input_bus_cfg must be output_bus_cfg.

Add support for handling a specific 8/10/12/16 variant in the connector
bus_formats if specified.

Signed-off-by: Neil Armstrong <narmstrong@xxxxxxxxxxxx>
---
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 45 ++++++++++++++++++-----
1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index cb560b231d74..b96119c6fad2 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -2213,23 +2213,50 @@ static int dw_hdmi_bridge_atomic_check(struct drm_bridge *bridge,
struct drm_connector_state *conn_state)
{
struct dw_hdmi *hdmi = bridge->driver_private;
+ struct drm_connector *conn = conn_state->connector;
+ struct drm_display_info *info = &conn->display_info;
+ struct drm_display_mode *mode = &crtc_state->mode;
+ bool is_hdmi2_sink = info->hdmi.scdc.supported;
int ret;

- ret = drm_atomic_bridge_choose_output_bus_cfg(bridge_state, crtc_state,
- conn_state);
- if (ret)
- return ret;
+ /*
+ * If the current mode enforces 4:2:0, force the output but format
+ * or use the connector bus formats if a non 8bit 4:2:0 format
+ * is provided.
+ */
+ if (drm_mode_is_420_only(info, mode) ||
+ (!is_hdmi2_sink && drm_mode_is_420_also(info, mode))) {
+ if (info->num_bus_formats && info->bus_formats &&
+ hdmi_bus_fmt_is_yuv420(info->bus_formats[0]))
+ bridge_state->output_bus_cfg.fmt = info->bus_formats[0];
+ else
+ bridge_state->output_bus_cfg.fmt =
+ MEDIA_BUS_FMT_UYYVYY8_0_5X24;
+ } else {
+ ret = drm_atomic_bridge_choose_output_bus_cfg(bridge_state,
+ crtc_state,
+ conn_state);
+ if (ret)
+ return ret;
+ }
+
+ if (hdmi_bus_fmt_is_yuv420(bridge_state->output_bus_cfg.fmt)) {
+ /* The DW-HDMI CSC cannot interpolate and decimate in 4:2:0 */
+ bridge_state->input_bus_cfg.fmt =
+ bridge_state->output_bus_cfg.fmt;
+ } else {
+ ret = drm_atomic_bridge_choose_input_bus_cfg(bridge_state,
+ crtc_state,
+ conn_state);
+ if (ret)
+ return ret;
+ }

dev_dbg(hdmi->dev, "selected output format %x\n",
bridge_state->output_bus_cfg.fmt);

hdmi->hdmi_data.enc_out_bus_format = bridge_state->output_bus_cfg.fmt;

- ret = drm_atomic_bridge_choose_input_bus_cfg(bridge_state, crtc_state,
- conn_state);
- if (ret)
- return ret;
-
dev_dbg(hdmi->dev, "selected input format %x\n",
bridge_state->input_bus_cfg.fmt);

--
2.22.0