drm_bridge.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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/ctype.h>
  25. #include <linux/list.h>
  26. #include <linux/mutex.h>
  27. #include <drm/drm_atomic.h>
  28. #include <drm/drm_encoder.h>
  29. #include <drm/drm_mode_object.h>
  30. #include <drm/drm_modes.h>
  31. struct drm_bridge;
  32. struct drm_bridge_timings;
  33. struct drm_connector;
  34. struct drm_display_info;
  35. struct drm_panel;
  36. struct edid;
  37. struct i2c_adapter;
  38. /**
  39. * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach
  40. */
  41. enum drm_bridge_attach_flags {
  42. /**
  43. * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge
  44. * shall not create a drm_connector.
  45. */
  46. DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0),
  47. };
  48. /**
  49. * struct drm_bridge_funcs - drm_bridge control functions
  50. */
  51. struct drm_bridge_funcs {
  52. /**
  53. * @attach:
  54. *
  55. * This callback is invoked whenever our bridge is being attached to a
  56. * &drm_encoder. The flags argument tunes the behaviour of the attach
  57. * operation (see DRM_BRIDGE_ATTACH_*).
  58. *
  59. * The @attach callback is optional.
  60. *
  61. * RETURNS:
  62. *
  63. * Zero on success, error code on failure.
  64. */
  65. int (*attach)(struct drm_bridge *bridge,
  66. enum drm_bridge_attach_flags flags);
  67. /**
  68. * @detach:
  69. *
  70. * This callback is invoked whenever our bridge is being detached from a
  71. * &drm_encoder.
  72. *
  73. * The @detach callback is optional.
  74. */
  75. void (*detach)(struct drm_bridge *bridge);
  76. /**
  77. * @mode_valid:
  78. *
  79. * This callback is used to check if a specific mode is valid in this
  80. * bridge. This should be implemented if the bridge has some sort of
  81. * restriction in the modes it can display. For example, a given bridge
  82. * may be responsible to set a clock value. If the clock can not
  83. * produce all the values for the available modes then this callback
  84. * can be used to restrict the number of modes to only the ones that
  85. * can be displayed.
  86. *
  87. * This hook is used by the probe helpers to filter the mode list in
  88. * drm_helper_probe_single_connector_modes(), and it is used by the
  89. * atomic helpers to validate modes supplied by userspace in
  90. * drm_atomic_helper_check_modeset().
  91. *
  92. * The @mode_valid callback is optional.
  93. *
  94. * NOTE:
  95. *
  96. * Since this function is both called from the check phase of an atomic
  97. * commit, and the mode validation in the probe paths it is not allowed
  98. * to look at anything else but the passed-in mode, and validate it
  99. * against configuration-invariant hardward constraints. Any further
  100. * limits which depend upon the configuration can only be checked in
  101. * @mode_fixup.
  102. *
  103. * RETURNS:
  104. *
  105. * drm_mode_status Enum
  106. */
  107. enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
  108. const struct drm_display_info *info,
  109. const struct drm_display_mode *mode);
  110. /**
  111. * @mode_fixup:
  112. *
  113. * This callback is used to validate and adjust a mode. The parameter
  114. * mode is the display mode that should be fed to the next element in
  115. * the display chain, either the final &drm_connector or the next
  116. * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
  117. * requires. It can be modified by this callback and does not need to
  118. * match mode. See also &drm_crtc_state.adjusted_mode for more details.
  119. *
  120. * This is the only hook that allows a bridge to reject a modeset. If
  121. * this function passes all other callbacks must succeed for this
  122. * configuration.
  123. *
  124. * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()
  125. * is not called when &drm_bridge_funcs.atomic_check() is implemented,
  126. * so only one of them should be provided.
  127. *
  128. * NOTE:
  129. *
  130. * This function is called in the check phase of atomic modesets, which
  131. * can be aborted for any reason (including on userspace's request to
  132. * just check whether a configuration would be possible). Drivers MUST
  133. * NOT touch any persistent state (hardware or software) or data
  134. * structures except the passed in @state parameter.
  135. *
  136. * Also beware that userspace can request its own custom modes, neither
  137. * core nor helpers filter modes to the list of probe modes reported by
  138. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  139. * that modes are filtered consistently put any bridge constraints and
  140. * limits checks into @mode_valid.
  141. *
  142. * RETURNS:
  143. *
  144. * True if an acceptable configuration is possible, false if the modeset
  145. * operation should be rejected.
  146. */
  147. bool (*mode_fixup)(struct drm_bridge *bridge,
  148. const struct drm_display_mode *mode,
  149. struct drm_display_mode *adjusted_mode);
  150. /**
  151. * @disable:
  152. *
  153. * This callback should disable the bridge. It is called right before
  154. * the preceding element in the display pipe is disabled. If the
  155. * preceding element is a bridge this means it's called before that
  156. * bridge's @disable vfunc. If the preceding element is a &drm_encoder
  157. * it's called right before the &drm_encoder_helper_funcs.disable,
  158. * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
  159. * hook.
  160. *
  161. * The bridge can assume that the display pipe (i.e. clocks and timing
  162. * signals) feeding it is still running when this callback is called.
  163. *
  164. * The @disable callback is optional.
  165. */
  166. void (*disable)(struct drm_bridge *bridge);
  167. /**
  168. * @post_disable:
  169. *
  170. * This callback should disable the bridge. It is called right after the
  171. * preceding element in the display pipe is disabled. If the preceding
  172. * element is a bridge this means it's called after that bridge's
  173. * @post_disable function. If the preceding element is a &drm_encoder
  174. * it's called right after the encoder's
  175. * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
  176. * or &drm_encoder_helper_funcs.dpms hook.
  177. *
  178. * The bridge must assume that the display pipe (i.e. clocks and timing
  179. * singals) feeding it is no longer running when this callback is
  180. * called.
  181. *
  182. * The @post_disable callback is optional.
  183. */
  184. void (*post_disable)(struct drm_bridge *bridge);
  185. /**
  186. * @mode_set:
  187. *
  188. * This callback should set the given mode on the bridge. It is called
  189. * after the @mode_set callback for the preceding element in the display
  190. * pipeline has been called already. If the bridge is the first element
  191. * then this would be &drm_encoder_helper_funcs.mode_set. The display
  192. * pipe (i.e. clocks and timing signals) is off when this function is
  193. * called.
  194. *
  195. * The adjusted_mode parameter is the mode output by the CRTC for the
  196. * first bridge in the chain. It can be different from the mode
  197. * parameter that contains the desired mode for the connector at the end
  198. * of the bridges chain, for instance when the first bridge in the chain
  199. * performs scaling. The adjusted mode is mostly useful for the first
  200. * bridge in the chain and is likely irrelevant for the other bridges.
  201. *
  202. * For atomic drivers the adjusted_mode is the mode stored in
  203. * &drm_crtc_state.adjusted_mode.
  204. *
  205. * NOTE:
  206. *
  207. * If a need arises to store and access modes adjusted for other
  208. * locations than the connection between the CRTC and the first bridge,
  209. * the DRM framework will have to be extended with DRM bridge states.
  210. */
  211. void (*mode_set)(struct drm_bridge *bridge,
  212. const struct drm_display_mode *mode,
  213. const struct drm_display_mode *adjusted_mode);
  214. /**
  215. * @pre_enable:
  216. *
  217. * This callback should enable the bridge. It is called right before
  218. * the preceding element in the display pipe is enabled. If the
  219. * preceding element is a bridge this means it's called before that
  220. * bridge's @pre_enable function. If the preceding element is a
  221. * &drm_encoder it's called right before the encoder's
  222. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  223. * &drm_encoder_helper_funcs.dpms hook.
  224. *
  225. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  226. * will not yet be running when this callback is called. The bridge must
  227. * not enable the display link feeding the next bridge in the chain (if
  228. * there is one) when this callback is called.
  229. *
  230. * The @pre_enable callback is optional.
  231. */
  232. void (*pre_enable)(struct drm_bridge *bridge);
  233. /**
  234. * @enable:
  235. *
  236. * This callback should enable the bridge. It is called right after
  237. * the preceding element in the display pipe is enabled. If the
  238. * preceding element is a bridge this means it's called after that
  239. * bridge's @enable function. If the preceding element is a
  240. * &drm_encoder it's called right after the encoder's
  241. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  242. * &drm_encoder_helper_funcs.dpms hook.
  243. *
  244. * The bridge can assume that the display pipe (i.e. clocks and timing
  245. * signals) feeding it is running when this callback is called. This
  246. * callback must enable the display link feeding the next bridge in the
  247. * chain if there is one.
  248. *
  249. * The @enable callback is optional.
  250. */
  251. void (*enable)(struct drm_bridge *bridge);
  252. /**
  253. * @atomic_pre_enable:
  254. *
  255. * This callback should enable the bridge. It is called right before
  256. * the preceding element in the display pipe is enabled. If the
  257. * preceding element is a bridge this means it's called before that
  258. * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
  259. * element is a &drm_encoder it's called right before the encoder's
  260. * &drm_encoder_helper_funcs.atomic_enable hook.
  261. *
  262. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  263. * will not yet be running when this callback is called. The bridge must
  264. * not enable the display link feeding the next bridge in the chain (if
  265. * there is one) when this callback is called.
  266. *
  267. * Note that this function will only be invoked in the context of an
  268. * atomic commit. It will not be invoked from
  269. * &drm_bridge_chain_pre_enable. It would be prudent to also provide an
  270. * implementation of @pre_enable if you are expecting driver calls into
  271. * &drm_bridge_chain_pre_enable.
  272. *
  273. * The @atomic_pre_enable callback is optional.
  274. */
  275. void (*atomic_pre_enable)(struct drm_bridge *bridge,
  276. struct drm_bridge_state *old_bridge_state);
  277. /**
  278. * @atomic_enable:
  279. *
  280. * This callback should enable the bridge. It is called right after
  281. * the preceding element in the display pipe is enabled. If the
  282. * preceding element is a bridge this means it's called after that
  283. * bridge's @atomic_enable or @enable function. If the preceding element
  284. * is a &drm_encoder it's called right after the encoder's
  285. * &drm_encoder_helper_funcs.atomic_enable hook.
  286. *
  287. * The bridge can assume that the display pipe (i.e. clocks and timing
  288. * signals) feeding it is running when this callback is called. This
  289. * callback must enable the display link feeding the next bridge in the
  290. * chain if there is one.
  291. *
  292. * Note that this function will only be invoked in the context of an
  293. * atomic commit. It will not be invoked from &drm_bridge_chain_enable.
  294. * It would be prudent to also provide an implementation of @enable if
  295. * you are expecting driver calls into &drm_bridge_chain_enable.
  296. *
  297. * The @atomic_enable callback is optional.
  298. */
  299. void (*atomic_enable)(struct drm_bridge *bridge,
  300. struct drm_bridge_state *old_bridge_state);
  301. /**
  302. * @atomic_disable:
  303. *
  304. * This callback should disable the bridge. It is called right before
  305. * the preceding element in the display pipe is disabled. If the
  306. * preceding element is a bridge this means it's called before that
  307. * bridge's @atomic_disable or @disable vfunc. If the preceding element
  308. * is a &drm_encoder it's called right before the
  309. * &drm_encoder_helper_funcs.atomic_disable hook.
  310. *
  311. * The bridge can assume that the display pipe (i.e. clocks and timing
  312. * signals) feeding it is still running when this callback is called.
  313. *
  314. * Note that this function will only be invoked in the context of an
  315. * atomic commit. It will not be invoked from
  316. * &drm_bridge_chain_disable. It would be prudent to also provide an
  317. * implementation of @disable if you are expecting driver calls into
  318. * &drm_bridge_chain_disable.
  319. *
  320. * The @atomic_disable callback is optional.
  321. */
  322. void (*atomic_disable)(struct drm_bridge *bridge,
  323. struct drm_bridge_state *old_bridge_state);
  324. /**
  325. * @atomic_post_disable:
  326. *
  327. * This callback should disable the bridge. It is called right after the
  328. * preceding element in the display pipe is disabled. If the preceding
  329. * element is a bridge this means it's called after that bridge's
  330. * @atomic_post_disable or @post_disable function. If the preceding
  331. * element is a &drm_encoder it's called right after the encoder's
  332. * &drm_encoder_helper_funcs.atomic_disable hook.
  333. *
  334. * The bridge must assume that the display pipe (i.e. clocks and timing
  335. * signals) feeding it is no longer running when this callback is
  336. * called.
  337. *
  338. * Note that this function will only be invoked in the context of an
  339. * atomic commit. It will not be invoked from
  340. * &drm_bridge_chain_post_disable.
  341. * It would be prudent to also provide an implementation of
  342. * @post_disable if you are expecting driver calls into
  343. * &drm_bridge_chain_post_disable.
  344. *
  345. * The @atomic_post_disable callback is optional.
  346. */
  347. void (*atomic_post_disable)(struct drm_bridge *bridge,
  348. struct drm_bridge_state *old_bridge_state);
  349. /**
  350. * @atomic_duplicate_state:
  351. *
  352. * Duplicate the current bridge state object (which is guaranteed to be
  353. * non-NULL).
  354. *
  355. * The atomic_duplicate_state hook is mandatory if the bridge
  356. * implements any of the atomic hooks, and should be left unassigned
  357. * otherwise. For bridges that don't subclass &drm_bridge_state, the
  358. * drm_atomic_helper_bridge_duplicate_state() helper function shall be
  359. * used to implement this hook.
  360. *
  361. * RETURNS:
  362. * A valid drm_bridge_state object or NULL if the allocation fails.
  363. */
  364. struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
  365. /**
  366. * @atomic_destroy_state:
  367. *
  368. * Destroy a bridge state object previously allocated by
  369. * &drm_bridge_funcs.atomic_duplicate_state().
  370. *
  371. * The atomic_destroy_state hook is mandatory if the bridge implements
  372. * any of the atomic hooks, and should be left unassigned otherwise.
  373. * For bridges that don't subclass &drm_bridge_state, the
  374. * drm_atomic_helper_bridge_destroy_state() helper function shall be
  375. * used to implement this hook.
  376. */
  377. void (*atomic_destroy_state)(struct drm_bridge *bridge,
  378. struct drm_bridge_state *state);
  379. /**
  380. * @atomic_get_output_bus_fmts:
  381. *
  382. * Return the supported bus formats on the output end of a bridge.
  383. * The returned array must be allocated with kmalloc() and will be
  384. * freed by the caller. If the allocation fails, NULL should be
  385. * returned. num_output_fmts must be set to the returned array size.
  386. * Formats listed in the returned array should be listed in decreasing
  387. * preference order (the core will try all formats until it finds one
  388. * that works).
  389. *
  390. * This method is only called on the last element of the bridge chain
  391. * as part of the bus format negotiation process that happens in
  392. * &drm_atomic_bridge_chain_select_bus_fmts().
  393. * This method is optional. When not implemented, the core will
  394. * fall back to &drm_connector.display_info.bus_formats[0] if
  395. * &drm_connector.display_info.num_bus_formats > 0,
  396. * or to MEDIA_BUS_FMT_FIXED otherwise.
  397. */
  398. u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
  399. struct drm_bridge_state *bridge_state,
  400. struct drm_crtc_state *crtc_state,
  401. struct drm_connector_state *conn_state,
  402. unsigned int *num_output_fmts);
  403. /**
  404. * @atomic_get_input_bus_fmts:
  405. *
  406. * Return the supported bus formats on the input end of a bridge for
  407. * a specific output bus format.
  408. *
  409. * The returned array must be allocated with kmalloc() and will be
  410. * freed by the caller. If the allocation fails, NULL should be
  411. * returned. num_output_fmts must be set to the returned array size.
  412. * Formats listed in the returned array should be listed in decreasing
  413. * preference order (the core will try all formats until it finds one
  414. * that works). When the format is not supported NULL should be
  415. * returned and num_output_fmts should be set to 0.
  416. *
  417. * This method is called on all elements of the bridge chain as part of
  418. * the bus format negotiation process that happens in
  419. * drm_atomic_bridge_chain_select_bus_fmts().
  420. * This method is optional. When not implemented, the core will bypass
  421. * bus format negotiation on this element of the bridge without
  422. * failing, and the previous element in the chain will be passed
  423. * MEDIA_BUS_FMT_FIXED as its output bus format.
  424. *
  425. * Bridge drivers that need to support being linked to bridges that are
  426. * not supporting bus format negotiation should handle the
  427. * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
  428. * sensible default value or extracting this information from somewhere
  429. * else (FW property, &drm_display_mode, &drm_display_info, ...)
  430. *
  431. * Note: Even if input format selection on the first bridge has no
  432. * impact on the negotiation process (bus format negotiation stops once
  433. * we reach the first element of the chain), drivers are expected to
  434. * return accurate input formats as the input format may be used to
  435. * configure the CRTC output appropriately.
  436. */
  437. u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
  438. struct drm_bridge_state *bridge_state,
  439. struct drm_crtc_state *crtc_state,
  440. struct drm_connector_state *conn_state,
  441. u32 output_fmt,
  442. unsigned int *num_input_fmts);
  443. /**
  444. * @atomic_check:
  445. *
  446. * This method is responsible for checking bridge state correctness.
  447. * It can also check the state of the surrounding components in chain
  448. * to make sure the whole pipeline can work properly.
  449. *
  450. * &drm_bridge_funcs.atomic_check() hooks are called in reverse
  451. * order (from the last to the first bridge).
  452. *
  453. * This method is optional. &drm_bridge_funcs.mode_fixup() is not
  454. * called when &drm_bridge_funcs.atomic_check() is implemented, so only
  455. * one of them should be provided.
  456. *
  457. * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
  458. * &drm_bridge_state.output_bus_cfg.flags it should happen in
  459. * this function. By default the &drm_bridge_state.output_bus_cfg.flags
  460. * field is set to the next bridge
  461. * &drm_bridge_state.input_bus_cfg.flags value or
  462. * &drm_connector.display_info.bus_flags if the bridge is the last
  463. * element in the chain.
  464. *
  465. * RETURNS:
  466. * zero if the check passed, a negative error code otherwise.
  467. */
  468. int (*atomic_check)(struct drm_bridge *bridge,
  469. struct drm_bridge_state *bridge_state,
  470. struct drm_crtc_state *crtc_state,
  471. struct drm_connector_state *conn_state);
  472. /**
  473. * @atomic_reset:
  474. *
  475. * Reset the bridge to a predefined state (or retrieve its current
  476. * state) and return a &drm_bridge_state object matching this state.
  477. * This function is called at attach time.
  478. *
  479. * The atomic_reset hook is mandatory if the bridge implements any of
  480. * the atomic hooks, and should be left unassigned otherwise. For
  481. * bridges that don't subclass &drm_bridge_state, the
  482. * drm_atomic_helper_bridge_reset() helper function shall be used to
  483. * implement this hook.
  484. *
  485. * Note that the atomic_reset() semantics is not exactly matching the
  486. * reset() semantics found on other components (connector, plane, ...).
  487. *
  488. * 1. The reset operation happens when the bridge is attached, not when
  489. * drm_mode_config_reset() is called
  490. * 2. It's meant to be used exclusively on bridges that have been
  491. * converted to the ATOMIC API
  492. *
  493. * RETURNS:
  494. * A valid drm_bridge_state object in case of success, an ERR_PTR()
  495. * giving the reason of the failure otherwise.
  496. */
  497. struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
  498. /**
  499. * @detect:
  500. *
  501. * Check if anything is attached to the bridge output.
  502. *
  503. * This callback is optional, if not implemented the bridge will be
  504. * considered as always having a component attached to its output.
  505. * Bridges that implement this callback shall set the
  506. * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.
  507. *
  508. * RETURNS:
  509. *
  510. * drm_connector_status indicating the bridge output status.
  511. */
  512. enum drm_connector_status (*detect)(struct drm_bridge *bridge);
  513. /**
  514. * @get_modes:
  515. *
  516. * Fill all modes currently valid for the sink into the &drm_connector
  517. * with drm_mode_probed_add().
  518. *
  519. * The @get_modes callback is mostly intended to support non-probeable
  520. * displays such as many fixed panels. Bridges that support reading
  521. * EDID shall leave @get_modes unimplemented and implement the
  522. * &drm_bridge_funcs->get_edid callback instead.
  523. *
  524. * This callback is optional. Bridges that implement it shall set the
  525. * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.
  526. *
  527. * The connector parameter shall be used for the sole purpose of
  528. * filling modes, and shall not be stored internally by bridge drivers
  529. * for future usage.
  530. *
  531. * RETURNS:
  532. *
  533. * The number of modes added by calling drm_mode_probed_add().
  534. */
  535. int (*get_modes)(struct drm_bridge *bridge,
  536. struct drm_connector *connector);
  537. /**
  538. * @get_edid:
  539. *
  540. * Read and parse the EDID data of the connected display.
  541. *
  542. * The @get_edid callback is the preferred way of reporting mode
  543. * information for a display connected to the bridge output. Bridges
  544. * that support reading EDID shall implement this callback and leave
  545. * the @get_modes callback unimplemented.
  546. *
  547. * The caller of this operation shall first verify the output
  548. * connection status and refrain from reading EDID from a disconnected
  549. * output.
  550. *
  551. * This callback is optional. Bridges that implement it shall set the
  552. * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.
  553. *
  554. * The connector parameter shall be used for the sole purpose of EDID
  555. * retrieval and parsing, and shall not be stored internally by bridge
  556. * drivers for future usage.
  557. *
  558. * RETURNS:
  559. *
  560. * An edid structure newly allocated with kmalloc() (or similar) on
  561. * success, or NULL otherwise. The caller is responsible for freeing
  562. * the returned edid structure with kfree().
  563. */
  564. struct edid *(*get_edid)(struct drm_bridge *bridge,
  565. struct drm_connector *connector);
  566. /**
  567. * @hpd_notify:
  568. *
  569. * Notify the bridge of hot plug detection.
  570. *
  571. * This callback is optional, it may be implemented by bridges that
  572. * need to be notified of display connection or disconnection for
  573. * internal reasons. One use case is to reset the internal state of CEC
  574. * controllers for HDMI bridges.
  575. */
  576. void (*hpd_notify)(struct drm_bridge *bridge,
  577. enum drm_connector_status status);
  578. /**
  579. * @hpd_enable:
  580. *
  581. * Enable hot plug detection. From now on the bridge shall call
  582. * drm_bridge_hpd_notify() each time a change is detected in the output
  583. * connection status, until hot plug detection gets disabled with
  584. * @hpd_disable.
  585. *
  586. * This callback is optional and shall only be implemented by bridges
  587. * that support hot-plug notification without polling. Bridges that
  588. * implement it shall also implement the @hpd_disable callback and set
  589. * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
  590. */
  591. void (*hpd_enable)(struct drm_bridge *bridge);
  592. /**
  593. * @hpd_disable:
  594. *
  595. * Disable hot plug detection. Once this function returns the bridge
  596. * shall not call drm_bridge_hpd_notify() when a change in the output
  597. * connection status occurs.
  598. *
  599. * This callback is optional and shall only be implemented by bridges
  600. * that support hot-plug notification without polling. Bridges that
  601. * implement it shall also implement the @hpd_enable callback and set
  602. * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
  603. */
  604. void (*hpd_disable)(struct drm_bridge *bridge);
  605. };
  606. /**
  607. * struct drm_bridge_timings - timing information for the bridge
  608. */
  609. struct drm_bridge_timings {
  610. /**
  611. * @input_bus_flags:
  612. *
  613. * Tells what additional settings for the pixel data on the bus
  614. * this bridge requires (like pixel signal polarity). See also
  615. * &drm_display_info->bus_flags.
  616. */
  617. u32 input_bus_flags;
  618. /**
  619. * @setup_time_ps:
  620. *
  621. * Defines the time in picoseconds the input data lines must be
  622. * stable before the clock edge.
  623. */
  624. u32 setup_time_ps;
  625. /**
  626. * @hold_time_ps:
  627. *
  628. * Defines the time in picoseconds taken for the bridge to sample the
  629. * input signal after the clock edge.
  630. */
  631. u32 hold_time_ps;
  632. /**
  633. * @dual_link:
  634. *
  635. * True if the bus operates in dual-link mode. The exact meaning is
  636. * dependent on the bus type. For LVDS buses, this indicates that even-
  637. * and odd-numbered pixels are received on separate links.
  638. */
  639. bool dual_link;
  640. };
  641. /**
  642. * enum drm_bridge_ops - Bitmask of operations supported by the bridge
  643. */
  644. enum drm_bridge_ops {
  645. /**
  646. * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to
  647. * its output. Bridges that set this flag shall implement the
  648. * &drm_bridge_funcs->detect callback.
  649. */
  650. DRM_BRIDGE_OP_DETECT = BIT(0),
  651. /**
  652. * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display
  653. * connected to its output. Bridges that set this flag shall implement
  654. * the &drm_bridge_funcs->get_edid callback.
  655. */
  656. DRM_BRIDGE_OP_EDID = BIT(1),
  657. /**
  658. * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug
  659. * without requiring polling. Bridges that set this flag shall
  660. * implement the &drm_bridge_funcs->hpd_enable and
  661. * &drm_bridge_funcs->hpd_disable callbacks if they support enabling
  662. * and disabling hot-plug detection dynamically.
  663. */
  664. DRM_BRIDGE_OP_HPD = BIT(2),
  665. /**
  666. * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported
  667. * by the display at its output. This does not include reading EDID
  668. * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set
  669. * this flag shall implement the &drm_bridge_funcs->get_modes callback.
  670. */
  671. DRM_BRIDGE_OP_MODES = BIT(3),
  672. };
  673. /**
  674. * struct drm_bridge - central DRM bridge control structure
  675. */
  676. struct drm_bridge {
  677. /** @base: inherit from &drm_private_object */
  678. struct drm_private_obj base;
  679. /** @dev: DRM device this bridge belongs to */
  680. struct drm_device *dev;
  681. /** @encoder: encoder to which this bridge is connected */
  682. struct drm_encoder *encoder;
  683. /** @chain_node: used to form a bridge chain */
  684. struct list_head chain_node;
  685. #ifdef CONFIG_OF
  686. /** @of_node: device node pointer to the bridge */
  687. struct device_node *of_node;
  688. #endif
  689. /** @list: to keep track of all added bridges */
  690. struct list_head list;
  691. /**
  692. * @timings:
  693. *
  694. * the timing specification for the bridge, if any (may be NULL)
  695. */
  696. const struct drm_bridge_timings *timings;
  697. /** @funcs: control functions */
  698. const struct drm_bridge_funcs *funcs;
  699. /** @driver_private: pointer to the bridge driver's internal context */
  700. void *driver_private;
  701. /** @ops: bitmask of operations supported by the bridge */
  702. enum drm_bridge_ops ops;
  703. /**
  704. * @type: Type of the connection at the bridge output
  705. * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this
  706. * identifies the type of connected display.
  707. */
  708. int type;
  709. /**
  710. * @interlace_allowed: Indicate that the bridge can handle interlaced
  711. * modes.
  712. */
  713. bool interlace_allowed;
  714. /**
  715. * @ddc: Associated I2C adapter for DDC access, if any.
  716. */
  717. struct i2c_adapter *ddc;
  718. /** private: */
  719. /**
  720. * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.
  721. */
  722. struct mutex hpd_mutex;
  723. /**
  724. * @hpd_cb: Hot plug detection callback, registered with
  725. * drm_bridge_hpd_enable().
  726. */
  727. void (*hpd_cb)(void *data, enum drm_connector_status status);
  728. /**
  729. * @hpd_data: Private data passed to the Hot plug detection callback
  730. * @hpd_cb.
  731. */
  732. void *hpd_data;
  733. };
  734. static inline struct drm_bridge *
  735. drm_priv_to_bridge(struct drm_private_obj *priv)
  736. {
  737. return container_of(priv, struct drm_bridge, base);
  738. }
  739. void drm_bridge_add(struct drm_bridge *bridge);
  740. void drm_bridge_remove(struct drm_bridge *bridge);
  741. struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  742. int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
  743. struct drm_bridge *previous,
  744. enum drm_bridge_attach_flags flags);
  745. /**
  746. * drm_bridge_get_next_bridge() - Get the next bridge in the chain
  747. * @bridge: bridge object
  748. *
  749. * RETURNS:
  750. * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
  751. */
  752. static inline struct drm_bridge *
  753. drm_bridge_get_next_bridge(struct drm_bridge *bridge)
  754. {
  755. if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
  756. return NULL;
  757. return list_next_entry(bridge, chain_node);
  758. }
  759. /**
  760. * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
  761. * @bridge: bridge object
  762. *
  763. * RETURNS:
  764. * the previous bridge in the chain, or NULL if @bridge is the first.
  765. */
  766. static inline struct drm_bridge *
  767. drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
  768. {
  769. if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
  770. return NULL;
  771. return list_prev_entry(bridge, chain_node);
  772. }
  773. /**
  774. * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
  775. * @encoder: encoder object
  776. *
  777. * RETURNS:
  778. * the first bridge in the chain, or NULL if @encoder has no bridge attached
  779. * to it.
  780. */
  781. static inline struct drm_bridge *
  782. drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
  783. {
  784. return list_first_entry_or_null(&encoder->bridge_chain,
  785. struct drm_bridge, chain_node);
  786. }
  787. /**
  788. * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain
  789. * @encoder: the encoder to iterate bridges on
  790. * @bridge: a bridge pointer updated to point to the current bridge at each
  791. * iteration
  792. *
  793. * Iterate over all bridges present in the bridge chain attached to @encoder.
  794. */
  795. #define drm_for_each_bridge_in_chain(encoder, bridge) \
  796. list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node)
  797. bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
  798. const struct drm_display_mode *mode,
  799. struct drm_display_mode *adjusted_mode);
  800. enum drm_mode_status
  801. drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
  802. const struct drm_display_info *info,
  803. const struct drm_display_mode *mode);
  804. void drm_bridge_chain_disable(struct drm_bridge *bridge);
  805. void drm_bridge_chain_post_disable(struct drm_bridge *bridge);
  806. void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
  807. const struct drm_display_mode *mode,
  808. const struct drm_display_mode *adjusted_mode);
  809. void drm_bridge_chain_pre_enable(struct drm_bridge *bridge);
  810. void drm_bridge_chain_enable(struct drm_bridge *bridge);
  811. int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
  812. struct drm_crtc_state *crtc_state,
  813. struct drm_connector_state *conn_state);
  814. void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
  815. struct drm_atomic_state *state);
  816. void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
  817. struct drm_atomic_state *state);
  818. void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
  819. struct drm_atomic_state *state);
  820. void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
  821. struct drm_atomic_state *state);
  822. u32 *
  823. drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
  824. struct drm_bridge_state *bridge_state,
  825. struct drm_crtc_state *crtc_state,
  826. struct drm_connector_state *conn_state,
  827. u32 output_fmt,
  828. unsigned int *num_input_fmts);
  829. enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge);
  830. int drm_bridge_get_modes(struct drm_bridge *bridge,
  831. struct drm_connector *connector);
  832. struct edid *drm_bridge_get_edid(struct drm_bridge *bridge,
  833. struct drm_connector *connector);
  834. void drm_bridge_hpd_enable(struct drm_bridge *bridge,
  835. void (*cb)(void *data,
  836. enum drm_connector_status status),
  837. void *data);
  838. void drm_bridge_hpd_disable(struct drm_bridge *bridge);
  839. void drm_bridge_hpd_notify(struct drm_bridge *bridge,
  840. enum drm_connector_status status);
  841. #ifdef CONFIG_DRM_PANEL_BRIDGE
  842. struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
  843. struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
  844. u32 connector_type);
  845. void drm_panel_bridge_remove(struct drm_bridge *bridge);
  846. struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
  847. struct drm_panel *panel);
  848. struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
  849. struct drm_panel *panel,
  850. u32 connector_type);
  851. struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
  852. #endif
  853. #endif