drm_bridge.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. struct drm_panel;
  30. /**
  31. * struct drm_bridge_funcs - drm_bridge control functions
  32. */
  33. struct drm_bridge_funcs {
  34. /**
  35. * @attach:
  36. *
  37. * This callback is invoked whenever our bridge is being attached to a
  38. * &drm_encoder.
  39. *
  40. * The attach callback is optional.
  41. *
  42. * RETURNS:
  43. *
  44. * Zero on success, error code on failure.
  45. */
  46. int (*attach)(struct drm_bridge *bridge);
  47. /**
  48. * @detach:
  49. *
  50. * This callback is invoked whenever our bridge is being detached from a
  51. * &drm_encoder.
  52. *
  53. * The detach callback is optional.
  54. */
  55. void (*detach)(struct drm_bridge *bridge);
  56. /**
  57. * @mode_valid:
  58. *
  59. * This callback is used to check if a specific mode is valid in this
  60. * bridge. This should be implemented if the bridge has some sort of
  61. * restriction in the modes it can display. For example, a given bridge
  62. * may be responsible to set a clock value. If the clock can not
  63. * produce all the values for the available modes then this callback
  64. * can be used to restrict the number of modes to only the ones that
  65. * can be displayed.
  66. *
  67. * This hook is used by the probe helpers to filter the mode list in
  68. * drm_helper_probe_single_connector_modes(), and it is used by the
  69. * atomic helpers to validate modes supplied by userspace in
  70. * drm_atomic_helper_check_modeset().
  71. *
  72. * This function is optional.
  73. *
  74. * NOTE:
  75. *
  76. * Since this function is both called from the check phase of an atomic
  77. * commit, and the mode validation in the probe paths it is not allowed
  78. * to look at anything else but the passed-in mode, and validate it
  79. * against configuration-invariant hardward constraints. Any further
  80. * limits which depend upon the configuration can only be checked in
  81. * @mode_fixup.
  82. *
  83. * RETURNS:
  84. *
  85. * drm_mode_status Enum
  86. */
  87. enum drm_mode_status (*mode_valid)(struct drm_bridge *crtc,
  88. const struct drm_display_mode *mode);
  89. /**
  90. * @mode_fixup:
  91. *
  92. * This callback is used to validate and adjust a mode. The paramater
  93. * mode is the display mode that should be fed to the next element in
  94. * the display chain, either the final &drm_connector or the next
  95. * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
  96. * requires. It can be modified by this callback and does not need to
  97. * match mode. See also &drm_crtc_state.adjusted_mode for more details.
  98. *
  99. * This is the only hook that allows a bridge to reject a modeset. If
  100. * this function passes all other callbacks must succeed for this
  101. * configuration.
  102. *
  103. * The mode_fixup callback is optional.
  104. *
  105. * NOTE:
  106. *
  107. * This function is called in the check phase of atomic modesets, which
  108. * can be aborted for any reason (including on userspace's request to
  109. * just check whether a configuration would be possible). Drivers MUST
  110. * NOT touch any persistent state (hardware or software) or data
  111. * structures except the passed in @state parameter.
  112. *
  113. * Also beware that userspace can request its own custom modes, neither
  114. * core nor helpers filter modes to the list of probe modes reported by
  115. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  116. * that modes are filtered consistently put any bridge constraints and
  117. * limits checks into @mode_valid.
  118. *
  119. * RETURNS:
  120. *
  121. * True if an acceptable configuration is possible, false if the modeset
  122. * operation should be rejected.
  123. */
  124. bool (*mode_fixup)(struct drm_bridge *bridge,
  125. const struct drm_display_mode *mode,
  126. struct drm_display_mode *adjusted_mode);
  127. /**
  128. * @disable:
  129. *
  130. * This callback should disable the bridge. It is called right before
  131. * the preceding element in the display pipe is disabled. If the
  132. * preceding element is a bridge this means it's called before that
  133. * bridge's @disable vfunc. If the preceding element is a &drm_encoder
  134. * it's called right before the &drm_encoder_helper_funcs.disable,
  135. * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
  136. * hook.
  137. *
  138. * The bridge can assume that the display pipe (i.e. clocks and timing
  139. * signals) feeding it is still running when this callback is called.
  140. *
  141. * The disable callback is optional.
  142. */
  143. void (*disable)(struct drm_bridge *bridge);
  144. /**
  145. * @post_disable:
  146. *
  147. * This callback should disable the bridge. It is called right after the
  148. * preceding element in the display pipe is disabled. If the preceding
  149. * element is a bridge this means it's called after that bridge's
  150. * @post_disable function. If the preceding element is a &drm_encoder
  151. * it's called right after the encoder's
  152. * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
  153. * or &drm_encoder_helper_funcs.dpms hook.
  154. *
  155. * The bridge must assume that the display pipe (i.e. clocks and timing
  156. * singals) feeding it is no longer running when this callback is
  157. * called.
  158. *
  159. * The post_disable callback is optional.
  160. */
  161. void (*post_disable)(struct drm_bridge *bridge);
  162. /**
  163. * @mode_set:
  164. *
  165. * This callback should set the given mode on the bridge. It is called
  166. * after the @mode_set callback for the preceding element in the display
  167. * pipeline has been called already. If the bridge is the first element
  168. * then this would be &drm_encoder_helper_funcs.mode_set. The display
  169. * pipe (i.e. clocks and timing signals) is off when this function is
  170. * called.
  171. */
  172. void (*mode_set)(struct drm_bridge *bridge,
  173. struct drm_display_mode *mode,
  174. struct drm_display_mode *adjusted_mode);
  175. /**
  176. * @pre_enable:
  177. *
  178. * This callback should enable the bridge. It is called right before
  179. * the preceding element in the display pipe is enabled. If the
  180. * preceding element is a bridge this means it's called before that
  181. * bridge's @pre_enable function. If the preceding element is a
  182. * &drm_encoder it's called right before the encoder's
  183. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  184. * &drm_encoder_helper_funcs.dpms hook.
  185. *
  186. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  187. * will not yet be running when this callback is called. The bridge must
  188. * not enable the display link feeding the next bridge in the chain (if
  189. * there is one) when this callback is called.
  190. *
  191. * The pre_enable callback is optional.
  192. */
  193. void (*pre_enable)(struct drm_bridge *bridge);
  194. /**
  195. * @enable:
  196. *
  197. * This callback should enable the bridge. It is called right after
  198. * the preceding element in the display pipe is enabled. If the
  199. * preceding element is a bridge this means it's called after that
  200. * bridge's @enable function. If the preceding element is a
  201. * &drm_encoder it's called right after the encoder's
  202. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  203. * &drm_encoder_helper_funcs.dpms hook.
  204. *
  205. * The bridge can assume that the display pipe (i.e. clocks and timing
  206. * signals) feeding it is running when this callback is called. This
  207. * callback must enable the display link feeding the next bridge in the
  208. * chain if there is one.
  209. *
  210. * The enable callback is optional.
  211. */
  212. void (*enable)(struct drm_bridge *bridge);
  213. };
  214. /**
  215. * struct drm_bridge - central DRM bridge control structure
  216. * @dev: DRM device this bridge belongs to
  217. * @encoder: encoder to which this bridge is connected
  218. * @next: the next bridge in the encoder chain
  219. * @of_node: device node pointer to the bridge
  220. * @list: to keep track of all added bridges
  221. * @funcs: control functions
  222. * @driver_private: pointer to the bridge driver's internal context
  223. */
  224. struct drm_bridge {
  225. struct drm_device *dev;
  226. struct drm_encoder *encoder;
  227. struct drm_bridge *next;
  228. #ifdef CONFIG_OF
  229. struct device_node *of_node;
  230. #endif
  231. struct list_head list;
  232. const struct drm_bridge_funcs *funcs;
  233. void *driver_private;
  234. };
  235. int drm_bridge_add(struct drm_bridge *bridge);
  236. void drm_bridge_remove(struct drm_bridge *bridge);
  237. struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  238. int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
  239. struct drm_bridge *previous);
  240. bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
  241. const struct drm_display_mode *mode,
  242. struct drm_display_mode *adjusted_mode);
  243. enum drm_mode_status drm_bridge_mode_valid(struct drm_bridge *bridge,
  244. const struct drm_display_mode *mode);
  245. void drm_bridge_disable(struct drm_bridge *bridge);
  246. void drm_bridge_post_disable(struct drm_bridge *bridge);
  247. void drm_bridge_mode_set(struct drm_bridge *bridge,
  248. struct drm_display_mode *mode,
  249. struct drm_display_mode *adjusted_mode);
  250. void drm_bridge_pre_enable(struct drm_bridge *bridge);
  251. void drm_bridge_enable(struct drm_bridge *bridge);
  252. #ifdef CONFIG_DRM_PANEL_BRIDGE
  253. struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel,
  254. u32 connector_type);
  255. void drm_panel_bridge_remove(struct drm_bridge *bridge);
  256. struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
  257. struct drm_panel *panel,
  258. u32 connector_type);
  259. #endif
  260. #endif