drm_bridge.h 12 KB

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