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: 1802 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 8E5B03F15A for ; Fri, 10 Dec 2021 12:17:40 +0100 (CET) Received: by mail-pf1-f199.google.com with SMTP id x14-20020a627c0e000000b0049473df362dsf5470690pfc.12 for ; Fri, 10 Dec 2021 03:17:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1639135057; cv=pass; d=google.com; s=arc-20160816; b=vjpK/cCmITgBEan8vcC0M5pdGqYKixLcoBq5a+Ba+Vibe7rPi1c+xF6/pLXJJHKBe7 PeqTxig6sR1aiF6LFgF/cNa6alM8g1IF5hjoycU9eLLqcPntNTOxumsPN1QHuJvK1syM OPiguvMbgAQX1pAUDyeU70cH8trwI5KOIGPgxkybrUDIkk0rWPBCfJWV/avYtY/z1eK7 tyECnJQHWCU32285Fy0O6QA30MmEaXymbVGrvSukZOWNTEPLAxeJFCcG9R16nPwJm9Hl fku+bW8b3lxxgkEoMrxz89Z98XLbIwdb7sFuZjksunnBXni2bWIeZQSXgszN2Htt0Y0N KFsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=LG+h4KBtehl8P2aSUtHn4WoDezt7Q4lXIek/izZO10k=; b=gVpwKFrskKxsiwiRczdDKoUYZJa/+GwBGNNNqd4HiQ/RnMY1+BmJaQSym9i6ByDbvV XbpWyIi9og+Q9gKbq7gL9W4uoVkH3baAAmzsml3x9HNdKpPE0MwH9lKMiyb8OLhcil/t MzePW9jASf4afA6EhD8ytuOvv5iHSAnYVpxoy22N5paK3lEB12REiaCKJ04um0QWMJbJ hvF8+jGJPD/l17FnvA4/vAs/1d4yH5/MnMsZpqddloYvxArVcY46eImGElOKi1InZWLQ 21h6GEIC2LMmcoZUTnsmsfXZC0GvNGjUblAwbGXigGPVBLyWnL/oDZxD3kb0l0JL7gfz p/EA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=hc5MSWMS; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com 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:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=LG+h4KBtehl8P2aSUtHn4WoDezt7Q4lXIek/izZO10k=; b=DKHO8kHJlFcOvAXnqPjjnUG5vDZZOnMkSujY0udZbKUN6tUE6o9CHWlpkyeS4LfhDp kI6sbp2xjoYOGhZD/+4sXgcxCLjxwGMuQcffLp/98OCes26CCmj9VrRyp3EiHfFPQAYR yXzRMXhKPjzZrFVhX6Q2EPJMLL2z2h8NYdnuk= 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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=LG+h4KBtehl8P2aSUtHn4WoDezt7Q4lXIek/izZO10k=; b=FXoKzhca6rMgc+A2XF/xjwPxGgHy0UM8L5mzPIu8dPNHt4NzbajZXshMBbUYU5LKvG R3Gvp3L4MYepz1O8eU9KbqL6qWmqoofhmovlgsNXPJustbn3qaVISZrEBpZoMRsoX2/E 3HypOUIlC5KMgnitYfw0mEzKkaO07cuuLfjfdrjHxTLB9ctyVn/xeLDvAtOQwo5gR3Li K51oF3nRBm3bj5s1XzYMaki8WYai6Z2g9eP4MIxCeRlPzEAzfiByfVTsc42sbC+1dIr0 ikkIuengGB64x9+fJ1VYXR28llC8hgkkfk9n0FeVJ4sCeVmO5ek0iYdurUCwKyHwkNI1 X+/A== X-Gm-Message-State: AOAM533oZ2tt/LW++mYdFREO5SfJU6ybbYQq5PT73BXxsDqYbap3UWSd CAJaPqdRoifsCxWk199Gz+zgGqYC X-Google-Smtp-Source: ABdhPJzp35IuL14y8Q2v7MM1QFXIwKWVnIPa28bak/9FV4Kj3kB/5zWmkH6/eUQgG9yT31TE9chMpA== X-Received: by 2002:aa7:8105:0:b0:4a0:2f7c:81b with SMTP id b5-20020aa78105000000b004a02f7c081bmr17297601pfi.25.1639135056870; Fri, 10 Dec 2021 03:17:36 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:f687:: with SMTP id l7ls4798331plg.10.gmail; Fri, 10 Dec 2021 03:17:36 -0800 (PST) X-Received: by 2002:a17:90a:bb03:: with SMTP id u3mr23256806pjr.85.1639135056048; Fri, 10 Dec 2021 03:17:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639135056; cv=none; d=google.com; s=arc-20160816; b=dvYKBW8VeShdNGEEpecfUjQ+WBysc3xztTxsBcg8Jz3srkyHXueQ2K/IjMFd9n/faB 6bSuuiGTavEaMjOEXbgfuJvxgnAth7F1zdHswgfTMRHG5GY5D/pR402zO+ldyM2m1A0D PZ0wAU1Zfs71JwSotRDS+ajqIqFzm3DVVEhQU+BXO3Nn3Zc78ydX2A5bCwY0R9l0thS5 AxeDhLaWvhXjBBMDyVytejopJQ+peDD4EMCna/H78ZnI03VX8CfSDlv8BfOGBohl+9cH JXhW87ubOx85dyOFBEMYmpthmgQEC41lyEkWV1IvFMyZVlC6ec/u7Y+NeE3KrBqmtoMd 4c1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=TqiplFeVk+BY4Qw9hiZLgYutFh3HymB4iR0Knju+k4M=; b=OFQ2MInzZLtgD3GQk1bS9X3qffS9Nlt5Lga0VGkZWNkBjoI7XnS9KaNJGLfHNFHwU0 x+LVPmRnEFIcm8gun/z8Kv5+dKc30/RDeDGWzlGGcmOLTO/1hjdUbqLCpWO466LFkoIx 20TcF5/uhS1PgDdONrk4rUlzASd45afzzB03x7JLndmHXftxZaXjLNwm1nXpKEcFB1Mp px3vtSPIu88S/1ekoxdKg2qmjTMZFyUxJEcZy+1V3PKzPf6B00r6X3GCcVbVYfNyW7g5 GFuI7BCqJgG8VbObdKawF6iQ34+/XfGHNalVMGuR3wsWXg31FkaLsvpkK3RPE7Ng3UCK C9gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=hc5MSWMS; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id lp10sor2327623pjb.21.2021.12.10.03.17.36 for (Google Transport Security); Fri, 10 Dec 2021 03:17:36 -0800 (PST) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; 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-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=hc5MSWMS; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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);