From patchwork Mon Nov 22 06:52:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 1782 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id E3B3B3F15A for ; Mon, 22 Nov 2021 07:53:31 +0100 (CET) Received: by mail-pl1-f200.google.com with SMTP id s16-20020a170902ea1000b00142728c2ccasf6944510plg.23 for ; Sun, 21 Nov 2021 22:53:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1637564010; cv=pass; d=google.com; s=arc-20160816; b=NetrxK8VJvbCN3BRaFsdW7uarU3sB6tzembPOzfnZcrME6D94ixbs9AGHosOEaxjzc QmG+zG+/oFhUlcvfmikYNkyAAlIatACG1ozeAQ35J1ZnneZP4QF8u4MmkcRC9yo4u7+J 2Vev0EbKxrMsyQ1+bnpJdLLJLoUlBTRCJR1spBYA7TLq7Dl6GQKGx9+MXCrbjopQftP1 xMxENHz+vdcilK9EhYgxN6sLwpfXSWKo/IwvqQj5NWwRuLDLWrVbJT5AawbFHwphLMRN XNLNWDB54qrDaVFY+6+bnJ3XL2W5mjy/96ymleNa1EBykfWfYvft3DshQV5DJzLprI87 6IQQ== 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=hlv4rTIb90pDxzFMwdeDfPLDEaVdSSwTYp+eifycsok=; b=cn+RXh/Wwz8+M6yIzwBhtqG+jXWaGaCqxsJTW7LRwBQgFqjvFV6gYFXxbV9Am8SIfk jZPjs/geNS55ynwAc+G8nBN1BW2q1tOHJuj+j3mGAD1WZTIfdj0BR/Woeh5A8atNvat8 Y3A+Z0ueS3lAcAfjQWjMQRk4msh4MdaW/ruq5y8/sYYZIDf36b/giNZ5wVfOYoAoPrys 0tbL1jcbU0hIdKRNQG3iRohNTTnXdbEKLvJI+Joo5htYZnV3ocd8W5bc9HLQZ2yw+OAo YTsH2W+XFncfpKBVB3kxqxkPj7IBt2wV6E+man1JnP3zcBFZA4NC13EXngyYFLaTFgS8 VN5g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QPVgrYGL; 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=hlv4rTIb90pDxzFMwdeDfPLDEaVdSSwTYp+eifycsok=; b=fkPbfmkkNkseWmaTwAnUu0kUJ8R7zuDC0qimXSoCAz1eLyGbaVs05HH7bIxWUogpom 4m7WAvUsWiF5u4CS6phV9jgSe2bdb9irAH2o2HsMCQGAslO2r0A9NwxYimSG8f84ysPr Ypx3vqGn8EX+YtkhMQcsDCtIUUXvXpfaRTrYk= 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=hlv4rTIb90pDxzFMwdeDfPLDEaVdSSwTYp+eifycsok=; b=EKrnWl1NUZtHdvWjcJXrq5X3AdkZWPz09EO/vqWKmfZfVCYdF1N+XhpX3V+ArY2qnP 8HdZUszYrs6XJSdf18o3iyxxcU7U0tTLaaS+BTU2pj9e44CBrMtN/dHkG64e4J31FL4i qEUTQJT9BaBvVNIx6sMlLez4Q1nqJrRp6E9PdhcVHjNvQcP5SVJYabzWCH+jbHHwVcWY RvoB+4l8AyLhLhlE6m0cnC6HTy/cGhpVGMakejHfe+8JZpl2ED9sn+a6/Qfr0dXwplpE KtvqJftC3uTlAko/6N80lEKuO/3ou9fgTYtS+Bor0WLqwDhkdTWjMmkkjqmiPZ5k3HTv dNWw== X-Gm-Message-State: AOAM533K/KH/cEpoxhzTX/kMCLQwWqGVVCmgT3yhJ+P6yKGdGnPokXks dsK44TgSidK+yVGsnoGtxMFYu8K7 X-Google-Smtp-Source: ABdhPJxot2s/HMLHQ2BLHa0idHFg4ymRfT0P4hyNhYeFEtefRe9hqCOGEAvvoXL/tFO0AfGwH+ug+Q== X-Received: by 2002:a17:90b:4b83:: with SMTP id lr3mr28508805pjb.98.1637564010713; Sun, 21 Nov 2021 22:53:30 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:e749:: with SMTP id p9ls4023366plf.6.gmail; Sun, 21 Nov 2021 22:53:30 -0800 (PST) X-Received: by 2002:a17:902:7616:b0:143:a8cd:ef0 with SMTP id k22-20020a170902761600b00143a8cd0ef0mr98651234pll.48.1637564009932; Sun, 21 Nov 2021 22:53:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637564009; cv=none; d=google.com; s=arc-20160816; b=uSfyUwJNTRjZDUHOMKwlIZx6wrPSbZrA+F9Mv/HkCy8AHXgXNr6yejTBDLT0kUEX/c P1Yy1hxN68gECqSNp/N81RlSxSKy3heeLH9UXZ8q5+2ZMdcG+QmBedvgQCS154lng+pU TIo7FJ3ICzrIUvhGqDWsrWDz2k9w1BmK5Ybcoemxal1nEvry38tRejTxE/yQxEke0Nyp tnPiUZhUB+4W64ZFzNZvowMD5I5PA9SirTSdxXe2TKbO8T3d/rk38qkMuRN80xoT0BL7 sV4pdHis/b0qTycN5VBUZFURaEdsYPaIYfXkSo3zHIMkTy0c1cvIupwoOaj3ftIBpr2S PL7A== 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=CqcHDPI5j3BreTYZLwb22+vjVwocrgSYWGCGb32eVhw=; b=q6sIN5C92zdAdcpPlIYAgLgbkDOVnwP3ie5jYlF5+Zt5rL79GkrU02H3QUNEY6GM/3 vQVZZCpjMVPDl0NMP/rEluLq0J1qsPup8VlQlk1nFwN0lmpfUY4sC83i74KpVly289Vg XTgVKLOz5nmCNkgoABdM9hYpdtsSgLk+Hzltvgo7UUeUUAz5gOJ853PaLaektMo/OE2R 1YsNTB48w8QKWiphWIaRxbjllD0E5eW8U+uvYLF7DFgeOyoCBlmM40DLGoKh6bgdyO+N sNIAWXv7KeyOoWiO0tnlN6fXWIHtTWBEv1tNro/1HfmZxXuRxetKfksCxwsMd7+YrvMg CyxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=QPVgrYGL; 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 l3sor4057770plg.46.2021.11.21.22.53.29 for (Google Transport Security); Sun, 21 Nov 2021 22:53:29 -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:903:2091:b0:142:8567:e794 with SMTP id d17-20020a170903209100b001428567e794mr105544020plc.50.1637564009666; Sun, 21 Nov 2021 22:53:29 -0800 (PST) Received: from localhost.localdomain ([2405:201:c00a:a0a9:eed6:c913:819a:3850]) by smtp.gmail.com with ESMTPSA id a8sm7935904pfv.176.2021.11.21.22.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Nov 2021 22:53:29 -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 v5 2/7] drm: sun4i: dsi: Add component only once DSI device attached Date: Mon, 22 Nov 2021 12:22:18 +0530 Message-Id: <20211122065223.88059-3-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211122065223.88059-1-jagan@amarulasolutions.com> References: <20211122065223.88059-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=QPVgrYGL; 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 v5: - new patch drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c | 119 +++++++++++++------------ 1 file changed, 60 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..43d9c9e5198d 100644 --- a/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c +++ b/drivers/gpu/drm/sun4i/sun6i_mipi_dsi.c @@ -959,11 +959,62 @@ 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); + int ret; if (IS_ERR(panel)) return PTR_ERR(panel); @@ -973,6 +1024,13 @@ static int sun6i_dsi_attach(struct mipi_dsi_host *host, dev_info(host->dev, "Attached device %s\n", device->name); + ret = component_add(dsi->dev, &sun6i_dsi_ops); + if (ret) { + dev_err(dsi->dev, "Couldn't register our component\n"); + mipi_dsi_host_unregister(&dsi->host); + return ret; + } + return 0; } @@ -984,6 +1042,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 +1101,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 +1182,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 +1197,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);