Skip to content

Commit 52c2cf1

Browse files
committed
drm: xlnx: zynqmp_dpsub: Parse DT to find connected ports
To prepare for live video input support, parse the device tree to find the connected ports. Warn about unsupported configurations, and error out when invalid. Signed-off-by: Laurent Pinchart <[email protected]>
1 parent 4ce6ecd commit 52c2cf1

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

drivers/gpu/drm/xlnx/zynqmp_dpsub.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/clk.h>
1313
#include <linux/dma-mapping.h>
1414
#include <linux/module.h>
15+
#include <linux/of_graph.h>
1516
#include <linux/of_reserved_mem.h>
1617
#include <linux/platform_device.h>
1718
#include <linux/pm_runtime.h>
@@ -142,6 +143,55 @@ static int zynqmp_dpsub_init_clocks(struct zynqmp_dpsub *dpsub)
142143
return 0;
143144
}
144145

146+
static int zynqmp_dpsub_parse_dt(struct zynqmp_dpsub *dpsub)
147+
{
148+
struct device_node *np;
149+
unsigned int i;
150+
151+
/*
152+
* For backward compatibility with old device trees that don't contain
153+
* ports, consider that only the DP output port is connected if no
154+
* ports child no exists.
155+
*/
156+
np = of_get_child_by_name(dpsub->dev->of_node, "ports");
157+
of_node_put(np);
158+
if (!np) {
159+
dev_warn(dpsub->dev, "missing ports, update DT bindings\n");
160+
dpsub->connected_ports = BIT(ZYNQMP_DPSUB_PORT_OUT_DP);
161+
return 0;
162+
}
163+
164+
/* Check which ports are connected. */
165+
for (i = 0; i < ZYNQMP_DPSUB_NUM_PORTS; ++i) {
166+
struct device_node *np;
167+
168+
np = of_graph_get_remote_node(dpsub->dev->of_node, i, -1);
169+
if (np) {
170+
dpsub->connected_ports |= BIT(i);
171+
of_node_put(np);
172+
}
173+
}
174+
175+
/* Sanity checks. */
176+
if ((dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_LIVE_VIDEO)) ||
177+
(dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_LIVE_GFX)))
178+
dev_warn(dpsub->dev, "live video unsupported, ignoring\n");
179+
180+
if (dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_LIVE_AUDIO))
181+
dev_warn(dpsub->dev, "live audio unsupported, ignoring\n");
182+
183+
if ((dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_OUT_VIDEO)) ||
184+
(dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_OUT_AUDIO)))
185+
dev_warn(dpsub->dev, "output to PL unsupported, ignoring\n");
186+
187+
if (!(dpsub->connected_ports & BIT(ZYNQMP_DPSUB_PORT_OUT_DP))) {
188+
dev_err(dpsub->dev, "DP output port not connected\n");
189+
return -EINVAL;
190+
}
191+
192+
return 0;
193+
}
194+
145195
void zynqmp_dpsub_release(struct zynqmp_dpsub *dpsub)
146196
{
147197
kfree(dpsub->disp);
@@ -171,6 +221,10 @@ static int zynqmp_dpsub_probe(struct platform_device *pdev)
171221
if (ret < 0)
172222
goto err_mem;
173223

224+
ret = zynqmp_dpsub_parse_dt(dpsub);
225+
if (ret < 0)
226+
goto err_mem;
227+
174228
pm_runtime_enable(&pdev->dev);
175229

176230
/*

drivers/gpu/drm/xlnx/zynqmp_dpsub.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ struct zynqmp_dpsub_drm;
2222

2323
#define ZYNQMP_DPSUB_NUM_LAYERS 2
2424

25+
enum zynqmp_dpsub_port {
26+
ZYNQMP_DPSUB_PORT_LIVE_VIDEO,
27+
ZYNQMP_DPSUB_PORT_LIVE_GFX,
28+
ZYNQMP_DPSUB_PORT_LIVE_AUDIO,
29+
ZYNQMP_DPSUB_PORT_OUT_VIDEO,
30+
ZYNQMP_DPSUB_PORT_OUT_AUDIO,
31+
ZYNQMP_DPSUB_PORT_OUT_DP,
32+
ZYNQMP_DPSUB_NUM_PORTS,
33+
};
34+
2535
enum zynqmp_dpsub_format {
2636
ZYNQMP_DPSUB_FORMAT_RGB,
2737
ZYNQMP_DPSUB_FORMAT_YCRCB444,
@@ -37,6 +47,7 @@ enum zynqmp_dpsub_format {
3747
* @vid_clk_from_ps: True of the video clock comes from PS, false from PL
3848
* @aud_clk: Audio clock
3949
* @aud_clk_from_ps: True of the audio clock comes from PS, false from PL
50+
* @connected_ports: Bitmask of connected ports in the device tree
4051
* @drm: The DRM/KMS device data
4152
* @bridge: The DP encoder bridge
4253
* @disp: The display controller
@@ -52,6 +63,8 @@ struct zynqmp_dpsub {
5263
struct clk *aud_clk;
5364
bool aud_clk_from_ps;
5465

66+
unsigned int connected_ports;
67+
5568
struct zynqmp_dpsub_drm *drm;
5669
struct drm_bridge *bridge;
5770

0 commit comments

Comments
 (0)