From patchwork Tue Jan 21 10:14:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yannick FERTRE X-Patchwork-Id: 11343429 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D165B6C1 for ; Tue, 21 Jan 2020 10:15:23 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id AF23024654 for ; Tue, 21 Jan 2020 10:15:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jeMuTaf2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="wduEk0Lv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF23024654 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=aSG8A3XC7k0pImFj510UOGZCKpYIMNB4KTdd3PoS95o=; b=jeMuTaf2oX9oIO c+UX5hKfGTX0sXVJ2snrSh0Rh/nTvO/TARDe+stOU27ccGDKHVGECC913tkDRrAwFmgb8yRENqYCe pxu8QHb3k69MyqdLw5XRbgnSAyLC+2yLd4p+tI1ESBHLiSnIeVSpcm/PFtuN2Pn2qblKIjWI8i3kb ywwlykYWk2fWYWwkVeRiHuDL/Dm75dKBBjR/+rkvS41sKxt3zGWDXO4sSI1GmZfmdzY2Xy/ONkbIv MWFNqf+/7KGs0ukxx+4DXyUo6ONm8jtlnC1kdrCfe7MZA+Ju1MNnO2ZMclQF9P0mGTH2Ovil6cSZk /Znh8jyy9k8lgvUb0CkA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1itqZ5-0007Jj-5e; Tue, 21 Jan 2020 10:15:19 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1itqYT-0005bK-Nl for linux-arm-kernel@lists.infradead.org; Tue, 21 Jan 2020 10:14:46 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 00LA7oZc022161; Tue, 21 Jan 2020 11:14:36 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=STMicroelectronics; bh=k5qJRWoSgLmpSjylS2Utl+lUx5HEle5o+YTZ31pLcBY=; b=wduEk0LvIblC2IcFcHYwE7nIdG53pbfzZg6CUixJoMHvLCga8LLYZHhVlTBWnnQnTYri KzCSJ4cKGDzV5Y+4Dvw4LniveJQjHSWRtvMyfdLC0JoXYi5nAkE3sdMaRlKF3dmc34Rd EVjTFgmnhvIw1pcfNmh1cIW0OQf/ApBZTe61MP6rKG7R1TUzMXo+SnxvHwcJ0r5DR2Tk 1UZJo8+zw8HQNlAenjGRnyb+EnHKQdePG0DEXNUSTzIEFtZsW4OYOdLtKcUrZ+Z00RRR pxqwNi11kGkQEgNca1CGmj6BXh0+AB5lRCRGr3MfC6k75GAyXTcuJqGwKyAvZmaqcfCh wQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2xkrc4x3h0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Jan 2020 11:14:36 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1431510002A; Tue, 21 Jan 2020 11:14:36 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag6node1.st.com [10.75.127.16]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 04B062B1874; Tue, 21 Jan 2020 11:14:36 +0100 (CET) Received: from localhost (10.75.127.44) by SFHDAG6NODE1.st.com (10.75.127.16) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 21 Jan 2020 11:14:35 +0100 From: Yannick Fertre To: Yannick Fertre , Philippe Cornu , Benjamin Gaignard , David Airlie , Daniel Vetter , Maxime Coquelin , Alexandre Torgue , , , , Subject: [PATCH] drm/stm: ltdc: check number of endpoints Date: Tue, 21 Jan 2020 11:14:33 +0100 Message-ID: <1579601673-7111-1-git-send-email-yannick.fertre@st.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG7NODE3.st.com (10.75.127.21) To SFHDAG6NODE1.st.com (10.75.127.16) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-01-21_02:2020-01-21, 2020-01-21 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200121_021442_118744_11C97CE5 X-CRM114-Status: GOOD ( 16.96 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [62.209.51.94 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Number of endpoints could exceed the fix value MAX_ENDPOINTS(2). Instead of increase simply this value, the number of endpoint could be read from device tree. Load sequence has been a little rework to take care of several panel or bridge which can be connected/disconnected or enable/disable. Signed-off-by: Yannick Fertré Acked-by: Philippe Cornu --- drivers/gpu/drm/stm/ltdc.c | 104 ++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c index c2815e8..dba8e7f 100644 --- a/drivers/gpu/drm/stm/ltdc.c +++ b/drivers/gpu/drm/stm/ltdc.c @@ -42,8 +42,6 @@ #define MAX_IRQ 4 -#define MAX_ENDPOINTS 2 - #define HWVER_10200 0x010200 #define HWVER_10300 0x010300 #define HWVER_20101 0x020101 @@ -1190,36 +1188,20 @@ int ltdc_load(struct drm_device *ddev) struct ltdc_device *ldev = ddev->dev_private; struct device *dev = ddev->dev; struct device_node *np = dev->of_node; - struct drm_bridge *bridge[MAX_ENDPOINTS] = {NULL}; - struct drm_panel *panel[MAX_ENDPOINTS] = {NULL}; + struct drm_bridge *bridge; + struct drm_panel *panel; struct drm_crtc *crtc; struct reset_control *rstc; struct resource *res; - int irq, ret, i, endpoint_not_ready = -ENODEV; + int irq, i, nb_endpoints; + int ret = -ENODEV; DRM_DEBUG_DRIVER("\n"); - /* Get endpoints if any */ - for (i = 0; i < MAX_ENDPOINTS; i++) { - ret = drm_of_find_panel_or_bridge(np, 0, i, &panel[i], - &bridge[i]); - - /* - * If at least one endpoint is -EPROBE_DEFER, defer probing, - * else if at least one endpoint is ready, continue probing. - */ - if (ret == -EPROBE_DEFER) - return ret; - else if (!ret) - endpoint_not_ready = 0; - } - - if (endpoint_not_ready) - return endpoint_not_ready; - - rstc = devm_reset_control_get_exclusive(dev, NULL); - - mutex_init(&ldev->err_lock); + /* Get number of endpoints */ + nb_endpoints = of_graph_get_endpoint_count(np); + if (!nb_endpoints) + return -ENODEV; ldev->pixel_clk = devm_clk_get(dev, "lcd"); if (IS_ERR(ldev->pixel_clk)) { @@ -1233,6 +1215,43 @@ int ltdc_load(struct drm_device *ddev) return -ENODEV; } + /* Get endpoints if any */ + for (i = 0; i < nb_endpoints; i++) { + ret = drm_of_find_panel_or_bridge(np, 0, i, &panel, &bridge); + + /* + * If at least one endpoint is -ENODEV, continue probing, + * else if at least one endpoint returned an error + * (ie -EPROBE_DEFER) then stop probing. + */ + if (ret == -ENODEV) + continue; + else if (ret) + goto err; + + if (panel) { + bridge = drm_panel_bridge_add_typed(panel, + DRM_MODE_CONNECTOR_DPI); + if (IS_ERR(bridge)) { + DRM_ERROR("panel-bridge endpoint %d\n", i); + ret = PTR_ERR(bridge); + goto err; + } + } + + if (bridge) { + ret = ltdc_encoder_init(ddev, bridge); + if (ret) { + DRM_ERROR("init encoder endpoint %d\n", i); + goto err; + } + } + } + + rstc = devm_reset_control_get_exclusive(dev, NULL); + + mutex_init(&ldev->err_lock); + if (!IS_ERR(rstc)) { reset_control_assert(rstc); usleep_range(10, 20); @@ -1268,7 +1287,6 @@ int ltdc_load(struct drm_device *ddev) } } - ret = ltdc_get_caps(ddev); if (ret) { DRM_ERROR("hardware identifier (0x%08x) not supported!\n", @@ -1278,27 +1296,6 @@ int ltdc_load(struct drm_device *ddev) DRM_DEBUG_DRIVER("ltdc hw version 0x%08x\n", ldev->caps.hw_version); - /* Add endpoints panels or bridges if any */ - for (i = 0; i < MAX_ENDPOINTS; i++) { - if (panel[i]) { - bridge[i] = drm_panel_bridge_add_typed(panel[i], - DRM_MODE_CONNECTOR_DPI); - if (IS_ERR(bridge[i])) { - DRM_ERROR("panel-bridge endpoint %d\n", i); - ret = PTR_ERR(bridge[i]); - goto err; - } - } - - if (bridge[i]) { - ret = ltdc_encoder_init(ddev, bridge[i]); - if (ret) { - DRM_ERROR("init encoder endpoint %d\n", i); - goto err; - } - } - } - crtc = devm_kzalloc(dev, sizeof(*crtc), GFP_KERNEL); if (!crtc) { DRM_ERROR("Failed to allocate crtc\n"); @@ -1331,8 +1328,8 @@ int ltdc_load(struct drm_device *ddev) return 0; err: - for (i = 0; i < MAX_ENDPOINTS; i++) - drm_panel_bridge_remove(bridge[i]); + for (i = 0; i < nb_endpoints; i++) + drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i); clk_disable_unprepare(ldev->pixel_clk); @@ -1341,11 +1338,14 @@ int ltdc_load(struct drm_device *ddev) void ltdc_unload(struct drm_device *ddev) { - int i; + struct device *dev = ddev->dev; + int nb_endpoints, i; DRM_DEBUG_DRIVER("\n"); - for (i = 0; i < MAX_ENDPOINTS; i++) + nb_endpoints = of_graph_get_endpoint_count(dev->of_node); + + for (i = 0; i < nb_endpoints; i++) drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i); pm_runtime_disable(ddev->dev);