drm_of.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. int drm_of_lvds_get_data_mapping(const struct device_node *port);
  49. int drm_of_get_data_lanes_count(const struct device_node *endpoint,
  50. const unsigned int min, const unsigned int max);
  51. int drm_of_get_data_lanes_count_ep(const struct device_node *port,
  52. int port_reg, int reg,
  53. const unsigned int min,
  54. const unsigned int max);
  55. #else
  56. static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
  57. struct device_node *port)
  58. {
  59. return 0;
  60. }
  61. static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
  62. struct device_node *port)
  63. {
  64. return 0;
  65. }
  66. static inline void
  67. drm_of_component_match_add(struct device *master,
  68. struct component_match **matchptr,
  69. int (*compare)(struct device *, void *),
  70. struct device_node *node)
  71. {
  72. }
  73. static inline int
  74. drm_of_component_probe(struct device *dev,
  75. int (*compare_of)(struct device *, void *),
  76. const struct component_master_ops *m_ops)
  77. {
  78. return -EINVAL;
  79. }
  80. static inline int drm_of_encoder_active_endpoint(struct device_node *node,
  81. struct drm_encoder *encoder,
  82. struct of_endpoint *endpoint)
  83. {
  84. return -EINVAL;
  85. }
  86. static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
  87. int port, int endpoint,
  88. struct drm_panel **panel,
  89. struct drm_bridge **bridge)
  90. {
  91. return -EINVAL;
  92. }
  93. static inline int
  94. drm_of_lvds_get_dual_link_pixel_order(const struct device_node *port1,
  95. const struct device_node *port2)
  96. {
  97. return -EINVAL;
  98. }
  99. static inline int
  100. drm_of_lvds_get_data_mapping(const struct device_node *port)
  101. {
  102. return -EINVAL;
  103. }
  104. static inline int
  105. drm_of_get_data_lanes_count(const struct device_node *endpoint,
  106. const unsigned int min, const unsigned int max)
  107. {
  108. return -EINVAL;
  109. }
  110. static inline int
  111. drm_of_get_data_lanes_count_ep(const struct device_node *port,
  112. int port_reg, int reg,
  113. const unsigned int min,
  114. const unsigned int max)
  115. {
  116. return -EINVAL;
  117. }
  118. #endif
  119. /*
  120. * drm_of_panel_bridge_remove - remove panel bridge
  121. * @np: device tree node containing panel bridge output ports
  122. *
  123. * Remove the panel bridge of a given DT node's port and endpoint number
  124. *
  125. * Returns zero if successful, or one of the standard error codes if it fails.
  126. */
  127. static inline int drm_of_panel_bridge_remove(const struct device_node *np,
  128. int port, int endpoint)
  129. {
  130. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
  131. struct drm_bridge *bridge;
  132. struct device_node *remote;
  133. remote = of_graph_get_remote_node(np, port, endpoint);
  134. if (!remote)
  135. return -ENODEV;
  136. bridge = of_drm_find_bridge(remote);
  137. drm_panel_bridge_remove(bridge);
  138. return 0;
  139. #else
  140. return -EINVAL;
  141. #endif
  142. }
  143. static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
  144. struct drm_encoder *encoder)
  145. {
  146. struct of_endpoint endpoint;
  147. int ret = drm_of_encoder_active_endpoint(node, encoder,
  148. &endpoint);
  149. return ret ?: endpoint.id;
  150. }
  151. static inline int drm_of_encoder_active_port_id(struct device_node *node,
  152. struct drm_encoder *encoder)
  153. {
  154. struct of_endpoint endpoint;
  155. int ret = drm_of_encoder_active_endpoint(node, encoder,
  156. &endpoint);
  157. return ret ?: endpoint.port;
  158. }
  159. #endif /* __DRM_OF_H__ */