drm_bridge.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  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. * NOTE:
  167. *
  168. * This is deprecated, do not use!
  169. * New drivers shall use &drm_bridge_funcs.atomic_disable.
  170. */
  171. void (*disable)(struct drm_bridge *bridge);
  172. /**
  173. * @post_disable:
  174. *
  175. * This callback should disable the bridge. It is called right after the
  176. * preceding element in the display pipe is disabled. If the preceding
  177. * element is a bridge this means it's called after that bridge's
  178. * @post_disable function. If the preceding element is a &drm_encoder
  179. * it's called right after the encoder's
  180. * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
  181. * or &drm_encoder_helper_funcs.dpms hook.
  182. *
  183. * The bridge must assume that the display pipe (i.e. clocks and timing
  184. * singals) feeding it is no longer running when this callback is
  185. * called.
  186. *
  187. * The @post_disable callback is optional.
  188. *
  189. * NOTE:
  190. *
  191. * This is deprecated, do not use!
  192. * New drivers shall use &drm_bridge_funcs.atomic_post_disable.
  193. */
  194. void (*post_disable)(struct drm_bridge *bridge);
  195. /**
  196. * @mode_set:
  197. *
  198. * This callback should set the given mode on the bridge. It is called
  199. * after the @mode_set callback for the preceding element in the display
  200. * pipeline has been called already. If the bridge is the first element
  201. * then this would be &drm_encoder_helper_funcs.mode_set. The display
  202. * pipe (i.e. clocks and timing signals) is off when this function is
  203. * called.
  204. *
  205. * The adjusted_mode parameter is the mode output by the CRTC for the
  206. * first bridge in the chain. It can be different from the mode
  207. * parameter that contains the desired mode for the connector at the end
  208. * of the bridges chain, for instance when the first bridge in the chain
  209. * performs scaling. The adjusted mode is mostly useful for the first
  210. * bridge in the chain and is likely irrelevant for the other bridges.
  211. *
  212. * For atomic drivers the adjusted_mode is the mode stored in
  213. * &drm_crtc_state.adjusted_mode.
  214. *
  215. * NOTE:
  216. *
  217. * This is deprecated, do not use!
  218. * New drivers shall set their mode in the
  219. * &drm_bridge_funcs.atomic_enable operation.
  220. */
  221. void (*mode_set)(struct drm_bridge *bridge,
  222. const struct drm_display_mode *mode,
  223. const struct drm_display_mode *adjusted_mode);
  224. /**
  225. * @pre_enable:
  226. *
  227. * This callback should enable the bridge. It is called right before
  228. * the preceding element in the display pipe is enabled. If the
  229. * preceding element is a bridge this means it's called before that
  230. * bridge's @pre_enable function. If the preceding element is a
  231. * &drm_encoder it's called right before the encoder's
  232. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  233. * &drm_encoder_helper_funcs.dpms hook.
  234. *
  235. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  236. * will not yet be running when this callback is called. The bridge must
  237. * not enable the display link feeding the next bridge in the chain (if
  238. * there is one) when this callback is called.
  239. *
  240. * The @pre_enable callback is optional.
  241. *
  242. * NOTE:
  243. *
  244. * This is deprecated, do not use!
  245. * New drivers shall use &drm_bridge_funcs.atomic_pre_enable.
  246. */
  247. void (*pre_enable)(struct drm_bridge *bridge);
  248. /**
  249. * @enable:
  250. *
  251. * This callback should enable the bridge. It is called right after
  252. * the preceding element in the display pipe is enabled. If the
  253. * preceding element is a bridge this means it's called after that
  254. * bridge's @enable function. If the preceding element is a
  255. * &drm_encoder it's called right after the encoder's
  256. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  257. * &drm_encoder_helper_funcs.dpms hook.
  258. *
  259. * The bridge can assume that the display pipe (i.e. clocks and timing
  260. * signals) feeding it is running when this callback is called. This
  261. * callback must enable the display link feeding the next bridge in the
  262. * chain if there is one.
  263. *
  264. * The @enable callback is optional.
  265. *
  266. * NOTE:
  267. *
  268. * This is deprecated, do not use!
  269. * New drivers shall use &drm_bridge_funcs.atomic_enable.
  270. */
  271. void (*enable)(struct drm_bridge *bridge);
  272. /**
  273. * @atomic_pre_enable:
  274. *
  275. * This callback should enable the bridge. It is called right before
  276. * the preceding element in the display pipe is enabled. If the
  277. * preceding element is a bridge this means it's called before that
  278. * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
  279. * element is a &drm_encoder it's called right before the encoder's
  280. * &drm_encoder_helper_funcs.atomic_enable hook.
  281. *
  282. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  283. * will not yet be running when this callback is called. The bridge must
  284. * not enable the display link feeding the next bridge in the chain (if
  285. * there is one) when this callback is called.
  286. *
  287. * Note that this function will only be invoked in the context of an
  288. * atomic commit. It will not be invoked from
  289. * &drm_bridge_chain_pre_enable. It would be prudent to also provide an
  290. * implementation of @pre_enable if you are expecting driver calls into
  291. * &drm_bridge_chain_pre_enable.
  292. *
  293. * The @atomic_pre_enable callback is optional.
  294. */
  295. void (*atomic_pre_enable)(struct drm_bridge *bridge,
  296. struct drm_bridge_state *old_bridge_state);
  297. /**
  298. * @atomic_enable:
  299. *
  300. * This callback should enable the bridge. It is called right after
  301. * the preceding element in the display pipe is enabled. If the
  302. * preceding element is a bridge this means it's called after that
  303. * bridge's @atomic_enable or @enable function. If the preceding element
  304. * is a &drm_encoder it's called right after the encoder's
  305. * &drm_encoder_helper_funcs.atomic_enable hook.
  306. *
  307. * The bridge can assume that the display pipe (i.e. clocks and timing
  308. * signals) feeding it is running when this callback is called. This
  309. * callback must enable the display link feeding the next bridge in the
  310. * chain if there is one.
  311. *
  312. * Note that this function will only be invoked in the context of an
  313. * atomic commit. It will not be invoked from &drm_bridge_chain_enable.
  314. * It would be prudent to also provide an implementation of @enable if
  315. * you are expecting driver calls into &drm_bridge_chain_enable.
  316. *
  317. * The @atomic_enable callback is optional.
  318. */
  319. void (*atomic_enable)(struct drm_bridge *bridge,
  320. struct drm_bridge_state *old_bridge_state);
  321. /**
  322. * @atomic_disable:
  323. *
  324. * This callback should disable the bridge. It is called right before
  325. * the preceding element in the display pipe is disabled. If the
  326. * preceding element is a bridge this means it's called before that
  327. * bridge's @atomic_disable or @disable vfunc. If the preceding element
  328. * is a &drm_encoder it's called right before the
  329. * &drm_encoder_helper_funcs.atomic_disable hook.
  330. *
  331. * The bridge can assume that the display pipe (i.e. clocks and timing
  332. * signals) feeding it is still running when this callback is called.
  333. *
  334. * Note that this function will only be invoked in the context of an
  335. * atomic commit. It will not be invoked from
  336. * &drm_bridge_chain_disable. It would be prudent to also provide an
  337. * implementation of @disable if you are expecting driver calls into
  338. * &drm_bridge_chain_disable.
  339. *
  340. * The @atomic_disable callback is optional.
  341. */
  342. void (*atomic_disable)(struct drm_bridge *bridge,
  343. struct drm_bridge_state *old_bridge_state);
  344. /**
  345. * @atomic_post_disable:
  346. *
  347. * This callback should disable the bridge. It is called right after the
  348. * preceding element in the display pipe is disabled. If the preceding
  349. * element is a bridge this means it's called after that bridge's
  350. * @atomic_post_disable or @post_disable function. If the preceding
  351. * element is a &drm_encoder it's called right after the encoder's
  352. * &drm_encoder_helper_funcs.atomic_disable hook.
  353. *
  354. * The bridge must assume that the display pipe (i.e. clocks and timing
  355. * signals) feeding it is no longer running when this callback is
  356. * called.
  357. *
  358. * Note that this function will only be invoked in the context of an
  359. * atomic commit. It will not be invoked from
  360. * &drm_bridge_chain_post_disable.
  361. * It would be prudent to also provide an implementation of
  362. * @post_disable if you are expecting driver calls into
  363. * &drm_bridge_chain_post_disable.
  364. *
  365. * The @atomic_post_disable callback is optional.
  366. */
  367. void (*atomic_post_disable)(struct drm_bridge *bridge,
  368. struct drm_bridge_state *old_bridge_state);
  369. /**
  370. * @atomic_duplicate_state:
  371. *
  372. * Duplicate the current bridge state object (which is guaranteed to be
  373. * non-NULL).
  374. *
  375. * The atomic_duplicate_state hook is mandatory if the bridge
  376. * implements any of the atomic hooks, and should be left unassigned
  377. * otherwise. For bridges that don't subclass &drm_bridge_state, the
  378. * drm_atomic_helper_bridge_duplicate_state() helper function shall be
  379. * used to implement this hook.
  380. *
  381. * RETURNS:
  382. * A valid drm_bridge_state object or NULL if the allocation fails.
  383. */
  384. struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
  385. /**
  386. * @atomic_destroy_state:
  387. *
  388. * Destroy a bridge state object previously allocated by
  389. * &drm_bridge_funcs.atomic_duplicate_state().
  390. *
  391. * The atomic_destroy_state hook is mandatory if the bridge implements
  392. * any of the atomic hooks, and should be left unassigned otherwise.
  393. * For bridges that don't subclass &drm_bridge_state, the
  394. * drm_atomic_helper_bridge_destroy_state() helper function shall be
  395. * used to implement this hook.
  396. */
  397. void (*atomic_destroy_state)(struct drm_bridge *bridge,
  398. struct drm_bridge_state *state);
  399. /**
  400. * @atomic_get_output_bus_fmts:
  401. *
  402. * Return the supported bus formats on the output end of a bridge.
  403. * The returned array must be allocated with kmalloc() and will be
  404. * freed by the caller. If the allocation fails, NULL should be
  405. * returned. num_output_fmts must be set to the returned array size.
  406. * Formats listed in the returned array should be listed in decreasing
  407. * preference order (the core will try all formats until it finds one
  408. * that works).
  409. *
  410. * This method is only called on the last element of the bridge chain
  411. * as part of the bus format negotiation process that happens in
  412. * &drm_atomic_bridge_chain_select_bus_fmts().
  413. * This method is optional. When not implemented, the core will
  414. * fall back to &drm_connector.display_info.bus_formats[0] if
  415. * &drm_connector.display_info.num_bus_formats > 0,
  416. * or to MEDIA_BUS_FMT_FIXED otherwise.
  417. */
  418. u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
  419. struct drm_bridge_state *bridge_state,
  420. struct drm_crtc_state *crtc_state,
  421. struct drm_connector_state *conn_state,
  422. unsigned int *num_output_fmts);
  423. /**
  424. * @atomic_get_input_bus_fmts:
  425. *
  426. * Return the supported bus formats on the input end of a bridge for
  427. * a specific output bus format.
  428. *
  429. * The returned array must be allocated with kmalloc() and will be
  430. * freed by the caller. If the allocation fails, NULL should be
  431. * returned. num_input_fmts must be set to the returned array size.
  432. * Formats listed in the returned array should be listed in decreasing
  433. * preference order (the core will try all formats until it finds one
  434. * that works). When the format is not supported NULL should be
  435. * returned and num_input_fmts should be set to 0.
  436. *
  437. * This method is called on all elements of the bridge chain as part of
  438. * the bus format negotiation process that happens in
  439. * drm_atomic_bridge_chain_select_bus_fmts().
  440. * This method is optional. When not implemented, the core will bypass
  441. * bus format negotiation on this element of the bridge without
  442. * failing, and the previous element in the chain will be passed
  443. * MEDIA_BUS_FMT_FIXED as its output bus format.
  444. *
  445. * Bridge drivers that need to support being linked to bridges that are
  446. * not supporting bus format negotiation should handle the
  447. * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
  448. * sensible default value or extracting this information from somewhere
  449. * else (FW property, &drm_display_mode, &drm_display_info, ...)
  450. *
  451. * Note: Even if input format selection on the first bridge has no
  452. * impact on the negotiation process (bus format negotiation stops once
  453. * we reach the first element of the chain), drivers are expected to
  454. * return accurate input formats as the input format may be used to
  455. * configure the CRTC output appropriately.
  456. */
  457. u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
  458. struct drm_bridge_state *bridge_state,
  459. struct drm_crtc_state *crtc_state,
  460. struct drm_connector_state *conn_state,
  461. u32 output_fmt,
  462. unsigned int *num_input_fmts);
  463. /**
  464. * @atomic_check:
  465. *
  466. * This method is responsible for checking bridge state correctness.
  467. * It can also check the state of the surrounding components in chain
  468. * to make sure the whole pipeline can work properly.
  469. *
  470. * &drm_bridge_funcs.atomic_check() hooks are called in reverse
  471. * order (from the last to the first bridge).
  472. *
  473. * This method is optional. &drm_bridge_funcs.mode_fixup() is not
  474. * called when &drm_bridge_funcs.atomic_check() is implemented, so only
  475. * one of them should be provided.
  476. *
  477. * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
  478. * &drm_bridge_state.output_bus_cfg.flags it should happen in
  479. * this function. By default the &drm_bridge_state.output_bus_cfg.flags
  480. * field is set to the next bridge
  481. * &drm_bridge_state.input_bus_cfg.flags value or
  482. * &drm_connector.display_info.bus_flags if the bridge is the last
  483. * element in the chain.
  484. *
  485. * RETURNS:
  486. * zero if the check passed, a negative error code otherwise.
  487. */
  488. int (*atomic_check)(struct drm_bridge *bridge,
  489. struct drm_bridge_state *bridge_state,
  490. struct drm_crtc_state *crtc_state,
  491. struct drm_connector_state *conn_state);
  492. /**
  493. * @atomic_reset:
  494. *
  495. * Reset the bridge to a predefined state (or retrieve its current
  496. * state) and return a &drm_bridge_state object matching this state.
  497. * This function is called at attach time.
  498. *
  499. * The atomic_reset hook is mandatory if the bridge implements any of
  500. * the atomic hooks, and should be left unassigned otherwise. For
  501. * bridges that don't subclass &drm_bridge_state, the
  502. * drm_atomic_helper_bridge_reset() helper function shall be used to
  503. * implement this hook.
  504. *
  505. * Note that the atomic_reset() semantics is not exactly matching the
  506. * reset() semantics found on other components (connector, plane, ...).
  507. *
  508. * 1. The reset operation happens when the bridge is attached, not when
  509. * drm_mode_config_reset() is called
  510. * 2. It's meant to be used exclusively on bridges that have been
  511. * converted to the ATOMIC API
  512. *
  513. * RETURNS:
  514. * A valid drm_bridge_state object in case of success, an ERR_PTR()
  515. * giving the reason of the failure otherwise.
  516. */
  517. struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
  518. /**
  519. * @detect:
  520. *
  521. * Check if anything is attached to the bridge output.
  522. *
  523. * This callback is optional, if not implemented the bridge will be
  524. * considered as always having a component attached to its output.
  525. * Bridges that implement this callback shall set the
  526. * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.
  527. *
  528. * RETURNS:
  529. *
  530. * drm_connector_status indicating the bridge output status.
  531. */
  532. enum drm_connector_status (*detect)(struct drm_bridge *bridge);
  533. /**
  534. * @get_modes:
  535. *
  536. * Fill all modes currently valid for the sink into the &drm_connector
  537. * with drm_mode_probed_add().
  538. *
  539. * The @get_modes callback is mostly intended to support non-probeable
  540. * displays such as many fixed panels. Bridges that support reading
  541. * EDID shall leave @get_modes unimplemented and implement the
  542. * &drm_bridge_funcs->get_edid callback instead.
  543. *
  544. * This callback is optional. Bridges that implement it shall set the
  545. * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.
  546. *
  547. * The connector parameter shall be used for the sole purpose of
  548. * filling modes, and shall not be stored internally by bridge drivers
  549. * for future usage.
  550. *
  551. * RETURNS:
  552. *
  553. * The number of modes added by calling drm_mode_probed_add().
  554. */
  555. int (*get_modes)(struct drm_bridge *bridge,
  556. struct drm_connector *connector);
  557. /**
  558. * @get_edid:
  559. *
  560. * Read and parse the EDID data of the connected display.
  561. *
  562. * The @get_edid callback is the preferred way of reporting mode
  563. * information for a display connected to the bridge output. Bridges
  564. * that support reading EDID shall implement this callback and leave
  565. * the @get_modes callback unimplemented.
  566. *
  567. * The caller of this operation shall first verify the output
  568. * connection status and refrain from reading EDID from a disconnected
  569. * output.
  570. *
  571. * This callback is optional. Bridges that implement it shall set the
  572. * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.
  573. *
  574. * The connector parameter shall be used for the sole purpose of EDID
  575. * retrieval and parsing, and shall not be stored internally by bridge
  576. * drivers for future usage.
  577. *
  578. * RETURNS:
  579. *
  580. * An edid structure newly allocated with kmalloc() (or similar) on
  581. * success, or NULL otherwise. The caller is responsible for freeing
  582. * the returned edid structure with kfree().
  583. */
  584. struct edid *(*get_edid)(struct drm_bridge *bridge,
  585. struct drm_connector *connector);
  586. /**
  587. * @hpd_notify:
  588. *
  589. * Notify the bridge of hot plug detection.
  590. *
  591. * This callback is optional, it may be implemented by bridges that
  592. * need to be notified of display connection or disconnection for
  593. * internal reasons. One use case is to reset the internal state of CEC
  594. * controllers for HDMI bridges.
  595. */
  596. void (*hpd_notify)(struct drm_bridge *bridge,
  597. enum drm_connector_status status);
  598. /**
  599. * @hpd_enable:
  600. *
  601. * Enable hot plug detection. From now on the bridge shall call
  602. * drm_bridge_hpd_notify() each time a change is detected in the output
  603. * connection status, until hot plug detection gets disabled with
  604. * @hpd_disable.
  605. *
  606. * This callback is optional and shall only be implemented by bridges
  607. * that support hot-plug notification without polling. Bridges that
  608. * implement it shall also implement the @hpd_disable callback and set
  609. * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
  610. */
  611. void (*hpd_enable)(struct drm_bridge *bridge);
  612. /**
  613. * @hpd_disable:
  614. *
  615. * Disable hot plug detection. Once this function returns the bridge
  616. * shall not call drm_bridge_hpd_notify() when a change in the output
  617. * connection status occurs.
  618. *
  619. * This callback is optional and shall only be implemented by bridges
  620. * that support hot-plug notification without polling. Bridges that
  621. * implement it shall also implement the @hpd_enable callback and set
  622. * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
  623. */
  624. void (*hpd_disable)(struct drm_bridge *bridge);
  625. /**
  626. * @debugfs_init:
  627. *
  628. * Allows bridges to create bridge-specific debugfs files.
  629. */
  630. void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root);
  631. };
  632. /**
  633. * struct drm_bridge_timings - timing information for the bridge
  634. */
  635. struct drm_bridge_timings {
  636. /**
  637. * @input_bus_flags:
  638. *
  639. * Tells what additional settings for the pixel data on the bus
  640. * this bridge requires (like pixel signal polarity). See also
  641. * &drm_display_info->bus_flags.
  642. */
  643. u32 input_bus_flags;
  644. /**
  645. * @setup_time_ps:
  646. *
  647. * Defines the time in picoseconds the input data lines must be
  648. * stable before the clock edge.
  649. */
  650. u32 setup_time_ps;
  651. /**
  652. * @hold_time_ps:
  653. *
  654. * Defines the time in picoseconds taken for the bridge to sample the
  655. * input signal after the clock edge.
  656. */
  657. u32 hold_time_ps;
  658. /**
  659. * @dual_link:
  660. *
  661. * True if the bus operates in dual-link mode. The exact meaning is
  662. * dependent on the bus type. For LVDS buses, this indicates that even-
  663. * and odd-numbered pixels are received on separate links.
  664. */
  665. bool dual_link;
  666. };
  667. /**
  668. * enum drm_bridge_ops - Bitmask of operations supported by the bridge
  669. */
  670. enum drm_bridge_ops {
  671. /**
  672. * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to
  673. * its output. Bridges that set this flag shall implement the
  674. * &drm_bridge_funcs->detect callback.
  675. */
  676. DRM_BRIDGE_OP_DETECT = BIT(0),
  677. /**
  678. * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display
  679. * connected to its output. Bridges that set this flag shall implement
  680. * the &drm_bridge_funcs->get_edid callback.
  681. */
  682. DRM_BRIDGE_OP_EDID = BIT(1),
  683. /**
  684. * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug
  685. * without requiring polling. Bridges that set this flag shall
  686. * implement the &drm_bridge_funcs->hpd_enable and
  687. * &drm_bridge_funcs->hpd_disable callbacks if they support enabling
  688. * and disabling hot-plug detection dynamically.
  689. */
  690. DRM_BRIDGE_OP_HPD = BIT(2),
  691. /**
  692. * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported
  693. * by the display at its output. This does not include reading EDID
  694. * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set
  695. * this flag shall implement the &drm_bridge_funcs->get_modes callback.
  696. */
  697. DRM_BRIDGE_OP_MODES = BIT(3),
  698. };
  699. /**
  700. * struct drm_bridge - central DRM bridge control structure
  701. */
  702. struct drm_bridge {
  703. /** @base: inherit from &drm_private_object */
  704. struct drm_private_obj base;
  705. /** @dev: DRM device this bridge belongs to */
  706. struct drm_device *dev;
  707. /** @encoder: encoder to which this bridge is connected */
  708. struct drm_encoder *encoder;
  709. /** @chain_node: used to form a bridge chain */
  710. struct list_head chain_node;
  711. #ifdef CONFIG_OF
  712. /** @of_node: device node pointer to the bridge */
  713. struct device_node *of_node;
  714. #endif
  715. /** @list: to keep track of all added bridges */
  716. struct list_head list;
  717. /**
  718. * @timings:
  719. *
  720. * the timing specification for the bridge, if any (may be NULL)
  721. */
  722. const struct drm_bridge_timings *timings;
  723. /** @funcs: control functions */
  724. const struct drm_bridge_funcs *funcs;
  725. /** @driver_private: pointer to the bridge driver's internal context */
  726. void *driver_private;
  727. /** @ops: bitmask of operations supported by the bridge */
  728. enum drm_bridge_ops ops;
  729. /**
  730. * @type: Type of the connection at the bridge output
  731. * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this
  732. * identifies the type of connected display.
  733. */
  734. int type;
  735. /**
  736. * @interlace_allowed: Indicate that the bridge can handle interlaced
  737. * modes.
  738. */
  739. bool interlace_allowed;
  740. /**
  741. * @ddc: Associated I2C adapter for DDC access, if any.
  742. */
  743. struct i2c_adapter *ddc;
  744. /** private: */
  745. /**
  746. * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.
  747. */
  748. struct mutex hpd_mutex;
  749. /**
  750. * @hpd_cb: Hot plug detection callback, registered with
  751. * drm_bridge_hpd_enable().
  752. */
  753. void (*hpd_cb)(void *data, enum drm_connector_status status);
  754. /**
  755. * @hpd_data: Private data passed to the Hot plug detection callback
  756. * @hpd_cb.
  757. */
  758. void *hpd_data;
  759. };
  760. static inline struct drm_bridge *
  761. drm_priv_to_bridge(struct drm_private_obj *priv)
  762. {
  763. return container_of(priv, struct drm_bridge, base);
  764. }
  765. void drm_bridge_add(struct drm_bridge *bridge);
  766. int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge);
  767. void drm_bridge_remove(struct drm_bridge *bridge);
  768. int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
  769. struct drm_bridge *previous,
  770. enum drm_bridge_attach_flags flags);
  771. #ifdef CONFIG_OF
  772. struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  773. #else
  774. static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
  775. {
  776. return NULL;
  777. }
  778. #endif
  779. /**
  780. * drm_bridge_get_next_bridge() - Get the next bridge in the chain
  781. * @bridge: bridge object
  782. *
  783. * RETURNS:
  784. * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
  785. */
  786. static inline struct drm_bridge *
  787. drm_bridge_get_next_bridge(struct drm_bridge *bridge)
  788. {
  789. if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
  790. return NULL;
  791. return list_next_entry(bridge, chain_node);
  792. }
  793. /**
  794. * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
  795. * @bridge: bridge object
  796. *
  797. * RETURNS:
  798. * the previous bridge in the chain, or NULL if @bridge is the first.
  799. */
  800. static inline struct drm_bridge *
  801. drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
  802. {
  803. if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
  804. return NULL;
  805. return list_prev_entry(bridge, chain_node);
  806. }
  807. /**
  808. * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
  809. * @encoder: encoder object
  810. *
  811. * RETURNS:
  812. * the first bridge in the chain, or NULL if @encoder has no bridge attached
  813. * to it.
  814. */
  815. static inline struct drm_bridge *
  816. drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
  817. {
  818. return list_first_entry_or_null(&encoder->bridge_chain,
  819. struct drm_bridge, chain_node);
  820. }
  821. /**
  822. * drm_for_each_bridge_in_chain() - Iterate over all bridges present in a chain
  823. * @encoder: the encoder to iterate bridges on
  824. * @bridge: a bridge pointer updated to point to the current bridge at each
  825. * iteration
  826. *
  827. * Iterate over all bridges present in the bridge chain attached to @encoder.
  828. */
  829. #define drm_for_each_bridge_in_chain(encoder, bridge) \
  830. list_for_each_entry(bridge, &(encoder)->bridge_chain, chain_node)
  831. bool drm_bridge_chain_mode_fixup(struct drm_bridge *bridge,
  832. const struct drm_display_mode *mode,
  833. struct drm_display_mode *adjusted_mode);
  834. enum drm_mode_status
  835. drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
  836. const struct drm_display_info *info,
  837. const struct drm_display_mode *mode);
  838. void drm_bridge_chain_disable(struct drm_bridge *bridge);
  839. void drm_bridge_chain_post_disable(struct drm_bridge *bridge);
  840. void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
  841. const struct drm_display_mode *mode,
  842. const struct drm_display_mode *adjusted_mode);
  843. void drm_bridge_chain_pre_enable(struct drm_bridge *bridge);
  844. void drm_bridge_chain_enable(struct drm_bridge *bridge);
  845. int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
  846. struct drm_crtc_state *crtc_state,
  847. struct drm_connector_state *conn_state);
  848. void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
  849. struct drm_atomic_state *state);
  850. void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
  851. struct drm_atomic_state *state);
  852. void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
  853. struct drm_atomic_state *state);
  854. void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
  855. struct drm_atomic_state *state);
  856. u32 *
  857. drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
  858. struct drm_bridge_state *bridge_state,
  859. struct drm_crtc_state *crtc_state,
  860. struct drm_connector_state *conn_state,
  861. u32 output_fmt,
  862. unsigned int *num_input_fmts);
  863. enum drm_connector_status drm_bridge_detect(struct drm_bridge *bridge);
  864. int drm_bridge_get_modes(struct drm_bridge *bridge,
  865. struct drm_connector *connector);
  866. struct edid *drm_bridge_get_edid(struct drm_bridge *bridge,
  867. struct drm_connector *connector);
  868. void drm_bridge_hpd_enable(struct drm_bridge *bridge,
  869. void (*cb)(void *data,
  870. enum drm_connector_status status),
  871. void *data);
  872. void drm_bridge_hpd_disable(struct drm_bridge *bridge);
  873. void drm_bridge_hpd_notify(struct drm_bridge *bridge,
  874. enum drm_connector_status status);
  875. #ifdef CONFIG_DRM_PANEL_BRIDGE
  876. bool drm_bridge_is_panel(const struct drm_bridge *bridge);
  877. struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
  878. struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
  879. u32 connector_type);
  880. void drm_panel_bridge_remove(struct drm_bridge *bridge);
  881. int drm_panel_bridge_set_orientation(struct drm_connector *connector,
  882. struct drm_bridge *bridge);
  883. struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
  884. struct drm_panel *panel);
  885. struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
  886. struct drm_panel *panel,
  887. u32 connector_type);
  888. struct drm_bridge *drmm_panel_bridge_add(struct drm_device *drm,
  889. struct drm_panel *panel);
  890. struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
  891. #else
  892. static inline bool drm_bridge_is_panel(const struct drm_bridge *bridge)
  893. {
  894. return false;
  895. }
  896. static inline int drm_panel_bridge_set_orientation(struct drm_connector *connector,
  897. struct drm_bridge *bridge)
  898. {
  899. return -EINVAL;
  900. }
  901. #endif
  902. #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE)
  903. struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,
  904. u32 port, u32 endpoint);
  905. struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, struct device_node *node,
  906. u32 port, u32 endpoint);
  907. #else
  908. static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
  909. struct device_node *node,
  910. u32 port,
  911. u32 endpoint)
  912. {
  913. return ERR_PTR(-ENODEV);
  914. }
  915. static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,
  916. struct device_node *node,
  917. u32 port,
  918. u32 endpoint)
  919. {
  920. return ERR_PTR(-ENODEV);
  921. }
  922. #endif
  923. #endif