From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B085606A325 for ; Fri, 20 Nov 2026 12:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ux+5WFDX Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ADCBE112A07; Fri, 20 Nov 2026 12:58:16 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id A70FE10E8D1 for ; Fri, 20 Nov 2026 12:57:36 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8FE8B4323D; Fri, 20 Nov 2026 12:57:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8A921F000CF; Fri, 20 Nov 2026 12:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795179456; bh=oZGwhwG/z5xzT9/mrEWIvuCB7lLLzD9FsVzJ3CXGlBU=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=Ux+5WFDX7zBG050O1M86G7DW724XO8d+/w2N7cz4NM5u924zT3sxivYIpeTrn+lxp nSz3NNeNb2bw0T+XJwUFBxiTfaYcVqfraRyLY5+5eSH8u86i1iqLBjftVqQf4fISlY 9iSwQFXR08/MZsG7nFBFhH0NE3LA4f3XxmMGBYfNIM94hRHoUgB6Hsa1IvohWEiIAU MH+AaNaG5FfeSmH+FTFJpuURGa2be6Sw0RBXn8ACH80VqGTj5h5BJOpnuIQ8Vr8b4p sfP569DRDqUEKOYmVJuLmhpCrnBpW7jAXCJw+VBCGGUrffhRS7C0rnAC0d2RevmNj2 AI8z3akcLFKWw== From: Maxime Ripard Date: Fri, 20 Nov 2026 13:55:31 +0100 Subject: [PATCH v9 39/42] drm/panel: Implement state readout support X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261120-drm-state-readout-v9-39-a67c2b45b8ec@kernel.org> References: <20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org> In-Reply-To: <20261120-drm-state-readout-v9-0-a67c2b45b8ec@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Jyri Sarha , Tomi Valkeinen Cc: Devarsh Thakkar , dri-devel@lists.freedesktop.org, Maxime Ripard X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8118; i=mripard@kernel.org; h=from:subject:message-id; bh=mz0C74VfgdbwL60P2y1GRLInFgX7TCYhGCAJVa0QPhU=; b=owGbwMvMwCmsHn9OcpHtvjLG02pJDNkMzsYTZn0/tkn3r82GjaEpf8qZayzKK3hZTsoePGbDc ff90ZNCHVNZGIQ5GWTFFFmeyISdXt6+uMrBfuUPmDmsTCBDGLg4BWAiGoGMDe/nhHue22S2ou/Y 5CmFx26JVE/iCWoOSFhRN3eCRoTVWXOhLVt/bLKTXXAzyDNjds2s54w1HDY73HitXRnK9dK/Xug 1aNAMzTW3eT5H08MhbduKA8nlunEPaxhlTkWcOvfk2L7NaW0A X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 A panel bridge has no state of its own to read out of the hardware: neither the panel enable state nor the bus configuration is observable through it. The bus configuration the atomic helpers negotiate can however be reconstructed: the panel bridge is always the last bridge of a chain, so the negotiation picks the first connector display info format as its output format, or MEDIA_BUS_FMT_FIXED when the display info has none, passes it through to its input end, and propagates the display info flags to both ends. The atomic_sro_readout_state hook reports that configuration. The display info is only populated once the connector modes have been read, after the initial state has been created: the fixed format reported then matches what the negotiation would produce, and is harmless as the initial state is never compared. The atomic_sro_connector_readout hook reports the connector as bound to the current CRTC of its encoder whenever that CRTC was read out as active, the panel being assumed enabled whenever its pipeline is. A panel bridge only carries DRM_BRIDGE_OP_CONNECTOR_HW_READOUT when no bridge attached earlier in its chain provides a connector readout: drm_bridge_connector_init() picks the last bridge carrying that op, and earlier bridges may know the actual link state. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_panel.c | 129 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index 560ea57591bd..9c60942de90b 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -7,14 +7,17 @@ #include #include #include #include +#include #include #include #include +#include +#include #include #include #include #include #include @@ -81,12 +84,35 @@ static int panel_bridge_attach(struct drm_bridge *bridge, struct drm_encoder *encoder, enum drm_bridge_attach_flags flags) { struct drm_panel *panel = drm_bridge_to_panel(bridge); struct drm_connector *connector = &panel->connector; + bool upstream_readout = false; int ret; + /* + * drm_bridge_connector_init() picks the connector readout + * provider from the last bridge of the chain carrying + * DRM_BRIDGE_OP_CONNECTOR_HW_READOUT. Only provide the + * fallback readout of a panel bridge when no bridge earlier + * in the chain provides one, as those know the actual link + * state while a panel bridge can only assume the panel is + * enabled. + */ + drm_for_each_bridge_in_chain(encoder, iter) { + if (iter == bridge) + break; + + if (iter->ops & DRM_BRIDGE_OP_CONNECTOR_HW_READOUT) { + upstream_readout = true; + break; + } + } + + if (!upstream_readout) + bridge->ops |= DRM_BRIDGE_OP_CONNECTOR_HW_READOUT; + if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) return 0; drm_connector_helper_add(connector, &panel_bridge_connector_helper_funcs); @@ -224,10 +250,110 @@ static void panel_bridge_debugfs_init(struct drm_bridge *bridge, root = debugfs_create_dir("panel", root); if (panel->funcs->debugfs_init) panel->funcs->debugfs_init(panel, root); } +/* + * A panel bridge has no state of its own to read out of the hardware: + * reconstruct the bus configuration the atomic helpers negotiate + * instead. + * + * The panel bridge is always the last bridge of a chain, and the + * negotiation picks the first connector display info format as its + * output format (or MEDIA_BUS_FMT_FIXED when the display info has + * none), which drm_atomic_helper_bridge_propagate_bus_fmt() passes + * through to its input. drm_atomic_bridge_propagate_bus_flags() + * similarly propagates the display info flags to both its output and + * input. This is also what happens when the display info has no + * formats yet, like during the initial state creation at probe time + * before any mode has been read: the bus configuration then reports + * a fixed format, which is harmless as the initial state is never + * compared, and every commit negotiates the bus configuration anew. + * + * The format the negotiation selects can only differ from the first + * display info format when the connector reports several formats and + * the rest of the bridge chain rejects it, which panel connectors + * don't do. + */ +static int +panel_bridge_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 drm_connector *connector = conn_state->connector; + struct drm_display_info *info = &connector->display_info; + u32 format; + + if (info->num_bus_formats) + format = info->bus_formats[0]; + else + format = MEDIA_BUS_FMT_FIXED; + + bridge_state->input_bus_cfg.format = format; + bridge_state->output_bus_cfg.format = format; + + bridge_state->input_bus_cfg.flags = info->bus_flags; + bridge_state->output_bus_cfg.flags = info->bus_flags; + + return 0; +} + +/* + * A panel bridge has no way to read the panel state out of the + * hardware: assume the panel is enabled whenever its pipeline is. + */ +static int +panel_bridge_connector_readout(struct drm_bridge *bridge, + struct drm_atomic_sro_state *state, + struct drm_connector_state *conn_state) +{ + struct drm_connector *connector = conn_state->connector; + struct drm_crtc_state *crtc_state; + struct drm_encoder *encoder; + struct drm_crtc *crtc; + + encoder = bridge->encoder; + if (!encoder->funcs || !encoder->funcs->atomic_sro_get_current_crtc) + return -ENODEV; + + /* The encoder is disabled, there is nothing to read out. */ + crtc = encoder->funcs->atomic_sro_get_current_crtc(encoder); + if (!crtc) + return 0; + + /* + * A readout limited to the objects of a commit doesn't have a + * state for a CRTC that isn't part of it, and a CRTC can't be + * left out of a commit enabling it. + */ + crtc_state = drm_atomic_sro_get_crtc_state(state, crtc); + if (!crtc_state) + return 0; + + /* The pipeline is off, there is nothing to read out. */ + if (!crtc_state->active) + return 0; + + crtc_state->encoder_mask |= drm_encoder_mask(encoder); + crtc_state->connector_mask |= drm_connector_mask(connector); + + /* + * drm_atomic_set_crtc_for_connector() takes a connector + * reference when setting the crtc pointer, which is later + * released by __drm_atomic_helper_connector_destroy_state(). + * The readout bypasses that path, so take the reference + * explicitly. + */ + drm_connector_get(connector); + conn_state->crtc = crtc; + conn_state->best_encoder = encoder; + + return 0; +} + static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { .attach = panel_bridge_attach, .detach = panel_bridge_detach, .atomic_pre_enable = panel_bridge_atomic_pre_enable, .atomic_enable = panel_bridge_atomic_enable, @@ -237,10 +363,13 @@ static const struct drm_bridge_funcs panel_bridge_bridge_funcs = { .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_get_input_bus_fmts = drm_atomic_helper_bridge_propagate_bus_fmt, .debugfs_init = panel_bridge_debugfs_init, + .atomic_sro_readout_state = panel_bridge_readout_state, + .atomic_sro_compare_state = drm_atomic_helper_bridge_compare_state, + .atomic_sro_connector_readout = panel_bridge_connector_readout, }; /** * drm_bridge_is_panel - Checks if a drm_bridge is a panel_bridge. * -- 2.56.1