Re: [PATCH v12 04/25] drm/bridge: Act on the DRM color format property

Dmitry Baryshkov
2026-04-09T22:08:30Z

On Thu, Apr 09, 2026 at 05:44:54PM +0200, Nicolas Frattaroli wrote:
> The new DRM color format property allows userspace to request a specific
> color format on a connector. In turn, this fills the connector state's
> color_format member to switch color formats.
>
> Make drm_bridges consider the color_format set in the connector state
> during the atomic bridge check. For bridges that represent HDMI bridges,
> rely on whatever format the HDMI logic set. Reject any output bus
> formats that do not correspond to the requested color format.
>
> Non-HDMI last bridges with DRM_CONNECTOR_COLOR_FORMAT_AUTO set will end
> up choosing the first output format that functions to make a whole
> recursive bridge chain format selection succeed.
>
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
> ---
> drivers/gpu/drm/drm_bridge.c | 89 +++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 88 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> index ba80bebb5685..7c1516864d96 100644
> --- a/drivers/gpu/drm/drm_bridge.c
> +++ b/drivers/gpu/drm/drm_bridge.c
> @@ -1150,6 +1150,47 @@ static int select_bus_fmt_recursive(struct drm_bridge *first_bridge,
> return ret;
> }
>
> +static bool __pure bus_format_is_color_fmt(u32 bus_fmt, enum drm_connector_color_format fmt)
> +{
> + if (fmt == DRM_CONNECTOR_COLOR_FORMAT_AUTO)
> + return true;
> +
> + switch (bus_fmt) {
> + case MEDIA_BUS_FMT_FIXED:
> + return true;
> + case MEDIA_BUS_FMT_RGB888_1X24:
> + case MEDIA_BUS_FMT_RGB101010_1X30:
> + case MEDIA_BUS_FMT_RGB121212_1X36:
> + case MEDIA_BUS_FMT_RGB161616_1X48:
> + return fmt == DRM_CONNECTOR_COLOR_FORMAT_RGB444;
> + case MEDIA_BUS_FMT_YUV8_1X24:
> + case MEDIA_BUS_FMT_YUV10_1X30:
> + case MEDIA_BUS_FMT_YUV12_1X36:
> + case MEDIA_BUS_FMT_YUV16_1X48:
> + return fmt == DRM_CONNECTOR_COLOR_FORMAT_YCBCR444;
> + case MEDIA_BUS_FMT_UYVY8_1X16:
> + case MEDIA_BUS_FMT_VYUY8_1X16:
> + case MEDIA_BUS_FMT_YUYV8_1X16:
> + case MEDIA_BUS_FMT_YVYU8_1X16:
> + case MEDIA_BUS_FMT_UYVY10_1X20:
> + case MEDIA_BUS_FMT_YUYV10_1X20:
> + case MEDIA_BUS_FMT_VYUY10_1X20:
> + case MEDIA_BUS_FMT_YVYU10_1X20:
> + case MEDIA_BUS_FMT_UYVY12_1X24:
> + case MEDIA_BUS_FMT_VYUY12_1X24:
> + case MEDIA_BUS_FMT_YUYV12_1X24:
> + case MEDIA_BUS_FMT_YVYU12_1X24:
> + return fmt == DRM_CONNECTOR_COLOR_FORMAT_YCBCR422;
> + case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
> + case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
> + case MEDIA_BUS_FMT_UYYVYY12_0_5X36:
> + case MEDIA_BUS_FMT_UYYVYY16_0_5X48:
> + return fmt == DRM_CONNECTOR_COLOR_FORMAT_YCBCR420;
> + default:
> + return false;
> + }
> +}
> +
> /*
> * This function is called by &drm_atomic_bridge_chain_check() just before
> * calling &drm_bridge_funcs.atomic_check() on all elements of the chain.
> @@ -1193,6 +1234,7 @@ drm_atomic_bridge_chain_select_bus_fmts(struct drm_bridge *bridge,
> struct drm_encoder *encoder = bridge->encoder;
> struct drm_bridge_state *last_bridge_state;
> unsigned int i, num_out_bus_fmts = 0;
> + enum drm_connector_color_format fmt;
> u32 *out_bus_fmts;
> int ret = 0;
>
> @@ -1234,13 +1276,58 @@ drm_atomic_bridge_chain_select_bus_fmts(struct drm_bridge *bridge,
> out_bus_fmts[0] = MEDIA_BUS_FMT_FIXED;
> }
>
> + /*
> + * On HDMI connectors, use the output format chosen by whatever does the
> + * HDMI logic. For everyone else, just trust that the bridge out_bus_fmts
> + * are sorted by preference for %DRM_CONNECTOR_COLOR_FORMAT_AUTO, as
> + * bus_format_is_color_fmt() always returns true for AUTO.
> + */
> + if (last_bridge->type == DRM_MODE_CONNECTOR_HDMIA) {

I still think this is misplaced (and misidentified). Consider HDMI
bridge being routed to the DVI-D connector. The last bridge would have
different type, but the HDMI-specific logic must still be applied. The
bridge must use RGB444, but it must be handled in a generic way.

Or other way around, a DVI bridge being routed through the HDMI
connector (thinking about PandaBoard here). The combo should not go
through the HDMI-specific color format selection although the last
bridge in the chanin is the HDMI-A bridge.

I think all these cases should be handled by the connector, which knows
if there is an OP_HDMI bridge in the chain or not.

> + drm_dbg_kms(last_bridge->dev,
> + "HDMI bridge requests format %s\n",
> + drm_hdmi_connector_get_output_format_name(
> + conn_state->hdmi.output_format));
> + switch (conn_state->hdmi.output_format) {
> + case DRM_OUTPUT_COLOR_FORMAT_RGB444:
> + fmt = DRM_CONNECTOR_COLOR_FORMAT_RGB444;
> + break;
> + case DRM_OUTPUT_COLOR_FORMAT_YCBCR444:
> + fmt = DRM_CONNECTOR_COLOR_FORMAT_YCBCR444;
> + break;
> + case DRM_OUTPUT_COLOR_FORMAT_YCBCR422:
> + fmt = DRM_CONNECTOR_COLOR_FORMAT_YCBCR422;
> + break;
> + case DRM_OUTPUT_COLOR_FORMAT_YCBCR420:
> + fmt = DRM_CONNECTOR_COLOR_FORMAT_YCBCR420;
> + break;
> + default:
> + ret = -EINVAL;
> + goto out_free_bus_fmts;
> + }
> + } else {
> + fmt = conn_state->color_format;
> + drm_dbg_kms(last_bridge->dev, "Non-HDMI bridge requests format %d\n", fmt);
> + }
> +
> for (i = 0; i < num_out_bus_fmts; i++) {
> + if (!bus_format_is_color_fmt(out_bus_fmts[i], fmt)) {
> + drm_dbg_kms(last_bridge->dev,
> + "Skipping bus format 0x%04x as it doesn't match format %d\n",
> + out_bus_fmts[i], fmt);
> + ret = -ENOTSUPP;
> + continue;
> + }
> ret = select_bus_fmt_recursive(bridge, last_bridge, crtc_state,
> conn_state, out_bus_fmts[i]);
> - if (ret != -ENOTSUPP)
> + if (ret != -ENOTSUPP) {
> + drm_dbg_kms(last_bridge->dev,
> + "Found bridge chain ending with bus format 0x%04x\n",
> + out_bus_fmts[i]);
> break;
> + }
> }
>
> +out_free_bus_fmts:
> kfree(out_bus_fmts);
>
> return ret;
>
> --
> 2.53.0
>

--
With best wishes
Dmitry