From patchwork Tue Aug 29 07:32:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Ujfalusi X-Patchwork-Id: 9926811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46A5460380 for ; Tue, 29 Aug 2017 07:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35B5828722 for ; Tue, 29 Aug 2017 07:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2833F28889; Tue, 29 Aug 2017 07:47:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9DC0528722 for ; Tue, 29 Aug 2017 07:46:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33FAF6E36A; Tue, 29 Aug 2017 07:46:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 892 seconds by postgrey-1.35 at gabe; Tue, 29 Aug 2017 07:46:56 UTC Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id B14596E36A for ; Tue, 29 Aug 2017 07:46:56 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id v7T7W994003110; Tue, 29 Aug 2017 02:32:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1503991929; bh=qA9PFihZN0OIP9mWD487HCdo++wwNZpWXlFyMVZt0P4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=JAVZSgN2BXprQzMRLhNRwhSMcizMFCmiipEEuMTa76FKckIh+fKVRK+PZh64YWRVj NLTJ5geJ1rKjHxhY7dCbACqHyNfz14rUR1YR4YysmBk/zT2l3UwmOricAQ/L081WjM FqI12zf1p9NR7gXppUMLAyxLSa0AI3J3aMM+YAH8= Received: from DLEE102.ent.ti.com (dlee102.ent.ti.com [157.170.170.32]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v7T7W4pv016474; Tue, 29 Aug 2017 02:32:04 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34; Tue, 29 Aug 2017 02:32:04 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend Transport; Tue, 29 Aug 2017 02:32:04 -0500 Received: from feketebors.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v7T7VsJb020217; Tue, 29 Aug 2017 02:32:02 -0500 From: Peter Ujfalusi To: , , Subject: [RFC 4/7] drm/omap: Separate the dssdevs array setup from the connect function Date: Tue, 29 Aug 2017 10:32:15 +0300 Message-ID: <20170829073218.11097-5-peter.ujfalusi@ti.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170829073218.11097-1-peter.ujfalusi@ti.com> References: <20170829073218.11097-1-peter.ujfalusi@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP In order to ease up on the logic, break the current code to gather the dssdevs: first get all available dssdevs, then call connect on each dssdev. As the last step remove the dssdevs which failed to connect from the available dssdev list. Signed-off-by: Peter Ujfalusi --- drivers/gpu/drm/omapdrm/omap_drv.c | 54 ++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_drv.c b/drivers/gpu/drm/omapdrm/omap_drv.c index b089604e871c..32dc0e88220f 100644 --- a/drivers/gpu/drm/omapdrm/omap_drv.c +++ b/drivers/gpu/drm/omapdrm/omap_drv.c @@ -162,34 +162,60 @@ static void omap_disconnect_dssdevs(struct drm_device *ddev) priv->num_dssdevs = 0; } -static int omap_connect_dssdevs(struct drm_device *ddev) +static void omap_collect_dssdevs(struct drm_device *ddev) { struct omap_drm_private *priv = ddev->dev_private; struct omap_dss_device *dssdev = NULL; - int r; + + for_each_dss_dev(dssdev) { + omap_dss_get_device(dssdev); + priv->dssdevs[priv->num_dssdevs++] = dssdev; + if (priv->num_dssdevs == ARRAY_SIZE(priv->dssdevs)) { + /* To balance the 'for_each_dss_dev' loop */ + omap_dss_put_device(dssdev); + break; + } + } +} + +static int omap_connect_dssdevs(struct drm_device *ddev) +{ + struct omap_drm_private *priv = ddev->dev_private; + u32 working = 0; + int r, i, j; if (!omapdss_stack_is_ready()) return -EPROBE_DEFER; - for_each_dss_dev(dssdev) { + omap_collect_dssdevs(ddev); + + for (i = 0; i < priv->num_dssdevs; i++) { + struct omap_dss_device *dssdev = priv->dssdevs[i]; + r = dssdev->driver->connect(dssdev); - if (r == -EPROBE_DEFER) { - omap_dss_put_device(dssdev); + if (r == -EPROBE_DEFER) goto cleanup; - } else if (r) { + else if (r) dev_warn(dssdev->dev, "could not connect display: %s\n", - dssdev->name); + dssdev->name); + else + working |= BIT(i); + } + + /* Remove the dssdevs if their connect failed */ + j = 0; + for (i = 0; i < priv->num_dssdevs; i++) { + if (working & BIT(i)) { + if (j != i) + priv->dssdevs[j] = priv->dssdevs[i]; + j++; } else { - omap_dss_get_device(dssdev); - priv->dssdevs[priv->num_dssdevs++] = dssdev; - if (priv->num_dssdevs == ARRAY_SIZE(priv->dssdevs)) { - /* To balance the 'for_each_dss_dev' loop */ - omap_dss_put_device(dssdev); - break; - } + omap_dss_put_device(priv->dssdevs[i]); } } + priv->num_dssdevs = j; + return 0; cleanup: