From patchwork Fri Dec 10 11:17:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 12695588 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 3A34AC433F5 for ; Fri, 10 Dec 2021 11:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tlfQbOfBYBE2ldUgk1l+xRVYNd2D30Oad0sirHDvMc4=; b=GDWoOdYgrAaJoH /Db2IJMWgM2Y5VpFmv5Xddli4pyV7szfb2Jn5s6eau/3aUWL9MJCxrhFH6L/r+AVzh21F8gYsAliL +DBITil1Le0r4Cawmu7P4kyw4CLpnUMeBdear/JlBjqFAF1YPhOQBpRBMm/eiz9LzMfXNOWNeEKJI MGV5ZOQmN4hqwuWMlZ/uI+Z7KZiFGeNaFKLPfRFN4ujCjCNTpwwDg7wteUQ3TQiT06EiCedNc6Pwp t4495GA7CIPQ7AyidyDl8KF2FiVYgxTs+wATQQL3n/mv6lVG4ReG1z5WJEA5/ZTim/2GmTilvu8C9 zCj9xiP3D+dS7QIU5uYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvduV-001cCM-VK; Fri, 10 Dec 2021 11:17:56 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvduC-001c5r-Se for linux-arm-kernel@lists.infradead.org; Fri, 10 Dec 2021 11:17:38 +0000 Received: by mail-pj1-x1029.google.com with SMTP id np3so6603686pjb.4 for ; Fri, 10 Dec 2021 03:17:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TqiplFeVk+BY4Qw9hiZLgYutFh3HymB4iR0Knju+k4M=; b=hc5MSWMSmWihwCW9f7LVkiPvI2cAZobPX13gbbARWCsv+yFWJb9+byA455H+n0HLEu zJCHuzFurAX3JI5eChIJY4GmqkbUfsTnPf5l7jPAwfpHbeoGFAPQgNHFsjIEHQ4wk9R1 rQEXYZXYddbgHX3NIMH2vzzaAQzZ3NH3uqPYY= 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=TqiplFeVk+BY4Qw9hiZLgYutFh3HymB4iR0Knju+k4M=; b=rBl08Ox4x1MXau4+HuMee7wR1h/QlQVGw4nN82kjUBfms/xLTy76MrPZGzBkQbovX6 va2nfb3XbWQfIzcunvxPEqtb05FnoEmFagSmVgGrqllSNB8gmLnO/bdFDB2uaQkXVW0D rkcOH6NUjtXqXV8nMyd5CuHj1Gv0JA9QyIsAI2dee26vr5B2AO92ovM7eDDG1HrY/aDy 7EsuEf0xVHptRpy+ujZNZu5XXUBHUAd7UfaQDRAMEELoz18jZUBUBm715K3wWUs+9pa+ d8NwC99junfwdHBoQb/B2L3WETQE0+HmuuoWU5VaP2KjQYIwHvTXDRhAMKZEzZij8xnp W1zA== X-Gm-Message-State: AOAM530VWfQliqgLzFJueu+Lv1oE8JvK4pi4kArVWaHUrFD6VAwuys0P FhrSozi4wPh7tTiRMyRZDoke4g== X-Google-Smtp-Source: ABdhPJxbXk+Y+AkJpt/at6ihAaxF1I+qlvCRxQFcPf0bHCTVmGkPmNLdWe08qUGGXgwj8VMpqUh/TA== X-Received: by 2002:a17:90b:4ace:: with SMTP id mh14mr23232501pjb.164.1639135055791; Fri, 10 Dec 2021 03:17:35 -0800 (PST) Received: from localhost.localdomain ([2405:201:c00a:a0a9:c40f:36d4:b45d:731]) by smtp.gmail.com with ESMTPSA id qe12sm13125607pjb.29.2021.12.10.03.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 03:17:35 -0800 (PST) From: Jagan Teki To: Maxime Ripard , Chen-Yu Tsai , Laurent Pinchart , Neil Armstrong , Robert Foss , Sam Ravnborg Cc: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@googlegroups.com, linux-amarula@amarulasolutions.com, Jagan Teki Subject: [PATCH v6 2/6] drm: sun4i: dsi: Add component only once DSI device attached Date: Fri, 10 Dec 2021 16:47:07 +0530 Message-Id: <20211210111711.2072660-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211210111711.2072660-1-jagan@amarulasolutions.com> References: <20211210111711.2072660-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211210_031736_963415_D6507BD3 X-CRM114-Status: GOOD ( 20.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Having component_add for running all drm bind callbacks returns error or unbound due to chain of DSI devices connected across bridge topology on a display pipeline. In a typical bridge oriented display pipeline where the host is connected to the bridge converter and that indeed connected to a panel. DRM => SUN6I DSI Host => Chipone ICN6211 => BananaPi Panel The bridge converter is looking for a panel to probe first and then attach the host. The host attach is looking for a bridge converter to probe and preserve bridge pointer, at this movement the host is trying to bind the all callbacks and one of the bind callback in the DSI host is trying to find the bridge using the bridge pointer in sun6i_dsi_attach call. chipone_probe().start drm_of_find_panel_or_bridge mipi_dsi_attach sun6i_dsi_attach drm_of_find_panel_or_bridge chipone_probe().done sun6i_dsi_probe().start mipi_dsi_host_register component_add sun6i_dsi_probe().done However, the movement when panel defers the probe, will make the bridge converter defer the host attach call which eventually found a NULL bridge pointer during DSI component bind callback. So, in order to prevent this scenario of binding invalid bridge, wait for DSI devices on the pipeline to probe first and start the binding process by moving component_add in host probe to attach call. chipone_probe().start drm_of_find_panel_or_bridge mipi_dsi_attach sun6i_dsi_attach drm_of_find_panel_or_bridge component_add chipone_probe().done sun6i_dsi_probe().start mipi_dsi_host_register sun6i_dsi_probe().done Signed-off-by: Jagan Teki --- Changes for v6: - none Changes for v5: - new patch drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 120 +++++++++++++------------ 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c index 4bdcce8f1d84..9cf91dcac3f2 100644 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c @@ -959,11 +959,63 @@ static int sun6i_dsi_dcs_read(struct sun6i_dsi *dsi, return 1; } +static int sun6i_dsi_bind(struct device *dev, struct device *master, + void *data) +{ + struct drm_device *drm = data; + struct sun6i_dsi *dsi = dev_get_drvdata(dev); + int ret; + + drm_encoder_helper_add(&dsi->encoder, + &sun6i_dsi_enc_helper_funcs); + ret = drm_simple_encoder_init(drm, &dsi->encoder, + DRM_MODE_ENCODER_DSI); + if (ret) { + dev_err(dsi->dev, "Couldn't initialise the DSI encoder\n"); + return ret; + } + dsi->encoder.possible_crtcs = BIT(0); + + drm_connector_helper_add(&dsi->connector, + &sun6i_dsi_connector_helper_funcs); + ret = drm_connector_init(drm, &dsi->connector, + &sun6i_dsi_connector_funcs, + DRM_MODE_CONNECTOR_DSI); + if (ret) { + dev_err(dsi->dev, + "Couldn't initialise the DSI connector\n"); + goto err_cleanup_connector; + } + + drm_connector_attach_encoder(&dsi->connector, &dsi->encoder); + + return 0; + +err_cleanup_connector: + drm_encoder_cleanup(&dsi->encoder); + return ret; +} + +static void sun6i_dsi_unbind(struct device *dev, struct device *master, + void *data) +{ + struct sun6i_dsi *dsi = dev_get_drvdata(dev); + + drm_encoder_cleanup(&dsi->encoder); +} + +static const struct component_ops sun6i_dsi_ops = { + .bind = sun6i_dsi_bind, + .unbind = sun6i_dsi_unbind, +}; + static int sun6i_dsi_attach(struct mipi_dsi_host *host, struct mipi_dsi_device *device) { struct sun6i_dsi *dsi = host_to_sun6i_dsi(host); struct drm_panel *panel = of_drm_find_panel(device->dev.of_node); + struct device *dev = dsi->dev; + int ret; if (IS_ERR(panel)) return PTR_ERR(panel); @@ -973,6 +1025,13 @@ static int sun6i_dsi_attach(struct mipi_dsi_host *host, dev_info(host->dev, "Attached device %s\n", device->name); + ret = component_add(dev, &sun6i_dsi_ops); + if (ret) { + dev_err(dev, "Couldn't register our component\n"); + mipi_dsi_host_unregister(&dsi->host); + return ret; + } + return 0; } @@ -984,6 +1043,8 @@ static int sun6i_dsi_detach(struct mipi_dsi_host *host, dsi->panel = NULL; dsi->device = NULL; + component_del(dsi->dev, &sun6i_dsi_ops); + return 0; } @@ -1041,56 +1102,6 @@ static const struct regmap_config sun6i_dsi_regmap_config = { .name = "mipi-dsi", }; -static int sun6i_dsi_bind(struct device *dev, struct device *master, - void *data) -{ - struct drm_device *drm = data; - struct sun6i_dsi *dsi = dev_get_drvdata(dev); - int ret; - - drm_encoder_helper_add(&dsi->encoder, - &sun6i_dsi_enc_helper_funcs); - ret = drm_simple_encoder_init(drm, &dsi->encoder, - DRM_MODE_ENCODER_DSI); - if (ret) { - dev_err(dsi->dev, "Couldn't initialise the DSI encoder\n"); - return ret; - } - dsi->encoder.possible_crtcs = BIT(0); - - drm_connector_helper_add(&dsi->connector, - &sun6i_dsi_connector_helper_funcs); - ret = drm_connector_init(drm, &dsi->connector, - &sun6i_dsi_connector_funcs, - DRM_MODE_CONNECTOR_DSI); - if (ret) { - dev_err(dsi->dev, - "Couldn't initialise the DSI connector\n"); - goto err_cleanup_connector; - } - - drm_connector_attach_encoder(&dsi->connector, &dsi->encoder); - - return 0; - -err_cleanup_connector: - drm_encoder_cleanup(&dsi->encoder); - return ret; -} - -static void sun6i_dsi_unbind(struct device *dev, struct device *master, - void *data) -{ - struct sun6i_dsi *dsi = dev_get_drvdata(dev); - - drm_encoder_cleanup(&dsi->encoder); -} - -static const struct component_ops sun6i_dsi_ops = { - .bind = sun6i_dsi_bind, - .unbind = sun6i_dsi_unbind, -}; - static int sun6i_dsi_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1172,16 +1183,8 @@ static int sun6i_dsi_probe(struct platform_device *pdev) goto err_unprotect_clk; } - ret = component_add(&pdev->dev, &sun6i_dsi_ops); - if (ret) { - dev_err(dev, "Couldn't register our component\n"); - goto err_remove_dsi_host; - } - return 0; -err_remove_dsi_host: - mipi_dsi_host_unregister(&dsi->host); err_unprotect_clk: clk_rate_exclusive_put(dsi->mod_clk); err_attach_clk: @@ -1195,7 +1198,6 @@ static int sun6i_dsi_remove(struct platform_device *pdev) struct device *dev = &pdev->dev; struct sun6i_dsi *dsi = dev_get_drvdata(dev); - component_del(&pdev->dev, &sun6i_dsi_ops); mipi_dsi_host_unregister(&dsi->host); clk_rate_exclusive_put(dsi->mod_clk);