drm_of.h 5.2 KB

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