blob: 63b76eac018fab0e78ffba566d633ee84a1e35fe [file] [log] [blame]
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +03001/*
2 * Copyright © 2014-2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#include "intel_drv.h"
25
Ander Conselvan de Oliveiraf38861b2016-10-06 19:22:18 +030026/**
27 * DOC: DPIO
28 *
29 * VLV, CHV and BXT have slightly peculiar display PHYs for driving DP/HDMI
30 * ports. DPIO is the name given to such a display PHY. These PHYs
31 * don't follow the standard programming model using direct MMIO
32 * registers, and instead their registers must be accessed trough IOSF
33 * sideband. VLV has one such PHY for driving ports B and C, and CHV
34 * adds another PHY for driving port D. Each PHY responds to specific
35 * IOSF-SB port.
36 *
37 * Each display PHY is made up of one or two channels. Each channel
38 * houses a common lane part which contains the PLL and other common
39 * logic. CH0 common lane also contains the IOSF-SB logic for the
40 * Common Register Interface (CRI) ie. the DPIO registers. CRI clock
41 * must be running when any DPIO registers are accessed.
42 *
43 * In addition to having their own registers, the PHYs are also
44 * controlled through some dedicated signals from the display
45 * controller. These include PLL reference clock enable, PLL enable,
46 * and CRI clock selection, for example.
47 *
48 * Eeach channel also has two splines (also called data lanes), and
49 * each spline is made up of one Physical Access Coding Sub-Layer
50 * (PCS) block and two TX lanes. So each channel has two PCS blocks
51 * and four TX lanes. The TX lanes are used as DP lanes or TMDS
52 * data/clock pairs depending on the output type.
53 *
54 * Additionally the PHY also contains an AUX lane with AUX blocks
55 * for each channel. This is used for DP AUX communication, but
56 * this fact isn't really relevant for the driver since AUX is
57 * controlled from the display controller side. No DPIO registers
58 * need to be accessed during AUX communication,
59 *
60 * Generally on VLV/CHV the common lane corresponds to the pipe and
61 * the spline (PCS/TX) corresponds to the port.
62 *
63 * For dual channel PHY (VLV/CHV):
64 *
65 * pipe A == CMN/PLL/REF CH0
66 *
67 * pipe B == CMN/PLL/REF CH1
68 *
69 * port B == PCS/TX CH0
70 *
71 * port C == PCS/TX CH1
72 *
73 * This is especially important when we cross the streams
74 * ie. drive port B with pipe B, or port C with pipe A.
75 *
76 * For single channel PHY (CHV):
77 *
78 * pipe C == CMN/PLL/REF CH0
79 *
80 * port D == PCS/TX CH0
81 *
82 * On BXT the entire PHY channel corresponds to the port. That means
83 * the PLL is also now associated with the port rather than the pipe,
84 * and so the clock needs to be routed to the appropriate transcoder.
85 * Port A PLL is directly connected to transcoder EDP and port B/C
86 * PLLs can be routed to any transcoder A/B/C.
87 *
88 * Note: DDI0 is digital port B, DD1 is digital port C, and DDI2 is
89 * digital port D (CHV) or port A (BXT). ::
90 *
91 *
92 * Dual channel PHY (VLV/CHV/BXT)
93 * ---------------------------------
94 * | CH0 | CH1 |
95 * | CMN/PLL/REF | CMN/PLL/REF |
96 * |---------------|---------------| Display PHY
97 * | PCS01 | PCS23 | PCS01 | PCS23 |
98 * |-------|-------|-------|-------|
99 * |TX0|TX1|TX2|TX3|TX0|TX1|TX2|TX3|
100 * ---------------------------------
101 * | DDI0 | DDI1 | DP/HDMI ports
102 * ---------------------------------
103 *
104 * Single channel PHY (CHV/BXT)
105 * -----------------
106 * | CH0 |
107 * | CMN/PLL/REF |
108 * |---------------| Display PHY
109 * | PCS01 | PCS23 |
110 * |-------|-------|
111 * |TX0|TX1|TX2|TX3|
112 * -----------------
113 * | DDI2 | DP/HDMI port
114 * -----------------
115 */
116
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300117/**
118 * struct bxt_ddi_phy_info - Hold info for a broxton DDI phy
119 */
120struct bxt_ddi_phy_info {
121 /**
122 * @dual_channel: true if this phy has a second channel.
123 */
124 bool dual_channel;
125
126 /**
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300127 * @rcomp_phy: If -1, indicates this phy has its own rcomp resistor.
128 * Otherwise the GRC value will be copied from the phy indicated by
129 * this field.
130 */
131 enum dpio_phy rcomp_phy;
132
133 /**
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200134 * @reset_delay: delay in us to wait before setting the common reset
135 * bit in BXT_PHY_CTL_FAMILY, which effectively enables the phy.
136 */
137 int reset_delay;
138
139 /**
140 * @pwron_mask: Mask with the appropriate bit set that would cause the
141 * punit to power this phy if written to BXT_P_CR_GT_DISP_PWRON.
142 */
143 u32 pwron_mask;
144
145 /**
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300146 * @channel: struct containing per channel information.
147 */
148 struct {
149 /**
150 * @port: which port maps to this channel.
151 */
152 enum port port;
153 } channel[2];
154};
155
156static const struct bxt_ddi_phy_info bxt_ddi_phy_info[] = {
157 [DPIO_PHY0] = {
158 .dual_channel = true,
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300159 .rcomp_phy = DPIO_PHY1,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200160 .pwron_mask = BIT(0),
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300161
162 .channel = {
163 [DPIO_CH0] = { .port = PORT_B },
164 [DPIO_CH1] = { .port = PORT_C },
165 }
166 },
167 [DPIO_PHY1] = {
168 .dual_channel = false,
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300169 .rcomp_phy = -1,
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200170 .pwron_mask = BIT(1),
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300171
172 .channel = {
173 [DPIO_CH0] = { .port = PORT_A },
174 }
175 },
176};
177
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200178static const struct bxt_ddi_phy_info glk_ddi_phy_info[] = {
179 [DPIO_PHY0] = {
180 .dual_channel = false,
181 .rcomp_phy = DPIO_PHY1,
182 .pwron_mask = BIT(0),
183 .reset_delay = 20,
184
185 .channel = {
186 [DPIO_CH0] = { .port = PORT_B },
187 }
188 },
189 [DPIO_PHY1] = {
190 .dual_channel = false,
191 .rcomp_phy = -1,
192 .pwron_mask = BIT(3),
193 .reset_delay = 20,
194
195 .channel = {
196 [DPIO_CH0] = { .port = PORT_A },
197 }
198 },
199 [DPIO_PHY2] = {
200 .dual_channel = false,
201 .rcomp_phy = DPIO_PHY1,
202 .pwron_mask = BIT(1),
203 .reset_delay = 20,
204
205 .channel = {
206 [DPIO_CH0] = { .port = PORT_C },
207 }
208 },
209};
210
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200211static const struct bxt_ddi_phy_info *
212bxt_get_phy_list(struct drm_i915_private *dev_priv, int *count)
213{
214 if (IS_GEMINILAKE(dev_priv)) {
215 *count = ARRAY_SIZE(glk_ddi_phy_info);
216 return glk_ddi_phy_info;
217 } else {
218 *count = ARRAY_SIZE(bxt_ddi_phy_info);
219 return bxt_ddi_phy_info;
220 }
221}
222
223static const struct bxt_ddi_phy_info *
224bxt_get_phy_info(struct drm_i915_private *dev_priv, enum dpio_phy phy)
225{
226 int count;
227 const struct bxt_ddi_phy_info *phy_list =
228 bxt_get_phy_list(dev_priv, &count);
229
230 return &phy_list[phy];
231}
232
233void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300234 enum dpio_phy *phy, enum dpio_channel *ch)
235{
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200236 const struct bxt_ddi_phy_info *phy_info, *phys;
237 int i, count;
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300238
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200239 phys = bxt_get_phy_list(dev_priv, &count);
240
241 for (i = 0; i < count; i++) {
242 phy_info = &phys[i];
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300243
244 if (port == phy_info->channel[DPIO_CH0].port) {
245 *phy = i;
246 *ch = DPIO_CH0;
247 return;
248 }
249
250 if (phy_info->dual_channel &&
251 port == phy_info->channel[DPIO_CH1].port) {
252 *phy = i;
253 *ch = DPIO_CH1;
254 return;
255 }
256 }
257
258 WARN(1, "PHY not found for PORT %c", port_name(port));
259 *phy = DPIO_PHY0;
260 *ch = DPIO_CH0;
261}
262
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300263void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
264 enum port port, u32 margin, u32 scale,
265 u32 enable, u32 deemphasis)
266{
267 u32 val;
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300268 enum dpio_phy phy;
269 enum dpio_channel ch;
270
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200271 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300272
273 /*
274 * While we write to the group register to program all lanes at once we
275 * can read only lane registers and we pick lanes 0/1 for that.
276 */
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300277 val = I915_READ(BXT_PORT_PCS_DW10_LN01(phy, ch));
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300278 val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300279 I915_WRITE(BXT_PORT_PCS_DW10_GRP(phy, ch), val);
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300280
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300281 val = I915_READ(BXT_PORT_TX_DW2_LN0(phy, ch));
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300282 val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
283 val |= margin << MARGIN_000_SHIFT | scale << UNIQ_TRANS_SCALE_SHIFT;
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300284 I915_WRITE(BXT_PORT_TX_DW2_GRP(phy, ch), val);
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300285
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300286 val = I915_READ(BXT_PORT_TX_DW3_LN0(phy, ch));
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300287 val &= ~SCALE_DCOMP_METHOD;
288 if (enable)
289 val |= SCALE_DCOMP_METHOD;
290
291 if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
292 DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set");
293
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300294 I915_WRITE(BXT_PORT_TX_DW3_GRP(phy, ch), val);
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300295
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300296 val = I915_READ(BXT_PORT_TX_DW4_LN0(phy, ch));
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300297 val &= ~DE_EMPHASIS;
298 val |= deemphasis << DEEMPH_SHIFT;
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300299 I915_WRITE(BXT_PORT_TX_DW4_GRP(phy, ch), val);
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300300
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300301 val = I915_READ(BXT_PORT_PCS_DW10_LN01(phy, ch));
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300302 val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300303 I915_WRITE(BXT_PORT_PCS_DW10_GRP(phy, ch), val);
Ander Conselvan de Oliveirab6e08202016-10-06 19:22:19 +0300304}
305
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300306bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
307 enum dpio_phy phy)
308{
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200309 const struct bxt_ddi_phy_info *phy_info;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300310
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200311 phy_info = bxt_get_phy_info(dev_priv, phy);
312
313 if (!(I915_READ(BXT_P_CR_GT_DISP_PWRON) & phy_info->pwron_mask))
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300314 return false;
315
316 if ((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
317 (PHY_POWER_GOOD | PHY_RESERVED)) != PHY_POWER_GOOD) {
318 DRM_DEBUG_DRIVER("DDI PHY %d powered, but power hasn't settled\n",
319 phy);
320
321 return false;
322 }
323
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300324 if (!(I915_READ(BXT_PHY_CTL_FAMILY(phy)) & COMMON_RESET_DIS)) {
325 DRM_DEBUG_DRIVER("DDI PHY %d powered, but still in reset\n",
326 phy);
327
328 return false;
329 }
330
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300331 return true;
332}
333
334static u32 bxt_get_grc(struct drm_i915_private *dev_priv, enum dpio_phy phy)
335{
336 u32 val = I915_READ(BXT_PORT_REF_DW6(phy));
337
338 return (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
339}
340
341static void bxt_phy_wait_grc_done(struct drm_i915_private *dev_priv,
342 enum dpio_phy phy)
343{
344 if (intel_wait_for_register(dev_priv,
345 BXT_PORT_REF_DW3(phy),
346 GRC_DONE, GRC_DONE,
347 10))
348 DRM_ERROR("timeout waiting for PHY%d GRC\n", phy);
349}
350
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300351static void _bxt_ddi_phy_init(struct drm_i915_private *dev_priv,
352 enum dpio_phy phy)
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300353{
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200354 const struct bxt_ddi_phy_info *phy_info;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300355 u32 val;
356
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200357 phy_info = bxt_get_phy_info(dev_priv, phy);
358
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300359 if (bxt_ddi_phy_is_enabled(dev_priv, phy)) {
360 /* Still read out the GRC value for state verification */
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300361 if (phy_info->rcomp_phy != -1)
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300362 dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv, phy);
363
364 if (bxt_ddi_phy_verify_state(dev_priv, phy)) {
365 DRM_DEBUG_DRIVER("DDI PHY %d already enabled, "
366 "won't reprogram it\n", phy);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300367 return;
368 }
369
370 DRM_DEBUG_DRIVER("DDI PHY %d enabled with invalid state, "
371 "force reprogramming it\n", phy);
372 }
373
374 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200375 val |= phy_info->pwron_mask;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300376 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
377
378 /*
379 * The PHY registers start out inaccessible and respond to reads with
380 * all 1s. Eventually they become accessible as they power up, then
381 * the reserved bit will give the default 0. Poll on the reserved bit
382 * becoming 0 to find when the PHY is accessible.
383 * HW team confirmed that the time to reach phypowergood status is
384 * anywhere between 50 us and 100us.
385 */
386 if (wait_for_us(((I915_READ(BXT_PORT_CL1CM_DW0(phy)) &
387 (PHY_RESERVED | PHY_POWER_GOOD)) == PHY_POWER_GOOD), 100)) {
388 DRM_ERROR("timeout during PHY%d power on\n", phy);
389 }
390
391 /* Program PLL Rcomp code offset */
392 val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
393 val &= ~IREF0RC_OFFSET_MASK;
394 val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
395 I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
396
397 val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
398 val &= ~IREF1RC_OFFSET_MASK;
399 val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
400 I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
401
402 /* Program power gating */
403 val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
404 val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
405 SUS_CLK_CONFIG;
406 I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
407
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300408 if (phy_info->dual_channel) {
409 val = I915_READ(BXT_PORT_CL2CM_DW6(phy));
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300410 val |= DW6_OLDO_DYN_PWR_DOWN_EN;
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300411 I915_WRITE(BXT_PORT_CL2CM_DW6(phy), val);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300412 }
413
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300414 if (phy_info->rcomp_phy != -1) {
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300415 uint32_t grc_code;
Rodrigo Vivi01a55192016-11-17 11:17:36 -0800416
417 bxt_phy_wait_grc_done(dev_priv, phy_info->rcomp_phy);
418
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300419 /*
420 * PHY0 isn't connected to an RCOMP resistor so copy over
421 * the corresponding calibrated value from PHY1, and disable
422 * the automatic calibration on PHY0.
423 */
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300424 val = dev_priv->bxt_phy_grc = bxt_get_grc(dev_priv,
425 phy_info->rcomp_phy);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300426 grc_code = val << GRC_CODE_FAST_SHIFT |
427 val << GRC_CODE_SLOW_SHIFT |
428 val;
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300429 I915_WRITE(BXT_PORT_REF_DW6(phy), grc_code);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300430
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300431 val = I915_READ(BXT_PORT_REF_DW8(phy));
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300432 val |= GRC_DIS | GRC_RDY_OVRD;
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300433 I915_WRITE(BXT_PORT_REF_DW8(phy), val);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300434 }
435
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200436 if (phy_info->reset_delay)
437 udelay(phy_info->reset_delay);
438
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300439 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
440 val |= COMMON_RESET_DIS;
441 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300442}
443
444void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy)
445{
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200446 const struct bxt_ddi_phy_info *phy_info;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300447 uint32_t val;
448
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200449 phy_info = bxt_get_phy_info(dev_priv, phy);
450
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300451 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
452 val &= ~COMMON_RESET_DIS;
453 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
454
455 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200456 val &= ~phy_info->pwron_mask;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300457 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
458}
459
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300460void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy)
461{
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200462 const struct bxt_ddi_phy_info *phy_info =
463 bxt_get_phy_info(dev_priv, phy);
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300464 enum dpio_phy rcomp_phy = phy_info->rcomp_phy;
465 bool was_enabled;
466
467 lockdep_assert_held(&dev_priv->power_domains.lock);
468
469 if (rcomp_phy != -1) {
470 was_enabled = bxt_ddi_phy_is_enabled(dev_priv, rcomp_phy);
471
472 /*
473 * We need to copy the GRC calibration value from rcomp_phy,
474 * so make sure it's powered up.
475 */
476 if (!was_enabled)
477 _bxt_ddi_phy_init(dev_priv, rcomp_phy);
478 }
479
480 _bxt_ddi_phy_init(dev_priv, phy);
481
482 if (rcomp_phy != -1 && !was_enabled)
483 bxt_ddi_phy_uninit(dev_priv, phy_info->rcomp_phy);
484}
485
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300486static bool __printf(6, 7)
487__phy_reg_verify_state(struct drm_i915_private *dev_priv, enum dpio_phy phy,
488 i915_reg_t reg, u32 mask, u32 expected,
489 const char *reg_fmt, ...)
490{
491 struct va_format vaf;
492 va_list args;
493 u32 val;
494
495 val = I915_READ(reg);
496 if ((val & mask) == expected)
497 return true;
498
499 va_start(args, reg_fmt);
500 vaf.fmt = reg_fmt;
501 vaf.va = &args;
502
503 DRM_DEBUG_DRIVER("DDI PHY %d reg %pV [%08x] state mismatch: "
504 "current %08x, expected %08x (mask %08x)\n",
505 phy, &vaf, reg.reg, val, (val & ~mask) | expected,
506 mask);
507
508 va_end(args);
509
510 return false;
511}
512
513bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
514 enum dpio_phy phy)
515{
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200516 const struct bxt_ddi_phy_info *phy_info;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300517 uint32_t mask;
518 bool ok;
519
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200520 phy_info = bxt_get_phy_info(dev_priv, phy);
521
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300522#define _CHK(reg, mask, exp, fmt, ...) \
523 __phy_reg_verify_state(dev_priv, phy, reg, mask, exp, fmt, \
524 ## __VA_ARGS__)
525
526 if (!bxt_ddi_phy_is_enabled(dev_priv, phy))
527 return false;
528
529 ok = true;
530
531 /* PLL Rcomp code offset */
532 ok &= _CHK(BXT_PORT_CL1CM_DW9(phy),
533 IREF0RC_OFFSET_MASK, 0xe4 << IREF0RC_OFFSET_SHIFT,
534 "BXT_PORT_CL1CM_DW9(%d)", phy);
535 ok &= _CHK(BXT_PORT_CL1CM_DW10(phy),
536 IREF1RC_OFFSET_MASK, 0xe4 << IREF1RC_OFFSET_SHIFT,
537 "BXT_PORT_CL1CM_DW10(%d)", phy);
538
539 /* Power gating */
540 mask = OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | SUS_CLK_CONFIG;
541 ok &= _CHK(BXT_PORT_CL1CM_DW28(phy), mask, mask,
542 "BXT_PORT_CL1CM_DW28(%d)", phy);
543
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300544 if (phy_info->dual_channel)
545 ok &= _CHK(BXT_PORT_CL2CM_DW6(phy),
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300546 DW6_OLDO_DYN_PWR_DOWN_EN, DW6_OLDO_DYN_PWR_DOWN_EN,
Ander Conselvan de Oliveira842d4162016-10-06 19:22:20 +0300547 "BXT_PORT_CL2CM_DW6(%d)", phy);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300548
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300549 if (phy_info->rcomp_phy != -1) {
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300550 u32 grc_code = dev_priv->bxt_phy_grc;
551
552 grc_code = grc_code << GRC_CODE_FAST_SHIFT |
553 grc_code << GRC_CODE_SLOW_SHIFT |
554 grc_code;
555 mask = GRC_CODE_FAST_MASK | GRC_CODE_SLOW_MASK |
556 GRC_CODE_NOM_MASK;
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300557 ok &= _CHK(BXT_PORT_REF_DW6(phy), mask, grc_code,
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300558 "BXT_PORT_REF_DW6(%d)", phy);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300559
560 mask = GRC_DIS | GRC_RDY_OVRD;
Ander Conselvan de Oliveirae7583f72016-10-06 19:22:21 +0300561 ok &= _CHK(BXT_PORT_REF_DW8(phy), mask, mask,
562 "BXT_PORT_REF_DW8(%d)", phy);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300563 }
564
565 return ok;
566#undef _CHK
567}
568
569uint8_t
Ville Syrjälä5161d052017-10-27 16:43:48 +0300570bxt_ddi_phy_calc_lane_lat_optim_mask(uint8_t lane_count)
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300571{
572 switch (lane_count) {
573 case 1:
574 return 0;
575 case 2:
576 return BIT(2) | BIT(0);
577 case 4:
578 return BIT(3) | BIT(2) | BIT(0);
579 default:
580 MISSING_CASE(lane_count);
581
582 return 0;
583 }
584}
585
586void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
587 uint8_t lane_lat_optim_mask)
588{
589 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
590 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
591 enum port port = dport->port;
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300592 enum dpio_phy phy;
593 enum dpio_channel ch;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300594 int lane;
595
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200596 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300597
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300598 for (lane = 0; lane < 4; lane++) {
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300599 u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300600
601 /*
602 * Note that on CHV this flag is called UPAR, but has
603 * the same function.
604 */
605 val &= ~LATENCY_OPTIM;
606 if (lane_lat_optim_mask & BIT(lane))
607 val |= LATENCY_OPTIM;
608
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300609 I915_WRITE(BXT_PORT_TX_DW14_LN(phy, ch, lane), val);
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300610 }
611}
612
613uint8_t
614bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder)
615{
616 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
617 struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
618 enum port port = dport->port;
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300619 enum dpio_phy phy;
620 enum dpio_channel ch;
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300621 int lane;
622 uint8_t mask;
623
Ander Conselvan de Oliveira0a116ce2016-12-02 10:23:51 +0200624 bxt_port_to_phy_channel(dev_priv, port, &phy, &ch);
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300625
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300626 mask = 0;
627 for (lane = 0; lane < 4; lane++) {
Ander Conselvan de Oliveiraed378922016-10-19 10:59:00 +0300628 u32 val = I915_READ(BXT_PORT_TX_DW14_LN(phy, ch, lane));
Ander Conselvan de Oliveira47a6bc62016-10-06 19:22:17 +0300629
630 if (val & LATENCY_OPTIM)
631 mask |= BIT(lane);
632 }
633
634 return mask;
635}
636
637
Ander Conselvan de Oliveirab7fa22d2016-04-27 15:44:17 +0300638void chv_set_phy_signal_level(struct intel_encoder *encoder,
639 u32 deemph_reg_value, u32 margin_reg_value,
640 bool uniq_trans_scale)
641{
642 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
643 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
644 struct intel_crtc *intel_crtc = to_intel_crtc(dport->base.base.crtc);
645 enum dpio_channel ch = vlv_dport_to_channel(dport);
646 enum pipe pipe = intel_crtc->pipe;
647 u32 val;
648 int i;
649
650 mutex_lock(&dev_priv->sb_lock);
651
652 /* Clear calc init */
653 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
654 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
655 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
656 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
657 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
658
659 if (intel_crtc->config->lane_count > 2) {
660 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
661 val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
662 val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
663 val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
664 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
665 }
666
667 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
668 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
669 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
670 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
671
672 if (intel_crtc->config->lane_count > 2) {
673 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
674 val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
675 val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
676 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
677 }
678
679 /* Program swing deemph */
680 for (i = 0; i < intel_crtc->config->lane_count; i++) {
681 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
682 val &= ~DPIO_SWING_DEEMPH9P5_MASK;
683 val |= deemph_reg_value << DPIO_SWING_DEEMPH9P5_SHIFT;
684 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
685 }
686
687 /* Program swing margin */
688 for (i = 0; i < intel_crtc->config->lane_count; i++) {
689 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
690
691 val &= ~DPIO_SWING_MARGIN000_MASK;
692 val |= margin_reg_value << DPIO_SWING_MARGIN000_SHIFT;
693
694 /*
695 * Supposedly this value shouldn't matter when unique transition
696 * scale is disabled, but in fact it does matter. Let's just
697 * always program the same value and hope it's OK.
698 */
699 val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
700 val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
701
702 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
703 }
704
705 /*
706 * The document said it needs to set bit 27 for ch0 and bit 26
707 * for ch1. Might be a typo in the doc.
708 * For now, for this unique transition scale selection, set bit
709 * 27 for ch0 and ch1.
710 */
711 for (i = 0; i < intel_crtc->config->lane_count; i++) {
712 val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
713 if (uniq_trans_scale)
714 val |= DPIO_TX_UNIQ_TRANS_SCALE_EN;
715 else
716 val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
717 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
718 }
719
720 /* Start swing calculation */
721 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
722 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
723 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
724
725 if (intel_crtc->config->lane_count > 2) {
726 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
727 val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
728 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
729 }
730
731 mutex_unlock(&dev_priv->sb_lock);
732
733}
734
Ander Conselvan de Oliveira844b2f92016-04-27 15:44:18 +0300735void chv_data_lane_soft_reset(struct intel_encoder *encoder,
736 bool reset)
737{
738 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
739 enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
740 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
741 enum pipe pipe = crtc->pipe;
742 uint32_t val;
743
744 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
745 if (reset)
746 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
747 else
748 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
749 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
750
751 if (crtc->config->lane_count > 2) {
752 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
753 if (reset)
754 val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
755 else
756 val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
757 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
758 }
759
760 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
761 val |= CHV_PCS_REQ_SOFTRESET_EN;
762 if (reset)
763 val &= ~DPIO_PCS_CLK_SOFT_RESET;
764 else
765 val |= DPIO_PCS_CLK_SOFT_RESET;
766 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
767
768 if (crtc->config->lane_count > 2) {
769 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
770 val |= CHV_PCS_REQ_SOFTRESET_EN;
771 if (reset)
772 val &= ~DPIO_PCS_CLK_SOFT_RESET;
773 else
774 val |= DPIO_PCS_CLK_SOFT_RESET;
775 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
776 }
777}
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +0300778
779void chv_phy_pre_pll_enable(struct intel_encoder *encoder)
780{
781 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
782 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100783 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira419b1b72016-04-27 15:44:19 +0300784 struct intel_crtc *intel_crtc =
785 to_intel_crtc(encoder->base.crtc);
786 enum dpio_channel ch = vlv_dport_to_channel(dport);
787 enum pipe pipe = intel_crtc->pipe;
788 unsigned int lane_mask =
789 intel_dp_unused_lane_mask(intel_crtc->config->lane_count);
790 u32 val;
791
792 /*
793 * Must trick the second common lane into life.
794 * Otherwise we can't even access the PLL.
795 */
796 if (ch == DPIO_CH0 && pipe == PIPE_B)
797 dport->release_cl2_override =
798 !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
799
800 chv_phy_powergate_lanes(encoder, true, lane_mask);
801
802 mutex_lock(&dev_priv->sb_lock);
803
804 /* Assert data lane reset */
805 chv_data_lane_soft_reset(encoder, true);
806
807 /* program left/right clock distribution */
808 if (pipe != PIPE_B) {
809 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
810 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
811 if (ch == DPIO_CH0)
812 val |= CHV_BUFLEFTENA1_FORCE;
813 if (ch == DPIO_CH1)
814 val |= CHV_BUFRIGHTENA1_FORCE;
815 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
816 } else {
817 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
818 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
819 if (ch == DPIO_CH0)
820 val |= CHV_BUFLEFTENA2_FORCE;
821 if (ch == DPIO_CH1)
822 val |= CHV_BUFRIGHTENA2_FORCE;
823 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
824 }
825
826 /* program clock channel usage */
827 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
828 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
829 if (pipe != PIPE_B)
830 val &= ~CHV_PCS_USEDCLKCHANNEL;
831 else
832 val |= CHV_PCS_USEDCLKCHANNEL;
833 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
834
835 if (intel_crtc->config->lane_count > 2) {
836 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
837 val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
838 if (pipe != PIPE_B)
839 val &= ~CHV_PCS_USEDCLKCHANNEL;
840 else
841 val |= CHV_PCS_USEDCLKCHANNEL;
842 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
843 }
844
845 /*
846 * This a a bit weird since generally CL
847 * matches the pipe, but here we need to
848 * pick the CL based on the port.
849 */
850 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
851 if (pipe != PIPE_B)
852 val &= ~CHV_CMN_USEDCLKCHANNEL;
853 else
854 val |= CHV_CMN_USEDCLKCHANNEL;
855 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
856
857 mutex_unlock(&dev_priv->sb_lock);
858}
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +0300859
860void chv_phy_pre_encoder_enable(struct intel_encoder *encoder)
861{
862 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
863 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
864 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100865 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveirae7d2a7172016-04-27 15:44:20 +0300866 struct intel_crtc *intel_crtc =
867 to_intel_crtc(encoder->base.crtc);
868 enum dpio_channel ch = vlv_dport_to_channel(dport);
869 int pipe = intel_crtc->pipe;
870 int data, i, stagger;
871 u32 val;
872
873 mutex_lock(&dev_priv->sb_lock);
874
875 /* allow hardware to manage TX FIFO reset source */
876 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
877 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
878 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
879
880 if (intel_crtc->config->lane_count > 2) {
881 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
882 val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
883 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
884 }
885
886 /* Program Tx lane latency optimal setting*/
887 for (i = 0; i < intel_crtc->config->lane_count; i++) {
888 /* Set the upar bit */
889 if (intel_crtc->config->lane_count == 1)
890 data = 0x0;
891 else
892 data = (i == 1) ? 0x0 : 0x1;
893 vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
894 data << DPIO_UPAR_SHIFT);
895 }
896
897 /* Data lane stagger programming */
898 if (intel_crtc->config->port_clock > 270000)
899 stagger = 0x18;
900 else if (intel_crtc->config->port_clock > 135000)
901 stagger = 0xd;
902 else if (intel_crtc->config->port_clock > 67500)
903 stagger = 0x7;
904 else if (intel_crtc->config->port_clock > 33750)
905 stagger = 0x4;
906 else
907 stagger = 0x2;
908
909 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
910 val |= DPIO_TX2_STAGGER_MASK(0x1f);
911 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
912
913 if (intel_crtc->config->lane_count > 2) {
914 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
915 val |= DPIO_TX2_STAGGER_MASK(0x1f);
916 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
917 }
918
919 vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
920 DPIO_LANESTAGGER_STRAP(stagger) |
921 DPIO_LANESTAGGER_STRAP_OVRD |
922 DPIO_TX1_STAGGER_MASK(0x1f) |
923 DPIO_TX1_STAGGER_MULT(6) |
924 DPIO_TX2_STAGGER_MULT(0));
925
926 if (intel_crtc->config->lane_count > 2) {
927 vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
928 DPIO_LANESTAGGER_STRAP(stagger) |
929 DPIO_LANESTAGGER_STRAP_OVRD |
930 DPIO_TX1_STAGGER_MASK(0x1f) |
931 DPIO_TX1_STAGGER_MULT(7) |
932 DPIO_TX2_STAGGER_MULT(5));
933 }
934
935 /* Deassert data lane reset */
936 chv_data_lane_soft_reset(encoder, false);
937
938 mutex_unlock(&dev_priv->sb_lock);
939}
940
941void chv_phy_release_cl2_override(struct intel_encoder *encoder)
942{
943 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
944 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
945
946 if (dport->release_cl2_override) {
947 chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
948 dport->release_cl2_override = false;
949 }
950}
Ander Conselvan de Oliveira204970b2016-04-27 15:44:21 +0300951
952void chv_phy_post_pll_disable(struct intel_encoder *encoder)
953{
954 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
955 enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
956 u32 val;
957
958 mutex_lock(&dev_priv->sb_lock);
959
960 /* disable left/right clock distribution */
961 if (pipe != PIPE_B) {
962 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
963 val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
964 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
965 } else {
966 val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
967 val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
968 vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
969 }
970
971 mutex_unlock(&dev_priv->sb_lock);
972
973 /*
974 * Leave the power down bit cleared for at least one
975 * lane so that chv_powergate_phy_ch() will power
976 * on something when the channel is otherwise unused.
977 * When the port is off and the override is removed
978 * the lanes power down anyway, so otherwise it doesn't
979 * really matter what the state of power down bits is
980 * after this.
981 */
982 chv_phy_powergate_lanes(encoder, false, 0x0);
983}
Ander Conselvan de Oliveira53d98722016-04-27 15:44:22 +0300984
985void vlv_set_phy_signal_level(struct intel_encoder *encoder,
986 u32 demph_reg_value, u32 preemph_reg_value,
987 u32 uniqtranscale_reg_value, u32 tx3_demph)
988{
989 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
990 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
991 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
992 enum dpio_channel port = vlv_dport_to_channel(dport);
993 int pipe = intel_crtc->pipe;
994
995 mutex_lock(&dev_priv->sb_lock);
996 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0x00000000);
997 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), demph_reg_value);
998 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port),
999 uniqtranscale_reg_value);
1000 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0C782040);
1001
1002 if (tx3_demph)
1003 vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), tx3_demph);
1004
1005 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
1006 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), preemph_reg_value);
1007 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
1008 mutex_unlock(&dev_priv->sb_lock);
1009}
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03001010
1011void vlv_phy_pre_pll_enable(struct intel_encoder *encoder)
1012{
1013 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
1014 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001015 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6da2e612016-04-27 15:44:23 +03001016 struct intel_crtc *intel_crtc =
1017 to_intel_crtc(encoder->base.crtc);
1018 enum dpio_channel port = vlv_dport_to_channel(dport);
1019 int pipe = intel_crtc->pipe;
1020
1021 /* Program Tx lane resets to default */
1022 mutex_lock(&dev_priv->sb_lock);
1023 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
1024 DPIO_PCS_TX_LANE2_RESET |
1025 DPIO_PCS_TX_LANE1_RESET);
1026 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
1027 DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
1028 DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
1029 (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
1030 DPIO_PCS_CLK_SOFT_RESET);
1031
1032 /* Fix up inter-pair skew failure */
1033 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
1034 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
1035 vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
1036 mutex_unlock(&dev_priv->sb_lock);
1037}
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03001038
1039void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder)
1040{
1041 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
1042 struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
1043 struct drm_device *dev = encoder->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001044 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira5f68c272016-04-27 15:44:24 +03001045 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
1046 enum dpio_channel port = vlv_dport_to_channel(dport);
1047 int pipe = intel_crtc->pipe;
1048 u32 val;
1049
1050 mutex_lock(&dev_priv->sb_lock);
1051
1052 /* Enable clock channels for this port */
1053 val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
1054 val = 0;
1055 if (pipe)
1056 val |= (1<<21);
1057 else
1058 val &= ~(1<<21);
1059 val |= 0x001000c4;
1060 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
1061
1062 /* Program lane clock */
1063 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
1064 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
1065
1066 mutex_unlock(&dev_priv->sb_lock);
1067}
Ander Conselvan de Oliveira0f572eb2016-04-27 15:44:25 +03001068
1069void vlv_phy_reset_lanes(struct intel_encoder *encoder)
1070{
1071 struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001072 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Ander Conselvan de Oliveira0f572eb2016-04-27 15:44:25 +03001073 struct intel_crtc *intel_crtc =
1074 to_intel_crtc(encoder->base.crtc);
1075 enum dpio_channel port = vlv_dport_to_channel(dport);
1076 int pipe = intel_crtc->pipe;
1077
1078 mutex_lock(&dev_priv->sb_lock);
1079 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
1080 vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
1081 mutex_unlock(&dev_priv->sb_lock);
1082}