drm_of.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #ifdef CONFIG_OF
  17. uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
  18. struct device_node *port);
  19. uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
  20. struct device_node *port);
  21. void drm_of_component_match_add(struct device *master,
  22. struct component_match **matchptr,
  23. int (*compare)(struct device *, void *),
  24. struct device_node *node);
  25. int drm_of_component_probe(struct device *dev,
  26. int (*compare_of)(struct device *, void *),
  27. const struct component_master_ops *m_ops);
  28. int drm_of_encoder_active_endpoint(struct device_node *node,
  29. struct drm_encoder *encoder,
  30. struct of_endpoint *endpoint);
  31. int drm_of_find_panel_or_bridge(const struct device_node *np,
  32. int port, int endpoint,
  33. struct drm_panel **panel,
  34. struct drm_bridge **bridge);
  35. #else
  36. static inline uint32_t drm_of_crtc_port_mask(struct drm_device *dev,
  37. struct device_node *port)
  38. {
  39. return 0;
  40. }
  41. static inline uint32_t drm_of_find_possible_crtcs(struct drm_device *dev,
  42. struct device_node *port)
  43. {
  44. return 0;
  45. }
  46. static inline void
  47. drm_of_component_match_add(struct device *master,
  48. struct component_match **matchptr,
  49. int (*compare)(struct device *, void *),
  50. struct device_node *node)
  51. {
  52. }
  53. static inline int
  54. drm_of_component_probe(struct device *dev,
  55. int (*compare_of)(struct device *, void *),
  56. const struct component_master_ops *m_ops)
  57. {
  58. return -EINVAL;
  59. }
  60. static inline int drm_of_encoder_active_endpoint(struct device_node *node,
  61. struct drm_encoder *encoder,
  62. struct of_endpoint *endpoint)
  63. {
  64. return -EINVAL;
  65. }
  66. static inline int drm_of_find_panel_or_bridge(const struct device_node *np,
  67. int port, int endpoint,
  68. struct drm_panel **panel,
  69. struct drm_bridge **bridge)
  70. {
  71. return -EINVAL;
  72. }
  73. #endif
  74. /*
  75. * drm_of_panel_bridge_remove - remove panel bridge
  76. * @np: device tree node containing panel bridge output ports
  77. *
  78. * Remove the panel bridge of a given DT node's port and endpoint number
  79. *
  80. * Returns zero if successful, or one of the standard error codes if it fails.
  81. */
  82. static inline int drm_of_panel_bridge_remove(const struct device_node *np,
  83. int port, int endpoint)
  84. {
  85. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DRM_PANEL_BRIDGE)
  86. struct drm_bridge *bridge;
  87. struct device_node *remote;
  88. remote = of_graph_get_remote_node(np, port, endpoint);
  89. if (!remote)
  90. return -ENODEV;
  91. bridge = of_drm_find_bridge(remote);
  92. drm_panel_bridge_remove(bridge);
  93. return 0;
  94. #else
  95. return -EINVAL;
  96. #endif
  97. }
  98. static inline int drm_of_encoder_active_endpoint_id(struct device_node *node,
  99. struct drm_encoder *encoder)
  100. {
  101. struct of_endpoint endpoint;
  102. int ret = drm_of_encoder_active_endpoint(node, encoder,
  103. &endpoint);
  104. return ret ?: endpoint.id;
  105. }
  106. static inline int drm_of_encoder_active_port_id(struct device_node *node,
  107. struct drm_encoder *encoder)
  108. {
  109. struct of_endpoint endpoint;
  110. int ret = drm_of_encoder_active_endpoint(node, encoder,
  111. &endpoint);
  112. return ret ?: endpoint.port;
  113. }
  114. #endif /* __DRM_OF_H__ */