From patchwork Thu Mar 9 10:05:31 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: 9614399 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 1E8C1604D9 for ; Fri, 10 Mar 2017 00:38:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11C36286DC for ; Fri, 10 Mar 2017 00:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06A5C286E6; Fri, 10 Mar 2017 00:38:24 +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 AFE59286DC for ; Fri, 10 Mar 2017 00:38:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 63B4C6ED44; Fri, 10 Mar 2017 00:38:16 +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 E188A6EBA4 for ; Thu, 9 Mar 2017 10:05:41 +0000 (UTC) Received: by wens.csie.org (Postfix, from userid 1000) id 665CD5FE22; Thu, 9 Mar 2017 18:05:35 +0800 (CST) From: Chen-Yu Tsai To: Maxime Ripard , David Airlie Subject: [PATCH 08/11] drm/sun4i: Fetch TCON ID from device tree Date: Thu, 9 Mar 2017 18:05:31 +0800 Message-Id: <20170309100534.14023-9-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 2 display pipelines, as in 2 of each components, including the frontend, backend, TCON, and any other extras. As the backend and TCON are always paired together and form the CRTC, we need to know which backend or TCON we are currently probing, so we can pair them when initializing the CRTC. This patch figures out the TCON's ID from the device tree and stores it in the TCON's data structure. It does this by looking at the "reg" property of any remote endpoints connected to the TCON's output port, except LCD panels or external bridges on the RGB interface. If none are found, it assumes the system only has 1 TCON. Signed-off-by: Chen-Yu Tsai --- drivers/gpu/drm/sun4i/sun4i_tcon.c | 60 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/sun4i/sun4i_tcon.h | 2 ++ 2 files changed, 62 insertions(+) diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c index 3ced0b1cef6e..b774c9a50c55 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -471,6 +471,55 @@ struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node) return of_drm_find_bridge(remote) ?: ERR_PTR(-EPROBE_DEFER); } +/* + * The tcon can output video to an tv or hdmi encoder. When there are 2 + * tcons, on older SoCs with DE 1.0, either tcon can be muxed to the + * encoder. + * + * This relationship within the display pipeline is encoded in the device + * tree with of_graph. Here we use it to figure out which tcon, if there + * are 2 or more, we are currently probing. The number would be in the + * "reg" property of the downstream input port endpoint. + */ +static int sun4i_tcon_of_get_id(struct device_node *node) +{ + struct device_node *port, *ep; + int ret = -EINVAL; + + /* output is port 1 */ + port = of_graph_get_port_by_id(node, 1); + if (!port) + return -EINVAL; + + /* try finding a downstream endpoint */ + for_each_available_child_of_node(port, ep) { + struct device_node *remote; + u32 reg; + + ret = of_property_read_u32(ep, "reg", ®); + if (ret) + continue; + + /* Skip endpoint 0, the LCD panel interface */ + if (!reg) + continue; + + remote = of_parse_phandle(ep, "remote-endpoint", 0); + if (!remote) + continue; + + ret = of_property_read_u32(remote, "reg", ®); + if (ret) + continue; + + ret = reg; + } + + of_node_put(port); + + return ret; +} + static int sun4i_tcon_bind(struct device *dev, struct device *master, void *data) { @@ -488,6 +537,17 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, tcon->dev = dev; tcon->quirks = of_device_get_match_data(dev); + /* 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; + } + 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"); diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.h b/drivers/gpu/drm/sun4i/sun4i_tcon.h index f636343a935d..28b8da1e6c18 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.h +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.h @@ -172,6 +172,8 @@ struct sun4i_tcon { /* Associated crtc */ struct sun4i_crtc *crtc; + + int id; }; struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node);