blob: f9f55bc05e7d82f4fcd6ede49315d206455a94ec [file] [log] [blame]
Eugeni Dodonov45244b82012-05-09 15:37:20 -03001/*
2 * Copyright © 2012 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 DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eugeni Dodonov <eugeni.dodonov@intel.com>
25 *
26 */
27
28#include "i915_drv.h"
29#include "intel_drv.h"
30
Jani Nikula10122052014-08-27 16:27:30 +030031struct ddi_buf_trans {
32 u32 trans1; /* balance leg enable, de-emph level */
33 u32 trans2; /* vref sel, vswing */
34};
35
Eugeni Dodonov45244b82012-05-09 15:37:20 -030036/* HDMI/DVI modes ignore everything but the last 2 items. So we share
37 * them for both DP and FDI transports, allowing those ports to
38 * automatically adapt to HDMI connections as well
39 */
Jani Nikula10122052014-08-27 16:27:30 +030040static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
41 { 0x00FFFFFF, 0x0006000E },
42 { 0x00D75FFF, 0x0005000A },
43 { 0x00C30FFF, 0x00040006 },
44 { 0x80AAAFFF, 0x000B0000 },
45 { 0x00FFFFFF, 0x0005000A },
46 { 0x00D75FFF, 0x000C0004 },
47 { 0x80C30FFF, 0x000B0000 },
48 { 0x00FFFFFF, 0x00040006 },
49 { 0x80D75FFF, 0x000B0000 },
Eugeni Dodonov45244b82012-05-09 15:37:20 -030050};
51
Jani Nikula10122052014-08-27 16:27:30 +030052static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
53 { 0x00FFFFFF, 0x0007000E },
54 { 0x00D75FFF, 0x000F000A },
55 { 0x00C30FFF, 0x00060006 },
56 { 0x00AAAFFF, 0x001E0000 },
57 { 0x00FFFFFF, 0x000F000A },
58 { 0x00D75FFF, 0x00160004 },
59 { 0x00C30FFF, 0x001E0000 },
60 { 0x00FFFFFF, 0x00060006 },
61 { 0x00D75FFF, 0x001E0000 },
Paulo Zanoni6acab152013-09-12 17:06:24 -030062};
63
Jani Nikula10122052014-08-27 16:27:30 +030064static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
65 /* Idx NT mV d T mV d db */
66 { 0x00FFFFFF, 0x0006000E }, /* 0: 400 400 0 */
67 { 0x00E79FFF, 0x000E000C }, /* 1: 400 500 2 */
68 { 0x00D75FFF, 0x0005000A }, /* 2: 400 600 3.5 */
69 { 0x00FFFFFF, 0x0005000A }, /* 3: 600 600 0 */
70 { 0x00E79FFF, 0x001D0007 }, /* 4: 600 750 2 */
71 { 0x00D75FFF, 0x000C0004 }, /* 5: 600 900 3.5 */
72 { 0x00FFFFFF, 0x00040006 }, /* 6: 800 800 0 */
73 { 0x80E79FFF, 0x00030002 }, /* 7: 800 1000 2 */
74 { 0x00FFFFFF, 0x00140005 }, /* 8: 850 850 0 */
75 { 0x00FFFFFF, 0x000C0004 }, /* 9: 900 900 0 */
76 { 0x00FFFFFF, 0x001C0003 }, /* 10: 950 950 0 */
77 { 0x80FFFFFF, 0x00030002 }, /* 11: 1000 1000 0 */
Eugeni Dodonov45244b82012-05-09 15:37:20 -030078};
79
Jani Nikula10122052014-08-27 16:27:30 +030080static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
81 { 0x00FFFFFF, 0x00000012 },
82 { 0x00EBAFFF, 0x00020011 },
83 { 0x00C71FFF, 0x0006000F },
84 { 0x00AAAFFF, 0x000E000A },
85 { 0x00FFFFFF, 0x00020011 },
86 { 0x00DB6FFF, 0x0005000F },
87 { 0x00BEEFFF, 0x000A000C },
88 { 0x00FFFFFF, 0x0005000F },
89 { 0x00DB6FFF, 0x000A000C },
Paulo Zanoni300644c2013-11-02 21:07:42 -070090};
91
Jani Nikula10122052014-08-27 16:27:30 +030092static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
93 { 0x00FFFFFF, 0x0007000E },
94 { 0x00D75FFF, 0x000E000A },
95 { 0x00BEFFFF, 0x00140006 },
96 { 0x80B2CFFF, 0x001B0002 },
97 { 0x00FFFFFF, 0x000E000A },
Rodrigo Vivi17b523b2014-09-24 20:32:43 -040098 { 0x00DB6FFF, 0x00160005 },
Rodrigo Vivi6805b2a2014-09-25 12:28:32 -040099 { 0x80C71FFF, 0x001A0002 },
Jani Nikula10122052014-08-27 16:27:30 +0300100 { 0x00F7DFFF, 0x00180004 },
101 { 0x80D75FFF, 0x001B0002 },
Art Runyane58623c2013-11-02 21:07:41 -0700102};
103
Jani Nikula10122052014-08-27 16:27:30 +0300104static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
105 { 0x00FFFFFF, 0x0001000E },
106 { 0x00D75FFF, 0x0004000A },
107 { 0x00C30FFF, 0x00070006 },
108 { 0x00AAAFFF, 0x000C0000 },
109 { 0x00FFFFFF, 0x0004000A },
110 { 0x00D75FFF, 0x00090004 },
111 { 0x00C30FFF, 0x000C0000 },
112 { 0x00FFFFFF, 0x00070006 },
113 { 0x00D75FFF, 0x000C0000 },
Art Runyane58623c2013-11-02 21:07:41 -0700114};
115
Jani Nikula10122052014-08-27 16:27:30 +0300116static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
117 /* Idx NT mV d T mV df db */
118 { 0x00FFFFFF, 0x0007000E }, /* 0: 400 400 0 */
119 { 0x00D75FFF, 0x000E000A }, /* 1: 400 600 3.5 */
120 { 0x00BEFFFF, 0x00140006 }, /* 2: 400 800 6 */
121 { 0x00FFFFFF, 0x0009000D }, /* 3: 450 450 0 */
122 { 0x00FFFFFF, 0x000E000A }, /* 4: 600 600 0 */
123 { 0x00D7FFFF, 0x00140006 }, /* 5: 600 800 2.5 */
124 { 0x80CB2FFF, 0x001B0002 }, /* 6: 600 1000 4.5 */
125 { 0x00FFFFFF, 0x00140006 }, /* 7: 800 800 0 */
126 { 0x80E79FFF, 0x001B0002 }, /* 8: 800 1000 2 */
127 { 0x80FFFFFF, 0x001B0002 }, /* 9: 1000 1000 0 */
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100128};
129
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000130static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
Damien Lespiau6c930682014-11-26 13:37:26 +0000131 { 0x00000018, 0x000000a2 },
132 { 0x00004014, 0x0000009B },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000133 { 0x00006012, 0x00000088 },
Damien Lespiau6c930682014-11-26 13:37:26 +0000134 { 0x00008010, 0x00000087 },
135 { 0x00000018, 0x0000009B },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000136 { 0x00004014, 0x00000088 },
Damien Lespiau6c930682014-11-26 13:37:26 +0000137 { 0x00006012, 0x00000087 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000138 { 0x00000018, 0x00000088 },
Damien Lespiau6c930682014-11-26 13:37:26 +0000139 { 0x00004014, 0x00000087 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000140};
141
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530142/* eDP 1.4 low vswing translation parameters */
143static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
144 { 0x00000018, 0x000000a8 },
145 { 0x00002016, 0x000000ab },
146 { 0x00006012, 0x000000a2 },
147 { 0x00008010, 0x00000088 },
148 { 0x00000018, 0x000000ab },
149 { 0x00004014, 0x000000a2 },
150 { 0x00006012, 0x000000a6 },
151 { 0x00000018, 0x000000a2 },
152 { 0x00005013, 0x0000009c },
153 { 0x00000018, 0x00000088 },
154};
155
156
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000157static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
Sonika Jindalb7192a52015-04-15 11:02:33 +0530158 { 0x00000018, 0x000000ac },
159 { 0x00005012, 0x0000009d },
160 { 0x00007011, 0x00000088 },
161 { 0x00000018, 0x000000a1 },
162 { 0x00000018, 0x00000098 },
163 { 0x00004013, 0x00000088 },
164 { 0x00006012, 0x00000087 },
165 { 0x00000018, 0x000000df },
166 { 0x00003015, 0x00000087 },
167 { 0x00003015, 0x000000c7 },
168 { 0x00000018, 0x000000c7 },
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000169};
170
Jani Nikula20f4dbe2013-08-30 19:40:28 +0300171enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
Paulo Zanonifc914632012-10-05 12:05:54 -0300172{
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300173 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonifc914632012-10-05 12:05:54 -0300174 int type = intel_encoder->type;
175
Dave Airlie0e32b392014-05-02 14:02:48 +1000176 if (type == INTEL_OUTPUT_DP_MST) {
177 struct intel_digital_port *intel_dig_port = enc_to_mst(encoder)->primary;
178 return intel_dig_port->port;
179 } else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
Paulo Zanoni00c09d72012-10-26 19:05:52 -0200180 type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
Paulo Zanoni174edf12012-10-26 19:05:50 -0200181 struct intel_digital_port *intel_dig_port =
182 enc_to_dig_port(encoder);
183 return intel_dig_port->port;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300184
Paulo Zanonifc914632012-10-05 12:05:54 -0300185 } else if (type == INTEL_OUTPUT_ANALOG) {
186 return PORT_E;
Paulo Zanoni0bdee302012-10-15 15:51:38 -0300187
Paulo Zanonifc914632012-10-05 12:05:54 -0300188 } else {
189 DRM_ERROR("Invalid DDI encoder type %d\n", type);
190 BUG();
191 }
192}
193
Art Runyane58623c2013-11-02 21:07:41 -0700194/*
195 * Starting with Haswell, DDI port buffers must be programmed with correct
196 * values in advance. The buffer values are different for FDI and DP modes,
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300197 * but the HDMI/DVI fields are shared among those. So we program the DDI
198 * in either FDI or DP modes only, as HDMI connections will work with both
199 * of those
200 */
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300201static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port)
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300202{
203 struct drm_i915_private *dev_priv = dev->dev_private;
204 u32 reg;
Damien Lespiau7ff44672015-03-02 16:19:36 +0000205 int i, n_hdmi_entries, n_dp_entries, n_edp_entries, hdmi_default_entry,
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530206 size;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300207 int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
Jani Nikula10122052014-08-27 16:27:30 +0300208 const struct ddi_buf_trans *ddi_translations_fdi;
209 const struct ddi_buf_trans *ddi_translations_dp;
210 const struct ddi_buf_trans *ddi_translations_edp;
211 const struct ddi_buf_trans *ddi_translations_hdmi;
212 const struct ddi_buf_trans *ddi_translations;
Art Runyane58623c2013-11-02 21:07:41 -0700213
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000214 if (IS_SKYLAKE(dev)) {
215 ddi_translations_fdi = NULL;
216 ddi_translations_dp = skl_ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530217 n_dp_entries = ARRAY_SIZE(skl_ddi_translations_dp);
218 if (dev_priv->vbt.edp_low_vswing) {
219 ddi_translations_edp = skl_ddi_translations_edp;
220 n_edp_entries = ARRAY_SIZE(skl_ddi_translations_edp);
221 } else {
222 ddi_translations_edp = skl_ddi_translations_dp;
223 n_edp_entries = ARRAY_SIZE(skl_ddi_translations_dp);
224 }
225
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000226 ddi_translations_hdmi = skl_ddi_translations_hdmi;
227 n_hdmi_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
Sonika Jindalb7192a52015-04-15 11:02:33 +0530228 hdmi_default_entry = 7;
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000229 } else if (IS_BROADWELL(dev)) {
Art Runyane58623c2013-11-02 21:07:41 -0700230 ddi_translations_fdi = bdw_ddi_translations_fdi;
231 ddi_translations_dp = bdw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700232 ddi_translations_edp = bdw_ddi_translations_edp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100233 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530234 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
235 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300236 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000237 hdmi_default_entry = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700238 } else if (IS_HASWELL(dev)) {
239 ddi_translations_fdi = hsw_ddi_translations_fdi;
240 ddi_translations_dp = hsw_ddi_translations_dp;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700241 ddi_translations_edp = hsw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100242 ddi_translations_hdmi = hsw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530243 n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300244 n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000245 hdmi_default_entry = 6;
Art Runyane58623c2013-11-02 21:07:41 -0700246 } else {
247 WARN(1, "ddi translation table missing\n");
Paulo Zanoni300644c2013-11-02 21:07:42 -0700248 ddi_translations_edp = bdw_ddi_translations_dp;
Art Runyane58623c2013-11-02 21:07:41 -0700249 ddi_translations_fdi = bdw_ddi_translations_fdi;
250 ddi_translations_dp = bdw_ddi_translations_dp;
Damien Lespiaua26aa8b2014-08-01 11:07:55 +0100251 ddi_translations_hdmi = bdw_ddi_translations_hdmi;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530252 n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
253 n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
Jani Nikula10122052014-08-27 16:27:30 +0300254 n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
Damien Lespiau7ff44672015-03-02 16:19:36 +0000255 hdmi_default_entry = 7;
Art Runyane58623c2013-11-02 21:07:41 -0700256 }
257
Paulo Zanoni300644c2013-11-02 21:07:42 -0700258 switch (port) {
259 case PORT_A:
260 ddi_translations = ddi_translations_edp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530261 size = n_edp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700262 break;
263 case PORT_B:
264 case PORT_C:
Paulo Zanoni300644c2013-11-02 21:07:42 -0700265 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530266 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700267 break;
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700268 case PORT_D:
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530269 if (intel_dp_is_edp(dev, PORT_D)) {
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700270 ddi_translations = ddi_translations_edp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530271 size = n_edp_entries;
272 } else {
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700273 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530274 size = n_dp_entries;
275 }
Paulo Zanoni77d8d002013-11-02 21:07:45 -0700276 break;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700277 case PORT_E:
Damien Lespiau7f88e3a2013-12-03 13:56:25 +0000278 if (ddi_translations_fdi)
279 ddi_translations = ddi_translations_fdi;
280 else
281 ddi_translations = ddi_translations_dp;
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530282 size = n_dp_entries;
Paulo Zanoni300644c2013-11-02 21:07:42 -0700283 break;
284 default:
285 BUG();
286 }
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300287
Sonika Jindal7ad14a22015-02-25 10:29:12 +0530288 for (i = 0, reg = DDI_BUF_TRANS(port); i < size; i++) {
Jani Nikula10122052014-08-27 16:27:30 +0300289 I915_WRITE(reg, ddi_translations[i].trans1);
290 reg += 4;
291 I915_WRITE(reg, ddi_translations[i].trans2);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300292 reg += 4;
293 }
Damien Lespiauce4dd492014-08-01 11:07:54 +0100294
295 /* Choose a good default if VBT is badly populated */
296 if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
297 hdmi_level >= n_hdmi_entries)
Damien Lespiau7ff44672015-03-02 16:19:36 +0000298 hdmi_level = hdmi_default_entry;
Damien Lespiauce4dd492014-08-01 11:07:54 +0100299
Paulo Zanoni6acab152013-09-12 17:06:24 -0300300 /* Entry 9 is for HDMI: */
Jani Nikula10122052014-08-27 16:27:30 +0300301 I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans1);
302 reg += 4;
303 I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans2);
304 reg += 4;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300305}
306
307/* Program DDI buffers translations for DP. By default, program ports A-D in DP
308 * mode and port E for FDI.
309 */
310void intel_prepare_ddi(struct drm_device *dev)
311{
312 int port;
313
Paulo Zanoni0d536cb2012-11-23 16:46:41 -0200314 if (!HAS_DDI(dev))
315 return;
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300316
Paulo Zanoniad8d2702013-08-05 17:25:56 -0300317 for (port = PORT_A; port <= PORT_E; port++)
318 intel_prepare_ddi_buffers(dev, port);
Eugeni Dodonov45244b82012-05-09 15:37:20 -0300319}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300320
Paulo Zanoni248138b2012-11-29 11:29:31 -0200321static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
322 enum port port)
323{
324 uint32_t reg = DDI_BUF_CTL(port);
325 int i;
326
Vandana Kannan3449ca82015-03-27 14:19:09 +0200327 for (i = 0; i < 16; i++) {
Paulo Zanoni248138b2012-11-29 11:29:31 -0200328 udelay(1);
329 if (I915_READ(reg) & DDI_BUF_IS_IDLE)
330 return;
331 }
332 DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
333}
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300334
335/* Starting with Haswell, different DDI ports can work in FDI mode for
336 * connection to the PCH-located connectors. For this, it is necessary to train
337 * both the DDI port and PCH receiver for the desired DDI buffer settings.
338 *
339 * The recommended port to work in FDI mode is DDI E, which we use here. Also,
340 * please note that when FDI mode is active on DDI E, it shares 2 lines with
341 * DDI A (which is used for eDP)
342 */
343
344void hsw_fdi_link_train(struct drm_crtc *crtc)
345{
346 struct drm_device *dev = crtc->dev;
347 struct drm_i915_private *dev_priv = dev->dev_private;
348 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni04945642012-11-01 21:00:59 -0200349 u32 temp, i, rx_ctl_val;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300350
Paulo Zanoni04945642012-11-01 21:00:59 -0200351 /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
352 * mode set "sequence for CRT port" document:
353 * - TP1 to TP2 time with the default value
354 * - FDI delay to 90h
Damien Lespiau8693a822013-05-03 18:48:11 +0100355 *
356 * WaFDIAutoLinkSetTimingOverrride:hsw
Paulo Zanoni04945642012-11-01 21:00:59 -0200357 */
358 I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) |
359 FDI_RX_PWRDN_LANE0_VAL(2) |
360 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
361
362 /* Enable the PCH Receiver FDI PLL */
Damien Lespiau3e683202012-12-11 18:48:29 +0000363 rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
Daniel Vetter33d29b12013-02-13 18:04:45 +0100364 FDI_RX_PLL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200365 FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
Paulo Zanoni04945642012-11-01 21:00:59 -0200366 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
367 POSTING_READ(_FDI_RXA_CTL);
368 udelay(220);
369
370 /* Switch from Rawclk to PCDclk */
371 rx_ctl_val |= FDI_PCDCLK;
372 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
373
374 /* Configure Port Clock Select */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200375 I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config->ddi_pll_sel);
376 WARN_ON(intel_crtc->config->ddi_pll_sel != PORT_CLK_SEL_SPLL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200377
378 /* Start the training iterating through available voltages and emphasis,
379 * testing each value twice. */
Jani Nikula10122052014-08-27 16:27:30 +0300380 for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300381 /* Configure DP_TP_CTL with auto-training */
382 I915_WRITE(DP_TP_CTL(PORT_E),
383 DP_TP_CTL_FDI_AUTOTRAIN |
384 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
385 DP_TP_CTL_LINK_TRAIN_PAT1 |
386 DP_TP_CTL_ENABLE);
387
Damien Lespiau876a8cd2012-12-11 18:48:30 +0000388 /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
389 * DDI E does not support port reversal, the functionality is
390 * achieved on the PCH side in FDI_RX_CTL, so no need to set the
391 * port reversal bit */
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300392 I915_WRITE(DDI_BUF_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200393 DDI_BUF_CTL_ENABLE |
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +0200394 ((intel_crtc->config->fdi_lanes - 1) << 1) |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530395 DDI_BUF_TRANS_SELECT(i / 2));
Paulo Zanoni04945642012-11-01 21:00:59 -0200396 POSTING_READ(DDI_BUF_CTL(PORT_E));
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300397
398 udelay(600);
399
Paulo Zanoni04945642012-11-01 21:00:59 -0200400 /* Program PCH FDI Receiver TU */
401 I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
Eugeni Dodonov4acf5182012-07-04 20:15:16 -0300402
Paulo Zanoni04945642012-11-01 21:00:59 -0200403 /* Enable PCH FDI Receiver with auto-training */
404 rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
405 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
406 POSTING_READ(_FDI_RXA_CTL);
407
408 /* Wait for FDI receiver lane calibration */
409 udelay(30);
410
411 /* Unset FDI_RX_MISC pwrdn lanes */
412 temp = I915_READ(_FDI_RXA_MISC);
413 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
414 I915_WRITE(_FDI_RXA_MISC, temp);
415 POSTING_READ(_FDI_RXA_MISC);
416
417 /* Wait for FDI auto training time */
418 udelay(5);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300419
420 temp = I915_READ(DP_TP_STATUS(PORT_E));
421 if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
Paulo Zanoni04945642012-11-01 21:00:59 -0200422 DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300423
424 /* Enable normal pixel sending for FDI */
425 I915_WRITE(DP_TP_CTL(PORT_E),
Paulo Zanoni04945642012-11-01 21:00:59 -0200426 DP_TP_CTL_FDI_AUTOTRAIN |
427 DP_TP_CTL_LINK_TRAIN_NORMAL |
428 DP_TP_CTL_ENHANCED_FRAME_ENABLE |
429 DP_TP_CTL_ENABLE);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300430
Paulo Zanoni04945642012-11-01 21:00:59 -0200431 return;
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300432 }
Paulo Zanoni04945642012-11-01 21:00:59 -0200433
Paulo Zanoni248138b2012-11-29 11:29:31 -0200434 temp = I915_READ(DDI_BUF_CTL(PORT_E));
435 temp &= ~DDI_BUF_CTL_ENABLE;
436 I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
437 POSTING_READ(DDI_BUF_CTL(PORT_E));
438
Paulo Zanoni04945642012-11-01 21:00:59 -0200439 /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
Paulo Zanoni248138b2012-11-29 11:29:31 -0200440 temp = I915_READ(DP_TP_CTL(PORT_E));
441 temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
442 temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
443 I915_WRITE(DP_TP_CTL(PORT_E), temp);
444 POSTING_READ(DP_TP_CTL(PORT_E));
445
446 intel_wait_ddi_buf_idle(dev_priv, PORT_E);
Paulo Zanoni04945642012-11-01 21:00:59 -0200447
448 rx_ctl_val &= ~FDI_RX_ENABLE;
449 I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200450 POSTING_READ(_FDI_RXA_CTL);
Paulo Zanoni04945642012-11-01 21:00:59 -0200451
452 /* Reset FDI_RX_MISC pwrdn lanes */
453 temp = I915_READ(_FDI_RXA_MISC);
454 temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
455 temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
456 I915_WRITE(_FDI_RXA_MISC, temp);
Paulo Zanoni248138b2012-11-29 11:29:31 -0200457 POSTING_READ(_FDI_RXA_MISC);
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300458 }
459
Paulo Zanoni04945642012-11-01 21:00:59 -0200460 DRM_ERROR("FDI link training failed!\n");
Eugeni Dodonovc82e4d22012-05-09 15:37:21 -0300461}
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -0300462
Dave Airlie44905a272014-05-02 13:36:43 +1000463void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
464{
465 struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
466 struct intel_digital_port *intel_dig_port =
467 enc_to_dig_port(&encoder->base);
468
469 intel_dp->DP = intel_dig_port->saved_port_bits |
Sonika Jindalc5fe6a02014-08-11 08:57:36 +0530470 DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
Dave Airlie44905a272014-05-02 13:36:43 +1000471 intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
472
473}
474
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300475static struct intel_encoder *
476intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
477{
478 struct drm_device *dev = crtc->dev;
479 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
480 struct intel_encoder *intel_encoder, *ret = NULL;
481 int num_encoders = 0;
482
483 for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
484 ret = intel_encoder;
485 num_encoders++;
486 }
487
488 if (num_encoders != 1)
Ville Syrjälä84f44ce2013-04-17 17:48:49 +0300489 WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
490 pipe_name(intel_crtc->pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -0300491
492 BUG_ON(ret == NULL);
493 return ret;
494}
495
Satheeshakrishna Mbcddf612014-08-22 09:49:10 +0530496struct intel_encoder *
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200497intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200498{
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200499 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
500 struct intel_encoder *ret = NULL;
501 struct drm_atomic_state *state;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200502 int num_encoders = 0;
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200503 int i;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200504
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +0200505 state = crtc_state->base.state;
506
507 for (i = 0; i < state->num_connector; i++) {
508 if (!state->connectors[i] ||
509 state->connector_states[i]->crtc != crtc_state->base.crtc)
510 continue;
511
512 ret = to_intel_encoder(state->connector_states[i]->best_encoder);
513 num_encoders++;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +0200514 }
515
516 WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
517 pipe_name(crtc->pipe));
518
519 BUG_ON(ret == NULL);
520 return ret;
521}
522
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100523#define LC_FREQ 2700
Damien Lespiau27893392014-09-04 12:27:23 +0100524#define LC_FREQ_2K U64_C(LC_FREQ * 2000)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100525
526#define P_MIN 2
527#define P_MAX 64
528#define P_INC 2
529
530/* Constraints for PLL good behavior */
531#define REF_MIN 48
532#define REF_MAX 400
533#define VCO_MIN 2400
534#define VCO_MAX 4800
535
Damien Lespiau27893392014-09-04 12:27:23 +0100536#define abs_diff(a, b) ({ \
537 typeof(a) __a = (a); \
538 typeof(b) __b = (b); \
539 (void) (&__a == &__b); \
540 __a > __b ? (__a - __b) : (__b - __a); })
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100541
542struct wrpll_rnp {
543 unsigned p, n2, r2;
544};
545
546static unsigned wrpll_get_budget_for_freq(int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300547{
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100548 unsigned budget;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300549
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100550 switch (clock) {
551 case 25175000:
552 case 25200000:
553 case 27000000:
554 case 27027000:
555 case 37762500:
556 case 37800000:
557 case 40500000:
558 case 40541000:
559 case 54000000:
560 case 54054000:
561 case 59341000:
562 case 59400000:
563 case 72000000:
564 case 74176000:
565 case 74250000:
566 case 81000000:
567 case 81081000:
568 case 89012000:
569 case 89100000:
570 case 108000000:
571 case 108108000:
572 case 111264000:
573 case 111375000:
574 case 148352000:
575 case 148500000:
576 case 162000000:
577 case 162162000:
578 case 222525000:
579 case 222750000:
580 case 296703000:
581 case 297000000:
582 budget = 0;
583 break;
584 case 233500000:
585 case 245250000:
586 case 247750000:
587 case 253250000:
588 case 298000000:
589 budget = 1500;
590 break;
591 case 169128000:
592 case 169500000:
593 case 179500000:
594 case 202000000:
595 budget = 2000;
596 break;
597 case 256250000:
598 case 262500000:
599 case 270000000:
600 case 272500000:
601 case 273750000:
602 case 280750000:
603 case 281250000:
604 case 286000000:
605 case 291750000:
606 budget = 4000;
607 break;
608 case 267250000:
609 case 268500000:
610 budget = 5000;
611 break;
612 default:
613 budget = 1000;
614 break;
615 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300616
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100617 return budget;
618}
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300619
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100620static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
621 unsigned r2, unsigned n2, unsigned p,
622 struct wrpll_rnp *best)
623{
624 uint64_t a, b, c, d, diff, diff_best;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300625
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100626 /* No best (r,n,p) yet */
627 if (best->p == 0) {
628 best->p = p;
629 best->n2 = n2;
630 best->r2 = r2;
631 return;
632 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300633
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100634 /*
635 * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
636 * freq2k.
637 *
638 * delta = 1e6 *
639 * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
640 * freq2k;
641 *
642 * and we would like delta <= budget.
643 *
644 * If the discrepancy is above the PPM-based budget, always prefer to
645 * improve upon the previous solution. However, if you're within the
646 * budget, try to maximize Ref * VCO, that is N / (P * R^2).
647 */
648 a = freq2k * budget * p * r2;
649 b = freq2k * budget * best->p * best->r2;
Damien Lespiau27893392014-09-04 12:27:23 +0100650 diff = abs_diff(freq2k * p * r2, LC_FREQ_2K * n2);
651 diff_best = abs_diff(freq2k * best->p * best->r2,
652 LC_FREQ_2K * best->n2);
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100653 c = 1000000 * diff;
654 d = 1000000 * diff_best;
655
656 if (a < c && b < d) {
657 /* If both are above the budget, pick the closer */
658 if (best->p * best->r2 * diff < p * r2 * diff_best) {
659 best->p = p;
660 best->n2 = n2;
661 best->r2 = r2;
662 }
663 } else if (a >= c && b < d) {
664 /* If A is below the threshold but B is above it? Update. */
665 best->p = p;
666 best->n2 = n2;
667 best->r2 = r2;
668 } else if (a >= c && b >= d) {
669 /* Both are below the limit, so pick the higher n2/(r2*r2) */
670 if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
671 best->p = p;
672 best->n2 = n2;
673 best->r2 = r2;
674 }
675 }
676 /* Otherwise a < c && b >= d, do nothing */
677}
678
Jesse Barnes11578552014-01-21 12:42:10 -0800679static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
680 int reg)
681{
682 int refclk = LC_FREQ;
683 int n, p, r;
684 u32 wrpll;
685
686 wrpll = I915_READ(reg);
Daniel Vetter114fe482014-06-25 22:01:48 +0300687 switch (wrpll & WRPLL_PLL_REF_MASK) {
688 case WRPLL_PLL_SSC:
689 case WRPLL_PLL_NON_SSC:
Jesse Barnes11578552014-01-21 12:42:10 -0800690 /*
691 * We could calculate spread here, but our checking
692 * code only cares about 5% accuracy, and spread is a max of
693 * 0.5% downspread.
694 */
695 refclk = 135;
696 break;
Daniel Vetter114fe482014-06-25 22:01:48 +0300697 case WRPLL_PLL_LCPLL:
Jesse Barnes11578552014-01-21 12:42:10 -0800698 refclk = LC_FREQ;
699 break;
700 default:
701 WARN(1, "bad wrpll refclk\n");
702 return 0;
703 }
704
705 r = wrpll & WRPLL_DIVIDER_REF_MASK;
706 p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
707 n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
708
Jesse Barnes20f0ec12014-01-22 12:58:04 -0800709 /* Convert to KHz, p & r have a fixed point portion */
710 return (refclk * n * 100) / (p * r);
Jesse Barnes11578552014-01-21 12:42:10 -0800711}
712
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000713static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
714 uint32_t dpll)
715{
716 uint32_t cfgcr1_reg, cfgcr2_reg;
717 uint32_t cfgcr1_val, cfgcr2_val;
718 uint32_t p0, p1, p2, dco_freq;
719
720 cfgcr1_reg = GET_CFG_CR1_REG(dpll);
721 cfgcr2_reg = GET_CFG_CR2_REG(dpll);
722
723 cfgcr1_val = I915_READ(cfgcr1_reg);
724 cfgcr2_val = I915_READ(cfgcr2_reg);
725
726 p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
727 p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
728
729 if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
730 p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
731 else
732 p1 = 1;
733
734
735 switch (p0) {
736 case DPLL_CFGCR2_PDIV_1:
737 p0 = 1;
738 break;
739 case DPLL_CFGCR2_PDIV_2:
740 p0 = 2;
741 break;
742 case DPLL_CFGCR2_PDIV_3:
743 p0 = 3;
744 break;
745 case DPLL_CFGCR2_PDIV_7:
746 p0 = 7;
747 break;
748 }
749
750 switch (p2) {
751 case DPLL_CFGCR2_KDIV_5:
752 p2 = 5;
753 break;
754 case DPLL_CFGCR2_KDIV_2:
755 p2 = 2;
756 break;
757 case DPLL_CFGCR2_KDIV_3:
758 p2 = 3;
759 break;
760 case DPLL_CFGCR2_KDIV_1:
761 p2 = 1;
762 break;
763 }
764
765 dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
766
767 dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
768 1000) / 0x8000;
769
770 return dco_freq / (p0 * p1 * p2 * 5);
771}
772
773
774static void skl_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200775 struct intel_crtc_state *pipe_config)
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000776{
777 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000778 int link_clock = 0;
779 uint32_t dpll_ctl1, dpll;
780
Damien Lespiau134ffa42014-11-14 17:24:34 +0000781 dpll = pipe_config->ddi_pll_sel;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000782
783 dpll_ctl1 = I915_READ(DPLL_CTRL1);
784
785 if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
786 link_clock = skl_calc_wrpll_link(dev_priv, dpll);
787 } else {
788 link_clock = dpll_ctl1 & DPLL_CRTL1_LINK_RATE_MASK(dpll);
789 link_clock >>= DPLL_CRTL1_LINK_RATE_SHIFT(dpll);
790
791 switch (link_clock) {
792 case DPLL_CRTL1_LINK_RATE_810:
793 link_clock = 81000;
794 break;
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530795 case DPLL_CRTL1_LINK_RATE_1080:
796 link_clock = 108000;
797 break;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000798 case DPLL_CRTL1_LINK_RATE_1350:
799 link_clock = 135000;
800 break;
Sonika Jindala8f3ef62015-03-05 10:02:30 +0530801 case DPLL_CRTL1_LINK_RATE_1620:
802 link_clock = 162000;
803 break;
804 case DPLL_CRTL1_LINK_RATE_2160:
805 link_clock = 216000;
806 break;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000807 case DPLL_CRTL1_LINK_RATE_2700:
808 link_clock = 270000;
809 break;
810 default:
811 WARN(1, "Unsupported link rate\n");
812 break;
813 }
814 link_clock *= 2;
815 }
816
817 pipe_config->port_clock = link_clock;
818
819 if (pipe_config->has_dp_encoder)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200820 pipe_config->base.adjusted_mode.crtc_clock =
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000821 intel_dotclock_calculate(pipe_config->port_clock,
822 &pipe_config->dp_m_n);
823 else
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200824 pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
Satheeshakrishna M540e7322014-11-13 14:55:16 +0000825}
826
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200827static void hsw_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200828 struct intel_crtc_state *pipe_config)
Jesse Barnes11578552014-01-21 12:42:10 -0800829{
830 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
Jesse Barnes11578552014-01-21 12:42:10 -0800831 int link_clock = 0;
832 u32 val, pll;
833
Daniel Vetter26804af2014-06-25 22:01:55 +0300834 val = pipe_config->ddi_pll_sel;
Jesse Barnes11578552014-01-21 12:42:10 -0800835 switch (val & PORT_CLK_SEL_MASK) {
836 case PORT_CLK_SEL_LCPLL_810:
837 link_clock = 81000;
838 break;
839 case PORT_CLK_SEL_LCPLL_1350:
840 link_clock = 135000;
841 break;
842 case PORT_CLK_SEL_LCPLL_2700:
843 link_clock = 270000;
844 break;
845 case PORT_CLK_SEL_WRPLL1:
846 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
847 break;
848 case PORT_CLK_SEL_WRPLL2:
849 link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
850 break;
851 case PORT_CLK_SEL_SPLL:
852 pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
853 if (pll == SPLL_PLL_FREQ_810MHz)
854 link_clock = 81000;
855 else if (pll == SPLL_PLL_FREQ_1350MHz)
856 link_clock = 135000;
857 else if (pll == SPLL_PLL_FREQ_2700MHz)
858 link_clock = 270000;
859 else {
860 WARN(1, "bad spll freq\n");
861 return;
862 }
863 break;
864 default:
865 WARN(1, "bad port clock sel\n");
866 return;
867 }
868
869 pipe_config->port_clock = link_clock * 2;
870
871 if (pipe_config->has_pch_encoder)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200872 pipe_config->base.adjusted_mode.crtc_clock =
Jesse Barnes11578552014-01-21 12:42:10 -0800873 intel_dotclock_calculate(pipe_config->port_clock,
874 &pipe_config->fdi_m_n);
875 else if (pipe_config->has_dp_encoder)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200876 pipe_config->base.adjusted_mode.crtc_clock =
Jesse Barnes11578552014-01-21 12:42:10 -0800877 intel_dotclock_calculate(pipe_config->port_clock,
878 &pipe_config->dp_m_n);
879 else
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +0200880 pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
Jesse Barnes11578552014-01-21 12:42:10 -0800881}
882
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530883static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
884 enum intel_dpll_id dpll)
885{
886 /* FIXME formula not available in bspec */
887 return 0;
888}
889
890static void bxt_ddi_clock_get(struct intel_encoder *encoder,
891 struct intel_crtc_state *pipe_config)
892{
893 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
894 enum port port = intel_ddi_get_encoder_port(encoder);
895 uint32_t dpll = port;
896
897 pipe_config->port_clock =
898 bxt_calc_pll_link(dev_priv, dpll);
899
900 if (pipe_config->has_dp_encoder)
901 pipe_config->base.adjusted_mode.crtc_clock =
902 intel_dotclock_calculate(pipe_config->port_clock,
903 &pipe_config->dp_m_n);
904 else
905 pipe_config->base.adjusted_mode.crtc_clock =
906 pipe_config->port_clock;
907}
908
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200909void intel_ddi_clock_get(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200910 struct intel_crtc_state *pipe_config)
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200911{
Damien Lespiau22606a12014-12-12 14:26:57 +0000912 struct drm_device *dev = encoder->base.dev;
913
914 if (INTEL_INFO(dev)->gen <= 8)
915 hsw_ddi_clock_get(encoder, pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530916 else if (IS_SKYLAKE(dev))
Damien Lespiau22606a12014-12-12 14:26:57 +0000917 skl_ddi_clock_get(encoder, pipe_config);
Satheeshakrishna M977bb382014-08-22 09:49:12 +0530918 else if (IS_BROXTON(dev))
919 bxt_ddi_clock_get(encoder, pipe_config);
Daniel Vetter3d51278a2014-07-29 20:57:08 +0200920}
921
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100922static void
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100923hsw_ddi_calculate_wrpll(int clock /* in Hz */,
924 unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100925{
926 uint64_t freq2k;
927 unsigned p, n2, r2;
928 struct wrpll_rnp best = { 0, 0, 0 };
929 unsigned budget;
930
931 freq2k = clock / 100;
932
933 budget = wrpll_get_budget_for_freq(clock);
934
935 /* Special case handling for 540 pixel clock: bypass WR PLL entirely
936 * and directly pass the LC PLL to it. */
937 if (freq2k == 5400000) {
938 *n2_out = 2;
939 *p_out = 1;
940 *r2_out = 2;
941 return;
942 }
943
944 /*
945 * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
946 * the WR PLL.
947 *
948 * We want R so that REF_MIN <= Ref <= REF_MAX.
949 * Injecting R2 = 2 * R gives:
950 * REF_MAX * r2 > LC_FREQ * 2 and
951 * REF_MIN * r2 < LC_FREQ * 2
952 *
953 * Which means the desired boundaries for r2 are:
954 * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
955 *
956 */
957 for (r2 = LC_FREQ * 2 / REF_MAX + 1;
958 r2 <= LC_FREQ * 2 / REF_MIN;
959 r2++) {
960
961 /*
962 * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
963 *
964 * Once again we want VCO_MIN <= VCO <= VCO_MAX.
965 * Injecting R2 = 2 * R and N2 = 2 * N, we get:
966 * VCO_MAX * r2 > n2 * LC_FREQ and
967 * VCO_MIN * r2 < n2 * LC_FREQ)
968 *
969 * Which means the desired boundaries for n2 are:
970 * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
971 */
972 for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
973 n2 <= VCO_MAX * r2 / LC_FREQ;
974 n2++) {
975
976 for (p = P_MIN; p <= P_MAX; p += P_INC)
977 wrpll_update_rnp(freq2k, budget,
978 r2, n2, p, &best);
979 }
980 }
981
982 *n2_out = best.n2;
983 *p_out = best.p;
984 *r2_out = best.r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300985}
986
Damien Lespiau0220ab62014-07-29 18:06:22 +0100987static bool
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100988hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +0200989 struct intel_crtc_state *crtc_state,
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100990 struct intel_encoder *intel_encoder,
991 int clock)
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300992{
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100993 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
Daniel Vettere0b01be2014-06-25 22:02:01 +0300994 struct intel_shared_dpll *pll;
Daniel Vetter716c2e52014-06-25 22:02:02 +0300995 uint32_t val;
Damien Lespiau1c0b85c2013-05-10 14:01:51 +0100996 unsigned p, n2, r2;
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300997
Damien Lespiaud664c0c2014-07-29 18:06:23 +0100998 hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
Paulo Zanoni6441ab52012-10-05 12:05:58 -0300999
Daniel Vetter114fe482014-06-25 22:01:48 +03001000 val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001001 WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
1002 WRPLL_DIVIDER_POST(p);
1003
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001004 crtc_state->dpll_hw_state.wrpll = val;
Daniel Vetter716c2e52014-06-25 22:02:02 +03001005
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001006 pll = intel_get_shared_dpll(intel_crtc, crtc_state);
Daniel Vetter716c2e52014-06-25 22:02:02 +03001007 if (pll == NULL) {
1008 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1009 pipe_name(intel_crtc->pipe));
Paulo Zanoni06940012013-10-30 18:27:43 -02001010 return false;
1011 }
1012
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001013 crtc_state->ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001014 }
1015
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001016 return true;
1017}
1018
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001019struct skl_wrpll_params {
1020 uint32_t dco_fraction;
1021 uint32_t dco_integer;
1022 uint32_t qdiv_ratio;
1023 uint32_t qdiv_mode;
1024 uint32_t kdiv;
1025 uint32_t pdiv;
1026 uint32_t central_freq;
1027};
1028
1029static void
1030skl_ddi_calculate_wrpll(int clock /* in Hz */,
1031 struct skl_wrpll_params *wrpll_params)
1032{
1033 uint64_t afe_clock = clock * 5; /* AFE Clock is 5x Pixel clock */
Damien Lespiau21318cc2014-11-14 14:20:27 +00001034 uint64_t dco_central_freq[3] = {8400000000ULL,
1035 9000000000ULL,
1036 9600000000ULL};
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001037 uint32_t min_dco_deviation = 400;
1038 uint32_t min_dco_index = 3;
1039 uint32_t P0[4] = {1, 2, 3, 7};
1040 uint32_t P2[4] = {1, 2, 3, 5};
1041 bool found = false;
1042 uint32_t candidate_p = 0;
1043 uint32_t candidate_p0[3] = {0}, candidate_p1[3] = {0};
1044 uint32_t candidate_p2[3] = {0};
1045 uint32_t dco_central_freq_deviation[3];
1046 uint32_t i, P1, k, dco_count;
1047 bool retry_with_odd = false;
1048 uint64_t dco_freq;
1049
1050 /* Determine P0, P1 or P2 */
1051 for (dco_count = 0; dco_count < 3; dco_count++) {
1052 found = false;
1053 candidate_p =
1054 div64_u64(dco_central_freq[dco_count], afe_clock);
1055 if (retry_with_odd == false)
1056 candidate_p = (candidate_p % 2 == 0 ?
1057 candidate_p : candidate_p + 1);
1058
1059 for (P1 = 1; P1 < candidate_p; P1++) {
1060 for (i = 0; i < 4; i++) {
1061 if (!(P0[i] != 1 || P1 == 1))
1062 continue;
1063
1064 for (k = 0; k < 4; k++) {
1065 if (P1 != 1 && P2[k] != 2)
1066 continue;
1067
1068 if (candidate_p == P0[i] * P1 * P2[k]) {
1069 /* Found possible P0, P1, P2 */
1070 found = true;
1071 candidate_p0[dco_count] = P0[i];
1072 candidate_p1[dco_count] = P1;
1073 candidate_p2[dco_count] = P2[k];
1074 goto found;
1075 }
1076
1077 }
1078 }
1079 }
1080
1081found:
1082 if (found) {
1083 dco_central_freq_deviation[dco_count] =
1084 div64_u64(10000 *
1085 abs_diff((candidate_p * afe_clock),
1086 dco_central_freq[dco_count]),
1087 dco_central_freq[dco_count]);
1088
1089 if (dco_central_freq_deviation[dco_count] <
1090 min_dco_deviation) {
1091 min_dco_deviation =
1092 dco_central_freq_deviation[dco_count];
1093 min_dco_index = dco_count;
1094 }
1095 }
1096
1097 if (min_dco_index > 2 && dco_count == 2) {
1098 retry_with_odd = true;
1099 dco_count = 0;
1100 }
1101 }
1102
1103 if (min_dco_index > 2) {
1104 WARN(1, "No valid values found for the given pixel clock\n");
1105 } else {
1106 wrpll_params->central_freq = dco_central_freq[min_dco_index];
1107
1108 switch (dco_central_freq[min_dco_index]) {
Damien Lespiau21318cc2014-11-14 14:20:27 +00001109 case 9600000000ULL:
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001110 wrpll_params->central_freq = 0;
1111 break;
Damien Lespiau21318cc2014-11-14 14:20:27 +00001112 case 9000000000ULL:
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001113 wrpll_params->central_freq = 1;
1114 break;
Damien Lespiau21318cc2014-11-14 14:20:27 +00001115 case 8400000000ULL:
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001116 wrpll_params->central_freq = 3;
1117 }
1118
1119 switch (candidate_p0[min_dco_index]) {
1120 case 1:
1121 wrpll_params->pdiv = 0;
1122 break;
1123 case 2:
1124 wrpll_params->pdiv = 1;
1125 break;
1126 case 3:
1127 wrpll_params->pdiv = 2;
1128 break;
1129 case 7:
1130 wrpll_params->pdiv = 4;
1131 break;
1132 default:
1133 WARN(1, "Incorrect PDiv\n");
1134 }
1135
1136 switch (candidate_p2[min_dco_index]) {
1137 case 5:
1138 wrpll_params->kdiv = 0;
1139 break;
1140 case 2:
1141 wrpll_params->kdiv = 1;
1142 break;
1143 case 3:
1144 wrpll_params->kdiv = 2;
1145 break;
1146 case 1:
1147 wrpll_params->kdiv = 3;
1148 break;
1149 default:
1150 WARN(1, "Incorrect KDiv\n");
1151 }
1152
1153 wrpll_params->qdiv_ratio = candidate_p1[min_dco_index];
1154 wrpll_params->qdiv_mode =
1155 (wrpll_params->qdiv_ratio == 1) ? 0 : 1;
1156
1157 dco_freq = candidate_p0[min_dco_index] *
1158 candidate_p1[min_dco_index] *
1159 candidate_p2[min_dco_index] * afe_clock;
1160
1161 /*
1162 * Intermediate values are in Hz.
1163 * Divide by MHz to match bsepc
1164 */
1165 wrpll_params->dco_integer = div_u64(dco_freq, (24 * MHz(1)));
1166 wrpll_params->dco_fraction =
1167 div_u64(((div_u64(dco_freq, 24) -
1168 wrpll_params->dco_integer * MHz(1)) * 0x8000), MHz(1));
1169
1170 }
1171}
1172
1173
1174static bool
1175skl_ddi_pll_select(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001176 struct intel_crtc_state *crtc_state,
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001177 struct intel_encoder *intel_encoder,
1178 int clock)
1179{
1180 struct intel_shared_dpll *pll;
1181 uint32_t ctrl1, cfgcr1, cfgcr2;
1182
1183 /*
1184 * See comment in intel_dpll_hw_state to understand why we always use 0
1185 * as the DPLL id in this function.
1186 */
1187
1188 ctrl1 = DPLL_CTRL1_OVERRIDE(0);
1189
1190 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
1191 struct skl_wrpll_params wrpll_params = { 0, };
1192
1193 ctrl1 |= DPLL_CTRL1_HDMI_MODE(0);
1194
1195 skl_ddi_calculate_wrpll(clock * 1000, &wrpll_params);
1196
1197 cfgcr1 = DPLL_CFGCR1_FREQ_ENABLE |
1198 DPLL_CFGCR1_DCO_FRACTION(wrpll_params.dco_fraction) |
1199 wrpll_params.dco_integer;
1200
1201 cfgcr2 = DPLL_CFGCR2_QDIV_RATIO(wrpll_params.qdiv_ratio) |
1202 DPLL_CFGCR2_QDIV_MODE(wrpll_params.qdiv_mode) |
1203 DPLL_CFGCR2_KDIV(wrpll_params.kdiv) |
1204 DPLL_CFGCR2_PDIV(wrpll_params.pdiv) |
1205 wrpll_params.central_freq;
1206 } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) {
1207 struct drm_encoder *encoder = &intel_encoder->base;
1208 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1209
1210 switch (intel_dp->link_bw) {
1211 case DP_LINK_BW_1_62:
1212 ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_810, 0);
1213 break;
1214 case DP_LINK_BW_2_7:
1215 ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_1350, 0);
1216 break;
1217 case DP_LINK_BW_5_4:
1218 ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_2700, 0);
1219 break;
1220 }
1221
1222 cfgcr1 = cfgcr2 = 0;
1223 } else /* eDP */
1224 return true;
1225
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001226 crtc_state->dpll_hw_state.ctrl1 = ctrl1;
1227 crtc_state->dpll_hw_state.cfgcr1 = cfgcr1;
1228 crtc_state->dpll_hw_state.cfgcr2 = cfgcr2;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001229
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001230 pll = intel_get_shared_dpll(intel_crtc, crtc_state);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001231 if (pll == NULL) {
1232 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1233 pipe_name(intel_crtc->pipe));
1234 return false;
1235 }
1236
1237 /* shared DPLL id 0 is DPLL 1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001238 crtc_state->ddi_pll_sel = pll->id + 1;
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001239
1240 return true;
1241}
Damien Lespiau0220ab62014-07-29 18:06:22 +01001242
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301243/* bxt clock parameters */
1244struct bxt_clk_div {
1245 uint32_t p1;
1246 uint32_t p2;
1247 uint32_t m2_int;
1248 uint32_t m2_frac;
1249 bool m2_frac_en;
1250 uint32_t n;
1251 uint32_t prop_coef;
1252 uint32_t int_coef;
1253 uint32_t gain_ctl;
1254 uint32_t targ_cnt;
1255 uint32_t lanestagger;
1256};
1257
1258/* pre-calculated values for DP linkrates */
1259static struct bxt_clk_div bxt_dp_clk_val[7] = {
1260 /* 162 */ {4, 2, 32, 1677722, 1, 1, 5, 11, 2, 9, 0xd},
1261 /* 270 */ {4, 1, 27, 0, 0, 1, 3, 8, 1, 9, 0xd},
1262 /* 540 */ {2, 1, 27, 0, 0, 1, 3, 8, 1, 9, 0x18},
1263 /* 216 */ {3, 2, 32, 1677722, 1, 1, 5, 11, 2, 9, 0xd},
1264 /* 243 */ {4, 1, 24, 1258291, 1, 1, 5, 11, 2, 9, 0xd},
1265 /* 324 */ {4, 1, 32, 1677722, 1, 1, 5, 11, 2, 9, 0xd},
1266 /* 432 */ {3, 1, 32, 1677722, 1, 1, 5, 11, 2, 9, 0x18}
1267};
1268
1269static bool
1270bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
1271 struct intel_crtc_state *crtc_state,
1272 struct intel_encoder *intel_encoder,
1273 int clock)
1274{
1275 struct intel_shared_dpll *pll;
1276 struct bxt_clk_div clk_div = {0};
1277
1278 if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
1279 intel_clock_t best_clock;
1280
1281 /* Calculate HDMI div */
1282 /*
1283 * FIXME: tie the following calculation into
1284 * i9xx_crtc_compute_clock
1285 */
1286 if (!bxt_find_best_dpll(crtc_state, clock, &best_clock)) {
1287 DRM_DEBUG_DRIVER("no PLL dividers found for clock %d pipe %c\n",
1288 clock, pipe_name(intel_crtc->pipe));
1289 return false;
1290 }
1291
1292 clk_div.p1 = best_clock.p1;
1293 clk_div.p2 = best_clock.p2;
1294 WARN_ON(best_clock.m1 != 2);
1295 clk_div.n = best_clock.n;
1296 clk_div.m2_int = best_clock.m2 >> 22;
1297 clk_div.m2_frac = best_clock.m2 & ((1 << 22) - 1);
1298 clk_div.m2_frac_en = clk_div.m2_frac != 0;
1299
1300 /* FIXME: set coef, gain, targcnt based on freq band */
1301 clk_div.prop_coef = 5;
1302 clk_div.int_coef = 11;
1303 clk_div.gain_ctl = 2;
1304 clk_div.targ_cnt = 9;
1305 if (clock > 270000)
1306 clk_div.lanestagger = 0x18;
1307 else if (clock > 135000)
1308 clk_div.lanestagger = 0x0d;
1309 else if (clock > 67000)
1310 clk_div.lanestagger = 0x07;
1311 else if (clock > 33000)
1312 clk_div.lanestagger = 0x04;
1313 else
1314 clk_div.lanestagger = 0x02;
1315 } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
1316 intel_encoder->type == INTEL_OUTPUT_EDP) {
1317 struct drm_encoder *encoder = &intel_encoder->base;
1318 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1319
1320 switch (intel_dp->link_bw) {
1321 case DP_LINK_BW_1_62:
1322 clk_div = bxt_dp_clk_val[0];
1323 break;
1324 case DP_LINK_BW_2_7:
1325 clk_div = bxt_dp_clk_val[1];
1326 break;
1327 case DP_LINK_BW_5_4:
1328 clk_div = bxt_dp_clk_val[2];
1329 break;
1330 default:
1331 clk_div = bxt_dp_clk_val[0];
1332 DRM_ERROR("Unknown link rate\n");
1333 }
1334 }
1335
1336 crtc_state->dpll_hw_state.ebb0 =
1337 PORT_PLL_P1(clk_div.p1) | PORT_PLL_P2(clk_div.p2);
1338 crtc_state->dpll_hw_state.pll0 = clk_div.m2_int;
1339 crtc_state->dpll_hw_state.pll1 = PORT_PLL_N(clk_div.n);
1340 crtc_state->dpll_hw_state.pll2 = clk_div.m2_frac;
1341
1342 if (clk_div.m2_frac_en)
1343 crtc_state->dpll_hw_state.pll3 =
1344 PORT_PLL_M2_FRAC_ENABLE;
1345
1346 crtc_state->dpll_hw_state.pll6 =
1347 clk_div.prop_coef | PORT_PLL_INT_COEFF(clk_div.int_coef);
1348 crtc_state->dpll_hw_state.pll6 |=
1349 PORT_PLL_GAIN_CTL(clk_div.gain_ctl);
1350
1351 crtc_state->dpll_hw_state.pll8 = clk_div.targ_cnt;
1352
1353 crtc_state->dpll_hw_state.pcsdw12 =
1354 LANESTAGGER_STRAP_OVRD | clk_div.lanestagger;
1355
1356 pll = intel_get_shared_dpll(intel_crtc, crtc_state);
1357 if (pll == NULL) {
1358 DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
1359 pipe_name(intel_crtc->pipe));
1360 return false;
1361 }
1362
1363 /* shared DPLL id 0 is DPLL A */
1364 crtc_state->ddi_pll_sel = pll->id;
1365
1366 return true;
1367}
1368
Damien Lespiau0220ab62014-07-29 18:06:22 +01001369/*
1370 * Tries to find a *shared* PLL for the CRTC and store it in
1371 * intel_crtc->ddi_pll_sel.
1372 *
1373 * For private DPLLs, compute_config() should do the selection for us. This
1374 * function should be folded into compute_config() eventually.
1375 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001376bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
1377 struct intel_crtc_state *crtc_state)
Damien Lespiau0220ab62014-07-29 18:06:22 +01001378{
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001379 struct drm_device *dev = intel_crtc->base.dev;
Ander Conselvan de Oliveirad0737e12014-10-29 11:32:30 +02001380 struct intel_encoder *intel_encoder =
Ander Conselvan de Oliveira3165c072015-03-20 16:18:12 +02001381 intel_ddi_get_crtc_new_encoder(crtc_state);
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001382 int clock = crtc_state->port_clock;
Damien Lespiau0220ab62014-07-29 18:06:22 +01001383
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001384 if (IS_SKYLAKE(dev))
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001385 return skl_ddi_pll_select(intel_crtc, crtc_state,
1386 intel_encoder, clock);
Satheeshakrishna Md683f3b2014-08-22 09:49:08 +05301387 else if (IS_BROXTON(dev))
1388 return bxt_ddi_pll_select(intel_crtc, crtc_state,
1389 intel_encoder, clock);
Satheeshakrishna M82d35432014-11-13 14:55:20 +00001390 else
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02001391 return hsw_ddi_pll_select(intel_crtc, crtc_state,
1392 intel_encoder, clock);
Damien Lespiau0220ab62014-07-29 18:06:22 +01001393}
1394
Paulo Zanonidae84792012-10-15 15:51:30 -03001395void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
1396{
1397 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1398 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1399 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001400 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonidae84792012-10-15 15:51:30 -03001401 int type = intel_encoder->type;
1402 uint32_t temp;
1403
Dave Airlie0e32b392014-05-02 14:02:48 +10001404 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
Paulo Zanonic9809792012-10-23 18:30:00 -02001405 temp = TRANS_MSA_SYNC_CLK;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001406 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidae84792012-10-15 15:51:30 -03001407 case 18:
Paulo Zanonic9809792012-10-23 18:30:00 -02001408 temp |= TRANS_MSA_6_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001409 break;
1410 case 24:
Paulo Zanonic9809792012-10-23 18:30:00 -02001411 temp |= TRANS_MSA_8_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001412 break;
1413 case 30:
Paulo Zanonic9809792012-10-23 18:30:00 -02001414 temp |= TRANS_MSA_10_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001415 break;
1416 case 36:
Paulo Zanonic9809792012-10-23 18:30:00 -02001417 temp |= TRANS_MSA_12_BPC;
Paulo Zanonidae84792012-10-15 15:51:30 -03001418 break;
1419 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001420 BUG();
Paulo Zanonidae84792012-10-15 15:51:30 -03001421 }
Paulo Zanonic9809792012-10-23 18:30:00 -02001422 I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
Paulo Zanonidae84792012-10-15 15:51:30 -03001423 }
1424}
1425
Dave Airlie0e32b392014-05-02 14:02:48 +10001426void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
1427{
1428 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1429 struct drm_device *dev = crtc->dev;
1430 struct drm_i915_private *dev_priv = dev->dev_private;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001431 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Dave Airlie0e32b392014-05-02 14:02:48 +10001432 uint32_t temp;
1433 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1434 if (state == true)
1435 temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1436 else
1437 temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
1438 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
1439}
1440
Damien Lespiau8228c252013-03-07 15:30:27 +00001441void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001442{
1443 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1444 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001445 struct drm_encoder *encoder = &intel_encoder->base;
Paulo Zanonic7670b12013-11-02 21:07:37 -07001446 struct drm_device *dev = crtc->dev;
1447 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001448 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001449 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001450 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni7739c332012-10-15 15:51:29 -03001451 int type = intel_encoder->type;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001452 uint32_t temp;
1453
Paulo Zanoniad80a812012-10-24 16:06:19 -02001454 /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
1455 temp = TRANS_DDI_FUNC_ENABLE;
Paulo Zanoni174edf12012-10-26 19:05:50 -02001456 temp |= TRANS_DDI_SELECT_PORT(port);
Paulo Zanonidfcef252012-08-08 14:15:29 -03001457
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001458 switch (intel_crtc->config->pipe_bpp) {
Paulo Zanonidfcef252012-08-08 14:15:29 -03001459 case 18:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001460 temp |= TRANS_DDI_BPC_6;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001461 break;
1462 case 24:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001463 temp |= TRANS_DDI_BPC_8;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001464 break;
1465 case 30:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001466 temp |= TRANS_DDI_BPC_10;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001467 break;
1468 case 36:
Paulo Zanoniad80a812012-10-24 16:06:19 -02001469 temp |= TRANS_DDI_BPC_12;
Paulo Zanonidfcef252012-08-08 14:15:29 -03001470 break;
1471 default:
Daniel Vetter4e53c2e2013-03-27 00:44:58 +01001472 BUG();
Paulo Zanonidfcef252012-08-08 14:15:29 -03001473 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001474
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001475 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001476 temp |= TRANS_DDI_PVSYNC;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001477 if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001478 temp |= TRANS_DDI_PHSYNC;
Paulo Zanonif63eb7c42012-08-08 14:15:28 -03001479
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001480 if (cpu_transcoder == TRANSCODER_EDP) {
1481 switch (pipe) {
1482 case PIPE_A:
Paulo Zanonic7670b12013-11-02 21:07:37 -07001483 /* On Haswell, can only use the always-on power well for
1484 * eDP when not using the panel fitter, and when not
1485 * using motion blur mitigation (which we don't
1486 * support). */
Daniel Vetterfabf6e52014-05-29 14:10:22 +02001487 if (IS_HASWELL(dev) &&
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001488 (intel_crtc->config->pch_pfit.enabled ||
1489 intel_crtc->config->pch_pfit.force_thru))
Daniel Vetterd6dd9eb2013-01-29 16:35:20 -02001490 temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
1491 else
1492 temp |= TRANS_DDI_EDP_INPUT_A_ON;
Paulo Zanonie6f0bfc2012-10-23 18:30:04 -02001493 break;
1494 case PIPE_B:
1495 temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
1496 break;
1497 case PIPE_C:
1498 temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
1499 break;
1500 default:
1501 BUG();
1502 break;
1503 }
1504 }
1505
Paulo Zanoni7739c332012-10-15 15:51:29 -03001506 if (type == INTEL_OUTPUT_HDMI) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001507 if (intel_crtc->config->has_hdmi_sink)
Paulo Zanoniad80a812012-10-24 16:06:19 -02001508 temp |= TRANS_DDI_MODE_SELECT_HDMI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001509 else
Paulo Zanoniad80a812012-10-24 16:06:19 -02001510 temp |= TRANS_DDI_MODE_SELECT_DVI;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001511
Paulo Zanoni7739c332012-10-15 15:51:29 -03001512 } else if (type == INTEL_OUTPUT_ANALOG) {
Paulo Zanoniad80a812012-10-24 16:06:19 -02001513 temp |= TRANS_DDI_MODE_SELECT_FDI;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001514 temp |= (intel_crtc->config->fdi_lanes - 1) << 1;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001515
1516 } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
1517 type == INTEL_OUTPUT_EDP) {
1518 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1519
Dave Airlie0e32b392014-05-02 14:02:48 +10001520 if (intel_dp->is_mst) {
1521 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
1522 } else
1523 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
1524
1525 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
1526 } else if (type == INTEL_OUTPUT_DP_MST) {
1527 struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
1528
1529 if (intel_dp->is_mst) {
1530 temp |= TRANS_DDI_MODE_SELECT_DP_MST;
1531 } else
1532 temp |= TRANS_DDI_MODE_SELECT_DP_SST;
Paulo Zanoni7739c332012-10-15 15:51:29 -03001533
Daniel Vetter17aa6be2013-04-30 14:01:40 +02001534 temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001535 } else {
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001536 WARN(1, "Invalid encoder type %d for pipe %c\n",
1537 intel_encoder->type, pipe_name(pipe));
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001538 }
1539
Paulo Zanoniad80a812012-10-24 16:06:19 -02001540 I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001541}
1542
Paulo Zanoniad80a812012-10-24 16:06:19 -02001543void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
1544 enum transcoder cpu_transcoder)
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001545{
Paulo Zanoniad80a812012-10-24 16:06:19 -02001546 uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001547 uint32_t val = I915_READ(reg);
1548
Dave Airlie0e32b392014-05-02 14:02:48 +10001549 val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
Paulo Zanoniad80a812012-10-24 16:06:19 -02001550 val |= TRANS_DDI_PORT_NONE;
Paulo Zanoni8d9ddbc2012-10-05 12:05:53 -03001551 I915_WRITE(reg, val);
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001552}
1553
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001554bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
1555{
1556 struct drm_device *dev = intel_connector->base.dev;
1557 struct drm_i915_private *dev_priv = dev->dev_private;
1558 struct intel_encoder *intel_encoder = intel_connector->encoder;
1559 int type = intel_connector->base.connector_type;
1560 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1561 enum pipe pipe = 0;
1562 enum transcoder cpu_transcoder;
Paulo Zanoni882244a2014-04-01 14:55:12 -03001563 enum intel_display_power_domain power_domain;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001564 uint32_t tmp;
1565
Paulo Zanoni882244a2014-04-01 14:55:12 -03001566 power_domain = intel_display_port_power_domain(intel_encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001567 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Paulo Zanoni882244a2014-04-01 14:55:12 -03001568 return false;
1569
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001570 if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
1571 return false;
1572
1573 if (port == PORT_A)
1574 cpu_transcoder = TRANSCODER_EDP;
1575 else
Daniel Vetter1a240d42012-11-29 22:18:51 +01001576 cpu_transcoder = (enum transcoder) pipe;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001577
1578 tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
1579
1580 switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
1581 case TRANS_DDI_MODE_SELECT_HDMI:
1582 case TRANS_DDI_MODE_SELECT_DVI:
1583 return (type == DRM_MODE_CONNECTOR_HDMIA);
1584
1585 case TRANS_DDI_MODE_SELECT_DP_SST:
1586 if (type == DRM_MODE_CONNECTOR_eDP)
1587 return true;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001588 return (type == DRM_MODE_CONNECTOR_DisplayPort);
Dave Airlie0e32b392014-05-02 14:02:48 +10001589 case TRANS_DDI_MODE_SELECT_DP_MST:
1590 /* if the transcoder is in MST state then
1591 * connector isn't connected */
1592 return false;
Paulo Zanonibcbc8892012-10-26 19:05:51 -02001593
1594 case TRANS_DDI_MODE_SELECT_FDI:
1595 return (type == DRM_MODE_CONNECTOR_VGA);
1596
1597 default:
1598 return false;
1599 }
1600}
1601
Daniel Vetter85234cd2012-07-02 13:27:29 +02001602bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
1603 enum pipe *pipe)
1604{
1605 struct drm_device *dev = encoder->base.dev;
1606 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001607 enum port port = intel_ddi_get_encoder_port(encoder);
Imre Deak6d129be2014-03-05 16:20:54 +02001608 enum intel_display_power_domain power_domain;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001609 u32 tmp;
1610 int i;
1611
Imre Deak6d129be2014-03-05 16:20:54 +02001612 power_domain = intel_display_port_power_domain(encoder);
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001613 if (!intel_display_power_is_enabled(dev_priv, power_domain))
Imre Deak6d129be2014-03-05 16:20:54 +02001614 return false;
1615
Paulo Zanonife43d3f2012-10-15 15:51:39 -03001616 tmp = I915_READ(DDI_BUF_CTL(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001617
1618 if (!(tmp & DDI_BUF_CTL_ENABLE))
1619 return false;
1620
Paulo Zanoniad80a812012-10-24 16:06:19 -02001621 if (port == PORT_A) {
1622 tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001623
Paulo Zanoniad80a812012-10-24 16:06:19 -02001624 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
1625 case TRANS_DDI_EDP_INPUT_A_ON:
1626 case TRANS_DDI_EDP_INPUT_A_ONOFF:
1627 *pipe = PIPE_A;
1628 break;
1629 case TRANS_DDI_EDP_INPUT_B_ONOFF:
1630 *pipe = PIPE_B;
1631 break;
1632 case TRANS_DDI_EDP_INPUT_C_ONOFF:
1633 *pipe = PIPE_C;
1634 break;
1635 }
1636
1637 return true;
1638 } else {
1639 for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
1640 tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
1641
1642 if ((tmp & TRANS_DDI_PORT_MASK)
1643 == TRANS_DDI_SELECT_PORT(port)) {
Dave Airlie0e32b392014-05-02 14:02:48 +10001644 if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST)
1645 return false;
1646
Paulo Zanoniad80a812012-10-24 16:06:19 -02001647 *pipe = i;
1648 return true;
1649 }
Daniel Vetter85234cd2012-07-02 13:27:29 +02001650 }
1651 }
1652
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03001653 DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
Daniel Vetter85234cd2012-07-02 13:27:29 +02001654
Jesse Barnes22f9fe52013-04-02 10:03:55 -07001655 return false;
Daniel Vetter85234cd2012-07-02 13:27:29 +02001656}
1657
Paulo Zanonifc914632012-10-05 12:05:54 -03001658void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
1659{
1660 struct drm_crtc *crtc = &intel_crtc->base;
1661 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
1662 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
1663 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001664 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001665
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001666 if (cpu_transcoder != TRANSCODER_EDP)
1667 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1668 TRANS_CLK_SEL_PORT(port));
Paulo Zanonifc914632012-10-05 12:05:54 -03001669}
1670
1671void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
1672{
1673 struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001674 enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
Paulo Zanonifc914632012-10-05 12:05:54 -03001675
Paulo Zanonibb523fc2012-10-23 18:29:56 -02001676 if (cpu_transcoder != TRANSCODER_EDP)
1677 I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
1678 TRANS_CLK_SEL_DISABLED);
Paulo Zanonifc914632012-10-05 12:05:54 -03001679}
1680
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001681static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001682{
Paulo Zanonic19b0662012-10-15 15:51:41 -03001683 struct drm_encoder *encoder = &intel_encoder->base;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001684 struct drm_device *dev = encoder->dev;
1685 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001686 struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001687 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001688 int type = intel_encoder->type;
1689
1690 if (type == INTEL_OUTPUT_EDP) {
1691 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter4be73782014-01-17 14:39:48 +01001692 intel_edp_panel_on(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001693 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001694
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001695 if (IS_SKYLAKE(dev)) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001696 uint32_t dpll = crtc->config->ddi_pll_sel;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001697 uint32_t val;
1698
Damien Lespiau5416d872014-11-14 17:24:33 +00001699 /*
1700 * DPLL0 is used for eDP and is the only "private" DPLL (as
1701 * opposed to shared) on SKL
1702 */
1703 if (type == INTEL_OUTPUT_EDP) {
1704 WARN_ON(dpll != SKL_DPLL0);
1705
1706 val = I915_READ(DPLL_CTRL1);
1707
1708 val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) |
1709 DPLL_CTRL1_SSC(dpll) |
1710 DPLL_CRTL1_LINK_RATE_MASK(dpll));
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001711 val |= crtc->config->dpll_hw_state.ctrl1 << (dpll * 6);
Damien Lespiau5416d872014-11-14 17:24:33 +00001712
1713 I915_WRITE(DPLL_CTRL1, val);
1714 POSTING_READ(DPLL_CTRL1);
1715 }
1716
1717 /* DDI -> PLL mapping */
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001718 val = I915_READ(DPLL_CTRL2);
1719
1720 val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
1721 DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
1722 val |= (DPLL_CTRL2_DDI_CLK_SEL(dpll, port) |
1723 DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
1724
1725 I915_WRITE(DPLL_CTRL2, val);
Damien Lespiau5416d872014-11-14 17:24:33 +00001726
Satheeshakrishna M1ab23382014-08-22 09:49:06 +05301727 } else if (INTEL_INFO(dev)->gen < 9) {
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001728 WARN_ON(crtc->config->ddi_pll_sel == PORT_CLK_SEL_NONE);
1729 I915_WRITE(PORT_CLK_SEL(port), crtc->config->ddi_pll_sel);
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001730 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03001731
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001732 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanonic19b0662012-10-15 15:51:41 -03001733 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001734
Dave Airlie44905a272014-05-02 13:36:43 +10001735 intel_ddi_init_dp_buf_reg(intel_encoder);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001736
1737 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
1738 intel_dp_start_link_train(intel_dp);
1739 intel_dp_complete_link_train(intel_dp);
Vandana Kannan23f08d82014-11-13 14:55:22 +00001740 if (port != PORT_A || INTEL_INFO(dev)->gen >= 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03001741 intel_dp_stop_link_train(intel_dp);
Daniel Vetter30cf6db2014-04-24 23:54:58 +02001742 } else if (type == INTEL_OUTPUT_HDMI) {
1743 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
1744
1745 intel_hdmi->set_infoframes(encoder,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001746 crtc->config->has_hdmi_sink,
1747 &crtc->config->base.adjusted_mode);
Paulo Zanonic19b0662012-10-15 15:51:41 -03001748 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001749}
1750
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001751static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001752{
1753 struct drm_encoder *encoder = &intel_encoder->base;
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001754 struct drm_device *dev = encoder->dev;
1755 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001756 enum port port = intel_ddi_get_encoder_port(intel_encoder);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001757 int type = intel_encoder->type;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001758 uint32_t val;
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001759 bool wait = false;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001760
1761 val = I915_READ(DDI_BUF_CTL(port));
1762 if (val & DDI_BUF_CTL_ENABLE) {
1763 val &= ~DDI_BUF_CTL_ENABLE;
1764 I915_WRITE(DDI_BUF_CTL(port), val);
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001765 wait = true;
Paulo Zanoni2886e932012-10-05 12:06:00 -03001766 }
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001767
Paulo Zanonia836bdf2012-10-15 15:51:32 -03001768 val = I915_READ(DP_TP_CTL(port));
1769 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
1770 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
1771 I915_WRITE(DP_TP_CTL(port), val);
1772
1773 if (wait)
1774 intel_wait_ddi_buf_idle(dev_priv, port);
1775
Jani Nikula76bb80e2013-11-15 15:29:57 +02001776 if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001777 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
Jani Nikula76bb80e2013-11-15 15:29:57 +02001778 intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
Jani Nikula24f3e092014-03-17 16:43:36 +02001779 intel_edp_panel_vdd_on(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001780 intel_edp_panel_off(intel_dp);
Paulo Zanoni82a4d9c2012-10-23 18:30:07 -02001781 }
1782
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001783 if (IS_SKYLAKE(dev))
1784 I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
1785 DPLL_CTRL2_DDI_CLK_OFF(port)));
Satheeshakrishna M1ab23382014-08-22 09:49:06 +05301786 else if (INTEL_INFO(dev)->gen < 9)
Satheeshakrishna Mefa80ad2014-11-13 14:55:19 +00001787 I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
Paulo Zanoni6441ab52012-10-05 12:05:58 -03001788}
1789
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001790static void intel_enable_ddi(struct intel_encoder *intel_encoder)
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001791{
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001792 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001793 struct drm_crtc *crtc = encoder->crtc;
1794 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001795 struct drm_device *dev = encoder->dev;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001796 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001797 enum port port = intel_ddi_get_encoder_port(intel_encoder);
1798 int type = intel_encoder->type;
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001799
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001800 if (type == INTEL_OUTPUT_HDMI) {
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001801 struct intel_digital_port *intel_dig_port =
1802 enc_to_dig_port(encoder);
1803
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001804 /* In HDMI/DVI mode, the port width, and swing/emphasis values
1805 * are ignored so nothing special needs to be done besides
1806 * enabling the port.
1807 */
Damien Lespiau876a8cd2012-12-11 18:48:30 +00001808 I915_WRITE(DDI_BUF_CTL(port),
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07001809 intel_dig_port->saved_port_bits |
1810 DDI_BUF_CTL_ENABLE);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001811 } else if (type == INTEL_OUTPUT_EDP) {
1812 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1813
Vandana Kannan23f08d82014-11-13 14:55:22 +00001814 if (port == PORT_A && INTEL_INFO(dev)->gen < 9)
Imre Deak3ab9c632013-05-03 12:57:41 +03001815 intel_dp_stop_link_train(intel_dp);
1816
Daniel Vetter4be73782014-01-17 14:39:48 +01001817 intel_edp_backlight_on(intel_dp);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08001818 intel_psr_enable(intel_dp);
Vandana Kannanc3955782015-01-22 15:17:40 +05301819 intel_edp_drrs_enable(intel_dp);
Paulo Zanoni6547fef2012-10-15 15:51:40 -03001820 }
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001821
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001822 if (intel_crtc->config->has_audio) {
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001823 intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
Jani Nikula69bfe1a2014-10-27 16:26:50 +02001824 intel_audio_codec_enable(intel_encoder);
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001825 }
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001826}
1827
Paulo Zanoni00c09d72012-10-26 19:05:52 -02001828static void intel_disable_ddi(struct intel_encoder *intel_encoder)
Daniel Vetter5ab432e2012-06-30 08:59:56 +02001829{
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001830 struct drm_encoder *encoder = &intel_encoder->base;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001831 struct drm_crtc *crtc = encoder->crtc;
1832 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001833 int type = intel_encoder->type;
Wang Xingchao7b9f35a2013-01-22 23:25:25 +08001834 struct drm_device *dev = encoder->dev;
1835 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001836
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02001837 if (intel_crtc->config->has_audio) {
Jani Nikula69bfe1a2014-10-27 16:26:50 +02001838 intel_audio_codec_disable(intel_encoder);
Paulo Zanonid45a0bf2014-05-21 17:29:31 -03001839 intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
1840 }
Paulo Zanoni2831d8422013-03-06 20:03:09 -03001841
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001842 if (type == INTEL_OUTPUT_EDP) {
1843 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
1844
Vandana Kannanc3955782015-01-22 15:17:40 +05301845 intel_edp_drrs_disable(intel_dp);
Rodrigo Vivi0bc12bc2014-11-14 08:52:28 -08001846 intel_psr_disable(intel_dp);
Daniel Vetter4be73782014-01-17 14:39:48 +01001847 intel_edp_backlight_off(intel_dp);
Paulo Zanonid6c50ff2012-10-23 18:30:06 -02001848 }
Eugeni Dodonov72662e12012-05-09 15:37:31 -03001849}
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001850
Daniel Vettere0b01be2014-06-25 22:02:01 +03001851static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv,
1852 struct intel_shared_dpll *pll)
1853{
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02001854 I915_WRITE(WRPLL_CTL(pll->id), pll->config.hw_state.wrpll);
Daniel Vettere0b01be2014-06-25 22:02:01 +03001855 POSTING_READ(WRPLL_CTL(pll->id));
1856 udelay(20);
1857}
1858
Daniel Vetter12030432014-06-25 22:02:00 +03001859static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv,
1860 struct intel_shared_dpll *pll)
1861{
1862 uint32_t val;
1863
1864 val = I915_READ(WRPLL_CTL(pll->id));
Daniel Vetter12030432014-06-25 22:02:00 +03001865 I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
1866 POSTING_READ(WRPLL_CTL(pll->id));
1867}
1868
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001869static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
1870 struct intel_shared_dpll *pll,
1871 struct intel_dpll_hw_state *hw_state)
1872{
1873 uint32_t val;
1874
Daniel Vetterf458ebb2014-09-30 10:56:39 +02001875 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001876 return false;
1877
1878 val = I915_READ(WRPLL_CTL(pll->id));
1879 hw_state->wrpll = val;
1880
1881 return val & WRPLL_PLL_ENABLE;
1882}
1883
Damien Lespiauca1381b2014-07-15 15:05:33 +01001884static const char * const hsw_ddi_pll_names[] = {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001885 "WRPLL 1",
1886 "WRPLL 2",
1887};
1888
Damien Lespiau143b3072014-07-29 18:06:19 +01001889static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv)
Paulo Zanoni79f689a2012-10-05 12:05:52 -03001890{
Daniel Vetter9cd86932014-06-25 22:01:57 +03001891 int i;
1892
Daniel Vetter716c2e52014-06-25 22:02:02 +03001893 dev_priv->num_shared_dpll = 2;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001894
Daniel Vetter716c2e52014-06-25 22:02:02 +03001895 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
Daniel Vetter9cd86932014-06-25 22:01:57 +03001896 dev_priv->shared_dplls[i].id = i;
1897 dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
Daniel Vetter12030432014-06-25 22:02:00 +03001898 dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable;
Daniel Vettere0b01be2014-06-25 22:02:01 +03001899 dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable;
Daniel Vetterd452c5b2014-07-04 11:27:39 -03001900 dev_priv->shared_dplls[i].get_hw_state =
1901 hsw_ddi_pll_get_hw_state;
Daniel Vetter9cd86932014-06-25 22:01:57 +03001902 }
Damien Lespiau143b3072014-07-29 18:06:19 +01001903}
1904
Satheeshakrishna Md1a2dc72014-11-13 14:55:18 +00001905static const char * const skl_ddi_pll_names[] = {
1906 "DPLL 1",
1907 "DPLL 2",
1908 "DPLL 3",
1909};
1910
1911struct skl_dpll_regs {
1912 u32 ctl, cfgcr1, cfgcr2;
1913};
1914
1915/* this array is indexed by the *shared* pll id */
1916static const struct skl_dpll_regs skl_dpll_regs[3] = {
1917 {
1918 /* DPLL 1 */
1919 .ctl = LCPLL2_CTL,
1920 .cfgcr1 = DPLL1_CFGCR1,
1921 .cfgcr2 = DPLL1_CFGCR2,
1922 },
1923 {
1924 /* DPLL 2 */
1925 .ctl = WRPLL_CTL1,
1926 .cfgcr1 = DPLL2_CFGCR1,
1927 .cfgcr2 = DPLL2_CFGCR2,
1928 },
1929 {
1930 /* DPLL 3 */
1931 .ctl = WRPLL_CTL2,
1932 .cfgcr1 = DPLL3_CFGCR1,
1933 .cfgcr2 = DPLL3_CFGCR2,
1934 },
1935};
1936
1937static void skl_ddi_pll_enable(struct drm_i915_private *dev_priv,
1938 struct intel_shared_dpll *pll)
1939{
1940 uint32_t val;
1941 unsigned int dpll;
1942 const struct skl_dpll_regs *regs = skl_dpll_regs;
1943
1944 /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */
1945 dpll = pll->id + 1;
1946
1947 val = I915_READ(DPLL_CTRL1);
1948
1949 val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) | DPLL_CTRL1_SSC(dpll) |
1950 DPLL_CRTL1_LINK_RATE_MASK(dpll));
1951 val |= pll->config.hw_state.ctrl1 << (dpll * 6);
1952
1953 I915_WRITE(DPLL_CTRL1, val);
1954 POSTING_READ(DPLL_CTRL1);
1955
1956 I915_WRITE(regs[pll->id].cfgcr1, pll->config.hw_state.cfgcr1);
1957 I915_WRITE(regs[pll->id].cfgcr2, pll->config.hw_state.cfgcr2);
1958 POSTING_READ(regs[pll->id].cfgcr1);
1959 POSTING_READ(regs[pll->id].cfgcr2);
1960
1961 /* the enable bit is always bit 31 */
1962 I915_WRITE(regs[pll->id].ctl,
1963 I915_READ(regs[pll->id].ctl) | LCPLL_PLL_ENABLE);
1964
1965 if (wait_for(I915_READ(DPLL_STATUS) & DPLL_LOCK(dpll), 5))
1966 DRM_ERROR("DPLL %d not locked\n", dpll);
1967}
1968
1969static void skl_ddi_pll_disable(struct drm_i915_private *dev_priv,
1970 struct intel_shared_dpll *pll)
1971{
1972 const struct skl_dpll_regs *regs = skl_dpll_regs;
1973
1974 /* the enable bit is always bit 31 */
1975 I915_WRITE(regs[pll->id].ctl,
1976 I915_READ(regs[pll->id].ctl) & ~LCPLL_PLL_ENABLE);
1977 POSTING_READ(regs[pll->id].ctl);
1978}
1979
1980static bool skl_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
1981 struct intel_shared_dpll *pll,
1982 struct intel_dpll_hw_state *hw_state)
1983{
1984 uint32_t val;
1985 unsigned int dpll;
1986 const struct skl_dpll_regs *regs = skl_dpll_regs;
1987
1988 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
1989 return false;
1990
1991 /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */
1992 dpll = pll->id + 1;
1993
1994 val = I915_READ(regs[pll->id].ctl);
1995 if (!(val & LCPLL_PLL_ENABLE))
1996 return false;
1997
1998 val = I915_READ(DPLL_CTRL1);
1999 hw_state->ctrl1 = (val >> (dpll * 6)) & 0x3f;
2000
2001 /* avoid reading back stale values if HDMI mode is not enabled */
2002 if (val & DPLL_CTRL1_HDMI_MODE(dpll)) {
2003 hw_state->cfgcr1 = I915_READ(regs[pll->id].cfgcr1);
2004 hw_state->cfgcr2 = I915_READ(regs[pll->id].cfgcr2);
2005 }
2006
2007 return true;
2008}
2009
2010static void skl_shared_dplls_init(struct drm_i915_private *dev_priv)
2011{
2012 int i;
2013
2014 dev_priv->num_shared_dpll = 3;
2015
2016 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2017 dev_priv->shared_dplls[i].id = i;
2018 dev_priv->shared_dplls[i].name = skl_ddi_pll_names[i];
2019 dev_priv->shared_dplls[i].disable = skl_ddi_pll_disable;
2020 dev_priv->shared_dplls[i].enable = skl_ddi_pll_enable;
2021 dev_priv->shared_dplls[i].get_hw_state =
2022 skl_ddi_pll_get_hw_state;
2023 }
2024}
2025
Vandana Kannan5c6706e2014-11-24 13:37:39 +05302026static void broxton_phy_init(struct drm_i915_private *dev_priv,
2027 enum dpio_phy phy)
2028{
2029 enum port port;
2030 uint32_t val;
2031
2032 val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
2033 val |= GT_DISPLAY_POWER_ON(phy);
2034 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
2035
2036 /* Considering 10ms timeout until BSpec is updated */
2037 if (wait_for(I915_READ(BXT_PORT_CL1CM_DW0(phy)) & PHY_POWER_GOOD, 10))
2038 DRM_ERROR("timeout during PHY%d power on\n", phy);
2039
2040 for (port = (phy == DPIO_PHY0 ? PORT_B : PORT_A);
2041 port <= (phy == DPIO_PHY0 ? PORT_C : PORT_A); port++) {
2042 int lane;
2043
2044 for (lane = 0; lane < 4; lane++) {
2045 val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
2046 /*
2047 * Note that on CHV this flag is called UPAR, but has
2048 * the same function.
2049 */
2050 val &= ~LATENCY_OPTIM;
2051 if (lane != 1)
2052 val |= LATENCY_OPTIM;
2053
2054 I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val);
2055 }
2056 }
2057
2058 /* Program PLL Rcomp code offset */
2059 val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
2060 val &= ~IREF0RC_OFFSET_MASK;
2061 val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
2062 I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
2063
2064 val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
2065 val &= ~IREF1RC_OFFSET_MASK;
2066 val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
2067 I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
2068
2069 /* Program power gating */
2070 val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
2071 val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
2072 SUS_CLK_CONFIG;
2073 I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
2074
2075 if (phy == DPIO_PHY0) {
2076 val = I915_READ(BXT_PORT_CL2CM_DW6_BC);
2077 val |= DW6_OLDO_DYN_PWR_DOWN_EN;
2078 I915_WRITE(BXT_PORT_CL2CM_DW6_BC, val);
2079 }
2080
2081 val = I915_READ(BXT_PORT_CL1CM_DW30(phy));
2082 val &= ~OCL2_LDOFUSE_PWR_DIS;
2083 /*
2084 * On PHY1 disable power on the second channel, since no port is
2085 * connected there. On PHY0 both channels have a port, so leave it
2086 * enabled.
2087 * TODO: port C is only connected on BXT-P, so on BXT0/1 we should
2088 * power down the second channel on PHY0 as well.
2089 */
2090 if (phy == DPIO_PHY1)
2091 val |= OCL2_LDOFUSE_PWR_DIS;
2092 I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val);
2093
2094 if (phy == DPIO_PHY0) {
2095 uint32_t grc_code;
2096 /*
2097 * PHY0 isn't connected to an RCOMP resistor so copy over
2098 * the corresponding calibrated value from PHY1, and disable
2099 * the automatic calibration on PHY0.
2100 */
2101 if (wait_for(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE,
2102 10))
2103 DRM_ERROR("timeout waiting for PHY1 GRC\n");
2104
2105 val = I915_READ(BXT_PORT_REF_DW6(DPIO_PHY1));
2106 val = (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
2107 grc_code = val << GRC_CODE_FAST_SHIFT |
2108 val << GRC_CODE_SLOW_SHIFT |
2109 val;
2110 I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code);
2111
2112 val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0));
2113 val |= GRC_DIS | GRC_RDY_OVRD;
2114 I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val);
2115 }
2116
2117 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
2118 val |= COMMON_RESET_DIS;
2119 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
2120}
2121
2122void broxton_ddi_phy_init(struct drm_device *dev)
2123{
2124 /* Enable PHY1 first since it provides Rcomp for PHY0 */
2125 broxton_phy_init(dev->dev_private, DPIO_PHY1);
2126 broxton_phy_init(dev->dev_private, DPIO_PHY0);
2127}
2128
2129static void broxton_phy_uninit(struct drm_i915_private *dev_priv,
2130 enum dpio_phy phy)
2131{
2132 uint32_t val;
2133
2134 val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
2135 val &= ~COMMON_RESET_DIS;
2136 I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
2137}
2138
2139void broxton_ddi_phy_uninit(struct drm_device *dev)
2140{
2141 struct drm_i915_private *dev_priv = dev->dev_private;
2142
2143 broxton_phy_uninit(dev_priv, DPIO_PHY1);
2144 broxton_phy_uninit(dev_priv, DPIO_PHY0);
2145
2146 /* FIXME: do this in broxton_phy_uninit per phy */
2147 I915_WRITE(BXT_P_CR_GT_DISP_PWRON, 0);
2148}
2149
Satheeshakrishna Mdfb82402014-08-22 09:49:09 +05302150static const char * const bxt_ddi_pll_names[] = {
2151 "PORT PLL A",
2152 "PORT PLL B",
2153 "PORT PLL C",
2154};
2155
2156static void bxt_ddi_pll_enable(struct drm_i915_private *dev_priv,
2157 struct intel_shared_dpll *pll)
2158{
2159 uint32_t temp;
2160 enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
2161
2162 temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
2163 temp &= ~PORT_PLL_REF_SEL;
2164 /* Non-SSC reference */
2165 I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
2166
2167 /* Disable 10 bit clock */
2168 temp = I915_READ(BXT_PORT_PLL_EBB_4(port));
2169 temp &= ~PORT_PLL_10BIT_CLK_ENABLE;
2170 I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
2171
2172 /* Write P1 & P2 */
2173 temp = I915_READ(BXT_PORT_PLL_EBB_0(port));
2174 temp &= ~(PORT_PLL_P1_MASK | PORT_PLL_P2_MASK);
2175 temp |= pll->config.hw_state.ebb0;
2176 I915_WRITE(BXT_PORT_PLL_EBB_0(port), temp);
2177
2178 /* Write M2 integer */
2179 temp = I915_READ(BXT_PORT_PLL(port, 0));
2180 temp &= ~PORT_PLL_M2_MASK;
2181 temp |= pll->config.hw_state.pll0;
2182 I915_WRITE(BXT_PORT_PLL(port, 0), temp);
2183
2184 /* Write N */
2185 temp = I915_READ(BXT_PORT_PLL(port, 1));
2186 temp &= ~PORT_PLL_N_MASK;
2187 temp |= pll->config.hw_state.pll1;
2188 I915_WRITE(BXT_PORT_PLL(port, 1), temp);
2189
2190 /* Write M2 fraction */
2191 temp = I915_READ(BXT_PORT_PLL(port, 2));
2192 temp &= ~PORT_PLL_M2_FRAC_MASK;
2193 temp |= pll->config.hw_state.pll2;
2194 I915_WRITE(BXT_PORT_PLL(port, 2), temp);
2195
2196 /* Write M2 fraction enable */
2197 temp = I915_READ(BXT_PORT_PLL(port, 3));
2198 temp &= ~PORT_PLL_M2_FRAC_ENABLE;
2199 temp |= pll->config.hw_state.pll3;
2200 I915_WRITE(BXT_PORT_PLL(port, 3), temp);
2201
2202 /* Write coeff */
2203 temp = I915_READ(BXT_PORT_PLL(port, 6));
2204 temp &= ~PORT_PLL_PROP_COEFF_MASK;
2205 temp &= ~PORT_PLL_INT_COEFF_MASK;
2206 temp &= ~PORT_PLL_GAIN_CTL_MASK;
2207 temp |= pll->config.hw_state.pll6;
2208 I915_WRITE(BXT_PORT_PLL(port, 6), temp);
2209
2210 /* Write calibration val */
2211 temp = I915_READ(BXT_PORT_PLL(port, 8));
2212 temp &= ~PORT_PLL_TARGET_CNT_MASK;
2213 temp |= pll->config.hw_state.pll8;
2214 I915_WRITE(BXT_PORT_PLL(port, 8), temp);
2215
2216 /*
2217 * FIXME: program PORT_PLL_9/i_lockthresh according to the latest
2218 * specification update.
2219 */
2220
2221 /* Recalibrate with new settings */
2222 temp = I915_READ(BXT_PORT_PLL_EBB_4(port));
2223 temp |= PORT_PLL_RECALIBRATE;
2224 I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
2225 /* Enable 10 bit clock */
2226 temp |= PORT_PLL_10BIT_CLK_ENABLE;
2227 I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
2228
2229 /* Enable PLL */
2230 temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
2231 temp |= PORT_PLL_ENABLE;
2232 I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
2233 POSTING_READ(BXT_PORT_PLL_ENABLE(port));
2234
2235 if (wait_for_atomic_us((I915_READ(BXT_PORT_PLL_ENABLE(port)) &
2236 PORT_PLL_LOCK), 200))
2237 DRM_ERROR("PLL %d not locked\n", port);
2238
2239 /*
2240 * While we write to the group register to program all lanes at once we
2241 * can read only lane registers and we pick lanes 0/1 for that.
2242 */
2243 temp = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
2244 temp &= ~LANE_STAGGER_MASK;
2245 temp &= ~LANESTAGGER_STRAP_OVRD;
2246 temp |= pll->config.hw_state.pcsdw12;
2247 I915_WRITE(BXT_PORT_PCS_DW12_GRP(port), temp);
2248}
2249
2250static void bxt_ddi_pll_disable(struct drm_i915_private *dev_priv,
2251 struct intel_shared_dpll *pll)
2252{
2253 enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
2254 uint32_t temp;
2255
2256 temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
2257 temp &= ~PORT_PLL_ENABLE;
2258 I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
2259 POSTING_READ(BXT_PORT_PLL_ENABLE(port));
2260}
2261
2262static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
2263 struct intel_shared_dpll *pll,
2264 struct intel_dpll_hw_state *hw_state)
2265{
2266 enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
2267 uint32_t val;
2268
2269 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
2270 return false;
2271
2272 val = I915_READ(BXT_PORT_PLL_ENABLE(port));
2273 if (!(val & PORT_PLL_ENABLE))
2274 return false;
2275
2276 hw_state->ebb0 = I915_READ(BXT_PORT_PLL_EBB_0(port));
2277 hw_state->pll0 = I915_READ(BXT_PORT_PLL(port, 0));
2278 hw_state->pll1 = I915_READ(BXT_PORT_PLL(port, 1));
2279 hw_state->pll2 = I915_READ(BXT_PORT_PLL(port, 2));
2280 hw_state->pll3 = I915_READ(BXT_PORT_PLL(port, 3));
2281 hw_state->pll6 = I915_READ(BXT_PORT_PLL(port, 6));
2282 hw_state->pll8 = I915_READ(BXT_PORT_PLL(port, 8));
2283 /*
2284 * While we write to the group register to program all lanes at once we
2285 * can read only lane registers. We configure all lanes the same way, so
2286 * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
2287 */
2288 hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
2289 if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12))
2290 DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
2291 hw_state->pcsdw12,
2292 I915_READ(BXT_PORT_PCS_DW12_LN23(port)));
2293
2294 return true;
2295}
2296
2297static void bxt_shared_dplls_init(struct drm_i915_private *dev_priv)
2298{
2299 int i;
2300
2301 dev_priv->num_shared_dpll = 3;
2302
2303 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2304 dev_priv->shared_dplls[i].id = i;
2305 dev_priv->shared_dplls[i].name = bxt_ddi_pll_names[i];
2306 dev_priv->shared_dplls[i].disable = bxt_ddi_pll_disable;
2307 dev_priv->shared_dplls[i].enable = bxt_ddi_pll_enable;
2308 dev_priv->shared_dplls[i].get_hw_state =
2309 bxt_ddi_pll_get_hw_state;
2310 }
2311}
2312
Damien Lespiau143b3072014-07-29 18:06:19 +01002313void intel_ddi_pll_init(struct drm_device *dev)
2314{
2315 struct drm_i915_private *dev_priv = dev->dev_private;
2316 uint32_t val = I915_READ(LCPLL_CTL);
2317
Satheeshakrishna Md1a2dc72014-11-13 14:55:18 +00002318 if (IS_SKYLAKE(dev))
2319 skl_shared_dplls_init(dev_priv);
Satheeshakrishna Mdfb82402014-08-22 09:49:09 +05302320 else if (IS_BROXTON(dev))
2321 bxt_shared_dplls_init(dev_priv);
Satheeshakrishna Md1a2dc72014-11-13 14:55:18 +00002322 else
2323 hsw_shared_dplls_init(dev_priv);
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002324
Paulo Zanonib2b877f2013-05-03 17:23:42 -03002325 DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
Ville Syrjälä1652d192015-03-31 14:12:01 +03002326 dev_priv->display.get_display_clock_speed(dev));
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002327
Satheeshakrishna M121643c2014-11-13 14:55:15 +00002328 if (IS_SKYLAKE(dev)) {
2329 if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE))
2330 DRM_ERROR("LCPLL1 is disabled\n");
Vandana Kannanf8437dd12014-11-24 13:37:39 +05302331 } else if (IS_BROXTON(dev)) {
2332 broxton_init_cdclk(dev);
Vandana Kannan5c6706e2014-11-24 13:37:39 +05302333 broxton_ddi_phy_init(dev);
Satheeshakrishna M121643c2014-11-13 14:55:15 +00002334 } else {
2335 /*
2336 * The LCPLL register should be turned on by the BIOS. For now
2337 * let's just check its state and print errors in case
2338 * something is wrong. Don't even try to turn it on.
2339 */
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002340
Satheeshakrishna M121643c2014-11-13 14:55:15 +00002341 if (val & LCPLL_CD_SOURCE_FCLK)
2342 DRM_ERROR("CDCLK source is not LCPLL\n");
2343
2344 if (val & LCPLL_PLL_DISABLE)
2345 DRM_ERROR("LCPLL is disabled\n");
2346 }
Paulo Zanoni79f689a2012-10-05 12:05:52 -03002347}
Paulo Zanonic19b0662012-10-15 15:51:41 -03002348
2349void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
2350{
Paulo Zanoni174edf12012-10-26 19:05:50 -02002351 struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
2352 struct intel_dp *intel_dp = &intel_dig_port->dp;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002353 struct drm_i915_private *dev_priv = encoder->dev->dev_private;
Paulo Zanoni174edf12012-10-26 19:05:50 -02002354 enum port port = intel_dig_port->port;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002355 uint32_t val;
Syam Sidhardhanf3e227d2013-02-25 04:05:38 +05302356 bool wait = false;
Paulo Zanonic19b0662012-10-15 15:51:41 -03002357
2358 if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
2359 val = I915_READ(DDI_BUF_CTL(port));
2360 if (val & DDI_BUF_CTL_ENABLE) {
2361 val &= ~DDI_BUF_CTL_ENABLE;
2362 I915_WRITE(DDI_BUF_CTL(port), val);
2363 wait = true;
2364 }
2365
2366 val = I915_READ(DP_TP_CTL(port));
2367 val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
2368 val |= DP_TP_CTL_LINK_TRAIN_PAT1;
2369 I915_WRITE(DP_TP_CTL(port), val);
2370 POSTING_READ(DP_TP_CTL(port));
2371
2372 if (wait)
2373 intel_wait_ddi_buf_idle(dev_priv, port);
2374 }
2375
Dave Airlie0e32b392014-05-02 14:02:48 +10002376 val = DP_TP_CTL_ENABLE |
Paulo Zanonic19b0662012-10-15 15:51:41 -03002377 DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
Dave Airlie0e32b392014-05-02 14:02:48 +10002378 if (intel_dp->is_mst)
2379 val |= DP_TP_CTL_MODE_MST;
2380 else {
2381 val |= DP_TP_CTL_MODE_SST;
2382 if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
2383 val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
2384 }
Paulo Zanonic19b0662012-10-15 15:51:41 -03002385 I915_WRITE(DP_TP_CTL(port), val);
2386 POSTING_READ(DP_TP_CTL(port));
2387
2388 intel_dp->DP |= DDI_BUF_CTL_ENABLE;
2389 I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
2390 POSTING_READ(DDI_BUF_CTL(port));
2391
2392 udelay(600);
2393}
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002394
Paulo Zanoni1ad960f2012-11-01 21:05:05 -02002395void intel_ddi_fdi_disable(struct drm_crtc *crtc)
2396{
2397 struct drm_i915_private *dev_priv = crtc->dev->dev_private;
2398 struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
2399 uint32_t val;
2400
2401 intel_ddi_post_disable(intel_encoder);
2402
2403 val = I915_READ(_FDI_RXA_CTL);
2404 val &= ~FDI_RX_ENABLE;
2405 I915_WRITE(_FDI_RXA_CTL, val);
2406
2407 val = I915_READ(_FDI_RXA_MISC);
2408 val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
2409 val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
2410 I915_WRITE(_FDI_RXA_MISC, val);
2411
2412 val = I915_READ(_FDI_RXA_CTL);
2413 val &= ~FDI_PCDCLK;
2414 I915_WRITE(_FDI_RXA_CTL, val);
2415
2416 val = I915_READ(_FDI_RXA_CTL);
2417 val &= ~FDI_RX_PLL_ENABLE;
2418 I915_WRITE(_FDI_RXA_CTL, val);
2419}
2420
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002421static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
2422{
Dave Airlie0e32b392014-05-02 14:02:48 +10002423 struct intel_digital_port *intel_dig_port = enc_to_dig_port(&intel_encoder->base);
2424 int type = intel_dig_port->base.type;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002425
Dave Airlie0e32b392014-05-02 14:02:48 +10002426 if (type != INTEL_OUTPUT_DISPLAYPORT &&
2427 type != INTEL_OUTPUT_EDP &&
2428 type != INTEL_OUTPUT_UNKNOWN) {
2429 return;
2430 }
2431
2432 intel_dp_hot_plug(intel_encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002433}
2434
Ville Syrjälä6801c182013-09-24 14:24:05 +03002435void intel_ddi_get_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002436 struct intel_crtc_state *pipe_config)
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002437{
2438 struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
2439 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
Ander Conselvan de Oliveira0cb09a92015-01-30 12:17:23 +02002440 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002441 struct intel_hdmi *intel_hdmi;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002442 u32 temp, flags = 0;
2443
2444 temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
2445 if (temp & TRANS_DDI_PHSYNC)
2446 flags |= DRM_MODE_FLAG_PHSYNC;
2447 else
2448 flags |= DRM_MODE_FLAG_NHSYNC;
2449 if (temp & TRANS_DDI_PVSYNC)
2450 flags |= DRM_MODE_FLAG_PVSYNC;
2451 else
2452 flags |= DRM_MODE_FLAG_NVSYNC;
2453
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02002454 pipe_config->base.adjusted_mode.flags |= flags;
Ville Syrjälä42571ae2013-09-06 23:29:00 +03002455
2456 switch (temp & TRANS_DDI_BPC_MASK) {
2457 case TRANS_DDI_BPC_6:
2458 pipe_config->pipe_bpp = 18;
2459 break;
2460 case TRANS_DDI_BPC_8:
2461 pipe_config->pipe_bpp = 24;
2462 break;
2463 case TRANS_DDI_BPC_10:
2464 pipe_config->pipe_bpp = 30;
2465 break;
2466 case TRANS_DDI_BPC_12:
2467 pipe_config->pipe_bpp = 36;
2468 break;
2469 default:
2470 break;
2471 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002472
2473 switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
2474 case TRANS_DDI_MODE_SELECT_HDMI:
Daniel Vetter6897b4b2014-04-24 23:54:47 +02002475 pipe_config->has_hdmi_sink = true;
Daniel Vetterbbd440f2014-11-20 22:33:59 +01002476 intel_hdmi = enc_to_intel_hdmi(&encoder->base);
2477
2478 if (intel_hdmi->infoframe_enabled(&encoder->base))
2479 pipe_config->has_infoframe = true;
Jesse Barnescbc572a2014-11-17 13:08:47 -08002480 break;
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03002481 case TRANS_DDI_MODE_SELECT_DVI:
2482 case TRANS_DDI_MODE_SELECT_FDI:
2483 break;
2484 case TRANS_DDI_MODE_SELECT_DP_SST:
2485 case TRANS_DDI_MODE_SELECT_DP_MST:
2486 pipe_config->has_dp_encoder = true;
2487 intel_dp_get_m_n(intel_crtc, pipe_config);
2488 break;
2489 default:
2490 break;
2491 }
Daniel Vetter10214422013-11-18 07:38:16 +01002492
Daniel Vetterf458ebb2014-09-30 10:56:39 +02002493 if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
Paulo Zanonia60551b2014-05-21 16:23:20 -03002494 temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
Jani Nikula82910ac2014-10-27 16:26:59 +02002495 if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
Paulo Zanonia60551b2014-05-21 16:23:20 -03002496 pipe_config->has_audio = true;
2497 }
Daniel Vetter9ed109a2014-04-24 23:54:52 +02002498
Daniel Vetter10214422013-11-18 07:38:16 +01002499 if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
2500 pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
2501 /*
2502 * This is a big fat ugly hack.
2503 *
2504 * Some machines in UEFI boot mode provide us a VBT that has 18
2505 * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
2506 * unknown we fail to light up. Yet the same BIOS boots up with
2507 * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
2508 * max, not what it tells us to use.
2509 *
2510 * Note: This will still be broken if the eDP panel is not lit
2511 * up by the BIOS, and thus we can't get the mode at module
2512 * load.
2513 */
2514 DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
2515 pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
2516 dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
2517 }
Jesse Barnes11578552014-01-21 12:42:10 -08002518
Damien Lespiau22606a12014-12-12 14:26:57 +00002519 intel_ddi_clock_get(encoder, pipe_config);
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002520}
2521
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002522static void intel_ddi_destroy(struct drm_encoder *encoder)
2523{
2524 /* HDMI has nothing special to destroy, so we can go with this. */
2525 intel_dp_encoder_destroy(encoder);
2526}
2527
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002528static bool intel_ddi_compute_config(struct intel_encoder *encoder,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02002529 struct intel_crtc_state *pipe_config)
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002530{
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002531 int type = encoder->type;
Daniel Vettereccb1402013-05-22 00:50:22 +02002532 int port = intel_ddi_get_encoder_port(encoder);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002533
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002534 WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002535
Daniel Vettereccb1402013-05-22 00:50:22 +02002536 if (port == PORT_A)
2537 pipe_config->cpu_transcoder = TRANSCODER_EDP;
2538
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002539 if (type == INTEL_OUTPUT_HDMI)
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002540 return intel_hdmi_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002541 else
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002542 return intel_dp_compute_config(encoder, pipe_config);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002543}
2544
2545static const struct drm_encoder_funcs intel_ddi_funcs = {
2546 .destroy = intel_ddi_destroy,
2547};
2548
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002549static struct intel_connector *
2550intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
2551{
2552 struct intel_connector *connector;
2553 enum port port = intel_dig_port->port;
2554
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002555 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002556 if (!connector)
2557 return NULL;
2558
2559 intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
2560 if (!intel_dp_init_connector(intel_dig_port, connector)) {
2561 kfree(connector);
2562 return NULL;
2563 }
2564
2565 return connector;
2566}
2567
2568static struct intel_connector *
2569intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
2570{
2571 struct intel_connector *connector;
2572 enum port port = intel_dig_port->port;
2573
Ander Conselvan de Oliveira9bdbd0b2015-04-10 10:59:10 +03002574 connector = intel_connector_alloc();
Paulo Zanoni4a28ae52013-10-09 13:52:36 -03002575 if (!connector)
2576 return NULL;
2577
2578 intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
2579 intel_hdmi_init_connector(intel_dig_port, connector);
2580
2581 return connector;
2582}
2583
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002584void intel_ddi_init(struct drm_device *dev, enum port port)
2585{
Damien Lespiau876a8cd2012-12-11 18:48:30 +00002586 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002587 struct intel_digital_port *intel_dig_port;
2588 struct intel_encoder *intel_encoder;
2589 struct drm_encoder *encoder;
Paulo Zanoni311a2092013-09-12 17:12:18 -03002590 bool init_hdmi, init_dp;
2591
2592 init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
2593 dev_priv->vbt.ddi_port_info[port].supports_hdmi);
2594 init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
2595 if (!init_dp && !init_hdmi) {
Chris Wilsonf68d6972014-08-04 07:15:09 +01002596 DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, assuming it is\n",
Paulo Zanoni311a2092013-09-12 17:12:18 -03002597 port_name(port));
2598 init_hdmi = true;
2599 init_dp = true;
2600 }
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002601
Daniel Vetterb14c5672013-09-19 12:18:32 +02002602 intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002603 if (!intel_dig_port)
2604 return;
2605
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002606 intel_encoder = &intel_dig_port->base;
2607 encoder = &intel_encoder->base;
2608
2609 drm_encoder_init(dev, encoder, &intel_ddi_funcs,
2610 DRM_MODE_ENCODER_TMDS);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002611
Daniel Vetter5bfe2ac2013-03-27 00:44:55 +01002612 intel_encoder->compute_config = intel_ddi_compute_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002613 intel_encoder->enable = intel_enable_ddi;
2614 intel_encoder->pre_enable = intel_ddi_pre_enable;
2615 intel_encoder->disable = intel_disable_ddi;
2616 intel_encoder->post_disable = intel_ddi_post_disable;
2617 intel_encoder->get_hw_state = intel_ddi_get_hw_state;
Jesse Barnes045ac3b2013-05-14 17:08:26 -07002618 intel_encoder->get_config = intel_ddi_get_config;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002619
2620 intel_dig_port->port = port;
Stéphane Marchesinbcf53de2013-07-12 13:54:41 -07002621 intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
2622 (DDI_BUF_PORT_REVERSAL |
2623 DDI_A_4_LANES);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002624
2625 intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
Chris Wilsonf68d6972014-08-04 07:15:09 +01002626 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
Ville Syrjäläbc079e82014-03-03 16:15:28 +02002627 intel_encoder->cloneable = 0;
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002628 intel_encoder->hot_plug = intel_ddi_hot_plug;
2629
Chris Wilsonf68d6972014-08-04 07:15:09 +01002630 if (init_dp) {
2631 if (!intel_ddi_init_dp_connector(intel_dig_port))
2632 goto err;
Dave Airlie13cf5502014-06-18 11:29:35 +10002633
Chris Wilsonf68d6972014-08-04 07:15:09 +01002634 intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
2635 dev_priv->hpd_irq_port[port] = intel_dig_port;
2636 }
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002637
Paulo Zanoni311a2092013-09-12 17:12:18 -03002638 /* In theory we don't need the encoder->type check, but leave it just in
2639 * case we have some really bad VBTs... */
Chris Wilsonf68d6972014-08-04 07:15:09 +01002640 if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
2641 if (!intel_ddi_init_hdmi_connector(intel_dig_port))
2642 goto err;
Daniel Vetter21a8e6a2013-04-10 23:28:35 +02002643 }
Chris Wilsonf68d6972014-08-04 07:15:09 +01002644
2645 return;
2646
2647err:
2648 drm_encoder_cleanup(encoder);
2649 kfree(intel_dig_port);
Paulo Zanoni00c09d72012-10-26 19:05:52 -02002650}