drm_dp_helper.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. /*
  2. * Copyright © 2008 Keith Packard
  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_DP_HELPER_H_
  23. #define _DRM_DP_HELPER_H_
  24. #include <linux/delay.h>
  25. #include <linux/i2c.h>
  26. #include <drm/display/drm_dp.h>
  27. #include <drm/drm_connector.h>
  28. struct drm_device;
  29. struct drm_dp_aux;
  30. struct drm_panel;
  31. bool drm_dp_channel_eq_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
  32. int lane_count);
  33. bool drm_dp_clock_recovery_ok(const u8 link_status[DP_LINK_STATUS_SIZE],
  34. int lane_count);
  35. u8 drm_dp_get_adjust_request_voltage(const u8 link_status[DP_LINK_STATUS_SIZE],
  36. int lane);
  37. u8 drm_dp_get_adjust_request_pre_emphasis(const u8 link_status[DP_LINK_STATUS_SIZE],
  38. int lane);
  39. u8 drm_dp_get_adjust_tx_ffe_preset(const u8 link_status[DP_LINK_STATUS_SIZE],
  40. int lane);
  41. int drm_dp_read_clock_recovery_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  42. enum drm_dp_phy dp_phy, bool uhbr);
  43. int drm_dp_read_channel_eq_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  44. enum drm_dp_phy dp_phy, bool uhbr);
  45. void drm_dp_link_train_clock_recovery_delay(const struct drm_dp_aux *aux,
  46. const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
  47. void drm_dp_lttpr_link_train_clock_recovery_delay(void);
  48. void drm_dp_link_train_channel_eq_delay(const struct drm_dp_aux *aux,
  49. const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
  50. void drm_dp_lttpr_link_train_channel_eq_delay(const struct drm_dp_aux *aux,
  51. const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
  52. int drm_dp_128b132b_read_aux_rd_interval(struct drm_dp_aux *aux);
  53. bool drm_dp_128b132b_lane_channel_eq_done(const u8 link_status[DP_LINK_STATUS_SIZE],
  54. int lane_count);
  55. bool drm_dp_128b132b_lane_symbol_locked(const u8 link_status[DP_LINK_STATUS_SIZE],
  56. int lane_count);
  57. bool drm_dp_128b132b_eq_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);
  58. bool drm_dp_128b132b_cds_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);
  59. bool drm_dp_128b132b_link_training_failed(const u8 link_status[DP_LINK_STATUS_SIZE]);
  60. u8 drm_dp_link_rate_to_bw_code(int link_rate);
  61. int drm_dp_bw_code_to_link_rate(u8 link_bw);
  62. const char *drm_dp_phy_name(enum drm_dp_phy dp_phy);
  63. /**
  64. * struct drm_dp_vsc_sdp - drm DP VSC SDP
  65. *
  66. * This structure represents a DP VSC SDP of drm
  67. * It is based on DP 1.4 spec [Table 2-116: VSC SDP Header Bytes] and
  68. * [Table 2-117: VSC SDP Payload for DB16 through DB18]
  69. *
  70. * @sdp_type: secondary-data packet type
  71. * @revision: revision number
  72. * @length: number of valid data bytes
  73. * @pixelformat: pixel encoding format
  74. * @colorimetry: colorimetry format
  75. * @bpc: bit per color
  76. * @dynamic_range: dynamic range information
  77. * @content_type: CTA-861-G defines content types and expected processing by a sink device
  78. */
  79. struct drm_dp_vsc_sdp {
  80. unsigned char sdp_type;
  81. unsigned char revision;
  82. unsigned char length;
  83. enum dp_pixelformat pixelformat;
  84. enum dp_colorimetry colorimetry;
  85. int bpc;
  86. enum dp_dynamic_range dynamic_range;
  87. enum dp_content_type content_type;
  88. };
  89. /**
  90. * struct drm_dp_as_sdp - drm DP Adaptive Sync SDP
  91. *
  92. * This structure represents a DP AS SDP of drm
  93. * It is based on DP 2.1 spec [Table 2-126: Adaptive-Sync SDP Header Bytes] and
  94. * [Table 2-127: Adaptive-Sync SDP Payload for DB0 through DB8]
  95. *
  96. * @sdp_type: Secondary-data packet type
  97. * @revision: Revision Number
  98. * @length: Number of valid data bytes
  99. * @vtotal: Minimum Vertical Vtotal
  100. * @target_rr: Target Refresh
  101. * @duration_incr_ms: Successive frame duration increase
  102. * @duration_decr_ms: Successive frame duration decrease
  103. * @target_rr_divider: Target refresh rate divider
  104. * @mode: Adaptive Sync Operation Mode
  105. */
  106. struct drm_dp_as_sdp {
  107. unsigned char sdp_type;
  108. unsigned char revision;
  109. unsigned char length;
  110. int vtotal;
  111. int target_rr;
  112. int duration_incr_ms;
  113. int duration_decr_ms;
  114. bool target_rr_divider;
  115. enum operation_mode mode;
  116. };
  117. void drm_dp_as_sdp_log(struct drm_printer *p,
  118. const struct drm_dp_as_sdp *as_sdp);
  119. void drm_dp_vsc_sdp_log(struct drm_printer *p, const struct drm_dp_vsc_sdp *vsc);
  120. bool drm_dp_vsc_sdp_supported(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
  121. bool drm_dp_as_sdp_supported(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);
  122. int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);
  123. static inline int
  124. drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  125. {
  126. return drm_dp_bw_code_to_link_rate(dpcd[DP_MAX_LINK_RATE]);
  127. }
  128. static inline u8
  129. drm_dp_max_lane_count(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  130. {
  131. return dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
  132. }
  133. static inline bool
  134. drm_dp_enhanced_frame_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  135. {
  136. return dpcd[DP_DPCD_REV] >= 0x11 &&
  137. (dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP);
  138. }
  139. static inline bool
  140. drm_dp_fast_training_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  141. {
  142. return dpcd[DP_DPCD_REV] >= 0x11 &&
  143. (dpcd[DP_MAX_DOWNSPREAD] & DP_NO_AUX_HANDSHAKE_LINK_TRAINING);
  144. }
  145. static inline bool
  146. drm_dp_tps3_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  147. {
  148. return dpcd[DP_DPCD_REV] >= 0x12 &&
  149. dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED;
  150. }
  151. static inline bool
  152. drm_dp_max_downspread(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  153. {
  154. return dpcd[DP_DPCD_REV] >= 0x11 ||
  155. dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5;
  156. }
  157. static inline bool
  158. drm_dp_tps4_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  159. {
  160. return dpcd[DP_DPCD_REV] >= 0x14 &&
  161. dpcd[DP_MAX_DOWNSPREAD] & DP_TPS4_SUPPORTED;
  162. }
  163. static inline u8
  164. drm_dp_training_pattern_mask(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  165. {
  166. return (dpcd[DP_DPCD_REV] >= 0x14) ? DP_TRAINING_PATTERN_MASK_1_4 :
  167. DP_TRAINING_PATTERN_MASK;
  168. }
  169. static inline bool
  170. drm_dp_is_branch(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  171. {
  172. return dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT;
  173. }
  174. /* DP/eDP DSC support */
  175. u8 drm_dp_dsc_sink_bpp_incr(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);
  176. u8 drm_dp_dsc_sink_max_slice_count(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],
  177. bool is_edp);
  178. u8 drm_dp_dsc_sink_line_buf_depth(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);
  179. int drm_dp_dsc_sink_supported_input_bpcs(const u8 dsc_dpc[DP_DSC_RECEIVER_CAP_SIZE],
  180. u8 dsc_bpc[3]);
  181. static inline bool
  182. drm_dp_sink_supports_dsc(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
  183. {
  184. return dsc_dpcd[DP_DSC_SUPPORT - DP_DSC_SUPPORT] &
  185. DP_DSC_DECOMPRESSION_IS_SUPPORTED;
  186. }
  187. static inline u16
  188. drm_edp_dsc_sink_output_bpp(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
  189. {
  190. return dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_LOW - DP_DSC_SUPPORT] |
  191. ((dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] &
  192. DP_DSC_MAX_BITS_PER_PIXEL_HI_MASK) << 8);
  193. }
  194. static inline u32
  195. drm_dp_dsc_sink_max_slice_width(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])
  196. {
  197. /* Max Slicewidth = Number of Pixels * 320 */
  198. return dsc_dpcd[DP_DSC_MAX_SLICE_WIDTH - DP_DSC_SUPPORT] *
  199. DP_DSC_SLICE_WIDTH_MULTIPLIER;
  200. }
  201. /**
  202. * drm_dp_dsc_sink_supports_format() - check if sink supports DSC with given output format
  203. * @dsc_dpcd : DSC-capability DPCDs of the sink
  204. * @output_format: output_format which is to be checked
  205. *
  206. * Returns true if the sink supports DSC with the given output_format, false otherwise.
  207. */
  208. static inline bool
  209. drm_dp_dsc_sink_supports_format(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE], u8 output_format)
  210. {
  211. return dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] & output_format;
  212. }
  213. /* Forward Error Correction Support on DP 1.4 */
  214. static inline bool
  215. drm_dp_sink_supports_fec(const u8 fec_capable)
  216. {
  217. return fec_capable & DP_FEC_CAPABLE;
  218. }
  219. static inline bool
  220. drm_dp_channel_coding_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  221. {
  222. return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_8B10B;
  223. }
  224. static inline bool
  225. drm_dp_128b132b_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  226. {
  227. return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_128B132B;
  228. }
  229. static inline bool
  230. drm_dp_alternate_scrambler_reset_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  231. {
  232. return dpcd[DP_EDP_CONFIGURATION_CAP] &
  233. DP_ALTERNATE_SCRAMBLER_RESET_CAP;
  234. }
  235. /* Ignore MSA timing for Adaptive Sync support on DP 1.4 */
  236. static inline bool
  237. drm_dp_sink_can_do_video_without_timing_msa(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
  238. {
  239. return dpcd[DP_DOWN_STREAM_PORT_COUNT] &
  240. DP_MSA_TIMING_PAR_IGNORED;
  241. }
  242. /**
  243. * drm_edp_backlight_supported() - Check an eDP DPCD for VESA backlight support
  244. * @edp_dpcd: The DPCD to check
  245. *
  246. * Note that currently this function will return %false for panels which support various DPCD
  247. * backlight features but which require the brightness be set through PWM, and don't support setting
  248. * the brightness level via the DPCD.
  249. *
  250. * Returns: %True if @edp_dpcd indicates that VESA backlight controls are supported, %false
  251. * otherwise
  252. */
  253. static inline bool
  254. drm_edp_backlight_supported(const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE])
  255. {
  256. return !!(edp_dpcd[1] & DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP);
  257. }
  258. /**
  259. * drm_dp_is_uhbr_rate - Determine if a link rate is UHBR
  260. * @link_rate: link rate in 10kbits/s units
  261. *
  262. * Determine if the provided link rate is an UHBR rate.
  263. *
  264. * Returns: %True if @link_rate is an UHBR rate.
  265. */
  266. static inline bool drm_dp_is_uhbr_rate(int link_rate)
  267. {
  268. return link_rate >= 1000000;
  269. }
  270. /*
  271. * DisplayPort AUX channel
  272. */
  273. /**
  274. * struct drm_dp_aux_msg - DisplayPort AUX channel transaction
  275. * @address: address of the (first) register to access
  276. * @request: contains the type of transaction (see DP_AUX_* macros)
  277. * @reply: upon completion, contains the reply type of the transaction
  278. * @buffer: pointer to a transmission or reception buffer
  279. * @size: size of @buffer
  280. */
  281. struct drm_dp_aux_msg {
  282. unsigned int address;
  283. u8 request;
  284. u8 reply;
  285. void *buffer;
  286. size_t size;
  287. };
  288. struct cec_adapter;
  289. struct drm_connector;
  290. struct drm_edid;
  291. /**
  292. * struct drm_dp_aux_cec - DisplayPort CEC-Tunneling-over-AUX
  293. * @lock: mutex protecting this struct
  294. * @adap: the CEC adapter for CEC-Tunneling-over-AUX support.
  295. * @connector: the connector this CEC adapter is associated with
  296. * @unregister_work: unregister the CEC adapter
  297. */
  298. struct drm_dp_aux_cec {
  299. struct mutex lock;
  300. struct cec_adapter *adap;
  301. struct drm_connector *connector;
  302. struct delayed_work unregister_work;
  303. };
  304. /**
  305. * struct drm_dp_aux - DisplayPort AUX channel
  306. *
  307. * An AUX channel can also be used to transport I2C messages to a sink. A
  308. * typical application of that is to access an EDID that's present in the sink
  309. * device. The @transfer() function can also be used to execute such
  310. * transactions. The drm_dp_aux_register() function registers an I2C adapter
  311. * that can be passed to drm_probe_ddc(). Upon removal, drivers should call
  312. * drm_dp_aux_unregister() to remove the I2C adapter. The I2C adapter uses long
  313. * transfers by default; if a partial response is received, the adapter will
  314. * drop down to the size given by the partial response for this transaction
  315. * only.
  316. */
  317. struct drm_dp_aux {
  318. /**
  319. * @name: user-visible name of this AUX channel and the
  320. * I2C-over-AUX adapter.
  321. *
  322. * It's also used to specify the name of the I2C adapter. If set
  323. * to %NULL, dev_name() of @dev will be used.
  324. */
  325. const char *name;
  326. /**
  327. * @ddc: I2C adapter that can be used for I2C-over-AUX
  328. * communication
  329. */
  330. struct i2c_adapter ddc;
  331. /**
  332. * @dev: pointer to struct device that is the parent for this
  333. * AUX channel.
  334. */
  335. struct device *dev;
  336. /**
  337. * @drm_dev: pointer to the &drm_device that owns this AUX channel.
  338. * Beware, this may be %NULL before drm_dp_aux_register() has been
  339. * called.
  340. *
  341. * It should be set to the &drm_device that will be using this AUX
  342. * channel as early as possible. For many graphics drivers this should
  343. * happen before drm_dp_aux_init(), however it's perfectly fine to set
  344. * this field later so long as it's assigned before calling
  345. * drm_dp_aux_register().
  346. */
  347. struct drm_device *drm_dev;
  348. /**
  349. * @crtc: backpointer to the crtc that is currently using this
  350. * AUX channel
  351. */
  352. struct drm_crtc *crtc;
  353. /**
  354. * @hw_mutex: internal mutex used for locking transfers.
  355. *
  356. * Note that if the underlying hardware is shared among multiple
  357. * channels, the driver needs to do additional locking to
  358. * prevent concurrent access.
  359. */
  360. struct mutex hw_mutex;
  361. /**
  362. * @crc_work: worker that captures CRCs for each frame
  363. */
  364. struct work_struct crc_work;
  365. /**
  366. * @crc_count: counter of captured frame CRCs
  367. */
  368. u8 crc_count;
  369. /**
  370. * @transfer: transfers a message representing a single AUX
  371. * transaction.
  372. *
  373. * This is a hardware-specific implementation of how
  374. * transactions are executed that the drivers must provide.
  375. *
  376. * A pointer to a &drm_dp_aux_msg structure describing the
  377. * transaction is passed into this function. Upon success, the
  378. * implementation should return the number of payload bytes that
  379. * were transferred, or a negative error-code on failure.
  380. *
  381. * Helpers will propagate these errors, with the exception of
  382. * the %-EBUSY error, which causes a transaction to be retried.
  383. * On a short, helpers will return %-EPROTO to make it simpler
  384. * to check for failure.
  385. *
  386. * The @transfer() function must only modify the reply field of
  387. * the &drm_dp_aux_msg structure. The retry logic and i2c
  388. * helpers assume this is the case.
  389. *
  390. * Also note that this callback can be called no matter the
  391. * state @dev is in and also no matter what state the panel is
  392. * in. It's expected:
  393. *
  394. * - If the @dev providing the AUX bus is currently unpowered then
  395. * it will power itself up for the transfer.
  396. *
  397. * - If we're on eDP (using a drm_panel) and the panel is not in a
  398. * state where it can respond (it's not powered or it's in a
  399. * low power state) then this function may return an error, but
  400. * not crash. It's up to the caller of this code to make sure that
  401. * the panel is powered on if getting an error back is not OK. If a
  402. * drm_panel driver is initiating a DP AUX transfer it may power
  403. * itself up however it wants. All other code should ensure that
  404. * the pre_enable() bridge chain (which eventually calls the
  405. * drm_panel prepare function) has powered the panel.
  406. */
  407. ssize_t (*transfer)(struct drm_dp_aux *aux,
  408. struct drm_dp_aux_msg *msg);
  409. /**
  410. * @wait_hpd_asserted: wait for HPD to be asserted
  411. *
  412. * This is mainly useful for eDP panels drivers to wait for an eDP
  413. * panel to finish powering on. It is optional for DP AUX controllers
  414. * to implement this function. It is required for DP AUX endpoints
  415. * (panel drivers) to call this function after powering up but before
  416. * doing AUX transfers unless the DP AUX endpoint driver knows that
  417. * we're not using the AUX controller's HPD. One example of the panel
  418. * driver not needing to call this is if HPD is hooked up to a GPIO
  419. * that the panel driver can read directly.
  420. *
  421. * If a DP AUX controller does not implement this function then it
  422. * may still support eDP panels that use the AUX controller's built-in
  423. * HPD signal by implementing a long wait for HPD in the transfer()
  424. * callback, though this is deprecated.
  425. *
  426. * This function will efficiently wait for the HPD signal to be
  427. * asserted. The `wait_us` parameter that is passed in says that we
  428. * know that the HPD signal is expected to be asserted within `wait_us`
  429. * microseconds. This function could wait for longer than `wait_us` if
  430. * the logic in the DP controller has a long debouncing time. The
  431. * important thing is that if this function returns success that the
  432. * DP controller is ready to send AUX transactions.
  433. *
  434. * This function returns 0 if HPD was asserted or -ETIMEDOUT if time
  435. * expired and HPD wasn't asserted. This function should not print
  436. * timeout errors to the log.
  437. *
  438. * The semantics of this function are designed to match the
  439. * readx_poll_timeout() function. That means a `wait_us` of 0 means
  440. * to wait forever. Like readx_poll_timeout(), this function may sleep.
  441. *
  442. * NOTE: this function specifically reports the state of the HPD pin
  443. * that's associated with the DP AUX channel. This is different from
  444. * the HPD concept in much of the rest of DRM which is more about
  445. * physical presence of a display. For eDP, for instance, a display is
  446. * assumed always present even if the HPD pin is deasserted.
  447. */
  448. int (*wait_hpd_asserted)(struct drm_dp_aux *aux, unsigned long wait_us);
  449. /**
  450. * @i2c_nack_count: Counts I2C NACKs, used for DP validation.
  451. */
  452. unsigned i2c_nack_count;
  453. /**
  454. * @i2c_defer_count: Counts I2C DEFERs, used for DP validation.
  455. */
  456. unsigned i2c_defer_count;
  457. /**
  458. * @cec: struct containing fields used for CEC-Tunneling-over-AUX.
  459. */
  460. struct drm_dp_aux_cec cec;
  461. /**
  462. * @is_remote: Is this AUX CH actually using sideband messaging.
  463. */
  464. bool is_remote;
  465. /**
  466. * @powered_down: If true then the remote endpoint is powered down.
  467. */
  468. bool powered_down;
  469. };
  470. int drm_dp_dpcd_probe(struct drm_dp_aux *aux, unsigned int offset);
  471. void drm_dp_dpcd_set_powered(struct drm_dp_aux *aux, bool powered);
  472. ssize_t drm_dp_dpcd_read(struct drm_dp_aux *aux, unsigned int offset,
  473. void *buffer, size_t size);
  474. ssize_t drm_dp_dpcd_write(struct drm_dp_aux *aux, unsigned int offset,
  475. void *buffer, size_t size);
  476. /**
  477. * drm_dp_dpcd_readb() - read a single byte from the DPCD
  478. * @aux: DisplayPort AUX channel
  479. * @offset: address of the register to read
  480. * @valuep: location where the value of the register will be stored
  481. *
  482. * Returns the number of bytes transferred (1) on success, or a negative
  483. * error code on failure.
  484. */
  485. static inline ssize_t drm_dp_dpcd_readb(struct drm_dp_aux *aux,
  486. unsigned int offset, u8 *valuep)
  487. {
  488. return drm_dp_dpcd_read(aux, offset, valuep, 1);
  489. }
  490. /**
  491. * drm_dp_dpcd_writeb() - write a single byte to the DPCD
  492. * @aux: DisplayPort AUX channel
  493. * @offset: address of the register to write
  494. * @value: value to write to the register
  495. *
  496. * Returns the number of bytes transferred (1) on success, or a negative
  497. * error code on failure.
  498. */
  499. static inline ssize_t drm_dp_dpcd_writeb(struct drm_dp_aux *aux,
  500. unsigned int offset, u8 value)
  501. {
  502. return drm_dp_dpcd_write(aux, offset, &value, 1);
  503. }
  504. int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux,
  505. u8 dpcd[DP_RECEIVER_CAP_SIZE]);
  506. int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux,
  507. u8 status[DP_LINK_STATUS_SIZE]);
  508. int drm_dp_dpcd_read_phy_link_status(struct drm_dp_aux *aux,
  509. enum drm_dp_phy dp_phy,
  510. u8 link_status[DP_LINK_STATUS_SIZE]);
  511. bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux,
  512. u8 real_edid_checksum);
  513. int drm_dp_read_downstream_info(struct drm_dp_aux *aux,
  514. const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  515. u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]);
  516. bool drm_dp_downstream_is_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  517. const u8 port_cap[4], u8 type);
  518. bool drm_dp_downstream_is_tmds(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  519. const u8 port_cap[4],
  520. const struct drm_edid *drm_edid);
  521. int drm_dp_downstream_max_dotclock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  522. const u8 port_cap[4]);
  523. int drm_dp_downstream_max_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  524. const u8 port_cap[4],
  525. const struct drm_edid *drm_edid);
  526. int drm_dp_downstream_min_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  527. const u8 port_cap[4],
  528. const struct drm_edid *drm_edid);
  529. int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  530. const u8 port_cap[4],
  531. const struct drm_edid *drm_edid);
  532. bool drm_dp_downstream_420_passthrough(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  533. const u8 port_cap[4]);
  534. bool drm_dp_downstream_444_to_420_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  535. const u8 port_cap[4]);
  536. struct drm_display_mode *drm_dp_downstream_mode(struct drm_device *dev,
  537. const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  538. const u8 port_cap[4]);
  539. int drm_dp_downstream_id(struct drm_dp_aux *aux, char id[6]);
  540. void drm_dp_downstream_debug(struct seq_file *m,
  541. const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  542. const u8 port_cap[4],
  543. const struct drm_edid *drm_edid,
  544. struct drm_dp_aux *aux);
  545. enum drm_mode_subconnector
  546. drm_dp_subconnector_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  547. const u8 port_cap[4]);
  548. void drm_dp_set_subconnector_property(struct drm_connector *connector,
  549. enum drm_connector_status status,
  550. const u8 *dpcd,
  551. const u8 port_cap[4]);
  552. struct drm_dp_desc;
  553. bool drm_dp_read_sink_count_cap(struct drm_connector *connector,
  554. const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  555. const struct drm_dp_desc *desc);
  556. int drm_dp_read_sink_count(struct drm_dp_aux *aux);
  557. int drm_dp_read_lttpr_common_caps(struct drm_dp_aux *aux,
  558. const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  559. u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
  560. int drm_dp_read_lttpr_phy_caps(struct drm_dp_aux *aux,
  561. const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  562. enum drm_dp_phy dp_phy,
  563. u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
  564. int drm_dp_lttpr_count(const u8 cap[DP_LTTPR_COMMON_CAP_SIZE]);
  565. int drm_dp_lttpr_max_link_rate(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
  566. int drm_dp_lttpr_max_lane_count(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);
  567. bool drm_dp_lttpr_voltage_swing_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
  568. bool drm_dp_lttpr_pre_emphasis_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);
  569. void drm_dp_remote_aux_init(struct drm_dp_aux *aux);
  570. void drm_dp_aux_init(struct drm_dp_aux *aux);
  571. int drm_dp_aux_register(struct drm_dp_aux *aux);
  572. void drm_dp_aux_unregister(struct drm_dp_aux *aux);
  573. int drm_dp_start_crc(struct drm_dp_aux *aux, struct drm_crtc *crtc);
  574. int drm_dp_stop_crc(struct drm_dp_aux *aux);
  575. struct drm_dp_dpcd_ident {
  576. u8 oui[3];
  577. u8 device_id[6];
  578. u8 hw_rev;
  579. u8 sw_major_rev;
  580. u8 sw_minor_rev;
  581. } __packed;
  582. /**
  583. * struct drm_dp_desc - DP branch/sink device descriptor
  584. * @ident: DP device identification from DPCD 0x400 (sink) or 0x500 (branch).
  585. * @quirks: Quirks; use drm_dp_has_quirk() to query for the quirks.
  586. */
  587. struct drm_dp_desc {
  588. struct drm_dp_dpcd_ident ident;
  589. u32 quirks;
  590. };
  591. int drm_dp_read_desc(struct drm_dp_aux *aux, struct drm_dp_desc *desc,
  592. bool is_branch);
  593. int drm_dp_dump_lttpr_desc(struct drm_dp_aux *aux, enum drm_dp_phy dp_phy);
  594. /**
  595. * enum drm_dp_quirk - Display Port sink/branch device specific quirks
  596. *
  597. * Display Port sink and branch devices in the wild have a variety of bugs, try
  598. * to collect them here. The quirks are shared, but it's up to the drivers to
  599. * implement workarounds for them.
  600. */
  601. enum drm_dp_quirk {
  602. /**
  603. * @DP_DPCD_QUIRK_CONSTANT_N:
  604. *
  605. * The device requires main link attributes Mvid and Nvid to be limited
  606. * to 16 bits. So will give a constant value (0x8000) for compatability.
  607. */
  608. DP_DPCD_QUIRK_CONSTANT_N,
  609. /**
  610. * @DP_DPCD_QUIRK_NO_PSR:
  611. *
  612. * The device does not support PSR even if reports that it supports or
  613. * driver still need to implement proper handling for such device.
  614. */
  615. DP_DPCD_QUIRK_NO_PSR,
  616. /**
  617. * @DP_DPCD_QUIRK_NO_SINK_COUNT:
  618. *
  619. * The device does not set SINK_COUNT to a non-zero value.
  620. * The driver should ignore SINK_COUNT during detection. Note that
  621. * drm_dp_read_sink_count_cap() automatically checks for this quirk.
  622. */
  623. DP_DPCD_QUIRK_NO_SINK_COUNT,
  624. /**
  625. * @DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD:
  626. *
  627. * The device supports MST DSC despite not supporting Virtual DPCD.
  628. * The DSC caps can be read from the physical aux instead.
  629. */
  630. DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD,
  631. /**
  632. * @DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS:
  633. *
  634. * The device supports a link rate of 3.24 Gbps (multiplier 0xc) despite
  635. * the DP_MAX_LINK_RATE register reporting a lower max multiplier.
  636. */
  637. DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS,
  638. /**
  639. * @DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC:
  640. *
  641. * The device applies HBLANK expansion for some modes, but this
  642. * requires enabling DSC.
  643. */
  644. DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC,
  645. };
  646. /**
  647. * drm_dp_has_quirk() - does the DP device have a specific quirk
  648. * @desc: Device descriptor filled by drm_dp_read_desc()
  649. * @quirk: Quirk to query for
  650. *
  651. * Return true if DP device identified by @desc has @quirk.
  652. */
  653. static inline bool
  654. drm_dp_has_quirk(const struct drm_dp_desc *desc, enum drm_dp_quirk quirk)
  655. {
  656. return desc->quirks & BIT(quirk);
  657. }
  658. /**
  659. * struct drm_edp_backlight_info - Probed eDP backlight info struct
  660. * @pwmgen_bit_count: The pwmgen bit count
  661. * @pwm_freq_pre_divider: The PWM frequency pre-divider value being used for this backlight, if any
  662. * @max: The maximum backlight level that may be set
  663. * @lsb_reg_used: Do we also write values to the DP_EDP_BACKLIGHT_BRIGHTNESS_LSB register?
  664. * @aux_enable: Does the panel support the AUX enable cap?
  665. * @aux_set: Does the panel support setting the brightness through AUX?
  666. *
  667. * This structure contains various data about an eDP backlight, which can be populated by using
  668. * drm_edp_backlight_init().
  669. */
  670. struct drm_edp_backlight_info {
  671. u8 pwmgen_bit_count;
  672. u8 pwm_freq_pre_divider;
  673. u16 max;
  674. bool lsb_reg_used : 1;
  675. bool aux_enable : 1;
  676. bool aux_set : 1;
  677. };
  678. int
  679. drm_edp_backlight_init(struct drm_dp_aux *aux, struct drm_edp_backlight_info *bl,
  680. u16 driver_pwm_freq_hz, const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE],
  681. u16 *current_level, u8 *current_mode);
  682. int drm_edp_backlight_set_level(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,
  683. u16 level);
  684. int drm_edp_backlight_enable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,
  685. u16 level);
  686. int drm_edp_backlight_disable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl);
  687. #if IS_ENABLED(CONFIG_DRM_KMS_HELPER) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \
  688. (IS_MODULE(CONFIG_DRM_KMS_HELPER) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))
  689. int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux);
  690. #else
  691. static inline int drm_panel_dp_aux_backlight(struct drm_panel *panel,
  692. struct drm_dp_aux *aux)
  693. {
  694. return 0;
  695. }
  696. #endif
  697. #ifdef CONFIG_DRM_DISPLAY_DP_AUX_CEC
  698. void drm_dp_cec_irq(struct drm_dp_aux *aux);
  699. void drm_dp_cec_register_connector(struct drm_dp_aux *aux,
  700. struct drm_connector *connector);
  701. void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux);
  702. void drm_dp_cec_attach(struct drm_dp_aux *aux, u16 source_physical_address);
  703. void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid);
  704. void drm_dp_cec_unset_edid(struct drm_dp_aux *aux);
  705. #else
  706. static inline void drm_dp_cec_irq(struct drm_dp_aux *aux)
  707. {
  708. }
  709. static inline void
  710. drm_dp_cec_register_connector(struct drm_dp_aux *aux,
  711. struct drm_connector *connector)
  712. {
  713. }
  714. static inline void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux)
  715. {
  716. }
  717. static inline void drm_dp_cec_attach(struct drm_dp_aux *aux,
  718. u16 source_physical_address)
  719. {
  720. }
  721. static inline void drm_dp_cec_set_edid(struct drm_dp_aux *aux,
  722. const struct edid *edid)
  723. {
  724. }
  725. static inline void drm_dp_cec_unset_edid(struct drm_dp_aux *aux)
  726. {
  727. }
  728. #endif
  729. /**
  730. * struct drm_dp_phy_test_params - DP Phy Compliance parameters
  731. * @link_rate: Requested Link rate from DPCD 0x219
  732. * @num_lanes: Number of lanes requested by sing through DPCD 0x220
  733. * @phy_pattern: DP Phy test pattern from DPCD 0x248
  734. * @hbr2_reset: DP HBR2_COMPLIANCE_SCRAMBLER_RESET from DCPD 0x24A and 0x24B
  735. * @custom80: DP Test_80BIT_CUSTOM_PATTERN from DPCDs 0x250 through 0x259
  736. * @enhanced_frame_cap: flag for enhanced frame capability.
  737. */
  738. struct drm_dp_phy_test_params {
  739. int link_rate;
  740. u8 num_lanes;
  741. u8 phy_pattern;
  742. u8 hbr2_reset[2];
  743. u8 custom80[10];
  744. bool enhanced_frame_cap;
  745. };
  746. int drm_dp_get_phy_test_pattern(struct drm_dp_aux *aux,
  747. struct drm_dp_phy_test_params *data);
  748. int drm_dp_set_phy_test_pattern(struct drm_dp_aux *aux,
  749. struct drm_dp_phy_test_params *data, u8 dp_rev);
  750. int drm_dp_get_pcon_max_frl_bw(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  751. const u8 port_cap[4]);
  752. int drm_dp_pcon_frl_prepare(struct drm_dp_aux *aux, bool enable_frl_ready_hpd);
  753. bool drm_dp_pcon_is_frl_ready(struct drm_dp_aux *aux);
  754. int drm_dp_pcon_frl_configure_1(struct drm_dp_aux *aux, int max_frl_gbps,
  755. u8 frl_mode);
  756. int drm_dp_pcon_frl_configure_2(struct drm_dp_aux *aux, int max_frl_mask,
  757. u8 frl_type);
  758. int drm_dp_pcon_reset_frl_config(struct drm_dp_aux *aux);
  759. int drm_dp_pcon_frl_enable(struct drm_dp_aux *aux);
  760. bool drm_dp_pcon_hdmi_link_active(struct drm_dp_aux *aux);
  761. int drm_dp_pcon_hdmi_link_mode(struct drm_dp_aux *aux, u8 *frl_trained_mask);
  762. void drm_dp_pcon_hdmi_frl_link_error_count(struct drm_dp_aux *aux,
  763. struct drm_connector *connector);
  764. bool drm_dp_pcon_enc_is_dsc_1_2(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
  765. int drm_dp_pcon_dsc_max_slices(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
  766. int drm_dp_pcon_dsc_max_slice_width(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
  767. int drm_dp_pcon_dsc_bpp_incr(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);
  768. int drm_dp_pcon_pps_default(struct drm_dp_aux *aux);
  769. int drm_dp_pcon_pps_override_buf(struct drm_dp_aux *aux, u8 pps_buf[128]);
  770. int drm_dp_pcon_pps_override_param(struct drm_dp_aux *aux, u8 pps_param[6]);
  771. bool drm_dp_downstream_rgb_to_ycbcr_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],
  772. const u8 port_cap[4], u8 color_spc);
  773. int drm_dp_pcon_convert_rgb_to_ycbcr(struct drm_dp_aux *aux, u8 color_spc);
  774. #define DRM_DP_BW_OVERHEAD_MST BIT(0)
  775. #define DRM_DP_BW_OVERHEAD_UHBR BIT(1)
  776. #define DRM_DP_BW_OVERHEAD_SSC_REF_CLK BIT(2)
  777. #define DRM_DP_BW_OVERHEAD_FEC BIT(3)
  778. #define DRM_DP_BW_OVERHEAD_DSC BIT(4)
  779. int drm_dp_bw_overhead(int lane_count, int hactive,
  780. int dsc_slice_count,
  781. int bpp_x16, unsigned long flags);
  782. int drm_dp_bw_channel_coding_efficiency(bool is_uhbr);
  783. int drm_dp_max_dprx_data_rate(int max_link_rate, int max_lanes);
  784. ssize_t drm_dp_vsc_sdp_pack(const struct drm_dp_vsc_sdp *vsc, struct dp_sdp *sdp);
  785. #endif /* _DRM_DP_HELPER_H_ */