1ca4d9b3aSHarry Wentland /*
2ca4d9b3aSHarry Wentland * Copyright 2012-15 Advanced Micro Devices, Inc.
3ca4d9b3aSHarry Wentland *
4ca4d9b3aSHarry Wentland * Permission is hereby granted, free of charge, to any person obtaining a
5ca4d9b3aSHarry Wentland * copy of this software and associated documentation files (the "Software"),
6ca4d9b3aSHarry Wentland * to deal in the Software without restriction, including without limitation
7ca4d9b3aSHarry Wentland * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8ca4d9b3aSHarry Wentland * and/or sell copies of the Software, and to permit persons to whom the
9ca4d9b3aSHarry Wentland * Software is furnished to do so, subject to the following conditions:
10ca4d9b3aSHarry Wentland *
11ca4d9b3aSHarry Wentland * The above copyright notice and this permission notice shall be included in
12ca4d9b3aSHarry Wentland * all copies or substantial portions of the Software.
13ca4d9b3aSHarry Wentland *
14ca4d9b3aSHarry Wentland * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15ca4d9b3aSHarry Wentland * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16ca4d9b3aSHarry Wentland * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17ca4d9b3aSHarry Wentland * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18ca4d9b3aSHarry Wentland * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ca4d9b3aSHarry Wentland * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20ca4d9b3aSHarry Wentland * OTHER DEALINGS IN THE SOFTWARE.
21ca4d9b3aSHarry Wentland *
22ca4d9b3aSHarry Wentland * Authors: AMD
23ca4d9b3aSHarry Wentland *
24ca4d9b3aSHarry Wentland */
25ca4d9b3aSHarry Wentland
26ca4d9b3aSHarry Wentland #include "reg_helper.h"
27ca4d9b3aSHarry Wentland
28ca4d9b3aSHarry Wentland #include "core_types.h"
29ca4d9b3aSHarry Wentland #include "link_encoder.h"
30ca4d9b3aSHarry Wentland #include "dcn20_link_encoder.h"
31ca4d9b3aSHarry Wentland #include "stream_encoder.h"
32ca4d9b3aSHarry Wentland #include "dc_bios_types.h"
33ca4d9b3aSHarry Wentland
34ca4d9b3aSHarry Wentland #include "gpio_service_interface.h"
35ca4d9b3aSHarry Wentland
36ca4d9b3aSHarry Wentland #define CTX \
37ca4d9b3aSHarry Wentland enc10->base.ctx
38ca4d9b3aSHarry Wentland #define DC_LOGGER \
39ca4d9b3aSHarry Wentland enc10->base.ctx->logger
40ca4d9b3aSHarry Wentland
41ca4d9b3aSHarry Wentland #define REG(reg)\
42ca4d9b3aSHarry Wentland (enc10->link_regs->reg)
43ca4d9b3aSHarry Wentland
44ca4d9b3aSHarry Wentland #undef FN
45ca4d9b3aSHarry Wentland #define FN(reg_name, field_name) \
46ca4d9b3aSHarry Wentland enc10->link_shift->field_name, enc10->link_mask->field_name
47ca4d9b3aSHarry Wentland
48ca4d9b3aSHarry Wentland #define IND_REG(index) \
49ca4d9b3aSHarry Wentland (enc10->link_regs->index)
50ca4d9b3aSHarry Wentland
518ccf0e20SWenjing Liu #ifndef MAX
528ccf0e20SWenjing Liu #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
538ccf0e20SWenjing Liu #endif
548ccf0e20SWenjing Liu #ifndef MIN
558ccf0e20SWenjing Liu #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
568ccf0e20SWenjing Liu #endif
57ca4d9b3aSHarry Wentland
58ca4d9b3aSHarry Wentland static struct mpll_cfg dcn2_mpll_cfg[] = {
59ca4d9b3aSHarry Wentland // RBR
60ca4d9b3aSHarry Wentland {
61ca4d9b3aSHarry Wentland .hdmimode_enable = 1,
62ca4d9b3aSHarry Wentland .ref_range = 3,
63ca4d9b3aSHarry Wentland .ref_clk_mpllb_div = 2,
64ca4d9b3aSHarry Wentland .mpllb_ssc_en = 1,
65ca4d9b3aSHarry Wentland .mpllb_div5_clk_en = 1,
66ca4d9b3aSHarry Wentland .mpllb_multiplier = 226,
67ca4d9b3aSHarry Wentland .mpllb_fracn_en = 1,
68ca4d9b3aSHarry Wentland .mpllb_fracn_quot = 39321,
69ca4d9b3aSHarry Wentland .mpllb_fracn_rem = 3,
70ca4d9b3aSHarry Wentland .mpllb_fracn_den = 5,
71ca4d9b3aSHarry Wentland .mpllb_ssc_up_spread = 0,
72ca4d9b3aSHarry Wentland .mpllb_ssc_peak = 38221,
73ca4d9b3aSHarry Wentland .mpllb_ssc_stepsize = 49314,
74ca4d9b3aSHarry Wentland .mpllb_div_clk_en = 0,
75ca4d9b3aSHarry Wentland .mpllb_div_multiplier = 0,
76ca4d9b3aSHarry Wentland .mpllb_hdmi_div = 0,
77ca4d9b3aSHarry Wentland .mpllb_tx_clk_div = 2,
78ca4d9b3aSHarry Wentland .tx_vboost_lvl = 4,
79ca4d9b3aSHarry Wentland .mpllb_pmix_en = 1,
80ca4d9b3aSHarry Wentland .mpllb_word_div2_en = 0,
81ca4d9b3aSHarry Wentland .mpllb_ana_v2i = 2,
82ca4d9b3aSHarry Wentland .mpllb_ana_freq_vco = 2,
83ca4d9b3aSHarry Wentland .mpllb_ana_cp_int = 7,
84ca4d9b3aSHarry Wentland .mpllb_ana_cp_prop = 18,
85ca4d9b3aSHarry Wentland .hdmi_pixel_clk_div = 0,
86ca4d9b3aSHarry Wentland },
87ca4d9b3aSHarry Wentland // HBR
88ca4d9b3aSHarry Wentland {
89ca4d9b3aSHarry Wentland .hdmimode_enable = 1,
90ca4d9b3aSHarry Wentland .ref_range = 3,
91ca4d9b3aSHarry Wentland .ref_clk_mpllb_div = 2,
92ca4d9b3aSHarry Wentland .mpllb_ssc_en = 1,
93ca4d9b3aSHarry Wentland .mpllb_div5_clk_en = 1,
94ca4d9b3aSHarry Wentland .mpllb_multiplier = 184,
95ca4d9b3aSHarry Wentland .mpllb_fracn_en = 0,
96ca4d9b3aSHarry Wentland .mpllb_fracn_quot = 0,
97ca4d9b3aSHarry Wentland .mpllb_fracn_rem = 0,
98ca4d9b3aSHarry Wentland .mpllb_fracn_den = 1,
99ca4d9b3aSHarry Wentland .mpllb_ssc_up_spread = 0,
100ca4d9b3aSHarry Wentland .mpllb_ssc_peak = 31850,
101ca4d9b3aSHarry Wentland .mpllb_ssc_stepsize = 41095,
102ca4d9b3aSHarry Wentland .mpllb_div_clk_en = 0,
103ca4d9b3aSHarry Wentland .mpllb_div_multiplier = 0,
104ca4d9b3aSHarry Wentland .mpllb_hdmi_div = 0,
105ca4d9b3aSHarry Wentland .mpllb_tx_clk_div = 1,
106ca4d9b3aSHarry Wentland .tx_vboost_lvl = 4,
107ca4d9b3aSHarry Wentland .mpllb_pmix_en = 1,
108ca4d9b3aSHarry Wentland .mpllb_word_div2_en = 0,
109ca4d9b3aSHarry Wentland .mpllb_ana_v2i = 2,
110ca4d9b3aSHarry Wentland .mpllb_ana_freq_vco = 3,
111ca4d9b3aSHarry Wentland .mpllb_ana_cp_int = 7,
112ca4d9b3aSHarry Wentland .mpllb_ana_cp_prop = 18,
113ca4d9b3aSHarry Wentland .hdmi_pixel_clk_div = 0,
114ca4d9b3aSHarry Wentland },
115ca4d9b3aSHarry Wentland //HBR2
116ca4d9b3aSHarry Wentland {
117ca4d9b3aSHarry Wentland .hdmimode_enable = 1,
118ca4d9b3aSHarry Wentland .ref_range = 3,
119ca4d9b3aSHarry Wentland .ref_clk_mpllb_div = 2,
120ca4d9b3aSHarry Wentland .mpllb_ssc_en = 1,
121ca4d9b3aSHarry Wentland .mpllb_div5_clk_en = 1,
122ca4d9b3aSHarry Wentland .mpllb_multiplier = 184,
123ca4d9b3aSHarry Wentland .mpllb_fracn_en = 0,
124ca4d9b3aSHarry Wentland .mpllb_fracn_quot = 0,
125ca4d9b3aSHarry Wentland .mpllb_fracn_rem = 0,
126ca4d9b3aSHarry Wentland .mpllb_fracn_den = 1,
127ca4d9b3aSHarry Wentland .mpllb_ssc_up_spread = 0,
128ca4d9b3aSHarry Wentland .mpllb_ssc_peak = 31850,
129ca4d9b3aSHarry Wentland .mpllb_ssc_stepsize = 41095,
130ca4d9b3aSHarry Wentland .mpllb_div_clk_en = 0,
131ca4d9b3aSHarry Wentland .mpllb_div_multiplier = 0,
132ca4d9b3aSHarry Wentland .mpllb_hdmi_div = 0,
133ca4d9b3aSHarry Wentland .mpllb_tx_clk_div = 0,
134ca4d9b3aSHarry Wentland .tx_vboost_lvl = 4,
135ca4d9b3aSHarry Wentland .mpllb_pmix_en = 1,
136ca4d9b3aSHarry Wentland .mpllb_word_div2_en = 0,
137ca4d9b3aSHarry Wentland .mpllb_ana_v2i = 2,
138ca4d9b3aSHarry Wentland .mpllb_ana_freq_vco = 3,
139ca4d9b3aSHarry Wentland .mpllb_ana_cp_int = 7,
140ca4d9b3aSHarry Wentland .mpllb_ana_cp_prop = 18,
141ca4d9b3aSHarry Wentland .hdmi_pixel_clk_div = 0,
142ca4d9b3aSHarry Wentland },
143ca4d9b3aSHarry Wentland //HBR3
144ca4d9b3aSHarry Wentland {
145ca4d9b3aSHarry Wentland .hdmimode_enable = 1,
146ca4d9b3aSHarry Wentland .ref_range = 3,
147ca4d9b3aSHarry Wentland .ref_clk_mpllb_div = 2,
148ca4d9b3aSHarry Wentland .mpllb_ssc_en = 1,
149ca4d9b3aSHarry Wentland .mpllb_div5_clk_en = 1,
150ca4d9b3aSHarry Wentland .mpllb_multiplier = 292,
151ca4d9b3aSHarry Wentland .mpllb_fracn_en = 0,
152ca4d9b3aSHarry Wentland .mpllb_fracn_quot = 0,
153ca4d9b3aSHarry Wentland .mpllb_fracn_rem = 0,
154ca4d9b3aSHarry Wentland .mpllb_fracn_den = 1,
155ca4d9b3aSHarry Wentland .mpllb_ssc_up_spread = 0,
156ca4d9b3aSHarry Wentland .mpllb_ssc_peak = 47776,
157ca4d9b3aSHarry Wentland .mpllb_ssc_stepsize = 61642,
158ca4d9b3aSHarry Wentland .mpllb_div_clk_en = 0,
159ca4d9b3aSHarry Wentland .mpllb_div_multiplier = 0,
160ca4d9b3aSHarry Wentland .mpllb_hdmi_div = 0,
161ca4d9b3aSHarry Wentland .mpllb_tx_clk_div = 0,
162ca4d9b3aSHarry Wentland .tx_vboost_lvl = 4,
163ca4d9b3aSHarry Wentland .mpllb_pmix_en = 1,
164ca4d9b3aSHarry Wentland .mpllb_word_div2_en = 0,
165ca4d9b3aSHarry Wentland .mpllb_ana_v2i = 2,
166ca4d9b3aSHarry Wentland .mpllb_ana_freq_vco = 0,
167ca4d9b3aSHarry Wentland .mpllb_ana_cp_int = 7,
168ca4d9b3aSHarry Wentland .mpllb_ana_cp_prop = 18,
169ca4d9b3aSHarry Wentland .hdmi_pixel_clk_div = 0,
170ca4d9b3aSHarry Wentland },
171ca4d9b3aSHarry Wentland };
172ca4d9b3aSHarry Wentland
enc2_fec_set_enable(struct link_encoder * enc,bool enable)173ca4d9b3aSHarry Wentland void enc2_fec_set_enable(struct link_encoder *enc, bool enable)
174ca4d9b3aSHarry Wentland {
175ca4d9b3aSHarry Wentland struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
17697bda032SHarry Wentland DC_LOG_DSC("%s FEC at link encoder inst %d",
17797bda032SHarry Wentland enable ? "Enabling" : "Disabling", enc->id.enum_id);
178ca4d9b3aSHarry Wentland REG_UPDATE(DP_DPHY_CNTL, DPHY_FEC_EN, enable);
179ca4d9b3aSHarry Wentland }
180ca4d9b3aSHarry Wentland
enc2_fec_set_ready(struct link_encoder * enc,bool ready)181ca4d9b3aSHarry Wentland void enc2_fec_set_ready(struct link_encoder *enc, bool ready)
182ca4d9b3aSHarry Wentland {
183ca4d9b3aSHarry Wentland struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
184ca4d9b3aSHarry Wentland
185ca4d9b3aSHarry Wentland REG_UPDATE(DP_DPHY_CNTL, DPHY_FEC_READY_SHADOW, ready);
186ca4d9b3aSHarry Wentland }
187ca4d9b3aSHarry Wentland
enc2_fec_is_active(struct link_encoder * enc)188ca4d9b3aSHarry Wentland bool enc2_fec_is_active(struct link_encoder *enc)
189ca4d9b3aSHarry Wentland {
190ca4d9b3aSHarry Wentland uint32_t active = 0;
191ca4d9b3aSHarry Wentland struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
192ca4d9b3aSHarry Wentland
193ca4d9b3aSHarry Wentland REG_GET(DP_DPHY_CNTL, DPHY_FEC_ACTIVE_STATUS, &active);
194ca4d9b3aSHarry Wentland
195ca4d9b3aSHarry Wentland return (active != 0);
196ca4d9b3aSHarry Wentland }
197ca4d9b3aSHarry Wentland
19897bda032SHarry Wentland /* this function reads dsc related register fields to be logged later in dcn10_log_hw_state
19997bda032SHarry Wentland * into a dcn_dsc_state struct.
20097bda032SHarry Wentland */
link_enc2_read_state(struct link_encoder * enc,struct link_enc_state * s)20197bda032SHarry Wentland void link_enc2_read_state(struct link_encoder *enc, struct link_enc_state *s)
20297bda032SHarry Wentland {
20397bda032SHarry Wentland struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
20497bda032SHarry Wentland
20597bda032SHarry Wentland REG_GET(DP_DPHY_CNTL, DPHY_FEC_EN, &s->dphy_fec_en);
20697bda032SHarry Wentland REG_GET(DP_DPHY_CNTL, DPHY_FEC_READY_SHADOW, &s->dphy_fec_ready_shadow);
20797bda032SHarry Wentland REG_GET(DP_DPHY_CNTL, DPHY_FEC_ACTIVE_STATUS, &s->dphy_fec_active_status);
208ae8cf977SLeo (Hanghong) Ma REG_GET(DP_LINK_CNTL, DP_LINK_TRAINING_COMPLETE, &s->dp_link_training_complete);
20997bda032SHarry Wentland }
210ca4d9b3aSHarry Wentland
update_cfg_data(struct dcn10_link_encoder * enc10,const struct dc_link_settings * link_settings,struct dpcssys_phy_seq_cfg * cfg)211ca4d9b3aSHarry Wentland static bool update_cfg_data(
212ca4d9b3aSHarry Wentland struct dcn10_link_encoder *enc10,
213ca4d9b3aSHarry Wentland const struct dc_link_settings *link_settings,
214ca4d9b3aSHarry Wentland struct dpcssys_phy_seq_cfg *cfg)
215ca4d9b3aSHarry Wentland {
216ca4d9b3aSHarry Wentland int i;
217ca4d9b3aSHarry Wentland
218ca4d9b3aSHarry Wentland cfg->load_sram_fw = false;
219ca4d9b3aSHarry Wentland
220ca4d9b3aSHarry Wentland for (i = 0; i < link_settings->lane_count; i++)
221ca4d9b3aSHarry Wentland cfg->lane_en[i] = true;
222ca4d9b3aSHarry Wentland
223ca4d9b3aSHarry Wentland switch (link_settings->link_rate) {
224ca4d9b3aSHarry Wentland case LINK_RATE_LOW:
225ca4d9b3aSHarry Wentland cfg->mpll_cfg = dcn2_mpll_cfg[0];
226ca4d9b3aSHarry Wentland break;
227ca4d9b3aSHarry Wentland case LINK_RATE_HIGH:
228ca4d9b3aSHarry Wentland cfg->mpll_cfg = dcn2_mpll_cfg[1];
229ca4d9b3aSHarry Wentland break;
230ca4d9b3aSHarry Wentland case LINK_RATE_HIGH2:
231ca4d9b3aSHarry Wentland cfg->mpll_cfg = dcn2_mpll_cfg[2];
232ca4d9b3aSHarry Wentland break;
233ca4d9b3aSHarry Wentland case LINK_RATE_HIGH3:
234ca4d9b3aSHarry Wentland cfg->mpll_cfg = dcn2_mpll_cfg[3];
235ca4d9b3aSHarry Wentland break;
236ca4d9b3aSHarry Wentland default:
237ca4d9b3aSHarry Wentland DC_LOG_ERROR("%s: No supported link rate found %X!\n",
238ca4d9b3aSHarry Wentland __func__, link_settings->link_rate);
239ca4d9b3aSHarry Wentland return false;
240ca4d9b3aSHarry Wentland }
241ca4d9b3aSHarry Wentland
242ca4d9b3aSHarry Wentland return true;
243ca4d9b3aSHarry Wentland }
244ca4d9b3aSHarry Wentland
dcn20_link_encoder_enable_dp_output(struct link_encoder * enc,const struct dc_link_settings * link_settings,enum clock_source_id clock_source)245c5509aadSEric Bernstein void dcn20_link_encoder_enable_dp_output(
246ca4d9b3aSHarry Wentland struct link_encoder *enc,
247ca4d9b3aSHarry Wentland const struct dc_link_settings *link_settings,
248ca4d9b3aSHarry Wentland enum clock_source_id clock_source)
249ca4d9b3aSHarry Wentland {
250ca4d9b3aSHarry Wentland struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
251ca4d9b3aSHarry Wentland struct dcn20_link_encoder *enc20 = (struct dcn20_link_encoder *) enc10;
252ca4d9b3aSHarry Wentland struct dpcssys_phy_seq_cfg *cfg = &enc20->phy_seq_cfg;
253ca4d9b3aSHarry Wentland
254ca4d9b3aSHarry Wentland if (!enc->ctx->dc->debug.avoid_vbios_exec_table) {
255ca4d9b3aSHarry Wentland dcn10_link_encoder_enable_dp_output(enc, link_settings, clock_source);
256ca4d9b3aSHarry Wentland return;
257ca4d9b3aSHarry Wentland }
258ca4d9b3aSHarry Wentland
259ca4d9b3aSHarry Wentland if (!update_cfg_data(enc10, link_settings, cfg))
260ca4d9b3aSHarry Wentland return;
261ca4d9b3aSHarry Wentland
262ca4d9b3aSHarry Wentland enc1_configure_encoder(enc10, link_settings);
263ca4d9b3aSHarry Wentland
264ca4d9b3aSHarry Wentland dcn10_link_encoder_setup(enc, SIGNAL_TYPE_DISPLAY_PORT);
265ca4d9b3aSHarry Wentland
266ca4d9b3aSHarry Wentland }
267ca4d9b3aSHarry Wentland
dcn20_link_encoder_get_max_link_cap(struct link_encoder * enc,struct dc_link_settings * link_settings)2688ccf0e20SWenjing Liu void dcn20_link_encoder_get_max_link_cap(struct link_encoder *enc,
2698ccf0e20SWenjing Liu struct dc_link_settings *link_settings)
2708ccf0e20SWenjing Liu {
2718ccf0e20SWenjing Liu struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
2728ccf0e20SWenjing Liu uint32_t is_in_usb_c_dp4_mode = 0;
2738ccf0e20SWenjing Liu
2748ccf0e20SWenjing Liu dcn10_link_encoder_get_max_link_cap(enc, link_settings);
2758ccf0e20SWenjing Liu
2768ccf0e20SWenjing Liu /* in usb c dp2 mode, max lane count is 2 */
2778ccf0e20SWenjing Liu if (enc->funcs->is_in_alt_mode && enc->funcs->is_in_alt_mode(enc)) {
2788ccf0e20SWenjing Liu REG_GET(RDPCSTX_PHY_CNTL6, RDPCS_PHY_DPALT_DP4, &is_in_usb_c_dp4_mode);
2798ccf0e20SWenjing Liu if (!is_in_usb_c_dp4_mode)
2808ccf0e20SWenjing Liu link_settings->lane_count = MIN(LANE_COUNT_TWO, link_settings->lane_count);
2818ccf0e20SWenjing Liu }
2828ccf0e20SWenjing Liu
2838ccf0e20SWenjing Liu }
2848ccf0e20SWenjing Liu
dcn20_link_encoder_is_in_alt_mode(struct link_encoder * enc)2858ccf0e20SWenjing Liu bool dcn20_link_encoder_is_in_alt_mode(struct link_encoder *enc)
2868ccf0e20SWenjing Liu {
2878ccf0e20SWenjing Liu struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
2888ccf0e20SWenjing Liu uint32_t dp_alt_mode_disable = 0;
2898ccf0e20SWenjing Liu bool is_usb_c_alt_mode = false;
2908ccf0e20SWenjing Liu
2918ccf0e20SWenjing Liu if (enc->features.flags.bits.DP_IS_USB_C) {
2928ccf0e20SWenjing Liu /* if value == 1 alt mode is disabled, otherwise it is enabled */
2938ccf0e20SWenjing Liu REG_GET(RDPCSTX_PHY_CNTL6, RDPCS_PHY_DPALT_DISABLE, &dp_alt_mode_disable);
2948ccf0e20SWenjing Liu is_usb_c_alt_mode = (dp_alt_mode_disable == 0);
2958ccf0e20SWenjing Liu }
2968ccf0e20SWenjing Liu
2978ccf0e20SWenjing Liu return is_usb_c_alt_mode;
2988ccf0e20SWenjing Liu }
2998ccf0e20SWenjing Liu
300ca4d9b3aSHarry Wentland #define AUX_REG(reg)\
301ca4d9b3aSHarry Wentland (enc10->aux_regs->reg)
302ca4d9b3aSHarry Wentland
303ca4d9b3aSHarry Wentland #define AUX_REG_READ(reg_name) \
304ca4d9b3aSHarry Wentland dm_read_reg(CTX, AUX_REG(reg_name))
305ca4d9b3aSHarry Wentland
306ca4d9b3aSHarry Wentland #define AUX_REG_WRITE(reg_name, val) \
307ca4d9b3aSHarry Wentland dm_write_reg(CTX, AUX_REG(reg_name), val)
enc2_hw_init(struct link_encoder * enc)308ca4d9b3aSHarry Wentland void enc2_hw_init(struct link_encoder *enc)
309ca4d9b3aSHarry Wentland {
310ca4d9b3aSHarry Wentland struct dcn10_link_encoder *enc10 = TO_DCN10_LINK_ENC(enc);
311ca4d9b3aSHarry Wentland /*
312ca4d9b3aSHarry Wentland 00 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__1to2 : 1/2
313ca4d9b3aSHarry Wentland 01 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__3to4 : 3/4
314ca4d9b3aSHarry Wentland 02 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__7to8 : 7/8
315ca4d9b3aSHarry Wentland 03 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__15to16 : 15/16
316ca4d9b3aSHarry Wentland 04 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__31to32 : 31/32
317ca4d9b3aSHarry Wentland 05 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__63to64 : 63/64
318ca4d9b3aSHarry Wentland 06 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__127to128 : 127/128
319ca4d9b3aSHarry Wentland 07 - DP_AUX_DPHY_RX_DETECTION_THRESHOLD__255to256 : 255/256
320ca4d9b3aSHarry Wentland */
321ca4d9b3aSHarry Wentland
322ca4d9b3aSHarry Wentland /*
323ca4d9b3aSHarry Wentland AUX_REG_UPDATE_5(AUX_DPHY_RX_CONTROL0,
324ca4d9b3aSHarry Wentland AUX_RX_START_WINDOW = 1 [6:4]
325ca4d9b3aSHarry Wentland AUX_RX_RECEIVE_WINDOW = 1 default is 2 [10:8]
326ca4d9b3aSHarry Wentland AUX_RX_HALF_SYM_DETECT_LEN = 1 [13:12] default is 1
327ca4d9b3aSHarry Wentland AUX_RX_TRANSITION_FILTER_EN = 1 [16] default is 1
328ca4d9b3aSHarry Wentland AUX_RX_ALLOW_BELOW_THRESHOLD_PHASE_DETECT [17] is 0 default is 0
329ca4d9b3aSHarry Wentland AUX_RX_ALLOW_BELOW_THRESHOLD_START [18] is 1 default is 1
330ca4d9b3aSHarry Wentland AUX_RX_ALLOW_BELOW_THRESHOLD_STOP [19] is 1 default is 1
331ca4d9b3aSHarry Wentland AUX_RX_PHASE_DETECT_LEN, [21,20] = 0x3 default is 3
332ca4d9b3aSHarry Wentland AUX_RX_DETECTION_THRESHOLD [30:28] = 1
333ca4d9b3aSHarry Wentland */
33409821499SIgor Kravchenko if (enc->ctx->dc_bios->golden_table.dc_golden_table_ver > 0) {
33509821499SIgor Kravchenko AUX_REG_WRITE(AUX_DPHY_RX_CONTROL0, enc->ctx->dc_bios->golden_table.aux_dphy_rx_control0_val);
33609821499SIgor Kravchenko
33709821499SIgor Kravchenko AUX_REG_WRITE(AUX_DPHY_TX_CONTROL, enc->ctx->dc_bios->golden_table.aux_dphy_tx_control_val);
33809821499SIgor Kravchenko
33909821499SIgor Kravchenko AUX_REG_WRITE(AUX_DPHY_RX_CONTROL1, enc->ctx->dc_bios->golden_table.aux_dphy_rx_control1_val);
34009821499SIgor Kravchenko } else {
341ca4d9b3aSHarry Wentland AUX_REG_WRITE(AUX_DPHY_RX_CONTROL0, 0x103d1110);
342ca4d9b3aSHarry Wentland
343*5c458585SAlex Deucher AUX_REG_WRITE(AUX_DPHY_TX_CONTROL, 0x21c7a);
34409821499SIgor Kravchenko }
345ca4d9b3aSHarry Wentland
346ca4d9b3aSHarry Wentland //AUX_DPHY_TX_REF_CONTROL'AUX_TX_REF_DIV HW default is 0x32;
347ca4d9b3aSHarry Wentland // Set AUX_TX_REF_DIV Divider to generate 2 MHz reference from refclk
348ca4d9b3aSHarry Wentland // 27MHz -> 0xd
349ca4d9b3aSHarry Wentland // 100MHz -> 0x32
350ca4d9b3aSHarry Wentland // 48MHz -> 0x18
351ca4d9b3aSHarry Wentland
352ca4d9b3aSHarry Wentland // Set TMDS_CTL0 to 1. This is a legacy setting.
353ca4d9b3aSHarry Wentland REG_UPDATE(TMDS_CTL_BITS, TMDS_CTL0, 1);
354ca4d9b3aSHarry Wentland
355ca4d9b3aSHarry Wentland dcn10_aux_initialize(enc10);
356ca4d9b3aSHarry Wentland }
357ca4d9b3aSHarry Wentland
358ca4d9b3aSHarry Wentland static const struct link_encoder_funcs dcn20_link_enc_funcs = {
35997bda032SHarry Wentland .read_state = link_enc2_read_state,
360ca4d9b3aSHarry Wentland .validate_output_with_stream =
361ca4d9b3aSHarry Wentland dcn10_link_encoder_validate_output_with_stream,
362ca4d9b3aSHarry Wentland .hw_init = enc2_hw_init,
363ca4d9b3aSHarry Wentland .setup = dcn10_link_encoder_setup,
364166590ccSDerek Lai .enable_tmds_output = dcn10_link_encoder_enable_tmds_output_with_clk_pattern_wa,
365ca4d9b3aSHarry Wentland .enable_dp_output = dcn20_link_encoder_enable_dp_output,
366ca4d9b3aSHarry Wentland .enable_dp_mst_output = dcn10_link_encoder_enable_dp_mst_output,
367ca4d9b3aSHarry Wentland .disable_output = dcn10_link_encoder_disable_output,
368ca4d9b3aSHarry Wentland .dp_set_lane_settings = dcn10_link_encoder_dp_set_lane_settings,
369ca4d9b3aSHarry Wentland .dp_set_phy_pattern = dcn10_link_encoder_dp_set_phy_pattern,
370ca4d9b3aSHarry Wentland .update_mst_stream_allocation_table =
371ca4d9b3aSHarry Wentland dcn10_link_encoder_update_mst_stream_allocation_table,
372ca4d9b3aSHarry Wentland .psr_program_dp_dphy_fast_training =
373ca4d9b3aSHarry Wentland dcn10_psr_program_dp_dphy_fast_training,
374ca4d9b3aSHarry Wentland .psr_program_secondary_packet = dcn10_psr_program_secondary_packet,
375ca4d9b3aSHarry Wentland .connect_dig_be_to_fe = dcn10_link_encoder_connect_dig_be_to_fe,
376ca4d9b3aSHarry Wentland .enable_hpd = dcn10_link_encoder_enable_hpd,
377ca4d9b3aSHarry Wentland .disable_hpd = dcn10_link_encoder_disable_hpd,
378ca4d9b3aSHarry Wentland .is_dig_enabled = dcn10_is_dig_enabled,
379ca4d9b3aSHarry Wentland .destroy = dcn10_link_encoder_destroy,
380ca4d9b3aSHarry Wentland .fec_set_enable = enc2_fec_set_enable,
381ca4d9b3aSHarry Wentland .fec_set_ready = enc2_fec_set_ready,
382ca4d9b3aSHarry Wentland .fec_is_active = enc2_fec_is_active,
38378d9b95eSCharlene Liu .get_dig_mode = dcn10_get_dig_mode,
384ca4d9b3aSHarry Wentland .get_dig_frontend = dcn10_get_dig_frontend,
385c7f345e5SCharlene Liu .is_in_alt_mode = dcn20_link_encoder_is_in_alt_mode,
386c7f345e5SCharlene Liu .get_max_link_cap = dcn20_link_encoder_get_max_link_cap,
387ca4d9b3aSHarry Wentland };
388ca4d9b3aSHarry Wentland
dcn20_link_encoder_construct(struct dcn20_link_encoder * enc20,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)389ca4d9b3aSHarry Wentland void dcn20_link_encoder_construct(
390ca4d9b3aSHarry Wentland struct dcn20_link_encoder *enc20,
391ca4d9b3aSHarry Wentland const struct encoder_init_data *init_data,
392ca4d9b3aSHarry Wentland const struct encoder_feature_support *enc_features,
393ca4d9b3aSHarry Wentland const struct dcn10_link_enc_registers *link_regs,
394ca4d9b3aSHarry Wentland const struct dcn10_link_enc_aux_registers *aux_regs,
395ca4d9b3aSHarry Wentland const struct dcn10_link_enc_hpd_registers *hpd_regs,
396ca4d9b3aSHarry Wentland const struct dcn10_link_enc_shift *link_shift,
397ca4d9b3aSHarry Wentland const struct dcn10_link_enc_mask *link_mask)
398ca4d9b3aSHarry Wentland {
399ca4d9b3aSHarry Wentland struct bp_encoder_cap_info bp_cap_info = {0};
400ca4d9b3aSHarry Wentland const struct dc_vbios_funcs *bp_funcs = init_data->ctx->dc_bios->funcs;
401ca4d9b3aSHarry Wentland enum bp_result result = BP_RESULT_OK;
402ca4d9b3aSHarry Wentland struct dcn10_link_encoder *enc10 = &enc20->enc10;
403ca4d9b3aSHarry Wentland
404ca4d9b3aSHarry Wentland enc10->base.funcs = &dcn20_link_enc_funcs;
405ca4d9b3aSHarry Wentland enc10->base.ctx = init_data->ctx;
406ca4d9b3aSHarry Wentland enc10->base.id = init_data->encoder;
407ca4d9b3aSHarry Wentland
408ca4d9b3aSHarry Wentland enc10->base.hpd_source = init_data->hpd_source;
409ca4d9b3aSHarry Wentland enc10->base.connector = init_data->connector;
410ca4d9b3aSHarry Wentland
411ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
412ca4d9b3aSHarry Wentland
413ca4d9b3aSHarry Wentland enc10->base.features = *enc_features;
414ca4d9b3aSHarry Wentland
415ca4d9b3aSHarry Wentland enc10->base.transmitter = init_data->transmitter;
416ca4d9b3aSHarry Wentland
417ca4d9b3aSHarry Wentland /* set the flag to indicate whether driver poll the I2C data pin
418ca4d9b3aSHarry Wentland * while doing the DP sink detect
419ca4d9b3aSHarry Wentland */
420ca4d9b3aSHarry Wentland
421ca4d9b3aSHarry Wentland /* if (dal_adapter_service_is_feature_supported(as,
422ca4d9b3aSHarry Wentland FEATURE_DP_SINK_DETECT_POLL_DATA_PIN))
423ca4d9b3aSHarry Wentland enc10->base.features.flags.bits.
424ca4d9b3aSHarry Wentland DP_SINK_DETECT_POLL_DATA_PIN = true;*/
425ca4d9b3aSHarry Wentland
426ca4d9b3aSHarry Wentland enc10->base.output_signals =
427ca4d9b3aSHarry Wentland SIGNAL_TYPE_DVI_SINGLE_LINK |
428ca4d9b3aSHarry Wentland SIGNAL_TYPE_DVI_DUAL_LINK |
429ca4d9b3aSHarry Wentland SIGNAL_TYPE_LVDS |
430ca4d9b3aSHarry Wentland SIGNAL_TYPE_DISPLAY_PORT |
431ca4d9b3aSHarry Wentland SIGNAL_TYPE_DISPLAY_PORT_MST |
432ca4d9b3aSHarry Wentland SIGNAL_TYPE_EDP |
433ca4d9b3aSHarry Wentland SIGNAL_TYPE_HDMI_TYPE_A;
434ca4d9b3aSHarry Wentland
435ca4d9b3aSHarry Wentland /* For DCE 8.0 and 8.1, by design, UNIPHY is hardwired to DIG_BE.
436ca4d9b3aSHarry Wentland * SW always assign DIG_FE 1:1 mapped to DIG_FE for non-MST UNIPHY.
437ca4d9b3aSHarry Wentland * SW assign DIG_FE to non-MST UNIPHY first and MST last. So prefer
438ca4d9b3aSHarry Wentland * DIG is per UNIPHY and used by SST DP, eDP, HDMI, DVI and LVDS.
439ca4d9b3aSHarry Wentland * Prefer DIG assignment is decided by board design.
440ca4d9b3aSHarry Wentland * For DCE 8.0, there are only max 6 UNIPHYs, we assume board design
441ca4d9b3aSHarry Wentland * and VBIOS will filter out 7 UNIPHY for DCE 8.0.
442ca4d9b3aSHarry Wentland * By this, adding DIGG should not hurt DCE 8.0.
443ca4d9b3aSHarry Wentland * This will let DCE 8.1 share DCE 8.0 as much as possible
444ca4d9b3aSHarry Wentland */
445ca4d9b3aSHarry Wentland
446ca4d9b3aSHarry Wentland enc10->link_regs = link_regs;
447ca4d9b3aSHarry Wentland enc10->aux_regs = aux_regs;
448ca4d9b3aSHarry Wentland enc10->hpd_regs = hpd_regs;
449ca4d9b3aSHarry Wentland enc10->link_shift = link_shift;
450ca4d9b3aSHarry Wentland enc10->link_mask = link_mask;
451ca4d9b3aSHarry Wentland
452ca4d9b3aSHarry Wentland switch (enc10->base.transmitter) {
453ca4d9b3aSHarry Wentland case TRANSMITTER_UNIPHY_A:
454ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_DIGA;
455ca4d9b3aSHarry Wentland break;
456ca4d9b3aSHarry Wentland case TRANSMITTER_UNIPHY_B:
457ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_DIGB;
458ca4d9b3aSHarry Wentland break;
459ca4d9b3aSHarry Wentland case TRANSMITTER_UNIPHY_C:
460ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_DIGC;
461ca4d9b3aSHarry Wentland break;
462ca4d9b3aSHarry Wentland case TRANSMITTER_UNIPHY_D:
463ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_DIGD;
464ca4d9b3aSHarry Wentland break;
465ca4d9b3aSHarry Wentland case TRANSMITTER_UNIPHY_E:
466ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_DIGE;
467ca4d9b3aSHarry Wentland break;
468ca4d9b3aSHarry Wentland case TRANSMITTER_UNIPHY_F:
469ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_DIGF;
470ca4d9b3aSHarry Wentland break;
471ca4d9b3aSHarry Wentland case TRANSMITTER_UNIPHY_G:
472ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_DIGG;
473ca4d9b3aSHarry Wentland break;
474ca4d9b3aSHarry Wentland default:
475ca4d9b3aSHarry Wentland ASSERT_CRITICAL(false);
476ca4d9b3aSHarry Wentland enc10->base.preferred_engine = ENGINE_ID_UNKNOWN;
477ca4d9b3aSHarry Wentland }
478ca4d9b3aSHarry Wentland
479ca4d9b3aSHarry Wentland /* default to one to mirror Windows behavior */
480ca4d9b3aSHarry Wentland enc10->base.features.flags.bits.HDMI_6GB_EN = 1;
481ca4d9b3aSHarry Wentland
482ca4d9b3aSHarry Wentland result = bp_funcs->get_encoder_cap_info(enc10->base.ctx->dc_bios,
483ca4d9b3aSHarry Wentland enc10->base.id, &bp_cap_info);
484ca4d9b3aSHarry Wentland
485ca4d9b3aSHarry Wentland /* Override features with DCE-specific values */
486ca4d9b3aSHarry Wentland if (result == BP_RESULT_OK) {
487ca4d9b3aSHarry Wentland enc10->base.features.flags.bits.IS_HBR2_CAPABLE =
488ca4d9b3aSHarry Wentland bp_cap_info.DP_HBR2_EN;
489ca4d9b3aSHarry Wentland enc10->base.features.flags.bits.IS_HBR3_CAPABLE =
490ca4d9b3aSHarry Wentland bp_cap_info.DP_HBR3_EN;
491ca4d9b3aSHarry Wentland enc10->base.features.flags.bits.HDMI_6GB_EN = bp_cap_info.HDMI_6GB_EN;
492796c9eceSSamson Tam enc10->base.features.flags.bits.DP_IS_USB_C =
493796c9eceSSamson Tam bp_cap_info.DP_IS_USB_C;
494ca4d9b3aSHarry Wentland } else {
495ca4d9b3aSHarry Wentland DC_LOG_WARNING("%s: Failed to get encoder_cap_info from VBIOS with error code %d!\n",
496ca4d9b3aSHarry Wentland __func__,
497ca4d9b3aSHarry Wentland result);
498ca4d9b3aSHarry Wentland }
499ca4d9b3aSHarry Wentland if (enc10->base.ctx->dc->debug.hdmi20_disable) {
500ca4d9b3aSHarry Wentland enc10->base.features.flags.bits.HDMI_6GB_EN = 0;
501ca4d9b3aSHarry Wentland }
502ca4d9b3aSHarry Wentland }
503