Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1941399pxb; Wed, 9 Feb 2022 07:43:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHvOcY/sYZ17gNPK7OhvyLBsskdOqQQxyyycMlMNL7XgIMVhPQRfQTisU+/bWNOQ+GAfsW X-Received: by 2002:a17:907:16a6:: with SMTP id hc38mr2591671ejc.291.1644421410635; Wed, 09 Feb 2022 07:43:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644421410; cv=none; d=google.com; s=arc-20160816; b=b0L+XHY/d70yl00uWUW13Y0URK6fxJxbxrCMJd69TCpVP4MNb4uVI4siDQ66hlM+NZ MsmNm4ZuP0lxsCHkaALBc2K+iPHK2vbUSeG8LCUrgr/V/5107KJ8bgt7CMa64AQ9dkLR a/bD2kAiioBFKovCjJlaO7UCVEtPchenH8o1jcHjSrNBU6sHYYYnnhQYiF1UP8YTHNTf 4hTUSArYRHGzVavMp0RIl7iHiCsAHl3kQQrb648FH+9DcNvYI/ZAJJNgrOAKERUdU1O9 TANxBQguqNYgU7CIfgRPJO0FwtJYDE+gLIcFLrfuJJRXImKnACdeDkvS8Csghz9ia0/V o+LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9wxHCRPTyD0o735BwWa9LFwR/MUuZvYyZhAtULHcKFs=; b=sA15KnBHsJowT6EFoS2EC8DH8AcSRtkSpesnrKtszcv4sanJPCIeQrLFDgwxVqMqmY r0ma/tOvzAYdEEfyWv9prjgJaQPdo4SBoH1iTY+q5Poer2H32ATdvwdltgx6KLTkiwN3 VPuh7nQRjeFdTv02NixQXwpXBtJsJJ1+cg49coAXTnWZGHrf5XbDc8cQdWN/efrzV0k/ f9+lplxob5t05Looc7+C+p/9vBdRcToDSvlGn3RskC+3GCYVuNR1mYiaCWFD3QqkQc7i Cp0uNtSLBkzPvEqcgPfjs/dREwSwxu5vLxBbJyUVPImHpFSeT/dFnfdXpsxLrtozihUx HMBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CZRFVqjN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si616365edq.24.2022.02.09.07.43.04; Wed, 09 Feb 2022 07:43:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CZRFVqjN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235493AbiBIPG0 (ORCPT + 99 others); Wed, 9 Feb 2022 10:06:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbiBIPGT (ORCPT ); Wed, 9 Feb 2022 10:06:19 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72334C06157B; Wed, 9 Feb 2022 07:06:22 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0D88F60B53; Wed, 9 Feb 2022 15:06:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 709BFC340E7; Wed, 9 Feb 2022 15:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644419181; bh=IAAtDwe4u5no9i26p8atsTlrMbokvE4vwXnd8unhvoE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CZRFVqjNBFc70fy/8haPmLGDlqfqrNeVfOALfTg7JaWvUBR3MTdFnkAo2zPGgVyys K6AhmdZ2IJJ/QpI+MCBlgJ6G3VOklBl4xTmwOXd0OUYVxvdUNp9er2BvpFUUE95jbi 9hnELN1qhwq2uAGI2H2wj4Ru9LY+MpeR5RcyC+VNY2TXONbv6B2x3H2+E0xAt+5U2t hCukZlzjrYSViUpVl/p0jLSvhZop+L561uuFsZKRV//Y8kZKvv4QDQTlTrgBSo446n 51I1Ja8copXX3ngvA+Y8IOD8g/dik5ma6eviM930tQwJiiqlAG/Qwvg6FYchVaUNcg srLeEbBlQo30A== Received: by mail-ej1-f51.google.com with SMTP id k25so8187503ejp.5; Wed, 09 Feb 2022 07:06:21 -0800 (PST) X-Gm-Message-State: AOAM5310KmIs2xql9wsGQLWjDF06w9w5jM5Si0agdYh051fulQ6zJoc9 qRFZq0g93cEnl5TjJn8Yj7Vl9+QV33sZeFgRng== X-Received: by 2002:a17:907:6e14:: with SMTP id sd20mr1423550ejc.749.1644419179751; Wed, 09 Feb 2022 07:06:19 -0800 (PST) MIME-Version: 1.0 References: <20220131085520.287105-1-angelogioacchino.delregno@collabora.com> In-Reply-To: <20220131085520.287105-1-angelogioacchino.delregno@collabora.com> From: Chun-Kuang Hu Date: Wed, 9 Feb 2022 23:06:08 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4] drm/mediatek: mtk_dsi: Avoid EPROBE_DEFER loop with external bridge To: AngeloGioacchino Del Regno Cc: DRI Development , Chun-Kuang Hu , David Airlie , linux-kernel , stable , andrzej.hajda@intel.com, "moderated list:ARM/Mediatek SoC support" , Jagan Teki , Matthias Brugger , Collabora Kernel ML , Linux ARM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Hi, Angelo: AngeloGioacchino Del Regno =E6=96= =BC 2022=E5=B9=B41=E6=9C=8831=E6=97=A5 =E9=80=B1=E4=B8=80 =E4=B8=8B=E5=8D=884:5= 5=E5=AF=AB=E9=81=93=EF=BC=9A > > DRM bridge drivers are now attaching their DSI device at probe time, > which requires us to register our DSI host in order to let the bridge > to probe: this recently started producing an endless -EPROBE_DEFER > loop on some machines that are using external bridges, like the > parade-ps8640, found on the ACER Chromebook R13. > > Now that the DSI hosts/devices probe sequence is documented, we can > do adjustments to the mtk_dsi driver as to both fix now and make sure > to avoid this situation in the future: for this, following what is > documented in drm_bridge.c, move the mtk_dsi component_add() to the > mtk_dsi_ops.attach callback and delete it in the detach callback; > keeping in mind that we are registering a drm_bridge for our DSI, > which is only used/attached if the DSI Host is bound, it wouldn't > make sense to keep adding our bridge at probe time (as it would > be useless to have it if mtk_dsi_ops.attach() fails!), so also move > that one to the dsi host attach function (and remove it in detach). Applied to mediatek-drm-fixes[1], thanks. [1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/= log/?h=3Dmediatek-drm-fixes Regards, Chun-Kuang. > > Cc: # 5.15.x > Signed-off-by: AngeloGioacchino Del Regno > Reviewed-by: Andrzej Hajda > Reviewed-by: Jagan Teki > > --- > drivers/gpu/drm/mediatek/mtk_dsi.c | 167 +++++++++++++++-------------- > 1 file changed, 84 insertions(+), 83 deletions(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediate= k/mtk_dsi.c > index 5d90d2eb0019..bced4c7d668e 100644 > --- a/drivers/gpu/drm/mediatek/mtk_dsi.c > +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c > @@ -786,18 +786,101 @@ void mtk_dsi_ddp_stop(struct device *dev) > mtk_dsi_poweroff(dsi); > } > > +static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *= dsi) > +{ > + int ret; > + > + ret =3D drm_simple_encoder_init(drm, &dsi->encoder, > + DRM_MODE_ENCODER_DSI); > + if (ret) { > + DRM_ERROR("Failed to encoder init to drm\n"); > + return ret; > + } > + > + dsi->encoder.possible_crtcs =3D mtk_drm_find_possible_crtc_by_com= p(drm, dsi->host.dev); > + > + ret =3D drm_bridge_attach(&dsi->encoder, &dsi->bridge, NULL, > + DRM_BRIDGE_ATTACH_NO_CONNECTOR); > + if (ret) > + goto err_cleanup_encoder; > + > + dsi->connector =3D drm_bridge_connector_init(drm, &dsi->encoder); > + if (IS_ERR(dsi->connector)) { > + DRM_ERROR("Unable to create bridge connector\n"); > + ret =3D PTR_ERR(dsi->connector); > + goto err_cleanup_encoder; > + } > + drm_connector_attach_encoder(dsi->connector, &dsi->encoder); > + > + return 0; > + > +err_cleanup_encoder: > + drm_encoder_cleanup(&dsi->encoder); > + return ret; > +} > + > +static int mtk_dsi_bind(struct device *dev, struct device *master, void = *data) > +{ > + int ret; > + struct drm_device *drm =3D data; > + struct mtk_dsi *dsi =3D dev_get_drvdata(dev); > + > + ret =3D mtk_dsi_encoder_init(drm, dsi); > + if (ret) > + return ret; > + > + return device_reset_optional(dev); > +} > + > +static void mtk_dsi_unbind(struct device *dev, struct device *master, > + void *data) > +{ > + struct mtk_dsi *dsi =3D dev_get_drvdata(dev); > + > + drm_encoder_cleanup(&dsi->encoder); > +} > + > +static const struct component_ops mtk_dsi_component_ops =3D { > + .bind =3D mtk_dsi_bind, > + .unbind =3D mtk_dsi_unbind, > +}; > + > static int mtk_dsi_host_attach(struct mipi_dsi_host *host, > struct mipi_dsi_device *device) > { > struct mtk_dsi *dsi =3D host_to_dsi(host); > + struct device *dev =3D host->dev; > + int ret; > > dsi->lanes =3D device->lanes; > dsi->format =3D device->format; > dsi->mode_flags =3D device->mode_flags; > + dsi->next_bridge =3D devm_drm_of_get_bridge(dev, dev->of_node, 0,= 0); > + if (IS_ERR(dsi->next_bridge)) > + return PTR_ERR(dsi->next_bridge); > + > + drm_bridge_add(&dsi->bridge); > + > + ret =3D component_add(host->dev, &mtk_dsi_component_ops); > + if (ret) { > + DRM_ERROR("failed to add dsi_host component: %d\n", ret); > + drm_bridge_remove(&dsi->bridge); > + return ret; > + } > > return 0; > } > > +static int mtk_dsi_host_detach(struct mipi_dsi_host *host, > + struct mipi_dsi_device *device) > +{ > + struct mtk_dsi *dsi =3D host_to_dsi(host); > + > + component_del(host->dev, &mtk_dsi_component_ops); > + drm_bridge_remove(&dsi->bridge); > + return 0; > +} > + > static void mtk_dsi_wait_for_idle(struct mtk_dsi *dsi) > { > int ret; > @@ -938,73 +1021,14 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_d= si_host *host, > > static const struct mipi_dsi_host_ops mtk_dsi_ops =3D { > .attach =3D mtk_dsi_host_attach, > + .detach =3D mtk_dsi_host_detach, > .transfer =3D mtk_dsi_host_transfer, > }; > > -static int mtk_dsi_encoder_init(struct drm_device *drm, struct mtk_dsi *= dsi) > -{ > - int ret; > - > - ret =3D drm_simple_encoder_init(drm, &dsi->encoder, > - DRM_MODE_ENCODER_DSI); > - if (ret) { > - DRM_ERROR("Failed to encoder init to drm\n"); > - return ret; > - } > - > - dsi->encoder.possible_crtcs =3D mtk_drm_find_possible_crtc_by_com= p(drm, dsi->host.dev); > - > - ret =3D drm_bridge_attach(&dsi->encoder, &dsi->bridge, NULL, > - DRM_BRIDGE_ATTACH_NO_CONNECTOR); > - if (ret) > - goto err_cleanup_encoder; > - > - dsi->connector =3D drm_bridge_connector_init(drm, &dsi->encoder); > - if (IS_ERR(dsi->connector)) { > - DRM_ERROR("Unable to create bridge connector\n"); > - ret =3D PTR_ERR(dsi->connector); > - goto err_cleanup_encoder; > - } > - drm_connector_attach_encoder(dsi->connector, &dsi->encoder); > - > - return 0; > - > -err_cleanup_encoder: > - drm_encoder_cleanup(&dsi->encoder); > - return ret; > -} > - > -static int mtk_dsi_bind(struct device *dev, struct device *master, void = *data) > -{ > - int ret; > - struct drm_device *drm =3D data; > - struct mtk_dsi *dsi =3D dev_get_drvdata(dev); > - > - ret =3D mtk_dsi_encoder_init(drm, dsi); > - if (ret) > - return ret; > - > - return device_reset_optional(dev); > -} > - > -static void mtk_dsi_unbind(struct device *dev, struct device *master, > - void *data) > -{ > - struct mtk_dsi *dsi =3D dev_get_drvdata(dev); > - > - drm_encoder_cleanup(&dsi->encoder); > -} > - > -static const struct component_ops mtk_dsi_component_ops =3D { > - .bind =3D mtk_dsi_bind, > - .unbind =3D mtk_dsi_unbind, > -}; > - > static int mtk_dsi_probe(struct platform_device *pdev) > { > struct mtk_dsi *dsi; > struct device *dev =3D &pdev->dev; > - struct drm_panel *panel; > struct resource *regs; > int irq_num; > int ret; > @@ -1021,19 +1045,6 @@ static int mtk_dsi_probe(struct platform_device *p= dev) > return ret; > } > > - ret =3D drm_of_find_panel_or_bridge(dev->of_node, 0, 0, > - &panel, &dsi->next_bridge); > - if (ret) > - goto err_unregister_host; > - > - if (panel) { > - dsi->next_bridge =3D devm_drm_panel_bridge_add(dev, panel= ); > - if (IS_ERR(dsi->next_bridge)) { > - ret =3D PTR_ERR(dsi->next_bridge); > - goto err_unregister_host; > - } > - } > - > dsi->driver_data =3D of_device_get_match_data(dev); > > dsi->engine_clk =3D devm_clk_get(dev, "engine"); > @@ -1098,14 +1109,6 @@ static int mtk_dsi_probe(struct platform_device *p= dev) > dsi->bridge.of_node =3D dev->of_node; > dsi->bridge.type =3D DRM_MODE_CONNECTOR_DSI; > > - drm_bridge_add(&dsi->bridge); > - > - ret =3D component_add(&pdev->dev, &mtk_dsi_component_ops); > - if (ret) { > - dev_err(&pdev->dev, "failed to add component: %d\n", ret)= ; > - goto err_unregister_host; > - } > - > return 0; > > err_unregister_host: > @@ -1118,8 +1121,6 @@ static int mtk_dsi_remove(struct platform_device *p= dev) > struct mtk_dsi *dsi =3D platform_get_drvdata(pdev); > > mtk_output_dsi_disable(dsi); > - drm_bridge_remove(&dsi->bridge); > - component_del(&pdev->dev, &mtk_dsi_component_ops); > mipi_dsi_host_unregister(&dsi->host); > > return 0; > -- > 2.33.1 >