From nobody Sun Jun 28 02:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 809F3C433FE for ; Tue, 15 Feb 2022 23:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244905AbiBOXzI (ORCPT ); Tue, 15 Feb 2022 18:55:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244895AbiBOXzE (ORCPT ); Tue, 15 Feb 2022 18:55:04 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2CDAF65FD for ; Tue, 15 Feb 2022 15:54:53 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id f6so658641pfj.11 for ; Tue, 15 Feb 2022 15:54:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OTjPJEv3ppz+4wwYIsjeEfkrs5jHH+xc9iC4EpIvllM=; b=bX3WqJk+exjCq2P0E71uHI+d1H1gMFVhRanSZrq0RtyTM6ZnoNrpgaDZmfh8JQIb3P 9lp7dBU45gQfukf/Ecau1JNWXrD6fV/DwJL6kzQ6tqPKRPjQ0vg2uzA8LmE/DFcotBI8 Mb3q+EwmEEHoIF4mG07cGcDG8P8BPqZR0KveU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OTjPJEv3ppz+4wwYIsjeEfkrs5jHH+xc9iC4EpIvllM=; b=dTpC4pX//1k9jtJ/2hB6CaHkgNTpYt6K0hGszrsVPaEoJHg7mMcBDsgUM5YHPTYvnx u7x+ejXHz0Hc2iGEOqj3UVExn5IXT/WtgHDuvKjsu8HPCRCZSprSggbnOHVPKkqI3hk1 pNyX3zMTD9YsdJ7i6OIhYQ69OQqo743Vdrb8I8QRXU+0ozQAsgyLstpxk52cgB/Az3fl FnqDXgsKSExUC3I5Joql39kimbEmF2JJwXgBfTz7sRFGnH919QfAt3JQoyM94pxFrhnT ER5SbDEXQdBnHjfb7cw7hIruzAgCFPR3CImjHqSwOReE1g/f2RrzL6Po6CAZ4sPTB1/Z rb2w== X-Gm-Message-State: AOAM533oQNdLxVSNt1dc70/bUdghhctx3Bf/2pXdtyx3j5t0BbfFpxzI GVco0Js94+YHHxOWEPLyVBx0s/CN5Nf7aA== X-Google-Smtp-Source: ABdhPJyJigo6j1/TFkCRK+3+g9/LHae8UwKZbETfFM8qk5v8BSLotLEGqFJiM6DKZdJXWUXfP0QCWA== X-Received: by 2002:a62:5347:0:b0:4e0:2ea8:9f6c with SMTP id h68-20020a625347000000b004e02ea89f6cmr396742pfb.61.1644969293185; Tue, 15 Feb 2022 15:54:53 -0800 (PST) Received: from localhost ([2620:15c:202:201:97ca:4b5:7d22:b276]) by smtp.gmail.com with UTF8SMTPSA id gb8sm3325304pjb.21.2022.02.15.15.54.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Feb 2022 15:54:52 -0800 (PST) From: Brian Norris To: Andrzej Hajda , Neil Armstrong , Robert Foss , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: Heiko Stuebner , Jernej Skrabec , dri-devel@lists.freedesktop.org, Laurent Pinchart , Jonas Karlman , Sean Paul , linux-kernel@vger.kernel.org, Sean Paul , Brian Norris , stable@vger.kernel.org Subject: [PATCH 1/2] drm/bridge: analogix_dp: Support PSR-exit to disable transition Date: Tue, 15 Feb 2022 15:54:19 -0800 Message-Id: <20220215155417.1.I161904be17ba14526f78536ccd78b85818449b51@changeid> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog In-Reply-To: <20220215235420.1284208-1-briannorris@chromium.org> References: <20220215235420.1284208-1-briannorris@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Most eDP panel functions only work correctly when the panel is not in self-refresh. In particular, analogix_dp_bridge_disable() tends to hit AUX channel errors if the panel is in self-refresh. Given the above, it appears that so far, this driver assumes that we are never in self-refresh when it comes time to fully disable the bridge. Prior to commit 846c7dfc1193 ("drm/atomic: Try to preserve the crtc enabled state in drm_atomic_remove_fb, v2."), this tended to be true, because we would automatically disable the pipe when framebuffers were removed, and so we'd typically disable the bridge shortly after the last display activity. However, that is not guaranteed: an idle (self-refresh) display pipe may be disabled, e.g., when switching CRTCs. We need to exit PSR first. Stable notes: this is definitely a bugfix, and the bug has likely existed in some form for quite a while. It may predate the "PSR helpers" refactor, but the code looked very different before that, and it's probably not worth rewriting the fix. Cc: Fixes: 6c836d965bad ("drm/rockchip: Use the helpers for PSR") Signed-off-by: Brian Norris --- .../drm/bridge/analogix/analogix_dp_core.c | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c b/drivers/g= pu/drm/bridge/analogix/analogix_dp_core.c index b7d2e4449cfa..6ee0f62a7161 100644 --- a/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c +++ b/drivers/gpu/drm/bridge/analogix/analogix_dp_core.c @@ -1268,6 +1268,25 @@ static int analogix_dp_bridge_attach(struct drm_brid= ge *bridge, return 0; } =20 +static +struct drm_crtc *analogix_dp_get_old_crtc(struct analogix_dp_device *dp, + struct drm_atomic_state *state) +{ + struct drm_encoder *encoder =3D dp->encoder; + struct drm_connector *connector; + struct drm_connector_state *conn_state; + + connector =3D drm_atomic_get_old_connector_for_encoder(state, encoder); + if (!connector) + return NULL; + + conn_state =3D drm_atomic_get_old_connector_state(state, connector); + if (!conn_state) + return NULL; + + return conn_state->crtc; +} + static struct drm_crtc *analogix_dp_get_new_crtc(struct analogix_dp_device *dp, struct drm_atomic_state *state) @@ -1448,14 +1467,16 @@ analogix_dp_bridge_atomic_disable(struct drm_bridge= *bridge, { struct drm_atomic_state *old_state =3D old_bridge_state->base.state; struct analogix_dp_device *dp =3D bridge->driver_private; - struct drm_crtc *crtc; + struct drm_crtc *old_crtc, *new_crtc; + struct drm_crtc_state *old_crtc_state =3D NULL; struct drm_crtc_state *new_crtc_state =3D NULL; + int ret; =20 - crtc =3D analogix_dp_get_new_crtc(dp, old_state); - if (!crtc) + new_crtc =3D analogix_dp_get_new_crtc(dp, old_state); + if (!new_crtc) goto out; =20 - new_crtc_state =3D drm_atomic_get_new_crtc_state(old_state, crtc); + new_crtc_state =3D drm_atomic_get_new_crtc_state(old_state, new_crtc); if (!new_crtc_state) goto out; =20 @@ -1464,6 +1485,19 @@ analogix_dp_bridge_atomic_disable(struct drm_bridge = *bridge, return; =20 out: + old_crtc =3D analogix_dp_get_old_crtc(dp, old_state); + if (old_crtc) { + old_crtc_state =3D drm_atomic_get_old_crtc_state(old_state, + old_crtc); + + /* When moving from PSR to fully disabled, exit PSR first. */ + if (old_crtc_state && old_crtc_state->self_refresh_active) { + ret =3D analogix_dp_disable_psr(dp); + if (ret) + DRM_ERROR("Failed to disable psr (%d)\n", ret); + } + } + analogix_dp_bridge_disable(bridge); } =20 --=20 2.35.1.265.g69c8d7142f-goog From nobody Sun Jun 28 02:51:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F54FC433EF for ; Tue, 15 Feb 2022 23:55:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244915AbiBOXzL (ORCPT ); Tue, 15 Feb 2022 18:55:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:59370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244902AbiBOXzG (ORCPT ); Tue, 15 Feb 2022 18:55:06 -0500 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 235AEF65FE for ; Tue, 15 Feb 2022 15:54:56 -0800 (PST) Received: by mail-pj1-x102e.google.com with SMTP id v8-20020a17090a634800b001bb78857ccdso2550056pjs.1 for ; Tue, 15 Feb 2022 15:54:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XCMuYxh+2di03JYmyV8dujrYzv3SXhYvMBvZiel5/fo=; b=ccxhsBMFOCVfhgnoeerlnPe9CGG4uxGXLAYEhClhIyCP3tNpTcHx/x+JN4ucRCwQL2 WqY6MYRiz8wL1xuFwwtTVnDt4SsyShQuW1OnmDwEiIOaAiSnJKUYtZyf5HqPE0WTprMn +7Llc0763f37U4Tbbu48tie2OA6UAMwycMI/o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XCMuYxh+2di03JYmyV8dujrYzv3SXhYvMBvZiel5/fo=; b=kS/dOkSMPXJvnYrtaU3kkYBxuuEyE7wPSyGHnt7IL/yITxwOkA4ISScWkJGLrYC/uu BYPfii2jFI9Cl1UtMqqIv2aSzoMgy/uKmb5Hd+e+ppDO0TX0Ov0kZjO3LkqNqt12lYIi 3RreBdYo1A2wjql4ZVpajRZkk83ISLHBPCp2wZjqrgJRJmyu3XKfsAv6swQ0LA9OPAdS 1gfKUSP8pZvzUsBaz46qTI3R1vs8avO3Cjwl7V+bdBIfqzGGz5E4NDjG0UEap8LVUGOJ AiEpmg5Ma1Tund1jg1VRIBpk8gxw2l0ArJVjg4LFy+V5pVUKHL0KJz8OgXpxtrJYXWpM 9Hyg== X-Gm-Message-State: AOAM533EipWg0yBetcO9o+sEijKHWnKZFeEd/FtpCHmci+mkFIxpnaYq +9dG7Ri/9NkGZRY9E9izOpbBLg== X-Google-Smtp-Source: ABdhPJx6l/DF/88bJJ5I6OrdrZ57LWHcn7N2oIe+IhY40ktSvgddR6j7CB8zOcFwdg0ZCwoVNOcHcQ== X-Received: by 2002:a17:90b:4a02:b0:1b8:d3c7:7a2b with SMTP id kk2-20020a17090b4a0200b001b8d3c77a2bmr7163388pjb.194.1644969295688; Tue, 15 Feb 2022 15:54:55 -0800 (PST) Received: from localhost ([2620:15c:202:201:97ca:4b5:7d22:b276]) by smtp.gmail.com with UTF8SMTPSA id a12sm38166601pfv.18.2022.02.15.15.54.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Feb 2022 15:54:55 -0800 (PST) From: Brian Norris To: Andrzej Hajda , Neil Armstrong , Robert Foss , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: Heiko Stuebner , Jernej Skrabec , dri-devel@lists.freedesktop.org, Laurent Pinchart , Jonas Karlman , Sean Paul , linux-kernel@vger.kernel.org, Sean Paul , Brian Norris , stable@vger.kernel.org Subject: [PATCH 2/2] drm/atomic: Force bridge self-refresh-exit on CRTC switch Date: Tue, 15 Feb 2022 15:54:20 -0800 Message-Id: <20220215155417.2.Ic15a2ef69c540aee8732703103e2cff51fb9c399@changeid> X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog In-Reply-To: <20220215235420.1284208-1-briannorris@chromium.org> References: <20220215235420.1284208-1-briannorris@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's possible to change which CRTC is in use for a given connector/encoder/bridge while we're in self-refresh without fully disabling the connector/encoder/bridge along the way. This can confuse the bridge encoder/bridge, because (a) it needs to track the SR state (trying to perform "active" operations while the panel is still in SR can be Bad(TM)); and (b) it tracks the SR state via the CRTC state (and after the switch, the previous SR state is lost). Thus, we need to either somehow carry the self-refresh state over to the new CRTC, or else force an encoder/bridge self-refresh transition during such a switch. I choose the latter, so we disable the encoder (and exit PSR) before attaching it to the new CRTC (where we can continue to assume a clean (non-self-refresh) state). This fixes PSR issues seen on Rockchip RK3399 systems with drivers/gpu/drm/bridge/analogix/analogix_dp_core.c. Cc: Fixes: 1452c25b0e60 ("drm: Add helpers to kick off self refresh mode in dri= vers") Signed-off-by: Brian Norris --- drivers/gpu/drm/drm_atomic_helper.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atom= ic_helper.c index 9603193d2fa1..74161d007894 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1011,9 +1011,19 @@ crtc_needs_disable(struct drm_crtc_state *old_state, return drm_atomic_crtc_effectively_active(old_state); =20 /* - * We need to run through the crtc_funcs->disable() function if the CRTC - * is currently on, if it's transitioning to self refresh mode, or if - * it's in self refresh mode and needs to be fully disabled. + * We need to disable bridge(s) and CRTC if we're transitioning out of + * self-refresh and changing CRTCs at the same time, because the + * bridge tracks self-refresh status via CRTC state. + */ + if (old_state->self_refresh_active && new_state->enable && + old_state->crtc !=3D new_state->crtc) + return true; + + /* + * We also need to run through the crtc_funcs->disable() function if + * the CRTC is currently on, if it's transitioning to self refresh + * mode, or if it's in self refresh mode and needs to be fully + * disabled. */ return old_state->active || (old_state->self_refresh_active && !new_state->active) || --=20 2.35.1.265.g69c8d7142f-goog