Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 1 | /* |
| 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 | |
| 31 | /* HDMI/DVI modes ignore everything but the last 2 items. So we share |
| 32 | * them for both DP and FDI transports, allowing those ports to |
| 33 | * automatically adapt to HDMI connections as well |
| 34 | */ |
| 35 | static const u32 hsw_ddi_translations_dp[] = { |
| 36 | 0x00FFFFFF, 0x0006000E, /* DP parameters */ |
| 37 | 0x00D75FFF, 0x0005000A, |
| 38 | 0x00C30FFF, 0x00040006, |
| 39 | 0x80AAAFFF, 0x000B0000, |
| 40 | 0x00FFFFFF, 0x0005000A, |
| 41 | 0x00D75FFF, 0x000C0004, |
| 42 | 0x80C30FFF, 0x000B0000, |
| 43 | 0x00FFFFFF, 0x00040006, |
| 44 | 0x80D75FFF, 0x000B0000, |
| 45 | 0x00FFFFFF, 0x00040006 /* HDMI parameters */ |
| 46 | }; |
| 47 | |
| 48 | static const u32 hsw_ddi_translations_fdi[] = { |
| 49 | 0x00FFFFFF, 0x0007000E, /* FDI parameters */ |
| 50 | 0x00D75FFF, 0x000F000A, |
| 51 | 0x00C30FFF, 0x00060006, |
| 52 | 0x00AAAFFF, 0x001E0000, |
| 53 | 0x00FFFFFF, 0x000F000A, |
| 54 | 0x00D75FFF, 0x00160004, |
| 55 | 0x00C30FFF, 0x001E0000, |
| 56 | 0x00FFFFFF, 0x00060006, |
| 57 | 0x00D75FFF, 0x001E0000, |
| 58 | 0x00FFFFFF, 0x00040006 /* HDMI parameters */ |
| 59 | }; |
| 60 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 61 | static enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder) |
| 62 | { |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame^] | 63 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 64 | int type = intel_encoder->type; |
| 65 | |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame^] | 66 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
| 67 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 68 | return intel_dp->port; |
| 69 | |
| 70 | } else if (type == INTEL_OUTPUT_HDMI) { |
| 71 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 72 | return intel_hdmi->ddi_port; |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame^] | 73 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 74 | } else if (type == INTEL_OUTPUT_ANALOG) { |
| 75 | return PORT_E; |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame^] | 76 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 77 | } else { |
| 78 | DRM_ERROR("Invalid DDI encoder type %d\n", type); |
| 79 | BUG(); |
| 80 | } |
| 81 | } |
| 82 | |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 83 | /* On Haswell, DDI port buffers must be programmed with correct values |
| 84 | * in advance. The buffer values are different for FDI and DP modes, |
| 85 | * but the HDMI/DVI fields are shared among those. So we program the DDI |
| 86 | * in either FDI or DP modes only, as HDMI connections will work with both |
| 87 | * of those |
| 88 | */ |
| 89 | void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port, bool use_fdi_mode) |
| 90 | { |
| 91 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 92 | u32 reg; |
| 93 | int i; |
| 94 | const u32 *ddi_translations = ((use_fdi_mode) ? |
| 95 | hsw_ddi_translations_fdi : |
| 96 | hsw_ddi_translations_dp); |
| 97 | |
| 98 | DRM_DEBUG_DRIVER("Initializing DDI buffers for port %c in %s mode\n", |
| 99 | port_name(port), |
| 100 | use_fdi_mode ? "FDI" : "DP"); |
| 101 | |
| 102 | WARN((use_fdi_mode && (port != PORT_E)), |
| 103 | "Programming port %c in FDI mode, this probably will not work.\n", |
| 104 | port_name(port)); |
| 105 | |
| 106 | for (i=0, reg=DDI_BUF_TRANS(port); i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) { |
| 107 | I915_WRITE(reg, ddi_translations[i]); |
| 108 | reg += 4; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /* Program DDI buffers translations for DP. By default, program ports A-D in DP |
| 113 | * mode and port E for FDI. |
| 114 | */ |
| 115 | void intel_prepare_ddi(struct drm_device *dev) |
| 116 | { |
| 117 | int port; |
| 118 | |
| 119 | if (IS_HASWELL(dev)) { |
| 120 | for (port = PORT_A; port < PORT_E; port++) |
| 121 | intel_prepare_ddi_buffers(dev, port, false); |
| 122 | |
| 123 | /* DDI E is the suggested one to work in FDI mode, so program is as such by |
| 124 | * default. It will have to be re-programmed in case a digital DP output |
| 125 | * will be detected on it |
| 126 | */ |
| 127 | intel_prepare_ddi_buffers(dev, PORT_E, true); |
| 128 | } |
| 129 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 130 | |
| 131 | static const long hsw_ddi_buf_ctl_values[] = { |
| 132 | DDI_BUF_EMP_400MV_0DB_HSW, |
| 133 | DDI_BUF_EMP_400MV_3_5DB_HSW, |
| 134 | DDI_BUF_EMP_400MV_6DB_HSW, |
| 135 | DDI_BUF_EMP_400MV_9_5DB_HSW, |
| 136 | DDI_BUF_EMP_600MV_0DB_HSW, |
| 137 | DDI_BUF_EMP_600MV_3_5DB_HSW, |
| 138 | DDI_BUF_EMP_600MV_6DB_HSW, |
| 139 | DDI_BUF_EMP_800MV_0DB_HSW, |
| 140 | DDI_BUF_EMP_800MV_3_5DB_HSW |
| 141 | }; |
| 142 | |
| 143 | |
| 144 | /* Starting with Haswell, different DDI ports can work in FDI mode for |
| 145 | * connection to the PCH-located connectors. For this, it is necessary to train |
| 146 | * both the DDI port and PCH receiver for the desired DDI buffer settings. |
| 147 | * |
| 148 | * The recommended port to work in FDI mode is DDI E, which we use here. Also, |
| 149 | * please note that when FDI mode is active on DDI E, it shares 2 lines with |
| 150 | * DDI A (which is used for eDP) |
| 151 | */ |
| 152 | |
| 153 | void hsw_fdi_link_train(struct drm_crtc *crtc) |
| 154 | { |
| 155 | struct drm_device *dev = crtc->dev; |
| 156 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 157 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 158 | int pipe = intel_crtc->pipe; |
| 159 | u32 reg, temp, i; |
| 160 | |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 161 | /* Start the training iterating through available voltages and emphasis */ |
| 162 | for (i=0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values); i++) { |
| 163 | /* Configure DP_TP_CTL with auto-training */ |
| 164 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 165 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 166 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 167 | DP_TP_CTL_LINK_TRAIN_PAT1 | |
| 168 | DP_TP_CTL_ENABLE); |
| 169 | |
| 170 | /* Configure and enable DDI_BUF_CTL for DDI E with next voltage */ |
| 171 | temp = I915_READ(DDI_BUF_CTL(PORT_E)); |
| 172 | temp = (temp & ~DDI_BUF_EMP_MASK); |
| 173 | I915_WRITE(DDI_BUF_CTL(PORT_E), |
| 174 | temp | |
| 175 | DDI_BUF_CTL_ENABLE | |
| 176 | DDI_PORT_WIDTH_X2 | |
| 177 | hsw_ddi_buf_ctl_values[i]); |
| 178 | |
| 179 | udelay(600); |
| 180 | |
Eugeni Dodonov | 4acf518 | 2012-07-04 20:15:16 -0300 | [diff] [blame] | 181 | /* We need to program FDI_RX_MISC with the default TP1 to TP2 |
| 182 | * values before enabling the receiver, and configure the delay |
| 183 | * for the FDI timing generator to 90h. Luckily, all the other |
| 184 | * bits are supposed to be zeroed, so we can write those values |
| 185 | * directly. |
| 186 | */ |
| 187 | I915_WRITE(FDI_RX_MISC(pipe), FDI_RX_TP1_TO_TP2_48 | |
| 188 | FDI_RX_FDI_DELAY_90); |
| 189 | |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 190 | /* Enable CPU FDI Receiver with auto-training */ |
| 191 | reg = FDI_RX_CTL(pipe); |
| 192 | I915_WRITE(reg, |
| 193 | I915_READ(reg) | |
| 194 | FDI_LINK_TRAIN_AUTO | |
| 195 | FDI_RX_ENABLE | |
| 196 | FDI_LINK_TRAIN_PATTERN_1_CPT | |
| 197 | FDI_RX_ENHANCE_FRAME_ENABLE | |
| 198 | FDI_PORT_WIDTH_2X_LPT | |
| 199 | FDI_RX_PLL_ENABLE); |
| 200 | POSTING_READ(reg); |
| 201 | udelay(100); |
| 202 | |
| 203 | temp = I915_READ(DP_TP_STATUS(PORT_E)); |
| 204 | if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { |
| 205 | DRM_DEBUG_DRIVER("BUF_CTL training done on %d step\n", i); |
| 206 | |
| 207 | /* Enable normal pixel sending for FDI */ |
| 208 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 209 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 210 | DP_TP_CTL_LINK_TRAIN_NORMAL | |
| 211 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 212 | DP_TP_CTL_ENABLE); |
| 213 | |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 214 | break; |
| 215 | } else { |
| 216 | DRM_ERROR("Error training BUF_CTL %d\n", i); |
| 217 | |
| 218 | /* Disable DP_TP_CTL and FDI_RX_CTL) and retry */ |
| 219 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 220 | I915_READ(DP_TP_CTL(PORT_E)) & |
| 221 | ~DP_TP_CTL_ENABLE); |
| 222 | I915_WRITE(FDI_RX_CTL(pipe), |
| 223 | I915_READ(FDI_RX_CTL(pipe)) & |
| 224 | ~FDI_RX_PLL_ENABLE); |
| 225 | continue; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 230 | } |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 231 | |
| 232 | /* For DDI connections, it is possible to support different outputs over the |
| 233 | * same DDI port, such as HDMI or DP or even VGA via FDI. So we don't know by |
| 234 | * the time the output is detected what exactly is on the other end of it. This |
| 235 | * function aims at providing support for this detection and proper output |
| 236 | * configuration. |
| 237 | */ |
| 238 | void intel_ddi_init(struct drm_device *dev, enum port port) |
| 239 | { |
| 240 | /* For now, we don't do any proper output detection and assume that we |
| 241 | * handle HDMI only */ |
| 242 | |
| 243 | switch(port){ |
| 244 | case PORT_A: |
| 245 | /* We don't handle eDP and DP yet */ |
| 246 | DRM_DEBUG_DRIVER("Found digital output on DDI port A\n"); |
| 247 | break; |
| 248 | /* Assume that the ports B, C and D are working in HDMI mode for now */ |
| 249 | case PORT_B: |
| 250 | case PORT_C: |
| 251 | case PORT_D: |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 252 | intel_hdmi_init(dev, DDI_BUF_CTL(port), port); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 253 | break; |
| 254 | default: |
| 255 | DRM_DEBUG_DRIVER("No handlers defined for port %d, skipping DDI initialization\n", |
| 256 | port); |
| 257 | break; |
| 258 | } |
| 259 | } |
Eugeni Dodonov | 12a13a3 | 2012-05-09 15:37:29 -0300 | [diff] [blame] | 260 | |
| 261 | /* WRPLL clock dividers */ |
| 262 | struct wrpll_tmds_clock { |
| 263 | u32 clock; |
| 264 | u16 p; /* Post divider */ |
| 265 | u16 n2; /* Feedback divider */ |
| 266 | u16 r2; /* Reference divider */ |
| 267 | }; |
| 268 | |
Paulo Zanoni | 126e9be | 2012-08-10 10:03:03 -0300 | [diff] [blame] | 269 | /* Table of matching values for WRPLL clocks programming for each frequency. |
| 270 | * The code assumes this table is sorted. */ |
Eugeni Dodonov | 12a13a3 | 2012-05-09 15:37:29 -0300 | [diff] [blame] | 271 | static const struct wrpll_tmds_clock wrpll_tmds_clock_table[] = { |
| 272 | {19750, 38, 25, 18}, |
| 273 | {20000, 48, 32, 18}, |
| 274 | {21000, 36, 21, 15}, |
| 275 | {21912, 42, 29, 17}, |
| 276 | {22000, 36, 22, 15}, |
| 277 | {23000, 36, 23, 15}, |
| 278 | {23500, 40, 40, 23}, |
| 279 | {23750, 26, 16, 14}, |
Eugeni Dodonov | 12a13a3 | 2012-05-09 15:37:29 -0300 | [diff] [blame] | 280 | {24000, 36, 24, 15}, |
| 281 | {25000, 36, 25, 15}, |
| 282 | {25175, 26, 40, 33}, |
| 283 | {25200, 30, 21, 15}, |
| 284 | {26000, 36, 26, 15}, |
| 285 | {27000, 30, 21, 14}, |
| 286 | {27027, 18, 100, 111}, |
| 287 | {27500, 30, 29, 19}, |
| 288 | {28000, 34, 30, 17}, |
| 289 | {28320, 26, 30, 22}, |
| 290 | {28322, 32, 42, 25}, |
| 291 | {28750, 24, 23, 18}, |
| 292 | {29000, 30, 29, 18}, |
| 293 | {29750, 32, 30, 17}, |
| 294 | {30000, 30, 25, 15}, |
| 295 | {30750, 30, 41, 24}, |
| 296 | {31000, 30, 31, 18}, |
| 297 | {31500, 30, 28, 16}, |
| 298 | {32000, 30, 32, 18}, |
| 299 | {32500, 28, 32, 19}, |
| 300 | {33000, 24, 22, 15}, |
| 301 | {34000, 28, 30, 17}, |
| 302 | {35000, 26, 32, 19}, |
| 303 | {35500, 24, 30, 19}, |
| 304 | {36000, 26, 26, 15}, |
| 305 | {36750, 26, 46, 26}, |
| 306 | {37000, 24, 23, 14}, |
| 307 | {37762, 22, 40, 26}, |
| 308 | {37800, 20, 21, 15}, |
| 309 | {38000, 24, 27, 16}, |
| 310 | {38250, 24, 34, 20}, |
| 311 | {39000, 24, 26, 15}, |
| 312 | {40000, 24, 32, 18}, |
| 313 | {40500, 20, 21, 14}, |
| 314 | {40541, 22, 147, 89}, |
| 315 | {40750, 18, 19, 14}, |
| 316 | {41000, 16, 17, 14}, |
| 317 | {41500, 22, 44, 26}, |
| 318 | {41540, 22, 44, 26}, |
| 319 | {42000, 18, 21, 15}, |
| 320 | {42500, 22, 45, 26}, |
| 321 | {43000, 20, 43, 27}, |
| 322 | {43163, 20, 24, 15}, |
| 323 | {44000, 18, 22, 15}, |
| 324 | {44900, 20, 108, 65}, |
| 325 | {45000, 20, 25, 15}, |
| 326 | {45250, 20, 52, 31}, |
| 327 | {46000, 18, 23, 15}, |
| 328 | {46750, 20, 45, 26}, |
| 329 | {47000, 20, 40, 23}, |
| 330 | {48000, 18, 24, 15}, |
| 331 | {49000, 18, 49, 30}, |
| 332 | {49500, 16, 22, 15}, |
| 333 | {50000, 18, 25, 15}, |
| 334 | {50500, 18, 32, 19}, |
| 335 | {51000, 18, 34, 20}, |
| 336 | {52000, 18, 26, 15}, |
| 337 | {52406, 14, 34, 25}, |
| 338 | {53000, 16, 22, 14}, |
| 339 | {54000, 16, 24, 15}, |
| 340 | {54054, 16, 173, 108}, |
| 341 | {54500, 14, 24, 17}, |
| 342 | {55000, 12, 22, 18}, |
| 343 | {56000, 14, 45, 31}, |
| 344 | {56250, 16, 25, 15}, |
| 345 | {56750, 14, 25, 17}, |
| 346 | {57000, 16, 27, 16}, |
| 347 | {58000, 16, 43, 25}, |
| 348 | {58250, 16, 38, 22}, |
| 349 | {58750, 16, 40, 23}, |
| 350 | {59000, 14, 26, 17}, |
| 351 | {59341, 14, 40, 26}, |
| 352 | {59400, 16, 44, 25}, |
| 353 | {60000, 16, 32, 18}, |
| 354 | {60500, 12, 39, 29}, |
| 355 | {61000, 14, 49, 31}, |
| 356 | {62000, 14, 37, 23}, |
| 357 | {62250, 14, 42, 26}, |
| 358 | {63000, 12, 21, 15}, |
| 359 | {63500, 14, 28, 17}, |
| 360 | {64000, 12, 27, 19}, |
| 361 | {65000, 14, 32, 19}, |
| 362 | {65250, 12, 29, 20}, |
| 363 | {65500, 12, 32, 22}, |
| 364 | {66000, 12, 22, 15}, |
| 365 | {66667, 14, 38, 22}, |
| 366 | {66750, 10, 21, 17}, |
| 367 | {67000, 14, 33, 19}, |
| 368 | {67750, 14, 58, 33}, |
| 369 | {68000, 14, 30, 17}, |
| 370 | {68179, 14, 46, 26}, |
| 371 | {68250, 14, 46, 26}, |
| 372 | {69000, 12, 23, 15}, |
| 373 | {70000, 12, 28, 18}, |
| 374 | {71000, 12, 30, 19}, |
| 375 | {72000, 12, 24, 15}, |
| 376 | {73000, 10, 23, 17}, |
| 377 | {74000, 12, 23, 14}, |
| 378 | {74176, 8, 100, 91}, |
| 379 | {74250, 10, 22, 16}, |
| 380 | {74481, 12, 43, 26}, |
| 381 | {74500, 10, 29, 21}, |
| 382 | {75000, 12, 25, 15}, |
| 383 | {75250, 10, 39, 28}, |
| 384 | {76000, 12, 27, 16}, |
| 385 | {77000, 12, 53, 31}, |
| 386 | {78000, 12, 26, 15}, |
| 387 | {78750, 12, 28, 16}, |
| 388 | {79000, 10, 38, 26}, |
| 389 | {79500, 10, 28, 19}, |
| 390 | {80000, 12, 32, 18}, |
| 391 | {81000, 10, 21, 14}, |
| 392 | {81081, 6, 100, 111}, |
| 393 | {81624, 8, 29, 24}, |
| 394 | {82000, 8, 17, 14}, |
| 395 | {83000, 10, 40, 26}, |
| 396 | {83950, 10, 28, 18}, |
| 397 | {84000, 10, 28, 18}, |
| 398 | {84750, 6, 16, 17}, |
| 399 | {85000, 6, 17, 18}, |
| 400 | {85250, 10, 30, 19}, |
| 401 | {85750, 10, 27, 17}, |
| 402 | {86000, 10, 43, 27}, |
| 403 | {87000, 10, 29, 18}, |
| 404 | {88000, 10, 44, 27}, |
| 405 | {88500, 10, 41, 25}, |
| 406 | {89000, 10, 28, 17}, |
| 407 | {89012, 6, 90, 91}, |
| 408 | {89100, 10, 33, 20}, |
| 409 | {90000, 10, 25, 15}, |
| 410 | {91000, 10, 32, 19}, |
| 411 | {92000, 10, 46, 27}, |
| 412 | {93000, 10, 31, 18}, |
| 413 | {94000, 10, 40, 23}, |
| 414 | {94500, 10, 28, 16}, |
| 415 | {95000, 10, 44, 25}, |
| 416 | {95654, 10, 39, 22}, |
| 417 | {95750, 10, 39, 22}, |
| 418 | {96000, 10, 32, 18}, |
| 419 | {97000, 8, 23, 16}, |
| 420 | {97750, 8, 42, 29}, |
| 421 | {98000, 8, 45, 31}, |
| 422 | {99000, 8, 22, 15}, |
| 423 | {99750, 8, 34, 23}, |
| 424 | {100000, 6, 20, 18}, |
| 425 | {100500, 6, 19, 17}, |
| 426 | {101000, 6, 37, 33}, |
| 427 | {101250, 8, 21, 14}, |
| 428 | {102000, 6, 17, 15}, |
| 429 | {102250, 6, 25, 22}, |
| 430 | {103000, 8, 29, 19}, |
| 431 | {104000, 8, 37, 24}, |
| 432 | {105000, 8, 28, 18}, |
| 433 | {106000, 8, 22, 14}, |
| 434 | {107000, 8, 46, 29}, |
| 435 | {107214, 8, 27, 17}, |
| 436 | {108000, 8, 24, 15}, |
| 437 | {108108, 8, 173, 108}, |
| 438 | {109000, 6, 23, 19}, |
Eugeni Dodonov | 12a13a3 | 2012-05-09 15:37:29 -0300 | [diff] [blame] | 439 | {110000, 6, 22, 18}, |
| 440 | {110013, 6, 22, 18}, |
| 441 | {110250, 8, 49, 30}, |
| 442 | {110500, 8, 36, 22}, |
| 443 | {111000, 8, 23, 14}, |
| 444 | {111264, 8, 150, 91}, |
| 445 | {111375, 8, 33, 20}, |
| 446 | {112000, 8, 63, 38}, |
| 447 | {112500, 8, 25, 15}, |
| 448 | {113100, 8, 57, 34}, |
| 449 | {113309, 8, 42, 25}, |
| 450 | {114000, 8, 27, 16}, |
| 451 | {115000, 6, 23, 18}, |
| 452 | {116000, 8, 43, 25}, |
| 453 | {117000, 8, 26, 15}, |
| 454 | {117500, 8, 40, 23}, |
| 455 | {118000, 6, 38, 29}, |
| 456 | {119000, 8, 30, 17}, |
| 457 | {119500, 8, 46, 26}, |
| 458 | {119651, 8, 39, 22}, |
| 459 | {120000, 8, 32, 18}, |
| 460 | {121000, 6, 39, 29}, |
| 461 | {121250, 6, 31, 23}, |
| 462 | {121750, 6, 23, 17}, |
| 463 | {122000, 6, 42, 31}, |
| 464 | {122614, 6, 30, 22}, |
| 465 | {123000, 6, 41, 30}, |
| 466 | {123379, 6, 37, 27}, |
| 467 | {124000, 6, 51, 37}, |
| 468 | {125000, 6, 25, 18}, |
| 469 | {125250, 4, 13, 14}, |
| 470 | {125750, 4, 27, 29}, |
| 471 | {126000, 6, 21, 15}, |
| 472 | {127000, 6, 24, 17}, |
| 473 | {127250, 6, 41, 29}, |
| 474 | {128000, 6, 27, 19}, |
| 475 | {129000, 6, 43, 30}, |
| 476 | {129859, 4, 25, 26}, |
| 477 | {130000, 6, 26, 18}, |
| 478 | {130250, 6, 42, 29}, |
| 479 | {131000, 6, 32, 22}, |
| 480 | {131500, 6, 38, 26}, |
| 481 | {131850, 6, 41, 28}, |
| 482 | {132000, 6, 22, 15}, |
| 483 | {132750, 6, 28, 19}, |
| 484 | {133000, 6, 34, 23}, |
| 485 | {133330, 6, 37, 25}, |
| 486 | {134000, 6, 61, 41}, |
| 487 | {135000, 6, 21, 14}, |
| 488 | {135250, 6, 167, 111}, |
| 489 | {136000, 6, 62, 41}, |
| 490 | {137000, 6, 35, 23}, |
| 491 | {138000, 6, 23, 15}, |
| 492 | {138500, 6, 40, 26}, |
| 493 | {138750, 6, 37, 24}, |
| 494 | {139000, 6, 34, 22}, |
| 495 | {139050, 6, 34, 22}, |
| 496 | {139054, 6, 34, 22}, |
| 497 | {140000, 6, 28, 18}, |
| 498 | {141000, 6, 36, 23}, |
| 499 | {141500, 6, 22, 14}, |
| 500 | {142000, 6, 30, 19}, |
| 501 | {143000, 6, 27, 17}, |
| 502 | {143472, 4, 17, 16}, |
| 503 | {144000, 6, 24, 15}, |
| 504 | {145000, 6, 29, 18}, |
| 505 | {146000, 6, 47, 29}, |
| 506 | {146250, 6, 26, 16}, |
| 507 | {147000, 6, 49, 30}, |
| 508 | {147891, 6, 23, 14}, |
| 509 | {148000, 6, 23, 14}, |
| 510 | {148250, 6, 28, 17}, |
| 511 | {148352, 4, 100, 91}, |
| 512 | {148500, 6, 33, 20}, |
| 513 | {149000, 6, 48, 29}, |
| 514 | {150000, 6, 25, 15}, |
| 515 | {151000, 4, 19, 17}, |
| 516 | {152000, 6, 27, 16}, |
| 517 | {152280, 6, 44, 26}, |
| 518 | {153000, 6, 34, 20}, |
| 519 | {154000, 6, 53, 31}, |
| 520 | {155000, 6, 31, 18}, |
| 521 | {155250, 6, 50, 29}, |
| 522 | {155750, 6, 45, 26}, |
| 523 | {156000, 6, 26, 15}, |
| 524 | {157000, 6, 61, 35}, |
| 525 | {157500, 6, 28, 16}, |
| 526 | {158000, 6, 65, 37}, |
| 527 | {158250, 6, 44, 25}, |
| 528 | {159000, 6, 53, 30}, |
| 529 | {159500, 6, 39, 22}, |
| 530 | {160000, 6, 32, 18}, |
| 531 | {161000, 4, 31, 26}, |
| 532 | {162000, 4, 18, 15}, |
| 533 | {162162, 4, 131, 109}, |
| 534 | {162500, 4, 53, 44}, |
| 535 | {163000, 4, 29, 24}, |
| 536 | {164000, 4, 17, 14}, |
| 537 | {165000, 4, 22, 18}, |
| 538 | {166000, 4, 32, 26}, |
| 539 | {167000, 4, 26, 21}, |
| 540 | {168000, 4, 46, 37}, |
| 541 | {169000, 4, 104, 83}, |
| 542 | {169128, 4, 64, 51}, |
| 543 | {169500, 4, 39, 31}, |
| 544 | {170000, 4, 34, 27}, |
| 545 | {171000, 4, 19, 15}, |
| 546 | {172000, 4, 51, 40}, |
| 547 | {172750, 4, 32, 25}, |
| 548 | {172800, 4, 32, 25}, |
| 549 | {173000, 4, 41, 32}, |
| 550 | {174000, 4, 49, 38}, |
| 551 | {174787, 4, 22, 17}, |
| 552 | {175000, 4, 35, 27}, |
| 553 | {176000, 4, 30, 23}, |
| 554 | {177000, 4, 38, 29}, |
| 555 | {178000, 4, 29, 22}, |
| 556 | {178500, 4, 37, 28}, |
| 557 | {179000, 4, 53, 40}, |
| 558 | {179500, 4, 73, 55}, |
| 559 | {180000, 4, 20, 15}, |
| 560 | {181000, 4, 55, 41}, |
| 561 | {182000, 4, 31, 23}, |
| 562 | {183000, 4, 42, 31}, |
| 563 | {184000, 4, 30, 22}, |
| 564 | {184750, 4, 26, 19}, |
| 565 | {185000, 4, 37, 27}, |
| 566 | {186000, 4, 51, 37}, |
| 567 | {187000, 4, 36, 26}, |
| 568 | {188000, 4, 32, 23}, |
| 569 | {189000, 4, 21, 15}, |
| 570 | {190000, 4, 38, 27}, |
| 571 | {190960, 4, 41, 29}, |
| 572 | {191000, 4, 41, 29}, |
| 573 | {192000, 4, 27, 19}, |
| 574 | {192250, 4, 37, 26}, |
| 575 | {193000, 4, 20, 14}, |
| 576 | {193250, 4, 53, 37}, |
| 577 | {194000, 4, 23, 16}, |
| 578 | {194208, 4, 23, 16}, |
| 579 | {195000, 4, 26, 18}, |
| 580 | {196000, 4, 45, 31}, |
| 581 | {197000, 4, 35, 24}, |
| 582 | {197750, 4, 41, 28}, |
| 583 | {198000, 4, 22, 15}, |
| 584 | {198500, 4, 25, 17}, |
| 585 | {199000, 4, 28, 19}, |
| 586 | {200000, 4, 37, 25}, |
| 587 | {201000, 4, 61, 41}, |
| 588 | {202000, 4, 112, 75}, |
| 589 | {202500, 4, 21, 14}, |
| 590 | {203000, 4, 146, 97}, |
| 591 | {204000, 4, 62, 41}, |
| 592 | {204750, 4, 44, 29}, |
| 593 | {205000, 4, 38, 25}, |
| 594 | {206000, 4, 29, 19}, |
| 595 | {207000, 4, 23, 15}, |
| 596 | {207500, 4, 40, 26}, |
| 597 | {208000, 4, 37, 24}, |
| 598 | {208900, 4, 48, 31}, |
| 599 | {209000, 4, 48, 31}, |
| 600 | {209250, 4, 31, 20}, |
| 601 | {210000, 4, 28, 18}, |
| 602 | {211000, 4, 25, 16}, |
| 603 | {212000, 4, 22, 14}, |
| 604 | {213000, 4, 30, 19}, |
| 605 | {213750, 4, 38, 24}, |
| 606 | {214000, 4, 46, 29}, |
| 607 | {214750, 4, 35, 22}, |
| 608 | {215000, 4, 43, 27}, |
| 609 | {216000, 4, 24, 15}, |
| 610 | {217000, 4, 37, 23}, |
| 611 | {218000, 4, 42, 26}, |
| 612 | {218250, 4, 42, 26}, |
| 613 | {218750, 4, 34, 21}, |
| 614 | {219000, 4, 47, 29}, |
Eugeni Dodonov | 12a13a3 | 2012-05-09 15:37:29 -0300 | [diff] [blame] | 615 | {220000, 4, 44, 27}, |
| 616 | {220640, 4, 49, 30}, |
| 617 | {220750, 4, 36, 22}, |
| 618 | {221000, 4, 36, 22}, |
| 619 | {222000, 4, 23, 14}, |
| 620 | {222525, 4, 28, 17}, |
| 621 | {222750, 4, 33, 20}, |
| 622 | {227000, 4, 37, 22}, |
| 623 | {230250, 4, 29, 17}, |
| 624 | {233500, 4, 38, 22}, |
| 625 | {235000, 4, 40, 23}, |
| 626 | {238000, 4, 30, 17}, |
| 627 | {241500, 2, 17, 19}, |
| 628 | {245250, 2, 20, 22}, |
| 629 | {247750, 2, 22, 24}, |
| 630 | {253250, 2, 15, 16}, |
| 631 | {256250, 2, 18, 19}, |
| 632 | {262500, 2, 31, 32}, |
| 633 | {267250, 2, 66, 67}, |
| 634 | {268500, 2, 94, 95}, |
| 635 | {270000, 2, 14, 14}, |
| 636 | {272500, 2, 77, 76}, |
| 637 | {273750, 2, 57, 56}, |
| 638 | {280750, 2, 24, 23}, |
| 639 | {281250, 2, 23, 22}, |
| 640 | {286000, 2, 17, 16}, |
| 641 | {291750, 2, 26, 24}, |
| 642 | {296703, 2, 56, 51}, |
| 643 | {297000, 2, 22, 20}, |
| 644 | {298000, 2, 21, 19}, |
| 645 | }; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 646 | |
| 647 | void intel_ddi_mode_set(struct drm_encoder *encoder, |
| 648 | struct drm_display_mode *mode, |
| 649 | struct drm_display_mode *adjusted_mode) |
| 650 | { |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 651 | struct drm_crtc *crtc = encoder->crtc; |
| 652 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 653 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 654 | int port = intel_hdmi->ddi_port; |
| 655 | int pipe = intel_crtc->pipe; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 656 | |
| 657 | /* On Haswell, we need to enable the clocks and prepare DDI function to |
| 658 | * work in HDMI mode for this pipe. |
| 659 | */ |
| 660 | DRM_DEBUG_KMS("Preparing HDMI DDI mode for Haswell on port %c, pipe %c\n", port_name(port), pipe_name(pipe)); |
| 661 | |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 662 | if (intel_hdmi->has_audio) { |
| 663 | /* Proper support for digital audio needs a new logic and a new set |
| 664 | * of registers, so we leave it for future patch bombing. |
| 665 | */ |
Wang Xingchao | 4f07854 | 2012-08-09 16:52:16 +0800 | [diff] [blame] | 666 | DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n", |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 667 | pipe_name(intel_crtc->pipe)); |
Wang Xingchao | 4f07854 | 2012-08-09 16:52:16 +0800 | [diff] [blame] | 668 | |
| 669 | /* write eld */ |
| 670 | DRM_DEBUG_DRIVER("HDMI audio: write eld information\n"); |
| 671 | intel_write_eld(encoder, adjusted_mode); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 672 | } |
| 673 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 674 | intel_hdmi->set_infoframes(encoder, adjusted_mode); |
| 675 | } |
| 676 | |
| 677 | static struct intel_encoder * |
| 678 | intel_ddi_get_crtc_encoder(struct drm_crtc *crtc) |
| 679 | { |
| 680 | struct drm_device *dev = crtc->dev; |
| 681 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 682 | struct intel_encoder *intel_encoder, *ret = NULL; |
| 683 | int num_encoders = 0; |
| 684 | |
| 685 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 686 | ret = intel_encoder; |
| 687 | num_encoders++; |
| 688 | } |
| 689 | |
| 690 | if (num_encoders != 1) |
| 691 | WARN(1, "%d encoders on crtc for pipe %d\n", num_encoders, |
| 692 | intel_crtc->pipe); |
| 693 | |
| 694 | BUG_ON(ret == NULL); |
| 695 | return ret; |
| 696 | } |
| 697 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 698 | void intel_ddi_put_crtc_pll(struct drm_crtc *crtc) |
| 699 | { |
| 700 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 701 | struct intel_ddi_plls *plls = &dev_priv->ddi_plls; |
| 702 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 703 | uint32_t val; |
| 704 | |
| 705 | switch (intel_crtc->ddi_pll_sel) { |
| 706 | case PORT_CLK_SEL_SPLL: |
| 707 | plls->spll_refcount--; |
| 708 | if (plls->spll_refcount == 0) { |
| 709 | DRM_DEBUG_KMS("Disabling SPLL\n"); |
| 710 | val = I915_READ(SPLL_CTL); |
| 711 | WARN_ON(!(val & SPLL_PLL_ENABLE)); |
| 712 | I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE); |
| 713 | POSTING_READ(SPLL_CTL); |
| 714 | } |
| 715 | break; |
| 716 | case PORT_CLK_SEL_WRPLL1: |
| 717 | plls->wrpll1_refcount--; |
| 718 | if (plls->wrpll1_refcount == 0) { |
| 719 | DRM_DEBUG_KMS("Disabling WRPLL 1\n"); |
| 720 | val = I915_READ(WRPLL_CTL1); |
| 721 | WARN_ON(!(val & WRPLL_PLL_ENABLE)); |
| 722 | I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE); |
| 723 | POSTING_READ(WRPLL_CTL1); |
| 724 | } |
| 725 | break; |
| 726 | case PORT_CLK_SEL_WRPLL2: |
| 727 | plls->wrpll2_refcount--; |
| 728 | if (plls->wrpll2_refcount == 0) { |
| 729 | DRM_DEBUG_KMS("Disabling WRPLL 2\n"); |
| 730 | val = I915_READ(WRPLL_CTL2); |
| 731 | WARN_ON(!(val & WRPLL_PLL_ENABLE)); |
| 732 | I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE); |
| 733 | POSTING_READ(WRPLL_CTL2); |
| 734 | } |
| 735 | break; |
| 736 | } |
| 737 | |
| 738 | WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n"); |
| 739 | WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n"); |
| 740 | WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n"); |
| 741 | |
| 742 | intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE; |
| 743 | } |
| 744 | |
| 745 | static void intel_ddi_calculate_wrpll(int clock, int *p, int *n2, int *r2) |
| 746 | { |
| 747 | u32 i; |
| 748 | |
| 749 | for (i = 0; i < ARRAY_SIZE(wrpll_tmds_clock_table); i++) |
| 750 | if (clock <= wrpll_tmds_clock_table[i].clock) |
| 751 | break; |
| 752 | |
| 753 | if (i == ARRAY_SIZE(wrpll_tmds_clock_table)) |
| 754 | i--; |
| 755 | |
| 756 | *p = wrpll_tmds_clock_table[i].p; |
| 757 | *n2 = wrpll_tmds_clock_table[i].n2; |
| 758 | *r2 = wrpll_tmds_clock_table[i].r2; |
| 759 | |
| 760 | if (wrpll_tmds_clock_table[i].clock != clock) |
| 761 | DRM_INFO("WRPLL: using settings for %dKHz on %dKHz mode\n", |
| 762 | wrpll_tmds_clock_table[i].clock, clock); |
| 763 | |
| 764 | DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n", |
| 765 | clock, *p, *n2, *r2); |
| 766 | } |
| 767 | |
| 768 | bool intel_ddi_pll_mode_set(struct drm_crtc *crtc, int clock) |
| 769 | { |
| 770 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 771 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Paulo Zanoni | 068759b | 2012-10-15 15:51:31 -0300 | [diff] [blame] | 772 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 773 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 774 | struct intel_ddi_plls *plls = &dev_priv->ddi_plls; |
| 775 | int type = intel_encoder->type; |
| 776 | enum pipe pipe = intel_crtc->pipe; |
| 777 | uint32_t reg, val; |
| 778 | |
| 779 | /* TODO: reuse PLLs when possible (compare values) */ |
| 780 | |
| 781 | intel_ddi_put_crtc_pll(crtc); |
| 782 | |
Paulo Zanoni | 068759b | 2012-10-15 15:51:31 -0300 | [diff] [blame] | 783 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
| 784 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 785 | |
| 786 | switch (intel_dp->link_bw) { |
| 787 | case DP_LINK_BW_1_62: |
| 788 | intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810; |
| 789 | break; |
| 790 | case DP_LINK_BW_2_7: |
| 791 | intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350; |
| 792 | break; |
| 793 | case DP_LINK_BW_5_4: |
| 794 | intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700; |
| 795 | break; |
| 796 | default: |
| 797 | DRM_ERROR("Link bandwidth %d unsupported\n", |
| 798 | intel_dp->link_bw); |
| 799 | return false; |
| 800 | } |
| 801 | |
| 802 | /* We don't need to turn any PLL on because we'll use LCPLL. */ |
| 803 | return true; |
| 804 | |
| 805 | } else if (type == INTEL_OUTPUT_HDMI) { |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 806 | int p, n2, r2; |
| 807 | |
| 808 | if (plls->wrpll1_refcount == 0) { |
| 809 | DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n", |
| 810 | pipe_name(pipe)); |
| 811 | plls->wrpll1_refcount++; |
| 812 | reg = WRPLL_CTL1; |
| 813 | intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1; |
| 814 | } else if (plls->wrpll2_refcount == 0) { |
| 815 | DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n", |
| 816 | pipe_name(pipe)); |
| 817 | plls->wrpll2_refcount++; |
| 818 | reg = WRPLL_CTL2; |
| 819 | intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2; |
| 820 | } else { |
| 821 | DRM_ERROR("No WRPLLs available!\n"); |
| 822 | return false; |
| 823 | } |
| 824 | |
| 825 | WARN(I915_READ(reg) & WRPLL_PLL_ENABLE, |
| 826 | "WRPLL already enabled\n"); |
| 827 | |
| 828 | intel_ddi_calculate_wrpll(clock, &p, &n2, &r2); |
| 829 | |
| 830 | val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 | |
| 831 | WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) | |
| 832 | WRPLL_DIVIDER_POST(p); |
| 833 | |
| 834 | } else if (type == INTEL_OUTPUT_ANALOG) { |
| 835 | if (plls->spll_refcount == 0) { |
| 836 | DRM_DEBUG_KMS("Using SPLL on pipe %c\n", |
| 837 | pipe_name(pipe)); |
| 838 | plls->spll_refcount++; |
| 839 | reg = SPLL_CTL; |
| 840 | intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL; |
| 841 | } |
| 842 | |
| 843 | WARN(I915_READ(reg) & SPLL_PLL_ENABLE, |
| 844 | "SPLL already enabled\n"); |
| 845 | |
Damien Lespiau | 39bc66c | 2012-10-11 15:24:04 +0100 | [diff] [blame] | 846 | val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz | SPLL_PLL_SSC; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 847 | |
| 848 | } else { |
| 849 | WARN(1, "Invalid DDI encoder type %d\n", type); |
| 850 | return false; |
| 851 | } |
| 852 | |
| 853 | I915_WRITE(reg, val); |
| 854 | udelay(20); |
| 855 | |
| 856 | return true; |
| 857 | } |
| 858 | |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 859 | void intel_ddi_set_pipe_settings(struct drm_crtc *crtc) |
| 860 | { |
| 861 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 862 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 863 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 864 | enum pipe pipe = intel_crtc->pipe; |
| 865 | int type = intel_encoder->type; |
| 866 | uint32_t temp; |
| 867 | |
| 868 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
| 869 | |
| 870 | temp = PIPE_MSA_SYNC_CLK; |
| 871 | switch (intel_crtc->bpp) { |
| 872 | case 18: |
| 873 | temp |= PIPE_MSA_6_BPC; |
| 874 | break; |
| 875 | case 24: |
| 876 | temp |= PIPE_MSA_8_BPC; |
| 877 | break; |
| 878 | case 30: |
| 879 | temp |= PIPE_MSA_10_BPC; |
| 880 | break; |
| 881 | case 36: |
| 882 | temp |= PIPE_MSA_12_BPC; |
| 883 | break; |
| 884 | default: |
| 885 | temp |= PIPE_MSA_8_BPC; |
| 886 | WARN(1, "%d bpp unsupported by pipe DDI function\n", |
| 887 | intel_crtc->bpp); |
| 888 | } |
| 889 | I915_WRITE(PIPE_MSA_MISC(pipe), temp); |
| 890 | } |
| 891 | } |
| 892 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 893 | void intel_ddi_enable_pipe_func(struct drm_crtc *crtc) |
| 894 | { |
| 895 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 896 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 897 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 898 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 899 | enum pipe pipe = intel_crtc->pipe; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 900 | int type = intel_encoder->type; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 901 | uint32_t temp; |
| 902 | |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 903 | /* Enable PIPE_DDI_FUNC_CTL for the pipe to work in HDMI mode */ |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 904 | temp = PIPE_DDI_FUNC_ENABLE; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 905 | |
| 906 | switch (intel_crtc->bpp) { |
| 907 | case 18: |
| 908 | temp |= PIPE_DDI_BPC_6; |
| 909 | break; |
| 910 | case 24: |
| 911 | temp |= PIPE_DDI_BPC_8; |
| 912 | break; |
| 913 | case 30: |
| 914 | temp |= PIPE_DDI_BPC_10; |
| 915 | break; |
| 916 | case 36: |
| 917 | temp |= PIPE_DDI_BPC_12; |
| 918 | break; |
| 919 | default: |
| 920 | WARN(1, "%d bpp unsupported by pipe DDI function\n", |
| 921 | intel_crtc->bpp); |
| 922 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 923 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 924 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Paulo Zanoni | f63eb7c4 | 2012-08-08 14:15:28 -0300 | [diff] [blame] | 925 | temp |= PIPE_DDI_PVSYNC; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 926 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Paulo Zanoni | f63eb7c4 | 2012-08-08 14:15:28 -0300 | [diff] [blame] | 927 | temp |= PIPE_DDI_PHSYNC; |
| 928 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 929 | if (type == INTEL_OUTPUT_HDMI) { |
| 930 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 931 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 932 | if (intel_hdmi->has_hdmi_sink) |
| 933 | temp |= PIPE_DDI_MODE_SELECT_HDMI; |
| 934 | else |
| 935 | temp |= PIPE_DDI_MODE_SELECT_DVI; |
| 936 | |
| 937 | temp |= PIPE_DDI_SELECT_PORT(intel_hdmi->ddi_port); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 938 | |
| 939 | } else if (type == INTEL_OUTPUT_ANALOG) { |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 940 | temp |= PIPE_DDI_MODE_SELECT_FDI; |
| 941 | temp |= PIPE_DDI_SELECT_PORT(PORT_E); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 942 | |
| 943 | } else if (type == INTEL_OUTPUT_DISPLAYPORT || |
| 944 | type == INTEL_OUTPUT_EDP) { |
| 945 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 946 | |
| 947 | temp |= PIPE_DDI_MODE_SELECT_DP_SST; |
| 948 | temp |= PIPE_DDI_SELECT_PORT(intel_dp->port); |
| 949 | |
| 950 | switch (intel_dp->lane_count) { |
| 951 | case 1: |
| 952 | temp |= PIPE_DDI_PORT_WIDTH_X1; |
| 953 | break; |
| 954 | case 2: |
| 955 | temp |= PIPE_DDI_PORT_WIDTH_X2; |
| 956 | break; |
| 957 | case 4: |
| 958 | temp |= PIPE_DDI_PORT_WIDTH_X4; |
| 959 | break; |
| 960 | default: |
| 961 | temp |= PIPE_DDI_PORT_WIDTH_X4; |
| 962 | WARN(1, "Unsupported lane count %d\n", |
| 963 | intel_dp->lane_count); |
| 964 | } |
| 965 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 966 | } else { |
| 967 | WARN(1, "Invalid encoder type %d for pipe %d\n", |
| 968 | intel_encoder->type, pipe); |
| 969 | } |
| 970 | |
| 971 | I915_WRITE(DDI_FUNC_CTL(pipe), temp); |
| 972 | } |
| 973 | |
| 974 | void intel_ddi_disable_pipe_func(struct drm_i915_private *dev_priv, |
| 975 | enum pipe pipe) |
| 976 | { |
| 977 | uint32_t reg = DDI_FUNC_CTL(pipe); |
| 978 | uint32_t val = I915_READ(reg); |
| 979 | |
| 980 | val &= ~(PIPE_DDI_FUNC_ENABLE | PIPE_DDI_PORT_MASK); |
| 981 | val |= PIPE_DDI_PORT_NONE; |
| 982 | I915_WRITE(reg, val); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 983 | } |
| 984 | |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 985 | bool intel_ddi_get_hw_state(struct intel_encoder *encoder, |
| 986 | enum pipe *pipe) |
| 987 | { |
| 988 | struct drm_device *dev = encoder->base.dev; |
| 989 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 990 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
| 991 | u32 tmp; |
| 992 | int i; |
| 993 | |
| 994 | tmp = I915_READ(DDI_BUF_CTL(intel_hdmi->ddi_port)); |
| 995 | |
| 996 | if (!(tmp & DDI_BUF_CTL_ENABLE)) |
| 997 | return false; |
| 998 | |
| 999 | for_each_pipe(i) { |
| 1000 | tmp = I915_READ(DDI_FUNC_CTL(i)); |
| 1001 | |
| 1002 | if ((tmp & PIPE_DDI_PORT_MASK) |
| 1003 | == PIPE_DDI_SELECT_PORT(intel_hdmi->ddi_port)) { |
| 1004 | *pipe = i; |
| 1005 | return true; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | DRM_DEBUG_KMS("No pipe for ddi port %i found\n", intel_hdmi->ddi_port); |
| 1010 | |
| 1011 | return true; |
| 1012 | } |
| 1013 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1014 | static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv, |
| 1015 | enum pipe pipe) |
| 1016 | { |
| 1017 | uint32_t temp, ret; |
| 1018 | enum port port; |
| 1019 | int i; |
| 1020 | |
| 1021 | temp = I915_READ(DDI_FUNC_CTL(pipe)); |
| 1022 | temp &= PIPE_DDI_PORT_MASK; |
| 1023 | for (i = PORT_A; i <= PORT_E; i++) |
| 1024 | if (temp == PIPE_DDI_SELECT_PORT(i)) |
| 1025 | port = i; |
| 1026 | |
| 1027 | ret = I915_READ(PORT_CLK_SEL(port)); |
| 1028 | |
| 1029 | DRM_DEBUG_KMS("Pipe %c connected to port %c using clock 0x%08x\n", |
| 1030 | pipe_name(pipe), port_name(port), ret); |
| 1031 | |
| 1032 | return ret; |
| 1033 | } |
| 1034 | |
| 1035 | void intel_ddi_setup_hw_pll_state(struct drm_device *dev) |
| 1036 | { |
| 1037 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1038 | enum pipe pipe; |
| 1039 | struct intel_crtc *intel_crtc; |
| 1040 | |
| 1041 | for_each_pipe(pipe) { |
| 1042 | intel_crtc = |
| 1043 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 1044 | |
| 1045 | if (!intel_crtc->active) |
| 1046 | continue; |
| 1047 | |
| 1048 | intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv, |
| 1049 | pipe); |
| 1050 | |
| 1051 | switch (intel_crtc->ddi_pll_sel) { |
| 1052 | case PORT_CLK_SEL_SPLL: |
| 1053 | dev_priv->ddi_plls.spll_refcount++; |
| 1054 | break; |
| 1055 | case PORT_CLK_SEL_WRPLL1: |
| 1056 | dev_priv->ddi_plls.wrpll1_refcount++; |
| 1057 | break; |
| 1058 | case PORT_CLK_SEL_WRPLL2: |
| 1059 | dev_priv->ddi_plls.wrpll2_refcount++; |
| 1060 | break; |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1065 | void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1066 | { |
| 1067 | struct drm_crtc *crtc = &intel_crtc->base; |
| 1068 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1069 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 1070 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1071 | |
| 1072 | I915_WRITE(PIPE_CLK_SEL(intel_crtc->pipe), PIPE_CLK_SEL_PORT(port)); |
| 1073 | } |
| 1074 | |
| 1075 | void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1076 | { |
| 1077 | struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private; |
| 1078 | |
| 1079 | I915_WRITE(PIPE_CLK_SEL(intel_crtc->pipe), PIPE_CLK_SEL_DISABLED); |
| 1080 | } |
| 1081 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1082 | void intel_ddi_pre_enable(struct intel_encoder *intel_encoder) |
| 1083 | { |
| 1084 | struct drm_crtc *crtc = intel_encoder->base.crtc; |
| 1085 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1086 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1087 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1088 | |
| 1089 | WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE); |
| 1090 | |
| 1091 | I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel); |
| 1092 | } |
| 1093 | |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1094 | static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, |
| 1095 | enum port port) |
| 1096 | { |
| 1097 | uint32_t reg = DDI_BUF_CTL(port); |
| 1098 | int i; |
| 1099 | |
| 1100 | for (i = 0; i < 8; i++) { |
| 1101 | udelay(1); |
| 1102 | if (I915_READ(reg) & DDI_BUF_IS_IDLE) |
| 1103 | return; |
| 1104 | } |
| 1105 | DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port)); |
| 1106 | } |
| 1107 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1108 | void intel_ddi_post_disable(struct intel_encoder *intel_encoder) |
| 1109 | { |
| 1110 | struct drm_encoder *encoder = &intel_encoder->base; |
| 1111 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 1112 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1113 | uint32_t val; |
| 1114 | |
| 1115 | val = I915_READ(DDI_BUF_CTL(port)); |
| 1116 | if (val & DDI_BUF_CTL_ENABLE) { |
| 1117 | val &= ~DDI_BUF_CTL_ENABLE; |
| 1118 | I915_WRITE(DDI_BUF_CTL(port), val); |
| 1119 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 1120 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1121 | |
| 1122 | I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE); |
| 1123 | } |
| 1124 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1125 | void intel_enable_ddi(struct intel_encoder *encoder) |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1126 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1127 | struct drm_device *dev = encoder->base.dev; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1128 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1129 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1130 | int port = intel_hdmi->ddi_port; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1131 | |
| 1132 | /* Enable DDI_BUF_CTL. In HDMI/DVI mode, the port width, |
| 1133 | * and swing/emphasis values are ignored so nothing special needs |
| 1134 | * to be done besides enabling the port. |
| 1135 | */ |
Paulo Zanoni | 1e6210f | 2012-10-05 12:05:59 -0300 | [diff] [blame] | 1136 | I915_WRITE(DDI_BUF_CTL(port), DDI_BUF_CTL_ENABLE); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | void intel_disable_ddi(struct intel_encoder *encoder) |
| 1140 | { |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1141 | /* This will be needed in the future, so leave it here for now */ |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1142 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1143 | |
| 1144 | static int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv) |
| 1145 | { |
| 1146 | if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 1147 | return 450; |
| 1148 | else if ((I915_READ(LCPLL_CTL) & LCPLL_CLK_FREQ_MASK) == |
| 1149 | LCPLL_CLK_FREQ_450) |
| 1150 | return 450; |
| 1151 | else |
| 1152 | return 540; |
| 1153 | } |
| 1154 | |
| 1155 | void intel_ddi_pll_init(struct drm_device *dev) |
| 1156 | { |
| 1157 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1158 | uint32_t val = I915_READ(LCPLL_CTL); |
| 1159 | |
| 1160 | /* The LCPLL register should be turned on by the BIOS. For now let's |
| 1161 | * just check its state and print errors in case something is wrong. |
| 1162 | * Don't even try to turn it on. |
| 1163 | */ |
| 1164 | |
| 1165 | DRM_DEBUG_KMS("CDCLK running at %dMHz\n", |
| 1166 | intel_ddi_get_cdclk_freq(dev_priv)); |
| 1167 | |
| 1168 | if (val & LCPLL_CD_SOURCE_FCLK) |
| 1169 | DRM_ERROR("CDCLK source is not LCPLL\n"); |
| 1170 | |
| 1171 | if (val & LCPLL_PLL_DISABLE) |
| 1172 | DRM_ERROR("LCPLL is disabled\n"); |
| 1173 | } |