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