drm_of.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #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. * drm_crtc_port_mask - find the mask of a registered CRTC by port OF node
  9. * @dev: DRM device
  10. * @port: port OF node
  11. *
  12. * Given a port OF node, return the possible mask of the corresponding
  13. * CRTC within a device's list of CRTCs. Returns zero if not found.
  14. */
  15. static uint32_t drm_crtc_port_mask(struct drm_device *dev,
  16. struct device_node *port)
  17. {
  18. unsigned int index = 0;
  19. struct drm_crtc *tmp;
  20. list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
  21. if (tmp->port == port)
  22. return 1 << index;
  23. index++;
  24. }
  25. return 0;
  26. }
  27. /**
  28. * drm_of_find_possible_crtcs - find the possible CRTCs for an encoder port
  29. * @dev: DRM device
  30. * @port: encoder port to scan for endpoints
  31. *
  32. * Scan all endpoints attached to a port, locate their attached CRTCs,
  33. * and generate the DRM mask of CRTCs which may be attached to this
  34. * encoder.
  35. *
  36. * See Documentation/devicetree/bindings/graph.txt for the bindings.
  37. */
  38. uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
  39. struct device_node *port)
  40. {
  41. struct device_node *remote_port, *ep;
  42. uint32_t possible_crtcs = 0;
  43. for_each_endpoint_of_node(port, ep) {
  44. remote_port = of_graph_get_remote_port(ep);
  45. if (!remote_port) {
  46. of_node_put(ep);
  47. return 0;
  48. }
  49. possible_crtcs |= drm_crtc_port_mask(dev, remote_port);
  50. of_node_put(remote_port);
  51. }
  52. return possible_crtcs;
  53. }
  54. EXPORT_SYMBOL(drm_of_find_possible_crtcs);