118e26a6dSFrançois Tigeot /*
218e26a6dSFrançois Tigeot  * Copyright © 2008 Keith Packard
318e26a6dSFrançois Tigeot  *
418e26a6dSFrançois Tigeot  * Permission to use, copy, modify, distribute, and sell this software and its
518e26a6dSFrançois Tigeot  * documentation for any purpose is hereby granted without fee, provided that
618e26a6dSFrançois Tigeot  * the above copyright notice appear in all copies and that both that copyright
718e26a6dSFrançois Tigeot  * notice and this permission notice appear in supporting documentation, and
818e26a6dSFrançois Tigeot  * that the name of the copyright holders not be used in advertising or
918e26a6dSFrançois Tigeot  * publicity pertaining to distribution of the software without specific,
1018e26a6dSFrançois Tigeot  * written prior permission.  The copyright holders make no representations
1118e26a6dSFrançois Tigeot  * about the suitability of this software for any purpose.  It is provided "as
1218e26a6dSFrançois Tigeot  * is" without express or implied warranty.
1318e26a6dSFrançois Tigeot  *
1418e26a6dSFrançois Tigeot  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1518e26a6dSFrançois Tigeot  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1618e26a6dSFrançois Tigeot  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1718e26a6dSFrançois Tigeot  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1818e26a6dSFrançois Tigeot  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1918e26a6dSFrançois Tigeot  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2018e26a6dSFrançois Tigeot  * OF THIS SOFTWARE.
2118e26a6dSFrançois Tigeot  */
2218e26a6dSFrançois Tigeot 
2318e26a6dSFrançois Tigeot #ifndef _DRM_DP_HELPER_H_
2418e26a6dSFrançois Tigeot #define _DRM_DP_HELPER_H_
2518e26a6dSFrançois Tigeot 
26*19df918dSFrançois Tigeot #include <linux/delay.h>
27*19df918dSFrançois Tigeot 
2818e26a6dSFrançois Tigeot /*
2918e26a6dSFrançois Tigeot  * Unless otherwise noted, all values are from the DP 1.1a spec.  Note that
3018e26a6dSFrançois Tigeot  * DP and DPCD versions are independent.  Differences from 1.0 are not noted,
3118e26a6dSFrançois Tigeot  * 1.0 devices basically don't exist in the wild.
3218e26a6dSFrançois Tigeot  *
3318e26a6dSFrançois Tigeot  * Abbreviations, in chronological order:
3418e26a6dSFrançois Tigeot  *
3518e26a6dSFrançois Tigeot  * eDP: Embedded DisplayPort version 1
3618e26a6dSFrançois Tigeot  * DPI: DisplayPort Interoperability Guideline v1.1a
3718e26a6dSFrançois Tigeot  * 1.2: DisplayPort 1.2
3818e26a6dSFrançois Tigeot  *
3918e26a6dSFrançois Tigeot  * 1.2 formally includes both eDP and DPI definitions.
4018e26a6dSFrançois Tigeot  */
4118e26a6dSFrançois Tigeot 
4218e26a6dSFrançois Tigeot #define AUX_NATIVE_WRITE	0x8
4318e26a6dSFrançois Tigeot #define AUX_NATIVE_READ		0x9
4418e26a6dSFrançois Tigeot #define AUX_I2C_WRITE		0x0
4518e26a6dSFrançois Tigeot #define AUX_I2C_READ		0x1
4618e26a6dSFrançois Tigeot #define AUX_I2C_STATUS		0x2
4718e26a6dSFrançois Tigeot #define AUX_I2C_MOT		0x4
4818e26a6dSFrançois Tigeot 
4918e26a6dSFrançois Tigeot #define AUX_NATIVE_REPLY_ACK	(0x0 << 4)
5018e26a6dSFrançois Tigeot #define AUX_NATIVE_REPLY_NACK	(0x1 << 4)
5118e26a6dSFrançois Tigeot #define AUX_NATIVE_REPLY_DEFER	(0x2 << 4)
5218e26a6dSFrançois Tigeot #define AUX_NATIVE_REPLY_MASK	(0x3 << 4)
5318e26a6dSFrançois Tigeot 
5418e26a6dSFrançois Tigeot #define AUX_I2C_REPLY_ACK	(0x0 << 6)
5518e26a6dSFrançois Tigeot #define AUX_I2C_REPLY_NACK	(0x1 << 6)
5618e26a6dSFrançois Tigeot #define AUX_I2C_REPLY_DEFER	(0x2 << 6)
5718e26a6dSFrançois Tigeot #define AUX_I2C_REPLY_MASK	(0x3 << 6)
5818e26a6dSFrançois Tigeot 
5918e26a6dSFrançois Tigeot /* AUX CH addresses */
6018e26a6dSFrançois Tigeot /* DPCD */
6118e26a6dSFrançois Tigeot #define DP_DPCD_REV                         0x000
6218e26a6dSFrançois Tigeot 
6318e26a6dSFrançois Tigeot #define DP_MAX_LINK_RATE                    0x001
6418e26a6dSFrançois Tigeot 
6518e26a6dSFrançois Tigeot #define DP_MAX_LANE_COUNT                   0x002
6618e26a6dSFrançois Tigeot # define DP_MAX_LANE_COUNT_MASK		    0x1f
6718e26a6dSFrançois Tigeot # define DP_TPS3_SUPPORTED		    (1 << 6) /* 1.2 */
6818e26a6dSFrançois Tigeot # define DP_ENHANCED_FRAME_CAP		    (1 << 7)
6918e26a6dSFrançois Tigeot 
7018e26a6dSFrançois Tigeot #define DP_MAX_DOWNSPREAD                   0x003
7118e26a6dSFrançois Tigeot # define DP_NO_AUX_HANDSHAKE_LINK_TRAINING  (1 << 6)
7218e26a6dSFrançois Tigeot 
7318e26a6dSFrançois Tigeot #define DP_NORP                             0x004
7418e26a6dSFrançois Tigeot 
7518e26a6dSFrançois Tigeot #define DP_DOWNSTREAMPORT_PRESENT           0x005
7618e26a6dSFrançois Tigeot # define DP_DWN_STRM_PORT_PRESENT           (1 << 0)
7718e26a6dSFrançois Tigeot # define DP_DWN_STRM_PORT_TYPE_MASK         0x06
7818e26a6dSFrançois Tigeot /* 00b = DisplayPort */
7918e26a6dSFrançois Tigeot /* 01b = Analog */
8018e26a6dSFrançois Tigeot /* 10b = TMDS or HDMI */
8118e26a6dSFrançois Tigeot /* 11b = Other */
8218e26a6dSFrançois Tigeot # define DP_FORMAT_CONVERSION               (1 << 3)
8318e26a6dSFrançois Tigeot # define DP_DETAILED_CAP_INFO_AVAILABLE	    (1 << 4) /* DPI */
8418e26a6dSFrançois Tigeot 
8518e26a6dSFrançois Tigeot #define DP_MAIN_LINK_CHANNEL_CODING         0x006
8618e26a6dSFrançois Tigeot 
8718e26a6dSFrançois Tigeot #define DP_DOWN_STREAM_PORT_COUNT	    0x007
8818e26a6dSFrançois Tigeot # define DP_PORT_COUNT_MASK		    0x0f
8918e26a6dSFrançois Tigeot # define DP_MSA_TIMING_PAR_IGNORED	    (1 << 6) /* eDP */
9018e26a6dSFrançois Tigeot # define DP_OUI_SUPPORT			    (1 << 7)
9118e26a6dSFrançois Tigeot 
9218e26a6dSFrançois Tigeot #define DP_I2C_SPEED_CAP		    0x00c    /* DPI */
9318e26a6dSFrançois Tigeot # define DP_I2C_SPEED_1K		    0x01
9418e26a6dSFrançois Tigeot # define DP_I2C_SPEED_5K		    0x02
9518e26a6dSFrançois Tigeot # define DP_I2C_SPEED_10K		    0x04
9618e26a6dSFrançois Tigeot # define DP_I2C_SPEED_100K		    0x08
9718e26a6dSFrançois Tigeot # define DP_I2C_SPEED_400K		    0x10
9818e26a6dSFrançois Tigeot # define DP_I2C_SPEED_1M		    0x20
9918e26a6dSFrançois Tigeot 
10018e26a6dSFrançois Tigeot #define DP_EDP_CONFIGURATION_CAP            0x00d   /* XXX 1.2? */
10118e26a6dSFrançois Tigeot #define DP_TRAINING_AUX_RD_INTERVAL         0x00e   /* XXX 1.2? */
10218e26a6dSFrançois Tigeot 
10318e26a6dSFrançois Tigeot /* Multiple stream transport */
10418e26a6dSFrançois Tigeot #define DP_MSTM_CAP			    0x021   /* 1.2 */
10518e26a6dSFrançois Tigeot # define DP_MST_CAP			    (1 << 0)
10618e26a6dSFrançois Tigeot 
10718e26a6dSFrançois Tigeot #define DP_PSR_SUPPORT                      0x070   /* XXX 1.2? */
10818e26a6dSFrançois Tigeot # define DP_PSR_IS_SUPPORTED                1
10918e26a6dSFrançois Tigeot #define DP_PSR_CAPS                         0x071   /* XXX 1.2? */
11018e26a6dSFrançois Tigeot # define DP_PSR_NO_TRAIN_ON_EXIT            1
11118e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_330              (0 << 1)
11218e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_275              (1 << 1)
11318e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_220              (2 << 1)
11418e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_165              (3 << 1)
11518e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_110              (4 << 1)
11618e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_55               (5 << 1)
11718e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_0                (6 << 1)
11818e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_MASK             (7 << 1)
11918e26a6dSFrançois Tigeot # define DP_PSR_SETUP_TIME_SHIFT            1
12018e26a6dSFrançois Tigeot 
12118e26a6dSFrançois Tigeot /*
12218e26a6dSFrançois Tigeot  * 0x80-0x8f describe downstream port capabilities, but there are two layouts
12318e26a6dSFrançois Tigeot  * based on whether DP_DETAILED_CAP_INFO_AVAILABLE was set.  If it was not,
12418e26a6dSFrançois Tigeot  * each port's descriptor is one byte wide.  If it was set, each port's is
12518e26a6dSFrançois Tigeot  * four bytes wide, starting with the one byte from the base info.  As of
12618e26a6dSFrançois Tigeot  * DP interop v1.1a only VGA defines additional detail.
12718e26a6dSFrançois Tigeot  */
12818e26a6dSFrançois Tigeot 
12918e26a6dSFrançois Tigeot /* offset 0 */
13018e26a6dSFrançois Tigeot #define DP_DOWNSTREAM_PORT_0		    0x80
13118e26a6dSFrançois Tigeot # define DP_DS_PORT_TYPE_MASK		    (7 << 0)
13218e26a6dSFrançois Tigeot # define DP_DS_PORT_TYPE_DP		    0
13318e26a6dSFrançois Tigeot # define DP_DS_PORT_TYPE_VGA		    1
13418e26a6dSFrançois Tigeot # define DP_DS_PORT_TYPE_DVI		    2
13518e26a6dSFrançois Tigeot # define DP_DS_PORT_TYPE_HDMI		    3
13618e26a6dSFrançois Tigeot # define DP_DS_PORT_TYPE_NON_EDID	    4
13718e26a6dSFrançois Tigeot # define DP_DS_PORT_HPD			    (1 << 3)
13818e26a6dSFrançois Tigeot /* offset 1 for VGA is maximum megapixels per second / 8 */
13918e26a6dSFrançois Tigeot /* offset 2 */
14018e26a6dSFrançois Tigeot # define DP_DS_VGA_MAX_BPC_MASK		    (3 << 0)
14118e26a6dSFrançois Tigeot # define DP_DS_VGA_8BPC			    0
14218e26a6dSFrançois Tigeot # define DP_DS_VGA_10BPC		    1
14318e26a6dSFrançois Tigeot # define DP_DS_VGA_12BPC		    2
14418e26a6dSFrançois Tigeot # define DP_DS_VGA_16BPC		    3
14518e26a6dSFrançois Tigeot 
14618e26a6dSFrançois Tigeot /* link configuration */
14718e26a6dSFrançois Tigeot #define	DP_LINK_BW_SET		            0x100
14818e26a6dSFrançois Tigeot # define DP_LINK_BW_1_62		    0x06
14918e26a6dSFrançois Tigeot # define DP_LINK_BW_2_7			    0x0a
15018e26a6dSFrançois Tigeot # define DP_LINK_BW_5_4			    0x14    /* 1.2 */
15118e26a6dSFrançois Tigeot 
15218e26a6dSFrançois Tigeot #define DP_LANE_COUNT_SET	            0x101
15318e26a6dSFrançois Tigeot # define DP_LANE_COUNT_MASK		    0x0f
15418e26a6dSFrançois Tigeot # define DP_LANE_COUNT_ENHANCED_FRAME_EN    (1 << 7)
15518e26a6dSFrançois Tigeot 
15618e26a6dSFrançois Tigeot #define DP_TRAINING_PATTERN_SET	            0x102
15718e26a6dSFrançois Tigeot # define DP_TRAINING_PATTERN_DISABLE	    0
15818e26a6dSFrançois Tigeot # define DP_TRAINING_PATTERN_1		    1
15918e26a6dSFrançois Tigeot # define DP_TRAINING_PATTERN_2		    2
16018e26a6dSFrançois Tigeot # define DP_TRAINING_PATTERN_3		    3	    /* 1.2 */
16118e26a6dSFrançois Tigeot # define DP_TRAINING_PATTERN_MASK	    0x3
16218e26a6dSFrançois Tigeot 
16318e26a6dSFrançois Tigeot # define DP_LINK_QUAL_PATTERN_DISABLE	    (0 << 2)
16418e26a6dSFrançois Tigeot # define DP_LINK_QUAL_PATTERN_D10_2	    (1 << 2)
16518e26a6dSFrançois Tigeot # define DP_LINK_QUAL_PATTERN_ERROR_RATE    (2 << 2)
16618e26a6dSFrançois Tigeot # define DP_LINK_QUAL_PATTERN_PRBS7	    (3 << 2)
16718e26a6dSFrançois Tigeot # define DP_LINK_QUAL_PATTERN_MASK	    (3 << 2)
16818e26a6dSFrançois Tigeot 
16918e26a6dSFrançois Tigeot # define DP_RECOVERED_CLOCK_OUT_EN	    (1 << 4)
17018e26a6dSFrançois Tigeot # define DP_LINK_SCRAMBLING_DISABLE	    (1 << 5)
17118e26a6dSFrançois Tigeot 
17218e26a6dSFrançois Tigeot # define DP_SYMBOL_ERROR_COUNT_BOTH	    (0 << 6)
17318e26a6dSFrançois Tigeot # define DP_SYMBOL_ERROR_COUNT_DISPARITY    (1 << 6)
17418e26a6dSFrançois Tigeot # define DP_SYMBOL_ERROR_COUNT_SYMBOL	    (2 << 6)
17518e26a6dSFrançois Tigeot # define DP_SYMBOL_ERROR_COUNT_MASK	    (3 << 6)
17618e26a6dSFrançois Tigeot 
17718e26a6dSFrançois Tigeot #define DP_TRAINING_LANE0_SET		    0x103
17818e26a6dSFrançois Tigeot #define DP_TRAINING_LANE1_SET		    0x104
17918e26a6dSFrançois Tigeot #define DP_TRAINING_LANE2_SET		    0x105
18018e26a6dSFrançois Tigeot #define DP_TRAINING_LANE3_SET		    0x106
18118e26a6dSFrançois Tigeot 
18218e26a6dSFrançois Tigeot # define DP_TRAIN_VOLTAGE_SWING_MASK	    0x3
18318e26a6dSFrançois Tigeot # define DP_TRAIN_VOLTAGE_SWING_SHIFT	    0
18418e26a6dSFrançois Tigeot # define DP_TRAIN_MAX_SWING_REACHED	    (1 << 2)
18518e26a6dSFrançois Tigeot # define DP_TRAIN_VOLTAGE_SWING_400	    (0 << 0)
18618e26a6dSFrançois Tigeot # define DP_TRAIN_VOLTAGE_SWING_600	    (1 << 0)
18718e26a6dSFrançois Tigeot # define DP_TRAIN_VOLTAGE_SWING_800	    (2 << 0)
18818e26a6dSFrançois Tigeot # define DP_TRAIN_VOLTAGE_SWING_1200	    (3 << 0)
18918e26a6dSFrançois Tigeot 
19018e26a6dSFrançois Tigeot # define DP_TRAIN_PRE_EMPHASIS_MASK	    (3 << 3)
19118e26a6dSFrançois Tigeot # define DP_TRAIN_PRE_EMPHASIS_0	    (0 << 3)
19218e26a6dSFrançois Tigeot # define DP_TRAIN_PRE_EMPHASIS_3_5	    (1 << 3)
19318e26a6dSFrançois Tigeot # define DP_TRAIN_PRE_EMPHASIS_6	    (2 << 3)
19418e26a6dSFrançois Tigeot # define DP_TRAIN_PRE_EMPHASIS_9_5	    (3 << 3)
19518e26a6dSFrançois Tigeot 
19618e26a6dSFrançois Tigeot # define DP_TRAIN_PRE_EMPHASIS_SHIFT	    3
19718e26a6dSFrançois Tigeot # define DP_TRAIN_MAX_PRE_EMPHASIS_REACHED  (1 << 5)
19818e26a6dSFrançois Tigeot 
19918e26a6dSFrançois Tigeot #define DP_DOWNSPREAD_CTRL		    0x107
20018e26a6dSFrançois Tigeot # define DP_SPREAD_AMP_0_5		    (1 << 4)
20118e26a6dSFrançois Tigeot # define DP_MSA_TIMING_PAR_IGNORE_EN	    (1 << 7) /* eDP */
20218e26a6dSFrançois Tigeot 
20318e26a6dSFrançois Tigeot #define DP_MAIN_LINK_CHANNEL_CODING_SET	    0x108
20418e26a6dSFrançois Tigeot # define DP_SET_ANSI_8B10B		    (1 << 0)
20518e26a6dSFrançois Tigeot 
20618e26a6dSFrançois Tigeot #define DP_I2C_SPEED_CONTROL_STATUS	    0x109   /* DPI */
20718e26a6dSFrançois Tigeot /* bitmask as for DP_I2C_SPEED_CAP */
20818e26a6dSFrançois Tigeot 
20918e26a6dSFrançois Tigeot #define DP_EDP_CONFIGURATION_SET            0x10a   /* XXX 1.2? */
21018e26a6dSFrançois Tigeot 
21118e26a6dSFrançois Tigeot #define DP_MSTM_CTRL			    0x111   /* 1.2 */
21218e26a6dSFrançois Tigeot # define DP_MST_EN			    (1 << 0)
21318e26a6dSFrançois Tigeot # define DP_UP_REQ_EN			    (1 << 1)
21418e26a6dSFrançois Tigeot # define DP_UPSTREAM_IS_SRC		    (1 << 2)
21518e26a6dSFrançois Tigeot 
21618e26a6dSFrançois Tigeot #define DP_PSR_EN_CFG			    0x170   /* XXX 1.2? */
21718e26a6dSFrançois Tigeot # define DP_PSR_ENABLE			    (1 << 0)
21818e26a6dSFrançois Tigeot # define DP_PSR_MAIN_LINK_ACTIVE	    (1 << 1)
21918e26a6dSFrançois Tigeot # define DP_PSR_CRC_VERIFICATION	    (1 << 2)
22018e26a6dSFrançois Tigeot # define DP_PSR_FRAME_CAPTURE		    (1 << 3)
22118e26a6dSFrançois Tigeot 
22218e26a6dSFrançois Tigeot #define DP_SINK_COUNT			    0x200
22318e26a6dSFrançois Tigeot /* prior to 1.2 bit 7 was reserved mbz */
22418e26a6dSFrançois Tigeot # define DP_GET_SINK_COUNT(x)		    ((((x) & 0x80) >> 1) | ((x) & 0x3f))
22518e26a6dSFrançois Tigeot # define DP_SINK_CP_READY		    (1 << 6)
22618e26a6dSFrançois Tigeot 
22718e26a6dSFrançois Tigeot #define DP_DEVICE_SERVICE_IRQ_VECTOR	    0x201
22818e26a6dSFrançois Tigeot # define DP_REMOTE_CONTROL_COMMAND_PENDING  (1 << 0)
22918e26a6dSFrançois Tigeot # define DP_AUTOMATED_TEST_REQUEST	    (1 << 1)
23018e26a6dSFrançois Tigeot # define DP_CP_IRQ			    (1 << 2)
23118e26a6dSFrançois Tigeot # define DP_SINK_SPECIFIC_IRQ		    (1 << 6)
23218e26a6dSFrançois Tigeot 
23318e26a6dSFrançois Tigeot #define DP_LANE0_1_STATUS		    0x202
23418e26a6dSFrançois Tigeot #define DP_LANE2_3_STATUS		    0x203
23518e26a6dSFrançois Tigeot # define DP_LANE_CR_DONE		    (1 << 0)
23618e26a6dSFrançois Tigeot # define DP_LANE_CHANNEL_EQ_DONE	    (1 << 1)
23718e26a6dSFrançois Tigeot # define DP_LANE_SYMBOL_LOCKED		    (1 << 2)
23818e26a6dSFrançois Tigeot 
23918e26a6dSFrançois Tigeot #define DP_CHANNEL_EQ_BITS (DP_LANE_CR_DONE |		\
24018e26a6dSFrançois Tigeot 			    DP_LANE_CHANNEL_EQ_DONE |	\
24118e26a6dSFrançois Tigeot 			    DP_LANE_SYMBOL_LOCKED)
24218e26a6dSFrançois Tigeot 
24318e26a6dSFrançois Tigeot #define DP_LANE_ALIGN_STATUS_UPDATED	    0x204
24418e26a6dSFrançois Tigeot 
24518e26a6dSFrançois Tigeot #define DP_INTERLANE_ALIGN_DONE		    (1 << 0)
24618e26a6dSFrançois Tigeot #define DP_DOWNSTREAM_PORT_STATUS_CHANGED   (1 << 6)
24718e26a6dSFrançois Tigeot #define DP_LINK_STATUS_UPDATED		    (1 << 7)
24818e26a6dSFrançois Tigeot 
24918e26a6dSFrançois Tigeot #define DP_SINK_STATUS			    0x205
25018e26a6dSFrançois Tigeot 
25118e26a6dSFrançois Tigeot #define DP_RECEIVE_PORT_0_STATUS	    (1 << 0)
25218e26a6dSFrançois Tigeot #define DP_RECEIVE_PORT_1_STATUS	    (1 << 1)
25318e26a6dSFrançois Tigeot 
25418e26a6dSFrançois Tigeot #define DP_ADJUST_REQUEST_LANE0_1	    0x206
25518e26a6dSFrançois Tigeot #define DP_ADJUST_REQUEST_LANE2_3	    0x207
25618e26a6dSFrançois Tigeot # define DP_ADJUST_VOLTAGE_SWING_LANE0_MASK  0x03
25718e26a6dSFrançois Tigeot # define DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT 0
25818e26a6dSFrançois Tigeot # define DP_ADJUST_PRE_EMPHASIS_LANE0_MASK   0x0c
25918e26a6dSFrançois Tigeot # define DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT  2
26018e26a6dSFrançois Tigeot # define DP_ADJUST_VOLTAGE_SWING_LANE1_MASK  0x30
26118e26a6dSFrançois Tigeot # define DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT 4
26218e26a6dSFrançois Tigeot # define DP_ADJUST_PRE_EMPHASIS_LANE1_MASK   0xc0
26318e26a6dSFrançois Tigeot # define DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT  6
26418e26a6dSFrançois Tigeot 
26518e26a6dSFrançois Tigeot #define DP_TEST_REQUEST			    0x218
26618e26a6dSFrançois Tigeot # define DP_TEST_LINK_TRAINING		    (1 << 0)
26718e26a6dSFrançois Tigeot # define DP_TEST_LINK_PATTERN		    (1 << 1)
26818e26a6dSFrançois Tigeot # define DP_TEST_LINK_EDID_READ		    (1 << 2)
26918e26a6dSFrançois Tigeot # define DP_TEST_LINK_PHY_TEST_PATTERN	    (1 << 3) /* DPCD >= 1.1 */
27018e26a6dSFrançois Tigeot 
27118e26a6dSFrançois Tigeot #define DP_TEST_LINK_RATE		    0x219
27218e26a6dSFrançois Tigeot # define DP_LINK_RATE_162		    (0x6)
27318e26a6dSFrançois Tigeot # define DP_LINK_RATE_27		    (0xa)
27418e26a6dSFrançois Tigeot 
27518e26a6dSFrançois Tigeot #define DP_TEST_LANE_COUNT		    0x220
27618e26a6dSFrançois Tigeot 
27718e26a6dSFrançois Tigeot #define DP_TEST_PATTERN			    0x221
27818e26a6dSFrançois Tigeot 
27918e26a6dSFrançois Tigeot #define DP_TEST_RESPONSE		    0x260
28018e26a6dSFrançois Tigeot # define DP_TEST_ACK			    (1 << 0)
28118e26a6dSFrançois Tigeot # define DP_TEST_NAK			    (1 << 1)
28218e26a6dSFrançois Tigeot # define DP_TEST_EDID_CHECKSUM_WRITE	    (1 << 2)
28318e26a6dSFrançois Tigeot 
28418e26a6dSFrançois Tigeot #define DP_SOURCE_OUI			    0x300
28518e26a6dSFrançois Tigeot #define DP_SINK_OUI			    0x400
28618e26a6dSFrançois Tigeot #define DP_BRANCH_OUI			    0x500
28718e26a6dSFrançois Tigeot 
28818e26a6dSFrançois Tigeot #define DP_SET_POWER                        0x600
28918e26a6dSFrançois Tigeot # define DP_SET_POWER_D0                    0x1
29018e26a6dSFrançois Tigeot # define DP_SET_POWER_D3                    0x2
29118e26a6dSFrançois Tigeot 
29218e26a6dSFrançois Tigeot #define DP_PSR_ERROR_STATUS                 0x2006  /* XXX 1.2? */
29318e26a6dSFrançois Tigeot # define DP_PSR_LINK_CRC_ERROR              (1 << 0)
29418e26a6dSFrançois Tigeot # define DP_PSR_RFB_STORAGE_ERROR           (1 << 1)
29518e26a6dSFrançois Tigeot 
29618e26a6dSFrançois Tigeot #define DP_PSR_ESI                          0x2007  /* XXX 1.2? */
29718e26a6dSFrançois Tigeot # define DP_PSR_CAPS_CHANGE                 (1 << 0)
29818e26a6dSFrançois Tigeot 
29918e26a6dSFrançois Tigeot #define DP_PSR_STATUS                       0x2008  /* XXX 1.2? */
30018e26a6dSFrançois Tigeot # define DP_PSR_SINK_INACTIVE               0
30118e26a6dSFrançois Tigeot # define DP_PSR_SINK_ACTIVE_SRC_SYNCED      1
30218e26a6dSFrançois Tigeot # define DP_PSR_SINK_ACTIVE_RFB             2
30318e26a6dSFrançois Tigeot # define DP_PSR_SINK_ACTIVE_SINK_SYNCED     3
30418e26a6dSFrançois Tigeot # define DP_PSR_SINK_ACTIVE_RESYNC          4
30518e26a6dSFrançois Tigeot # define DP_PSR_SINK_INTERNAL_ERROR         7
30618e26a6dSFrançois Tigeot # define DP_PSR_SINK_STATE_MASK             0x07
30718e26a6dSFrançois Tigeot 
30818e26a6dSFrançois Tigeot #define MODE_I2C_START	1
30918e26a6dSFrançois Tigeot #define MODE_I2C_WRITE	2
31018e26a6dSFrançois Tigeot #define MODE_I2C_READ	4
31118e26a6dSFrançois Tigeot #define MODE_I2C_STOP	8
31218e26a6dSFrançois Tigeot 
313ea132f0fSFrançois Tigeot /**
314ea132f0fSFrançois Tigeot  * struct i2c_algo_dp_aux_data - driver interface structure for i2c over dp
315ea132f0fSFrançois Tigeot  * 				 aux algorithm
316ea132f0fSFrançois Tigeot  * @running: set by the algo indicating whether an i2c is ongoing or whether
317ea132f0fSFrançois Tigeot  * 	     the i2c bus is quiescent
318ea132f0fSFrançois Tigeot  * @address: i2c target address for the currently ongoing transfer
319ea132f0fSFrançois Tigeot  * @aux_ch: driver callback to transfer a single byte of the i2c payload
320ea132f0fSFrançois Tigeot  */
32118e26a6dSFrançois Tigeot struct iic_dp_aux_data {
32218e26a6dSFrançois Tigeot 	bool running;
32318e26a6dSFrançois Tigeot 	u16 address;
32418e26a6dSFrançois Tigeot 	void *priv;
32518e26a6dSFrançois Tigeot 	int (*aux_ch)(device_t adapter, int mode, uint8_t write_byte,
32618e26a6dSFrançois Tigeot 	    uint8_t *read_byte);
32718e26a6dSFrançois Tigeot 	device_t port;
32818e26a6dSFrançois Tigeot };
32918e26a6dSFrançois Tigeot 
33018e26a6dSFrançois Tigeot int iic_dp_aux_add_bus(device_t dev, const char *name,
33118e26a6dSFrançois Tigeot     int (*ch)(device_t idev, int mode, uint8_t write_byte, uint8_t *read_byte),
33218e26a6dSFrançois Tigeot     void *priv, device_t *bus, device_t *adapter);
33318e26a6dSFrançois Tigeot 
33418e26a6dSFrançois Tigeot 
33518e26a6dSFrançois Tigeot #define DP_LINK_STATUS_SIZE	   6
33618e26a6dSFrançois Tigeot bool drm_dp_channel_eq_ok(u8 link_status[DP_LINK_STATUS_SIZE],
33718e26a6dSFrançois Tigeot 			  int lane_count);
33818e26a6dSFrançois Tigeot bool drm_dp_clock_recovery_ok(u8 link_status[DP_LINK_STATUS_SIZE],
33918e26a6dSFrançois Tigeot 			      int lane_count);
34018e26a6dSFrançois Tigeot u8 drm_dp_get_adjust_request_voltage(u8 link_status[DP_LINK_STATUS_SIZE],
34118e26a6dSFrançois Tigeot 				     int lane);
34218e26a6dSFrançois Tigeot u8 drm_dp_get_adjust_request_pre_emphasis(u8 link_status[DP_LINK_STATUS_SIZE],
34318e26a6dSFrançois Tigeot 					  int lane);
34418e26a6dSFrançois Tigeot 
34518e26a6dSFrançois Tigeot #define DP_RECEIVER_CAP_SIZE	0xf
34618e26a6dSFrançois Tigeot void drm_dp_link_train_clock_recovery_delay(u8 dpcd[DP_RECEIVER_CAP_SIZE]);
34718e26a6dSFrançois Tigeot void drm_dp_link_train_channel_eq_delay(u8 dpcd[DP_RECEIVER_CAP_SIZE]);
34818e26a6dSFrançois Tigeot 
34918e26a6dSFrançois Tigeot u8 drm_dp_link_rate_to_bw_code(int link_rate);
35018e26a6dSFrançois Tigeot int drm_dp_bw_code_to_link_rate(u8 link_bw);
35118e26a6dSFrançois Tigeot 
35218e26a6dSFrançois Tigeot static inline int
35318e26a6dSFrançois Tigeot drm_dp_max_link_rate(u8 dpcd[DP_RECEIVER_CAP_SIZE])
35418e26a6dSFrançois Tigeot {
35518e26a6dSFrançois Tigeot 	return drm_dp_bw_code_to_link_rate(dpcd[DP_MAX_LINK_RATE]);
35618e26a6dSFrançois Tigeot }
35718e26a6dSFrançois Tigeot 
35818e26a6dSFrançois Tigeot static inline u8
35918e26a6dSFrançois Tigeot drm_dp_max_lane_count(u8 dpcd[DP_RECEIVER_CAP_SIZE])
36018e26a6dSFrançois Tigeot {
36118e26a6dSFrançois Tigeot 	return dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
36218e26a6dSFrançois Tigeot }
36318e26a6dSFrançois Tigeot 
36418e26a6dSFrançois Tigeot #endif /* _DRM_DP_HELPER_H_ */
365