aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen-Yu Tsai <wens@csie.org>2017-04-21 04:38:52 -0400
committerMaxime Ripard <maxime.ripard@free-electrons.com>2017-05-14 02:27:41 -0400
commitda3a1c30dc10858b39a759432d8141f42b8529e8 (patch)
tree551ddb40124da0d492b59809841961f351497d12
parentfdde6e7bcd5e2de4da6da7b0aab9676c478f319e (diff)
drm/sun4i: backend: Fetch backend ID from device tree
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 backend's ID from the device tree and stores it in the backend's data structure. It does this by looking at the "reg" property of any remote endpoints connected to the backend's input port. Signed-off-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_backend.c44
-rw-r--r--drivers/gpu/drm/sun4i/sun4i_backend.h2
2 files changed, 46 insertions, 0 deletions
diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c
index e17e20036aa3..0b4222312e49 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.c
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/component.h> 21#include <linux/component.h>
22#include <linux/list.h> 22#include <linux/list.h>
23#include <linux/of_graph.h>
23#include <linux/reset.h> 24#include <linux/reset.h>
24 25
25#include "sun4i_backend.h" 26#include "sun4i_backend.h"
@@ -289,6 +290,45 @@ static int sun4i_backend_free_sat(struct device *dev) {
289 return 0; 290 return 0;
290} 291}
291 292
293/*
294 * The display backend can take video output from the display frontend, or
295 * the display enhancement unit on the A80, as input for one it its layers.
296 * This relationship within the display pipeline is encoded in the device
297 * tree with of_graph, and we use it here to figure out which backend, if
298 * there are 2 or more, we are currently probing. The number would be in
299 * the "reg" property of the upstream output port endpoint.
300 */
301static int sun4i_backend_of_get_id(struct device_node *node)
302{
303 struct device_node *port, *ep;
304 int ret = -EINVAL;
305
306 /* input is port 0 */
307 port = of_graph_get_port_by_id(node, 0);
308 if (!port)
309 return -EINVAL;
310
311 /* try finding an upstream endpoint */
312 for_each_available_child_of_node(port, ep) {
313 struct device_node *remote;
314 u32 reg;
315
316 remote = of_parse_phandle(ep, "remote-endpoint", 0);
317 if (!remote)
318 continue;
319
320 ret = of_property_read_u32(remote, "reg", &reg);
321 if (ret)
322 continue;
323
324 ret = reg;
325 }
326
327 of_node_put(port);
328
329 return ret;
330}
331
292static struct regmap_config sun4i_backend_regmap_config = { 332static struct regmap_config sun4i_backend_regmap_config = {
293 .reg_bits = 32, 333 .reg_bits = 32,
294 .val_bits = 32, 334 .val_bits = 32,
@@ -312,6 +352,10 @@ static int sun4i_backend_bind(struct device *dev, struct device *master,
312 return -ENOMEM; 352 return -ENOMEM;
313 dev_set_drvdata(dev, backend); 353 dev_set_drvdata(dev, backend);
314 354
355 backend->id = sun4i_backend_of_get_id(dev->of_node);
356 if (backend->id < 0)
357 return backend->id;
358
315 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 359 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
316 regs = devm_ioremap_resource(dev, res); 360 regs = devm_ioremap_resource(dev, res);
317 if (IS_ERR(regs)) 361 if (IS_ERR(regs))
diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.h b/drivers/gpu/drm/sun4i/sun4i_backend.h
index 9c8287309c65..45b7fc110590 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.h
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.h
@@ -151,6 +151,8 @@ struct sun4i_backend {
151 struct clk *sat_clk; 151 struct clk *sat_clk;
152 struct reset_control *sat_reset; 152 struct reset_control *sat_reset;
153 153
154 int id;
155
154 /* Backend list management */ 156 /* Backend list management */
155 struct list_head list; 157 struct list_head list;
156}; 158};