On Wednesday, 19 November 2025 05:32:46 Central European Standard Time Laurent
Pinchart wrote:
> On Mon, Nov 17, 2025 at 08:11:48PM +0100, 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. Specifically, reject any output bus
> > formats that do not correspond to the requested color format.
> >
> > Signed-off-by: Nicolas Frattaroli <[email protected]>
> > ---
> > drivers/gpu/drm/drm_bridge.c | 57
> > ++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 57 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c
> > index 8f355df883d8..b7df5cbad832 100644
> > --- a/drivers/gpu/drm/drm_bridge.c
> > +++ b/drivers/gpu/drm/drm_bridge.c
> > @@ -1052,6 +1052,59 @@ 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_color_format fmt)
> > +{
> > + if (bus_fmt == MEDIA_BUS_FMT_FIXED)
> > + return true;
> > +
> > + switch (fmt) {
> > + case DRM_COLOR_FORMAT_NONE:
> > + case DRM_COLOR_FORMAT_AUTO:
> > + return true;
> > + case DRM_COLOR_FORMAT_RGB444:
> > + switch (bus_fmt) {
> > + 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 true;
> > + default:
> > + return false;
> > + }
> > + case DRM_COLOR_FORMAT_YCBCR444:
> > + switch (bus_fmt) {
> > + 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 true;
> > + default:
> > + return false;
> > + }
> > + case DRM_COLOR_FORMAT_YCBCR422:
> > + switch (bus_fmt) {
> > + case MEDIA_BUS_FMT_UYVY8_1X16:
> > + case MEDIA_BUS_FMT_UYVY10_1X20:
> > + case MEDIA_BUS_FMT_UYVY12_1X24:
> > + return true;
> > + default:
> > + return false;
> > + }
> > + case DRM_COLOR_FORMAT_YCBCR420:
> > + switch (bus_fmt) {
> > + 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 true;
> > + default:
> > + return false;
> > + }
> > + }
>
> I'd find this more readable:
>
> if (fmt == DRM_COLOR_FORMAT_NONE || fmt == DRM_COLOR_FORMAT_AUTO)
> return true;
>
> switch (bus_fmt) {
> 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_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_COLOR_FORMAT_YCBCR444;
>
> case MEDIA_BUS_FMT_UYVY8_1X16:
> case MEDIA_BUS_FMT_UYVY10_1X20:
> case MEDIA_BUS_FMT_UYVY12_1X24:
> return fmt == DRM_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_COLOR_FORMAT_YCBCR420;
>
> default:
> return false;
> }
>
> but it could be a matter for personal preference ?
I agree, that is nicer.
>
> I'm also a bit concerned about the
>
> if (fmt == DRM_COLOR_FORMAT_NONE || fmt == DRM_COLOR_FORMAT_AUTO)
>
> test. What's the difference between NONE and AUTO ? Is it meaningful, or
> should the two enumerators be merged into a single one ?
I've noticed that as well but didn't act on it before sending out v4.
I think we should try to make them the same yes. I don't see a valid
reason why anything would ever set "NONE" when it means "AUTO". If
there is a non-AUTO "NONE" case to describe an invalid format, then
this code is wrong anyways. I'll do some digging.
> > +
> > + 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.
> > @@ -1137,6 +1190,10 @@ drm_atomic_bridge_chain_select_bus_fmts(struct
> > drm_bridge *bridge,
> > }
> >
> > for (i = 0; i < num_out_bus_fmts; i++) {
> > + if (!bus_format_is_color_fmt(out_bus_fmts[i],
> > conn_state->color_format)) {
> > + ret = -ENOTSUPP;
> > + continue;
> > + }
> > ret = select_bus_fmt_recursive(bridge, last_bridge, crtc_state,
> > conn_state, out_bus_fmts[i]);
> > if (ret != -ENOTSUPP)
>
>