From patchwork Thu Mar 30 14:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194226 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D4BBC6FD1D for ; Thu, 30 Mar 2023 14:16:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 77FBD10E3D5; Thu, 30 Mar 2023 14:16:45 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id E70B510E3D5 for ; Thu, 30 Mar 2023 14:16:37 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2B96F660310D; Thu, 30 Mar 2023 15:16:36 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185796; bh=aTfefQf7wUPldM8GfwxyIBQhpoEf1h/RP3aMOHoG5mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/hJlZxOEbaGyp+oaQoR1ff6jbmyH6VOaZJTv1qkCUr5ZN+0HOzujNwZvlNSON4Wm XoW+9USRjLmb7oA6Kc3IMqnzPhTlo882s0QEJs5JX/ZUsdunMcOkutO9RYERJSJAEc MP1cf6Xna9f/NN/2VVwr7aLZi0JfG1AQedugoImdSJ8eZKozW6kYU/L6pazR2AdpZf QP5uT5uRBpvtgi50o47j1vmpHdURXbCPGoGycob2nHfcY+VRMoDlWhZXmyCdgvlnOY E/VqX4LjIOJQhZ7E/qAC26gGrBzLhL0DXtnmpRarUfJiWXVEcRUWS3uOOVJlQSOmFm +HfruHQvhoLvQ== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 1/8] drm/mediatek: dp: Cache EDID for eDP panel Date: Thu, 30 Mar 2023 16:16:23 +0200 Message-Id: <20230330141631.190528-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Since eDP panels are not removable it is safe to cache the EDID: this will avoid a relatively long read transaction at every PM resume that is unnecessary only in the "special" case of eDP, hence speeding it up a little, as from now on, as resume operation, we will perform only link training. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index 1f94fcc144d3..84f82cc68672 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -118,6 +118,7 @@ struct mtk_dp { const struct mtk_dp_data *data; struct mtk_dp_info info; struct mtk_dp_train_info train_info; + struct edid *edid; struct platform_device *phy_dev; struct phy *phy; @@ -1993,7 +1994,11 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge, usleep_range(2000, 5000); } - new_edid = drm_get_edid(connector, &mtk_dp->aux.ddc); + /* eDP panels aren't removable, so we can return a cached EDID. */ + if (mtk_dp->edid && mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP) + new_edid = drm_edid_duplicate(mtk_dp->edid); + else + new_edid = drm_get_edid(connector, &mtk_dp->aux.ddc); /* * Parse capability here to let atomic_get_input_bus_fmts and @@ -2022,6 +2027,10 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge, drm_atomic_bridge_chain_post_disable(bridge, connector->state->state); } + /* If this is an eDP panel and the read EDID is good, cache it for later */ + if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP && !mtk_dp->edid && new_edid) + mtk_dp->edid = drm_edid_duplicate(new_edid); + return new_edid; } From patchwork Thu Mar 30 14:16:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194229 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98B37C761A6 for ; Thu, 30 Mar 2023 14:16:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 41D5C10EE6F; Thu, 30 Mar 2023 14:16:46 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id A4B7F10E3D5 for ; Thu, 30 Mar 2023 14:16:38 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id E2F986603182; Thu, 30 Mar 2023 15:16:36 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185797; bh=IS0da1vr/9JtA9BZ0bqYXl4kxrPBhntX0yK9vYbXQe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QX3hEc5bIjfn/9HXK/jajCuVuMbQRrBZ8Loplcaqwr1QocxrJZ+zBv6+c6/DiAeZT Mv9JHPxihln/XNGYfeDfp1/N5615fjGs0C69afbiTYj7CNa9UkY01gbQuwqkDlWmIQ H6ayZp7oNoT/5bQF7LALmtquNP1OT/YJuSj3dOwuj1yahcObgPHsM625uehycHYJ58 7x9x9+WynBYqBPMs2fjKBk5Sr7PRD0DH1uvCA2MV3p1HvDFKPizrYT8YorV2w/3KUZ PiAiqC7EisBDt9NjH+/48UPpci82qDhXFAG2yRAzDo0QVbV5Y1f8Zgy/MTbZ6evud8 YIWllQ4Fi/lmA== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 2/8] drm/mediatek: dp: Move AUX and panel poweron/off sequence to function Date: Thu, 30 Mar 2023 16:16:24 +0200 Message-Id: <20230330141631.190528-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Everytime we run bridge detection and/or EDID read we run a poweron and poweroff sequence for both the AUX and the panel; moreover, this is also done when enabling the bridge in the .atomic_enable() callback. Move this power on/off sequence to a new mtk_dp_aux_panel_poweron() function as to commonize it. Note that, before this commit, in mtk_dp_bridge_atomic_enable() only the AUX was getting powered on but the panel was left powered off if the DP cable wasn't plugged in while now we unconditionally send a D0 request and this is done for two reasons: - First, whether this request fails or not, it takes the same time and anyway the DP hardware won't produce any error (or, if it does, it's ignorable because it won't block further commands) - Second, training the link between a sleeping/standby/unpowered display makes little sense. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 76 ++++++++++++------------------- 1 file changed, 30 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index 84f82cc68672..76ea94167531 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -1253,6 +1253,29 @@ static void mtk_dp_audio_mute(struct mtk_dp *mtk_dp, bool mute) val[2], AU_TS_CFG_DP_ENC0_P0_MASK); } +static void mtk_dp_aux_panel_poweron(struct mtk_dp *mtk_dp, bool pwron) +{ + if (pwron) { + /* power on aux */ + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, + DP_PWR_STATE_BANDGAP_TPLL_LANE, + DP_PWR_STATE_MASK); + + /* power on panel */ + drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); + usleep_range(2000, 5000); + } else { + /* power off panel */ + drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); + usleep_range(2000, 3000); + + /* power off aux */ + mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, + DP_PWR_STATE_BANDGAP_TPLL, + DP_PWR_STATE_MASK); + } +} + static void mtk_dp_power_enable(struct mtk_dp *mtk_dp) { mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_RESET_AND_PROBE, @@ -1937,16 +1960,9 @@ static enum drm_connector_status mtk_dp_bdg_detect(struct drm_bridge *bridge) if (!mtk_dp->train_info.cable_plugged_in) return ret; - if (!enabled) { - /* power on aux */ - mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, - DP_PWR_STATE_BANDGAP_TPLL_LANE, - DP_PWR_STATE_MASK); + if (!enabled) + mtk_dp_aux_panel_poweron(mtk_dp, true); - /* power on panel */ - drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); - usleep_range(2000, 5000); - } /* * Some dongles still source HPD when they do not connect to any * sink device. To avoid this, we need to read the sink count @@ -1958,16 +1974,8 @@ static enum drm_connector_status mtk_dp_bdg_detect(struct drm_bridge *bridge) if (DP_GET_SINK_COUNT(sink_count)) ret = connector_status_connected; - if (!enabled) { - /* power off panel */ - drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); - usleep_range(2000, 3000); - - /* power off aux */ - mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, - DP_PWR_STATE_BANDGAP_TPLL, - DP_PWR_STATE_MASK); - } + if (!enabled) + mtk_dp_aux_panel_poweron(mtk_dp, false); return ret; } @@ -1983,15 +1991,7 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge, if (!enabled) { drm_atomic_bridge_chain_pre_enable(bridge, connector->state->state); - - /* power on aux */ - mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, - DP_PWR_STATE_BANDGAP_TPLL_LANE, - DP_PWR_STATE_MASK); - - /* power on panel */ - drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); - usleep_range(2000, 5000); + mtk_dp_aux_panel_poweron(mtk_dp, true); } /* eDP panels aren't removable, so we can return a cached EDID. */ @@ -2015,15 +2015,7 @@ static struct edid *mtk_dp_get_edid(struct drm_bridge *bridge, } if (!enabled) { - /* power off panel */ - drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D3); - usleep_range(2000, 3000); - - /* power off aux */ - mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, - DP_PWR_STATE_BANDGAP_TPLL, - DP_PWR_STATE_MASK); - + mtk_dp_aux_panel_poweron(mtk_dp, false); drm_atomic_bridge_chain_post_disable(bridge, connector->state->state); } @@ -2188,15 +2180,7 @@ static void mtk_dp_bridge_atomic_enable(struct drm_bridge *bridge, return; } - /* power on aux */ - mtk_dp_update_bits(mtk_dp, MTK_DP_TOP_PWR_STATE, - DP_PWR_STATE_BANDGAP_TPLL_LANE, - DP_PWR_STATE_MASK); - - if (mtk_dp->train_info.cable_plugged_in) { - drm_dp_dpcd_writeb(&mtk_dp->aux, DP_SET_POWER, DP_SET_POWER_D0); - usleep_range(2000, 5000); - } + mtk_dp_aux_panel_poweron(mtk_dp, true); /* Training */ ret = mtk_dp_training(mtk_dp); From patchwork Thu Mar 30 14:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194227 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 530DCC761AF for ; Thu, 30 Mar 2023 14:16:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BE11710EE6B; Thu, 30 Mar 2023 14:16:45 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5AA5310E3D5 for ; Thu, 30 Mar 2023 14:16:39 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id A63066603189; Thu, 30 Mar 2023 15:16:37 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185798; bh=l7DxgZbkLf1a/NAX8ACnOYom2qi3A95N4rbvhFxlUX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kok26pBYezCXLsDqlPBv2AAuuArwPCPm1egmztLbAPV5WKAfc+jLvl0aZaf7UVrMA l/Zhteq7VX7hcsoAwMknWLdZJSAi0O4Fio6waFY2Pr41THlth0BFXPi7deedr5xEPx 63S5QwMCvF8YA8KpXRt4nGT2Bbp9ceXaYVJWGp0vlqzDh7pToyaxp32L6x/UyxUfqA fyP/CP3Dd38Pm2kh/s0Kc5VQgkfuSADcIxGEzExSKXZ5eri9mqF5FyFPQFjDsvy8As aVx2r8UUvdYP8QRJJQzMoOvO7cYfz8rI5M7yGvor11hIymYm9ybjXMJMXn6rqzRX0K C6cNQX6P9RCxQ== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 3/8] drm/mediatek: dp: Always return connected status for eDP in .detect() Date: Thu, 30 Mar 2023 16:16:25 +0200 Message-Id: <20230330141631.190528-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If this is an eDP panel it's not removable, hence it's always connected: as a shortcut, always return connector_status_connected in the .detect() callback for eDP connector, avoiding a poweron, a check for sink count and a poweroff. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index 76ea94167531..c82dd1f0675d 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -1957,6 +1957,9 @@ static enum drm_connector_status mtk_dp_bdg_detect(struct drm_bridge *bridge) bool enabled = mtk_dp->enabled; u8 sink_count = 0; + if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP) + return connector_status_connected; + if (!mtk_dp->train_info.cable_plugged_in) return ret; From patchwork Thu Mar 30 14:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194225 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01645C761A6 for ; Thu, 30 Mar 2023 14:16:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC2DD10EE6A; Thu, 30 Mar 2023 14:16:43 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8047D10EE6A for ; Thu, 30 Mar 2023 14:16:40 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 696766603188; Thu, 30 Mar 2023 15:16:38 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185799; bh=3ZbLGCMsG/gn15JDSWm25FtN0N4B/ueru9VCCfJiapw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E3prFSel4ya0ptVFTP/t3CCVEDXD5CPfqu6LP2Idm1G5ho0artipcCQ2GfC454Sy7 EIZ4hfEH11GN0Uhap+714IMBcw9PbSA/qraXh50zxLr0lEhdpODjwoW2OjkHS1d+/c KTMsAvlq0ExWjJpeGvkQK/LAPqjkkGM9mpjLd2KEUZditEbQaGlvqob0dJ2MhhAU86 Ab1Vu7dDjeaItWiawNG3GTrrm8ZCNjuo7RLS3cF+gDxO/RUizb72gxeqU4WLT3G335 1AMNT7iLCp7Xw5aWznxtXwJkrb3AaKgh8+AR+d2D3T21+LXsMZkEYrw+Ol3DuW9JEn ZSCTYBFt8tWyQ== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 4/8] drm/mediatek: dp: Always set cable_plugged_in at resume for eDP panel Date: Thu, 30 Mar 2023 16:16:26 +0200 Message-Id: <20230330141631.190528-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" eDP panels are not removable: at PM resume, the cable will obviously still be plugged in. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index c82dd1f0675d..ac21eca0e20e 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -2607,6 +2607,9 @@ static int mtk_dp_resume(struct device *dev) mtk_dp_hwirq_enable(mtk_dp, true); mtk_dp_power_enable(mtk_dp); + if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP) + mtk_dp->train_info.cable_plugged_in = true; + return 0; } #endif From patchwork Thu Mar 30 14:16:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194228 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01BFAC761AF for ; Thu, 30 Mar 2023 14:16:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 37E0C10EE6D; Thu, 30 Mar 2023 14:16:46 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id A44A610E3D5 for ; Thu, 30 Mar 2023 14:16:41 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id EC1E3660318A; Thu, 30 Mar 2023 15:16:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185800; bh=dxC6MHx3NJXRAEW1ywTcNfOZX7I8dn5v2i9D/PKGK9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lxDdzA/skgD2ZgYdNlhX2IjyvEpd6f4YTDdMHHtsEDnq4u3PwMSSw+jGBl2NgXFOv fH4mkU7RvKer8Fz4LPpZdqJ/SpAkgocyp0wbF8XDnNRs1xF1zngb/WTffZibApmXK9 wcMF08O+71aHB/mjQlkigk+uwSGmwssq5A0aJY0naSk5PgwGh7n6xxiqsogSq7Tgl7 5ngx85N5LQ9KSB6HOVHe0ucb3hWFkndrBOFVIJPfWiCmb4r0L5woxvsw/5Q9t5x7xZ N7x0H4VlheGIcQpatW3ETkuOlzs11cYH9cEH6R5Jm60AJF9bbu6AN/nlOEzih51gfd 7BCMvtRa1IJSA== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 5/8] drm/mediatek: dp: Change logging to dev for mtk_dp_aux_transfer() Date: Thu, 30 Mar 2023 16:16:28 +0200 Message-Id: <20230330141631.190528-7-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Change logging from drm_{err,info}() to dev_{err,info}() in functions mtk_dp_aux_transfer() and mtk_dp_aux_do_transfer(): this will be essential to avoid getting NULL pointer kernel panics if any kind of error happens during AUX transfers happening before the bridge is attached. This may potentially start happening in a later commit implementing aux-bus support, as AUX transfers will be triggered from the panel driver (for EDID) before the mtk-dp bridge gets attached, and it's done in preparation for the same. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index ac21eca0e20e..19b145cf2e05 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -849,7 +849,7 @@ static int mtk_dp_aux_do_transfer(struct mtk_dp *mtk_dp, bool is_read, u8 cmd, u32 phy_status = mtk_dp_read(mtk_dp, MTK_DP_AUX_P0_3628) & AUX_RX_PHY_STATE_AUX_TX_P0_MASK; if (phy_status != AUX_RX_PHY_STATE_AUX_TX_P0_RX_IDLE) { - drm_err(mtk_dp->drm_dev, + dev_err(mtk_dp->dev, "AUX Rx Aux hang, need SW reset\n"); return -EIO; } @@ -2061,7 +2061,7 @@ static ssize_t mtk_dp_aux_transfer(struct drm_dp_aux *mtk_aux, is_read = true; break; default: - drm_err(mtk_aux->drm_dev, "invalid aux cmd = %d\n", + dev_err(mtk_dp->dev, "invalid aux cmd = %d\n", msg->request); ret = -EINVAL; goto err; @@ -2077,7 +2077,7 @@ static ssize_t mtk_dp_aux_transfer(struct drm_dp_aux *mtk_aux, to_access); if (ret) { - drm_info(mtk_dp->drm_dev, + dev_info(mtk_dp->dev, "Failed to do AUX transfer: %d\n", ret); goto err; } From patchwork Thu Mar 30 14:16:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194230 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11EBCC761AF for ; Thu, 30 Mar 2023 14:17:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 688FF10EE70; Thu, 30 Mar 2023 14:17:03 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6FCA710E3D5 for ; Thu, 30 Mar 2023 14:16:42 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id B0189660318D; Thu, 30 Mar 2023 15:16:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185801; bh=piJKx8AJRTNo3xZLCBhwQ0b5ZyuIg8W2w0zGxP4Udgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g5L7QZxGqzl2u0VKcmghM/MMjLooj5fsprmmNQ9NEj9rz+nlXW064NZKV3CImYyKK myo7/zMZP7GvqUYgajmGscUekHcWXfmcVEOrYNBZ9T6/q6YmrWabn9DH2Ub+kU+FLq VGgc6DHaLln0II3Le7D9oGMrlC2v/kfJQ9ZMy6fTJ8mLC8vb520n4hWeTYANCmqwZb vDaEkOA4ZPCucDZF5Ul2dxqjS8g7vl39rZ4F48SS04zYlBX3yOUCfyN1OSDTxtccYf fQ18iC69YmxonW4mxJR+372XwGMsKFdyvLPeIwBI9hRQHvIwaj57QnI5bZX92Gn6L5 WiEnKbtTGqtXg== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 6/8] drm/mediatek: dp: Enable event interrupt only when bridge attached Date: Thu, 30 Mar 2023 16:16:29 +0200 Message-Id: <20230330141631.190528-8-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for implementing support for aux-bus in this driver, add a IRQ_NOAUTOEN flag to the event interrupt that we request at probe time and manage the enablement of the ISR at bridge_attach and detach time. When aux-bus will be implemented, enabling the interrupt before attaching the bridge will create an event storm and hang the kernel during boot. In any case, the interrupt handler anyway requires resources that are initialized by mtk_dp_bridge_attach(), so it cannot do anything meaningful without... and even crash, but that's not happening in the current code because the HW remains unpowered until resources are made available. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index 19b145cf2e05..6aaf162a6bfe 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -100,6 +100,7 @@ struct mtk_dp_efuse_fmt { struct mtk_dp { bool enabled; bool need_debounce; + int irq; u8 max_lanes; u8 max_linkrate; u8 rx_cap[DP_RECEIVER_CAP_SIZE]; @@ -2148,6 +2149,8 @@ static int mtk_dp_bridge_attach(struct drm_bridge *bridge, mtk_dp->drm_dev = bridge->dev; + irq_clear_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); + enable_irq(mtk_dp->irq); mtk_dp_hwirq_enable(mtk_dp, true); return 0; @@ -2164,6 +2167,7 @@ static void mtk_dp_bridge_detach(struct drm_bridge *bridge) struct mtk_dp *mtk_dp = mtk_dp_from_bridge(bridge); mtk_dp_hwirq_enable(mtk_dp, false); + disable_irq(mtk_dp->irq); mtk_dp->drm_dev = NULL; mtk_dp_poweroff(mtk_dp); drm_dp_aux_unregister(&mtk_dp->aux); @@ -2482,7 +2486,7 @@ static int mtk_dp_probe(struct platform_device *pdev) { struct mtk_dp *mtk_dp; struct device *dev = &pdev->dev; - int ret, irq_num; + int ret; mtk_dp = devm_kzalloc(dev, sizeof(*mtk_dp), GFP_KERNEL); if (!mtk_dp) @@ -2491,9 +2495,9 @@ static int mtk_dp_probe(struct platform_device *pdev) mtk_dp->dev = dev; mtk_dp->data = (struct mtk_dp_data *)of_device_get_match_data(dev); - irq_num = platform_get_irq(pdev, 0); - if (irq_num < 0) - return dev_err_probe(dev, irq_num, + mtk_dp->irq = platform_get_irq(pdev, 0); + if (mtk_dp->irq < 0) + return dev_err_probe(dev, mtk_dp->irq, "failed to request dp irq resource\n"); mtk_dp->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); @@ -2514,7 +2518,8 @@ static int mtk_dp_probe(struct platform_device *pdev) spin_lock_init(&mtk_dp->irq_thread_lock); - ret = devm_request_threaded_irq(dev, irq_num, mtk_dp_hpd_event, + irq_set_status_flags(mtk_dp->irq, IRQ_NOAUTOEN); + ret = devm_request_threaded_irq(dev, mtk_dp->irq, mtk_dp_hpd_event, mtk_dp_hpd_event_thread, IRQ_TYPE_LEVEL_HIGH, dev_name(dev), mtk_dp); From patchwork Thu Mar 30 14:16:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194231 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87C29C77B60 for ; Thu, 30 Mar 2023 14:17:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E65A10EE72; Thu, 30 Mar 2023 14:17:04 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 311A110E3D5 for ; Thu, 30 Mar 2023 14:16:43 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 6D5746603191; Thu, 30 Mar 2023 15:16:41 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185802; bh=/+IRk8GyWs1c9yVT0iTCxo8DT1414PGgt9mTBDTdxe0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aK3ZHmDBVuEE2y80vMNCLAu6pwbfIkiUbL6aB4ukEEV+bjKDFx4xHQDIpmj7woNhm qrpd0m5OYgs86EzB8GKfAnLOVxB4fDmC+24RMfnCc2o2S1N2grVnj39w6HZga+2/1y VU1vFAwybwNulwZ4ibH9HlEQqQnekLBOHnigwSQdsMo5Bm4i0QL+klWEC5NPzoSxo1 X3xcKSN2TxINeDjkb2YsCfxdJhh5DJa63YxP71NoERP/VpsGCPtp9oxZIoZgM0GJlC GHiye2YoUQMFPlc8CTiQrDkqjH0wC1mGGIyvGu6VfdWGU/1XrM3OirRI3tinrlos16 0sZF23fDOPXlw== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 7/8] drm/mediatek: dp: Use devm variant of drm_bridge_add() Date: Thu, 30 Mar 2023 16:16:30 +0200 Message-Id: <20230330141631.190528-9-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for adding support for aux-bus, which will add a code path that may fail after the drm_bridge_add() call, change that to devm_drm_bridge_add() to simplify failure paths later. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index 6aaf162a6bfe..62d53c4b3feb 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -2565,7 +2565,7 @@ static int mtk_dp_probe(struct platform_device *pdev) DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID | DRM_BRIDGE_OP_HPD; mtk_dp->bridge.type = mtk_dp->data->bridge_type; - drm_bridge_add(&mtk_dp->bridge); + devm_drm_bridge_add(dev, &mtk_dp->bridge); mtk_dp->need_debounce = true; timer_setup(&mtk_dp->debounce_timer, mtk_dp_debounce_timer, 0); From patchwork Thu Mar 30 14:16:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 13194233 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 066EEC761A6 for ; Thu, 30 Mar 2023 14:17:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2D03910EE7A; Thu, 30 Mar 2023 14:17:23 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by gabe.freedesktop.org (Postfix) with ESMTPS id D8AD210E3D5 for ; Thu, 30 Mar 2023 14:16:43 +0000 (UTC) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id 325CD6603195; Thu, 30 Mar 2023 15:16:42 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680185802; bh=eZ/KgEJ3/NtZRipFLNfrQ0jkavJVDGo3ZnqqWIgjfIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CHlMbLXEvdEzvbDBs1TW7oa3xwSEoHjM2bENO0R5QP5j4s7rodfj4FGELpctOY9Ji ohQqqKGmadC97bCZnJnFQdzs95a1lseDpDPM5beVOboMscZkrRP98Eo4cCelKGsJ7Y WLgVPbegbzQWjritLRSisAzr3XcTxEMqJuFU8C03YuC5wmkDHB7PLTRMbUQzwLpqPq C8bnz4FihZx0Orfs6jYQxlmNGxKmzcEdn1By6XRVWlJ308SGaQbNkcXBy+hZ6ZGLDf fqrEvvx6WdLvc8hlWCNEH+vaFT3AKwOLqZH1ccCJWaaEKu4wfN7D92E4krjoMC7e22 Qltm04JGgSvjw== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Subject: [PATCH v1 8/8] drm/mediatek: dp: Add support for embedded DisplayPort aux-bus Date: Thu, 30 Mar 2023 16:16:31 +0200 Message-Id: <20230330141631.190528-10-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> References: <20230330141631.190528-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, matthias.bgg@gmail.com, kernel@collabora.com, linux-arm-kernel@lists.infradead.org, angelogioacchino.delregno@collabora.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" For the eDP case we can support using aux-bus on MediaTek DP: this gives us the possibility to declare our panel as generic "panel-edp" which will automatically configure the timings and available modes via the EDID that we read from it. To do this, move the panel parsing at the end of the probe function so that the hardware is initialized beforehand and also power it on as, when we populate the aux-bus, the panel driver will trigger an EDID read as panel detection. **** CUT **** Also, since the DP IP will always trigger a HPD interrupt at this stage, it was necessary to add a new `bridge_attached` member to the mtk_dp structure to make sure that `drm_helper_hpd_irq_event()` will not be called before the bridge gets actually attached, or otherwise we will get a NULL pointer KP due to mtk_dp->bridge.dev being uninitialized. **** CUT **** Last but not least, since now the AUX transfers can happen in the separated aux-bus, it was necessary to add an exclusion for the cable_plugged_in check in `mtk_dp_aux_transfer()` and the easiest way to do this is to simply ignore checking that when the bridge type is eDP. Signed-off-by: AngeloGioacchino Del Regno --- drivers/gpu/drm/mediatek/mtk_dp.c | 56 +++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index 62d53c4b3feb..f62ef24db67d 100644 --- a/drivers/gpu/drm/mediatek/mtk_dp.c +++ b/drivers/gpu/drm/mediatek/mtk_dp.c @@ -4,6 +4,7 @@ * Copyright (c) 2022 BayLibre */ +#include #include #include #include @@ -2041,7 +2042,8 @@ static ssize_t mtk_dp_aux_transfer(struct drm_dp_aux *mtk_aux, mtk_dp = container_of(mtk_aux, struct mtk_dp, aux); - if (!mtk_dp->train_info.cable_plugged_in) { + if (mtk_dp->bridge.type != DRM_MODE_CONNECTOR_eDP && + !mtk_dp->train_info.cable_plugged_in) { ret = -EAGAIN; goto err; } @@ -2153,6 +2155,11 @@ static int mtk_dp_bridge_attach(struct drm_bridge *bridge, enable_irq(mtk_dp->irq); mtk_dp_hwirq_enable(mtk_dp, true); + if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP /* && panel_on_aux_bus() */) { + mtk_dp->train_info.cable_plugged_in = true; + drm_helper_hpd_irq_event(mtk_dp->drm_dev); + } + return 0; err_bridge_attach: @@ -2482,6 +2489,20 @@ static int mtk_dp_register_audio_driver(struct device *dev) return PTR_ERR_OR_ZERO(mtk_dp->audio_pdev); } +static int mtk_dp_edp_link_panel(struct drm_dp_aux *mtk_aux) +{ + struct mtk_dp *mtk_dp = container_of(mtk_aux, struct mtk_dp, aux); + struct device *dev = mtk_aux->dev; + struct drm_bridge *panel_aux_bridge; + + panel_aux_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); + if (IS_ERR(panel_aux_bridge)) + return PTR_ERR(panel_aux_bridge); + + mtk_dp->next_bridge = panel_aux_bridge; + return 0; +} + static int mtk_dp_probe(struct platform_device *pdev) { struct mtk_dp *mtk_dp; @@ -2500,21 +2521,14 @@ static int mtk_dp_probe(struct platform_device *pdev) return dev_err_probe(dev, mtk_dp->irq, "failed to request dp irq resource\n"); - mtk_dp->next_bridge = devm_drm_of_get_bridge(dev, dev->of_node, 1, 0); - if (IS_ERR(mtk_dp->next_bridge) && - PTR_ERR(mtk_dp->next_bridge) == -ENODEV) - mtk_dp->next_bridge = NULL; - else if (IS_ERR(mtk_dp->next_bridge)) - return dev_err_probe(dev, PTR_ERR(mtk_dp->next_bridge), - "Failed to get bridge\n"); - ret = mtk_dp_dt_parse(mtk_dp, pdev); if (ret) return dev_err_probe(dev, ret, "Failed to parse dt\n"); - drm_dp_aux_init(&mtk_dp->aux); mtk_dp->aux.name = "aux_mtk_dp"; + mtk_dp->aux.dev = dev; mtk_dp->aux.transfer = mtk_dp_aux_transfer; + drm_dp_aux_init(&mtk_dp->aux); spin_lock_init(&mtk_dp->irq_thread_lock); @@ -2570,6 +2584,28 @@ static int mtk_dp_probe(struct platform_device *pdev) mtk_dp->need_debounce = true; timer_setup(&mtk_dp->debounce_timer, mtk_dp_debounce_timer, 0); + if (mtk_dp->bridge.type == DRM_MODE_CONNECTOR_eDP) { + /* Need to power on HW because aux-bus will read EDID */ + mtk_dp_aux_panel_poweron(mtk_dp, true); + + ret = devm_of_dp_aux_populate_bus(&mtk_dp->aux, NULL); + + /* Power off AUX and panel now as detection is done. */ + mtk_dp_aux_panel_poweron(mtk_dp, false); + + /* We ignore -ENODEV error, as the panel may not be on aux-bus */ + if (ret && ret != -ENODEV) + return ret; + + /* + * Here we don't ignore any error, as if there's no panel to + * link, eDP is not configured correctly and will be unusable. + */ + ret = mtk_dp_edp_link_panel(&mtk_dp->aux); + if (ret) + return ret; + } + pm_runtime_enable(dev); pm_runtime_get_sync(dev);