xref: /linux/drivers/gpu/drm/drm_of.c (revision 6295d607ad34ee4e43aab3f20714c2ef7a6adea1)
17e435aadSRussell King #include <linux/export.h>
27e435aadSRussell King #include <linux/list.h>
37e435aadSRussell King #include <linux/of_graph.h>
47e435aadSRussell King #include <drm/drmP.h>
57e435aadSRussell King #include <drm/drm_crtc.h>
67e435aadSRussell King #include <drm/drm_of.h>
77e435aadSRussell King 
87e435aadSRussell King /**
97e435aadSRussell King  * drm_crtc_port_mask - find the mask of a registered CRTC by port OF node
107e435aadSRussell King  * @dev: DRM device
117e435aadSRussell King  * @port: port OF node
127e435aadSRussell King  *
137e435aadSRussell King  * Given a port OF node, return the possible mask of the corresponding
147e435aadSRussell King  * CRTC within a device's list of CRTCs.  Returns zero if not found.
157e435aadSRussell King  */
167e435aadSRussell King static uint32_t drm_crtc_port_mask(struct drm_device *dev,
177e435aadSRussell King 				   struct device_node *port)
187e435aadSRussell King {
197e435aadSRussell King 	unsigned int index = 0;
207e435aadSRussell King 	struct drm_crtc *tmp;
217e435aadSRussell King 
22*6295d607SDaniel Vetter 	drm_for_each_crtc(tmp, dev) {
237e435aadSRussell King 		if (tmp->port == port)
247e435aadSRussell King 			return 1 << index;
257e435aadSRussell King 
267e435aadSRussell King 		index++;
277e435aadSRussell King 	}
287e435aadSRussell King 
297e435aadSRussell King 	return 0;
307e435aadSRussell King }
317e435aadSRussell King 
327e435aadSRussell King /**
337e435aadSRussell King  * drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port
347e435aadSRussell King  * @dev: DRM device
357e435aadSRussell King  * @port: encoder port to scan for endpoints
367e435aadSRussell King  *
377e435aadSRussell King  * Scan all endpoints attached to a port, locate their attached CRTCs,
387e435aadSRussell King  * and generate the DRM mask of CRTCs which may be attached to this
397e435aadSRussell King  * encoder.
407e435aadSRussell King  *
417e435aadSRussell King  * See Documentation/devicetree/bindings/graph.txt for the bindings.
427e435aadSRussell King  */
437e435aadSRussell King uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
447e435aadSRussell King 				    struct device_node *port)
457e435aadSRussell King {
467416f4e3SPhilipp Zabel 	struct device_node *remote_port, *ep;
477e435aadSRussell King 	uint32_t possible_crtcs = 0;
487e435aadSRussell King 
497416f4e3SPhilipp Zabel 	for_each_endpoint_of_node(port, ep) {
507e435aadSRussell King 		remote_port = of_graph_get_remote_port(ep);
517e435aadSRussell King 		if (!remote_port) {
527e435aadSRussell King 			of_node_put(ep);
537e435aadSRussell King 			return 0;
547e435aadSRussell King 		}
557e435aadSRussell King 
567e435aadSRussell King 		possible_crtcs |= drm_crtc_port_mask(dev, remote_port);
577e435aadSRussell King 
587e435aadSRussell King 		of_node_put(remote_port);
597416f4e3SPhilipp Zabel 	}
607e435aadSRussell King 
617e435aadSRussell King 	return possible_crtcs;
627e435aadSRussell King }
637e435aadSRussell King EXPORT_SYMBOL(drm_of_find_possible_crtcs);
64