drm_of.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __DRM_OF_H__
  3. #define __DRM_OF_H__
  4. #include <linux/of_graph.h>
  5. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
  6. #include <drm/drm_bridge.h>
  7. #endif
  8. struct component_master_ops;
  9. struct component_match;
  10. struct device;
  11. struct drm_device;
  12. struct drm_encoder;
  13. struct drm_panel;
  14. struct drm_bridge;
  15. struct device_node;
  16. /**
  17. * enum drm_lvds_dual_link_pixels - Pixel order of an LVDS dual-link connection
  18. * @DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS: Even pixels are expected to be generated
  19. * from the first port, odd pixels from the second port
  20. * @DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS: Odd pixels are expected to be generated
  21. * from the first port, even pixels from the second port
  22. */
  23. enum drm_lvds_dual_link_pixels {
  24. DRM_LVDS_DUAL_LINK_EVEN_ODD_PIXELS = 0,
  25. DRM_LVDS_DUAL_LINK_ODD_EVEN_PIXELS = 1,
  26. };
  27. #ifdef CONFIG_OF
  28. uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
  29. struct device_node *port);
  30. uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
  31. struct device_node *port);
  32. void drm_of_component_match_add(struct device *master,
  33. struct component_match **matchptr,
  34. int (*compare)(struct device *, void *),
  35. struct device_node *node);
  36. int drm_of_component_probe(struct device *dev,
  37. int (*compare_of)(struct device *, void *),
  38. const struct component_master_ops *m_ops);
  39. int drm_of_encoder_active_endpoint(struct device_node *node,
  40. struct drm_encoder *encoder,
  41. struct of_endpoint *endpoint);
  42. int drm_of_find_panel_or_bridge(const struct device_node *np,
  43. int port, int endpoint,
  44. struct drm_panel **panel,
  45. struct drm_bridge **bridge);
  46. int drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
  47. const struct device_node *port2);
  48. #else
  49. static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
  50. struct device_node *port)
  51. {
  52. return 0;
  53. }
  54. static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
  55. struct device_node *port)
  56. {
  57. return 0;
  58. }
  59. static inline void
  60. drm_of_component_match_add(struct device *master,
  61. struct component_match **matchptr,
  62. int (*compare)(struct device *, void *),
  63. struct device_node *node)
  64. {
  65. }
  66. static inline int
  67. drm_of_component_probe(struct device *dev,
  68. int (*compare_of)(struct device *, void *),
  69. const struct component_master_ops *m_ops)
  70. {
  71. return -EINVAL;
  72. }
  73. static inline int drm_of_encoder_active_endpoint(struct device_node *node,
  74. struct drm_encoder *encoder,
  75. struct of_endpoint *endpoint)
  76. {
  77. return -EINVAL;
  78. }
  79. static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
  80. int port, int endpoint,
  81. struct drm_panel **panel,
  82. struct drm_bridge **bridge)
  83. {
  84. return -EINVAL;
  85. }
  86. static inline int
  87. drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
  88. const struct device_node *port2)
  89. {
  90. return -EINVAL;
  91. }
  92. #endif
  93. /*
  94. * drm_of_panel_bridge_remove - remove panel bridge
  95. * @np: device tree node containing panel bridge output ports
  96. *
  97. * Remove the panel bridge of a given DT node's port and endpoint number
  98. *
  99. * Returns zero if successful, or one of the standard error codes if it fails.
  100. */
  101. static inline int drm_of_panel_bridge_remove(const struct device_node *np,
  102. int port, int endpoint)
  103. {
  104. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
  105. struct drm_bridge *bridge;
  106. struct device_node *remote;
  107. remote = of_graph_get_remote_node(np, port, endpoint);
  108. if (!remote)
  109. return -ENODEV;
  110. bridge = of_drm_find_bridge(remote);
  111. drm_panel_bridge_remove(bridge);
  112. return 0;
  113. #else
  114. return -EINVAL;
  115. #endif
  116. }
  117. static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
  118. struct drm_encoder *encoder)
  119. {
  120. struct of_endpoint endpoint;
  121. int ret = drm_of_encoder_active_endpoint(node, encoder,
  122. &endpoint);
  123. return ret ?: endpoint.id;
  124. }
  125. static inline int drm_of_encoder_active_port_id(struct device_node *node,
  126. struct drm_encoder *encoder)
  127. {
  128. struct of_endpoint endpoint;
  129. int ret = drm_of_encoder_active_endpoint(node, encoder,
  130. &endpoint);
  131. return ret ?: endpoint.port;
  132. }
  133. #endif /* __DRM_OF_H__ */