blob: be3884073ea4df9661903544f28358bb5b55359f [file] [log] [blame]
Russell King7e435aa2014-06-15 11:07:12 +01001#include <linux/export.h>
2#include <linux/list.h>
3#include <linux/of_graph.h>
4#include <drm/drmP.h>
5#include <drm/drm_crtc.h>
6#include <drm/drm_of.h>
7
8/**
9 * drm_crtc_port_mask - find the mask of a registered CRTC by port OF node
10 * @dev: DRM device
11 * @port: port OF node
12 *
13 * Given a port OF node, return the possible mask of the corresponding
14 * CRTC within a device's list of CRTCs. Returns zero if not found.
15 */
16static uint32_t drm_crtc_port_mask(struct drm_device *dev,
17 struct device_node *port)
18{
19 unsigned int index = 0;
20 struct drm_crtc *tmp;
21
Daniel Vetter6295d602015-07-09 23:44:25 +020022 drm_for_each_crtc(tmp, dev) {
Russell King7e435aa2014-06-15 11:07:12 +010023 if (tmp->port == port)
24 return 1 << index;
25
26 index++;
27 }
28
29 return 0;
30}
31
32/**
33 * drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port
34 * @dev: DRM device
35 * @port: encoder port to scan for endpoints
36 *
37 * Scan all endpoints attached to a port, locate their attached CRTCs,
38 * and generate the DRM mask of CRTCs which may be attached to this
39 * encoder.
40 *
41 * See Documentation/devicetree/bindings/graph.txt for the bindings.
42 */
43uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
44 struct device_node *port)
45{
Philipp Zabel7416f4e2014-07-03 22:59:51 +020046 struct device_node *remote_port, *ep;
Russell King7e435aa2014-06-15 11:07:12 +010047 uint32_t possible_crtcs = 0;
48
Philipp Zabel7416f4e2014-07-03 22:59:51 +020049 for_each_endpoint_of_node(port, ep) {
Russell King7e435aa2014-06-15 11:07:12 +010050 remote_port = of_graph_get_remote_port(ep);
51 if (!remote_port) {
52 of_node_put(ep);
53 return 0;
54 }
55
56 possible_crtcs |= drm_crtc_port_mask(dev, remote_port);
57
58 of_node_put(remote_port);
Philipp Zabel7416f4e2014-07-03 22:59:51 +020059 }
Russell King7e435aa2014-06-15 11:07:12 +010060
61 return possible_crtcs;
62}
63EXPORT_SYMBOL(drm_of_find_possible_crtcs);