drm_of.h 5.6 KB

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