Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5791696rwl; Tue, 4 Apr 2023 03:50:25 -0700 (PDT) X-Google-Smtp-Source: AKy350b451RJHi92h+J1f0YtDutoaRSPjtg/BziGWtsrlGoP4ONWkuHRkYHVuHY84VcLONawhy0c X-Received: by 2002:a17:907:217a:b0:92f:b47c:cefc with SMTP id rl26-20020a170907217a00b0092fb47ccefcmr1695270ejb.24.1680605425276; Tue, 04 Apr 2023 03:50:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680605425; cv=none; d=google.com; s=arc-20160816; b=EaG4f5Qj0UjF46bJvRhOxP+G0/r19N//QMLb3mn7nYLCA5y0ELXPADAN9Tqh87V2zd vbjimmgR+4Bb+O/yt5eewS/M33KpmKw03FePk8BgFGXW2UEKZ0L0PKXeQxDemPraLHkv WA2+MkeyKp76yd6CcOdRbVNx1yQTP0+n1JWbmB7+OMAvVpTxYJDYn8Z6NFnqwkblj6yH qKnN85Gh97FfT5gaFkqs14gtr9+fU22U1sui+RoZD3FjFs+okhz8o1/Kp+7VAH4H1aAl 7gVYhNFsCTR5csd6PUh6cN4EntDtBxWNPEmrTg3B/ikgKnMllaSpJxId7n9uJvjXgxVD uGrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hmWKdqxDsvfexi1yEi6FSub5mgsp34ZQ9W6zOyDfYqA=; b=zCMvceH8/q157MVK6OGxtE6W9xjXCHF5Cp3Evclu43V6fTNYHkSyw5LWJpit1+hIF7 4gGPejXqyR2Mrx5GejNbO9XPnXs2kJo+uC2WGd8J1iM9GtiZRVqCh/fzW7qOTKhydvz2 yCyVTmbJADcUzw75cpV276PiQXCVeWWKWvj9EMBVpVMGHPn1J+YEogIJoKob6a7prluX IopdxgeVYns4vDLL9FSL2xzh0ov9B/Mdz444W5JgH+hBT6qPHqdoA4+GSQP/2XX/A5xQ YxTII2J/yXpxgCvaf8beBhXGsSIl55Ze3PEmpY2llKQfmZhSR3AgSWURPX4SFSLjvbSC yuPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Efpx2sJ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a170906c18400b009307ca78eb1si9590665ejz.849.2023.04.04.03.50.01; Tue, 04 Apr 2023 03:50:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Efpx2sJ5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234644AbjDDKsq (ORCPT + 99 others); Tue, 4 Apr 2023 06:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234049AbjDDKsS (ORCPT ); Tue, 4 Apr 2023 06:48:18 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5072230C5 for ; Tue, 4 Apr 2023 03:48:14 -0700 (PDT) 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 85711660326B; Tue, 4 Apr 2023 11:48:12 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1680605293; bh=+E8hTN3wC4q97x93aXteKC9CVFfI18J5GBPZJYT7VQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Efpx2sJ5N9N3X1hL/oznHMWpKTzXWKL+gA3TXF9fED37IxvaVpNVe5nHbegXovHDM 7P55UpaxPdbpHkV3cbGNVAP00olpklBSGn1m/ZK1LRAw3mC8pjMYBdha3AI2FjF9Oe F5Vw6aUDUi3DxHRsl/dRugvuEAWhjQrl8JZ4qMSXzXa8BCjBAK3L1Ya0Ug7FzjrYHZ zNA7PWcT4/dCCJc5CrDnGj+B372wlqMbZDDS7encx4SKPnYoZIsi9NqaLXGvi4s7ob 9zT3NjbsuSweIkQJTvUJxsyAp4WPnvPEMrkzqczPvLLBmVAP42b5elmYCs3yn/YHAv 0F5oSJhBxnxJA== From: AngeloGioacchino Del Regno To: chunkuang.hu@kernel.org Cc: p.zabel@pengutronix.de, airlied@gmail.com, daniel@ffwll.ch, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, wenst@chromium.org Subject: [PATCH v3 9/9] drm/mediatek: dp: Add support for embedded DisplayPort aux-bus Date: Tue, 4 Apr 2023 12:48:00 +0200 Message-Id: <20230404104800.301150-10-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230404104800.301150-1-angelogioacchino.delregno@collabora.com> References: <20230404104800.301150-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 initialize the DPTX AUX block and power both on as, when we populate the aux-bus, the panel driver will trigger an EDID read to perform panel detection. 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 | 61 ++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_dp.c b/drivers/gpu/drm/mediatek/mtk_dp.c index a67143c22024..8109f5b4392b 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 @@ -2042,7 +2043,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; } @@ -2154,6 +2156,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) { + mtk_dp->train_info.cable_plugged_in = true; + drm_helper_hpd_irq_event(mtk_dp->drm_dev); + } + return 0; err_bridge_attach: @@ -2483,6 +2490,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; @@ -2501,21 +2522,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); @@ -2571,6 +2585,33 @@ 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) { + /* Initialize, reset and poweron the DPTX AUX block */ + mtk_dp_initialize_aux_settings(mtk_dp); + mtk_dp_power_enable(mtk_dp); + + /* Power on the panel to allow EDID read from aux-bus */ + mtk_dp_aux_panel_poweron(mtk_dp, true); + + ret = devm_of_dp_aux_populate_bus(&mtk_dp->aux, NULL); + + /* If the panel is present, detection is done: power off! */ + mtk_dp_aux_panel_poweron(mtk_dp, false); + mtk_dp_power_disable(mtk_dp); + + /* 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); -- 2.40.0