From patchwork Thu Mar 9 10:05:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 9614393 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 2A6F960417 for ; Fri, 10 Mar 2017 00:38:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A40B286DC for ; Fri, 10 Mar 2017 00:38:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AC26286E6; Fri, 10 Mar 2017 00:38:18 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 0E4D0286DC for ; Fri, 10 Mar 2017 00:38:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A5566E14E; Fri, 10 Mar 2017 00:38:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from wens.csie.org (mirror2.csie.ntu.edu.tw [140.112.30.76]) by gabe.freedesktop.org (Postfix) with ESMTPS id EE7BC6EBA5 for ; Thu, 9 Mar 2017 10:05:41 +0000 (UTC) Received: by wens.csie.org (Postfix, from userid 1000) id 6A2F05FE39; Thu, 9 Mar 2017 18:05:35 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , David Airlie Subject: [PATCH 09/11] drm/sun4i: Support two display pipelines Date: Thu, 9 Mar 2017 18:05:32 +0800 Message-Id: <20170309100534.14023-10-wens@csie.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170309100534.14023-1-wens@csie.org> References: <20170309100534.14023-1-wens@csie.org> X-Mailman-Approved-At: Fri, 10 Mar 2017 00:38:14 +0000 Cc: linux-arm-kernel@lists.infradead.org, Chen-Yu Tsai , linux-sunxi@googlegroups.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.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: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some Allwinner SoCs have two display pipelines (frontend -> backend -> tcon). Previously we only supported one pipeline. This patch extends the current driver to support two. It extends the tcon and backend pointers in sun4i_drv into arrays, and makes the related bind functions store the pointer into said arrays based on the id fetched from the device tree. In the case of the tcons, it falls back to a first come order if no encoders that can be used for differentiating the tcons are defined. The driver's depth-first traversal of the of graph, coupled with the increasing address ordering of the of graph endpoints, and the fact that tcon0 should always be enabled for the tcon/encoder mux to be accessible, means that tcon1 would always come after tcon0. Assignment of the device structure into sun4i_drv is moved to the end of the bind function, when all possible error checks have passed. This patch also drops a trailing 0 in one of the backend probe messages. Signed-off-by: Chen-Yu Tsai --- drivers/gpu/drm/sun4i/sun4i_backend.c | 9 +++++++-- drivers/gpu/drm/sun4i/sun4i_drv.c | 2 +- drivers/gpu/drm/sun4i/sun4i_drv.h | 6 ++++-- drivers/gpu/drm/sun4i/sun4i_tcon.c | 25 +++++++++++++++++-------- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c index f3c92d54c8e4..8d22efd5a9cc 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.c +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c @@ -350,12 +350,15 @@ static int sun4i_backend_bind(struct device *dev, struct device *master, if (!backend) return -ENOMEM; dev_set_drvdata(dev, backend); - drv->backend = backend; backend->id = sun4i_backend_of_get_id(dev->of_node); if (backend->id < 0) return backend->id; + /* We only support SUN4I_DRM_MAX_PIPELINES number of backends */ + if (backend->id >= SUN4I_DRM_MAX_PIPELINES) + return -EINVAL; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); regs = devm_ioremap_resource(dev, res); if (IS_ERR(regs)) @@ -364,7 +367,7 @@ static int sun4i_backend_bind(struct device *dev, struct device *master, backend->regs = devm_regmap_init_mmio(dev, regs, &sun4i_backend_regmap_config); if (IS_ERR(backend->regs)) { - dev_err(dev, "Couldn't create the backend0 regmap\n"); + dev_err(dev, "Couldn't create the backend regmap\n"); return PTR_ERR(backend->regs); } @@ -413,6 +416,8 @@ static int sun4i_backend_bind(struct device *dev, struct device *master, } } + drv->backend[backend->id] = backend; + /* Reset the registers */ for (i = 0x800; i < 0x1000; i += 4) regmap_write(backend->regs, i, 0); diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c index 767bbadcc85d..c15ecb8343d7 100644 --- a/drivers/gpu/drm/sun4i/sun4i_drv.c +++ b/drivers/gpu/drm/sun4i/sun4i_drv.c @@ -271,7 +271,7 @@ static int sun4i_drv_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; int i, count = 0; - for (i = 0;; i++) { + for (i = 0; i < SUN4I_DRM_MAX_PIPELINES; i++) { struct device_node *pipeline = of_parse_phandle(np, "allwinner,pipelines", i); diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.h b/drivers/gpu/drm/sun4i/sun4i_drv.h index 5df50126ff52..ec1c08af47e1 100644 --- a/drivers/gpu/drm/sun4i/sun4i_drv.h +++ b/drivers/gpu/drm/sun4i/sun4i_drv.h @@ -16,9 +16,11 @@ #include #include +#define SUN4I_DRM_MAX_PIPELINES 2 + struct sun4i_drv { - struct sun4i_backend *backend; - struct sun4i_tcon *tcon; + struct sun4i_backend *backend[SUN4I_DRM_MAX_PIPELINES]; + struct sun4i_tcon *tcon[SUN4I_DRM_MAX_PIPELINES]; struct drm_fbdev_cma *fbdev; }; diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c index b774c9a50c55..7749c3133f38 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -532,7 +532,6 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, if (!tcon) return -ENOMEM; dev_set_drvdata(dev, tcon); - drv->tcon = tcon; tcon->drm = drm; tcon->dev = dev; tcon->quirks = of_device_get_match_data(dev); @@ -540,14 +539,22 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, /* This can fail if the DT does not have any downstream encoders. */ tcon->id = sun4i_tcon_of_get_id(dev->of_node); if (tcon->id < 0) { - /* - * TODO We currently support only 1 TCON, so we can - * safely set this to 0. This should be revisited - * when we add support for multiple pipelines. - */ - tcon->id = 0; + int i; + + /* find the first empty tcon in sun4i_drv */ + for (i = 0; i < SUN4I_DRM_MAX_PIPELINES; i++) + if (!drv->tcon[i]) + tcon->id = i; + + /* bail out if that failed */ + if (tcon->id < 0) + return tcon->id; } + /* We only support SUN4I_DRM_MAX_PIPELINES number of tcons */ + if (tcon->id >= SUN4I_DRM_MAX_PIPELINES) + return -EINVAL; + tcon->lcd_rst = devm_reset_control_get(dev, "lcd"); if (IS_ERR(tcon->lcd_rst)) { dev_err(dev, "Couldn't get our reset line\n"); @@ -588,7 +595,7 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, goto err_free_dotclock; } - tcon->crtc = sun4i_crtc_init(drm, drv->backend, tcon); + tcon->crtc = sun4i_crtc_init(drm, drv->backend[tcon->id], tcon); if (IS_ERR(tcon->crtc)) { dev_err(dev, "Couldn't create our CRTC\n"); ret = PTR_ERR(tcon->crtc); @@ -599,6 +606,8 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, if (ret < 0) goto err_free_clocks; + drv->tcon[tcon->id] = tcon; + return 0; err_free_dotclock: