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, |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | static const u32 hsw_ddi_translations_fdi[] = { |
| 48 | 0x00FFFFFF, 0x0007000E, /* FDI parameters */ |
| 49 | 0x00D75FFF, 0x000F000A, |
| 50 | 0x00C30FFF, 0x00060006, |
| 51 | 0x00AAAFFF, 0x001E0000, |
| 52 | 0x00FFFFFF, 0x000F000A, |
| 53 | 0x00D75FFF, 0x00160004, |
| 54 | 0x00C30FFF, 0x001E0000, |
| 55 | 0x00FFFFFF, 0x00060006, |
| 56 | 0x00D75FFF, 0x001E0000, |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static const u32 hsw_ddi_translations_hdmi[] = { |
| 60 | /* Idx NT mV diff T mV diff db */ |
| 61 | 0x00FFFFFF, 0x0006000E, /* 0: 400 400 0 */ |
| 62 | 0x00E79FFF, 0x000E000C, /* 1: 400 500 2 */ |
| 63 | 0x00D75FFF, 0x0005000A, /* 2: 400 600 3.5 */ |
| 64 | 0x00FFFFFF, 0x0005000A, /* 3: 600 600 0 */ |
| 65 | 0x00E79FFF, 0x001D0007, /* 4: 600 750 2 */ |
| 66 | 0x00D75FFF, 0x000C0004, /* 5: 600 900 3.5 */ |
| 67 | 0x00FFFFFF, 0x00040006, /* 6: 800 800 0 */ |
| 68 | 0x80E79FFF, 0x00030002, /* 7: 800 1000 2 */ |
| 69 | 0x00FFFFFF, 0x00140005, /* 8: 850 850 0 */ |
| 70 | 0x00FFFFFF, 0x000C0004, /* 9: 900 900 0 */ |
| 71 | 0x00FFFFFF, 0x001C0003, /* 10: 950 950 0 */ |
| 72 | 0x80FFFFFF, 0x00030002, /* 11: 1000 1000 0 */ |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 73 | }; |
| 74 | |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 75 | static const u32 bdw_ddi_translations_edp[] = { |
Damien Lespiau | e1b2273 | 2013-12-03 13:46:58 +0000 | [diff] [blame] | 76 | 0x00FFFFFF, 0x00000012, /* eDP parameters */ |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 77 | 0x00EBAFFF, 0x00020011, |
| 78 | 0x00C71FFF, 0x0006000F, |
Paulo Zanoni | 9576c27 | 2014-06-13 18:45:40 -0300 | [diff] [blame] | 79 | 0x00AAAFFF, 0x000E000A, |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 80 | 0x00FFFFFF, 0x00020011, |
| 81 | 0x00DB6FFF, 0x0005000F, |
| 82 | 0x00BEEFFF, 0x000A000C, |
| 83 | 0x00FFFFFF, 0x0005000F, |
| 84 | 0x00DB6FFF, 0x000A000C, |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 85 | 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/ |
| 86 | }; |
| 87 | |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 88 | static const u32 bdw_ddi_translations_dp[] = { |
| 89 | 0x00FFFFFF, 0x0007000E, /* DP parameters */ |
| 90 | 0x00D75FFF, 0x000E000A, |
| 91 | 0x00BEFFFF, 0x00140006, |
Paulo Zanoni | 9576c27 | 2014-06-13 18:45:40 -0300 | [diff] [blame] | 92 | 0x80B2CFFF, 0x001B0002, |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 93 | 0x00FFFFFF, 0x000E000A, |
| 94 | 0x00D75FFF, 0x00180004, |
| 95 | 0x80CB2FFF, 0x001B0002, |
| 96 | 0x00F7DFFF, 0x00180004, |
| 97 | 0x80D75FFF, 0x001B0002, |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 98 | 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/ |
| 99 | }; |
| 100 | |
| 101 | static const u32 bdw_ddi_translations_fdi[] = { |
| 102 | 0x00FFFFFF, 0x0001000E, /* FDI parameters */ |
| 103 | 0x00D75FFF, 0x0004000A, |
| 104 | 0x00C30FFF, 0x00070006, |
| 105 | 0x00AAAFFF, 0x000C0000, |
| 106 | 0x00FFFFFF, 0x0004000A, |
| 107 | 0x00D75FFF, 0x00090004, |
| 108 | 0x00C30FFF, 0x000C0000, |
| 109 | 0x00FFFFFF, 0x00070006, |
| 110 | 0x00D75FFF, 0x000C0000, |
| 111 | 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/ |
| 112 | }; |
| 113 | |
Jani Nikula | 20f4dbe | 2013-08-30 19:40:28 +0300 | [diff] [blame] | 114 | enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder) |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 115 | { |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame] | 116 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 117 | int type = intel_encoder->type; |
| 118 | |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 119 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 120 | type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 121 | struct intel_digital_port *intel_dig_port = |
| 122 | enc_to_dig_port(encoder); |
| 123 | return intel_dig_port->port; |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame] | 124 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 125 | } else if (type == INTEL_OUTPUT_ANALOG) { |
| 126 | return PORT_E; |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame] | 127 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 128 | } else { |
| 129 | DRM_ERROR("Invalid DDI encoder type %d\n", type); |
| 130 | BUG(); |
| 131 | } |
| 132 | } |
| 133 | |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 134 | /* |
| 135 | * Starting with Haswell, DDI port buffers must be programmed with correct |
| 136 | * values in advance. The buffer values are different for FDI and DP modes, |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 137 | * but the HDMI/DVI fields are shared among those. So we program the DDI |
| 138 | * in either FDI or DP modes only, as HDMI connections will work with both |
| 139 | * of those |
| 140 | */ |
Paulo Zanoni | ad8d270 | 2013-08-05 17:25:56 -0300 | [diff] [blame] | 141 | static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port) |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 142 | { |
| 143 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 144 | u32 reg; |
| 145 | int i; |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 146 | int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 147 | const u32 *ddi_translations_fdi; |
| 148 | const u32 *ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 149 | const u32 *ddi_translations_edp; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 150 | const u32 *ddi_translations; |
| 151 | |
| 152 | if (IS_BROADWELL(dev)) { |
| 153 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 154 | ddi_translations_dp = bdw_ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 155 | ddi_translations_edp = bdw_ddi_translations_edp; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 156 | } else if (IS_HASWELL(dev)) { |
| 157 | ddi_translations_fdi = hsw_ddi_translations_fdi; |
| 158 | ddi_translations_dp = hsw_ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 159 | ddi_translations_edp = hsw_ddi_translations_dp; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 160 | } else { |
| 161 | WARN(1, "ddi translation table missing\n"); |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 162 | ddi_translations_edp = bdw_ddi_translations_dp; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 163 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 164 | ddi_translations_dp = bdw_ddi_translations_dp; |
| 165 | } |
| 166 | |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 167 | switch (port) { |
| 168 | case PORT_A: |
| 169 | ddi_translations = ddi_translations_edp; |
| 170 | break; |
| 171 | case PORT_B: |
| 172 | case PORT_C: |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 173 | ddi_translations = ddi_translations_dp; |
| 174 | break; |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 175 | case PORT_D: |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 176 | if (intel_dp_is_edp(dev, PORT_D)) |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 177 | ddi_translations = ddi_translations_edp; |
| 178 | else |
| 179 | ddi_translations = ddi_translations_dp; |
| 180 | break; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 181 | case PORT_E: |
| 182 | ddi_translations = ddi_translations_fdi; |
| 183 | break; |
| 184 | default: |
| 185 | BUG(); |
| 186 | } |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 187 | |
Paulo Zanoni | f72d19f | 2013-08-05 17:25:55 -0300 | [diff] [blame] | 188 | for (i = 0, reg = DDI_BUF_TRANS(port); |
| 189 | i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) { |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 190 | I915_WRITE(reg, ddi_translations[i]); |
| 191 | reg += 4; |
| 192 | } |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 193 | /* Entry 9 is for HDMI: */ |
| 194 | for (i = 0; i < 2; i++) { |
| 195 | I915_WRITE(reg, hsw_ddi_translations_hdmi[hdmi_level * 2 + i]); |
| 196 | reg += 4; |
| 197 | } |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* Program DDI buffers translations for DP. By default, program ports A-D in DP |
| 201 | * mode and port E for FDI. |
| 202 | */ |
| 203 | void intel_prepare_ddi(struct drm_device *dev) |
| 204 | { |
| 205 | int port; |
| 206 | |
Paulo Zanoni | 0d536cb | 2012-11-23 16:46:41 -0200 | [diff] [blame] | 207 | if (!HAS_DDI(dev)) |
| 208 | return; |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 209 | |
Paulo Zanoni | ad8d270 | 2013-08-05 17:25:56 -0300 | [diff] [blame] | 210 | for (port = PORT_A; port <= PORT_E; port++) |
| 211 | intel_prepare_ddi_buffers(dev, port); |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 212 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 213 | |
| 214 | static const long hsw_ddi_buf_ctl_values[] = { |
| 215 | DDI_BUF_EMP_400MV_0DB_HSW, |
| 216 | DDI_BUF_EMP_400MV_3_5DB_HSW, |
| 217 | DDI_BUF_EMP_400MV_6DB_HSW, |
| 218 | DDI_BUF_EMP_400MV_9_5DB_HSW, |
| 219 | DDI_BUF_EMP_600MV_0DB_HSW, |
| 220 | DDI_BUF_EMP_600MV_3_5DB_HSW, |
| 221 | DDI_BUF_EMP_600MV_6DB_HSW, |
| 222 | DDI_BUF_EMP_800MV_0DB_HSW, |
| 223 | DDI_BUF_EMP_800MV_3_5DB_HSW |
| 224 | }; |
| 225 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 226 | static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, |
| 227 | enum port port) |
| 228 | { |
| 229 | uint32_t reg = DDI_BUF_CTL(port); |
| 230 | int i; |
| 231 | |
| 232 | for (i = 0; i < 8; i++) { |
| 233 | udelay(1); |
| 234 | if (I915_READ(reg) & DDI_BUF_IS_IDLE) |
| 235 | return; |
| 236 | } |
| 237 | DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port)); |
| 238 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 239 | |
| 240 | /* Starting with Haswell, different DDI ports can work in FDI mode for |
| 241 | * connection to the PCH-located connectors. For this, it is necessary to train |
| 242 | * both the DDI port and PCH receiver for the desired DDI buffer settings. |
| 243 | * |
| 244 | * The recommended port to work in FDI mode is DDI E, which we use here. Also, |
| 245 | * please note that when FDI mode is active on DDI E, it shares 2 lines with |
| 246 | * DDI A (which is used for eDP) |
| 247 | */ |
| 248 | |
| 249 | void hsw_fdi_link_train(struct drm_crtc *crtc) |
| 250 | { |
| 251 | struct drm_device *dev = crtc->dev; |
| 252 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 253 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 254 | u32 temp, i, rx_ctl_val; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 255 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 256 | /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the |
| 257 | * mode set "sequence for CRT port" document: |
| 258 | * - TP1 to TP2 time with the default value |
| 259 | * - FDI delay to 90h |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 260 | * |
| 261 | * WaFDIAutoLinkSetTimingOverrride:hsw |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 262 | */ |
| 263 | I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) | |
| 264 | FDI_RX_PWRDN_LANE0_VAL(2) | |
| 265 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 266 | |
| 267 | /* Enable the PCH Receiver FDI PLL */ |
Damien Lespiau | 3e68320 | 2012-12-11 18:48:29 +0000 | [diff] [blame] | 268 | rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE | |
Daniel Vetter | 33d29b1 | 2013-02-13 18:04:45 +0100 | [diff] [blame] | 269 | FDI_RX_PLL_ENABLE | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 270 | FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 271 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 272 | POSTING_READ(_FDI_RXA_CTL); |
| 273 | udelay(220); |
| 274 | |
| 275 | /* Switch from Rawclk to PCDclk */ |
| 276 | rx_ctl_val |= FDI_PCDCLK; |
| 277 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 278 | |
| 279 | /* Configure Port Clock Select */ |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 280 | I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config.ddi_pll_sel); |
| 281 | WARN_ON(intel_crtc->config.ddi_pll_sel != PORT_CLK_SEL_SPLL); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 282 | |
| 283 | /* Start the training iterating through available voltages and emphasis, |
| 284 | * testing each value twice. */ |
| 285 | for (i = 0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values) * 2; i++) { |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 286 | /* Configure DP_TP_CTL with auto-training */ |
| 287 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 288 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 289 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 290 | DP_TP_CTL_LINK_TRAIN_PAT1 | |
| 291 | DP_TP_CTL_ENABLE); |
| 292 | |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 293 | /* Configure and enable DDI_BUF_CTL for DDI E with next voltage. |
| 294 | * DDI E does not support port reversal, the functionality is |
| 295 | * achieved on the PCH side in FDI_RX_CTL, so no need to set the |
| 296 | * port reversal bit */ |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 297 | I915_WRITE(DDI_BUF_CTL(PORT_E), |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 298 | DDI_BUF_CTL_ENABLE | |
Daniel Vetter | 33d29b1 | 2013-02-13 18:04:45 +0100 | [diff] [blame] | 299 | ((intel_crtc->config.fdi_lanes - 1) << 1) | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 300 | hsw_ddi_buf_ctl_values[i / 2]); |
| 301 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 302 | |
| 303 | udelay(600); |
| 304 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 305 | /* Program PCH FDI Receiver TU */ |
| 306 | I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64)); |
Eugeni Dodonov | 4acf518 | 2012-07-04 20:15:16 -0300 | [diff] [blame] | 307 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 308 | /* Enable PCH FDI Receiver with auto-training */ |
| 309 | rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO; |
| 310 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 311 | POSTING_READ(_FDI_RXA_CTL); |
| 312 | |
| 313 | /* Wait for FDI receiver lane calibration */ |
| 314 | udelay(30); |
| 315 | |
| 316 | /* Unset FDI_RX_MISC pwrdn lanes */ |
| 317 | temp = I915_READ(_FDI_RXA_MISC); |
| 318 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 319 | I915_WRITE(_FDI_RXA_MISC, temp); |
| 320 | POSTING_READ(_FDI_RXA_MISC); |
| 321 | |
| 322 | /* Wait for FDI auto training time */ |
| 323 | udelay(5); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 324 | |
| 325 | temp = I915_READ(DP_TP_STATUS(PORT_E)); |
| 326 | if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 327 | DRM_DEBUG_KMS("FDI link training done on step %d\n", i); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 328 | |
| 329 | /* Enable normal pixel sending for FDI */ |
| 330 | I915_WRITE(DP_TP_CTL(PORT_E), |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 331 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 332 | DP_TP_CTL_LINK_TRAIN_NORMAL | |
| 333 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 334 | DP_TP_CTL_ENABLE); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 335 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 336 | return; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 337 | } |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 338 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 339 | temp = I915_READ(DDI_BUF_CTL(PORT_E)); |
| 340 | temp &= ~DDI_BUF_CTL_ENABLE; |
| 341 | I915_WRITE(DDI_BUF_CTL(PORT_E), temp); |
| 342 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
| 343 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 344 | /* Disable DP_TP_CTL and FDI_RX_CTL and retry */ |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 345 | temp = I915_READ(DP_TP_CTL(PORT_E)); |
| 346 | temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 347 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 348 | I915_WRITE(DP_TP_CTL(PORT_E), temp); |
| 349 | POSTING_READ(DP_TP_CTL(PORT_E)); |
| 350 | |
| 351 | intel_wait_ddi_buf_idle(dev_priv, PORT_E); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 352 | |
| 353 | rx_ctl_val &= ~FDI_RX_ENABLE; |
| 354 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 355 | POSTING_READ(_FDI_RXA_CTL); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 356 | |
| 357 | /* Reset FDI_RX_MISC pwrdn lanes */ |
| 358 | temp = I915_READ(_FDI_RXA_MISC); |
| 359 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 360 | temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
| 361 | I915_WRITE(_FDI_RXA_MISC, temp); |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 362 | POSTING_READ(_FDI_RXA_MISC); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 363 | } |
| 364 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 365 | DRM_ERROR("FDI link training failed!\n"); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 366 | } |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 367 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 368 | static struct intel_encoder * |
| 369 | intel_ddi_get_crtc_encoder(struct drm_crtc *crtc) |
| 370 | { |
| 371 | struct drm_device *dev = crtc->dev; |
| 372 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 373 | struct intel_encoder *intel_encoder, *ret = NULL; |
| 374 | int num_encoders = 0; |
| 375 | |
| 376 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 377 | ret = intel_encoder; |
| 378 | num_encoders++; |
| 379 | } |
| 380 | |
| 381 | if (num_encoders != 1) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 382 | WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders, |
| 383 | pipe_name(intel_crtc->pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 384 | |
| 385 | BUG_ON(ret == NULL); |
| 386 | return ret; |
| 387 | } |
| 388 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 389 | void intel_ddi_put_crtc_pll(struct drm_crtc *crtc) |
| 390 | { |
| 391 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 392 | struct intel_ddi_plls *plls = &dev_priv->ddi_plls; |
| 393 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame^] | 394 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(intel_crtc); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 395 | |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 396 | switch (intel_crtc->config.ddi_pll_sel) { |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 397 | case PORT_CLK_SEL_WRPLL1: |
| 398 | plls->wrpll1_refcount--; |
| 399 | if (plls->wrpll1_refcount == 0) { |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame^] | 400 | pll->disable(dev_priv, pll); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 401 | } |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 402 | intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 403 | break; |
| 404 | case PORT_CLK_SEL_WRPLL2: |
| 405 | plls->wrpll2_refcount--; |
| 406 | if (plls->wrpll2_refcount == 0) { |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame^] | 407 | pll->disable(dev_priv, pll); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 408 | } |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 409 | intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 410 | break; |
| 411 | } |
| 412 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 413 | WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n"); |
| 414 | WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n"); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 415 | } |
| 416 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 417 | #define LC_FREQ 2700 |
| 418 | #define LC_FREQ_2K (LC_FREQ * 2000) |
| 419 | |
| 420 | #define P_MIN 2 |
| 421 | #define P_MAX 64 |
| 422 | #define P_INC 2 |
| 423 | |
| 424 | /* Constraints for PLL good behavior */ |
| 425 | #define REF_MIN 48 |
| 426 | #define REF_MAX 400 |
| 427 | #define VCO_MIN 2400 |
| 428 | #define VCO_MAX 4800 |
| 429 | |
| 430 | #define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a)) |
| 431 | |
| 432 | struct wrpll_rnp { |
| 433 | unsigned p, n2, r2; |
| 434 | }; |
| 435 | |
| 436 | static unsigned wrpll_get_budget_for_freq(int clock) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 437 | { |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 438 | unsigned budget; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 439 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 440 | switch (clock) { |
| 441 | case 25175000: |
| 442 | case 25200000: |
| 443 | case 27000000: |
| 444 | case 27027000: |
| 445 | case 37762500: |
| 446 | case 37800000: |
| 447 | case 40500000: |
| 448 | case 40541000: |
| 449 | case 54000000: |
| 450 | case 54054000: |
| 451 | case 59341000: |
| 452 | case 59400000: |
| 453 | case 72000000: |
| 454 | case 74176000: |
| 455 | case 74250000: |
| 456 | case 81000000: |
| 457 | case 81081000: |
| 458 | case 89012000: |
| 459 | case 89100000: |
| 460 | case 108000000: |
| 461 | case 108108000: |
| 462 | case 111264000: |
| 463 | case 111375000: |
| 464 | case 148352000: |
| 465 | case 148500000: |
| 466 | case 162000000: |
| 467 | case 162162000: |
| 468 | case 222525000: |
| 469 | case 222750000: |
| 470 | case 296703000: |
| 471 | case 297000000: |
| 472 | budget = 0; |
| 473 | break; |
| 474 | case 233500000: |
| 475 | case 245250000: |
| 476 | case 247750000: |
| 477 | case 253250000: |
| 478 | case 298000000: |
| 479 | budget = 1500; |
| 480 | break; |
| 481 | case 169128000: |
| 482 | case 169500000: |
| 483 | case 179500000: |
| 484 | case 202000000: |
| 485 | budget = 2000; |
| 486 | break; |
| 487 | case 256250000: |
| 488 | case 262500000: |
| 489 | case 270000000: |
| 490 | case 272500000: |
| 491 | case 273750000: |
| 492 | case 280750000: |
| 493 | case 281250000: |
| 494 | case 286000000: |
| 495 | case 291750000: |
| 496 | budget = 4000; |
| 497 | break; |
| 498 | case 267250000: |
| 499 | case 268500000: |
| 500 | budget = 5000; |
| 501 | break; |
| 502 | default: |
| 503 | budget = 1000; |
| 504 | break; |
| 505 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 506 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 507 | return budget; |
| 508 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 509 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 510 | static void wrpll_update_rnp(uint64_t freq2k, unsigned budget, |
| 511 | unsigned r2, unsigned n2, unsigned p, |
| 512 | struct wrpll_rnp *best) |
| 513 | { |
| 514 | uint64_t a, b, c, d, diff, diff_best; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 515 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 516 | /* No best (r,n,p) yet */ |
| 517 | if (best->p == 0) { |
| 518 | best->p = p; |
| 519 | best->n2 = n2; |
| 520 | best->r2 = r2; |
| 521 | return; |
| 522 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 523 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 524 | /* |
| 525 | * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to |
| 526 | * freq2k. |
| 527 | * |
| 528 | * delta = 1e6 * |
| 529 | * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) / |
| 530 | * freq2k; |
| 531 | * |
| 532 | * and we would like delta <= budget. |
| 533 | * |
| 534 | * If the discrepancy is above the PPM-based budget, always prefer to |
| 535 | * improve upon the previous solution. However, if you're within the |
| 536 | * budget, try to maximize Ref * VCO, that is N / (P * R^2). |
| 537 | */ |
| 538 | a = freq2k * budget * p * r2; |
| 539 | b = freq2k * budget * best->p * best->r2; |
| 540 | diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2)); |
| 541 | diff_best = ABS_DIFF((freq2k * best->p * best->r2), |
| 542 | (LC_FREQ_2K * best->n2)); |
| 543 | c = 1000000 * diff; |
| 544 | d = 1000000 * diff_best; |
| 545 | |
| 546 | if (a < c && b < d) { |
| 547 | /* If both are above the budget, pick the closer */ |
| 548 | if (best->p * best->r2 * diff < p * r2 * diff_best) { |
| 549 | best->p = p; |
| 550 | best->n2 = n2; |
| 551 | best->r2 = r2; |
| 552 | } |
| 553 | } else if (a >= c && b < d) { |
| 554 | /* If A is below the threshold but B is above it? Update. */ |
| 555 | best->p = p; |
| 556 | best->n2 = n2; |
| 557 | best->r2 = r2; |
| 558 | } else if (a >= c && b >= d) { |
| 559 | /* Both are below the limit, so pick the higher n2/(r2*r2) */ |
| 560 | if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) { |
| 561 | best->p = p; |
| 562 | best->n2 = n2; |
| 563 | best->r2 = r2; |
| 564 | } |
| 565 | } |
| 566 | /* Otherwise a < c && b >= d, do nothing */ |
| 567 | } |
| 568 | |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 569 | static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv, |
| 570 | int reg) |
| 571 | { |
| 572 | int refclk = LC_FREQ; |
| 573 | int n, p, r; |
| 574 | u32 wrpll; |
| 575 | |
| 576 | wrpll = I915_READ(reg); |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 577 | switch (wrpll & WRPLL_PLL_REF_MASK) { |
| 578 | case WRPLL_PLL_SSC: |
| 579 | case WRPLL_PLL_NON_SSC: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 580 | /* |
| 581 | * We could calculate spread here, but our checking |
| 582 | * code only cares about 5% accuracy, and spread is a max of |
| 583 | * 0.5% downspread. |
| 584 | */ |
| 585 | refclk = 135; |
| 586 | break; |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 587 | case WRPLL_PLL_LCPLL: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 588 | refclk = LC_FREQ; |
| 589 | break; |
| 590 | default: |
| 591 | WARN(1, "bad wrpll refclk\n"); |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | r = wrpll & WRPLL_DIVIDER_REF_MASK; |
| 596 | p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT; |
| 597 | n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT; |
| 598 | |
Jesse Barnes | 20f0ec1 | 2014-01-22 12:58:04 -0800 | [diff] [blame] | 599 | /* Convert to KHz, p & r have a fixed point portion */ |
| 600 | return (refclk * n * 100) / (p * r); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static void intel_ddi_clock_get(struct intel_encoder *encoder, |
| 604 | struct intel_crtc_config *pipe_config) |
| 605 | { |
| 606 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 607 | int link_clock = 0; |
| 608 | u32 val, pll; |
| 609 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 610 | val = pipe_config->ddi_pll_sel; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 611 | switch (val & PORT_CLK_SEL_MASK) { |
| 612 | case PORT_CLK_SEL_LCPLL_810: |
| 613 | link_clock = 81000; |
| 614 | break; |
| 615 | case PORT_CLK_SEL_LCPLL_1350: |
| 616 | link_clock = 135000; |
| 617 | break; |
| 618 | case PORT_CLK_SEL_LCPLL_2700: |
| 619 | link_clock = 270000; |
| 620 | break; |
| 621 | case PORT_CLK_SEL_WRPLL1: |
| 622 | link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1); |
| 623 | break; |
| 624 | case PORT_CLK_SEL_WRPLL2: |
| 625 | link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2); |
| 626 | break; |
| 627 | case PORT_CLK_SEL_SPLL: |
| 628 | pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK; |
| 629 | if (pll == SPLL_PLL_FREQ_810MHz) |
| 630 | link_clock = 81000; |
| 631 | else if (pll == SPLL_PLL_FREQ_1350MHz) |
| 632 | link_clock = 135000; |
| 633 | else if (pll == SPLL_PLL_FREQ_2700MHz) |
| 634 | link_clock = 270000; |
| 635 | else { |
| 636 | WARN(1, "bad spll freq\n"); |
| 637 | return; |
| 638 | } |
| 639 | break; |
| 640 | default: |
| 641 | WARN(1, "bad port clock sel\n"); |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | pipe_config->port_clock = link_clock * 2; |
| 646 | |
| 647 | if (pipe_config->has_pch_encoder) |
| 648 | pipe_config->adjusted_mode.crtc_clock = |
| 649 | intel_dotclock_calculate(pipe_config->port_clock, |
| 650 | &pipe_config->fdi_m_n); |
| 651 | else if (pipe_config->has_dp_encoder) |
| 652 | pipe_config->adjusted_mode.crtc_clock = |
| 653 | intel_dotclock_calculate(pipe_config->port_clock, |
| 654 | &pipe_config->dp_m_n); |
| 655 | else |
| 656 | pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock; |
| 657 | } |
| 658 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 659 | static void |
| 660 | intel_ddi_calculate_wrpll(int clock /* in Hz */, |
| 661 | unsigned *r2_out, unsigned *n2_out, unsigned *p_out) |
| 662 | { |
| 663 | uint64_t freq2k; |
| 664 | unsigned p, n2, r2; |
| 665 | struct wrpll_rnp best = { 0, 0, 0 }; |
| 666 | unsigned budget; |
| 667 | |
| 668 | freq2k = clock / 100; |
| 669 | |
| 670 | budget = wrpll_get_budget_for_freq(clock); |
| 671 | |
| 672 | /* Special case handling for 540 pixel clock: bypass WR PLL entirely |
| 673 | * and directly pass the LC PLL to it. */ |
| 674 | if (freq2k == 5400000) { |
| 675 | *n2_out = 2; |
| 676 | *p_out = 1; |
| 677 | *r2_out = 2; |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | /* |
| 682 | * Ref = LC_FREQ / R, where Ref is the actual reference input seen by |
| 683 | * the WR PLL. |
| 684 | * |
| 685 | * We want R so that REF_MIN <= Ref <= REF_MAX. |
| 686 | * Injecting R2 = 2 * R gives: |
| 687 | * REF_MAX * r2 > LC_FREQ * 2 and |
| 688 | * REF_MIN * r2 < LC_FREQ * 2 |
| 689 | * |
| 690 | * Which means the desired boundaries for r2 are: |
| 691 | * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN |
| 692 | * |
| 693 | */ |
| 694 | for (r2 = LC_FREQ * 2 / REF_MAX + 1; |
| 695 | r2 <= LC_FREQ * 2 / REF_MIN; |
| 696 | r2++) { |
| 697 | |
| 698 | /* |
| 699 | * VCO = N * Ref, that is: VCO = N * LC_FREQ / R |
| 700 | * |
| 701 | * Once again we want VCO_MIN <= VCO <= VCO_MAX. |
| 702 | * Injecting R2 = 2 * R and N2 = 2 * N, we get: |
| 703 | * VCO_MAX * r2 > n2 * LC_FREQ and |
| 704 | * VCO_MIN * r2 < n2 * LC_FREQ) |
| 705 | * |
| 706 | * Which means the desired boundaries for n2 are: |
| 707 | * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ |
| 708 | */ |
| 709 | for (n2 = VCO_MIN * r2 / LC_FREQ + 1; |
| 710 | n2 <= VCO_MAX * r2 / LC_FREQ; |
| 711 | n2++) { |
| 712 | |
| 713 | for (p = P_MIN; p <= P_MAX; p += P_INC) |
| 714 | wrpll_update_rnp(freq2k, budget, |
| 715 | r2, n2, p, &best); |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | *n2_out = best.n2; |
| 720 | *p_out = best.p; |
| 721 | *r2_out = best.r2; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 722 | } |
| 723 | |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 724 | /* |
| 725 | * Tries to find a PLL for the CRTC. If it finds, it increases the refcount and |
| 726 | * stores it in intel_crtc->ddi_pll_sel, so other mode sets won't be able to |
| 727 | * steal the selected PLL. You need to call intel_ddi_pll_enable to actually |
| 728 | * enable the PLL. |
| 729 | */ |
| 730 | bool intel_ddi_pll_select(struct intel_crtc *intel_crtc) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 731 | { |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 732 | struct drm_crtc *crtc = &intel_crtc->base; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 733 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 734 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 735 | struct intel_ddi_plls *plls = &dev_priv->ddi_plls; |
| 736 | int type = intel_encoder->type; |
| 737 | enum pipe pipe = intel_crtc->pipe; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 738 | int clock = intel_crtc->config.port_clock; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 739 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 740 | intel_ddi_put_crtc_pll(crtc); |
| 741 | |
Daniel Vetter | 0e50338 | 2014-07-04 11:26:04 -0300 | [diff] [blame] | 742 | if (type == INTEL_OUTPUT_HDMI) { |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 743 | uint32_t reg, val; |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 744 | unsigned p, n2, r2; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 745 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 746 | intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 747 | |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 748 | val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 749 | WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) | |
| 750 | WRPLL_DIVIDER_POST(p); |
| 751 | |
Paulo Zanoni | 0694001 | 2013-10-30 18:27:43 -0200 | [diff] [blame] | 752 | if (val == I915_READ(WRPLL_CTL1)) { |
| 753 | DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n", |
| 754 | pipe_name(pipe)); |
| 755 | reg = WRPLL_CTL1; |
| 756 | } else if (val == I915_READ(WRPLL_CTL2)) { |
| 757 | DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n", |
| 758 | pipe_name(pipe)); |
| 759 | reg = WRPLL_CTL2; |
| 760 | } else if (plls->wrpll1_refcount == 0) { |
| 761 | DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n", |
| 762 | pipe_name(pipe)); |
| 763 | reg = WRPLL_CTL1; |
| 764 | } else if (plls->wrpll2_refcount == 0) { |
| 765 | DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n", |
| 766 | pipe_name(pipe)); |
| 767 | reg = WRPLL_CTL2; |
| 768 | } else { |
| 769 | DRM_ERROR("No WRPLLs available!\n"); |
| 770 | return false; |
| 771 | } |
| 772 | |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 773 | DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n", |
| 774 | clock, p, n2, r2); |
| 775 | |
Paulo Zanoni | 0694001 | 2013-10-30 18:27:43 -0200 | [diff] [blame] | 776 | if (reg == WRPLL_CTL1) { |
| 777 | plls->wrpll1_refcount++; |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 778 | intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL1; |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 779 | intel_crtc->config.shared_dpll = DPLL_ID_WRPLL1; |
Paulo Zanoni | 0694001 | 2013-10-30 18:27:43 -0200 | [diff] [blame] | 780 | } else { |
| 781 | plls->wrpll2_refcount++; |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 782 | intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_WRPLL2; |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 783 | intel_crtc->config.shared_dpll = DPLL_ID_WRPLL2; |
Paulo Zanoni | 0694001 | 2013-10-30 18:27:43 -0200 | [diff] [blame] | 784 | } |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 785 | |
| 786 | intel_crtc->config.dpll_hw_state.wrpll = val; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 787 | } |
| 788 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 789 | return true; |
| 790 | } |
| 791 | |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 792 | /* |
| 793 | * To be called after intel_ddi_pll_select(). That one selects the PLL to be |
| 794 | * used, this one actually enables the PLL. |
| 795 | */ |
| 796 | void intel_ddi_pll_enable(struct intel_crtc *crtc) |
| 797 | { |
| 798 | struct drm_device *dev = crtc->base.dev; |
| 799 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 800 | struct intel_ddi_plls *plls = &dev_priv->ddi_plls; |
| 801 | int clock = crtc->config.port_clock; |
| 802 | uint32_t reg, cur_val, new_val; |
| 803 | int refcount; |
| 804 | const char *pll_name; |
| 805 | uint32_t enable_bit = (1 << 31); |
| 806 | unsigned int p, n2, r2; |
| 807 | |
| 808 | BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE); |
| 809 | BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE); |
| 810 | |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 811 | switch (crtc->config.ddi_pll_sel) { |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 812 | case PORT_CLK_SEL_WRPLL1: |
| 813 | case PORT_CLK_SEL_WRPLL2: |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 814 | if (crtc->config.ddi_pll_sel == PORT_CLK_SEL_WRPLL1) { |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 815 | pll_name = "WRPLL1"; |
| 816 | reg = WRPLL_CTL1; |
| 817 | refcount = plls->wrpll1_refcount; |
| 818 | } else { |
| 819 | pll_name = "WRPLL2"; |
| 820 | reg = WRPLL_CTL2; |
| 821 | refcount = plls->wrpll2_refcount; |
| 822 | } |
| 823 | |
| 824 | intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p); |
| 825 | |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 826 | new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL | |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 827 | WRPLL_DIVIDER_REFERENCE(r2) | |
| 828 | WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p); |
| 829 | |
| 830 | break; |
| 831 | |
| 832 | case PORT_CLK_SEL_NONE: |
| 833 | WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n"); |
| 834 | return; |
| 835 | default: |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 836 | return; |
| 837 | } |
| 838 | |
| 839 | cur_val = I915_READ(reg); |
| 840 | |
| 841 | WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount); |
| 842 | if (refcount == 1) { |
| 843 | WARN(cur_val & enable_bit, "%s already enabled\n", pll_name); |
| 844 | I915_WRITE(reg, new_val); |
| 845 | POSTING_READ(reg); |
| 846 | udelay(20); |
| 847 | } else { |
| 848 | WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name); |
| 849 | } |
| 850 | } |
| 851 | |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 852 | void intel_ddi_set_pipe_settings(struct drm_crtc *crtc) |
| 853 | { |
| 854 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 855 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 856 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 857 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 858 | int type = intel_encoder->type; |
| 859 | uint32_t temp; |
| 860 | |
| 861 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
| 862 | |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 863 | temp = TRANS_MSA_SYNC_CLK; |
Daniel Vetter | 965e0c4 | 2013-03-27 00:44:57 +0100 | [diff] [blame] | 864 | switch (intel_crtc->config.pipe_bpp) { |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 865 | case 18: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 866 | temp |= TRANS_MSA_6_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 867 | break; |
| 868 | case 24: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 869 | temp |= TRANS_MSA_8_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 870 | break; |
| 871 | case 30: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 872 | temp |= TRANS_MSA_10_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 873 | break; |
| 874 | case 36: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 875 | temp |= TRANS_MSA_12_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 876 | break; |
| 877 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 878 | BUG(); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 879 | } |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 880 | I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 881 | } |
| 882 | } |
| 883 | |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 884 | void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 885 | { |
| 886 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 887 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 888 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 889 | struct drm_device *dev = crtc->dev; |
| 890 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 891 | enum pipe pipe = intel_crtc->pipe; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 892 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 893 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 894 | int type = intel_encoder->type; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 895 | uint32_t temp; |
| 896 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 897 | /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */ |
| 898 | temp = TRANS_DDI_FUNC_ENABLE; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 899 | temp |= TRANS_DDI_SELECT_PORT(port); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 900 | |
Daniel Vetter | 965e0c4 | 2013-03-27 00:44:57 +0100 | [diff] [blame] | 901 | switch (intel_crtc->config.pipe_bpp) { |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 902 | case 18: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 903 | temp |= TRANS_DDI_BPC_6; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 904 | break; |
| 905 | case 24: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 906 | temp |= TRANS_DDI_BPC_8; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 907 | break; |
| 908 | case 30: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 909 | temp |= TRANS_DDI_BPC_10; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 910 | break; |
| 911 | case 36: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 912 | temp |= TRANS_DDI_BPC_12; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 913 | break; |
| 914 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 915 | BUG(); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 916 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 917 | |
Ville Syrjälä | a666283 | 2013-09-10 17:03:41 +0300 | [diff] [blame] | 918 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 919 | temp |= TRANS_DDI_PVSYNC; |
Ville Syrjälä | a666283 | 2013-09-10 17:03:41 +0300 | [diff] [blame] | 920 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 921 | temp |= TRANS_DDI_PHSYNC; |
Paulo Zanoni | f63eb7c4 | 2012-08-08 14:15:28 -0300 | [diff] [blame] | 922 | |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 923 | if (cpu_transcoder == TRANSCODER_EDP) { |
| 924 | switch (pipe) { |
| 925 | case PIPE_A: |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 926 | /* On Haswell, can only use the always-on power well for |
| 927 | * eDP when not using the panel fitter, and when not |
| 928 | * using motion blur mitigation (which we don't |
| 929 | * support). */ |
Daniel Vetter | fabf6e5 | 2014-05-29 14:10:22 +0200 | [diff] [blame] | 930 | if (IS_HASWELL(dev) && |
| 931 | (intel_crtc->config.pch_pfit.enabled || |
| 932 | intel_crtc->config.pch_pfit.force_thru)) |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 933 | temp |= TRANS_DDI_EDP_INPUT_A_ONOFF; |
| 934 | else |
| 935 | temp |= TRANS_DDI_EDP_INPUT_A_ON; |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 936 | break; |
| 937 | case PIPE_B: |
| 938 | temp |= TRANS_DDI_EDP_INPUT_B_ONOFF; |
| 939 | break; |
| 940 | case PIPE_C: |
| 941 | temp |= TRANS_DDI_EDP_INPUT_C_ONOFF; |
| 942 | break; |
| 943 | default: |
| 944 | BUG(); |
| 945 | break; |
| 946 | } |
| 947 | } |
| 948 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 949 | if (type == INTEL_OUTPUT_HDMI) { |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 950 | if (intel_crtc->config.has_hdmi_sink) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 951 | temp |= TRANS_DDI_MODE_SELECT_HDMI; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 952 | else |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 953 | temp |= TRANS_DDI_MODE_SELECT_DVI; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 954 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 955 | } else if (type == INTEL_OUTPUT_ANALOG) { |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 956 | temp |= TRANS_DDI_MODE_SELECT_FDI; |
Daniel Vetter | 33d29b1 | 2013-02-13 18:04:45 +0100 | [diff] [blame] | 957 | temp |= (intel_crtc->config.fdi_lanes - 1) << 1; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 958 | |
| 959 | } else if (type == INTEL_OUTPUT_DISPLAYPORT || |
| 960 | type == INTEL_OUTPUT_EDP) { |
| 961 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 962 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 963 | temp |= TRANS_DDI_MODE_SELECT_DP_SST; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 964 | |
Daniel Vetter | 17aa6be | 2013-04-30 14:01:40 +0200 | [diff] [blame] | 965 | temp |= DDI_PORT_WIDTH(intel_dp->lane_count); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 966 | } else { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 967 | WARN(1, "Invalid encoder type %d for pipe %c\n", |
| 968 | intel_encoder->type, pipe_name(pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 969 | } |
| 970 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 971 | I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 972 | } |
| 973 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 974 | void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv, |
| 975 | enum transcoder cpu_transcoder) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 976 | { |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 977 | uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 978 | uint32_t val = I915_READ(reg); |
| 979 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 980 | val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK); |
| 981 | val |= TRANS_DDI_PORT_NONE; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 982 | I915_WRITE(reg, val); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 983 | } |
| 984 | |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 985 | bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector) |
| 986 | { |
| 987 | struct drm_device *dev = intel_connector->base.dev; |
| 988 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 989 | struct intel_encoder *intel_encoder = intel_connector->encoder; |
| 990 | int type = intel_connector->base.connector_type; |
| 991 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 992 | enum pipe pipe = 0; |
| 993 | enum transcoder cpu_transcoder; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 994 | enum intel_display_power_domain power_domain; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 995 | uint32_t tmp; |
| 996 | |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 997 | power_domain = intel_display_port_power_domain(intel_encoder); |
| 998 | if (!intel_display_power_enabled(dev_priv, power_domain)) |
| 999 | return false; |
| 1000 | |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1001 | if (!intel_encoder->get_hw_state(intel_encoder, &pipe)) |
| 1002 | return false; |
| 1003 | |
| 1004 | if (port == PORT_A) |
| 1005 | cpu_transcoder = TRANSCODER_EDP; |
| 1006 | else |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1007 | cpu_transcoder = (enum transcoder) pipe; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1008 | |
| 1009 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1010 | |
| 1011 | switch (tmp & TRANS_DDI_MODE_SELECT_MASK) { |
| 1012 | case TRANS_DDI_MODE_SELECT_HDMI: |
| 1013 | case TRANS_DDI_MODE_SELECT_DVI: |
| 1014 | return (type == DRM_MODE_CONNECTOR_HDMIA); |
| 1015 | |
| 1016 | case TRANS_DDI_MODE_SELECT_DP_SST: |
| 1017 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 1018 | return true; |
| 1019 | case TRANS_DDI_MODE_SELECT_DP_MST: |
| 1020 | return (type == DRM_MODE_CONNECTOR_DisplayPort); |
| 1021 | |
| 1022 | case TRANS_DDI_MODE_SELECT_FDI: |
| 1023 | return (type == DRM_MODE_CONNECTOR_VGA); |
| 1024 | |
| 1025 | default: |
| 1026 | return false; |
| 1027 | } |
| 1028 | } |
| 1029 | |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1030 | bool intel_ddi_get_hw_state(struct intel_encoder *encoder, |
| 1031 | enum pipe *pipe) |
| 1032 | { |
| 1033 | struct drm_device *dev = encoder->base.dev; |
| 1034 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1035 | enum port port = intel_ddi_get_encoder_port(encoder); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1036 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1037 | u32 tmp; |
| 1038 | int i; |
| 1039 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1040 | power_domain = intel_display_port_power_domain(encoder); |
| 1041 | if (!intel_display_power_enabled(dev_priv, power_domain)) |
| 1042 | return false; |
| 1043 | |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1044 | tmp = I915_READ(DDI_BUF_CTL(port)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1045 | |
| 1046 | if (!(tmp & DDI_BUF_CTL_ENABLE)) |
| 1047 | return false; |
| 1048 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1049 | if (port == PORT_A) { |
| 1050 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1051 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1052 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 1053 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 1054 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 1055 | *pipe = PIPE_A; |
| 1056 | break; |
| 1057 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 1058 | *pipe = PIPE_B; |
| 1059 | break; |
| 1060 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 1061 | *pipe = PIPE_C; |
| 1062 | break; |
| 1063 | } |
| 1064 | |
| 1065 | return true; |
| 1066 | } else { |
| 1067 | for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) { |
| 1068 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(i)); |
| 1069 | |
| 1070 | if ((tmp & TRANS_DDI_PORT_MASK) |
| 1071 | == TRANS_DDI_SELECT_PORT(port)) { |
| 1072 | *pipe = i; |
| 1073 | return true; |
| 1074 | } |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1078 | DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1079 | |
Jesse Barnes | 22f9fe5 | 2013-04-02 10:03:55 -0700 | [diff] [blame] | 1080 | return false; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1081 | } |
| 1082 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1083 | void intel_ddi_setup_hw_pll_state(struct drm_device *dev) |
| 1084 | { |
| 1085 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1086 | enum pipe pipe; |
| 1087 | struct intel_crtc *intel_crtc; |
| 1088 | |
Paulo Zanoni | 0882dae | 2014-01-08 11:12:27 -0200 | [diff] [blame] | 1089 | dev_priv->ddi_plls.wrpll1_refcount = 0; |
| 1090 | dev_priv->ddi_plls.wrpll2_refcount = 0; |
| 1091 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1092 | for_each_pipe(pipe) { |
| 1093 | intel_crtc = |
| 1094 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 1095 | |
Paulo Zanoni | 0882dae | 2014-01-08 11:12:27 -0200 | [diff] [blame] | 1096 | if (!intel_crtc->active) { |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 1097 | intel_crtc->config.ddi_pll_sel = PORT_CLK_SEL_NONE; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1098 | continue; |
Paulo Zanoni | 0882dae | 2014-01-08 11:12:27 -0200 | [diff] [blame] | 1099 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1100 | |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 1101 | switch (intel_crtc->config.ddi_pll_sel) { |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1102 | case PORT_CLK_SEL_WRPLL1: |
| 1103 | dev_priv->ddi_plls.wrpll1_refcount++; |
| 1104 | break; |
| 1105 | case PORT_CLK_SEL_WRPLL2: |
| 1106 | dev_priv->ddi_plls.wrpll2_refcount++; |
| 1107 | break; |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1112 | void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1113 | { |
| 1114 | struct drm_crtc *crtc = &intel_crtc->base; |
| 1115 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1116 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 1117 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 1118 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1119 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1120 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1121 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1122 | TRANS_CLK_SEL_PORT(port)); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1126 | { |
| 1127 | struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 1128 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1129 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1130 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1131 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1132 | TRANS_CLK_SEL_DISABLED); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1133 | } |
| 1134 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1135 | static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1136 | { |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1137 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1138 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1139 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1140 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1141 | int type = intel_encoder->type; |
| 1142 | |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1143 | if (crtc->config.has_audio) { |
| 1144 | DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n", |
| 1145 | pipe_name(crtc->pipe)); |
| 1146 | |
| 1147 | /* write eld */ |
| 1148 | DRM_DEBUG_DRIVER("DDI audio: write eld information\n"); |
| 1149 | intel_write_eld(encoder, &crtc->config.adjusted_mode); |
| 1150 | } |
| 1151 | |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1152 | if (type == INTEL_OUTPUT_EDP) { |
| 1153 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1154 | intel_edp_panel_on(intel_dp); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1155 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1156 | |
Daniel Vetter | de7cfc6 | 2014-06-25 22:01:54 +0300 | [diff] [blame] | 1157 | WARN_ON(crtc->config.ddi_pll_sel == PORT_CLK_SEL_NONE); |
| 1158 | I915_WRITE(PORT_CLK_SEL(port), crtc->config.ddi_pll_sel); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1159 | |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1160 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1161 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1162 | struct intel_digital_port *intel_dig_port = |
| 1163 | enc_to_dig_port(encoder); |
| 1164 | |
| 1165 | intel_dp->DP = intel_dig_port->saved_port_bits | |
| 1166 | DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW; |
| 1167 | intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1168 | |
| 1169 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 1170 | intel_dp_start_link_train(intel_dp); |
| 1171 | intel_dp_complete_link_train(intel_dp); |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 1172 | if (port != PORT_A) |
| 1173 | intel_dp_stop_link_train(intel_dp); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1174 | } else if (type == INTEL_OUTPUT_HDMI) { |
| 1175 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 1176 | |
| 1177 | intel_hdmi->set_infoframes(encoder, |
| 1178 | crtc->config.has_hdmi_sink, |
| 1179 | &crtc->config.adjusted_mode); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1180 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1181 | } |
| 1182 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1183 | static void intel_ddi_post_disable(struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1184 | { |
| 1185 | struct drm_encoder *encoder = &intel_encoder->base; |
| 1186 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
| 1187 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1188 | int type = intel_encoder->type; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1189 | uint32_t val; |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1190 | bool wait = false; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1191 | |
| 1192 | val = I915_READ(DDI_BUF_CTL(port)); |
| 1193 | if (val & DDI_BUF_CTL_ENABLE) { |
| 1194 | val &= ~DDI_BUF_CTL_ENABLE; |
| 1195 | I915_WRITE(DDI_BUF_CTL(port), val); |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1196 | wait = true; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1197 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1198 | |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1199 | val = I915_READ(DP_TP_CTL(port)); |
| 1200 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 1201 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 1202 | I915_WRITE(DP_TP_CTL(port), val); |
| 1203 | |
| 1204 | if (wait) |
| 1205 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 1206 | |
Jani Nikula | 76bb80e | 2013-11-15 15:29:57 +0200 | [diff] [blame] | 1207 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1208 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Jani Nikula | 76bb80e | 2013-11-15 15:29:57 +0200 | [diff] [blame] | 1209 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 1210 | intel_edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1211 | intel_edp_panel_off(intel_dp); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1212 | } |
| 1213 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1214 | I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE); |
| 1215 | } |
| 1216 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1217 | static void intel_enable_ddi(struct intel_encoder *intel_encoder) |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1218 | { |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1219 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1220 | struct drm_crtc *crtc = encoder->crtc; |
| 1221 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1222 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1223 | struct drm_device *dev = encoder->dev; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1224 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1225 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1226 | int type = intel_encoder->type; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1227 | uint32_t tmp; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1228 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1229 | if (type == INTEL_OUTPUT_HDMI) { |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1230 | struct intel_digital_port *intel_dig_port = |
| 1231 | enc_to_dig_port(encoder); |
| 1232 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1233 | /* In HDMI/DVI mode, the port width, and swing/emphasis values |
| 1234 | * are ignored so nothing special needs to be done besides |
| 1235 | * enabling the port. |
| 1236 | */ |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1237 | I915_WRITE(DDI_BUF_CTL(port), |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 1238 | intel_dig_port->saved_port_bits | |
| 1239 | DDI_BUF_CTL_ENABLE); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1240 | } else if (type == INTEL_OUTPUT_EDP) { |
| 1241 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1242 | |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 1243 | if (port == PORT_A) |
| 1244 | intel_dp_stop_link_train(intel_dp); |
| 1245 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1246 | intel_edp_backlight_on(intel_dp); |
Rodrigo Vivi | 4906557 | 2013-07-11 18:45:05 -0300 | [diff] [blame] | 1247 | intel_edp_psr_enable(intel_dp); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1248 | } |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1249 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 1250 | if (intel_crtc->config.has_audio) { |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 1251 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1252 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
| 1253 | tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4)); |
| 1254 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
| 1255 | } |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1256 | } |
| 1257 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1258 | static void intel_disable_ddi(struct intel_encoder *intel_encoder) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1259 | { |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1260 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1261 | struct drm_crtc *crtc = encoder->crtc; |
| 1262 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1263 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1264 | int type = intel_encoder->type; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1265 | struct drm_device *dev = encoder->dev; |
| 1266 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1267 | uint32_t tmp; |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1268 | |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 1269 | /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this |
| 1270 | * register is part of the power well on Haswell. */ |
| 1271 | if (intel_crtc->config.has_audio) { |
| 1272 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
| 1273 | tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << |
| 1274 | (pipe * 4)); |
| 1275 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
| 1276 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
| 1277 | } |
Paulo Zanoni | 2831d842 | 2013-03-06 20:03:09 -0300 | [diff] [blame] | 1278 | |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1279 | if (type == INTEL_OUTPUT_EDP) { |
| 1280 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1281 | |
Rodrigo Vivi | 4906557 | 2013-07-11 18:45:05 -0300 | [diff] [blame] | 1282 | intel_edp_psr_disable(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1283 | intel_edp_backlight_off(intel_dp); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1284 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1285 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1286 | |
Paulo Zanoni | b8fc2f6 | 2012-10-23 18:30:05 -0200 | [diff] [blame] | 1287 | int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1288 | { |
Paulo Zanoni | e39bf98 | 2013-11-02 21:07:36 -0700 | [diff] [blame] | 1289 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | a400664 | 2013-08-06 18:57:11 -0300 | [diff] [blame] | 1290 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
Paulo Zanoni | e39bf98 | 2013-11-02 21:07:36 -0700 | [diff] [blame] | 1291 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
Paulo Zanoni | a400664 | 2013-08-06 18:57:11 -0300 | [diff] [blame] | 1292 | |
Paulo Zanoni | e39bf98 | 2013-11-02 21:07:36 -0700 | [diff] [blame] | 1293 | if (lcpll & LCPLL_CD_SOURCE_FCLK) { |
Paulo Zanoni | a400664 | 2013-08-06 18:57:11 -0300 | [diff] [blame] | 1294 | return 800000; |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 1295 | } else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) { |
Paulo Zanoni | b2b877f | 2013-05-03 17:23:42 -0300 | [diff] [blame] | 1296 | return 450000; |
Paulo Zanoni | e39bf98 | 2013-11-02 21:07:36 -0700 | [diff] [blame] | 1297 | } else if (freq == LCPLL_CLK_FREQ_450) { |
Paulo Zanoni | b2b877f | 2013-05-03 17:23:42 -0300 | [diff] [blame] | 1298 | return 450000; |
Paulo Zanoni | e39bf98 | 2013-11-02 21:07:36 -0700 | [diff] [blame] | 1299 | } else if (IS_HASWELL(dev)) { |
| 1300 | if (IS_ULT(dev)) |
| 1301 | return 337500; |
| 1302 | else |
| 1303 | return 540000; |
| 1304 | } else { |
| 1305 | if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 1306 | return 540000; |
| 1307 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 1308 | return 337500; |
| 1309 | else |
| 1310 | return 675000; |
| 1311 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1312 | } |
| 1313 | |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame^] | 1314 | static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv, |
| 1315 | struct intel_shared_dpll *pll) |
| 1316 | { |
| 1317 | uint32_t val; |
| 1318 | |
| 1319 | val = I915_READ(WRPLL_CTL(pll->id)); |
| 1320 | WARN_ON(!(val & WRPLL_PLL_ENABLE)); |
| 1321 | I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE); |
| 1322 | POSTING_READ(WRPLL_CTL(pll->id)); |
| 1323 | } |
| 1324 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 1325 | static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, |
| 1326 | struct intel_shared_dpll *pll, |
| 1327 | struct intel_dpll_hw_state *hw_state) |
| 1328 | { |
| 1329 | uint32_t val; |
| 1330 | |
| 1331 | if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
| 1332 | return false; |
| 1333 | |
| 1334 | val = I915_READ(WRPLL_CTL(pll->id)); |
| 1335 | hw_state->wrpll = val; |
| 1336 | |
| 1337 | return val & WRPLL_PLL_ENABLE; |
| 1338 | } |
| 1339 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1340 | static char *hsw_ddi_pll_names[] = { |
| 1341 | "WRPLL 1", |
| 1342 | "WRPLL 2", |
| 1343 | }; |
| 1344 | |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1345 | void intel_ddi_pll_init(struct drm_device *dev) |
| 1346 | { |
| 1347 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1348 | uint32_t val = I915_READ(LCPLL_CTL); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1349 | int i; |
| 1350 | |
| 1351 | /* Dummy setup until everything is moved over to avoid upsetting the hw |
| 1352 | * state cross checker. */ |
| 1353 | dev_priv->num_shared_dpll = 0; |
| 1354 | |
| 1355 | for (i = 0; i < 2; i++) { |
| 1356 | dev_priv->shared_dplls[i].id = i; |
| 1357 | dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i]; |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame^] | 1358 | dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 1359 | dev_priv->shared_dplls[i].get_hw_state = |
| 1360 | hsw_ddi_pll_get_hw_state; |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1361 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1362 | |
| 1363 | /* The LCPLL register should be turned on by the BIOS. For now let's |
| 1364 | * just check its state and print errors in case something is wrong. |
| 1365 | * Don't even try to turn it on. |
| 1366 | */ |
| 1367 | |
Paulo Zanoni | b2b877f | 2013-05-03 17:23:42 -0300 | [diff] [blame] | 1368 | DRM_DEBUG_KMS("CDCLK running at %dKHz\n", |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1369 | intel_ddi_get_cdclk_freq(dev_priv)); |
| 1370 | |
| 1371 | if (val & LCPLL_CD_SOURCE_FCLK) |
| 1372 | DRM_ERROR("CDCLK source is not LCPLL\n"); |
| 1373 | |
| 1374 | if (val & LCPLL_PLL_DISABLE) |
| 1375 | DRM_ERROR("LCPLL is disabled\n"); |
| 1376 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1377 | |
| 1378 | void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder) |
| 1379 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1380 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 1381 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1382 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1383 | enum port port = intel_dig_port->port; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1384 | uint32_t val; |
Syam Sidhardhan | f3e227d | 2013-02-25 04:05:38 +0530 | [diff] [blame] | 1385 | bool wait = false; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1386 | |
| 1387 | if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) { |
| 1388 | val = I915_READ(DDI_BUF_CTL(port)); |
| 1389 | if (val & DDI_BUF_CTL_ENABLE) { |
| 1390 | val &= ~DDI_BUF_CTL_ENABLE; |
| 1391 | I915_WRITE(DDI_BUF_CTL(port), val); |
| 1392 | wait = true; |
| 1393 | } |
| 1394 | |
| 1395 | val = I915_READ(DP_TP_CTL(port)); |
| 1396 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 1397 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 1398 | I915_WRITE(DP_TP_CTL(port), val); |
| 1399 | POSTING_READ(DP_TP_CTL(port)); |
| 1400 | |
| 1401 | if (wait) |
| 1402 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 1403 | } |
| 1404 | |
| 1405 | val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST | |
| 1406 | DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE; |
Jani Nikula | 6aba5b6 | 2013-10-04 15:08:10 +0300 | [diff] [blame] | 1407 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1408 | val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE; |
| 1409 | I915_WRITE(DP_TP_CTL(port), val); |
| 1410 | POSTING_READ(DP_TP_CTL(port)); |
| 1411 | |
| 1412 | intel_dp->DP |= DDI_BUF_CTL_ENABLE; |
| 1413 | I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP); |
| 1414 | POSTING_READ(DDI_BUF_CTL(port)); |
| 1415 | |
| 1416 | udelay(600); |
| 1417 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1418 | |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 1419 | void intel_ddi_fdi_disable(struct drm_crtc *crtc) |
| 1420 | { |
| 1421 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1422 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 1423 | uint32_t val; |
| 1424 | |
| 1425 | intel_ddi_post_disable(intel_encoder); |
| 1426 | |
| 1427 | val = I915_READ(_FDI_RXA_CTL); |
| 1428 | val &= ~FDI_RX_ENABLE; |
| 1429 | I915_WRITE(_FDI_RXA_CTL, val); |
| 1430 | |
| 1431 | val = I915_READ(_FDI_RXA_MISC); |
| 1432 | val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 1433 | val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
| 1434 | I915_WRITE(_FDI_RXA_MISC, val); |
| 1435 | |
| 1436 | val = I915_READ(_FDI_RXA_CTL); |
| 1437 | val &= ~FDI_PCDCLK; |
| 1438 | I915_WRITE(_FDI_RXA_CTL, val); |
| 1439 | |
| 1440 | val = I915_READ(_FDI_RXA_CTL); |
| 1441 | val &= ~FDI_RX_PLL_ENABLE; |
| 1442 | I915_WRITE(_FDI_RXA_CTL, val); |
| 1443 | } |
| 1444 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1445 | static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder) |
| 1446 | { |
| 1447 | struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base); |
| 1448 | int type = intel_encoder->type; |
| 1449 | |
| 1450 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) |
| 1451 | intel_dp_check_link_status(intel_dp); |
| 1452 | } |
| 1453 | |
Ville Syrjälä | 6801c18 | 2013-09-24 14:24:05 +0300 | [diff] [blame] | 1454 | void intel_ddi_get_config(struct intel_encoder *encoder, |
| 1455 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 1456 | { |
| 1457 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 1458 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 1459 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
| 1460 | u32 temp, flags = 0; |
| 1461 | |
| 1462 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1463 | if (temp & TRANS_DDI_PHSYNC) |
| 1464 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 1465 | else |
| 1466 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 1467 | if (temp & TRANS_DDI_PVSYNC) |
| 1468 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 1469 | else |
| 1470 | flags |= DRM_MODE_FLAG_NVSYNC; |
| 1471 | |
| 1472 | pipe_config->adjusted_mode.flags |= flags; |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 1473 | |
| 1474 | switch (temp & TRANS_DDI_BPC_MASK) { |
| 1475 | case TRANS_DDI_BPC_6: |
| 1476 | pipe_config->pipe_bpp = 18; |
| 1477 | break; |
| 1478 | case TRANS_DDI_BPC_8: |
| 1479 | pipe_config->pipe_bpp = 24; |
| 1480 | break; |
| 1481 | case TRANS_DDI_BPC_10: |
| 1482 | pipe_config->pipe_bpp = 30; |
| 1483 | break; |
| 1484 | case TRANS_DDI_BPC_12: |
| 1485 | pipe_config->pipe_bpp = 36; |
| 1486 | break; |
| 1487 | default: |
| 1488 | break; |
| 1489 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 1490 | |
| 1491 | switch (temp & TRANS_DDI_MODE_SELECT_MASK) { |
| 1492 | case TRANS_DDI_MODE_SELECT_HDMI: |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 1493 | pipe_config->has_hdmi_sink = true; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 1494 | case TRANS_DDI_MODE_SELECT_DVI: |
| 1495 | case TRANS_DDI_MODE_SELECT_FDI: |
| 1496 | break; |
| 1497 | case TRANS_DDI_MODE_SELECT_DP_SST: |
| 1498 | case TRANS_DDI_MODE_SELECT_DP_MST: |
| 1499 | pipe_config->has_dp_encoder = true; |
| 1500 | intel_dp_get_m_n(intel_crtc, pipe_config); |
| 1501 | break; |
| 1502 | default: |
| 1503 | break; |
| 1504 | } |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 1505 | |
Paulo Zanoni | a60551b | 2014-05-21 16:23:20 -0300 | [diff] [blame] | 1506 | if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) { |
| 1507 | temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
| 1508 | if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4))) |
| 1509 | pipe_config->has_audio = true; |
| 1510 | } |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 1511 | |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 1512 | if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp && |
| 1513 | pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) { |
| 1514 | /* |
| 1515 | * This is a big fat ugly hack. |
| 1516 | * |
| 1517 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 1518 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 1519 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 1520 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 1521 | * max, not what it tells us to use. |
| 1522 | * |
| 1523 | * Note: This will still be broken if the eDP panel is not lit |
| 1524 | * up by the BIOS, and thus we can't get the mode at module |
| 1525 | * load. |
| 1526 | */ |
| 1527 | DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", |
| 1528 | pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp); |
| 1529 | dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp; |
| 1530 | } |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 1531 | |
| 1532 | intel_ddi_clock_get(encoder, pipe_config); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1535 | static void intel_ddi_destroy(struct drm_encoder *encoder) |
| 1536 | { |
| 1537 | /* HDMI has nothing special to destroy, so we can go with this. */ |
| 1538 | intel_dp_encoder_destroy(encoder); |
| 1539 | } |
| 1540 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1541 | static bool intel_ddi_compute_config(struct intel_encoder *encoder, |
| 1542 | struct intel_crtc_config *pipe_config) |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1543 | { |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1544 | int type = encoder->type; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 1545 | int port = intel_ddi_get_encoder_port(encoder); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1546 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1547 | WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n"); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1548 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 1549 | if (port == PORT_A) |
| 1550 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 1551 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1552 | if (type == INTEL_OUTPUT_HDMI) |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1553 | return intel_hdmi_compute_config(encoder, pipe_config); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1554 | else |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1555 | return intel_dp_compute_config(encoder, pipe_config); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | static const struct drm_encoder_funcs intel_ddi_funcs = { |
| 1559 | .destroy = intel_ddi_destroy, |
| 1560 | }; |
| 1561 | |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 1562 | static struct intel_connector * |
| 1563 | intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port) |
| 1564 | { |
| 1565 | struct intel_connector *connector; |
| 1566 | enum port port = intel_dig_port->port; |
| 1567 | |
| 1568 | connector = kzalloc(sizeof(*connector), GFP_KERNEL); |
| 1569 | if (!connector) |
| 1570 | return NULL; |
| 1571 | |
| 1572 | intel_dig_port->dp.output_reg = DDI_BUF_CTL(port); |
| 1573 | if (!intel_dp_init_connector(intel_dig_port, connector)) { |
| 1574 | kfree(connector); |
| 1575 | return NULL; |
| 1576 | } |
| 1577 | |
| 1578 | return connector; |
| 1579 | } |
| 1580 | |
| 1581 | static struct intel_connector * |
| 1582 | intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port) |
| 1583 | { |
| 1584 | struct intel_connector *connector; |
| 1585 | enum port port = intel_dig_port->port; |
| 1586 | |
| 1587 | connector = kzalloc(sizeof(*connector), GFP_KERNEL); |
| 1588 | if (!connector) |
| 1589 | return NULL; |
| 1590 | |
| 1591 | intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port); |
| 1592 | intel_hdmi_init_connector(intel_dig_port, connector); |
| 1593 | |
| 1594 | return connector; |
| 1595 | } |
| 1596 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1597 | void intel_ddi_init(struct drm_device *dev, enum port port) |
| 1598 | { |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1599 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1600 | struct intel_digital_port *intel_dig_port; |
| 1601 | struct intel_encoder *intel_encoder; |
| 1602 | struct drm_encoder *encoder; |
| 1603 | struct intel_connector *hdmi_connector = NULL; |
| 1604 | struct intel_connector *dp_connector = NULL; |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 1605 | bool init_hdmi, init_dp; |
| 1606 | |
| 1607 | init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi || |
| 1608 | dev_priv->vbt.ddi_port_info[port].supports_hdmi); |
| 1609 | init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp; |
| 1610 | if (!init_dp && !init_hdmi) { |
| 1611 | DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n", |
| 1612 | port_name(port)); |
| 1613 | init_hdmi = true; |
| 1614 | init_dp = true; |
| 1615 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1616 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 1617 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1618 | if (!intel_dig_port) |
| 1619 | return; |
| 1620 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1621 | intel_encoder = &intel_dig_port->base; |
| 1622 | encoder = &intel_encoder->base; |
| 1623 | |
| 1624 | drm_encoder_init(dev, encoder, &intel_ddi_funcs, |
| 1625 | DRM_MODE_ENCODER_TMDS); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1626 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 1627 | intel_encoder->compute_config = intel_ddi_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1628 | intel_encoder->enable = intel_enable_ddi; |
| 1629 | intel_encoder->pre_enable = intel_ddi_pre_enable; |
| 1630 | intel_encoder->disable = intel_disable_ddi; |
| 1631 | intel_encoder->post_disable = intel_ddi_post_disable; |
| 1632 | intel_encoder->get_hw_state = intel_ddi_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 1633 | intel_encoder->get_config = intel_ddi_get_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1634 | |
| 1635 | intel_dig_port->port = port; |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 1636 | intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) & |
| 1637 | (DDI_BUF_PORT_REVERSAL | |
| 1638 | DDI_A_4_LANES); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1639 | |
| 1640 | intel_encoder->type = INTEL_OUTPUT_UNKNOWN; |
| 1641 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 1642 | intel_encoder->cloneable = 0; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1643 | intel_encoder->hot_plug = intel_ddi_hot_plug; |
| 1644 | |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 1645 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
| 1646 | dev_priv->hpd_irq_port[port] = intel_dig_port; |
| 1647 | |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 1648 | if (init_dp) |
| 1649 | dp_connector = intel_ddi_init_dp_connector(intel_dig_port); |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 1650 | |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 1651 | /* In theory we don't need the encoder->type check, but leave it just in |
| 1652 | * case we have some really bad VBTs... */ |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 1653 | if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) |
| 1654 | hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port); |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 1655 | |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 1656 | if (!dp_connector && !hdmi_connector) { |
| 1657 | drm_encoder_cleanup(encoder); |
| 1658 | kfree(intel_dig_port); |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 1659 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1660 | } |