The tidss encoder is backed by a bridge that sits first in the bridge chain, between the CRTC and the next bridge. Its state holds the bus configuration that the atomic helpers negotiate when checking a commit.
However, drm_atomic_bridge_chain_select_bus_fmts() and drm_atomic_bridge_propagate_bus_flags() don't run during a state readout, so each bridge has to reconstruct its own bus configuration. Implement the atomic_sro_readout_state hook for the tidss bridge, taking the CRTC state as its source since the CRTCs are read out before the bridges. The output bus format and the bus flags are taken from the CRTC state, which tidss_bridge_atomic_check() sets from the format the next bridge negotiated. The input bus format is MEDIA_BUS_FMT_FIXED since the bridge doesn't implement atomic_get_input_bus_fmts. Use drm_atomic_helper_bridge_compare_state() to compare the readout state with the committed one. Signed-off-by: Maxime Ripard <[email protected]> --- drivers/gpu/drm/tidss/tidss_encoder.c | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/gpu/drm/tidss/tidss_encoder.c b/drivers/gpu/drm/tidss/tidss_encoder.c index 10dbcc6cdf6a..5034e601ac86 100644 --- a/drivers/gpu/drm/tidss/tidss_encoder.c +++ b/drivers/gpu/drm/tidss/tidss_encoder.c @@ -3,12 +3,14 @@ * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/ * Author: Tomi Valkeinen <[email protected]> */ #include <linux/export.h> +#include <linux/media-bus-format.h> #include <drm/drm_atomic_helper.h> +#include <drm/drm_atomic_state_readout_helper.h> #include <drm/drm_bridge.h> #include <drm/drm_bridge_connector.h> #include <drm/drm_encoder.h> #include <drm/drm_crtc.h> #include <drm/drm_modeset_helper_vtables.h> @@ -71,16 +73,56 @@ static int tidss_bridge_atomic_check(struct drm_bridge *bridge, } return 0; } +static int tidss_readout_state(struct drm_bridge *bridge, + struct drm_atomic_sro_state *state, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct tidss_crtc_state *tcrtc_state = to_tidss_crtc_state(crtc_state); + + /* + * Reconstruct the bridge bus configuration from the CRTC readout state. + * + * During normal atomic check, + * drm_atomic_bridge_chain_select_bus_fmts() and + * drm_atomic_bridge_propagate_bus_flags() walk the bridge chain to + * negotiate formats and propagate flags. During SRO readout, those + * functions do not run, so each bridge must reconstruct its own + * state. + * + * This bridge is the first in the chain, so the CRTC state (read out + * before bridges) is used as the source. The output bus format is + * taken from the CRTC's bus_format, which during normal atomic check + * is set by tidss_bridge_atomic_check() to the next bridge's + * negotiated input format. The input bus format is + * MEDIA_BUS_FMT_FIXED since this bridge does not implement + * atomic_get_input_bus_fmts. Bus flags are taken from the CRTC + * state, which reads them from hardware registers during its own + * readout. + */ + + bridge_state->input_bus_cfg.format = MEDIA_BUS_FMT_FIXED; + bridge_state->output_bus_cfg.format = tcrtc_state->bus_format; + + bridge_state->output_bus_cfg.flags = tcrtc_state->bus_flags; + bridge_state->input_bus_cfg.flags = tcrtc_state->bus_flags; + + return 0; +} + static const struct drm_bridge_funcs tidss_bridge_funcs = { .attach = tidss_bridge_attach, .atomic_check = tidss_bridge_atomic_check, .atomic_create_state = drm_atomic_helper_bridge_create_state, .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, + .atomic_sro_readout_state = tidss_readout_state, + .atomic_sro_compare_state = drm_atomic_helper_bridge_compare_state, }; static const struct drm_encoder_funcs tidss_encoder_funcs = { .destroy = drm_encoder_cleanup, }; -- 2.56.1
