1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev * Copyright 2012-15 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev *
4*b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev *
11*b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev *
14*b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev *
22*b843c749SSergey Zigachev * Authors: AMD
23*b843c749SSergey Zigachev *
24*b843c749SSergey Zigachev */
25*b843c749SSergey Zigachev
26*b843c749SSergey Zigachev #include "reg_helper.h"
27*b843c749SSergey Zigachev
28*b843c749SSergey Zigachev #include "core_types.h"
29*b843c749SSergey Zigachev #include "link_encoder.h"
30*b843c749SSergey Zigachev #include "dcn10_link_encoder.h"
31*b843c749SSergey Zigachev #include "stream_encoder.h"
32*b843c749SSergey Zigachev #include "i2caux_interface.h"
33*b843c749SSergey Zigachev #include "dc_bios_types.h"
34*b843c749SSergey Zigachev
35*b843c749SSergey Zigachev #include "gpio_service_interface.h"
36*b843c749SSergey Zigachev
37*b843c749SSergey Zigachev #define CTX \
38*b843c749SSergey Zigachev enc10->base.ctx
39*b843c749SSergey Zigachev #define DC_LOGGER \
40*b843c749SSergey Zigachev enc10->base.ctx->logger
41*b843c749SSergey Zigachev
42*b843c749SSergey Zigachev #define REG(reg)\
43*b843c749SSergey Zigachev (enc10->link_regs->reg)
44*b843c749SSergey Zigachev
45*b843c749SSergey Zigachev #undef FN
46*b843c749SSergey Zigachev #define FN(reg_name, field_name) \
47*b843c749SSergey Zigachev enc10->link_shift->field_name, enc10->link_mask->field_name
48*b843c749SSergey Zigachev
49*b843c749SSergey Zigachev
50*b843c749SSergey Zigachev /*
51*b843c749SSergey Zigachev * @brief
52*b843c749SSergey Zigachev * Trigger Source Select
53*b843c749SSergey Zigachev * ASIC-dependent, actual values for register programming
54*b843c749SSergey Zigachev */
55*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_INVALID 0x0
56*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_DIGA 0x1
57*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_DIGB 0x2
58*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_DIGC 0x4
59*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_DIGD 0x08
60*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_DIGE 0x10
61*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_DIGF 0x20
62*b843c749SSergey Zigachev #define DCN10_DIG_FE_SOURCE_SELECT_DIGG 0x40
63*b843c749SSergey Zigachev
64*b843c749SSergey Zigachev enum {
65*b843c749SSergey Zigachev DP_MST_UPDATE_MAX_RETRY = 50
66*b843c749SSergey Zigachev };
67*b843c749SSergey Zigachev
68*b843c749SSergey Zigachev static const struct link_encoder_funcs dcn10_lnk_enc_funcs = {
69*b843c749SSergey Zigachev .validate_output_with_stream =
70*b843c749SSergey Zigachev dcn10_link_encoder_validate_output_with_stream,
71*b843c749SSergey Zigachev .hw_init = dcn10_link_encoder_hw_init,
72*b843c749SSergey Zigachev .setup = dcn10_link_encoder_setup,
73*b843c749SSergey Zigachev .enable_tmds_output = dcn10_link_encoder_enable_tmds_output,
74*b843c749SSergey Zigachev .enable_dp_output = dcn10_link_encoder_enable_dp_output,
75*b843c749SSergey Zigachev .enable_dp_mst_output = dcn10_link_encoder_enable_dp_mst_output,
76*b843c749SSergey Zigachev .disable_output = dcn10_link_encoder_disable_output,
77*b843c749SSergey Zigachev .dp_set_lane_settings = dcn10_link_encoder_dp_set_lane_settings,
78*b843c749SSergey Zigachev .dp_set_phy_pattern = dcn10_link_encoder_dp_set_phy_pattern,
79*b843c749SSergey Zigachev .update_mst_stream_allocation_table =
80*b843c749SSergey Zigachev dcn10_link_encoder_update_mst_stream_allocation_table,
81*b843c749SSergey Zigachev .psr_program_dp_dphy_fast_training =
82*b843c749SSergey Zigachev dcn10_psr_program_dp_dphy_fast_training,
83*b843c749SSergey Zigachev .psr_program_secondary_packet = dcn10_psr_program_secondary_packet,
84*b843c749SSergey Zigachev .connect_dig_be_to_fe = dcn10_link_encoder_connect_dig_be_to_fe,
85*b843c749SSergey Zigachev .enable_hpd = dcn10_link_encoder_enable_hpd,
86*b843c749SSergey Zigachev .disable_hpd = dcn10_link_encoder_disable_hpd,
87*b843c749SSergey Zigachev .is_dig_enabled = dcn10_is_dig_enabled,
88*b843c749SSergey Zigachev .destroy = dcn10_link_encoder_destroy
89*b843c749SSergey Zigachev };
90*b843c749SSergey Zigachev
link_transmitter_control(struct dcn10_link_encoder * enc10,struct bp_transmitter_control * cntl)91*b843c749SSergey Zigachev static enum bp_result link_transmitter_control(
92*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
93*b843c749SSergey Zigachev struct bp_transmitter_control *cntl)
94*b843c749SSergey Zigachev {
95*b843c749SSergey Zigachev enum bp_result result;
96*b843c749SSergey Zigachev struct dc_bios *bp = enc10->base.ctx->dc_bios;
97*b843c749SSergey Zigachev
98*b843c749SSergey Zigachev result = bp->funcs->transmitter_control(bp, cntl);
99*b843c749SSergey Zigachev
100*b843c749SSergey Zigachev return result;
101*b843c749SSergey Zigachev }
102*b843c749SSergey Zigachev
enable_phy_bypass_mode(struct dcn10_link_encoder * enc10,bool enable)103*b843c749SSergey Zigachev static void enable_phy_bypass_mode(
104*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
105*b843c749SSergey Zigachev bool enable)
106*b843c749SSergey Zigachev {
107*b843c749SSergey Zigachev /* This register resides in DP back end block;
108*b843c749SSergey Zigachev * transmitter is used for the offset
109*b843c749SSergey Zigachev */
110*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_CNTL, DPHY_BYPASS, enable);
111*b843c749SSergey Zigachev
112*b843c749SSergey Zigachev }
113*b843c749SSergey Zigachev
disable_prbs_symbols(struct dcn10_link_encoder * enc10,bool disable)114*b843c749SSergey Zigachev static void disable_prbs_symbols(
115*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
116*b843c749SSergey Zigachev bool disable)
117*b843c749SSergey Zigachev {
118*b843c749SSergey Zigachev /* This register resides in DP back end block;
119*b843c749SSergey Zigachev * transmitter is used for the offset
120*b843c749SSergey Zigachev */
121*b843c749SSergey Zigachev REG_UPDATE_4(DP_DPHY_CNTL,
122*b843c749SSergey Zigachev DPHY_ATEST_SEL_LANE0, disable,
123*b843c749SSergey Zigachev DPHY_ATEST_SEL_LANE1, disable,
124*b843c749SSergey Zigachev DPHY_ATEST_SEL_LANE2, disable,
125*b843c749SSergey Zigachev DPHY_ATEST_SEL_LANE3, disable);
126*b843c749SSergey Zigachev }
127*b843c749SSergey Zigachev
disable_prbs_mode(struct dcn10_link_encoder * enc10)128*b843c749SSergey Zigachev static void disable_prbs_mode(
129*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10)
130*b843c749SSergey Zigachev {
131*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_PRBS_CNTL, DPHY_PRBS_EN, 0);
132*b843c749SSergey Zigachev }
133*b843c749SSergey Zigachev
program_pattern_symbols(struct dcn10_link_encoder * enc10,uint16_t pattern_symbols[8])134*b843c749SSergey Zigachev static void program_pattern_symbols(
135*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
136*b843c749SSergey Zigachev uint16_t pattern_symbols[8])
137*b843c749SSergey Zigachev {
138*b843c749SSergey Zigachev /* This register resides in DP back end block;
139*b843c749SSergey Zigachev * transmitter is used for the offset
140*b843c749SSergey Zigachev */
141*b843c749SSergey Zigachev REG_SET_3(DP_DPHY_SYM0, 0,
142*b843c749SSergey Zigachev DPHY_SYM1, pattern_symbols[0],
143*b843c749SSergey Zigachev DPHY_SYM2, pattern_symbols[1],
144*b843c749SSergey Zigachev DPHY_SYM3, pattern_symbols[2]);
145*b843c749SSergey Zigachev
146*b843c749SSergey Zigachev /* This register resides in DP back end block;
147*b843c749SSergey Zigachev * transmitter is used for the offset
148*b843c749SSergey Zigachev */
149*b843c749SSergey Zigachev REG_SET_3(DP_DPHY_SYM1, 0,
150*b843c749SSergey Zigachev DPHY_SYM4, pattern_symbols[3],
151*b843c749SSergey Zigachev DPHY_SYM5, pattern_symbols[4],
152*b843c749SSergey Zigachev DPHY_SYM6, pattern_symbols[5]);
153*b843c749SSergey Zigachev
154*b843c749SSergey Zigachev /* This register resides in DP back end block;
155*b843c749SSergey Zigachev * transmitter is used for the offset
156*b843c749SSergey Zigachev */
157*b843c749SSergey Zigachev REG_SET_2(DP_DPHY_SYM2, 0,
158*b843c749SSergey Zigachev DPHY_SYM7, pattern_symbols[6],
159*b843c749SSergey Zigachev DPHY_SYM8, pattern_symbols[7]);
160*b843c749SSergey Zigachev }
161*b843c749SSergey Zigachev
set_dp_phy_pattern_d102(struct dcn10_link_encoder * enc10)162*b843c749SSergey Zigachev static void set_dp_phy_pattern_d102(
163*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10)
164*b843c749SSergey Zigachev {
165*b843c749SSergey Zigachev /* Disable PHY Bypass mode to setup the test pattern */
166*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
167*b843c749SSergey Zigachev
168*b843c749SSergey Zigachev /* For 10-bit PRBS or debug symbols
169*b843c749SSergey Zigachev * please use the following sequence:
170*b843c749SSergey Zigachev *
171*b843c749SSergey Zigachev * Enable debug symbols on the lanes
172*b843c749SSergey Zigachev */
173*b843c749SSergey Zigachev disable_prbs_symbols(enc10, true);
174*b843c749SSergey Zigachev
175*b843c749SSergey Zigachev /* Disable PRBS mode */
176*b843c749SSergey Zigachev disable_prbs_mode(enc10);
177*b843c749SSergey Zigachev
178*b843c749SSergey Zigachev /* Program debug symbols to be output */
179*b843c749SSergey Zigachev {
180*b843c749SSergey Zigachev uint16_t pattern_symbols[8] = {
181*b843c749SSergey Zigachev 0x2AA, 0x2AA, 0x2AA, 0x2AA,
182*b843c749SSergey Zigachev 0x2AA, 0x2AA, 0x2AA, 0x2AA
183*b843c749SSergey Zigachev };
184*b843c749SSergey Zigachev
185*b843c749SSergey Zigachev program_pattern_symbols(enc10, pattern_symbols);
186*b843c749SSergey Zigachev }
187*b843c749SSergey Zigachev
188*b843c749SSergey Zigachev /* Enable phy bypass mode to enable the test pattern */
189*b843c749SSergey Zigachev
190*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, true);
191*b843c749SSergey Zigachev }
192*b843c749SSergey Zigachev
set_link_training_complete(struct dcn10_link_encoder * enc10,bool complete)193*b843c749SSergey Zigachev static void set_link_training_complete(
194*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
195*b843c749SSergey Zigachev bool complete)
196*b843c749SSergey Zigachev {
197*b843c749SSergey Zigachev /* This register resides in DP back end block;
198*b843c749SSergey Zigachev * transmitter is used for the offset
199*b843c749SSergey Zigachev */
200*b843c749SSergey Zigachev REG_UPDATE(DP_LINK_CNTL, DP_LINK_TRAINING_COMPLETE, complete);
201*b843c749SSergey Zigachev
202*b843c749SSergey Zigachev }
203*b843c749SSergey Zigachev
dcn10_link_encoder_set_dp_phy_pattern_training_pattern(struct link_encoder * enc,uint32_t index)204*b843c749SSergey Zigachev void dcn10_link_encoder_set_dp_phy_pattern_training_pattern(
205*b843c749SSergey Zigachev struct link_encoder *enc,
206*b843c749SSergey Zigachev uint32_t index)
207*b843c749SSergey Zigachev {
208*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
209*b843c749SSergey Zigachev /* Write Training Pattern */
210*b843c749SSergey Zigachev
211*b843c749SSergey Zigachev REG_WRITE(DP_DPHY_TRAINING_PATTERN_SEL, index);
212*b843c749SSergey Zigachev
213*b843c749SSergey Zigachev /* Set HW Register Training Complete to false */
214*b843c749SSergey Zigachev
215*b843c749SSergey Zigachev set_link_training_complete(enc10, false);
216*b843c749SSergey Zigachev
217*b843c749SSergey Zigachev /* Disable PHY Bypass mode to output Training Pattern */
218*b843c749SSergey Zigachev
219*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
220*b843c749SSergey Zigachev
221*b843c749SSergey Zigachev /* Disable PRBS mode */
222*b843c749SSergey Zigachev disable_prbs_mode(enc10);
223*b843c749SSergey Zigachev }
224*b843c749SSergey Zigachev
setup_panel_mode(struct dcn10_link_encoder * enc10,enum dp_panel_mode panel_mode)225*b843c749SSergey Zigachev static void setup_panel_mode(
226*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
227*b843c749SSergey Zigachev enum dp_panel_mode panel_mode)
228*b843c749SSergey Zigachev {
229*b843c749SSergey Zigachev uint32_t value;
230*b843c749SSergey Zigachev
231*b843c749SSergey Zigachev ASSERT(REG(DP_DPHY_INTERNAL_CTRL));
232*b843c749SSergey Zigachev value = REG_READ(DP_DPHY_INTERNAL_CTRL);
233*b843c749SSergey Zigachev
234*b843c749SSergey Zigachev switch (panel_mode) {
235*b843c749SSergey Zigachev case DP_PANEL_MODE_EDP:
236*b843c749SSergey Zigachev value = 0x1;
237*b843c749SSergey Zigachev break;
238*b843c749SSergey Zigachev case DP_PANEL_MODE_SPECIAL:
239*b843c749SSergey Zigachev value = 0x11;
240*b843c749SSergey Zigachev break;
241*b843c749SSergey Zigachev default:
242*b843c749SSergey Zigachev value = 0x0;
243*b843c749SSergey Zigachev break;
244*b843c749SSergey Zigachev }
245*b843c749SSergey Zigachev
246*b843c749SSergey Zigachev REG_WRITE(DP_DPHY_INTERNAL_CTRL, value);
247*b843c749SSergey Zigachev }
248*b843c749SSergey Zigachev
set_dp_phy_pattern_symbol_error(struct dcn10_link_encoder * enc10)249*b843c749SSergey Zigachev static void set_dp_phy_pattern_symbol_error(
250*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10)
251*b843c749SSergey Zigachev {
252*b843c749SSergey Zigachev /* Disable PHY Bypass mode to setup the test pattern */
253*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
254*b843c749SSergey Zigachev
255*b843c749SSergey Zigachev /* program correct panel mode*/
256*b843c749SSergey Zigachev setup_panel_mode(enc10, DP_PANEL_MODE_DEFAULT);
257*b843c749SSergey Zigachev
258*b843c749SSergey Zigachev /* A PRBS23 pattern is used for most DP electrical measurements. */
259*b843c749SSergey Zigachev
260*b843c749SSergey Zigachev /* Enable PRBS symbols on the lanes */
261*b843c749SSergey Zigachev disable_prbs_symbols(enc10, false);
262*b843c749SSergey Zigachev
263*b843c749SSergey Zigachev /* For PRBS23 Set bit DPHY_PRBS_SEL=1 and Set bit DPHY_PRBS_EN=1 */
264*b843c749SSergey Zigachev REG_UPDATE_2(DP_DPHY_PRBS_CNTL,
265*b843c749SSergey Zigachev DPHY_PRBS_SEL, 1,
266*b843c749SSergey Zigachev DPHY_PRBS_EN, 1);
267*b843c749SSergey Zigachev
268*b843c749SSergey Zigachev /* Enable phy bypass mode to enable the test pattern */
269*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, true);
270*b843c749SSergey Zigachev }
271*b843c749SSergey Zigachev
set_dp_phy_pattern_prbs7(struct dcn10_link_encoder * enc10)272*b843c749SSergey Zigachev static void set_dp_phy_pattern_prbs7(
273*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10)
274*b843c749SSergey Zigachev {
275*b843c749SSergey Zigachev /* Disable PHY Bypass mode to setup the test pattern */
276*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
277*b843c749SSergey Zigachev
278*b843c749SSergey Zigachev /* A PRBS7 pattern is used for most DP electrical measurements. */
279*b843c749SSergey Zigachev
280*b843c749SSergey Zigachev /* Enable PRBS symbols on the lanes */
281*b843c749SSergey Zigachev disable_prbs_symbols(enc10, false);
282*b843c749SSergey Zigachev
283*b843c749SSergey Zigachev /* For PRBS7 Set bit DPHY_PRBS_SEL=0 and Set bit DPHY_PRBS_EN=1 */
284*b843c749SSergey Zigachev REG_UPDATE_2(DP_DPHY_PRBS_CNTL,
285*b843c749SSergey Zigachev DPHY_PRBS_SEL, 0,
286*b843c749SSergey Zigachev DPHY_PRBS_EN, 1);
287*b843c749SSergey Zigachev
288*b843c749SSergey Zigachev /* Enable phy bypass mode to enable the test pattern */
289*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, true);
290*b843c749SSergey Zigachev }
291*b843c749SSergey Zigachev
set_dp_phy_pattern_80bit_custom(struct dcn10_link_encoder * enc10,const uint8_t * pattern)292*b843c749SSergey Zigachev static void set_dp_phy_pattern_80bit_custom(
293*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
294*b843c749SSergey Zigachev const uint8_t *pattern)
295*b843c749SSergey Zigachev {
296*b843c749SSergey Zigachev /* Disable PHY Bypass mode to setup the test pattern */
297*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
298*b843c749SSergey Zigachev
299*b843c749SSergey Zigachev /* Enable debug symbols on the lanes */
300*b843c749SSergey Zigachev
301*b843c749SSergey Zigachev disable_prbs_symbols(enc10, true);
302*b843c749SSergey Zigachev
303*b843c749SSergey Zigachev /* Enable PHY bypass mode to enable the test pattern */
304*b843c749SSergey Zigachev /* TODO is it really needed ? */
305*b843c749SSergey Zigachev
306*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, true);
307*b843c749SSergey Zigachev
308*b843c749SSergey Zigachev /* Program 80 bit custom pattern */
309*b843c749SSergey Zigachev {
310*b843c749SSergey Zigachev uint16_t pattern_symbols[8];
311*b843c749SSergey Zigachev
312*b843c749SSergey Zigachev pattern_symbols[0] =
313*b843c749SSergey Zigachev ((pattern[1] & 0x03) << 8) | pattern[0];
314*b843c749SSergey Zigachev pattern_symbols[1] =
315*b843c749SSergey Zigachev ((pattern[2] & 0x0f) << 6) | ((pattern[1] >> 2) & 0x3f);
316*b843c749SSergey Zigachev pattern_symbols[2] =
317*b843c749SSergey Zigachev ((pattern[3] & 0x3f) << 4) | ((pattern[2] >> 4) & 0x0f);
318*b843c749SSergey Zigachev pattern_symbols[3] =
319*b843c749SSergey Zigachev (pattern[4] << 2) | ((pattern[3] >> 6) & 0x03);
320*b843c749SSergey Zigachev pattern_symbols[4] =
321*b843c749SSergey Zigachev ((pattern[6] & 0x03) << 8) | pattern[5];
322*b843c749SSergey Zigachev pattern_symbols[5] =
323*b843c749SSergey Zigachev ((pattern[7] & 0x0f) << 6) | ((pattern[6] >> 2) & 0x3f);
324*b843c749SSergey Zigachev pattern_symbols[6] =
325*b843c749SSergey Zigachev ((pattern[8] & 0x3f) << 4) | ((pattern[7] >> 4) & 0x0f);
326*b843c749SSergey Zigachev pattern_symbols[7] =
327*b843c749SSergey Zigachev (pattern[9] << 2) | ((pattern[8] >> 6) & 0x03);
328*b843c749SSergey Zigachev
329*b843c749SSergey Zigachev program_pattern_symbols(enc10, pattern_symbols);
330*b843c749SSergey Zigachev }
331*b843c749SSergey Zigachev
332*b843c749SSergey Zigachev /* Enable phy bypass mode to enable the test pattern */
333*b843c749SSergey Zigachev
334*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, true);
335*b843c749SSergey Zigachev }
336*b843c749SSergey Zigachev
set_dp_phy_pattern_hbr2_compliance_cp2520_2(struct dcn10_link_encoder * enc10,unsigned int cp2520_pattern)337*b843c749SSergey Zigachev static void set_dp_phy_pattern_hbr2_compliance_cp2520_2(
338*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
339*b843c749SSergey Zigachev unsigned int cp2520_pattern)
340*b843c749SSergey Zigachev {
341*b843c749SSergey Zigachev
342*b843c749SSergey Zigachev /* previously there is a register DP_HBR2_EYE_PATTERN
343*b843c749SSergey Zigachev * that is enabled to get the pattern.
344*b843c749SSergey Zigachev * But it does not work with the latest spec change,
345*b843c749SSergey Zigachev * so we are programming the following registers manually.
346*b843c749SSergey Zigachev *
347*b843c749SSergey Zigachev * The following settings have been confirmed
348*b843c749SSergey Zigachev * by Nick Chorney and Sandra Liu
349*b843c749SSergey Zigachev */
350*b843c749SSergey Zigachev
351*b843c749SSergey Zigachev /* Disable PHY Bypass mode to setup the test pattern */
352*b843c749SSergey Zigachev
353*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
354*b843c749SSergey Zigachev
355*b843c749SSergey Zigachev /* Setup DIG encoder in DP SST mode */
356*b843c749SSergey Zigachev enc10->base.funcs->setup(&enc10->base, SIGNAL_TYPE_DISPLAY_PORT);
357*b843c749SSergey Zigachev
358*b843c749SSergey Zigachev /* ensure normal panel mode. */
359*b843c749SSergey Zigachev setup_panel_mode(enc10, DP_PANEL_MODE_DEFAULT);
360*b843c749SSergey Zigachev
361*b843c749SSergey Zigachev /* no vbid after BS (SR)
362*b843c749SSergey Zigachev * DP_LINK_FRAMING_CNTL changed history Sandra Liu
363*b843c749SSergey Zigachev * 11000260 / 11000104 / 110000FC
364*b843c749SSergey Zigachev */
365*b843c749SSergey Zigachev REG_UPDATE_3(DP_LINK_FRAMING_CNTL,
366*b843c749SSergey Zigachev DP_IDLE_BS_INTERVAL, 0xFC,
367*b843c749SSergey Zigachev DP_VBID_DISABLE, 1,
368*b843c749SSergey Zigachev DP_VID_ENHANCED_FRAME_MODE, 1);
369*b843c749SSergey Zigachev
370*b843c749SSergey Zigachev /* swap every BS with SR */
371*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_SCRAM_CNTL, DPHY_SCRAMBLER_BS_COUNT, 0);
372*b843c749SSergey Zigachev
373*b843c749SSergey Zigachev /* select cp2520 patterns */
374*b843c749SSergey Zigachev if (REG(DP_DPHY_HBR2_PATTERN_CONTROL))
375*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_HBR2_PATTERN_CONTROL,
376*b843c749SSergey Zigachev DP_DPHY_HBR2_PATTERN_CONTROL, cp2520_pattern);
377*b843c749SSergey Zigachev else
378*b843c749SSergey Zigachev /* pre-DCE11 can only generate CP2520 pattern 2 */
379*b843c749SSergey Zigachev ASSERT(cp2520_pattern == 2);
380*b843c749SSergey Zigachev
381*b843c749SSergey Zigachev /* set link training complete */
382*b843c749SSergey Zigachev set_link_training_complete(enc10, true);
383*b843c749SSergey Zigachev
384*b843c749SSergey Zigachev /* disable video stream */
385*b843c749SSergey Zigachev REG_UPDATE(DP_VID_STREAM_CNTL, DP_VID_STREAM_ENABLE, 0);
386*b843c749SSergey Zigachev
387*b843c749SSergey Zigachev /* Disable PHY Bypass mode to setup the test pattern */
388*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
389*b843c749SSergey Zigachev }
390*b843c749SSergey Zigachev
set_dp_phy_pattern_passthrough_mode(struct dcn10_link_encoder * enc10,enum dp_panel_mode panel_mode)391*b843c749SSergey Zigachev static void set_dp_phy_pattern_passthrough_mode(
392*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
393*b843c749SSergey Zigachev enum dp_panel_mode panel_mode)
394*b843c749SSergey Zigachev {
395*b843c749SSergey Zigachev /* program correct panel mode */
396*b843c749SSergey Zigachev setup_panel_mode(enc10, panel_mode);
397*b843c749SSergey Zigachev
398*b843c749SSergey Zigachev /* restore LINK_FRAMING_CNTL and DPHY_SCRAMBLER_BS_COUNT
399*b843c749SSergey Zigachev * in case we were doing HBR2 compliance pattern before
400*b843c749SSergey Zigachev */
401*b843c749SSergey Zigachev REG_UPDATE_3(DP_LINK_FRAMING_CNTL,
402*b843c749SSergey Zigachev DP_IDLE_BS_INTERVAL, 0x2000,
403*b843c749SSergey Zigachev DP_VBID_DISABLE, 0,
404*b843c749SSergey Zigachev DP_VID_ENHANCED_FRAME_MODE, 1);
405*b843c749SSergey Zigachev
406*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_SCRAM_CNTL, DPHY_SCRAMBLER_BS_COUNT, 0x1FF);
407*b843c749SSergey Zigachev
408*b843c749SSergey Zigachev /* set link training complete */
409*b843c749SSergey Zigachev set_link_training_complete(enc10, true);
410*b843c749SSergey Zigachev
411*b843c749SSergey Zigachev /* Disable PHY Bypass mode to setup the test pattern */
412*b843c749SSergey Zigachev enable_phy_bypass_mode(enc10, false);
413*b843c749SSergey Zigachev
414*b843c749SSergey Zigachev /* Disable PRBS mode */
415*b843c749SSergey Zigachev disable_prbs_mode(enc10);
416*b843c749SSergey Zigachev }
417*b843c749SSergey Zigachev
418*b843c749SSergey Zigachev /* return value is bit-vector */
get_frontend_source(enum engine_id engine)419*b843c749SSergey Zigachev static uint8_t get_frontend_source(
420*b843c749SSergey Zigachev enum engine_id engine)
421*b843c749SSergey Zigachev {
422*b843c749SSergey Zigachev switch (engine) {
423*b843c749SSergey Zigachev case ENGINE_ID_DIGA:
424*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_DIGA;
425*b843c749SSergey Zigachev case ENGINE_ID_DIGB:
426*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_DIGB;
427*b843c749SSergey Zigachev case ENGINE_ID_DIGC:
428*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_DIGC;
429*b843c749SSergey Zigachev case ENGINE_ID_DIGD:
430*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_DIGD;
431*b843c749SSergey Zigachev case ENGINE_ID_DIGE:
432*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_DIGE;
433*b843c749SSergey Zigachev case ENGINE_ID_DIGF:
434*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_DIGF;
435*b843c749SSergey Zigachev case ENGINE_ID_DIGG:
436*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_DIGG;
437*b843c749SSergey Zigachev default:
438*b843c749SSergey Zigachev ASSERT_CRITICAL(false);
439*b843c749SSergey Zigachev return DCN10_DIG_FE_SOURCE_SELECT_INVALID;
440*b843c749SSergey Zigachev }
441*b843c749SSergey Zigachev }
442*b843c749SSergey Zigachev
configure_encoder(struct dcn10_link_encoder * enc10,const struct dc_link_settings * link_settings)443*b843c749SSergey Zigachev void configure_encoder(
444*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
445*b843c749SSergey Zigachev const struct dc_link_settings *link_settings)
446*b843c749SSergey Zigachev {
447*b843c749SSergey Zigachev /* set number of lanes */
448*b843c749SSergey Zigachev REG_SET(DP_CONFIG, 0,
449*b843c749SSergey Zigachev DP_UDI_LANES, link_settings->lane_count - LANE_COUNT_ONE);
450*b843c749SSergey Zigachev
451*b843c749SSergey Zigachev /* setup scrambler */
452*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_SCRAM_CNTL, DPHY_SCRAMBLER_ADVANCE, 1);
453*b843c749SSergey Zigachev }
454*b843c749SSergey Zigachev
dcn10_psr_program_dp_dphy_fast_training(struct link_encoder * enc,bool exit_link_training_required)455*b843c749SSergey Zigachev void dcn10_psr_program_dp_dphy_fast_training(struct link_encoder *enc,
456*b843c749SSergey Zigachev bool exit_link_training_required)
457*b843c749SSergey Zigachev {
458*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
459*b843c749SSergey Zigachev
460*b843c749SSergey Zigachev if (exit_link_training_required)
461*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_FAST_TRAINING,
462*b843c749SSergey Zigachev DPHY_RX_FAST_TRAINING_CAPABLE, 1);
463*b843c749SSergey Zigachev else {
464*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_FAST_TRAINING,
465*b843c749SSergey Zigachev DPHY_RX_FAST_TRAINING_CAPABLE, 0);
466*b843c749SSergey Zigachev /*In DCE 11, we are able to pre-program a Force SR register
467*b843c749SSergey Zigachev * to be able to trigger SR symbol after 5 idle patterns
468*b843c749SSergey Zigachev * transmitted. Upon PSR Exit, DMCU can trigger
469*b843c749SSergey Zigachev * DPHY_LOAD_BS_COUNT_START = 1. Upon writing 1 to
470*b843c749SSergey Zigachev * DPHY_LOAD_BS_COUNT_START and the internal counter
471*b843c749SSergey Zigachev * reaches DPHY_LOAD_BS_COUNT, the next BS symbol will be
472*b843c749SSergey Zigachev * replaced by SR symbol once.
473*b843c749SSergey Zigachev */
474*b843c749SSergey Zigachev
475*b843c749SSergey Zigachev REG_UPDATE(DP_DPHY_BS_SR_SWAP_CNTL, DPHY_LOAD_BS_COUNT, 0x5);
476*b843c749SSergey Zigachev }
477*b843c749SSergey Zigachev }
478*b843c749SSergey Zigachev
dcn10_psr_program_secondary_packet(struct link_encoder * enc,unsigned int sdp_transmit_line_num_deadline)479*b843c749SSergey Zigachev void dcn10_psr_program_secondary_packet(struct link_encoder *enc,
480*b843c749SSergey Zigachev unsigned int sdp_transmit_line_num_deadline)
481*b843c749SSergey Zigachev {
482*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
483*b843c749SSergey Zigachev
484*b843c749SSergey Zigachev REG_UPDATE_2(DP_SEC_CNTL1,
485*b843c749SSergey Zigachev DP_SEC_GSP0_LINE_NUM, sdp_transmit_line_num_deadline,
486*b843c749SSergey Zigachev DP_SEC_GSP0_PRIORITY, 1);
487*b843c749SSergey Zigachev }
488*b843c749SSergey Zigachev
dcn10_is_dig_enabled(struct link_encoder * enc)489*b843c749SSergey Zigachev bool dcn10_is_dig_enabled(struct link_encoder *enc)
490*b843c749SSergey Zigachev {
491*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
492*b843c749SSergey Zigachev uint32_t value;
493*b843c749SSergey Zigachev
494*b843c749SSergey Zigachev REG_GET(DIG_BE_EN_CNTL, DIG_ENABLE, &value);
495*b843c749SSergey Zigachev return value;
496*b843c749SSergey Zigachev }
497*b843c749SSergey Zigachev
link_encoder_disable(struct dcn10_link_encoder * enc10)498*b843c749SSergey Zigachev static void link_encoder_disable(struct dcn10_link_encoder *enc10)
499*b843c749SSergey Zigachev {
500*b843c749SSergey Zigachev /* reset training pattern */
501*b843c749SSergey Zigachev REG_SET(DP_DPHY_TRAINING_PATTERN_SEL, 0,
502*b843c749SSergey Zigachev DPHY_TRAINING_PATTERN_SEL, 0);
503*b843c749SSergey Zigachev
504*b843c749SSergey Zigachev /* reset training complete */
505*b843c749SSergey Zigachev REG_UPDATE(DP_LINK_CNTL, DP_LINK_TRAINING_COMPLETE, 0);
506*b843c749SSergey Zigachev
507*b843c749SSergey Zigachev /* reset panel mode */
508*b843c749SSergey Zigachev setup_panel_mode(enc10, DP_PANEL_MODE_DEFAULT);
509*b843c749SSergey Zigachev }
510*b843c749SSergey Zigachev
hpd_initialize(struct dcn10_link_encoder * enc10)511*b843c749SSergey Zigachev static void hpd_initialize(
512*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10)
513*b843c749SSergey Zigachev {
514*b843c749SSergey Zigachev /* Associate HPD with DIG_BE */
515*b843c749SSergey Zigachev enum hpd_source_id hpd_source = enc10->base.hpd_source;
516*b843c749SSergey Zigachev
517*b843c749SSergey Zigachev REG_UPDATE(DIG_BE_CNTL, DIG_HPD_SELECT, hpd_source);
518*b843c749SSergey Zigachev }
519*b843c749SSergey Zigachev
dcn10_link_encoder_validate_dvi_output(const struct dcn10_link_encoder * enc10,enum signal_type connector_signal,enum signal_type signal,const struct dc_crtc_timing * crtc_timing)520*b843c749SSergey Zigachev bool dcn10_link_encoder_validate_dvi_output(
521*b843c749SSergey Zigachev const struct dcn10_link_encoder *enc10,
522*b843c749SSergey Zigachev enum signal_type connector_signal,
523*b843c749SSergey Zigachev enum signal_type signal,
524*b843c749SSergey Zigachev const struct dc_crtc_timing *crtc_timing)
525*b843c749SSergey Zigachev {
526*b843c749SSergey Zigachev uint32_t max_pixel_clock = TMDS_MAX_PIXEL_CLOCK;
527*b843c749SSergey Zigachev
528*b843c749SSergey Zigachev if (signal == SIGNAL_TYPE_DVI_DUAL_LINK)
529*b843c749SSergey Zigachev max_pixel_clock *= 2;
530*b843c749SSergey Zigachev
531*b843c749SSergey Zigachev /* This handles the case of HDMI downgrade to DVI we don't want to
532*b843c749SSergey Zigachev * we don't want to cap the pixel clock if the DDI is not DVI.
533*b843c749SSergey Zigachev */
534*b843c749SSergey Zigachev if (connector_signal != SIGNAL_TYPE_DVI_DUAL_LINK &&
535*b843c749SSergey Zigachev connector_signal != SIGNAL_TYPE_DVI_SINGLE_LINK)
536*b843c749SSergey Zigachev max_pixel_clock = enc10->base.features.max_hdmi_pixel_clock;
537*b843c749SSergey Zigachev
538*b843c749SSergey Zigachev /* DVI only support RGB pixel encoding */
539*b843c749SSergey Zigachev if (crtc_timing->pixel_encoding != PIXEL_ENCODING_RGB)
540*b843c749SSergey Zigachev return false;
541*b843c749SSergey Zigachev
542*b843c749SSergey Zigachev /*connect DVI via adpater's HDMI connector*/
543*b843c749SSergey Zigachev if ((connector_signal == SIGNAL_TYPE_DVI_SINGLE_LINK ||
544*b843c749SSergey Zigachev connector_signal == SIGNAL_TYPE_HDMI_TYPE_A) &&
545*b843c749SSergey Zigachev signal != SIGNAL_TYPE_HDMI_TYPE_A &&
546*b843c749SSergey Zigachev crtc_timing->pix_clk_khz > TMDS_MAX_PIXEL_CLOCK)
547*b843c749SSergey Zigachev return false;
548*b843c749SSergey Zigachev if (crtc_timing->pix_clk_khz < TMDS_MIN_PIXEL_CLOCK)
549*b843c749SSergey Zigachev return false;
550*b843c749SSergey Zigachev
551*b843c749SSergey Zigachev if (crtc_timing->pix_clk_khz > max_pixel_clock)
552*b843c749SSergey Zigachev return false;
553*b843c749SSergey Zigachev
554*b843c749SSergey Zigachev /* DVI supports 6/8bpp single-link and 10/16bpp dual-link */
555*b843c749SSergey Zigachev switch (crtc_timing->display_color_depth) {
556*b843c749SSergey Zigachev case COLOR_DEPTH_666:
557*b843c749SSergey Zigachev case COLOR_DEPTH_888:
558*b843c749SSergey Zigachev break;
559*b843c749SSergey Zigachev case COLOR_DEPTH_101010:
560*b843c749SSergey Zigachev case COLOR_DEPTH_161616:
561*b843c749SSergey Zigachev if (signal != SIGNAL_TYPE_DVI_DUAL_LINK)
562*b843c749SSergey Zigachev return false;
563*b843c749SSergey Zigachev break;
564*b843c749SSergey Zigachev default:
565*b843c749SSergey Zigachev return false;
566*b843c749SSergey Zigachev }
567*b843c749SSergey Zigachev
568*b843c749SSergey Zigachev return true;
569*b843c749SSergey Zigachev }
570*b843c749SSergey Zigachev
dcn10_link_encoder_validate_hdmi_output(const struct dcn10_link_encoder * enc10,const struct dc_crtc_timing * crtc_timing,int adjusted_pix_clk_khz)571*b843c749SSergey Zigachev static bool dcn10_link_encoder_validate_hdmi_output(
572*b843c749SSergey Zigachev const struct dcn10_link_encoder *enc10,
573*b843c749SSergey Zigachev const struct dc_crtc_timing *crtc_timing,
574*b843c749SSergey Zigachev int adjusted_pix_clk_khz)
575*b843c749SSergey Zigachev {
576*b843c749SSergey Zigachev enum dc_color_depth max_deep_color =
577*b843c749SSergey Zigachev enc10->base.features.max_hdmi_deep_color;
578*b843c749SSergey Zigachev
579*b843c749SSergey Zigachev if (max_deep_color < crtc_timing->display_color_depth)
580*b843c749SSergey Zigachev return false;
581*b843c749SSergey Zigachev
582*b843c749SSergey Zigachev if (crtc_timing->display_color_depth < COLOR_DEPTH_888)
583*b843c749SSergey Zigachev return false;
584*b843c749SSergey Zigachev if (adjusted_pix_clk_khz < TMDS_MIN_PIXEL_CLOCK)
585*b843c749SSergey Zigachev return false;
586*b843c749SSergey Zigachev
587*b843c749SSergey Zigachev if ((adjusted_pix_clk_khz == 0) ||
588*b843c749SSergey Zigachev (adjusted_pix_clk_khz > enc10->base.features.max_hdmi_pixel_clock))
589*b843c749SSergey Zigachev return false;
590*b843c749SSergey Zigachev
591*b843c749SSergey Zigachev /* DCE11 HW does not support 420 */
592*b843c749SSergey Zigachev if (!enc10->base.features.ycbcr420_supported &&
593*b843c749SSergey Zigachev crtc_timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
594*b843c749SSergey Zigachev return false;
595*b843c749SSergey Zigachev
596*b843c749SSergey Zigachev if (!enc10->base.features.flags.bits.HDMI_6GB_EN &&
597*b843c749SSergey Zigachev adjusted_pix_clk_khz >= 300000)
598*b843c749SSergey Zigachev return false;
599*b843c749SSergey Zigachev if (enc10->base.ctx->dc->debug.hdmi20_disable &&
600*b843c749SSergey Zigachev crtc_timing->pixel_encoding == PIXEL_ENCODING_YCBCR420)
601*b843c749SSergey Zigachev return false;
602*b843c749SSergey Zigachev return true;
603*b843c749SSergey Zigachev }
604*b843c749SSergey Zigachev
dcn10_link_encoder_validate_dp_output(const struct dcn10_link_encoder * enc10,const struct dc_crtc_timing * crtc_timing)605*b843c749SSergey Zigachev bool dcn10_link_encoder_validate_dp_output(
606*b843c749SSergey Zigachev const struct dcn10_link_encoder *enc10,
607*b843c749SSergey Zigachev const struct dc_crtc_timing *crtc_timing)
608*b843c749SSergey Zigachev {
609*b843c749SSergey Zigachev /* default RGB only */
610*b843c749SSergey Zigachev if (crtc_timing->pixel_encoding == PIXEL_ENCODING_RGB)
611*b843c749SSergey Zigachev return true;
612*b843c749SSergey Zigachev
613*b843c749SSergey Zigachev if (enc10->base.features.flags.bits.IS_YCBCR_CAPABLE)
614*b843c749SSergey Zigachev return true;
615*b843c749SSergey Zigachev
616*b843c749SSergey Zigachev /* for DCE 8.x or later DP Y-only feature,
617*b843c749SSergey Zigachev * we need ASIC cap + FeatureSupportDPYonly, not support 666
618*b843c749SSergey Zigachev */
619*b843c749SSergey Zigachev if (crtc_timing->flags.Y_ONLY &&
620*b843c749SSergey Zigachev enc10->base.features.flags.bits.IS_YCBCR_CAPABLE &&
621*b843c749SSergey Zigachev crtc_timing->display_color_depth != COLOR_DEPTH_666)
622*b843c749SSergey Zigachev return true;
623*b843c749SSergey Zigachev
624*b843c749SSergey Zigachev return false;
625*b843c749SSergey Zigachev }
626*b843c749SSergey Zigachev
dcn10_link_encoder_construct(struct dcn10_link_encoder * enc10,const struct encoder_init_data * init_data,const struct encoder_feature_support * enc_features,const struct dcn10_link_enc_registers * link_regs,const struct dcn10_link_enc_aux_registers * aux_regs,const struct dcn10_link_enc_hpd_registers * hpd_regs,const struct dcn10_link_enc_shift * link_shift,const struct dcn10_link_enc_mask * link_mask)627*b843c749SSergey Zigachev void dcn10_link_encoder_construct(
628*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10,
629*b843c749SSergey Zigachev const struct encoder_init_data *init_data,
630*b843c749SSergey Zigachev const struct encoder_feature_support *enc_features,
631*b843c749SSergey Zigachev const struct dcn10_link_enc_registers *link_regs,
632*b843c749SSergey Zigachev const struct dcn10_link_enc_aux_registers *aux_regs,
633*b843c749SSergey Zigachev const struct dcn10_link_enc_hpd_registers *hpd_regs,
634*b843c749SSergey Zigachev const struct dcn10_link_enc_shift *link_shift,
635*b843c749SSergey Zigachev const struct dcn10_link_enc_mask *link_mask)
636*b843c749SSergey Zigachev {
637*b843c749SSergey Zigachev struct bp_encoder_cap_info bp_cap_info = {0};
638*b843c749SSergey Zigachev const struct dc_vbios_funcs *bp_funcs = init_data->ctx->dc_bios->funcs;
639*b843c749SSergey Zigachev enum bp_result result = BP_RESULT_OK;
640*b843c749SSergey Zigachev
641*b843c749SSergey Zigachev enc10->base.funcs = &dcn10_lnk_enc_funcs;
642*b843c749SSergey Zigachev enc10->base.ctx = init_data->ctx;
643*b843c749SSergey Zigachev enc10->base.id = init_data->encoder;
644*b843c749SSergey Zigachev
645*b843c749SSergey Zigachev enc10->base.hpd_source = init_data->hpd_source;
646*b843c749SSergey Zigachev enc10->base.connector = init_data->connector;
647*b843c749SSergey Zigachev
648*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
649*b843c749SSergey Zigachev
650*b843c749SSergey Zigachev enc10->base.features = *enc_features;
651*b843c749SSergey Zigachev
652*b843c749SSergey Zigachev enc10->base.transmitter = init_data->transmitter;
653*b843c749SSergey Zigachev
654*b843c749SSergey Zigachev /* set the flag to indicate whether driver poll the I2C data pin
655*b843c749SSergey Zigachev * while doing the DP sink detect
656*b843c749SSergey Zigachev */
657*b843c749SSergey Zigachev
658*b843c749SSergey Zigachev /* if (dal_adapter_service_is_feature_supported(as,
659*b843c749SSergey Zigachev FEATURE_DP_SINK_DETECT_POLL_DATA_PIN))
660*b843c749SSergey Zigachev enc10->base.features.flags.bits.
661*b843c749SSergey Zigachev DP_SINK_DETECT_POLL_DATA_PIN = true;*/
662*b843c749SSergey Zigachev
663*b843c749SSergey Zigachev enc10->base.output_signals =
664*b843c749SSergey Zigachev SIGNAL_TYPE_DVI_SINGLE_LINK |
665*b843c749SSergey Zigachev SIGNAL_TYPE_DVI_DUAL_LINK |
666*b843c749SSergey Zigachev SIGNAL_TYPE_LVDS |
667*b843c749SSergey Zigachev SIGNAL_TYPE_DISPLAY_PORT |
668*b843c749SSergey Zigachev SIGNAL_TYPE_DISPLAY_PORT_MST |
669*b843c749SSergey Zigachev SIGNAL_TYPE_EDP |
670*b843c749SSergey Zigachev SIGNAL_TYPE_HDMI_TYPE_A;
671*b843c749SSergey Zigachev
672*b843c749SSergey Zigachev /* For DCE 8.0 and 8.1, by design, UNIPHY is hardwired to DIG_BE.
673*b843c749SSergey Zigachev * SW always assign DIG_FE 1:1 mapped to DIG_FE for non-MST UNIPHY.
674*b843c749SSergey Zigachev * SW assign DIG_FE to non-MST UNIPHY first and MST last. So prefer
675*b843c749SSergey Zigachev * DIG is per UNIPHY and used by SST DP, eDP, HDMI, DVI and LVDS.
676*b843c749SSergey Zigachev * Prefer DIG assignment is decided by board design.
677*b843c749SSergey Zigachev * For DCE 8.0, there are only max 6 UNIPHYs, we assume board design
678*b843c749SSergey Zigachev * and VBIOS will filter out 7 UNIPHY for DCE 8.0.
679*b843c749SSergey Zigachev * By this, adding DIGG should not hurt DCE 8.0.
680*b843c749SSergey Zigachev * This will let DCE 8.1 share DCE 8.0 as much as possible
681*b843c749SSergey Zigachev */
682*b843c749SSergey Zigachev
683*b843c749SSergey Zigachev enc10->link_regs = link_regs;
684*b843c749SSergey Zigachev enc10->aux_regs = aux_regs;
685*b843c749SSergey Zigachev enc10->hpd_regs = hpd_regs;
686*b843c749SSergey Zigachev enc10->link_shift = link_shift;
687*b843c749SSergey Zigachev enc10->link_mask = link_mask;
688*b843c749SSergey Zigachev
689*b843c749SSergey Zigachev switch (enc10->base.transmitter) {
690*b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_A:
691*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_DIGA;
692*b843c749SSergey Zigachev break;
693*b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_B:
694*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_DIGB;
695*b843c749SSergey Zigachev break;
696*b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_C:
697*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_DIGC;
698*b843c749SSergey Zigachev break;
699*b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_D:
700*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_DIGD;
701*b843c749SSergey Zigachev break;
702*b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_E:
703*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_DIGE;
704*b843c749SSergey Zigachev break;
705*b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_F:
706*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_DIGF;
707*b843c749SSergey Zigachev break;
708*b843c749SSergey Zigachev case TRANSMITTER_UNIPHY_G:
709*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_DIGG;
710*b843c749SSergey Zigachev break;
711*b843c749SSergey Zigachev default:
712*b843c749SSergey Zigachev ASSERT_CRITICAL(false);
713*b843c749SSergey Zigachev enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
714*b843c749SSergey Zigachev }
715*b843c749SSergey Zigachev
716*b843c749SSergey Zigachev /* default to one to mirror Windows behavior */
717*b843c749SSergey Zigachev enc10->base.features.flags.bits.HDMI_6GB_EN = 1;
718*b843c749SSergey Zigachev
719*b843c749SSergey Zigachev result = bp_funcs->get_encoder_cap_info(enc10->base.ctx->dc_bios,
720*b843c749SSergey Zigachev enc10->base.id, &bp_cap_info);
721*b843c749SSergey Zigachev
722*b843c749SSergey Zigachev /* Override features with DCE-specific values */
723*b843c749SSergey Zigachev if (result == BP_RESULT_OK) {
724*b843c749SSergey Zigachev enc10->base.features.flags.bits.IS_HBR2_CAPABLE =
725*b843c749SSergey Zigachev bp_cap_info.DP_HBR2_EN;
726*b843c749SSergey Zigachev enc10->base.features.flags.bits.IS_HBR3_CAPABLE =
727*b843c749SSergey Zigachev bp_cap_info.DP_HBR3_EN;
728*b843c749SSergey Zigachev enc10->base.features.flags.bits.HDMI_6GB_EN = bp_cap_info.HDMI_6GB_EN;
729*b843c749SSergey Zigachev } else {
730*b843c749SSergey Zigachev DC_LOG_WARNING("%s: Failed to get encoder_cap_info from VBIOS with error code %d!\n",
731*b843c749SSergey Zigachev __func__,
732*b843c749SSergey Zigachev result);
733*b843c749SSergey Zigachev }
734*b843c749SSergey Zigachev if (enc10->base.ctx->dc->debug.hdmi20_disable) {
735*b843c749SSergey Zigachev enc10->base.features.flags.bits.HDMI_6GB_EN = 0;
736*b843c749SSergey Zigachev }
737*b843c749SSergey Zigachev }
738*b843c749SSergey Zigachev
dcn10_link_encoder_validate_output_with_stream(struct link_encoder * enc,const struct dc_stream_state * stream)739*b843c749SSergey Zigachev bool dcn10_link_encoder_validate_output_with_stream(
740*b843c749SSergey Zigachev struct link_encoder *enc,
741*b843c749SSergey Zigachev const struct dc_stream_state *stream)
742*b843c749SSergey Zigachev {
743*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
744*b843c749SSergey Zigachev bool is_valid;
745*b843c749SSergey Zigachev
746*b843c749SSergey Zigachev switch (stream->signal) {
747*b843c749SSergey Zigachev case SIGNAL_TYPE_DVI_SINGLE_LINK:
748*b843c749SSergey Zigachev case SIGNAL_TYPE_DVI_DUAL_LINK:
749*b843c749SSergey Zigachev is_valid = dcn10_link_encoder_validate_dvi_output(
750*b843c749SSergey Zigachev enc10,
751*b843c749SSergey Zigachev stream->sink->link->connector_signal,
752*b843c749SSergey Zigachev stream->signal,
753*b843c749SSergey Zigachev &stream->timing);
754*b843c749SSergey Zigachev break;
755*b843c749SSergey Zigachev case SIGNAL_TYPE_HDMI_TYPE_A:
756*b843c749SSergey Zigachev is_valid = dcn10_link_encoder_validate_hdmi_output(
757*b843c749SSergey Zigachev enc10,
758*b843c749SSergey Zigachev &stream->timing,
759*b843c749SSergey Zigachev stream->phy_pix_clk);
760*b843c749SSergey Zigachev break;
761*b843c749SSergey Zigachev case SIGNAL_TYPE_DISPLAY_PORT:
762*b843c749SSergey Zigachev case SIGNAL_TYPE_DISPLAY_PORT_MST:
763*b843c749SSergey Zigachev is_valid = dcn10_link_encoder_validate_dp_output(
764*b843c749SSergey Zigachev enc10, &stream->timing);
765*b843c749SSergey Zigachev break;
766*b843c749SSergey Zigachev case SIGNAL_TYPE_EDP:
767*b843c749SSergey Zigachev is_valid = (stream->timing.pixel_encoding == PIXEL_ENCODING_RGB) ? true : false;
768*b843c749SSergey Zigachev break;
769*b843c749SSergey Zigachev case SIGNAL_TYPE_VIRTUAL:
770*b843c749SSergey Zigachev is_valid = true;
771*b843c749SSergey Zigachev break;
772*b843c749SSergey Zigachev default:
773*b843c749SSergey Zigachev is_valid = false;
774*b843c749SSergey Zigachev break;
775*b843c749SSergey Zigachev }
776*b843c749SSergey Zigachev
777*b843c749SSergey Zigachev return is_valid;
778*b843c749SSergey Zigachev }
779*b843c749SSergey Zigachev
dcn10_link_encoder_hw_init(struct link_encoder * enc)780*b843c749SSergey Zigachev void dcn10_link_encoder_hw_init(
781*b843c749SSergey Zigachev struct link_encoder *enc)
782*b843c749SSergey Zigachev {
783*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
784*b843c749SSergey Zigachev struct bp_transmitter_control cntl = { 0 };
785*b843c749SSergey Zigachev enum bp_result result;
786*b843c749SSergey Zigachev
787*b843c749SSergey Zigachev cntl.action = TRANSMITTER_CONTROL_INIT;
788*b843c749SSergey Zigachev cntl.engine_id = ENGINE_ID_UNKNOWN;
789*b843c749SSergey Zigachev cntl.transmitter = enc10->base.transmitter;
790*b843c749SSergey Zigachev cntl.connector_obj_id = enc10->base.connector;
791*b843c749SSergey Zigachev cntl.lanes_number = LANE_COUNT_FOUR;
792*b843c749SSergey Zigachev cntl.coherent = false;
793*b843c749SSergey Zigachev cntl.hpd_sel = enc10->base.hpd_source;
794*b843c749SSergey Zigachev
795*b843c749SSergey Zigachev if (enc10->base.connector.id == CONNECTOR_ID_EDP)
796*b843c749SSergey Zigachev cntl.signal = SIGNAL_TYPE_EDP;
797*b843c749SSergey Zigachev
798*b843c749SSergey Zigachev result = link_transmitter_control(enc10, &cntl);
799*b843c749SSergey Zigachev
800*b843c749SSergey Zigachev if (result != BP_RESULT_OK) {
801*b843c749SSergey Zigachev DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
802*b843c749SSergey Zigachev __func__);
803*b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
804*b843c749SSergey Zigachev return;
805*b843c749SSergey Zigachev }
806*b843c749SSergey Zigachev
807*b843c749SSergey Zigachev if (enc10->base.connector.id == CONNECTOR_ID_LVDS) {
808*b843c749SSergey Zigachev cntl.action = TRANSMITTER_CONTROL_BACKLIGHT_BRIGHTNESS;
809*b843c749SSergey Zigachev
810*b843c749SSergey Zigachev result = link_transmitter_control(enc10, &cntl);
811*b843c749SSergey Zigachev
812*b843c749SSergey Zigachev ASSERT(result == BP_RESULT_OK);
813*b843c749SSergey Zigachev
814*b843c749SSergey Zigachev }
815*b843c749SSergey Zigachev dcn10_aux_initialize(enc10);
816*b843c749SSergey Zigachev
817*b843c749SSergey Zigachev /* reinitialize HPD.
818*b843c749SSergey Zigachev * hpd_initialize() will pass DIG_FE id to HW context.
819*b843c749SSergey Zigachev * All other routine within HW context will use fe_engine_offset
820*b843c749SSergey Zigachev * as DIG_FE id even caller pass DIG_FE id.
821*b843c749SSergey Zigachev * So this routine must be called first.
822*b843c749SSergey Zigachev */
823*b843c749SSergey Zigachev hpd_initialize(enc10);
824*b843c749SSergey Zigachev }
825*b843c749SSergey Zigachev
dcn10_link_encoder_destroy(struct link_encoder ** enc)826*b843c749SSergey Zigachev void dcn10_link_encoder_destroy(struct link_encoder **enc)
827*b843c749SSergey Zigachev {
828*b843c749SSergey Zigachev kfree(TO_DCN10_LINK_ENC(*enc));
829*b843c749SSergey Zigachev *enc = NULL;
830*b843c749SSergey Zigachev }
831*b843c749SSergey Zigachev
dcn10_link_encoder_setup(struct link_encoder * enc,enum signal_type signal)832*b843c749SSergey Zigachev void dcn10_link_encoder_setup(
833*b843c749SSergey Zigachev struct link_encoder *enc,
834*b843c749SSergey Zigachev enum signal_type signal)
835*b843c749SSergey Zigachev {
836*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
837*b843c749SSergey Zigachev
838*b843c749SSergey Zigachev switch (signal) {
839*b843c749SSergey Zigachev case SIGNAL_TYPE_EDP:
840*b843c749SSergey Zigachev case SIGNAL_TYPE_DISPLAY_PORT:
841*b843c749SSergey Zigachev /* DP SST */
842*b843c749SSergey Zigachev REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 0);
843*b843c749SSergey Zigachev break;
844*b843c749SSergey Zigachev case SIGNAL_TYPE_LVDS:
845*b843c749SSergey Zigachev /* LVDS */
846*b843c749SSergey Zigachev REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 1);
847*b843c749SSergey Zigachev break;
848*b843c749SSergey Zigachev case SIGNAL_TYPE_DVI_SINGLE_LINK:
849*b843c749SSergey Zigachev case SIGNAL_TYPE_DVI_DUAL_LINK:
850*b843c749SSergey Zigachev /* TMDS-DVI */
851*b843c749SSergey Zigachev REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 2);
852*b843c749SSergey Zigachev break;
853*b843c749SSergey Zigachev case SIGNAL_TYPE_HDMI_TYPE_A:
854*b843c749SSergey Zigachev /* TMDS-HDMI */
855*b843c749SSergey Zigachev REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 3);
856*b843c749SSergey Zigachev break;
857*b843c749SSergey Zigachev case SIGNAL_TYPE_DISPLAY_PORT_MST:
858*b843c749SSergey Zigachev /* DP MST */
859*b843c749SSergey Zigachev REG_UPDATE(DIG_BE_CNTL, DIG_MODE, 5);
860*b843c749SSergey Zigachev break;
861*b843c749SSergey Zigachev default:
862*b843c749SSergey Zigachev ASSERT_CRITICAL(false);
863*b843c749SSergey Zigachev /* invalid mode ! */
864*b843c749SSergey Zigachev break;
865*b843c749SSergey Zigachev }
866*b843c749SSergey Zigachev
867*b843c749SSergey Zigachev }
868*b843c749SSergey Zigachev
869*b843c749SSergey Zigachev /* TODO: still need depth or just pass in adjusted pixel clock? */
dcn10_link_encoder_enable_tmds_output(struct link_encoder * enc,enum clock_source_id clock_source,enum dc_color_depth color_depth,enum signal_type signal,uint32_t pixel_clock)870*b843c749SSergey Zigachev void dcn10_link_encoder_enable_tmds_output(
871*b843c749SSergey Zigachev struct link_encoder *enc,
872*b843c749SSergey Zigachev enum clock_source_id clock_source,
873*b843c749SSergey Zigachev enum dc_color_depth color_depth,
874*b843c749SSergey Zigachev enum signal_type signal,
875*b843c749SSergey Zigachev uint32_t pixel_clock)
876*b843c749SSergey Zigachev {
877*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
878*b843c749SSergey Zigachev struct bp_transmitter_control cntl = { 0 };
879*b843c749SSergey Zigachev enum bp_result result;
880*b843c749SSergey Zigachev
881*b843c749SSergey Zigachev /* Enable the PHY */
882*b843c749SSergey Zigachev
883*b843c749SSergey Zigachev cntl.action = TRANSMITTER_CONTROL_ENABLE;
884*b843c749SSergey Zigachev cntl.engine_id = enc->preferred_engine;
885*b843c749SSergey Zigachev cntl.transmitter = enc10->base.transmitter;
886*b843c749SSergey Zigachev cntl.pll_id = clock_source;
887*b843c749SSergey Zigachev cntl.signal = signal;
888*b843c749SSergey Zigachev if (cntl.signal == SIGNAL_TYPE_DVI_DUAL_LINK)
889*b843c749SSergey Zigachev cntl.lanes_number = 8;
890*b843c749SSergey Zigachev else
891*b843c749SSergey Zigachev cntl.lanes_number = 4;
892*b843c749SSergey Zigachev
893*b843c749SSergey Zigachev cntl.hpd_sel = enc10->base.hpd_source;
894*b843c749SSergey Zigachev
895*b843c749SSergey Zigachev cntl.pixel_clock = pixel_clock;
896*b843c749SSergey Zigachev cntl.color_depth = color_depth;
897*b843c749SSergey Zigachev
898*b843c749SSergey Zigachev result = link_transmitter_control(enc10, &cntl);
899*b843c749SSergey Zigachev
900*b843c749SSergey Zigachev if (result != BP_RESULT_OK) {
901*b843c749SSergey Zigachev DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
902*b843c749SSergey Zigachev __func__);
903*b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
904*b843c749SSergey Zigachev }
905*b843c749SSergey Zigachev }
906*b843c749SSergey Zigachev
907*b843c749SSergey Zigachev /* enables DP PHY output */
dcn10_link_encoder_enable_dp_output(struct link_encoder * enc,const struct dc_link_settings * link_settings,enum clock_source_id clock_source)908*b843c749SSergey Zigachev void dcn10_link_encoder_enable_dp_output(
909*b843c749SSergey Zigachev struct link_encoder *enc,
910*b843c749SSergey Zigachev const struct dc_link_settings *link_settings,
911*b843c749SSergey Zigachev enum clock_source_id clock_source)
912*b843c749SSergey Zigachev {
913*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
914*b843c749SSergey Zigachev struct bp_transmitter_control cntl = { 0 };
915*b843c749SSergey Zigachev enum bp_result result;
916*b843c749SSergey Zigachev
917*b843c749SSergey Zigachev /* Enable the PHY */
918*b843c749SSergey Zigachev
919*b843c749SSergey Zigachev /* number_of_lanes is used for pixel clock adjust,
920*b843c749SSergey Zigachev * but it's not passed to asic_control.
921*b843c749SSergey Zigachev * We need to set number of lanes manually.
922*b843c749SSergey Zigachev */
923*b843c749SSergey Zigachev configure_encoder(enc10, link_settings);
924*b843c749SSergey Zigachev
925*b843c749SSergey Zigachev cntl.action = TRANSMITTER_CONTROL_ENABLE;
926*b843c749SSergey Zigachev cntl.engine_id = enc->preferred_engine;
927*b843c749SSergey Zigachev cntl.transmitter = enc10->base.transmitter;
928*b843c749SSergey Zigachev cntl.pll_id = clock_source;
929*b843c749SSergey Zigachev cntl.signal = SIGNAL_TYPE_DISPLAY_PORT;
930*b843c749SSergey Zigachev cntl.lanes_number = link_settings->lane_count;
931*b843c749SSergey Zigachev cntl.hpd_sel = enc10->base.hpd_source;
932*b843c749SSergey Zigachev cntl.pixel_clock = link_settings->link_rate
933*b843c749SSergey Zigachev * LINK_RATE_REF_FREQ_IN_KHZ;
934*b843c749SSergey Zigachev /* TODO: check if undefined works */
935*b843c749SSergey Zigachev cntl.color_depth = COLOR_DEPTH_UNDEFINED;
936*b843c749SSergey Zigachev
937*b843c749SSergey Zigachev result = link_transmitter_control(enc10, &cntl);
938*b843c749SSergey Zigachev
939*b843c749SSergey Zigachev if (result != BP_RESULT_OK) {
940*b843c749SSergey Zigachev DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
941*b843c749SSergey Zigachev __func__);
942*b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
943*b843c749SSergey Zigachev }
944*b843c749SSergey Zigachev }
945*b843c749SSergey Zigachev
946*b843c749SSergey Zigachev /* enables DP PHY output in MST mode */
dcn10_link_encoder_enable_dp_mst_output(struct link_encoder * enc,const struct dc_link_settings * link_settings,enum clock_source_id clock_source)947*b843c749SSergey Zigachev void dcn10_link_encoder_enable_dp_mst_output(
948*b843c749SSergey Zigachev struct link_encoder *enc,
949*b843c749SSergey Zigachev const struct dc_link_settings *link_settings,
950*b843c749SSergey Zigachev enum clock_source_id clock_source)
951*b843c749SSergey Zigachev {
952*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
953*b843c749SSergey Zigachev struct bp_transmitter_control cntl = { 0 };
954*b843c749SSergey Zigachev enum bp_result result;
955*b843c749SSergey Zigachev
956*b843c749SSergey Zigachev /* Enable the PHY */
957*b843c749SSergey Zigachev
958*b843c749SSergey Zigachev /* number_of_lanes is used for pixel clock adjust,
959*b843c749SSergey Zigachev * but it's not passed to asic_control.
960*b843c749SSergey Zigachev * We need to set number of lanes manually.
961*b843c749SSergey Zigachev */
962*b843c749SSergey Zigachev configure_encoder(enc10, link_settings);
963*b843c749SSergey Zigachev
964*b843c749SSergey Zigachev cntl.action = TRANSMITTER_CONTROL_ENABLE;
965*b843c749SSergey Zigachev cntl.engine_id = ENGINE_ID_UNKNOWN;
966*b843c749SSergey Zigachev cntl.transmitter = enc10->base.transmitter;
967*b843c749SSergey Zigachev cntl.pll_id = clock_source;
968*b843c749SSergey Zigachev cntl.signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
969*b843c749SSergey Zigachev cntl.lanes_number = link_settings->lane_count;
970*b843c749SSergey Zigachev cntl.hpd_sel = enc10->base.hpd_source;
971*b843c749SSergey Zigachev cntl.pixel_clock = link_settings->link_rate
972*b843c749SSergey Zigachev * LINK_RATE_REF_FREQ_IN_KHZ;
973*b843c749SSergey Zigachev /* TODO: check if undefined works */
974*b843c749SSergey Zigachev cntl.color_depth = COLOR_DEPTH_UNDEFINED;
975*b843c749SSergey Zigachev
976*b843c749SSergey Zigachev result = link_transmitter_control(enc10, &cntl);
977*b843c749SSergey Zigachev
978*b843c749SSergey Zigachev if (result != BP_RESULT_OK) {
979*b843c749SSergey Zigachev DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
980*b843c749SSergey Zigachev __func__);
981*b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
982*b843c749SSergey Zigachev }
983*b843c749SSergey Zigachev }
984*b843c749SSergey Zigachev /*
985*b843c749SSergey Zigachev * @brief
986*b843c749SSergey Zigachev * Disable transmitter and its encoder
987*b843c749SSergey Zigachev */
dcn10_link_encoder_disable_output(struct link_encoder * enc,enum signal_type signal)988*b843c749SSergey Zigachev void dcn10_link_encoder_disable_output(
989*b843c749SSergey Zigachev struct link_encoder *enc,
990*b843c749SSergey Zigachev enum signal_type signal)
991*b843c749SSergey Zigachev {
992*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
993*b843c749SSergey Zigachev struct bp_transmitter_control cntl = { 0 };
994*b843c749SSergey Zigachev enum bp_result result;
995*b843c749SSergey Zigachev
996*b843c749SSergey Zigachev if (!dcn10_is_dig_enabled(enc)) {
997*b843c749SSergey Zigachev /* OF_SKIP_POWER_DOWN_INACTIVE_ENCODER */
998*b843c749SSergey Zigachev /*in DP_Alt_No_Connect case, we turn off the dig already,
999*b843c749SSergey Zigachev after excuation the PHY w/a sequence, not allow touch PHY any more*/
1000*b843c749SSergey Zigachev return;
1001*b843c749SSergey Zigachev }
1002*b843c749SSergey Zigachev /* Power-down RX and disable GPU PHY should be paired.
1003*b843c749SSergey Zigachev * Disabling PHY without powering down RX may cause
1004*b843c749SSergey Zigachev * symbol lock loss, on which we will get DP Sink interrupt.
1005*b843c749SSergey Zigachev */
1006*b843c749SSergey Zigachev
1007*b843c749SSergey Zigachev /* There is a case for the DP active dongles
1008*b843c749SSergey Zigachev * where we want to disable the PHY but keep RX powered,
1009*b843c749SSergey Zigachev * for those we need to ignore DP Sink interrupt
1010*b843c749SSergey Zigachev * by checking lane count that has been set
1011*b843c749SSergey Zigachev * on the last do_enable_output().
1012*b843c749SSergey Zigachev */
1013*b843c749SSergey Zigachev
1014*b843c749SSergey Zigachev /* disable transmitter */
1015*b843c749SSergey Zigachev cntl.action = TRANSMITTER_CONTROL_DISABLE;
1016*b843c749SSergey Zigachev cntl.transmitter = enc10->base.transmitter;
1017*b843c749SSergey Zigachev cntl.hpd_sel = enc10->base.hpd_source;
1018*b843c749SSergey Zigachev cntl.signal = signal;
1019*b843c749SSergey Zigachev cntl.connector_obj_id = enc10->base.connector;
1020*b843c749SSergey Zigachev
1021*b843c749SSergey Zigachev result = link_transmitter_control(enc10, &cntl);
1022*b843c749SSergey Zigachev
1023*b843c749SSergey Zigachev if (result != BP_RESULT_OK) {
1024*b843c749SSergey Zigachev DC_LOG_ERROR("%s: Failed to execute VBIOS command table!\n",
1025*b843c749SSergey Zigachev __func__);
1026*b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1027*b843c749SSergey Zigachev return;
1028*b843c749SSergey Zigachev }
1029*b843c749SSergey Zigachev
1030*b843c749SSergey Zigachev /* disable encoder */
1031*b843c749SSergey Zigachev if (dc_is_dp_signal(signal))
1032*b843c749SSergey Zigachev link_encoder_disable(enc10);
1033*b843c749SSergey Zigachev }
1034*b843c749SSergey Zigachev
dcn10_link_encoder_dp_set_lane_settings(struct link_encoder * enc,const struct link_training_settings * link_settings)1035*b843c749SSergey Zigachev void dcn10_link_encoder_dp_set_lane_settings(
1036*b843c749SSergey Zigachev struct link_encoder *enc,
1037*b843c749SSergey Zigachev const struct link_training_settings *link_settings)
1038*b843c749SSergey Zigachev {
1039*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1040*b843c749SSergey Zigachev union dpcd_training_lane_set training_lane_set = { { 0 } };
1041*b843c749SSergey Zigachev int32_t lane = 0;
1042*b843c749SSergey Zigachev struct bp_transmitter_control cntl = { 0 };
1043*b843c749SSergey Zigachev
1044*b843c749SSergey Zigachev if (!link_settings) {
1045*b843c749SSergey Zigachev BREAK_TO_DEBUGGER();
1046*b843c749SSergey Zigachev return;
1047*b843c749SSergey Zigachev }
1048*b843c749SSergey Zigachev
1049*b843c749SSergey Zigachev cntl.action = TRANSMITTER_CONTROL_SET_VOLTAGE_AND_PREEMPASIS;
1050*b843c749SSergey Zigachev cntl.transmitter = enc10->base.transmitter;
1051*b843c749SSergey Zigachev cntl.connector_obj_id = enc10->base.connector;
1052*b843c749SSergey Zigachev cntl.lanes_number = link_settings->link_settings.lane_count;
1053*b843c749SSergey Zigachev cntl.hpd_sel = enc10->base.hpd_source;
1054*b843c749SSergey Zigachev cntl.pixel_clock = link_settings->link_settings.link_rate *
1055*b843c749SSergey Zigachev LINK_RATE_REF_FREQ_IN_KHZ;
1056*b843c749SSergey Zigachev
1057*b843c749SSergey Zigachev for (lane = 0; lane < link_settings->link_settings.lane_count; lane++) {
1058*b843c749SSergey Zigachev /* translate lane settings */
1059*b843c749SSergey Zigachev
1060*b843c749SSergey Zigachev training_lane_set.bits.VOLTAGE_SWING_SET =
1061*b843c749SSergey Zigachev link_settings->lane_settings[lane].VOLTAGE_SWING;
1062*b843c749SSergey Zigachev training_lane_set.bits.PRE_EMPHASIS_SET =
1063*b843c749SSergey Zigachev link_settings->lane_settings[lane].PRE_EMPHASIS;
1064*b843c749SSergey Zigachev
1065*b843c749SSergey Zigachev /* post cursor 2 setting only applies to HBR2 link rate */
1066*b843c749SSergey Zigachev if (link_settings->link_settings.link_rate == LINK_RATE_HIGH2) {
1067*b843c749SSergey Zigachev /* this is passed to VBIOS
1068*b843c749SSergey Zigachev * to program post cursor 2 level
1069*b843c749SSergey Zigachev */
1070*b843c749SSergey Zigachev training_lane_set.bits.POST_CURSOR2_SET =
1071*b843c749SSergey Zigachev link_settings->lane_settings[lane].POST_CURSOR2;
1072*b843c749SSergey Zigachev }
1073*b843c749SSergey Zigachev
1074*b843c749SSergey Zigachev cntl.lane_select = lane;
1075*b843c749SSergey Zigachev cntl.lane_settings = training_lane_set.raw;
1076*b843c749SSergey Zigachev
1077*b843c749SSergey Zigachev /* call VBIOS table to set voltage swing and pre-emphasis */
1078*b843c749SSergey Zigachev link_transmitter_control(enc10, &cntl);
1079*b843c749SSergey Zigachev }
1080*b843c749SSergey Zigachev }
1081*b843c749SSergey Zigachev
1082*b843c749SSergey Zigachev /* set DP PHY test and training patterns */
dcn10_link_encoder_dp_set_phy_pattern(struct link_encoder * enc,const struct encoder_set_dp_phy_pattern_param * param)1083*b843c749SSergey Zigachev void dcn10_link_encoder_dp_set_phy_pattern(
1084*b843c749SSergey Zigachev struct link_encoder *enc,
1085*b843c749SSergey Zigachev const struct encoder_set_dp_phy_pattern_param *param)
1086*b843c749SSergey Zigachev {
1087*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1088*b843c749SSergey Zigachev
1089*b843c749SSergey Zigachev switch (param->dp_phy_pattern) {
1090*b843c749SSergey Zigachev case DP_TEST_PATTERN_TRAINING_PATTERN1:
1091*b843c749SSergey Zigachev dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 0);
1092*b843c749SSergey Zigachev break;
1093*b843c749SSergey Zigachev case DP_TEST_PATTERN_TRAINING_PATTERN2:
1094*b843c749SSergey Zigachev dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 1);
1095*b843c749SSergey Zigachev break;
1096*b843c749SSergey Zigachev case DP_TEST_PATTERN_TRAINING_PATTERN3:
1097*b843c749SSergey Zigachev dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 2);
1098*b843c749SSergey Zigachev break;
1099*b843c749SSergey Zigachev case DP_TEST_PATTERN_TRAINING_PATTERN4:
1100*b843c749SSergey Zigachev dcn10_link_encoder_set_dp_phy_pattern_training_pattern(enc, 3);
1101*b843c749SSergey Zigachev break;
1102*b843c749SSergey Zigachev case DP_TEST_PATTERN_D102:
1103*b843c749SSergey Zigachev set_dp_phy_pattern_d102(enc10);
1104*b843c749SSergey Zigachev break;
1105*b843c749SSergey Zigachev case DP_TEST_PATTERN_SYMBOL_ERROR:
1106*b843c749SSergey Zigachev set_dp_phy_pattern_symbol_error(enc10);
1107*b843c749SSergey Zigachev break;
1108*b843c749SSergey Zigachev case DP_TEST_PATTERN_PRBS7:
1109*b843c749SSergey Zigachev set_dp_phy_pattern_prbs7(enc10);
1110*b843c749SSergey Zigachev break;
1111*b843c749SSergey Zigachev case DP_TEST_PATTERN_80BIT_CUSTOM:
1112*b843c749SSergey Zigachev set_dp_phy_pattern_80bit_custom(
1113*b843c749SSergey Zigachev enc10, param->custom_pattern);
1114*b843c749SSergey Zigachev break;
1115*b843c749SSergey Zigachev case DP_TEST_PATTERN_CP2520_1:
1116*b843c749SSergey Zigachev set_dp_phy_pattern_hbr2_compliance_cp2520_2(enc10, 1);
1117*b843c749SSergey Zigachev break;
1118*b843c749SSergey Zigachev case DP_TEST_PATTERN_CP2520_2:
1119*b843c749SSergey Zigachev set_dp_phy_pattern_hbr2_compliance_cp2520_2(enc10, 2);
1120*b843c749SSergey Zigachev break;
1121*b843c749SSergey Zigachev case DP_TEST_PATTERN_CP2520_3:
1122*b843c749SSergey Zigachev set_dp_phy_pattern_hbr2_compliance_cp2520_2(enc10, 3);
1123*b843c749SSergey Zigachev break;
1124*b843c749SSergey Zigachev case DP_TEST_PATTERN_VIDEO_MODE: {
1125*b843c749SSergey Zigachev set_dp_phy_pattern_passthrough_mode(
1126*b843c749SSergey Zigachev enc10, param->dp_panel_mode);
1127*b843c749SSergey Zigachev break;
1128*b843c749SSergey Zigachev }
1129*b843c749SSergey Zigachev
1130*b843c749SSergey Zigachev default:
1131*b843c749SSergey Zigachev /* invalid phy pattern */
1132*b843c749SSergey Zigachev ASSERT_CRITICAL(false);
1133*b843c749SSergey Zigachev break;
1134*b843c749SSergey Zigachev }
1135*b843c749SSergey Zigachev }
1136*b843c749SSergey Zigachev
fill_stream_allocation_row_info(const struct link_mst_stream_allocation * stream_allocation,uint32_t * src,uint32_t * slots)1137*b843c749SSergey Zigachev static void fill_stream_allocation_row_info(
1138*b843c749SSergey Zigachev const struct link_mst_stream_allocation *stream_allocation,
1139*b843c749SSergey Zigachev uint32_t *src,
1140*b843c749SSergey Zigachev uint32_t *slots)
1141*b843c749SSergey Zigachev {
1142*b843c749SSergey Zigachev const struct stream_encoder *stream_enc = stream_allocation->stream_enc;
1143*b843c749SSergey Zigachev
1144*b843c749SSergey Zigachev if (stream_enc) {
1145*b843c749SSergey Zigachev *src = stream_enc->id;
1146*b843c749SSergey Zigachev *slots = stream_allocation->slot_count;
1147*b843c749SSergey Zigachev } else {
1148*b843c749SSergey Zigachev *src = 0;
1149*b843c749SSergey Zigachev *slots = 0;
1150*b843c749SSergey Zigachev }
1151*b843c749SSergey Zigachev }
1152*b843c749SSergey Zigachev
1153*b843c749SSergey Zigachev /* programs DP MST VC payload allocation */
dcn10_link_encoder_update_mst_stream_allocation_table(struct link_encoder * enc,const struct link_mst_stream_allocation_table * table)1154*b843c749SSergey Zigachev void dcn10_link_encoder_update_mst_stream_allocation_table(
1155*b843c749SSergey Zigachev struct link_encoder *enc,
1156*b843c749SSergey Zigachev const struct link_mst_stream_allocation_table *table)
1157*b843c749SSergey Zigachev {
1158*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1159*b843c749SSergey Zigachev uint32_t value0 = 0;
1160*b843c749SSergey Zigachev uint32_t value1 = 0;
1161*b843c749SSergey Zigachev uint32_t value2 = 0;
1162*b843c749SSergey Zigachev uint32_t slots = 0;
1163*b843c749SSergey Zigachev uint32_t src = 0;
1164*b843c749SSergey Zigachev uint32_t retries = 0;
1165*b843c749SSergey Zigachev
1166*b843c749SSergey Zigachev /* For CZ, there are only 3 pipes. So Virtual channel is up 3.*/
1167*b843c749SSergey Zigachev
1168*b843c749SSergey Zigachev /* --- Set MSE Stream Attribute -
1169*b843c749SSergey Zigachev * Setup VC Payload Table on Tx Side,
1170*b843c749SSergey Zigachev * Issue allocation change trigger
1171*b843c749SSergey Zigachev * to commit payload on both tx and rx side
1172*b843c749SSergey Zigachev */
1173*b843c749SSergey Zigachev
1174*b843c749SSergey Zigachev /* we should clean-up table each time */
1175*b843c749SSergey Zigachev
1176*b843c749SSergey Zigachev if (table->stream_count >= 1) {
1177*b843c749SSergey Zigachev fill_stream_allocation_row_info(
1178*b843c749SSergey Zigachev &table->stream_allocations[0],
1179*b843c749SSergey Zigachev &src,
1180*b843c749SSergey Zigachev &slots);
1181*b843c749SSergey Zigachev } else {
1182*b843c749SSergey Zigachev src = 0;
1183*b843c749SSergey Zigachev slots = 0;
1184*b843c749SSergey Zigachev }
1185*b843c749SSergey Zigachev
1186*b843c749SSergey Zigachev REG_UPDATE_2(DP_MSE_SAT0,
1187*b843c749SSergey Zigachev DP_MSE_SAT_SRC0, src,
1188*b843c749SSergey Zigachev DP_MSE_SAT_SLOT_COUNT0, slots);
1189*b843c749SSergey Zigachev
1190*b843c749SSergey Zigachev if (table->stream_count >= 2) {
1191*b843c749SSergey Zigachev fill_stream_allocation_row_info(
1192*b843c749SSergey Zigachev &table->stream_allocations[1],
1193*b843c749SSergey Zigachev &src,
1194*b843c749SSergey Zigachev &slots);
1195*b843c749SSergey Zigachev } else {
1196*b843c749SSergey Zigachev src = 0;
1197*b843c749SSergey Zigachev slots = 0;
1198*b843c749SSergey Zigachev }
1199*b843c749SSergey Zigachev
1200*b843c749SSergey Zigachev REG_UPDATE_2(DP_MSE_SAT0,
1201*b843c749SSergey Zigachev DP_MSE_SAT_SRC1, src,
1202*b843c749SSergey Zigachev DP_MSE_SAT_SLOT_COUNT1, slots);
1203*b843c749SSergey Zigachev
1204*b843c749SSergey Zigachev if (table->stream_count >= 3) {
1205*b843c749SSergey Zigachev fill_stream_allocation_row_info(
1206*b843c749SSergey Zigachev &table->stream_allocations[2],
1207*b843c749SSergey Zigachev &src,
1208*b843c749SSergey Zigachev &slots);
1209*b843c749SSergey Zigachev } else {
1210*b843c749SSergey Zigachev src = 0;
1211*b843c749SSergey Zigachev slots = 0;
1212*b843c749SSergey Zigachev }
1213*b843c749SSergey Zigachev
1214*b843c749SSergey Zigachev REG_UPDATE_2(DP_MSE_SAT1,
1215*b843c749SSergey Zigachev DP_MSE_SAT_SRC2, src,
1216*b843c749SSergey Zigachev DP_MSE_SAT_SLOT_COUNT2, slots);
1217*b843c749SSergey Zigachev
1218*b843c749SSergey Zigachev if (table->stream_count >= 4) {
1219*b843c749SSergey Zigachev fill_stream_allocation_row_info(
1220*b843c749SSergey Zigachev &table->stream_allocations[3],
1221*b843c749SSergey Zigachev &src,
1222*b843c749SSergey Zigachev &slots);
1223*b843c749SSergey Zigachev } else {
1224*b843c749SSergey Zigachev src = 0;
1225*b843c749SSergey Zigachev slots = 0;
1226*b843c749SSergey Zigachev }
1227*b843c749SSergey Zigachev
1228*b843c749SSergey Zigachev REG_UPDATE_2(DP_MSE_SAT1,
1229*b843c749SSergey Zigachev DP_MSE_SAT_SRC3, src,
1230*b843c749SSergey Zigachev DP_MSE_SAT_SLOT_COUNT3, slots);
1231*b843c749SSergey Zigachev
1232*b843c749SSergey Zigachev /* --- wait for transaction finish */
1233*b843c749SSergey Zigachev
1234*b843c749SSergey Zigachev /* send allocation change trigger (ACT) ?
1235*b843c749SSergey Zigachev * this step first sends the ACT,
1236*b843c749SSergey Zigachev * then double buffers the SAT into the hardware
1237*b843c749SSergey Zigachev * making the new allocation active on the DP MST mode link
1238*b843c749SSergey Zigachev */
1239*b843c749SSergey Zigachev
1240*b843c749SSergey Zigachev /* DP_MSE_SAT_UPDATE:
1241*b843c749SSergey Zigachev * 0 - No Action
1242*b843c749SSergey Zigachev * 1 - Update SAT with trigger
1243*b843c749SSergey Zigachev * 2 - Update SAT without trigger
1244*b843c749SSergey Zigachev */
1245*b843c749SSergey Zigachev REG_UPDATE(DP_MSE_SAT_UPDATE,
1246*b843c749SSergey Zigachev DP_MSE_SAT_UPDATE, 1);
1247*b843c749SSergey Zigachev
1248*b843c749SSergey Zigachev /* wait for update to complete
1249*b843c749SSergey Zigachev * (i.e. DP_MSE_SAT_UPDATE field is reset to 0)
1250*b843c749SSergey Zigachev * then wait for the transmission
1251*b843c749SSergey Zigachev * of at least 16 MTP headers on immediate local link.
1252*b843c749SSergey Zigachev * i.e. DP_MSE_16_MTP_KEEPOUT field (read only) is reset to 0
1253*b843c749SSergey Zigachev * a value of 1 indicates that DP MST mode
1254*b843c749SSergey Zigachev * is in the 16 MTP keepout region after a VC has been added.
1255*b843c749SSergey Zigachev * MST stream bandwidth (VC rate) can be configured
1256*b843c749SSergey Zigachev * after this bit is cleared
1257*b843c749SSergey Zigachev */
1258*b843c749SSergey Zigachev do {
1259*b843c749SSergey Zigachev udelay(10);
1260*b843c749SSergey Zigachev
1261*b843c749SSergey Zigachev value0 = REG_READ(DP_MSE_SAT_UPDATE);
1262*b843c749SSergey Zigachev
1263*b843c749SSergey Zigachev REG_GET(DP_MSE_SAT_UPDATE,
1264*b843c749SSergey Zigachev DP_MSE_SAT_UPDATE, &value1);
1265*b843c749SSergey Zigachev
1266*b843c749SSergey Zigachev REG_GET(DP_MSE_SAT_UPDATE,
1267*b843c749SSergey Zigachev DP_MSE_16_MTP_KEEPOUT, &value2);
1268*b843c749SSergey Zigachev
1269*b843c749SSergey Zigachev /* bit field DP_MSE_SAT_UPDATE is set to 1 already */
1270*b843c749SSergey Zigachev if (!value1 && !value2)
1271*b843c749SSergey Zigachev break;
1272*b843c749SSergey Zigachev ++retries;
1273*b843c749SSergey Zigachev } while (retries < DP_MST_UPDATE_MAX_RETRY);
1274*b843c749SSergey Zigachev }
1275*b843c749SSergey Zigachev
dcn10_link_encoder_connect_dig_be_to_fe(struct link_encoder * enc,enum engine_id engine,bool connect)1276*b843c749SSergey Zigachev void dcn10_link_encoder_connect_dig_be_to_fe(
1277*b843c749SSergey Zigachev struct link_encoder *enc,
1278*b843c749SSergey Zigachev enum engine_id engine,
1279*b843c749SSergey Zigachev bool connect)
1280*b843c749SSergey Zigachev {
1281*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1282*b843c749SSergey Zigachev uint32_t field;
1283*b843c749SSergey Zigachev
1284*b843c749SSergey Zigachev if (engine != ENGINE_ID_UNKNOWN) {
1285*b843c749SSergey Zigachev
1286*b843c749SSergey Zigachev REG_GET(DIG_BE_CNTL, DIG_FE_SOURCE_SELECT, &field);
1287*b843c749SSergey Zigachev
1288*b843c749SSergey Zigachev if (connect)
1289*b843c749SSergey Zigachev field |= get_frontend_source(engine);
1290*b843c749SSergey Zigachev else
1291*b843c749SSergey Zigachev field &= ~get_frontend_source(engine);
1292*b843c749SSergey Zigachev
1293*b843c749SSergey Zigachev REG_UPDATE(DIG_BE_CNTL, DIG_FE_SOURCE_SELECT, field);
1294*b843c749SSergey Zigachev }
1295*b843c749SSergey Zigachev }
1296*b843c749SSergey Zigachev
1297*b843c749SSergey Zigachev
1298*b843c749SSergey Zigachev #define HPD_REG(reg)\
1299*b843c749SSergey Zigachev (enc10->hpd_regs->reg)
1300*b843c749SSergey Zigachev
1301*b843c749SSergey Zigachev #define HPD_REG_READ(reg_name) \
1302*b843c749SSergey Zigachev dm_read_reg(CTX, HPD_REG(reg_name))
1303*b843c749SSergey Zigachev
1304*b843c749SSergey Zigachev #define HPD_REG_UPDATE_N(reg_name, n, ...) \
1305*b843c749SSergey Zigachev generic_reg_update_ex(CTX, \
1306*b843c749SSergey Zigachev HPD_REG(reg_name), \
1307*b843c749SSergey Zigachev HPD_REG_READ(reg_name), \
1308*b843c749SSergey Zigachev n, __VA_ARGS__)
1309*b843c749SSergey Zigachev
1310*b843c749SSergey Zigachev #define HPD_REG_UPDATE(reg_name, field, val) \
1311*b843c749SSergey Zigachev HPD_REG_UPDATE_N(reg_name, 1, \
1312*b843c749SSergey Zigachev FN(reg_name, field), val)
1313*b843c749SSergey Zigachev
dcn10_link_encoder_enable_hpd(struct link_encoder * enc)1314*b843c749SSergey Zigachev void dcn10_link_encoder_enable_hpd(struct link_encoder *enc)
1315*b843c749SSergey Zigachev {
1316*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1317*b843c749SSergey Zigachev
1318*b843c749SSergey Zigachev HPD_REG_UPDATE(DC_HPD_CONTROL,
1319*b843c749SSergey Zigachev DC_HPD_EN, 1);
1320*b843c749SSergey Zigachev }
1321*b843c749SSergey Zigachev
dcn10_link_encoder_disable_hpd(struct link_encoder * enc)1322*b843c749SSergey Zigachev void dcn10_link_encoder_disable_hpd(struct link_encoder *enc)
1323*b843c749SSergey Zigachev {
1324*b843c749SSergey Zigachev struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
1325*b843c749SSergey Zigachev
1326*b843c749SSergey Zigachev HPD_REG_UPDATE(DC_HPD_CONTROL,
1327*b843c749SSergey Zigachev DC_HPD_EN, 0);
1328*b843c749SSergey Zigachev }
1329*b843c749SSergey Zigachev
1330*b843c749SSergey Zigachev
1331*b843c749SSergey Zigachev #define AUX_REG(reg)\
1332*b843c749SSergey Zigachev (enc10->aux_regs->reg)
1333*b843c749SSergey Zigachev
1334*b843c749SSergey Zigachev #define AUX_REG_READ(reg_name) \
1335*b843c749SSergey Zigachev dm_read_reg(CTX, AUX_REG(reg_name))
1336*b843c749SSergey Zigachev
1337*b843c749SSergey Zigachev #define AUX_REG_UPDATE_N(reg_name, n, ...) \
1338*b843c749SSergey Zigachev generic_reg_update_ex(CTX, \
1339*b843c749SSergey Zigachev AUX_REG(reg_name), \
1340*b843c749SSergey Zigachev AUX_REG_READ(reg_name), \
1341*b843c749SSergey Zigachev n, __VA_ARGS__)
1342*b843c749SSergey Zigachev
1343*b843c749SSergey Zigachev #define AUX_REG_UPDATE(reg_name, field, val) \
1344*b843c749SSergey Zigachev AUX_REG_UPDATE_N(reg_name, 1, \
1345*b843c749SSergey Zigachev FN(reg_name, field), val)
1346*b843c749SSergey Zigachev
1347*b843c749SSergey Zigachev #define AUX_REG_UPDATE_2(reg, f1, v1, f2, v2) \
1348*b843c749SSergey Zigachev AUX_REG_UPDATE_N(reg, 2,\
1349*b843c749SSergey Zigachev FN(reg, f1), v1,\
1350*b843c749SSergey Zigachev FN(reg, f2), v2)
1351*b843c749SSergey Zigachev
dcn10_aux_initialize(struct dcn10_link_encoder * enc10)1352*b843c749SSergey Zigachev void dcn10_aux_initialize(struct dcn10_link_encoder *enc10)
1353*b843c749SSergey Zigachev {
1354*b843c749SSergey Zigachev enum hpd_source_id hpd_source = enc10->base.hpd_source;
1355*b843c749SSergey Zigachev
1356*b843c749SSergey Zigachev AUX_REG_UPDATE_2(AUX_CONTROL,
1357*b843c749SSergey Zigachev AUX_HPD_SEL, hpd_source,
1358*b843c749SSergey Zigachev AUX_LS_READ_EN, 0);
1359*b843c749SSergey Zigachev
1360*b843c749SSergey Zigachev /* 1/4 window (the maximum allowed) */
1361*b843c749SSergey Zigachev AUX_REG_UPDATE(AUX_DPHY_RX_CONTROL0,
1362*b843c749SSergey Zigachev AUX_RX_RECEIVE_WINDOW, 1);
1363*b843c749SSergey Zigachev }
1364