drm_bridge.h 36 KB

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