/*1* Copyright © 2008 Keith Packard2*3* Permission to use, copy, modify, distribute, and sell this software and its4* documentation for any purpose is hereby granted without fee, provided that5* the above copyright notice appear in all copies and that both that copyright6* notice and this permission notice appear in supporting documentation, and7* that the name of the copyright holders not be used in advertising or8* publicity pertaining to distribution of the software without specific,9* written prior permission. The copyright holders make no representations10* about the suitability of this software for any purpose. It is provided "as11* is" without express or implied warranty.12*13* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,14* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO15* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR16* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,17* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER18* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE19* OF THIS SOFTWARE.20*/2122#ifndef _DRM_DP_HELPER_H_23#define _DRM_DP_HELPER_H_2425#include <linux/delay.h>26#include <linux/i2c.h>2728#include <drm/display/drm_dp.h>29#include <drm/drm_connector.h>3031struct drm_device;32struct drm_dp_aux;33struct drm_panel;3435bool drm_dp_channel_eq_ok(const u8 link_status[DP_LINK_STATUS_SIZE],36int lane_count);37bool drm_dp_clock_recovery_ok(const u8 link_status[DP_LINK_STATUS_SIZE],38int lane_count);39u8 drm_dp_get_adjust_request_voltage(const u8 link_status[DP_LINK_STATUS_SIZE],40int lane);41u8 drm_dp_get_adjust_request_pre_emphasis(const u8 link_status[DP_LINK_STATUS_SIZE],42int lane);43u8 drm_dp_get_adjust_tx_ffe_preset(const u8 link_status[DP_LINK_STATUS_SIZE],44int lane);4546int drm_dp_read_clock_recovery_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],47enum drm_dp_phy dp_phy, bool uhbr);48int drm_dp_read_channel_eq_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],49enum drm_dp_phy dp_phy, bool uhbr);5051void drm_dp_link_train_clock_recovery_delay(const struct drm_dp_aux *aux,52const u8 dpcd[DP_RECEIVER_CAP_SIZE]);53void drm_dp_lttpr_link_train_clock_recovery_delay(void);54void drm_dp_link_train_channel_eq_delay(const struct drm_dp_aux *aux,55const u8 dpcd[DP_RECEIVER_CAP_SIZE]);56void drm_dp_lttpr_link_train_channel_eq_delay(const struct drm_dp_aux *aux,57const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);5859int drm_dp_128b132b_read_aux_rd_interval(struct drm_dp_aux *aux);60bool drm_dp_128b132b_lane_channel_eq_done(const u8 link_status[DP_LINK_STATUS_SIZE],61int lane_count);62bool drm_dp_128b132b_lane_symbol_locked(const u8 link_status[DP_LINK_STATUS_SIZE],63int lane_count);64bool drm_dp_128b132b_eq_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);65bool drm_dp_128b132b_cds_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);66bool drm_dp_128b132b_link_training_failed(const u8 link_status[DP_LINK_STATUS_SIZE]);6768u8 drm_dp_link_rate_to_bw_code(int link_rate);69int drm_dp_bw_code_to_link_rate(u8 link_bw);7071const char *drm_dp_phy_name(enum drm_dp_phy dp_phy);7273/**74* struct drm_dp_vsc_sdp - drm DP VSC SDP75*76* This structure represents a DP VSC SDP of drm77* It is based on DP 1.4 spec [Table 2-116: VSC SDP Header Bytes] and78* [Table 2-117: VSC SDP Payload for DB16 through DB18]79*80* @sdp_type: secondary-data packet type81* @revision: revision number82* @length: number of valid data bytes83* @pixelformat: pixel encoding format84* @colorimetry: colorimetry format85* @bpc: bit per color86* @dynamic_range: dynamic range information87* @content_type: CTA-861-G defines content types and expected processing by a sink device88*/89struct drm_dp_vsc_sdp {90unsigned char sdp_type;91unsigned char revision;92unsigned char length;93enum dp_pixelformat pixelformat;94enum dp_colorimetry colorimetry;95int bpc;96enum dp_dynamic_range dynamic_range;97enum dp_content_type content_type;98};99100/**101* struct drm_dp_as_sdp - drm DP Adaptive Sync SDP102*103* This structure represents a DP AS SDP of drm104* It is based on DP 2.1 spec [Table 2-126: Adaptive-Sync SDP Header Bytes] and105* [Table 2-127: Adaptive-Sync SDP Payload for DB0 through DB8]106*107* @sdp_type: Secondary-data packet type108* @revision: Revision Number109* @length: Number of valid data bytes110* @vtotal: Minimum Vertical Vtotal111* @target_rr: Target Refresh112* @duration_incr_ms: Successive frame duration increase113* @duration_decr_ms: Successive frame duration decrease114* @target_rr_divider: Target refresh rate divider115* @mode: Adaptive Sync Operation Mode116*/117struct drm_dp_as_sdp {118unsigned char sdp_type;119unsigned char revision;120unsigned char length;121int vtotal;122int target_rr;123int duration_incr_ms;124int duration_decr_ms;125bool target_rr_divider;126enum operation_mode mode;127};128129void drm_dp_as_sdp_log(struct drm_printer *p,130const struct drm_dp_as_sdp *as_sdp);131void drm_dp_vsc_sdp_log(struct drm_printer *p, const struct drm_dp_vsc_sdp *vsc);132133bool drm_dp_vsc_sdp_supported(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);134bool drm_dp_as_sdp_supported(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);135136int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);137138static inline int139drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])140{141return drm_dp_bw_code_to_link_rate(dpcd[DP_MAX_LINK_RATE]);142}143144static inline u8145drm_dp_max_lane_count(const u8 dpcd[DP_RECEIVER_CAP_SIZE])146{147return dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;148}149150static inline bool151drm_dp_enhanced_frame_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])152{153return dpcd[DP_DPCD_REV] >= 0x11 &&154(dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP);155}156157static inline bool158drm_dp_fast_training_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])159{160return dpcd[DP_DPCD_REV] >= 0x11 &&161(dpcd[DP_MAX_DOWNSPREAD] & DP_NO_AUX_HANDSHAKE_LINK_TRAINING);162}163164static inline bool165drm_dp_tps3_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])166{167return dpcd[DP_DPCD_REV] >= 0x12 &&168dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED;169}170171static inline bool172drm_dp_max_downspread(const u8 dpcd[DP_RECEIVER_CAP_SIZE])173{174return dpcd[DP_DPCD_REV] >= 0x11 ||175dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5;176}177178static inline bool179drm_dp_tps4_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])180{181return dpcd[DP_DPCD_REV] >= 0x14 &&182dpcd[DP_MAX_DOWNSPREAD] & DP_TPS4_SUPPORTED;183}184185static inline u8186drm_dp_training_pattern_mask(const u8 dpcd[DP_RECEIVER_CAP_SIZE])187{188return (dpcd[DP_DPCD_REV] >= 0x14) ? DP_TRAINING_PATTERN_MASK_1_4 :189DP_TRAINING_PATTERN_MASK;190}191192static inline bool193drm_dp_is_branch(const u8 dpcd[DP_RECEIVER_CAP_SIZE])194{195return dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT;196}197198/* DP/eDP DSC support */199u8 drm_dp_dsc_sink_bpp_incr(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);200u8 drm_dp_dsc_sink_max_slice_count(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],201bool is_edp);202u8 drm_dp_dsc_sink_line_buf_depth(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);203int drm_dp_dsc_sink_supported_input_bpcs(const u8 dsc_dpc[DP_DSC_RECEIVER_CAP_SIZE],204u8 dsc_bpc[3]);205206static inline bool207drm_dp_sink_supports_dsc(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])208{209return dsc_dpcd[DP_DSC_SUPPORT - DP_DSC_SUPPORT] &210DP_DSC_DECOMPRESSION_IS_SUPPORTED;211}212213static inline u16214drm_edp_dsc_sink_output_bpp(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])215{216return dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_LOW - DP_DSC_SUPPORT] |217((dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] &218DP_DSC_MAX_BITS_PER_PIXEL_HI_MASK) << 8);219}220221static inline u32222drm_dp_dsc_sink_max_slice_width(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])223{224/* Max Slicewidth = Number of Pixels * 320 */225return dsc_dpcd[DP_DSC_MAX_SLICE_WIDTH - DP_DSC_SUPPORT] *226DP_DSC_SLICE_WIDTH_MULTIPLIER;227}228229/**230* drm_dp_dsc_sink_supports_format() - check if sink supports DSC with given output format231* @dsc_dpcd : DSC-capability DPCDs of the sink232* @output_format: output_format which is to be checked233*234* Returns true if the sink supports DSC with the given output_format, false otherwise.235*/236static inline bool237drm_dp_dsc_sink_supports_format(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE], u8 output_format)238{239return dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] & output_format;240}241242/* Forward Error Correction Support on DP 1.4 */243static inline bool244drm_dp_sink_supports_fec(const u8 fec_capable)245{246return fec_capable & DP_FEC_CAPABLE;247}248249static inline bool250drm_dp_channel_coding_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])251{252return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_8B10B;253}254255static inline bool256drm_dp_128b132b_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])257{258return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_128B132B;259}260261static inline bool262drm_dp_alternate_scrambler_reset_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])263{264return dpcd[DP_EDP_CONFIGURATION_CAP] &265DP_ALTERNATE_SCRAMBLER_RESET_CAP;266}267268/* Ignore MSA timing for Adaptive Sync support on DP 1.4 */269static inline bool270drm_dp_sink_can_do_video_without_timing_msa(const u8 dpcd[DP_RECEIVER_CAP_SIZE])271{272return dpcd[DP_DOWN_STREAM_PORT_COUNT] &273DP_MSA_TIMING_PAR_IGNORED;274}275276/**277* drm_edp_backlight_supported() - Check an eDP DPCD for VESA backlight support278* @edp_dpcd: The DPCD to check279*280* Note that currently this function will return %false for panels which support various DPCD281* backlight features but which require the brightness be set through PWM, and don't support setting282* the brightness level via the DPCD.283*284* Returns: %True if @edp_dpcd indicates that VESA backlight controls are supported, %false285* otherwise286*/287static inline bool288drm_edp_backlight_supported(const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE])289{290return !!(edp_dpcd[1] & DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP);291}292293/**294* drm_dp_is_uhbr_rate - Determine if a link rate is UHBR295* @link_rate: link rate in 10kbits/s units296*297* Determine if the provided link rate is an UHBR rate.298*299* Returns: %True if @link_rate is an UHBR rate.300*/301static inline bool drm_dp_is_uhbr_rate(int link_rate)302{303return link_rate >= 1000000;304}305306/*307* DisplayPort AUX channel308*/309310/**311* struct drm_dp_aux_msg - DisplayPort AUX channel transaction312* @address: address of the (first) register to access313* @request: contains the type of transaction (see DP_AUX_* macros)314* @reply: upon completion, contains the reply type of the transaction315* @buffer: pointer to a transmission or reception buffer316* @size: size of @buffer317*/318struct drm_dp_aux_msg {319unsigned int address;320u8 request;321u8 reply;322void *buffer;323size_t size;324};325326struct cec_adapter;327struct drm_connector;328struct drm_edid;329330/**331* struct drm_dp_aux_cec - DisplayPort CEC-Tunneling-over-AUX332* @lock: mutex protecting this struct333* @adap: the CEC adapter for CEC-Tunneling-over-AUX support.334* @connector: the connector this CEC adapter is associated with335* @unregister_work: unregister the CEC adapter336*/337struct drm_dp_aux_cec {338struct mutex lock;339struct cec_adapter *adap;340struct drm_connector *connector;341struct delayed_work unregister_work;342};343344/**345* struct drm_dp_aux - DisplayPort AUX channel346*347* An AUX channel can also be used to transport I2C messages to a sink. A348* typical application of that is to access an EDID that's present in the sink349* device. The @transfer() function can also be used to execute such350* transactions. The drm_dp_aux_register() function registers an I2C adapter351* that can be passed to drm_probe_ddc(). Upon removal, drivers should call352* drm_dp_aux_unregister() to remove the I2C adapter. The I2C adapter uses long353* transfers by default; if a partial response is received, the adapter will354* drop down to the size given by the partial response for this transaction355* only.356*/357struct drm_dp_aux {358/**359* @name: user-visible name of this AUX channel and the360* I2C-over-AUX adapter.361*362* It's also used to specify the name of the I2C adapter. If set363* to %NULL, dev_name() of @dev will be used.364*/365const char *name;366367/**368* @ddc: I2C adapter that can be used for I2C-over-AUX369* communication370*/371struct i2c_adapter ddc;372373/**374* @dev: pointer to struct device that is the parent for this375* AUX channel.376*/377struct device *dev;378379/**380* @drm_dev: pointer to the &drm_device that owns this AUX channel.381* Beware, this may be %NULL before drm_dp_aux_register() has been382* called.383*384* It should be set to the &drm_device that will be using this AUX385* channel as early as possible. For many graphics drivers this should386* happen before drm_dp_aux_init(), however it's perfectly fine to set387* this field later so long as it's assigned before calling388* drm_dp_aux_register().389*/390struct drm_device *drm_dev;391392/**393* @crtc: backpointer to the crtc that is currently using this394* AUX channel395*/396struct drm_crtc *crtc;397398/**399* @hw_mutex: internal mutex used for locking transfers.400*401* Note that if the underlying hardware is shared among multiple402* channels, the driver needs to do additional locking to403* prevent concurrent access.404*/405struct mutex hw_mutex;406407/**408* @crc_work: worker that captures CRCs for each frame409*/410struct work_struct crc_work;411412/**413* @crc_count: counter of captured frame CRCs414*/415u8 crc_count;416417/**418* @transfer: transfers a message representing a single AUX419* transaction.420*421* This is a hardware-specific implementation of how422* transactions are executed that the drivers must provide.423*424* A pointer to a &drm_dp_aux_msg structure describing the425* transaction is passed into this function. Upon success, the426* implementation should return the number of payload bytes that427* were transferred, or a negative error-code on failure.428*429* Helpers will propagate these errors, with the exception of430* the %-EBUSY error, which causes a transaction to be retried.431* On a short, helpers will return %-EPROTO to make it simpler432* to check for failure.433*434* The @transfer() function must only modify the reply field of435* the &drm_dp_aux_msg structure. The retry logic and i2c436* helpers assume this is the case.437*438* Also note that this callback can be called no matter the439* state @dev is in and also no matter what state the panel is440* in. It's expected:441*442* - If the @dev providing the AUX bus is currently unpowered then443* it will power itself up for the transfer.444*445* - If we're on eDP (using a drm_panel) and the panel is not in a446* state where it can respond (it's not powered or it's in a447* low power state) then this function may return an error, but448* not crash. It's up to the caller of this code to make sure that449* the panel is powered on if getting an error back is not OK. If a450* drm_panel driver is initiating a DP AUX transfer it may power451* itself up however it wants. All other code should ensure that452* the pre_enable() bridge chain (which eventually calls the453* drm_panel prepare function) has powered the panel.454*/455ssize_t (*transfer)(struct drm_dp_aux *aux,456struct drm_dp_aux_msg *msg);457458/**459* @wait_hpd_asserted: wait for HPD to be asserted460*461* This is mainly useful for eDP panels drivers to wait for an eDP462* panel to finish powering on. It is optional for DP AUX controllers463* to implement this function. It is required for DP AUX endpoints464* (panel drivers) to call this function after powering up but before465* doing AUX transfers unless the DP AUX endpoint driver knows that466* we're not using the AUX controller's HPD. One example of the panel467* driver not needing to call this is if HPD is hooked up to a GPIO468* that the panel driver can read directly.469*470* If a DP AUX controller does not implement this function then it471* may still support eDP panels that use the AUX controller's built-in472* HPD signal by implementing a long wait for HPD in the transfer()473* callback, though this is deprecated.474*475* This function will efficiently wait for the HPD signal to be476* asserted. The `wait_us` parameter that is passed in says that we477* know that the HPD signal is expected to be asserted within `wait_us`478* microseconds. This function could wait for longer than `wait_us` if479* the logic in the DP controller has a long debouncing time. The480* important thing is that if this function returns success that the481* DP controller is ready to send AUX transactions.482*483* This function returns 0 if HPD was asserted or -ETIMEDOUT if time484* expired and HPD wasn't asserted. This function should not print485* timeout errors to the log.486*487* The semantics of this function are designed to match the488* readx_poll_timeout() function. That means a `wait_us` of 0 means489* to wait forever. Like readx_poll_timeout(), this function may sleep.490*491* NOTE: this function specifically reports the state of the HPD pin492* that's associated with the DP AUX channel. This is different from493* the HPD concept in much of the rest of DRM which is more about494* physical presence of a display. For eDP, for instance, a display is495* assumed always present even if the HPD pin is deasserted.496*/497int (*wait_hpd_asserted)(struct drm_dp_aux *aux, unsigned long wait_us);498499/**500* @i2c_nack_count: Counts I2C NACKs, used for DP validation.501*/502unsigned i2c_nack_count;503/**504* @i2c_defer_count: Counts I2C DEFERs, used for DP validation.505*/506unsigned i2c_defer_count;507/**508* @cec: struct containing fields used for CEC-Tunneling-over-AUX.509*/510struct drm_dp_aux_cec cec;511/**512* @is_remote: Is this AUX CH actually using sideband messaging.513*/514bool is_remote;515516/**517* @powered_down: If true then the remote endpoint is powered down.518*/519bool powered_down;520521/**522* @no_zero_sized: If the hw can't use zero sized transfers (NVIDIA)523*/524bool no_zero_sized;525526/**527* @dpcd_probe_disabled: If probing before a DPCD access is disabled.528*/529bool dpcd_probe_disabled;530};531532int drm_dp_dpcd_probe(struct drm_dp_aux *aux, unsigned int offset);533void drm_dp_dpcd_set_powered(struct drm_dp_aux *aux, bool powered);534void drm_dp_dpcd_set_probe(struct drm_dp_aux *aux, bool enable);535ssize_t drm_dp_dpcd_read(struct drm_dp_aux *aux, unsigned int offset,536void *buffer, size_t size);537ssize_t drm_dp_dpcd_write(struct drm_dp_aux *aux, unsigned int offset,538void *buffer, size_t size);539540/**541* drm_dp_dpcd_read_data() - read a series of bytes from the DPCD542* @aux: DisplayPort AUX channel (SST or MST)543* @offset: address of the (first) register to read544* @buffer: buffer to store the register values545* @size: number of bytes in @buffer546*547* Returns zero (0) on success, or a negative error548* code on failure. -EIO is returned if the request was NAKed by the sink or549* if the retry count was exceeded. If not all bytes were transferred, this550* function returns -EPROTO. Errors from the underlying AUX channel transfer551* function, with the exception of -EBUSY (which causes the transaction to552* be retried), are propagated to the caller.553*/554static inline int drm_dp_dpcd_read_data(struct drm_dp_aux *aux,555unsigned int offset,556void *buffer, size_t size)557{558int ret;559560ret = drm_dp_dpcd_read(aux, offset, buffer, size);561if (ret < 0)562return ret;563if (ret < size)564return -EPROTO;565566return 0;567}568569/**570* drm_dp_dpcd_write_data() - write a series of bytes to the DPCD571* @aux: DisplayPort AUX channel (SST or MST)572* @offset: address of the (first) register to write573* @buffer: buffer containing the values to write574* @size: number of bytes in @buffer575*576* Returns zero (0) on success, or a negative error577* code on failure. -EIO is returned if the request was NAKed by the sink or578* if the retry count was exceeded. If not all bytes were transferred, this579* function returns -EPROTO. Errors from the underlying AUX channel transfer580* function, with the exception of -EBUSY (which causes the transaction to581* be retried), are propagated to the caller.582*/583static inline int drm_dp_dpcd_write_data(struct drm_dp_aux *aux,584unsigned int offset,585void *buffer, size_t size)586{587int ret;588589ret = drm_dp_dpcd_write(aux, offset, buffer, size);590if (ret < 0)591return ret;592if (ret < size)593return -EPROTO;594595return 0;596}597598/**599* drm_dp_dpcd_readb() - read a single byte from the DPCD600* @aux: DisplayPort AUX channel601* @offset: address of the register to read602* @valuep: location where the value of the register will be stored603*604* Returns the number of bytes transferred (1) on success, or a negative605* error code on failure. In most of the cases you should be using606* drm_dp_dpcd_read_byte() instead.607*/608static inline ssize_t drm_dp_dpcd_readb(struct drm_dp_aux *aux,609unsigned int offset, u8 *valuep)610{611return drm_dp_dpcd_read(aux, offset, valuep, 1);612}613614/**615* drm_dp_dpcd_writeb() - write a single byte to the DPCD616* @aux: DisplayPort AUX channel617* @offset: address of the register to write618* @value: value to write to the register619*620* Returns the number of bytes transferred (1) on success, or a negative621* error code on failure. In most of the cases you should be using622* drm_dp_dpcd_write_byte() instead.623*/624static inline ssize_t drm_dp_dpcd_writeb(struct drm_dp_aux *aux,625unsigned int offset, u8 value)626{627return drm_dp_dpcd_write(aux, offset, &value, 1);628}629630/**631* drm_dp_dpcd_read_byte() - read a single byte from the DPCD632* @aux: DisplayPort AUX channel633* @offset: address of the register to read634* @valuep: location where the value of the register will be stored635*636* Returns zero (0) on success, or a negative error code on failure.637*/638static inline int drm_dp_dpcd_read_byte(struct drm_dp_aux *aux,639unsigned int offset, u8 *valuep)640{641return drm_dp_dpcd_read_data(aux, offset, valuep, 1);642}643644/**645* drm_dp_dpcd_write_byte() - write a single byte to the DPCD646* @aux: DisplayPort AUX channel647* @offset: address of the register to write648* @value: value to write to the register649*650* Returns zero (0) on success, or a negative error code on failure.651*/652static inline int drm_dp_dpcd_write_byte(struct drm_dp_aux *aux,653unsigned int offset, u8 value)654{655return drm_dp_dpcd_write_data(aux, offset, &value, 1);656}657658int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux,659u8 dpcd[DP_RECEIVER_CAP_SIZE]);660661int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux,662u8 status[DP_LINK_STATUS_SIZE]);663664int drm_dp_dpcd_read_phy_link_status(struct drm_dp_aux *aux,665enum drm_dp_phy dp_phy,666u8 link_status[DP_LINK_STATUS_SIZE]);667int drm_dp_link_power_up(struct drm_dp_aux *aux, unsigned char revision);668int drm_dp_link_power_down(struct drm_dp_aux *aux, unsigned char revision);669670int drm_dp_dpcd_write_payload(struct drm_dp_aux *aux,671int vcpid, u8 start_time_slot, u8 time_slot_count);672int drm_dp_dpcd_clear_payload(struct drm_dp_aux *aux);673int drm_dp_dpcd_poll_act_handled(struct drm_dp_aux *aux, int timeout_ms);674675bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux,676u8 real_edid_checksum);677678int drm_dp_read_downstream_info(struct drm_dp_aux *aux,679const u8 dpcd[DP_RECEIVER_CAP_SIZE],680u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]);681bool drm_dp_downstream_is_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],682const u8 port_cap[4], u8 type);683bool drm_dp_downstream_is_tmds(const u8 dpcd[DP_RECEIVER_CAP_SIZE],684const u8 port_cap[4],685const struct drm_edid *drm_edid);686int drm_dp_downstream_max_dotclock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],687const u8 port_cap[4]);688int drm_dp_downstream_max_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],689const u8 port_cap[4],690const struct drm_edid *drm_edid);691int drm_dp_downstream_min_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],692const u8 port_cap[4],693const struct drm_edid *drm_edid);694int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],695const u8 port_cap[4],696const struct drm_edid *drm_edid);697bool drm_dp_downstream_420_passthrough(const u8 dpcd[DP_RECEIVER_CAP_SIZE],698const u8 port_cap[4]);699bool drm_dp_downstream_444_to_420_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],700const u8 port_cap[4]);701struct drm_display_mode *drm_dp_downstream_mode(struct drm_device *dev,702const u8 dpcd[DP_RECEIVER_CAP_SIZE],703const u8 port_cap[4]);704int drm_dp_downstream_id(struct drm_dp_aux *aux, char id[6]);705void drm_dp_downstream_debug(struct seq_file *m,706const u8 dpcd[DP_RECEIVER_CAP_SIZE],707const u8 port_cap[4],708const struct drm_edid *drm_edid,709struct drm_dp_aux *aux);710enum drm_mode_subconnector711drm_dp_subconnector_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],712const u8 port_cap[4]);713void drm_dp_set_subconnector_property(struct drm_connector *connector,714enum drm_connector_status status,715const u8 *dpcd,716const u8 port_cap[4]);717718struct drm_dp_desc;719bool drm_dp_read_sink_count_cap(struct drm_connector *connector,720const u8 dpcd[DP_RECEIVER_CAP_SIZE],721const struct drm_dp_desc *desc);722int drm_dp_read_sink_count(struct drm_dp_aux *aux);723724int drm_dp_read_lttpr_common_caps(struct drm_dp_aux *aux,725const u8 dpcd[DP_RECEIVER_CAP_SIZE],726u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);727int drm_dp_read_lttpr_phy_caps(struct drm_dp_aux *aux,728const u8 dpcd[DP_RECEIVER_CAP_SIZE],729enum drm_dp_phy dp_phy,730u8 caps[DP_LTTPR_PHY_CAP_SIZE]);731int drm_dp_lttpr_count(const u8 cap[DP_LTTPR_COMMON_CAP_SIZE]);732int drm_dp_lttpr_max_link_rate(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);733int drm_dp_lttpr_set_transparent_mode(struct drm_dp_aux *aux, bool enable);734int drm_dp_lttpr_init(struct drm_dp_aux *aux, int lttpr_count);735int drm_dp_lttpr_max_lane_count(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);736bool drm_dp_lttpr_voltage_swing_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);737bool drm_dp_lttpr_pre_emphasis_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);738void drm_dp_lttpr_wake_timeout_setup(struct drm_dp_aux *aux, bool transparent_mode);739740void drm_dp_remote_aux_init(struct drm_dp_aux *aux);741void drm_dp_aux_init(struct drm_dp_aux *aux);742int drm_dp_aux_register(struct drm_dp_aux *aux);743void drm_dp_aux_unregister(struct drm_dp_aux *aux);744745int drm_dp_start_crc(struct drm_dp_aux *aux, struct drm_crtc *crtc);746int drm_dp_stop_crc(struct drm_dp_aux *aux);747748struct drm_dp_dpcd_ident {749u8 oui[3];750u8 device_id[6];751u8 hw_rev;752u8 sw_major_rev;753u8 sw_minor_rev;754} __packed;755756/**757* struct drm_dp_desc - DP branch/sink device descriptor758* @ident: DP device identification from DPCD 0x400 (sink) or 0x500 (branch).759* @quirks: Quirks; use drm_dp_has_quirk() to query for the quirks.760*/761struct drm_dp_desc {762struct drm_dp_dpcd_ident ident;763u32 quirks;764};765766int drm_dp_read_desc(struct drm_dp_aux *aux, struct drm_dp_desc *desc,767bool is_branch);768769int drm_dp_dump_lttpr_desc(struct drm_dp_aux *aux, enum drm_dp_phy dp_phy);770771/**772* enum drm_dp_quirk - Display Port sink/branch device specific quirks773*774* Display Port sink and branch devices in the wild have a variety of bugs, try775* to collect them here. The quirks are shared, but it's up to the drivers to776* implement workarounds for them.777*/778enum drm_dp_quirk {779/**780* @DP_DPCD_QUIRK_CONSTANT_N:781*782* The device requires main link attributes Mvid and Nvid to be limited783* to 16 bits. So will give a constant value (0x8000) for compatability.784*/785DP_DPCD_QUIRK_CONSTANT_N,786/**787* @DP_DPCD_QUIRK_NO_PSR:788*789* The device does not support PSR even if reports that it supports or790* driver still need to implement proper handling for such device.791*/792DP_DPCD_QUIRK_NO_PSR,793/**794* @DP_DPCD_QUIRK_NO_SINK_COUNT:795*796* The device does not set SINK_COUNT to a non-zero value.797* The driver should ignore SINK_COUNT during detection. Note that798* drm_dp_read_sink_count_cap() automatically checks for this quirk.799*/800DP_DPCD_QUIRK_NO_SINK_COUNT,801/**802* @DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD:803*804* The device supports MST DSC despite not supporting Virtual DPCD.805* The DSC caps can be read from the physical aux instead.806*/807DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD,808/**809* @DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS:810*811* The device supports a link rate of 3.24 Gbps (multiplier 0xc) despite812* the DP_MAX_LINK_RATE register reporting a lower max multiplier.813*/814DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS,815/**816* @DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC:817*818* The device applies HBLANK expansion for some modes, but this819* requires enabling DSC.820*/821DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC,822};823824/**825* drm_dp_has_quirk() - does the DP device have a specific quirk826* @desc: Device descriptor filled by drm_dp_read_desc()827* @quirk: Quirk to query for828*829* Return true if DP device identified by @desc has @quirk.830*/831static inline bool832drm_dp_has_quirk(const struct drm_dp_desc *desc, enum drm_dp_quirk quirk)833{834return desc->quirks & BIT(quirk);835}836837/**838* struct drm_edp_backlight_info - Probed eDP backlight info struct839* @pwmgen_bit_count: The pwmgen bit count840* @pwm_freq_pre_divider: The PWM frequency pre-divider value being used for this backlight, if any841* @max: The maximum backlight level that may be set842* @lsb_reg_used: Do we also write values to the DP_EDP_BACKLIGHT_BRIGHTNESS_LSB register?843* @aux_enable: Does the panel support the AUX enable cap?844* @aux_set: Does the panel support setting the brightness through AUX?845* @luminance_set: Does the panel support setting the brightness through AUX using luminance values?846*847* This structure contains various data about an eDP backlight, which can be populated by using848* drm_edp_backlight_init().849*/850struct drm_edp_backlight_info {851u8 pwmgen_bit_count;852u8 pwm_freq_pre_divider;853u32 max;854855bool lsb_reg_used : 1;856bool aux_enable : 1;857bool aux_set : 1;858bool luminance_set : 1;859};860861int862drm_edp_backlight_init(struct drm_dp_aux *aux, struct drm_edp_backlight_info *bl,863u32 max_luminance,864u16 driver_pwm_freq_hz, const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE],865u32 *current_level, u8 *current_mode, bool need_luminance);866int drm_edp_backlight_set_level(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,867u32 level);868int drm_edp_backlight_enable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,869u32 level);870int drm_edp_backlight_disable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl);871872#if IS_ENABLED(CONFIG_DRM_KMS_HELPER) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \873(IS_MODULE(CONFIG_DRM_KMS_HELPER) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))874875int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux);876877#else878879static inline int drm_panel_dp_aux_backlight(struct drm_panel *panel,880struct drm_dp_aux *aux)881{882return 0;883}884885#endif886887#ifdef CONFIG_DRM_DISPLAY_DP_AUX_CEC888void drm_dp_cec_irq(struct drm_dp_aux *aux);889void drm_dp_cec_register_connector(struct drm_dp_aux *aux,890struct drm_connector *connector);891void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux);892void drm_dp_cec_attach(struct drm_dp_aux *aux, u16 source_physical_address);893void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid);894void drm_dp_cec_unset_edid(struct drm_dp_aux *aux);895#else896static inline void drm_dp_cec_irq(struct drm_dp_aux *aux)897{898}899900static inline void901drm_dp_cec_register_connector(struct drm_dp_aux *aux,902struct drm_connector *connector)903{904}905906static inline void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux)907{908}909910static inline void drm_dp_cec_attach(struct drm_dp_aux *aux,911u16 source_physical_address)912{913}914915static inline void drm_dp_cec_set_edid(struct drm_dp_aux *aux,916const struct edid *edid)917{918}919920static inline void drm_dp_cec_unset_edid(struct drm_dp_aux *aux)921{922}923924#endif925926/**927* struct drm_dp_phy_test_params - DP Phy Compliance parameters928* @link_rate: Requested Link rate from DPCD 0x219929* @num_lanes: Number of lanes requested by sing through DPCD 0x220930* @phy_pattern: DP Phy test pattern from DPCD 0x248931* @hbr2_reset: DP HBR2_COMPLIANCE_SCRAMBLER_RESET from DCPD 0x24A and 0x24B932* @custom80: DP Test_80BIT_CUSTOM_PATTERN from DPCDs 0x250 through 0x259933* @enhanced_frame_cap: flag for enhanced frame capability.934*/935struct drm_dp_phy_test_params {936int link_rate;937u8 num_lanes;938u8 phy_pattern;939u8 hbr2_reset[2];940u8 custom80[10];941bool enhanced_frame_cap;942};943944int drm_dp_get_phy_test_pattern(struct drm_dp_aux *aux,945struct drm_dp_phy_test_params *data);946int drm_dp_set_phy_test_pattern(struct drm_dp_aux *aux,947struct drm_dp_phy_test_params *data, u8 dp_rev);948int drm_dp_get_pcon_max_frl_bw(const u8 dpcd[DP_RECEIVER_CAP_SIZE],949const u8 port_cap[4]);950int drm_dp_pcon_frl_prepare(struct drm_dp_aux *aux, bool enable_frl_ready_hpd);951bool drm_dp_pcon_is_frl_ready(struct drm_dp_aux *aux);952int drm_dp_pcon_frl_configure_1(struct drm_dp_aux *aux, int max_frl_gbps,953u8 frl_mode);954int drm_dp_pcon_frl_configure_2(struct drm_dp_aux *aux, int max_frl_mask,955u8 frl_type);956int drm_dp_pcon_reset_frl_config(struct drm_dp_aux *aux);957int drm_dp_pcon_frl_enable(struct drm_dp_aux *aux);958959bool drm_dp_pcon_hdmi_link_active(struct drm_dp_aux *aux);960int drm_dp_pcon_hdmi_link_mode(struct drm_dp_aux *aux, u8 *frl_trained_mask);961void drm_dp_pcon_hdmi_frl_link_error_count(struct drm_dp_aux *aux,962struct drm_connector *connector);963bool drm_dp_pcon_enc_is_dsc_1_2(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);964int drm_dp_pcon_dsc_max_slices(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);965int drm_dp_pcon_dsc_max_slice_width(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);966int drm_dp_pcon_dsc_bpp_incr(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);967int drm_dp_pcon_pps_default(struct drm_dp_aux *aux);968int drm_dp_pcon_pps_override_buf(struct drm_dp_aux *aux, u8 pps_buf[128]);969int drm_dp_pcon_pps_override_param(struct drm_dp_aux *aux, u8 pps_param[6]);970bool drm_dp_downstream_rgb_to_ycbcr_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],971const u8 port_cap[4], u8 color_spc);972int drm_dp_pcon_convert_rgb_to_ycbcr(struct drm_dp_aux *aux, u8 color_spc);973974#define DRM_DP_BW_OVERHEAD_MST BIT(0)975#define DRM_DP_BW_OVERHEAD_UHBR BIT(1)976#define DRM_DP_BW_OVERHEAD_SSC_REF_CLK BIT(2)977#define DRM_DP_BW_OVERHEAD_FEC BIT(3)978#define DRM_DP_BW_OVERHEAD_DSC BIT(4)979980int drm_dp_bw_overhead(int lane_count, int hactive,981int dsc_slice_count,982int bpp_x16, unsigned long flags);983int drm_dp_bw_channel_coding_efficiency(bool is_uhbr);984int drm_dp_max_dprx_data_rate(int max_link_rate, int max_lanes);985986ssize_t drm_dp_vsc_sdp_pack(const struct drm_dp_vsc_sdp *vsc, struct dp_sdp *sdp);987int drm_dp_link_symbol_cycles(int lane_count, int pixels, int dsc_slice_count,988int bpp_x16, int symbol_size, bool is_mst);989990#endif /* _DRM_DP_HELPER_H_ */991992993