drm_of.h 3.2 KB

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