drm_bridge.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  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/cleanup.h>
  25. #include <linux/ctype.h>
  26. #include <linux/list.h>
  27. #include <linux/mutex.h>
  28. #include <drm/drm_atomic.h>
  29. #include <drm/drm_encoder.h>
  30. #include <drm/drm_mode_object.h>
  31. #include <drm/drm_modes.h>
  32. struct cec_msg;
  33. struct device_node;
  34. struct drm_bridge;
  35. struct drm_bridge_timings;
  36. struct drm_connector;
  37. struct drm_display_info;
  38. struct drm_minor;
  39. struct drm_panel;
  40. struct edid;
  41. struct hdmi_codec_daifmt;
  42. struct hdmi_codec_params;
  43. struct i2c_adapter;
  44. /**
  45. * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach
  46. */
  47. enum drm_bridge_attach_flags {
  48. /**
  49. * @DRM_BRIDGE_ATTACH_NO_CONNECTOR: When this flag is set the bridge
  50. * shall not create a drm_connector.
  51. */
  52. DRM_BRIDGE_ATTACH_NO_CONNECTOR = BIT(0),
  53. };
  54. /**
  55. * struct drm_bridge_funcs - drm_bridge control functions
  56. */
  57. struct drm_bridge_funcs {
  58. /**
  59. * @attach:
  60. *
  61. * This callback is invoked whenever our bridge is being attached to a
  62. * &drm_encoder. The flags argument tunes the behaviour of the attach
  63. * operation (see DRM_BRIDGE_ATTACH_*).
  64. *
  65. * The @attach callback is optional.
  66. *
  67. * RETURNS:
  68. *
  69. * Zero on success, error code on failure.
  70. */
  71. int (*attach)(struct drm_bridge *bridge, struct drm_encoder *encoder,
  72. enum drm_bridge_attach_flags flags);
  73. /**
  74. * @destroy:
  75. *
  76. * This callback is invoked when the bridge is about to be
  77. * deallocated.
  78. *
  79. * The @destroy callback is optional.
  80. */
  81. void (*destroy)(struct drm_bridge *bridge);
  82. /**
  83. * @detach:
  84. *
  85. * This callback is invoked whenever our bridge is being detached from a
  86. * &drm_encoder.
  87. *
  88. * The @detach callback is optional.
  89. */
  90. void (*detach)(struct drm_bridge *bridge);
  91. /**
  92. * @mode_valid:
  93. *
  94. * This callback is used to check if a specific mode is valid in this
  95. * bridge. This should be implemented if the bridge has some sort of
  96. * restriction in the modes it can display. For example, a given bridge
  97. * may be responsible to set a clock value. If the clock can not
  98. * produce all the values for the available modes then this callback
  99. * can be used to restrict the number of modes to only the ones that
  100. * can be displayed.
  101. *
  102. * This hook is used by the probe helpers to filter the mode list in
  103. * drm_helper_probe_single_connector_modes(), and it is used by the
  104. * atomic helpers to validate modes supplied by userspace in
  105. * drm_atomic_helper_check_modeset().
  106. *
  107. * The @mode_valid callback is optional.
  108. *
  109. * NOTE:
  110. *
  111. * Since this function is both called from the check phase of an atomic
  112. * commit, and the mode validation in the probe paths it is not allowed
  113. * to look at anything else but the passed-in mode, and validate it
  114. * against configuration-invariant hardware constraints. Any further
  115. * limits which depend upon the configuration can only be checked in
  116. * @mode_fixup.
  117. *
  118. * RETURNS:
  119. *
  120. * drm_mode_status Enum
  121. */
  122. enum drm_mode_status (*mode_valid)(struct drm_bridge *bridge,
  123. const struct drm_display_info *info,
  124. const struct drm_display_mode *mode);
  125. /**
  126. * @mode_fixup:
  127. *
  128. * This callback is used to validate and adjust a mode. The parameter
  129. * mode is the display mode that should be fed to the next element in
  130. * the display chain, either the final &drm_connector or the next
  131. * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
  132. * requires. It can be modified by this callback and does not need to
  133. * match mode. See also &drm_crtc_state.adjusted_mode for more details.
  134. *
  135. * This is the only hook that allows a bridge to reject a modeset. If
  136. * this function passes all other callbacks must succeed for this
  137. * configuration.
  138. *
  139. * The mode_fixup callback is optional. &drm_bridge_funcs.mode_fixup()
  140. * is not called when &drm_bridge_funcs.atomic_check() is implemented,
  141. * so only one of them should be provided.
  142. *
  143. * NOTE:
  144. *
  145. * This function is called in the check phase of atomic modesets, which
  146. * can be aborted for any reason (including on userspace's request to
  147. * just check whether a configuration would be possible). Drivers MUST
  148. * NOT touch any persistent state (hardware or software) or data
  149. * structures except the passed in @state parameter.
  150. *
  151. * Also beware that userspace can request its own custom modes, neither
  152. * core nor helpers filter modes to the list of probe modes reported by
  153. * the GETCONNECTOR IOCTL and stored in &drm_connector.modes. To ensure
  154. * that modes are filtered consistently put any bridge constraints and
  155. * limits checks into @mode_valid.
  156. *
  157. * RETURNS:
  158. *
  159. * True if an acceptable configuration is possible, false if the modeset
  160. * operation should be rejected.
  161. */
  162. bool (*mode_fixup)(struct drm_bridge *bridge,
  163. const struct drm_display_mode *mode,
  164. struct drm_display_mode *adjusted_mode);
  165. /**
  166. * @disable:
  167. *
  168. * This callback should disable the bridge. It is called right before
  169. * the preceding element in the display pipe is disabled. If the
  170. * preceding element is a bridge this means it's called before that
  171. * bridge's @disable vfunc. If the preceding element is a &drm_encoder
  172. * it's called right before the &drm_encoder_helper_funcs.disable,
  173. * &drm_encoder_helper_funcs.prepare or &drm_encoder_helper_funcs.dpms
  174. * hook.
  175. *
  176. * The bridge can assume that the display pipe (i.e. clocks and timing
  177. * signals) feeding it is still running when this callback is called.
  178. *
  179. * The @disable callback is optional.
  180. *
  181. * NOTE:
  182. *
  183. * This is deprecated, do not use!
  184. * New drivers shall use &drm_bridge_funcs.atomic_disable.
  185. */
  186. void (*disable)(struct drm_bridge *bridge);
  187. /**
  188. * @post_disable:
  189. *
  190. * This callback should disable the bridge. It is called right after the
  191. * preceding element in the display pipe is disabled. If the preceding
  192. * element is a bridge this means it's called after that bridge's
  193. * @post_disable function. If the preceding element is a &drm_encoder
  194. * it's called right after the encoder's
  195. * &drm_encoder_helper_funcs.disable, &drm_encoder_helper_funcs.prepare
  196. * or &drm_encoder_helper_funcs.dpms hook.
  197. *
  198. * The bridge must assume that the display pipe (i.e. clocks and timing
  199. * signals) feeding it is no longer running when this callback is
  200. * called.
  201. *
  202. * The @post_disable callback is optional.
  203. *
  204. * NOTE:
  205. *
  206. * This is deprecated, do not use!
  207. * New drivers shall use &drm_bridge_funcs.atomic_post_disable.
  208. */
  209. void (*post_disable)(struct drm_bridge *bridge);
  210. /**
  211. * @mode_set:
  212. *
  213. * This callback should set the given mode on the bridge. It is called
  214. * after the @mode_set callback for the preceding element in the display
  215. * pipeline has been called already. If the bridge is the first element
  216. * then this would be &drm_encoder_helper_funcs.mode_set. The display
  217. * pipe (i.e. clocks and timing signals) is off when this function is
  218. * called.
  219. *
  220. * The adjusted_mode parameter is the mode output by the CRTC for the
  221. * first bridge in the chain. It can be different from the mode
  222. * parameter that contains the desired mode for the connector at the end
  223. * of the bridges chain, for instance when the first bridge in the chain
  224. * performs scaling. The adjusted mode is mostly useful for the first
  225. * bridge in the chain and is likely irrelevant for the other bridges.
  226. *
  227. * For atomic drivers the adjusted_mode is the mode stored in
  228. * &drm_crtc_state.adjusted_mode.
  229. *
  230. * NOTE:
  231. *
  232. * This is deprecated, do not use!
  233. * New drivers shall set their mode in the
  234. * &drm_bridge_funcs.atomic_enable operation.
  235. */
  236. void (*mode_set)(struct drm_bridge *bridge,
  237. const struct drm_display_mode *mode,
  238. const struct drm_display_mode *adjusted_mode);
  239. /**
  240. * @pre_enable:
  241. *
  242. * This callback should enable the bridge. It is called right before
  243. * the preceding element in the display pipe is enabled. If the
  244. * preceding element is a bridge this means it's called before that
  245. * bridge's @pre_enable function. If the preceding element is a
  246. * &drm_encoder it's called right before the encoder's
  247. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  248. * &drm_encoder_helper_funcs.dpms hook.
  249. *
  250. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  251. * will not yet be running when this callback is called. The bridge must
  252. * not enable the display link feeding the next bridge in the chain (if
  253. * there is one) when this callback is called.
  254. *
  255. * The @pre_enable callback is optional.
  256. *
  257. * NOTE:
  258. *
  259. * This is deprecated, do not use!
  260. * New drivers shall use &drm_bridge_funcs.atomic_pre_enable.
  261. */
  262. void (*pre_enable)(struct drm_bridge *bridge);
  263. /**
  264. * @enable:
  265. *
  266. * This callback should enable the bridge. It is called right after
  267. * the preceding element in the display pipe is enabled. If the
  268. * preceding element is a bridge this means it's called after that
  269. * bridge's @enable function. If the preceding element is a
  270. * &drm_encoder it's called right after the encoder's
  271. * &drm_encoder_helper_funcs.enable, &drm_encoder_helper_funcs.commit or
  272. * &drm_encoder_helper_funcs.dpms hook.
  273. *
  274. * The bridge can assume that the display pipe (i.e. clocks and timing
  275. * signals) feeding it is running when this callback is called. This
  276. * callback must enable the display link feeding the next bridge in the
  277. * chain if there is one.
  278. *
  279. * The @enable callback is optional.
  280. *
  281. * NOTE:
  282. *
  283. * This is deprecated, do not use!
  284. * New drivers shall use &drm_bridge_funcs.atomic_enable.
  285. */
  286. void (*enable)(struct drm_bridge *bridge);
  287. /**
  288. * @atomic_pre_enable:
  289. *
  290. * This callback should enable the bridge. It is called right before
  291. * the preceding element in the display pipe is enabled. If the
  292. * preceding element is a bridge this means it's called before that
  293. * bridge's @atomic_pre_enable or @pre_enable function. If the preceding
  294. * element is a &drm_encoder it's called right before the encoder's
  295. * &drm_encoder_helper_funcs.atomic_enable hook.
  296. *
  297. * The display pipe (i.e. clocks and timing signals) feeding this bridge
  298. * will not yet be running when this callback is called. The bridge must
  299. * not enable the display link feeding the next bridge in the chain (if
  300. * there is one) when this callback is called.
  301. *
  302. * The @atomic_pre_enable callback is optional.
  303. */
  304. void (*atomic_pre_enable)(struct drm_bridge *bridge,
  305. struct drm_atomic_state *state);
  306. /**
  307. * @atomic_enable:
  308. *
  309. * This callback should enable the bridge. It is called right after
  310. * the preceding element in the display pipe is enabled. If the
  311. * preceding element is a bridge this means it's called after that
  312. * bridge's @atomic_enable or @enable function. If the preceding element
  313. * is a &drm_encoder it's called right after the encoder's
  314. * &drm_encoder_helper_funcs.atomic_enable hook.
  315. *
  316. * The bridge can assume that the display pipe (i.e. clocks and timing
  317. * signals) feeding it is running when this callback is called. This
  318. * callback must enable the display link feeding the next bridge in the
  319. * chain if there is one.
  320. *
  321. * The @atomic_enable callback is optional.
  322. */
  323. void (*atomic_enable)(struct drm_bridge *bridge,
  324. struct drm_atomic_state *state);
  325. /**
  326. * @atomic_disable:
  327. *
  328. * This callback should disable the bridge. It is called right before
  329. * the preceding element in the display pipe is disabled. If the
  330. * preceding element is a bridge this means it's called before that
  331. * bridge's @atomic_disable or @disable vfunc. If the preceding element
  332. * is a &drm_encoder it's called right before the
  333. * &drm_encoder_helper_funcs.atomic_disable hook.
  334. *
  335. * The bridge can assume that the display pipe (i.e. clocks and timing
  336. * signals) feeding it is still running when this callback is called.
  337. *
  338. * The @atomic_disable callback is optional.
  339. */
  340. void (*atomic_disable)(struct drm_bridge *bridge,
  341. struct drm_atomic_state *state);
  342. /**
  343. * @atomic_post_disable:
  344. *
  345. * This callback should disable the bridge. It is called right after the
  346. * preceding element in the display pipe is disabled. If the preceding
  347. * element is a bridge this means it's called after that bridge's
  348. * @atomic_post_disable or @post_disable function. If the preceding
  349. * element is a &drm_encoder it's called right after the encoder's
  350. * &drm_encoder_helper_funcs.atomic_disable hook.
  351. *
  352. * The bridge must assume that the display pipe (i.e. clocks and timing
  353. * signals) feeding it is no longer running when this callback is
  354. * called.
  355. *
  356. * The @atomic_post_disable callback is optional.
  357. */
  358. void (*atomic_post_disable)(struct drm_bridge *bridge,
  359. struct drm_atomic_state *state);
  360. /**
  361. * @atomic_duplicate_state:
  362. *
  363. * Duplicate the current bridge state object (which is guaranteed to be
  364. * non-NULL).
  365. *
  366. * The atomic_duplicate_state hook is mandatory if the bridge
  367. * implements any of the atomic hooks, and should be left unassigned
  368. * otherwise. For bridges that don't subclass &drm_bridge_state, the
  369. * drm_atomic_helper_bridge_duplicate_state() helper function shall be
  370. * used to implement this hook.
  371. *
  372. * RETURNS:
  373. * A valid drm_bridge_state object or NULL if the allocation fails.
  374. */
  375. struct drm_bridge_state *(*atomic_duplicate_state)(struct drm_bridge *bridge);
  376. /**
  377. * @atomic_destroy_state:
  378. *
  379. * Destroy a bridge state object previously allocated by
  380. * &drm_bridge_funcs.atomic_duplicate_state().
  381. *
  382. * The atomic_destroy_state hook is mandatory if the bridge implements
  383. * any of the atomic hooks, and should be left unassigned otherwise.
  384. * For bridges that don't subclass &drm_bridge_state, the
  385. * drm_atomic_helper_bridge_destroy_state() helper function shall be
  386. * used to implement this hook.
  387. */
  388. void (*atomic_destroy_state)(struct drm_bridge *bridge,
  389. struct drm_bridge_state *state);
  390. /**
  391. * @atomic_get_output_bus_fmts:
  392. *
  393. * Return the supported bus formats on the output end of a bridge.
  394. * The returned array must be allocated with kmalloc() and will be
  395. * freed by the caller. If the allocation fails, NULL should be
  396. * returned. num_output_fmts must be set to the returned array size.
  397. * Formats listed in the returned array should be listed in decreasing
  398. * preference order (the core will try all formats until it finds one
  399. * that works).
  400. *
  401. * This method is only called on the last element of the bridge chain
  402. * as part of the bus format negotiation process that happens in
  403. * &drm_atomic_bridge_chain_select_bus_fmts().
  404. * This method is optional. When not implemented, the core will
  405. * fall back to &drm_connector.display_info.bus_formats[0] if
  406. * &drm_connector.display_info.num_bus_formats > 0,
  407. * or to MEDIA_BUS_FMT_FIXED otherwise.
  408. */
  409. u32 *(*atomic_get_output_bus_fmts)(struct drm_bridge *bridge,
  410. struct drm_bridge_state *bridge_state,
  411. struct drm_crtc_state *crtc_state,
  412. struct drm_connector_state *conn_state,
  413. unsigned int *num_output_fmts);
  414. /**
  415. * @atomic_get_input_bus_fmts:
  416. *
  417. * Return the supported bus formats on the input end of a bridge for
  418. * a specific output bus format.
  419. *
  420. * The returned array must be allocated with kmalloc() and will be
  421. * freed by the caller. If the allocation fails, NULL should be
  422. * returned. num_input_fmts must be set to the returned array size.
  423. * Formats listed in the returned array should be listed in decreasing
  424. * preference order (the core will try all formats until it finds one
  425. * that works). When the format is not supported NULL should be
  426. * returned and num_input_fmts should be set to 0.
  427. *
  428. * This method is called on all elements of the bridge chain as part of
  429. * the bus format negotiation process that happens in
  430. * drm_atomic_bridge_chain_select_bus_fmts().
  431. * This method is optional. When not implemented, the core will bypass
  432. * bus format negotiation on this element of the bridge without
  433. * failing, and the previous element in the chain will be passed
  434. * MEDIA_BUS_FMT_FIXED as its output bus format.
  435. *
  436. * Bridge drivers that need to support being linked to bridges that are
  437. * not supporting bus format negotiation should handle the
  438. * output_fmt == MEDIA_BUS_FMT_FIXED case appropriately, by selecting a
  439. * sensible default value or extracting this information from somewhere
  440. * else (FW property, &drm_display_mode, &drm_display_info, ...)
  441. *
  442. * Note: Even if input format selection on the first bridge has no
  443. * impact on the negotiation process (bus format negotiation stops once
  444. * we reach the first element of the chain), drivers are expected to
  445. * return accurate input formats as the input format may be used to
  446. * configure the CRTC output appropriately.
  447. */
  448. u32 *(*atomic_get_input_bus_fmts)(struct drm_bridge *bridge,
  449. struct drm_bridge_state *bridge_state,
  450. struct drm_crtc_state *crtc_state,
  451. struct drm_connector_state *conn_state,
  452. u32 output_fmt,
  453. unsigned int *num_input_fmts);
  454. /**
  455. * @atomic_check:
  456. *
  457. * This method is responsible for checking bridge state correctness.
  458. * It can also check the state of the surrounding components in chain
  459. * to make sure the whole pipeline can work properly.
  460. *
  461. * &drm_bridge_funcs.atomic_check() hooks are called in reverse
  462. * order (from the last to the first bridge).
  463. *
  464. * This method is optional. &drm_bridge_funcs.mode_fixup() is not
  465. * called when &drm_bridge_funcs.atomic_check() is implemented, so only
  466. * one of them should be provided.
  467. *
  468. * If drivers need to tweak &drm_bridge_state.input_bus_cfg.flags or
  469. * &drm_bridge_state.output_bus_cfg.flags it should happen in
  470. * this function. By default the &drm_bridge_state.output_bus_cfg.flags
  471. * field is set to the next bridge
  472. * &drm_bridge_state.input_bus_cfg.flags value or
  473. * &drm_connector.display_info.bus_flags if the bridge is the last
  474. * element in the chain.
  475. *
  476. * RETURNS:
  477. * zero if the check passed, a negative error code otherwise.
  478. */
  479. int (*atomic_check)(struct drm_bridge *bridge,
  480. struct drm_bridge_state *bridge_state,
  481. struct drm_crtc_state *crtc_state,
  482. struct drm_connector_state *conn_state);
  483. /**
  484. * @atomic_reset:
  485. *
  486. * Reset the bridge to a predefined state (or retrieve its current
  487. * state) and return a &drm_bridge_state object matching this state.
  488. * This function is called at attach time.
  489. *
  490. * The atomic_reset hook is mandatory if the bridge implements any of
  491. * the atomic hooks, and should be left unassigned otherwise. For
  492. * bridges that don't subclass &drm_bridge_state, the
  493. * drm_atomic_helper_bridge_reset() helper function shall be used to
  494. * implement this hook.
  495. *
  496. * Note that the atomic_reset() semantics is not exactly matching the
  497. * reset() semantics found on other components (connector, plane, ...).
  498. *
  499. * 1. The reset operation happens when the bridge is attached, not when
  500. * drm_mode_config_reset() is called
  501. * 2. It's meant to be used exclusively on bridges that have been
  502. * converted to the ATOMIC API
  503. *
  504. * RETURNS:
  505. * A valid drm_bridge_state object in case of success, an ERR_PTR()
  506. * giving the reason of the failure otherwise.
  507. */
  508. struct drm_bridge_state *(*atomic_reset)(struct drm_bridge *bridge);
  509. /**
  510. * @detect:
  511. *
  512. * Check if anything is attached to the bridge output.
  513. *
  514. * This callback is optional, if not implemented the bridge will be
  515. * considered as always having a component attached to its output.
  516. * Bridges that implement this callback shall set the
  517. * DRM_BRIDGE_OP_DETECT flag in their &drm_bridge->ops.
  518. *
  519. * RETURNS:
  520. *
  521. * drm_connector_status indicating the bridge output status.
  522. */
  523. enum drm_connector_status (*detect)(struct drm_bridge *bridge,
  524. struct drm_connector *connector);
  525. /**
  526. * @get_modes:
  527. *
  528. * Fill all modes currently valid for the sink into the &drm_connector
  529. * with drm_mode_probed_add().
  530. *
  531. * The @get_modes callback is mostly intended to support non-probeable
  532. * displays such as many fixed panels. Bridges that support reading
  533. * EDID shall leave @get_modes unimplemented and implement the
  534. * &drm_bridge_funcs->edid_read callback instead.
  535. *
  536. * This callback is optional. Bridges that implement it shall set the
  537. * DRM_BRIDGE_OP_MODES flag in their &drm_bridge->ops.
  538. *
  539. * The connector parameter shall be used for the sole purpose of
  540. * filling modes, and shall not be stored internally by bridge drivers
  541. * for future usage.
  542. *
  543. * RETURNS:
  544. *
  545. * The number of modes added by calling drm_mode_probed_add().
  546. */
  547. int (*get_modes)(struct drm_bridge *bridge,
  548. struct drm_connector *connector);
  549. /**
  550. * @edid_read:
  551. *
  552. * Read the EDID data of the connected display.
  553. *
  554. * The @edid_read callback is the preferred way of reporting mode
  555. * information for a display connected to the bridge output. Bridges
  556. * that support reading EDID shall implement this callback and leave
  557. * the @get_modes callback unimplemented.
  558. *
  559. * The caller of this operation shall first verify the output
  560. * connection status and refrain from reading EDID from a disconnected
  561. * output.
  562. *
  563. * This callback is optional. Bridges that implement it shall set the
  564. * DRM_BRIDGE_OP_EDID flag in their &drm_bridge->ops.
  565. *
  566. * The connector parameter shall be used for the sole purpose of EDID
  567. * retrieval, and shall not be stored internally by bridge drivers for
  568. * future usage.
  569. *
  570. * RETURNS:
  571. *
  572. * An edid structure newly allocated with drm_edid_alloc() or returned
  573. * from drm_edid_read() family of functions on success, or NULL
  574. * otherwise. The caller is responsible for freeing the returned edid
  575. * structure with drm_edid_free().
  576. */
  577. const struct drm_edid *(*edid_read)(struct drm_bridge *bridge,
  578. struct drm_connector *connector);
  579. /**
  580. * @hpd_notify:
  581. *
  582. * Notify the bridge of hot plug detection.
  583. *
  584. * This callback is optional, it may be implemented by bridges that
  585. * need to be notified of display connection or disconnection for
  586. * internal reasons. One use case is to reset the internal state of CEC
  587. * controllers for HDMI bridges.
  588. */
  589. void (*hpd_notify)(struct drm_bridge *bridge,
  590. struct drm_connector *connector,
  591. enum drm_connector_status status);
  592. /**
  593. * @hpd_enable:
  594. *
  595. * Enable hot plug detection. From now on the bridge shall call
  596. * drm_bridge_hpd_notify() each time a change is detected in the output
  597. * connection status, until hot plug detection gets disabled with
  598. * @hpd_disable.
  599. *
  600. * This callback is optional and shall only be implemented by bridges
  601. * that support hot-plug notification without polling. Bridges that
  602. * implement it shall also implement the @hpd_disable callback and set
  603. * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
  604. */
  605. void (*hpd_enable)(struct drm_bridge *bridge);
  606. /**
  607. * @hpd_disable:
  608. *
  609. * Disable hot plug detection. Once this function returns the bridge
  610. * shall not call drm_bridge_hpd_notify() when a change in the output
  611. * connection status occurs.
  612. *
  613. * This callback is optional and shall only be implemented by bridges
  614. * that support hot-plug notification without polling. Bridges that
  615. * implement it shall also implement the @hpd_enable callback and set
  616. * the DRM_BRIDGE_OP_HPD flag in their &drm_bridge->ops.
  617. */
  618. void (*hpd_disable)(struct drm_bridge *bridge);
  619. /**
  620. * @hdmi_tmds_char_rate_valid:
  621. *
  622. * Check whether a particular TMDS character rate is supported by the
  623. * driver.
  624. *
  625. * This callback is optional and should only be implemented by the
  626. * bridges that take part in the HDMI connector implementation. Bridges
  627. * that implement it shall set the DRM_BRIDGE_OP_HDMI flag in their
  628. * &drm_bridge->ops.
  629. *
  630. * Returns:
  631. *
  632. * Either &drm_mode_status.MODE_OK or one of the failure reasons
  633. * in &enum drm_mode_status.
  634. */
  635. enum drm_mode_status
  636. (*hdmi_tmds_char_rate_valid)(const struct drm_bridge *bridge,
  637. const struct drm_display_mode *mode,
  638. unsigned long long tmds_rate);
  639. /**
  640. * @hdmi_clear_avi_infoframe:
  641. *
  642. * This callback clears the infoframes in the hardware during commit.
  643. *
  644. * This callback is optional but it must be implemented by bridges that
  645. * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
  646. */
  647. int (*hdmi_clear_avi_infoframe)(struct drm_bridge *bridge);
  648. /**
  649. * @hdmi_write_avi_infoframe:
  650. *
  651. * Program the infoframe into the hardware.
  652. *
  653. * This callback is optional but it must be implemented by bridges that
  654. * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
  655. */
  656. int (*hdmi_write_avi_infoframe)(struct drm_bridge *bridge,
  657. const u8 *buffer, size_t len);
  658. /**
  659. * @hdmi_clear_hdmi_infoframe:
  660. *
  661. * This callback clears the infoframes in the hardware during commit.
  662. *
  663. * This callback is optional but it must be implemented by bridges that
  664. * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
  665. */
  666. int (*hdmi_clear_hdmi_infoframe)(struct drm_bridge *bridge);
  667. /**
  668. * @hdmi_write_hdmi_infoframe:
  669. *
  670. * Program the infoframe into the hardware.
  671. *
  672. * This callback is optional but it must be implemented by bridges that
  673. * set the DRM_BRIDGE_OP_HDMI flag in their &drm_bridge->ops.
  674. */
  675. int (*hdmi_write_hdmi_infoframe)(struct drm_bridge *bridge,
  676. const u8 *buffer, size_t len);
  677. /**
  678. * @hdmi_clear_hdr_drm_infoframe:
  679. *
  680. * This callback clears the infoframes in the hardware during commit.
  681. *
  682. * This callback is optional but it must be implemented by bridges that
  683. * set the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in their
  684. * &drm_bridge->ops.
  685. */
  686. int (*hdmi_clear_hdr_drm_infoframe)(struct drm_bridge *bridge);
  687. /**
  688. * @hdmi_write_hdr_drm_infoframe:
  689. *
  690. * Program the infoframe into the hardware.
  691. *
  692. * This callback is optional but it must be implemented by bridges that
  693. * set the DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME flag in their
  694. * &drm_bridge->ops.
  695. */
  696. int (*hdmi_write_hdr_drm_infoframe)(struct drm_bridge *bridge,
  697. const u8 *buffer, size_t len);
  698. /**
  699. * @hdmi_clear_spd_infoframe:
  700. *
  701. * This callback clears the infoframes in the hardware during commit.
  702. *
  703. * This callback is optional but it must be implemented by bridges that
  704. * set the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in their
  705. * &drm_bridge->ops.
  706. */
  707. int (*hdmi_clear_spd_infoframe)(struct drm_bridge *bridge);
  708. /**
  709. * @hdmi_write_spd_infoframe:
  710. *
  711. * Program the infoframe into the hardware.
  712. *
  713. * This callback is optional but it must be implemented by bridges that
  714. * set the DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME flag in their
  715. * &drm_bridge->ops.
  716. */
  717. int (*hdmi_write_spd_infoframe)(struct drm_bridge *bridge,
  718. const u8 *buffer, size_t len);
  719. /**
  720. * @hdmi_clear_audio_infoframe:
  721. *
  722. * This callback clears the infoframes in the hardware during commit.
  723. *
  724. * This callback is optional but it must be implemented by bridges that
  725. * set the DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
  726. */
  727. int (*hdmi_clear_audio_infoframe)(struct drm_bridge *bridge);
  728. /**
  729. * @hdmi_write_audio_infoframe:
  730. *
  731. * Program the infoframe into the hardware.
  732. *
  733. * This callback is optional but it must be implemented by bridges that
  734. * set the DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
  735. */
  736. int (*hdmi_write_audio_infoframe)(struct drm_bridge *bridge,
  737. const u8 *buffer, size_t len);
  738. /**
  739. * @hdmi_audio_startup:
  740. *
  741. * Called when ASoC starts an audio stream setup.
  742. *
  743. * This callback is optional, it can be implemented by bridges that
  744. * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
  745. *
  746. * Returns:
  747. * 0 on success, a negative error code otherwise
  748. */
  749. int (*hdmi_audio_startup)(struct drm_bridge *bridge,
  750. struct drm_connector *connector);
  751. /**
  752. * @hdmi_audio_prepare:
  753. * Configures HDMI-encoder for audio stream. Can be called multiple
  754. * times for each setup.
  755. *
  756. * This callback is optional but it must be implemented by bridges that
  757. * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
  758. *
  759. * Returns:
  760. * 0 on success, a negative error code otherwise
  761. */
  762. int (*hdmi_audio_prepare)(struct drm_bridge *bridge,
  763. struct drm_connector *connector,
  764. struct hdmi_codec_daifmt *fmt,
  765. struct hdmi_codec_params *hparms);
  766. /**
  767. * @hdmi_audio_shutdown:
  768. *
  769. * Shut down the audio stream.
  770. *
  771. * This callback is optional but it must be implemented by bridges that
  772. * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
  773. *
  774. * Returns:
  775. * 0 on success, a negative error code otherwise
  776. */
  777. void (*hdmi_audio_shutdown)(struct drm_bridge *bridge,
  778. struct drm_connector *connector);
  779. /**
  780. * @hdmi_audio_mute_stream:
  781. *
  782. * Mute/unmute HDMI audio stream.
  783. *
  784. * This callback is optional, it can be implemented by bridges that
  785. * set the @DRM_BRIDGE_OP_HDMI_AUDIO flag in their &drm_bridge->ops.
  786. *
  787. * Returns:
  788. * 0 on success, a negative error code otherwise
  789. */
  790. int (*hdmi_audio_mute_stream)(struct drm_bridge *bridge,
  791. struct drm_connector *connector,
  792. bool enable, int direction);
  793. /**
  794. * @hdmi_cec_init:
  795. *
  796. * Initialize CEC part of the bridge.
  797. *
  798. * This callback is optional, it can be implemented by bridges that
  799. * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
  800. * &drm_bridge->ops.
  801. *
  802. * Returns:
  803. * 0 on success, a negative error code otherwise
  804. */
  805. int (*hdmi_cec_init)(struct drm_bridge *bridge,
  806. struct drm_connector *connector);
  807. /**
  808. * @hdmi_cec_enable:
  809. *
  810. * Enable or disable the CEC adapter inside the bridge.
  811. *
  812. * This callback is optional, it can be implemented by bridges that
  813. * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
  814. * &drm_bridge->ops.
  815. *
  816. * Returns:
  817. * 0 on success, a negative error code otherwise
  818. */
  819. int (*hdmi_cec_enable)(struct drm_bridge *bridge, bool enable);
  820. /**
  821. * @hdmi_cec_log_addr:
  822. *
  823. * Set the logical address of the CEC adapter inside the bridge.
  824. *
  825. * This callback is optional, it can be implemented by bridges that
  826. * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
  827. * &drm_bridge->ops.
  828. *
  829. * Returns:
  830. * 0 on success, a negative error code otherwise
  831. */
  832. int (*hdmi_cec_log_addr)(struct drm_bridge *bridge, u8 logical_addr);
  833. /**
  834. * @hdmi_cec_transmit:
  835. *
  836. * Transmit the message using the CEC adapter inside the bridge.
  837. *
  838. * This callback is optional, it can be implemented by bridges that
  839. * set the @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER flag in their
  840. * &drm_bridge->ops.
  841. *
  842. * Returns:
  843. * 0 on success, a negative error code otherwise
  844. */
  845. int (*hdmi_cec_transmit)(struct drm_bridge *bridge, u8 attempts,
  846. u32 signal_free_time, struct cec_msg *msg);
  847. /**
  848. * @dp_audio_startup:
  849. *
  850. * Called when ASoC starts a DisplayPort audio stream setup.
  851. *
  852. * This callback is optional, it can be implemented by bridges that
  853. * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
  854. *
  855. * Returns:
  856. * 0 on success, a negative error code otherwise
  857. */
  858. int (*dp_audio_startup)(struct drm_bridge *bridge,
  859. struct drm_connector *connector);
  860. /**
  861. * @dp_audio_prepare:
  862. * Configures DisplayPort audio stream. Can be called multiple
  863. * times for each setup.
  864. *
  865. * This callback is optional but it must be implemented by bridges that
  866. * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
  867. *
  868. * Returns:
  869. * 0 on success, a negative error code otherwise
  870. */
  871. int (*dp_audio_prepare)(struct drm_bridge *bridge,
  872. struct drm_connector *connector,
  873. struct hdmi_codec_daifmt *fmt,
  874. struct hdmi_codec_params *hparms);
  875. /**
  876. * @dp_audio_shutdown:
  877. *
  878. * Shut down the DisplayPort audio stream.
  879. *
  880. * This callback is optional but it must be implemented by bridges that
  881. * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
  882. *
  883. * Returns:
  884. * 0 on success, a negative error code otherwise
  885. */
  886. void (*dp_audio_shutdown)(struct drm_bridge *bridge,
  887. struct drm_connector *connector);
  888. /**
  889. * @dp_audio_mute_stream:
  890. *
  891. * Mute/unmute DisplayPort audio stream.
  892. *
  893. * This callback is optional, it can be implemented by bridges that
  894. * set the @DRM_BRIDGE_OP_DP_AUDIO flag in their &drm_bridge->ops.
  895. *
  896. * Returns:
  897. * 0 on success, a negative error code otherwise
  898. */
  899. int (*dp_audio_mute_stream)(struct drm_bridge *bridge,
  900. struct drm_connector *connector,
  901. bool enable, int direction);
  902. /**
  903. * @debugfs_init:
  904. *
  905. * Allows bridges to create bridge-specific debugfs files.
  906. */
  907. void (*debugfs_init)(struct drm_bridge *bridge, struct dentry *root);
  908. };
  909. /**
  910. * struct drm_bridge_timings - timing information for the bridge
  911. */
  912. struct drm_bridge_timings {
  913. /**
  914. * @input_bus_flags:
  915. *
  916. * Tells what additional settings for the pixel data on the bus
  917. * this bridge requires (like pixel signal polarity). See also
  918. * &drm_display_info->bus_flags.
  919. */
  920. u32 input_bus_flags;
  921. /**
  922. * @setup_time_ps:
  923. *
  924. * Defines the time in picoseconds the input data lines must be
  925. * stable before the clock edge.
  926. */
  927. u32 setup_time_ps;
  928. /**
  929. * @hold_time_ps:
  930. *
  931. * Defines the time in picoseconds taken for the bridge to sample the
  932. * input signal after the clock edge.
  933. */
  934. u32 hold_time_ps;
  935. /**
  936. * @dual_link:
  937. *
  938. * True if the bus operates in dual-link mode. The exact meaning is
  939. * dependent on the bus type. For LVDS buses, this indicates that even-
  940. * and odd-numbered pixels are received on separate links.
  941. */
  942. bool dual_link;
  943. };
  944. /**
  945. * enum drm_bridge_ops - Bitmask of operations supported by the bridge
  946. */
  947. enum drm_bridge_ops {
  948. /**
  949. * @DRM_BRIDGE_OP_DETECT: The bridge can detect displays connected to
  950. * its output. Bridges that set this flag shall implement the
  951. * &drm_bridge_funcs->detect callback.
  952. */
  953. DRM_BRIDGE_OP_DETECT = BIT(0),
  954. /**
  955. * @DRM_BRIDGE_OP_EDID: The bridge can retrieve the EDID of the display
  956. * connected to its output. Bridges that set this flag shall implement
  957. * the &drm_bridge_funcs->edid_read callback.
  958. */
  959. DRM_BRIDGE_OP_EDID = BIT(1),
  960. /**
  961. * @DRM_BRIDGE_OP_HPD: The bridge can detect hot-plug and hot-unplug
  962. * without requiring polling. Bridges that set this flag shall
  963. * implement the &drm_bridge_funcs->hpd_enable and
  964. * &drm_bridge_funcs->hpd_disable callbacks if they support enabling
  965. * and disabling hot-plug detection dynamically.
  966. */
  967. DRM_BRIDGE_OP_HPD = BIT(2),
  968. /**
  969. * @DRM_BRIDGE_OP_MODES: The bridge can retrieve the modes supported
  970. * by the display at its output. This does not include reading EDID
  971. * which is separately covered by @DRM_BRIDGE_OP_EDID. Bridges that set
  972. * this flag shall implement the &drm_bridge_funcs->get_modes callback.
  973. */
  974. DRM_BRIDGE_OP_MODES = BIT(3),
  975. /**
  976. * @DRM_BRIDGE_OP_HDMI: The bridge provides HDMI connector operations,
  977. * including infoframes support. Bridges that set this flag must
  978. * provide HDMI-related information and implement the
  979. * &drm_bridge_funcs->clear_avi_infoframe,
  980. * &drm_bridge_funcs->write_avi_infoframe,
  981. * &drm_bridge_funcs->clear_hdmi_infoframe and
  982. * &drm_bridge_funcs->write_hdmi_infoframe callbacks.
  983. *
  984. * Note: currently there can be at most one bridge in a chain that sets
  985. * this bit. This is to simplify corresponding glue code in connector
  986. * drivers.
  987. */
  988. DRM_BRIDGE_OP_HDMI = BIT(4),
  989. /**
  990. * @DRM_BRIDGE_OP_HDMI_AUDIO: The bridge provides HDMI audio operations.
  991. * Bridges that set this flag must implement the
  992. * &drm_bridge_funcs->hdmi_audio_prepare and
  993. * &drm_bridge_funcs->hdmi_audio_shutdown callbacks.
  994. * If the bridge implements @DRM_BRIDGE_OP_HDMI, it also must implement
  995. * &drm_bridge_funcs->hdmi_write_audio_infoframe and
  996. * &drm_bridge_funcs->hdmi_cleaer_audio_infoframe callbacks.
  997. *
  998. * Note: currently there can be at most one bridge in a chain that sets
  999. * this bit. This is to simplify corresponding glue code in connector
  1000. * drivers. Also it is not possible to have a bridge in the chain that
  1001. * sets @DRM_BRIDGE_OP_DP_AUDIO if there is a bridge that sets this
  1002. * flag.
  1003. */
  1004. DRM_BRIDGE_OP_HDMI_AUDIO = BIT(5),
  1005. /**
  1006. * @DRM_BRIDGE_OP_DP_AUDIO: The bridge provides DisplayPort audio operations.
  1007. * Bridges that set this flag must implement the
  1008. * &drm_bridge_funcs->dp_audio_prepare and
  1009. * &drm_bridge_funcs->dp_audio_shutdown callbacks.
  1010. *
  1011. * Note: currently there can be at most one bridge in a chain that sets
  1012. * this bit. This is to simplify corresponding glue code in connector
  1013. * drivers. Also it is not possible to have a bridge in the chain that
  1014. * sets @DRM_BRIDGE_OP_HDMI_AUDIO if there is a bridge that sets this
  1015. * flag.
  1016. */
  1017. DRM_BRIDGE_OP_DP_AUDIO = BIT(6),
  1018. /**
  1019. * @DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER: The bridge requires CEC notifier
  1020. * to be present.
  1021. */
  1022. DRM_BRIDGE_OP_HDMI_CEC_NOTIFIER = BIT(7),
  1023. /**
  1024. * @DRM_BRIDGE_OP_HDMI_CEC_ADAPTER: The bridge requires CEC adapter
  1025. * to be present.
  1026. */
  1027. DRM_BRIDGE_OP_HDMI_CEC_ADAPTER = BIT(8),
  1028. /**
  1029. * @DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME: The bridge supports
  1030. * &drm_bridge_funcs->hdmi_write_hdr_drm_infoframe and
  1031. * &drm_bridge_funcs->hdmi_clear_hdr_drm_infoframe callbacks.
  1032. */
  1033. DRM_BRIDGE_OP_HDMI_HDR_DRM_INFOFRAME = BIT(9),
  1034. /**
  1035. * @DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME: The bridge supports
  1036. * &drm_bridge_funcs->hdmi_write_spd_infoframe and
  1037. * &drm_bridge_funcs->hdmi_clear_spd_infoframe callbacks.
  1038. */
  1039. DRM_BRIDGE_OP_HDMI_SPD_INFOFRAME = BIT(10),
  1040. };
  1041. /**
  1042. * struct drm_bridge - central DRM bridge control structure
  1043. */
  1044. struct drm_bridge {
  1045. /** @base: inherit from &drm_private_object */
  1046. struct drm_private_obj base;
  1047. /** @dev: DRM device this bridge belongs to */
  1048. struct drm_device *dev;
  1049. /** @encoder: encoder to which this bridge is connected */
  1050. struct drm_encoder *encoder;
  1051. /** @chain_node: used to form a bridge chain */
  1052. struct list_head chain_node;
  1053. /** @of_node: device node pointer to the bridge */
  1054. struct device_node *of_node;
  1055. /** @list: to keep track of all added bridges */
  1056. struct list_head list;
  1057. /**
  1058. * @timings:
  1059. *
  1060. * the timing specification for the bridge, if any (may be NULL)
  1061. */
  1062. const struct drm_bridge_timings *timings;
  1063. /** @funcs: control functions */
  1064. const struct drm_bridge_funcs *funcs;
  1065. /**
  1066. * @container: Pointer to the private driver struct embedding this
  1067. * @struct drm_bridge.
  1068. */
  1069. void *container;
  1070. /**
  1071. * @refcount: reference count of users referencing this bridge.
  1072. */
  1073. struct kref refcount;
  1074. /**
  1075. * @unplugged:
  1076. *
  1077. * Flag to tell if the bridge has been unplugged.
  1078. * See drm_bridge_enter() and drm_bridge_unplug().
  1079. */
  1080. bool unplugged;
  1081. /** @driver_private: pointer to the bridge driver's internal context */
  1082. void *driver_private;
  1083. /** @ops: bitmask of operations supported by the bridge */
  1084. enum drm_bridge_ops ops;
  1085. /**
  1086. * @type: Type of the connection at the bridge output
  1087. * (DRM_MODE_CONNECTOR_*). For bridges at the end of this chain this
  1088. * identifies the type of connected display.
  1089. */
  1090. int type;
  1091. /**
  1092. * @interlace_allowed: Indicate that the bridge can handle interlaced
  1093. * modes.
  1094. */
  1095. bool interlace_allowed;
  1096. /**
  1097. * @ycbcr_420_allowed: Indicate that the bridge can handle YCbCr 420
  1098. * output.
  1099. */
  1100. bool ycbcr_420_allowed;
  1101. /**
  1102. * @pre_enable_prev_first: The bridge requires that the prev
  1103. * bridge @pre_enable function is called before its @pre_enable,
  1104. * and conversely for post_disable. This is most frequently a
  1105. * requirement for DSI devices which need the host to be initialised
  1106. * before the peripheral.
  1107. */
  1108. bool pre_enable_prev_first;
  1109. /**
  1110. * @support_hdcp: Indicate that the bridge supports HDCP.
  1111. */
  1112. bool support_hdcp;
  1113. /**
  1114. * @ddc: Associated I2C adapter for DDC access, if any.
  1115. */
  1116. struct i2c_adapter *ddc;
  1117. /**
  1118. * @vendor: Vendor of the product to be used for the SPD InfoFrame
  1119. * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.
  1120. */
  1121. const char *vendor;
  1122. /**
  1123. * @product: Name of the product to be used for the SPD InfoFrame
  1124. * generation. This is required if @DRM_BRIDGE_OP_HDMI is set.
  1125. */
  1126. const char *product;
  1127. /**
  1128. * @supported_formats: Bitmask of @hdmi_colorspace listing supported
  1129. * output formats. This is only relevant if @DRM_BRIDGE_OP_HDMI is set.
  1130. */
  1131. unsigned int supported_formats;
  1132. /**
  1133. * @max_bpc: Maximum bits per char the HDMI bridge supports. Allowed
  1134. * values are 8, 10 and 12. This is only relevant if
  1135. * @DRM_BRIDGE_OP_HDMI is set.
  1136. */
  1137. unsigned int max_bpc;
  1138. /**
  1139. * @hdmi_cec_dev: device to be used as a containing device for CEC
  1140. * functions.
  1141. */
  1142. struct device *hdmi_cec_dev;
  1143. /**
  1144. * @hdmi_audio_dev: device to be used as a parent for the HDMI Codec if
  1145. * either of @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO is set.
  1146. */
  1147. struct device *hdmi_audio_dev;
  1148. /**
  1149. * @hdmi_audio_max_i2s_playback_channels: maximum number of playback
  1150. * I2S channels for the @DRM_BRIDGE_OP_HDMI_AUDIO or
  1151. * @DRM_BRIDGE_OP_DP_AUDIO.
  1152. */
  1153. int hdmi_audio_max_i2s_playback_channels;
  1154. /**
  1155. * @hdmi_audio_i2s_formats: supported I2S formats, optional. The
  1156. * default is to allow all formats supported by the corresponding I2S
  1157. * bus driver. This is only used for bridges setting
  1158. * @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO.
  1159. */
  1160. u64 hdmi_audio_i2s_formats;
  1161. /**
  1162. * @hdmi_audio_spdif_playback: set if this bridge has S/PDIF playback
  1163. * port for @DRM_BRIDGE_OP_HDMI_AUDIO or @DRM_BRIDGE_OP_DP_AUDIO.
  1164. */
  1165. unsigned int hdmi_audio_spdif_playback : 1;
  1166. /**
  1167. * @hdmi_audio_dai_port: sound DAI port for either of
  1168. * @DRM_BRIDGE_OP_HDMI_AUDIO and @DRM_BRIDGE_OP_DP_AUDIO, -1 if it is
  1169. * not used.
  1170. */
  1171. int hdmi_audio_dai_port;
  1172. /**
  1173. * @hdmi_cec_adapter_name: the name of the adapter to register
  1174. */
  1175. const char *hdmi_cec_adapter_name;
  1176. /**
  1177. * @hdmi_cec_available_las: number of logical addresses, CEC_MAX_LOG_ADDRS if unset
  1178. */
  1179. u8 hdmi_cec_available_las;
  1180. /** private: */
  1181. /**
  1182. * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.
  1183. */
  1184. struct mutex hpd_mutex;
  1185. /**
  1186. * @hpd_cb: Hot plug detection callback, registered with
  1187. * drm_bridge_hpd_enable().
  1188. */
  1189. void (*hpd_cb)(void *data, enum drm_connector_status status);
  1190. /**
  1191. * @hpd_data: Private data passed to the Hot plug detection callback
  1192. * @hpd_cb.
  1193. */
  1194. void *hpd_data;
  1195. /**
  1196. * @next_bridge: Pointer to the following bridge, automatically put
  1197. * when this bridge is freed (i.e. at destroy time). This is for
  1198. * drivers needing to store a pointer to the next bridge in the
  1199. * chain, and ensures any code still holding a reference to this
  1200. * bridge after its removal cannot use-after-free the next
  1201. * bridge. Any other bridge pointers stored by the driver must be
  1202. * put in the .destroy callback by driver code.
  1203. */
  1204. struct drm_bridge *next_bridge;
  1205. };
  1206. static inline struct drm_bridge *
  1207. drm_priv_to_bridge(struct drm_private_obj *priv)
  1208. {
  1209. return container_of(priv, struct drm_bridge, base);
  1210. }
  1211. bool drm_bridge_enter(struct drm_bridge *bridge, int *idx);
  1212. void drm_bridge_exit(int idx);
  1213. void drm_bridge_unplug(struct drm_bridge *bridge);
  1214. struct drm_bridge *drm_bridge_get(struct drm_bridge *bridge);
  1215. void drm_bridge_put(struct drm_bridge *bridge);
  1216. /* Cleanup action for use with __free() */
  1217. DEFINE_FREE(drm_bridge_put, struct drm_bridge *, if (_T) drm_bridge_put(_T))
  1218. void *__devm_drm_bridge_alloc(struct device *dev, size_t size, size_t offset,
  1219. const struct drm_bridge_funcs *funcs);
  1220. /**
  1221. * devm_drm_bridge_alloc - Allocate and initialize a bridge
  1222. * @dev: struct device of the bridge device
  1223. * @type: the type of the struct which contains struct &drm_bridge
  1224. * @member: the name of the &drm_bridge within @type
  1225. * @funcs: callbacks for this bridge
  1226. *
  1227. * The reference count of the returned bridge is initialized to 1. This
  1228. * reference will be automatically dropped via devm (by calling
  1229. * drm_bridge_put()) when @dev is removed.
  1230. *
  1231. * Returns:
  1232. * Pointer to new bridge, or ERR_PTR on failure.
  1233. */
  1234. #define devm_drm_bridge_alloc(dev, type, member, funcs) \
  1235. ((type *)__devm_drm_bridge_alloc(dev, sizeof(type), \
  1236. offsetof(type, member), funcs))
  1237. void drm_bridge_add(struct drm_bridge *bridge);
  1238. int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge);
  1239. void drm_bridge_remove(struct drm_bridge *bridge);
  1240. int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
  1241. struct drm_bridge *previous,
  1242. enum drm_bridge_attach_flags flags);
  1243. #ifdef CONFIG_OF
  1244. struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np);
  1245. struct drm_bridge *of_drm_find_bridge(struct device_node *np);
  1246. #else
  1247. static inline struct drm_bridge *of_drm_find_and_get_bridge(struct device_node *np)
  1248. {
  1249. return NULL;
  1250. }
  1251. static inline struct drm_bridge *of_drm_find_bridge(struct device_node *np)
  1252. {
  1253. return NULL;
  1254. }
  1255. #endif
  1256. static inline bool drm_bridge_is_last(struct drm_bridge *bridge)
  1257. {
  1258. return list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain);
  1259. }
  1260. /**
  1261. * drm_bridge_get_current_state() - Get the current bridge state
  1262. * @bridge: bridge object
  1263. *
  1264. * This function must be called with the modeset lock held.
  1265. *
  1266. * RETURNS:
  1267. *
  1268. * The current bridge state, or NULL if there is none.
  1269. */
  1270. static inline struct drm_bridge_state *
  1271. drm_bridge_get_current_state(struct drm_bridge *bridge)
  1272. {
  1273. if (!bridge)
  1274. return NULL;
  1275. /*
  1276. * Only atomic bridges will have bridge->base initialized by
  1277. * drm_atomic_private_obj_init(), so we need to make sure we're
  1278. * working with one before we try to use the lock.
  1279. */
  1280. if (!bridge->funcs || !bridge->funcs->atomic_reset)
  1281. return NULL;
  1282. drm_modeset_lock_assert_held(&bridge->base.lock);
  1283. if (!bridge->base.state)
  1284. return NULL;
  1285. return drm_priv_to_bridge_state(bridge->base.state);
  1286. }
  1287. /**
  1288. * drm_bridge_get_next_bridge() - Get the next bridge in the chain
  1289. * @bridge: bridge object
  1290. *
  1291. * The caller is responsible of having a reference to @bridge via
  1292. * drm_bridge_get() or equivalent. This function leaves the refcount of
  1293. * @bridge unmodified.
  1294. *
  1295. * The refcount of the returned bridge is incremented. Use drm_bridge_put()
  1296. * when done with it.
  1297. *
  1298. * RETURNS:
  1299. * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
  1300. */
  1301. static inline struct drm_bridge *
  1302. drm_bridge_get_next_bridge(struct drm_bridge *bridge)
  1303. {
  1304. if (list_is_last(&bridge->chain_node, &bridge->encoder->bridge_chain))
  1305. return NULL;
  1306. return drm_bridge_get(list_next_entry(bridge, chain_node));
  1307. }
  1308. /**
  1309. * drm_bridge_get_prev_bridge() - Get the previous bridge in the chain
  1310. * @bridge: bridge object
  1311. *
  1312. * The caller is responsible of having a reference to @bridge via
  1313. * drm_bridge_get() or equivalent. This function leaves the refcount of
  1314. * @bridge unmodified.
  1315. *
  1316. * The refcount of the returned bridge is incremented. Use drm_bridge_put()
  1317. * when done with it.
  1318. *
  1319. * RETURNS:
  1320. * the previous bridge in the chain, or NULL if @bridge is the first.
  1321. */
  1322. static inline struct drm_bridge *
  1323. drm_bridge_get_prev_bridge(struct drm_bridge *bridge)
  1324. {
  1325. if (list_is_first(&bridge->chain_node, &bridge->encoder->bridge_chain))
  1326. return NULL;
  1327. return drm_bridge_get(list_prev_entry(bridge, chain_node));
  1328. }
  1329. /**
  1330. * drm_bridge_chain_get_first_bridge() - Get the first bridge in the chain
  1331. * @encoder: encoder object
  1332. *
  1333. * The refcount of the returned bridge is incremented. Use drm_bridge_put()
  1334. * when done with it.
  1335. *
  1336. * RETURNS:
  1337. * the first bridge in the chain, or NULL if @encoder has no bridge attached
  1338. * to it.
  1339. */
  1340. static inline struct drm_bridge *
  1341. drm_bridge_chain_get_first_bridge(struct drm_encoder *encoder)
  1342. {
  1343. return drm_bridge_get(list_first_entry_or_null(&encoder->bridge_chain,
  1344. struct drm_bridge, chain_node));
  1345. }
  1346. /**
  1347. * drm_bridge_chain_get_last_bridge() - Get the last bridge in the chain
  1348. * @encoder: encoder object
  1349. *
  1350. * The refcount of the returned bridge is incremented. Use drm_bridge_put()
  1351. * when done with it.
  1352. *
  1353. * RETURNS:
  1354. * the last bridge in the chain, or NULL if @encoder has no bridge attached
  1355. * to it.
  1356. */
  1357. static inline struct drm_bridge *
  1358. drm_bridge_chain_get_last_bridge(struct drm_encoder *encoder)
  1359. {
  1360. return drm_bridge_get(list_last_entry_or_null(&encoder->bridge_chain,
  1361. struct drm_bridge, chain_node));
  1362. }
  1363. /**
  1364. * drm_bridge_get_next_bridge_and_put - Get the next bridge in the chain
  1365. * and put the previous
  1366. * @bridge: bridge object
  1367. *
  1368. * Same as drm_bridge_get_next_bridge() but additionally puts the @bridge.
  1369. *
  1370. * RETURNS:
  1371. * the next bridge in the chain after @bridge, or NULL if @bridge is the last.
  1372. */
  1373. static inline struct drm_bridge *
  1374. drm_bridge_get_next_bridge_and_put(struct drm_bridge *bridge)
  1375. {
  1376. struct drm_bridge *next = drm_bridge_get_next_bridge(bridge);
  1377. drm_bridge_put(bridge);
  1378. return next;
  1379. }
  1380. /**
  1381. * drm_for_each_bridge_in_chain_scoped - iterate over all bridges attached
  1382. * to an encoder
  1383. * @encoder: the encoder to iterate bridges on
  1384. * @bridge: a bridge pointer updated to point to the current bridge at each
  1385. * iteration
  1386. *
  1387. * Iterate over all bridges present in the bridge chain attached to @encoder.
  1388. *
  1389. * Automatically gets/puts the bridge reference while iterating, and puts
  1390. * the reference even if returning or breaking in the middle of the loop.
  1391. */
  1392. #define drm_for_each_bridge_in_chain_scoped(encoder, bridge) \
  1393. for (struct drm_bridge *bridge __free(drm_bridge_put) = \
  1394. drm_bridge_chain_get_first_bridge(encoder); \
  1395. bridge; \
  1396. bridge = drm_bridge_get_next_bridge_and_put(bridge))
  1397. /**
  1398. * drm_for_each_bridge_in_chain_from - iterate over all bridges starting
  1399. * from the given bridge
  1400. * @first_bridge: the bridge to start from
  1401. * @bridge: a bridge pointer updated to point to the current bridge at each
  1402. * iteration
  1403. *
  1404. * Iterate over all bridges in the encoder chain starting from
  1405. * @first_bridge, included.
  1406. *
  1407. * Automatically gets/puts the bridge reference while iterating, and puts
  1408. * the reference even if returning or breaking in the middle of the loop.
  1409. */
  1410. #define drm_for_each_bridge_in_chain_from(first_bridge, bridge) \
  1411. for (struct drm_bridge *bridge __free(drm_bridge_put) = \
  1412. drm_bridge_get(first_bridge); \
  1413. bridge; \
  1414. bridge = drm_bridge_get_next_bridge_and_put(bridge))
  1415. enum drm_mode_status
  1416. drm_bridge_chain_mode_valid(struct drm_bridge *bridge,
  1417. const struct drm_display_info *info,
  1418. const struct drm_display_mode *mode);
  1419. void drm_bridge_chain_mode_set(struct drm_bridge *bridge,
  1420. const struct drm_display_mode *mode,
  1421. const struct drm_display_mode *adjusted_mode);
  1422. int drm_atomic_bridge_chain_check(struct drm_bridge *bridge,
  1423. struct drm_crtc_state *crtc_state,
  1424. struct drm_connector_state *conn_state);
  1425. void drm_atomic_bridge_chain_disable(struct drm_bridge *bridge,
  1426. struct drm_atomic_state *state);
  1427. void drm_atomic_bridge_chain_post_disable(struct drm_bridge *bridge,
  1428. struct drm_atomic_state *state);
  1429. void drm_atomic_bridge_chain_pre_enable(struct drm_bridge *bridge,
  1430. struct drm_atomic_state *state);
  1431. void drm_atomic_bridge_chain_enable(struct drm_bridge *bridge,
  1432. struct drm_atomic_state *state);
  1433. u32 *
  1434. drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
  1435. struct drm_bridge_state *bridge_state,
  1436. struct drm_crtc_state *crtc_state,
  1437. struct drm_connector_state *conn_state,
  1438. u32 output_fmt,
  1439. unsigned int *num_input_fmts);
  1440. enum drm_connector_status
  1441. drm_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector);
  1442. int drm_bridge_get_modes(struct drm_bridge *bridge,
  1443. struct drm_connector *connector);
  1444. const struct drm_edid *drm_bridge_edid_read(struct drm_bridge *bridge,
  1445. struct drm_connector *connector);
  1446. void drm_bridge_hpd_enable(struct drm_bridge *bridge,
  1447. void (*cb)(void *data,
  1448. enum drm_connector_status status),
  1449. void *data);
  1450. void drm_bridge_hpd_disable(struct drm_bridge *bridge);
  1451. void drm_bridge_hpd_notify(struct drm_bridge *bridge,
  1452. enum drm_connector_status status);
  1453. #ifdef CONFIG_DRM_PANEL_BRIDGE
  1454. bool drm_bridge_is_panel(const struct drm_bridge *bridge);
  1455. struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel);
  1456. struct drm_bridge *drm_panel_bridge_add_typed(struct drm_panel *panel,
  1457. u32 connector_type);
  1458. void drm_panel_bridge_remove(struct drm_bridge *bridge);
  1459. int drm_panel_bridge_set_orientation(struct drm_connector *connector,
  1460. struct drm_bridge *bridge);
  1461. struct drm_bridge *devm_drm_panel_bridge_add(struct device *dev,
  1462. struct drm_panel *panel);
  1463. struct drm_bridge *devm_drm_panel_bridge_add_typed(struct device *dev,
  1464. struct drm_panel *panel,
  1465. u32 connector_type);
  1466. struct drm_bridge *drmm_panel_bridge_add(struct drm_device *drm,
  1467. struct drm_panel *panel);
  1468. struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge);
  1469. #else
  1470. static inline bool drm_bridge_is_panel(const struct drm_bridge *bridge)
  1471. {
  1472. return false;
  1473. }
  1474. static inline int drm_panel_bridge_set_orientation(struct drm_connector *connector,
  1475. struct drm_bridge *bridge)
  1476. {
  1477. return -EINVAL;
  1478. }
  1479. #endif
  1480. #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE)
  1481. struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,
  1482. u32 port, u32 endpoint);
  1483. struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm, struct device_node *node,
  1484. u32 port, u32 endpoint);
  1485. #else
  1486. static inline struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
  1487. struct device_node *node,
  1488. u32 port,
  1489. u32 endpoint)
  1490. {
  1491. return ERR_PTR(-ENODEV);
  1492. }
  1493. static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,
  1494. struct device_node *node,
  1495. u32 port,
  1496. u32 endpoint)
  1497. {
  1498. return ERR_PTR(-ENODEV);
  1499. }
  1500. #endif
  1501. void devm_drm_put_bridge(struct device *dev, struct drm_bridge *bridge);
  1502. void drm_bridge_debugfs_params(struct dentry *root);
  1503. void drm_bridge_debugfs_encoder_params(struct dentry *root, struct drm_encoder *encoder);
  1504. #endif