drm_bridge.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_BRIDGE_H__
  23. #define __DRM_BRIDGE_H__
  24. #include <linux/list.h>
  25. #include <linux/ctype.h>
  26. #include <drm/drm_mode_object.h>
  27. #include <drm/drm_modes.h>
  28. struct drm_bridge;
  29. /**
  30. * struct drm_bridge_funcs - drm_bridge control functions
  31. */
  32. struct drm_bridge_funcs {
  33. /**
  34. * @attach:
  35. *
  36. * This callback is invoked whenever our bridge is being attached to a
  37. * &drm_encoder.
  38. *
  39. * The attach callback is optional.
  40. *
  41. * RETURNS:
  42. *
  43. * Zero on success, error code on failure.
  44. */
  45. int (*attach)(struct drm_bridge *bridge);
  46. /**
  47. * @detach:
  48. *
  49. * This callback is invoked whenever our bridge is being detached from a
  50. * &drm_encoder.
  51. *
  52. * The detach callback is optional.
  53. */
  54. void (*detach)(struct drm_bridge *bridge);
  55. /**
  56. * @mode_fixup:
  57. *
  58. * This callback is used to validate and adjust a mode. The paramater
  59. * mode is the display mode that should be fed to the next element in
  60. * the display chain, either the final &drm_connector or the next
  61. * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
  62. * requires. It can be modified by this callback and does not need to
  63. * match mode.
  64. *
  65. * This is the only hook that allows a bridge to reject a modeset. If
  66. * this function passes all other callbacks must succeed for this
  67. * configuration.
  68. *
  69. * The mode_fixup callback is optional.
  70. *
  71. * NOTE:
  72. *
  73. * This function is called in the check phase of atomic modesets, which
  74. * can be aborted for any reason (including on userspace's request to
  75. * just check whether a configuration would be possible). Drivers MUST
  76. * NOT touch any persistent state (hardware or software) or data
  77. * structures except the passed in @state parameter.
  78. *
  79. * RETURNS:
  80. *
  81. * True if an acceptable configuration is possible, false if the modeset
  82. * operation should be rejected.
  83. */
  84. bool (*mode_fixup)(struct drm_bridge *bridge,
  85. const struct drm_display_mode *mode,
  86. struct drm_display_mode *adjusted_mode);
  87. /**
  88. * @disable:
  89. *
  90. * This callback should disable the bridge. It is called right before
  91. * the preceding element in the display pipe is disabled. If the
  92. * preceding element is a bridge this means it's called before that
  93. * bridge's ->disable() function. If the preceding element is a
  94. * &drm_encoder it's called right before the encoder's ->disable(),
  95. * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  96. *
  97. * The bridge can assume that the display pipe (i.e. clocks and timing
  98. * signals) feeding it is still running when this callback is called.
  99. *
  100. * The disable callback is optional.
  101. */
  102. void (*disable)(struct drm_bridge *bridge);
  103. /**
  104. * @post_disable:
  105. *
  106. * This callback should disable the bridge. It is called right after
  107. * the preceding element in the display pipe is disabled. If the
  108. * preceding element is a bridge this means it's called after that
  109. * bridge's ->post_disable() function. If the preceding element is a
  110. * &drm_encoder it's called right after the encoder's ->disable(),
  111. * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  112. *
  113. * The bridge must assume that the display pipe (i.e. clocks and timing
  114. * singals) feeding it is no longer running when this callback is
  115. * called.
  116. *
  117. * The post_disable callback is optional.
  118. */
  119. void (*post_disable)(struct drm_bridge *bridge);
  120. /**
  121. * @mode_set:
  122. *
  123. * This callback should set the given mode on the bridge. It is called
  124. * after the ->mode_set() callback for the preceding element in the
  125. * display pipeline has been called already. The display pipe (i.e.
  126. * clocks and timing signals) is off when this function is called.
  127. */
  128. void (*mode_set)(struct drm_bridge *bridge,
  129. struct drm_display_mode *mode,
  130. struct drm_display_mode *adjusted_mode);
  131. /**
  132. * @pre_enable:
  133. *
  134. * This callback should enable the bridge. It is called right before
  135. * the preceding element in the display pipe is enabled. If the
  136. * preceding element is a bridge this means it's called before that
  137. * bridge's ->pre_enable() function. If the preceding element is a
  138. * &drm_encoder it's called right before the encoder's ->enable(),
  139. * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  140. *
  141. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  142. * will not yet be running when this callback is called. The bridge must
  143. * not enable the display link feeding the next bridge in the chain (if
  144. * there is one) when this callback is called.
  145. *
  146. * The pre_enable callback is optional.
  147. */
  148. void (*pre_enable)(struct drm_bridge *bridge);
  149. /**
  150. * @enable:
  151. *
  152. * This callback should enable the bridge. It is called right after
  153. * the preceding element in the display pipe is enabled. If the
  154. * preceding element is a bridge this means it's called after that
  155. * bridge's ->enable() function. If the preceding element is a
  156. * &drm_encoder it's called right after the encoder's ->enable(),
  157. * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
  158. *
  159. * The bridge can assume that the display pipe (i.e. clocks and timing
  160. * signals) feeding it is running when this callback is called. This
  161. * callback must enable the display link feeding the next bridge in the
  162. * chain if there is one.
  163. *
  164. * The enable callback is optional.
  165. */
  166. void (*enable)(struct drm_bridge *bridge);
  167. };
  168. /**
  169. * struct drm_bridge - central DRM bridge control structure
  170. * @dev: DRM device this bridge belongs to
  171. * @encoder: encoder to which this bridge is connected
  172. * @next: the next bridge in the encoder chain
  173. * @of_node: device node pointer to the bridge
  174. * @list: to keep track of all added bridges
  175. * @funcs: control functions
  176. * @driver_private: pointer to the bridge driver's internal context
  177. */
  178. struct drm_bridge {
  179. struct drm_device *dev;
  180. struct drm_encoder *encoder;
  181. struct drm_bridge *next;
  182. #ifdef CONFIG_OF
  183. struct device_node *of_node;
  184. #endif
  185. struct list_head list;
  186. const struct drm_bridge_funcs *funcs;
  187. void *driver_private;
  188. };
  189. int drm_bridge_add(struct drm_bridge *bridge);
  190. void drm_bridge_remove(struct drm_bridge *bridge);
  191. struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  192. int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
  193. void drm_bridge_detach(struct drm_bridge *bridge);
  194. bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
  195. const struct drm_display_mode *mode,
  196. struct drm_display_mode *adjusted_mode);
  197. void drm_bridge_disable(struct drm_bridge *bridge);
  198. void drm_bridge_post_disable(struct drm_bridge *bridge);
  199. void drm_bridge_mode_set(struct drm_bridge *bridge,
  200. struct drm_display_mode *mode,
  201. struct drm_display_mode *adjusted_mode);
  202. void drm_bridge_pre_enable(struct drm_bridge *bridge);
  203. void drm_bridge_enable(struct drm_bridge *bridge);
  204. #endif