/*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);39bool drm_dp_post_lt_adj_req_in_progress(const u8 link_status[DP_LINK_STATUS_SIZE]);40u8 drm_dp_get_adjust_request_voltage(const u8 link_status[DP_LINK_STATUS_SIZE],41int lane);42u8 drm_dp_get_adjust_request_pre_emphasis(const u8 link_status[DP_LINK_STATUS_SIZE],43int lane);44u8 drm_dp_get_adjust_tx_ffe_preset(const u8 link_status[DP_LINK_STATUS_SIZE],45int lane);4647int drm_dp_read_clock_recovery_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],48enum drm_dp_phy dp_phy, bool uhbr);49int drm_dp_read_channel_eq_delay(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE],50enum drm_dp_phy dp_phy, bool uhbr);5152void drm_dp_link_train_clock_recovery_delay(const struct drm_dp_aux *aux,53const u8 dpcd[DP_RECEIVER_CAP_SIZE]);54void drm_dp_lttpr_link_train_clock_recovery_delay(void);55void drm_dp_link_train_channel_eq_delay(const struct drm_dp_aux *aux,56const u8 dpcd[DP_RECEIVER_CAP_SIZE]);57void drm_dp_lttpr_link_train_channel_eq_delay(const struct drm_dp_aux *aux,58const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);5960int drm_dp_128b132b_read_aux_rd_interval(struct drm_dp_aux *aux);61bool drm_dp_128b132b_lane_channel_eq_done(const u8 link_status[DP_LINK_STATUS_SIZE],62int lane_count);63bool drm_dp_128b132b_lane_symbol_locked(const u8 link_status[DP_LINK_STATUS_SIZE],64int lane_count);65bool drm_dp_128b132b_eq_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);66bool drm_dp_128b132b_cds_interlane_align_done(const u8 link_status[DP_LINK_STATUS_SIZE]);67bool drm_dp_128b132b_link_training_failed(const u8 link_status[DP_LINK_STATUS_SIZE]);6869u8 drm_dp_link_rate_to_bw_code(int link_rate);70int drm_dp_bw_code_to_link_rate(u8 link_bw);7172const char *drm_dp_phy_name(enum drm_dp_phy dp_phy);7374/**75* struct drm_dp_vsc_sdp - drm DP VSC SDP76*77* This structure represents a DP VSC SDP of drm78* It is based on DP 1.4 spec [Table 2-116: VSC SDP Header Bytes] and79* [Table 2-117: VSC SDP Payload for DB16 through DB18]80*81* @sdp_type: secondary-data packet type82* @revision: revision number83* @length: number of valid data bytes84* @pixelformat: pixel encoding format85* @colorimetry: colorimetry format86* @bpc: bit per color87* @dynamic_range: dynamic range information88* @content_type: CTA-861-G defines content types and expected processing by a sink device89*/90struct drm_dp_vsc_sdp {91unsigned char sdp_type;92unsigned char revision;93unsigned char length;94enum dp_pixelformat pixelformat;95enum dp_colorimetry colorimetry;96int bpc;97enum dp_dynamic_range dynamic_range;98enum dp_content_type content_type;99};100101/**102* struct drm_dp_as_sdp - drm DP Adaptive Sync SDP103*104* This structure represents a DP AS SDP of drm105* It is based on DP 2.1 spec [Table 2-126: Adaptive-Sync SDP Header Bytes] and106* [Table 2-127: Adaptive-Sync SDP Payload for DB0 through DB8]107*108* @sdp_type: Secondary-data packet type109* @revision: Revision Number110* @length: Number of valid data bytes111* @vtotal: Minimum Vertical Vtotal112* @target_rr: Target Refresh113* @duration_incr_ms: Successive frame duration increase114* @duration_decr_ms: Successive frame duration decrease115* @target_rr_divider: Target refresh rate divider116* @mode: Adaptive Sync Operation Mode117*/118struct drm_dp_as_sdp {119unsigned char sdp_type;120unsigned char revision;121unsigned char length;122int vtotal;123int target_rr;124int duration_incr_ms;125int duration_decr_ms;126bool target_rr_divider;127enum operation_mode mode;128};129130void drm_dp_as_sdp_log(struct drm_printer *p,131const struct drm_dp_as_sdp *as_sdp);132void drm_dp_vsc_sdp_log(struct drm_printer *p, const struct drm_dp_vsc_sdp *vsc);133134bool drm_dp_vsc_sdp_supported(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);135bool drm_dp_as_sdp_supported(struct drm_dp_aux *aux, const u8 dpcd[DP_RECEIVER_CAP_SIZE]);136137int drm_dp_psr_setup_time(const u8 psr_cap[EDP_PSR_RECEIVER_CAP_SIZE]);138139static inline int140drm_dp_max_link_rate(const u8 dpcd[DP_RECEIVER_CAP_SIZE])141{142return drm_dp_bw_code_to_link_rate(dpcd[DP_MAX_LINK_RATE]);143}144145static inline u8146drm_dp_max_lane_count(const u8 dpcd[DP_RECEIVER_CAP_SIZE])147{148return dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;149}150151static inline bool152drm_dp_enhanced_frame_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])153{154return dpcd[DP_DPCD_REV] >= 0x11 &&155(dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP);156}157158static inline bool159drm_dp_post_lt_adj_req_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])160{161return dpcd[DP_DPCD_REV] >= 0x13 &&162(dpcd[DP_MAX_LANE_COUNT] & DP_POST_LT_ADJ_REQ_SUPPORTED);163}164165static inline bool166drm_dp_fast_training_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])167{168return dpcd[DP_DPCD_REV] >= 0x11 &&169(dpcd[DP_MAX_DOWNSPREAD] & DP_NO_AUX_HANDSHAKE_LINK_TRAINING);170}171172static inline bool173drm_dp_tps3_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])174{175return dpcd[DP_DPCD_REV] >= 0x12 &&176dpcd[DP_MAX_LANE_COUNT] & DP_TPS3_SUPPORTED;177}178179static inline bool180drm_dp_max_downspread(const u8 dpcd[DP_RECEIVER_CAP_SIZE])181{182return dpcd[DP_DPCD_REV] >= 0x11 ||183dpcd[DP_MAX_DOWNSPREAD] & DP_MAX_DOWNSPREAD_0_5;184}185186static inline bool187drm_dp_tps4_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])188{189return dpcd[DP_DPCD_REV] >= 0x14 &&190dpcd[DP_MAX_DOWNSPREAD] & DP_TPS4_SUPPORTED;191}192193static inline u8194drm_dp_training_pattern_mask(const u8 dpcd[DP_RECEIVER_CAP_SIZE])195{196return (dpcd[DP_DPCD_REV] >= 0x14) ? DP_TRAINING_PATTERN_MASK_1_4 :197DP_TRAINING_PATTERN_MASK;198}199200static inline bool201drm_dp_is_branch(const u8 dpcd[DP_RECEIVER_CAP_SIZE])202{203return dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT;204}205206/* DP/eDP DSC support */207u8 drm_dp_dsc_sink_bpp_incr(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);208u32 drm_dp_dsc_slice_count_to_mask(int slice_count);209u32 drm_dp_dsc_sink_slice_count_mask(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],210bool is_edp);211u8 drm_dp_dsc_sink_max_slice_count(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],212bool is_edp);213u8 drm_dp_dsc_sink_line_buf_depth(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE]);214int drm_dp_dsc_sink_supported_input_bpcs(const u8 dsc_dpc[DP_DSC_RECEIVER_CAP_SIZE],215u8 dsc_bpc[3]);216int drm_dp_dsc_sink_max_slice_throughput(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE],217int peak_pixel_rate, bool is_rgb_yuv444);218int drm_dp_dsc_branch_max_overall_throughput(const u8 dsc_branch_dpcd[DP_DSC_BRANCH_CAP_SIZE],219bool is_rgb_yuv444);220int drm_dp_dsc_branch_max_line_width(const u8 dsc_branch_dpcd[DP_DSC_BRANCH_CAP_SIZE]);221222static inline bool223drm_dp_sink_supports_dsc(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])224{225return dsc_dpcd[DP_DSC_SUPPORT - DP_DSC_SUPPORT] &226DP_DSC_DECOMPRESSION_IS_SUPPORTED;227}228229static inline u16230drm_edp_dsc_sink_output_bpp(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])231{232return dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_LOW - DP_DSC_SUPPORT] |233((dsc_dpcd[DP_DSC_MAX_BITS_PER_PIXEL_HI - DP_DSC_SUPPORT] &234DP_DSC_MAX_BITS_PER_PIXEL_HI_MASK) << 8);235}236237static inline u32238drm_dp_dsc_sink_max_slice_width(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE])239{240/* Max Slicewidth = Number of Pixels * 320 */241return dsc_dpcd[DP_DSC_MAX_SLICE_WIDTH - DP_DSC_SUPPORT] *242DP_DSC_SLICE_WIDTH_MULTIPLIER;243}244245/**246* drm_dp_dsc_sink_supports_format() - check if sink supports DSC with given output format247* @dsc_dpcd : DSC-capability DPCDs of the sink248* @output_format: output_format which is to be checked249*250* Returns true if the sink supports DSC with the given output_format, false otherwise.251*/252static inline bool253drm_dp_dsc_sink_supports_format(const u8 dsc_dpcd[DP_DSC_RECEIVER_CAP_SIZE], u8 output_format)254{255return dsc_dpcd[DP_DSC_DEC_COLOR_FORMAT_CAP - DP_DSC_SUPPORT] & output_format;256}257258/* Forward Error Correction Support on DP 1.4 */259static inline bool260drm_dp_sink_supports_fec(const u8 fec_capable)261{262return fec_capable & DP_FEC_CAPABLE;263}264265static inline bool266drm_dp_channel_coding_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])267{268return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_8B10B;269}270271static inline bool272drm_dp_128b132b_supported(const u8 dpcd[DP_RECEIVER_CAP_SIZE])273{274return dpcd[DP_MAIN_LINK_CHANNEL_CODING] & DP_CAP_ANSI_128B132B;275}276277static inline bool278drm_dp_alternate_scrambler_reset_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])279{280return dpcd[DP_EDP_CONFIGURATION_CAP] &281DP_ALTERNATE_SCRAMBLER_RESET_CAP;282}283284/* Ignore MSA timing for Adaptive Sync support on DP 1.4 */285static inline bool286drm_dp_sink_can_do_video_without_timing_msa(const u8 dpcd[DP_RECEIVER_CAP_SIZE])287{288return dpcd[DP_DOWN_STREAM_PORT_COUNT] &289DP_MSA_TIMING_PAR_IGNORED;290}291292/**293* drm_edp_backlight_supported() - Check an eDP DPCD for VESA backlight support294* @edp_dpcd: The DPCD to check295*296* Note that currently this function will return %false for panels which support various DPCD297* backlight features but which require the brightness be set through PWM, and don't support setting298* the brightness level via the DPCD.299*300* Returns: %True if @edp_dpcd indicates that VESA backlight controls are supported, %false301* otherwise302*/303static inline bool304drm_edp_backlight_supported(const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE])305{306return !!(edp_dpcd[1] & DP_EDP_TCON_BACKLIGHT_ADJUSTMENT_CAP);307}308309/**310* drm_dp_is_uhbr_rate - Determine if a link rate is UHBR311* @link_rate: link rate in 10kbits/s units312*313* Determine if the provided link rate is an UHBR rate.314*315* Returns: %True if @link_rate is an UHBR rate.316*/317static inline bool drm_dp_is_uhbr_rate(int link_rate)318{319return link_rate >= 1000000;320}321322/*323* DisplayPort AUX channel324*/325326/**327* struct drm_dp_aux_msg - DisplayPort AUX channel transaction328* @address: address of the (first) register to access329* @request: contains the type of transaction (see DP_AUX_* macros)330* @reply: upon completion, contains the reply type of the transaction331* @buffer: pointer to a transmission or reception buffer332* @size: size of @buffer333*/334struct drm_dp_aux_msg {335unsigned int address;336u8 request;337u8 reply;338void *buffer;339size_t size;340};341342struct cec_adapter;343struct drm_connector;344struct drm_edid;345346/**347* struct drm_dp_aux_cec - DisplayPort CEC-Tunneling-over-AUX348* @lock: mutex protecting this struct349* @adap: the CEC adapter for CEC-Tunneling-over-AUX support.350* @connector: the connector this CEC adapter is associated with351* @unregister_work: unregister the CEC adapter352*/353struct drm_dp_aux_cec {354struct mutex lock;355struct cec_adapter *adap;356struct drm_connector *connector;357struct delayed_work unregister_work;358};359360/**361* struct drm_dp_aux - DisplayPort AUX channel362*363* An AUX channel can also be used to transport I2C messages to a sink. A364* typical application of that is to access an EDID that's present in the sink365* device. The @transfer() function can also be used to execute such366* transactions. The drm_dp_aux_register() function registers an I2C adapter367* that can be passed to drm_probe_ddc(). Upon removal, drivers should call368* drm_dp_aux_unregister() to remove the I2C adapter. The I2C adapter uses long369* transfers by default; if a partial response is received, the adapter will370* drop down to the size given by the partial response for this transaction371* only.372*/373struct drm_dp_aux {374/**375* @name: user-visible name of this AUX channel and the376* I2C-over-AUX adapter.377*378* It's also used to specify the name of the I2C adapter. If set379* to %NULL, dev_name() of @dev will be used.380*/381const char *name;382383/**384* @ddc: I2C adapter that can be used for I2C-over-AUX385* communication386*/387struct i2c_adapter ddc;388389/**390* @dev: pointer to struct device that is the parent for this391* AUX channel.392*/393struct device *dev;394395/**396* @drm_dev: pointer to the &drm_device that owns this AUX channel.397* Beware, this may be %NULL before drm_dp_aux_register() has been398* called.399*400* It should be set to the &drm_device that will be using this AUX401* channel as early as possible. For many graphics drivers this should402* happen before drm_dp_aux_init(), however it's perfectly fine to set403* this field later so long as it's assigned before calling404* drm_dp_aux_register().405*/406struct drm_device *drm_dev;407408/**409* @crtc: backpointer to the crtc that is currently using this410* AUX channel411*/412struct drm_crtc *crtc;413414/**415* @hw_mutex: internal mutex used for locking transfers.416*417* Note that if the underlying hardware is shared among multiple418* channels, the driver needs to do additional locking to419* prevent concurrent access.420*/421struct mutex hw_mutex;422423/**424* @crc_work: worker that captures CRCs for each frame425*/426struct work_struct crc_work;427428/**429* @crc_count: counter of captured frame CRCs430*/431u8 crc_count;432433/**434* @transfer: transfers a message representing a single AUX435* transaction.436*437* This is a hardware-specific implementation of how438* transactions are executed that the drivers must provide.439*440* A pointer to a &drm_dp_aux_msg structure describing the441* transaction is passed into this function. Upon success, the442* implementation should return the number of payload bytes that443* were transferred, or a negative error-code on failure.444*445* Helpers will propagate these errors, with the exception of446* the %-EBUSY error, which causes a transaction to be retried.447* On a short, helpers will return %-EPROTO to make it simpler448* to check for failure.449*450* The @transfer() function must only modify the reply field of451* the &drm_dp_aux_msg structure. The retry logic and i2c452* helpers assume this is the case.453*454* Also note that this callback can be called no matter the455* state @dev is in and also no matter what state the panel is456* in. It's expected:457*458* - If the @dev providing the AUX bus is currently unpowered then459* it will power itself up for the transfer.460*461* - If we're on eDP (using a drm_panel) and the panel is not in a462* state where it can respond (it's not powered or it's in a463* low power state) then this function may return an error, but464* not crash. It's up to the caller of this code to make sure that465* the panel is powered on if getting an error back is not OK. If a466* drm_panel driver is initiating a DP AUX transfer it may power467* itself up however it wants. All other code should ensure that468* the pre_enable() bridge chain (which eventually calls the469* drm_panel prepare function) has powered the panel.470*/471ssize_t (*transfer)(struct drm_dp_aux *aux,472struct drm_dp_aux_msg *msg);473474/**475* @wait_hpd_asserted: wait for HPD to be asserted476*477* This is mainly useful for eDP panels drivers to wait for an eDP478* panel to finish powering on. It is optional for DP AUX controllers479* to implement this function. It is required for DP AUX endpoints480* (panel drivers) to call this function after powering up but before481* doing AUX transfers unless the DP AUX endpoint driver knows that482* we're not using the AUX controller's HPD. One example of the panel483* driver not needing to call this is if HPD is hooked up to a GPIO484* that the panel driver can read directly.485*486* If a DP AUX controller does not implement this function then it487* may still support eDP panels that use the AUX controller's built-in488* HPD signal by implementing a long wait for HPD in the transfer()489* callback, though this is deprecated.490*491* This function will efficiently wait for the HPD signal to be492* asserted. The `wait_us` parameter that is passed in says that we493* know that the HPD signal is expected to be asserted within `wait_us`494* microseconds. This function could wait for longer than `wait_us` if495* the logic in the DP controller has a long debouncing time. The496* important thing is that if this function returns success that the497* DP controller is ready to send AUX transactions.498*499* This function returns 0 if HPD was asserted or -ETIMEDOUT if time500* expired and HPD wasn't asserted. This function should not print501* timeout errors to the log.502*503* The semantics of this function are designed to match the504* readx_poll_timeout() function. That means a `wait_us` of 0 means505* to wait forever. Like readx_poll_timeout(), this function may sleep.506*507* NOTE: this function specifically reports the state of the HPD pin508* that's associated with the DP AUX channel. This is different from509* the HPD concept in much of the rest of DRM which is more about510* physical presence of a display. For eDP, for instance, a display is511* assumed always present even if the HPD pin is deasserted.512*/513int (*wait_hpd_asserted)(struct drm_dp_aux *aux, unsigned long wait_us);514515/**516* @i2c_nack_count: Counts I2C NACKs, used for DP validation.517*/518unsigned i2c_nack_count;519/**520* @i2c_defer_count: Counts I2C DEFERs, used for DP validation.521*/522unsigned i2c_defer_count;523/**524* @cec: struct containing fields used for CEC-Tunneling-over-AUX.525*/526struct drm_dp_aux_cec cec;527/**528* @is_remote: Is this AUX CH actually using sideband messaging.529*/530bool is_remote;531532/**533* @powered_down: If true then the remote endpoint is powered down.534*/535bool powered_down;536537/**538* @no_zero_sized: If the hw can't use zero sized transfers (NVIDIA)539*/540bool no_zero_sized;541542/**543* @dpcd_probe_disabled: If probing before a DPCD access is disabled.544*/545bool dpcd_probe_disabled;546};547548int drm_dp_dpcd_probe(struct drm_dp_aux *aux, unsigned int offset);549void drm_dp_dpcd_set_powered(struct drm_dp_aux *aux, bool powered);550void drm_dp_dpcd_set_probe(struct drm_dp_aux *aux, bool enable);551ssize_t drm_dp_dpcd_read(struct drm_dp_aux *aux, unsigned int offset,552void *buffer, size_t size);553ssize_t drm_dp_dpcd_write(struct drm_dp_aux *aux, unsigned int offset,554void *buffer, size_t size);555556/**557* drm_dp_dpcd_readb() - read a single byte from the DPCD558* @aux: DisplayPort AUX channel559* @offset: address of the register to read560* @valuep: location where the value of the register will be stored561*562* Returns the number of bytes transferred (1) on success, or a negative563* error code on failure. In most of the cases you should be using564* drm_dp_dpcd_read_byte() instead.565*/566static inline ssize_t drm_dp_dpcd_readb(struct drm_dp_aux *aux,567unsigned int offset, u8 *valuep)568{569return drm_dp_dpcd_read(aux, offset, valuep, 1);570}571572/**573* drm_dp_dpcd_read_data() - read a series of bytes from the DPCD574* @aux: DisplayPort AUX channel (SST or MST)575* @offset: address of the (first) register to read576* @buffer: buffer to store the register values577* @size: number of bytes in @buffer578*579* Returns zero (0) on success, or a negative error580* code on failure. -EIO is returned if the request was NAKed by the sink or581* if the retry count was exceeded. If not all bytes were transferred, this582* function returns -EPROTO. Errors from the underlying AUX channel transfer583* function, with the exception of -EBUSY (which causes the transaction to584* be retried), are propagated to the caller.585*/586static inline int drm_dp_dpcd_read_data(struct drm_dp_aux *aux,587unsigned int offset,588void *buffer, size_t size)589{590int ret;591size_t i;592u8 *buf = buffer;593594ret = drm_dp_dpcd_read(aux, offset, buffer, size);595if (ret >= 0) {596if (ret < size)597return -EPROTO;598return 0;599}600601/*602* Workaround for USB-C hubs/adapters with buggy firmware that fail603* multi-byte AUX reads but work with single-byte reads.604* Known affected devices:605* - Lenovo USB-C to VGA adapter (VIA VL817, idVendor=17ef, idProduct=7217)606* - Dell DA310 USB-C hub (idVendor=413c, idProduct=c010)607* Attempt byte-by-byte reading as a fallback.608*/609for (i = 0; i < size; i++) {610ret = drm_dp_dpcd_readb(aux, offset + i, &buf[i]);611if (ret < 0)612return ret;613}614615return 0;616}617618/**619* drm_dp_dpcd_write_data() - write a series of bytes to the DPCD620* @aux: DisplayPort AUX channel (SST or MST)621* @offset: address of the (first) register to write622* @buffer: buffer containing the values to write623* @size: number of bytes in @buffer624*625* Returns zero (0) on success, or a negative error626* code on failure. -EIO is returned if the request was NAKed by the sink or627* if the retry count was exceeded. If not all bytes were transferred, this628* function returns -EPROTO. Errors from the underlying AUX channel transfer629* function, with the exception of -EBUSY (which causes the transaction to630* be retried), are propagated to the caller.631*/632static inline int drm_dp_dpcd_write_data(struct drm_dp_aux *aux,633unsigned int offset,634void *buffer, size_t size)635{636int ret;637638ret = drm_dp_dpcd_write(aux, offset, buffer, size);639if (ret < 0)640return ret;641if (ret < size)642return -EPROTO;643644return 0;645}646647/**648* drm_dp_dpcd_writeb() - write a single byte to the DPCD649* @aux: DisplayPort AUX channel650* @offset: address of the register to write651* @value: value to write to the register652*653* Returns the number of bytes transferred (1) on success, or a negative654* error code on failure. In most of the cases you should be using655* drm_dp_dpcd_write_byte() instead.656*/657static inline ssize_t drm_dp_dpcd_writeb(struct drm_dp_aux *aux,658unsigned int offset, u8 value)659{660return drm_dp_dpcd_write(aux, offset, &value, 1);661}662663/**664* drm_dp_dpcd_read_byte() - read a single byte from the DPCD665* @aux: DisplayPort AUX channel666* @offset: address of the register to read667* @valuep: location where the value of the register will be stored668*669* Returns zero (0) on success, or a negative error code on failure.670*/671static inline int drm_dp_dpcd_read_byte(struct drm_dp_aux *aux,672unsigned int offset, u8 *valuep)673{674return drm_dp_dpcd_read_data(aux, offset, valuep, 1);675}676677/**678* drm_dp_dpcd_write_byte() - write a single byte to the DPCD679* @aux: DisplayPort AUX channel680* @offset: address of the register to write681* @value: value to write to the register682*683* Returns zero (0) on success, or a negative error code on failure.684*/685static inline int drm_dp_dpcd_write_byte(struct drm_dp_aux *aux,686unsigned int offset, u8 value)687{688return drm_dp_dpcd_write_data(aux, offset, &value, 1);689}690691int drm_dp_read_dpcd_caps(struct drm_dp_aux *aux,692u8 dpcd[DP_RECEIVER_CAP_SIZE]);693694int drm_dp_dpcd_read_link_status(struct drm_dp_aux *aux,695u8 status[DP_LINK_STATUS_SIZE]);696697int drm_dp_dpcd_read_phy_link_status(struct drm_dp_aux *aux,698enum drm_dp_phy dp_phy,699u8 link_status[DP_LINK_STATUS_SIZE]);700int drm_dp_link_power_up(struct drm_dp_aux *aux, unsigned char revision);701int drm_dp_link_power_down(struct drm_dp_aux *aux, unsigned char revision);702703int drm_dp_dpcd_write_payload(struct drm_dp_aux *aux,704int vcpid, u8 start_time_slot, u8 time_slot_count);705int drm_dp_dpcd_clear_payload(struct drm_dp_aux *aux);706int drm_dp_dpcd_poll_act_handled(struct drm_dp_aux *aux, int timeout_ms);707708bool drm_dp_send_real_edid_checksum(struct drm_dp_aux *aux,709u8 real_edid_checksum);710711int drm_dp_read_downstream_info(struct drm_dp_aux *aux,712const u8 dpcd[DP_RECEIVER_CAP_SIZE],713u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS]);714bool drm_dp_downstream_is_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],715const u8 port_cap[4], u8 type);716bool drm_dp_downstream_is_tmds(const u8 dpcd[DP_RECEIVER_CAP_SIZE],717const u8 port_cap[4],718const struct drm_edid *drm_edid);719int drm_dp_downstream_max_dotclock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],720const u8 port_cap[4]);721int drm_dp_downstream_max_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],722const u8 port_cap[4],723const struct drm_edid *drm_edid);724int drm_dp_downstream_min_tmds_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE],725const u8 port_cap[4],726const struct drm_edid *drm_edid);727int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],728const u8 port_cap[4],729const struct drm_edid *drm_edid);730bool drm_dp_downstream_420_passthrough(const u8 dpcd[DP_RECEIVER_CAP_SIZE],731const u8 port_cap[4]);732bool drm_dp_downstream_444_to_420_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],733const u8 port_cap[4]);734struct drm_display_mode *drm_dp_downstream_mode(struct drm_device *dev,735const u8 dpcd[DP_RECEIVER_CAP_SIZE],736const u8 port_cap[4]);737int drm_dp_downstream_id(struct drm_dp_aux *aux, char id[6]);738void drm_dp_downstream_debug(struct seq_file *m,739const u8 dpcd[DP_RECEIVER_CAP_SIZE],740const u8 port_cap[4],741const struct drm_edid *drm_edid,742struct drm_dp_aux *aux);743enum drm_mode_subconnector744drm_dp_subconnector_type(const u8 dpcd[DP_RECEIVER_CAP_SIZE],745const u8 port_cap[4]);746void drm_dp_set_subconnector_property(struct drm_connector *connector,747enum drm_connector_status status,748const u8 *dpcd,749const u8 port_cap[4]);750751struct drm_dp_desc;752bool drm_dp_read_sink_count_cap(struct drm_connector *connector,753const u8 dpcd[DP_RECEIVER_CAP_SIZE],754const struct drm_dp_desc *desc);755int drm_dp_read_sink_count(struct drm_dp_aux *aux);756757int drm_dp_read_lttpr_common_caps(struct drm_dp_aux *aux,758const u8 dpcd[DP_RECEIVER_CAP_SIZE],759u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);760int drm_dp_read_lttpr_phy_caps(struct drm_dp_aux *aux,761const u8 dpcd[DP_RECEIVER_CAP_SIZE],762enum drm_dp_phy dp_phy,763u8 caps[DP_LTTPR_PHY_CAP_SIZE]);764int drm_dp_lttpr_count(const u8 cap[DP_LTTPR_COMMON_CAP_SIZE]);765int drm_dp_lttpr_max_link_rate(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);766int drm_dp_lttpr_set_transparent_mode(struct drm_dp_aux *aux, bool enable);767int drm_dp_lttpr_init(struct drm_dp_aux *aux, int lttpr_count);768int drm_dp_lttpr_max_lane_count(const u8 caps[DP_LTTPR_COMMON_CAP_SIZE]);769bool drm_dp_lttpr_voltage_swing_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);770bool drm_dp_lttpr_pre_emphasis_level_3_supported(const u8 caps[DP_LTTPR_PHY_CAP_SIZE]);771void drm_dp_lttpr_wake_timeout_setup(struct drm_dp_aux *aux, bool transparent_mode);772773void drm_dp_remote_aux_init(struct drm_dp_aux *aux);774void drm_dp_aux_init(struct drm_dp_aux *aux);775int drm_dp_aux_register(struct drm_dp_aux *aux);776void drm_dp_aux_unregister(struct drm_dp_aux *aux);777778int drm_dp_start_crc(struct drm_dp_aux *aux, struct drm_crtc *crtc);779int drm_dp_stop_crc(struct drm_dp_aux *aux);780781struct drm_dp_dpcd_ident {782u8 oui[3];783u8 device_id[6];784u8 hw_rev;785u8 sw_major_rev;786u8 sw_minor_rev;787} __packed;788789/**790* struct drm_dp_desc - DP branch/sink device descriptor791* @ident: DP device identification from DPCD 0x400 (sink) or 0x500 (branch).792* @quirks: Quirks; use drm_dp_has_quirk() to query for the quirks.793*/794struct drm_dp_desc {795struct drm_dp_dpcd_ident ident;796u32 quirks;797};798799int drm_dp_read_desc(struct drm_dp_aux *aux, struct drm_dp_desc *desc,800bool is_branch);801802int drm_dp_dump_lttpr_desc(struct drm_dp_aux *aux, enum drm_dp_phy dp_phy);803804/**805* enum drm_dp_quirk - Display Port sink/branch device specific quirks806*807* Display Port sink and branch devices in the wild have a variety of bugs, try808* to collect them here. The quirks are shared, but it's up to the drivers to809* implement workarounds for them.810*/811enum drm_dp_quirk {812/**813* @DP_DPCD_QUIRK_CONSTANT_N:814*815* The device requires main link attributes Mvid and Nvid to be limited816* to 16 bits. So will give a constant value (0x8000) for compatability.817*/818DP_DPCD_QUIRK_CONSTANT_N,819/**820* @DP_DPCD_QUIRK_NO_PSR:821*822* The device does not support PSR even if reports that it supports or823* driver still need to implement proper handling for such device.824*/825DP_DPCD_QUIRK_NO_PSR,826/**827* @DP_DPCD_QUIRK_NO_SINK_COUNT:828*829* The device does not set SINK_COUNT to a non-zero value.830* The driver should ignore SINK_COUNT during detection. Note that831* drm_dp_read_sink_count_cap() automatically checks for this quirk.832*/833DP_DPCD_QUIRK_NO_SINK_COUNT,834/**835* @DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD:836*837* The device supports MST DSC despite not supporting Virtual DPCD.838* The DSC caps can be read from the physical aux instead.839*/840DP_DPCD_QUIRK_DSC_WITHOUT_VIRTUAL_DPCD,841/**842* @DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS:843*844* The device supports a link rate of 3.24 Gbps (multiplier 0xc) despite845* the DP_MAX_LINK_RATE register reporting a lower max multiplier.846*/847DP_DPCD_QUIRK_CAN_DO_MAX_LINK_RATE_3_24_GBPS,848/**849* @DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC:850*851* The device applies HBLANK expansion for some modes, but this852* requires enabling DSC.853*/854DP_DPCD_QUIRK_HBLANK_EXPANSION_REQUIRES_DSC,855/**856* @DP_DPCD_QUIRK_DSC_THROUGHPUT_BPP_LIMIT:857*858* The device doesn't support DSC decompression at the maximum DSC859* pixel throughput and compressed bpp it indicates via its DPCD DSC860* capabilities. The compressed bpp must be limited above a device861* specific DSC pixel throughput.862*/863DP_DPCD_QUIRK_DSC_THROUGHPUT_BPP_LIMIT,864};865866/**867* drm_dp_has_quirk() - does the DP device have a specific quirk868* @desc: Device descriptor filled by drm_dp_read_desc()869* @quirk: Quirk to query for870*871* Return true if DP device identified by @desc has @quirk.872*/873static inline bool874drm_dp_has_quirk(const struct drm_dp_desc *desc, enum drm_dp_quirk quirk)875{876return desc->quirks & BIT(quirk);877}878879/**880* struct drm_edp_backlight_info - Probed eDP backlight info struct881* @pwmgen_bit_count: The pwmgen bit count882* @pwm_freq_pre_divider: The PWM frequency pre-divider value being used for this backlight, if any883* @max: The maximum backlight level that may be set884* @lsb_reg_used: Do we also write values to the DP_EDP_BACKLIGHT_BRIGHTNESS_LSB register?885* @aux_enable: Does the panel support the AUX enable cap?886* @aux_set: Does the panel support setting the brightness through AUX?887* @luminance_set: Does the panel support setting the brightness through AUX using luminance values?888*889* This structure contains various data about an eDP backlight, which can be populated by using890* drm_edp_backlight_init().891*/892struct drm_edp_backlight_info {893u8 pwmgen_bit_count;894u8 pwm_freq_pre_divider;895u32 max;896897bool lsb_reg_used : 1;898bool aux_enable : 1;899bool aux_set : 1;900bool luminance_set : 1;901};902903int904drm_edp_backlight_init(struct drm_dp_aux *aux, struct drm_edp_backlight_info *bl,905u32 max_luminance,906u16 driver_pwm_freq_hz, const u8 edp_dpcd[EDP_DISPLAY_CTL_CAP_SIZE],907u32 *current_level, u8 *current_mode, bool need_luminance);908int drm_edp_backlight_set_level(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,909u32 level);910int drm_edp_backlight_enable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl,911u32 level);912int drm_edp_backlight_disable(struct drm_dp_aux *aux, const struct drm_edp_backlight_info *bl);913914#if IS_ENABLED(CONFIG_DRM_KMS_HELPER) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \915(IS_MODULE(CONFIG_DRM_KMS_HELPER) && IS_MODULE(CONFIG_BACKLIGHT_CLASS_DEVICE)))916917int drm_panel_dp_aux_backlight(struct drm_panel *panel, struct drm_dp_aux *aux);918919#else920921static inline int drm_panel_dp_aux_backlight(struct drm_panel *panel,922struct drm_dp_aux *aux)923{924return 0;925}926927#endif928929#ifdef CONFIG_DRM_DISPLAY_DP_AUX_CEC930void drm_dp_cec_irq(struct drm_dp_aux *aux);931void drm_dp_cec_register_connector(struct drm_dp_aux *aux,932struct drm_connector *connector);933void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux);934void drm_dp_cec_attach(struct drm_dp_aux *aux, u16 source_physical_address);935void drm_dp_cec_set_edid(struct drm_dp_aux *aux, const struct edid *edid);936void drm_dp_cec_unset_edid(struct drm_dp_aux *aux);937#else938static inline void drm_dp_cec_irq(struct drm_dp_aux *aux)939{940}941942static inline void943drm_dp_cec_register_connector(struct drm_dp_aux *aux,944struct drm_connector *connector)945{946}947948static inline void drm_dp_cec_unregister_connector(struct drm_dp_aux *aux)949{950}951952static inline void drm_dp_cec_attach(struct drm_dp_aux *aux,953u16 source_physical_address)954{955}956957static inline void drm_dp_cec_set_edid(struct drm_dp_aux *aux,958const struct edid *edid)959{960}961962static inline void drm_dp_cec_unset_edid(struct drm_dp_aux *aux)963{964}965966#endif967968/**969* struct drm_dp_phy_test_params - DP Phy Compliance parameters970* @link_rate: Requested Link rate from DPCD 0x219971* @num_lanes: Number of lanes requested by sing through DPCD 0x220972* @phy_pattern: DP Phy test pattern from DPCD 0x248973* @hbr2_reset: DP HBR2_COMPLIANCE_SCRAMBLER_RESET from DCPD 0x24A and 0x24B974* @custom80: DP Test_80BIT_CUSTOM_PATTERN from DPCDs 0x250 through 0x259975* @enhanced_frame_cap: flag for enhanced frame capability.976*/977struct drm_dp_phy_test_params {978int link_rate;979u8 num_lanes;980u8 phy_pattern;981u8 hbr2_reset[2];982u8 custom80[10];983bool enhanced_frame_cap;984};985986int drm_dp_get_phy_test_pattern(struct drm_dp_aux *aux,987struct drm_dp_phy_test_params *data);988int drm_dp_set_phy_test_pattern(struct drm_dp_aux *aux,989struct drm_dp_phy_test_params *data, u8 dp_rev);990int drm_dp_get_pcon_max_frl_bw(const u8 dpcd[DP_RECEIVER_CAP_SIZE],991const u8 port_cap[4]);992int drm_dp_pcon_frl_prepare(struct drm_dp_aux *aux, bool enable_frl_ready_hpd);993bool drm_dp_pcon_is_frl_ready(struct drm_dp_aux *aux);994int drm_dp_pcon_frl_configure_1(struct drm_dp_aux *aux, int max_frl_gbps,995u8 frl_mode);996int drm_dp_pcon_frl_configure_2(struct drm_dp_aux *aux, int max_frl_mask,997u8 frl_type);998int drm_dp_pcon_reset_frl_config(struct drm_dp_aux *aux);999int drm_dp_pcon_frl_enable(struct drm_dp_aux *aux);10001001bool drm_dp_pcon_hdmi_link_active(struct drm_dp_aux *aux);1002int drm_dp_pcon_hdmi_link_mode(struct drm_dp_aux *aux, u8 *frl_trained_mask);1003void drm_dp_pcon_hdmi_frl_link_error_count(struct drm_dp_aux *aux,1004struct drm_connector *connector);1005bool drm_dp_pcon_enc_is_dsc_1_2(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);1006int drm_dp_pcon_dsc_max_slices(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);1007int drm_dp_pcon_dsc_max_slice_width(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);1008int drm_dp_pcon_dsc_bpp_incr(const u8 pcon_dsc_dpcd[DP_PCON_DSC_ENCODER_CAP_SIZE]);1009int drm_dp_pcon_pps_default(struct drm_dp_aux *aux);1010int drm_dp_pcon_pps_override_buf(struct drm_dp_aux *aux, u8 pps_buf[128]);1011int drm_dp_pcon_pps_override_param(struct drm_dp_aux *aux, u8 pps_param[6]);1012bool drm_dp_downstream_rgb_to_ycbcr_conversion(const u8 dpcd[DP_RECEIVER_CAP_SIZE],1013const u8 port_cap[4], u8 color_spc);1014int drm_dp_pcon_convert_rgb_to_ycbcr(struct drm_dp_aux *aux, u8 color_spc);10151016#define DRM_DP_BW_OVERHEAD_MST BIT(0)1017#define DRM_DP_BW_OVERHEAD_UHBR BIT(1)1018#define DRM_DP_BW_OVERHEAD_SSC_REF_CLK BIT(2)1019#define DRM_DP_BW_OVERHEAD_FEC BIT(3)1020#define DRM_DP_BW_OVERHEAD_DSC BIT(4)10211022int drm_dp_bw_overhead(int lane_count, int hactive,1023int dsc_slice_count,1024int bpp_x16, unsigned long flags);1025int drm_dp_bw_channel_coding_efficiency(bool is_uhbr);1026int drm_dp_max_dprx_data_rate(int max_link_rate, int max_lanes);10271028ssize_t drm_dp_vsc_sdp_pack(const struct drm_dp_vsc_sdp *vsc, struct dp_sdp *sdp);1029int drm_dp_link_symbol_cycles(int lane_count, int pixels, int dsc_slice_count,1030int bpp_x16, int symbol_size, bool is_mst);10311032#endif /* _DRM_DP_HELPER_H_ */103310341035