drm_bridge.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 vfunc. If the preceding element is a &drm_encoder
  94. * it's called right before the &drm_encoder_helper_funcs.disable,
  95. * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
  96. * hook.
  97. *
  98. * The bridge can assume that the display pipe (i.e. clocks and timing
  99. * signals) feeding it is still running when this callback is called.
  100. *
  101. * The disable callback is optional.
  102. */
  103. void (*disable)(struct drm_bridge *bridge);
  104. /**
  105. * @post_disable:
  106. *
  107. * This callback should disable the bridge. It is called right after the
  108. * preceding element in the display pipe is disabled. If the preceding
  109. * element is a bridge this means it's called after that bridge's
  110. * @post_disable function. If the preceding element is a &drm_encoder
  111. * it's called right after the encoder's
  112. * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
  113. * or &drm_encoder_helper_funcs.dpms hook.
  114. *
  115. * The bridge must assume that the display pipe (i.e. clocks and timing
  116. * singals) feeding it is no longer running when this callback is
  117. * called.
  118. *
  119. * The post_disable callback is optional.
  120. */
  121. void (*post_disable)(struct drm_bridge *bridge);
  122. /**
  123. * @mode_set:
  124. *
  125. * This callback should set the given mode on the bridge. It is called
  126. * after the @mode_set callback for the preceding element in the display
  127. * pipeline has been called already. If the bridge is the first element
  128. * then this would be &drm_encoder_helper_funcs.mode_set. The display
  129. * pipe (i.e. clocks and timing signals) is off when this function is
  130. * called.
  131. */
  132. void (*mode_set)(struct drm_bridge *bridge,
  133. struct drm_display_mode *mode,
  134. struct drm_display_mode *adjusted_mode);
  135. /**
  136. * @pre_enable:
  137. *
  138. * This callback should enable the bridge. It is called right before
  139. * the preceding element in the display pipe is enabled. If the
  140. * preceding element is a bridge this means it's called before that
  141. * bridge's @pre_enable function. If the preceding element is a
  142. * &drm_encoder it's called right before the encoder's
  143. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  144. * &drm_encoder_helper_funcs.dpms hook.
  145. *
  146. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  147. * will not yet be running when this callback is called. The bridge must
  148. * not enable the display link feeding the next bridge in the chain (if
  149. * there is one) when this callback is called.
  150. *
  151. * The pre_enable callback is optional.
  152. */
  153. void (*pre_enable)(struct drm_bridge *bridge);
  154. /**
  155. * @enable:
  156. *
  157. * This callback should enable the bridge. It is called right after
  158. * the preceding element in the display pipe is enabled. If the
  159. * preceding element is a bridge this means it's called after that
  160. * bridge's @enable function. If the preceding element is a
  161. * &drm_encoder it's called right after the encoder's
  162. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  163. * &drm_encoder_helper_funcs.dpms hook.
  164. *
  165. * The bridge can assume that the display pipe (i.e. clocks and timing
  166. * signals) feeding it is running when this callback is called. This
  167. * callback must enable the display link feeding the next bridge in the
  168. * chain if there is one.
  169. *
  170. * The enable callback is optional.
  171. */
  172. void (*enable)(struct drm_bridge *bridge);
  173. };
  174. /**
  175. * struct drm_bridge - central DRM bridge control structure
  176. * @dev: DRM device this bridge belongs to
  177. * @encoder: encoder to which this bridge is connected
  178. * @next: the next bridge in the encoder chain
  179. * @of_node: device node pointer to the bridge
  180. * @list: to keep track of all added bridges
  181. * @funcs: control functions
  182. * @driver_private: pointer to the bridge driver's internal context
  183. */
  184. struct drm_bridge {
  185. struct drm_device *dev;
  186. struct drm_encoder *encoder;
  187. struct drm_bridge *next;
  188. #ifdef CONFIG_OF
  189. struct device_node *of_node;
  190. #endif
  191. struct list_head list;
  192. const struct drm_bridge_funcs *funcs;
  193. void *driver_private;
  194. };
  195. int drm_bridge_add(struct drm_bridge *bridge);
  196. void drm_bridge_remove(struct drm_bridge *bridge);
  197. struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  198. int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
  199. struct drm_bridge *previous);
  200. bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
  201. const struct drm_display_mode *mode,
  202. struct drm_display_mode *adjusted_mode);
  203. void drm_bridge_disable(struct drm_bridge *bridge);
  204. void drm_bridge_post_disable(struct drm_bridge *bridge);
  205. void drm_bridge_mode_set(struct drm_bridge *bridge,
  206. struct drm_display_mode *mode,
  207. struct drm_display_mode *adjusted_mode);
  208. void drm_bridge_pre_enable(struct drm_bridge *bridge);
  209. void drm_bridge_enable(struct drm_bridge *bridge);
  210. #endif