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 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 31 | struct ddi_buf_trans { |
| 32 | u32 trans1; /* balance leg enable, de-emph level */ |
| 33 | u32 trans2; /* vref sel, vswing */ |
| 34 | }; |
| 35 | |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 36 | /* HDMI/DVI modes ignore everything but the last 2 items. So we share |
| 37 | * them for both DP and FDI transports, allowing those ports to |
| 38 | * automatically adapt to HDMI connections as well |
| 39 | */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 40 | static const struct ddi_buf_trans hsw_ddi_translations_dp[] = { |
| 41 | { 0x00FFFFFF, 0x0006000E }, |
| 42 | { 0x00D75FFF, 0x0005000A }, |
| 43 | { 0x00C30FFF, 0x00040006 }, |
| 44 | { 0x80AAAFFF, 0x000B0000 }, |
| 45 | { 0x00FFFFFF, 0x0005000A }, |
| 46 | { 0x00D75FFF, 0x000C0004 }, |
| 47 | { 0x80C30FFF, 0x000B0000 }, |
| 48 | { 0x00FFFFFF, 0x00040006 }, |
| 49 | { 0x80D75FFF, 0x000B0000 }, |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 50 | }; |
| 51 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 52 | static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = { |
| 53 | { 0x00FFFFFF, 0x0007000E }, |
| 54 | { 0x00D75FFF, 0x000F000A }, |
| 55 | { 0x00C30FFF, 0x00060006 }, |
| 56 | { 0x00AAAFFF, 0x001E0000 }, |
| 57 | { 0x00FFFFFF, 0x000F000A }, |
| 58 | { 0x00D75FFF, 0x00160004 }, |
| 59 | { 0x00C30FFF, 0x001E0000 }, |
| 60 | { 0x00FFFFFF, 0x00060006 }, |
| 61 | { 0x00D75FFF, 0x001E0000 }, |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 62 | }; |
| 63 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 64 | static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = { |
| 65 | /* Idx NT mV d T mV d db */ |
| 66 | { 0x00FFFFFF, 0x0006000E }, /* 0: 400 400 0 */ |
| 67 | { 0x00E79FFF, 0x000E000C }, /* 1: 400 500 2 */ |
| 68 | { 0x00D75FFF, 0x0005000A }, /* 2: 400 600 3.5 */ |
| 69 | { 0x00FFFFFF, 0x0005000A }, /* 3: 600 600 0 */ |
| 70 | { 0x00E79FFF, 0x001D0007 }, /* 4: 600 750 2 */ |
| 71 | { 0x00D75FFF, 0x000C0004 }, /* 5: 600 900 3.5 */ |
| 72 | { 0x00FFFFFF, 0x00040006 }, /* 6: 800 800 0 */ |
| 73 | { 0x80E79FFF, 0x00030002 }, /* 7: 800 1000 2 */ |
| 74 | { 0x00FFFFFF, 0x00140005 }, /* 8: 850 850 0 */ |
| 75 | { 0x00FFFFFF, 0x000C0004 }, /* 9: 900 900 0 */ |
| 76 | { 0x00FFFFFF, 0x001C0003 }, /* 10: 950 950 0 */ |
| 77 | { 0x80FFFFFF, 0x00030002 }, /* 11: 1000 1000 0 */ |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 78 | }; |
| 79 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 80 | static const struct ddi_buf_trans bdw_ddi_translations_edp[] = { |
| 81 | { 0x00FFFFFF, 0x00000012 }, |
| 82 | { 0x00EBAFFF, 0x00020011 }, |
| 83 | { 0x00C71FFF, 0x0006000F }, |
| 84 | { 0x00AAAFFF, 0x000E000A }, |
| 85 | { 0x00FFFFFF, 0x00020011 }, |
| 86 | { 0x00DB6FFF, 0x0005000F }, |
| 87 | { 0x00BEEFFF, 0x000A000C }, |
| 88 | { 0x00FFFFFF, 0x0005000F }, |
| 89 | { 0x00DB6FFF, 0x000A000C }, |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 92 | static const struct ddi_buf_trans bdw_ddi_translations_dp[] = { |
| 93 | { 0x00FFFFFF, 0x0007000E }, |
| 94 | { 0x00D75FFF, 0x000E000A }, |
| 95 | { 0x00BEFFFF, 0x00140006 }, |
| 96 | { 0x80B2CFFF, 0x001B0002 }, |
| 97 | { 0x00FFFFFF, 0x000E000A }, |
Rodrigo Vivi | 17b523b | 2014-09-24 20:32:43 -0400 | [diff] [blame] | 98 | { 0x00DB6FFF, 0x00160005 }, |
Rodrigo Vivi | 6805b2a | 2014-09-25 12:28:32 -0400 | [diff] [blame] | 99 | { 0x80C71FFF, 0x001A0002 }, |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 100 | { 0x00F7DFFF, 0x00180004 }, |
| 101 | { 0x80D75FFF, 0x001B0002 }, |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 104 | static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = { |
| 105 | { 0x00FFFFFF, 0x0001000E }, |
| 106 | { 0x00D75FFF, 0x0004000A }, |
| 107 | { 0x00C30FFF, 0x00070006 }, |
| 108 | { 0x00AAAFFF, 0x000C0000 }, |
| 109 | { 0x00FFFFFF, 0x0004000A }, |
| 110 | { 0x00D75FFF, 0x00090004 }, |
| 111 | { 0x00C30FFF, 0x000C0000 }, |
| 112 | { 0x00FFFFFF, 0x00070006 }, |
| 113 | { 0x00D75FFF, 0x000C0000 }, |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 116 | static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = { |
| 117 | /* Idx NT mV d T mV df db */ |
| 118 | { 0x00FFFFFF, 0x0007000E }, /* 0: 400 400 0 */ |
| 119 | { 0x00D75FFF, 0x000E000A }, /* 1: 400 600 3.5 */ |
| 120 | { 0x00BEFFFF, 0x00140006 }, /* 2: 400 800 6 */ |
| 121 | { 0x00FFFFFF, 0x0009000D }, /* 3: 450 450 0 */ |
| 122 | { 0x00FFFFFF, 0x000E000A }, /* 4: 600 600 0 */ |
| 123 | { 0x00D7FFFF, 0x00140006 }, /* 5: 600 800 2.5 */ |
| 124 | { 0x80CB2FFF, 0x001B0002 }, /* 6: 600 1000 4.5 */ |
| 125 | { 0x00FFFFFF, 0x00140006 }, /* 7: 800 800 0 */ |
| 126 | { 0x80E79FFF, 0x001B0002 }, /* 8: 800 1000 2 */ |
| 127 | { 0x80FFFFFF, 0x001B0002 }, /* 9: 1000 1000 0 */ |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 128 | }; |
| 129 | |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 130 | static const struct ddi_buf_trans skl_ddi_translations_dp[] = { |
Damien Lespiau | 6c93068 | 2014-11-26 13:37:26 +0000 | [diff] [blame] | 131 | { 0x00000018, 0x000000a2 }, |
| 132 | { 0x00004014, 0x0000009B }, |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 133 | { 0x00006012, 0x00000088 }, |
Damien Lespiau | 6c93068 | 2014-11-26 13:37:26 +0000 | [diff] [blame] | 134 | { 0x00008010, 0x00000087 }, |
| 135 | { 0x00000018, 0x0000009B }, |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 136 | { 0x00004014, 0x00000088 }, |
Damien Lespiau | 6c93068 | 2014-11-26 13:37:26 +0000 | [diff] [blame] | 137 | { 0x00006012, 0x00000087 }, |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 138 | { 0x00000018, 0x00000088 }, |
Damien Lespiau | 6c93068 | 2014-11-26 13:37:26 +0000 | [diff] [blame] | 139 | { 0x00004014, 0x00000087 }, |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 142 | /* eDP 1.4 low vswing translation parameters */ |
| 143 | static const struct ddi_buf_trans skl_ddi_translations_edp[] = { |
| 144 | { 0x00000018, 0x000000a8 }, |
| 145 | { 0x00002016, 0x000000ab }, |
| 146 | { 0x00006012, 0x000000a2 }, |
| 147 | { 0x00008010, 0x00000088 }, |
| 148 | { 0x00000018, 0x000000ab }, |
| 149 | { 0x00004014, 0x000000a2 }, |
| 150 | { 0x00006012, 0x000000a6 }, |
| 151 | { 0x00000018, 0x000000a2 }, |
| 152 | { 0x00005013, 0x0000009c }, |
| 153 | { 0x00000018, 0x00000088 }, |
| 154 | }; |
| 155 | |
| 156 | |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 157 | static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = { |
Sonika Jindal | b7192a5 | 2015-04-15 11:02:33 +0530 | [diff] [blame] | 158 | { 0x00000018, 0x000000ac }, |
| 159 | { 0x00005012, 0x0000009d }, |
| 160 | { 0x00007011, 0x00000088 }, |
| 161 | { 0x00000018, 0x000000a1 }, |
| 162 | { 0x00000018, 0x00000098 }, |
| 163 | { 0x00004013, 0x00000088 }, |
| 164 | { 0x00006012, 0x00000087 }, |
| 165 | { 0x00000018, 0x000000df }, |
| 166 | { 0x00003015, 0x00000087 }, |
| 167 | { 0x00003015, 0x000000c7 }, |
| 168 | { 0x00000018, 0x000000c7 }, |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 169 | }; |
| 170 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 171 | struct bxt_ddi_buf_trans { |
| 172 | u32 margin; /* swing value */ |
| 173 | u32 scale; /* scale value */ |
| 174 | u32 enable; /* scale enable */ |
| 175 | u32 deemphasis; |
| 176 | bool default_index; /* true if the entry represents default value */ |
| 177 | }; |
| 178 | |
| 179 | /* BSpec does not define separate vswing/pre-emphasis values for eDP. |
| 180 | * Using DP values for eDP as well. |
| 181 | */ |
| 182 | static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = { |
| 183 | /* Idx NT mV diff db */ |
| 184 | { 52, 0, 0, 128, true }, /* 0: 400 0 */ |
| 185 | { 78, 0, 0, 85, false }, /* 1: 400 3.5 */ |
| 186 | { 104, 0, 0, 64, false }, /* 2: 400 6 */ |
| 187 | { 154, 0, 0, 43, false }, /* 3: 400 9.5 */ |
| 188 | { 77, 0, 0, 128, false }, /* 4: 600 0 */ |
| 189 | { 116, 0, 0, 85, false }, /* 5: 600 3.5 */ |
| 190 | { 154, 0, 0, 64, false }, /* 6: 600 6 */ |
| 191 | { 102, 0, 0, 128, false }, /* 7: 800 0 */ |
| 192 | { 154, 0, 0, 85, false }, /* 8: 800 3.5 */ |
| 193 | { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */ |
| 194 | }; |
| 195 | |
| 196 | /* BSpec has 2 recommended values - entries 0 and 8. |
| 197 | * Using the entry with higher vswing. |
| 198 | */ |
| 199 | static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = { |
| 200 | /* Idx NT mV diff db */ |
| 201 | { 52, 0, 0, 128, false }, /* 0: 400 0 */ |
| 202 | { 52, 0, 0, 85, false }, /* 1: 400 3.5 */ |
| 203 | { 52, 0, 0, 64, false }, /* 2: 400 6 */ |
| 204 | { 42, 0, 0, 43, false }, /* 3: 400 9.5 */ |
| 205 | { 77, 0, 0, 128, false }, /* 4: 600 0 */ |
| 206 | { 77, 0, 0, 85, false }, /* 5: 600 3.5 */ |
| 207 | { 77, 0, 0, 64, false }, /* 6: 600 6 */ |
| 208 | { 102, 0, 0, 128, false }, /* 7: 800 0 */ |
| 209 | { 102, 0, 0, 85, false }, /* 8: 800 3.5 */ |
| 210 | { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */ |
| 211 | }; |
| 212 | |
Imre Deak | a1e6ad6 | 2015-04-17 19:31:21 +0300 | [diff] [blame] | 213 | static void ddi_get_encoder_port(struct intel_encoder *intel_encoder, |
| 214 | struct intel_digital_port **dig_port, |
| 215 | enum port *port) |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 216 | { |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame] | 217 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 218 | int type = intel_encoder->type; |
| 219 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 220 | if (type == INTEL_OUTPUT_DP_MST) { |
Imre Deak | a1e6ad6 | 2015-04-17 19:31:21 +0300 | [diff] [blame] | 221 | *dig_port = enc_to_mst(encoder)->primary; |
| 222 | *port = (*dig_port)->port; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 223 | } else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 224 | type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) { |
Imre Deak | a1e6ad6 | 2015-04-17 19:31:21 +0300 | [diff] [blame] | 225 | *dig_port = enc_to_dig_port(encoder); |
| 226 | *port = (*dig_port)->port; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 227 | } else if (type == INTEL_OUTPUT_ANALOG) { |
Imre Deak | a1e6ad6 | 2015-04-17 19:31:21 +0300 | [diff] [blame] | 228 | *dig_port = NULL; |
| 229 | *port = PORT_E; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 230 | } else { |
| 231 | DRM_ERROR("Invalid DDI encoder type %d\n", type); |
| 232 | BUG(); |
| 233 | } |
| 234 | } |
| 235 | |
Imre Deak | a1e6ad6 | 2015-04-17 19:31:21 +0300 | [diff] [blame] | 236 | enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder) |
| 237 | { |
| 238 | struct intel_digital_port *dig_port; |
| 239 | enum port port; |
| 240 | |
| 241 | ddi_get_encoder_port(intel_encoder, &dig_port, &port); |
| 242 | |
| 243 | return port; |
| 244 | } |
| 245 | |
Damien Lespiau | ce3b7e9 | 2014-08-04 15:04:43 +0100 | [diff] [blame] | 246 | static bool |
| 247 | intel_dig_port_supports_hdmi(const struct intel_digital_port *intel_dig_port) |
| 248 | { |
| 249 | return intel_dig_port->hdmi.hdmi_reg; |
| 250 | } |
| 251 | |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 252 | /* |
| 253 | * Starting with Haswell, DDI port buffers must be programmed with correct |
| 254 | * 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] | 255 | * but the HDMI/DVI fields are shared among those. So we program the DDI |
| 256 | * in either FDI or DP modes only, as HDMI connections will work with both |
| 257 | * of those |
| 258 | */ |
Imre Deak | faa0cdb | 2015-04-17 19:31:22 +0300 | [diff] [blame] | 259 | static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port, |
| 260 | bool supports_hdmi) |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 261 | { |
| 262 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 263 | u32 reg; |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame] | 264 | int i, n_hdmi_entries, n_dp_entries, n_edp_entries, hdmi_default_entry, |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 265 | size; |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 266 | int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift; |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 267 | const struct ddi_buf_trans *ddi_translations_fdi; |
| 268 | const struct ddi_buf_trans *ddi_translations_dp; |
| 269 | const struct ddi_buf_trans *ddi_translations_edp; |
| 270 | const struct ddi_buf_trans *ddi_translations_hdmi; |
| 271 | const struct ddi_buf_trans *ddi_translations; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 272 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 273 | if (IS_BROXTON(dev)) { |
Imre Deak | faa0cdb | 2015-04-17 19:31:22 +0300 | [diff] [blame] | 274 | if (!supports_hdmi) |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 275 | return; |
| 276 | |
| 277 | /* Vswing programming for HDMI */ |
| 278 | bxt_ddi_vswing_sequence(dev, hdmi_level, port, |
| 279 | INTEL_OUTPUT_HDMI); |
| 280 | return; |
| 281 | } else if (IS_SKYLAKE(dev)) { |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 282 | ddi_translations_fdi = NULL; |
| 283 | ddi_translations_dp = skl_ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 284 | n_dp_entries = ARRAY_SIZE(skl_ddi_translations_dp); |
Sonika Jindal | 9e45803 | 2015-05-06 17:35:48 +0530 | [diff] [blame] | 285 | if (dev_priv->edp_low_vswing) { |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 286 | ddi_translations_edp = skl_ddi_translations_edp; |
| 287 | n_edp_entries = ARRAY_SIZE(skl_ddi_translations_edp); |
| 288 | } else { |
| 289 | ddi_translations_edp = skl_ddi_translations_dp; |
| 290 | n_edp_entries = ARRAY_SIZE(skl_ddi_translations_dp); |
| 291 | } |
| 292 | |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 293 | ddi_translations_hdmi = skl_ddi_translations_hdmi; |
| 294 | n_hdmi_entries = ARRAY_SIZE(skl_ddi_translations_hdmi); |
Sonika Jindal | b7192a5 | 2015-04-15 11:02:33 +0530 | [diff] [blame] | 295 | hdmi_default_entry = 7; |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 296 | } else if (IS_BROADWELL(dev)) { |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 297 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 298 | ddi_translations_dp = bdw_ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 299 | ddi_translations_edp = bdw_ddi_translations_edp; |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 300 | ddi_translations_hdmi = bdw_ddi_translations_hdmi; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 301 | n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp); |
| 302 | n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 303 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame] | 304 | hdmi_default_entry = 7; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 305 | } else if (IS_HASWELL(dev)) { |
| 306 | ddi_translations_fdi = hsw_ddi_translations_fdi; |
| 307 | ddi_translations_dp = hsw_ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 308 | ddi_translations_edp = hsw_ddi_translations_dp; |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 309 | ddi_translations_hdmi = hsw_ddi_translations_hdmi; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 310 | n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp); |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 311 | n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame] | 312 | hdmi_default_entry = 6; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 313 | } else { |
| 314 | WARN(1, "ddi translation table missing\n"); |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 315 | ddi_translations_edp = bdw_ddi_translations_dp; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 316 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 317 | ddi_translations_dp = bdw_ddi_translations_dp; |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 318 | ddi_translations_hdmi = bdw_ddi_translations_hdmi; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 319 | n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp); |
| 320 | n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 321 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame] | 322 | hdmi_default_entry = 7; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 325 | switch (port) { |
| 326 | case PORT_A: |
| 327 | ddi_translations = ddi_translations_edp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 328 | size = n_edp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 329 | break; |
| 330 | case PORT_B: |
| 331 | case PORT_C: |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 332 | ddi_translations = ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 333 | size = n_dp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 334 | break; |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 335 | case PORT_D: |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 336 | if (intel_dp_is_edp(dev, PORT_D)) { |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 337 | ddi_translations = ddi_translations_edp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 338 | size = n_edp_entries; |
| 339 | } else { |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 340 | ddi_translations = ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 341 | size = n_dp_entries; |
| 342 | } |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 343 | break; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 344 | case PORT_E: |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 345 | if (ddi_translations_fdi) |
| 346 | ddi_translations = ddi_translations_fdi; |
| 347 | else |
| 348 | ddi_translations = ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 349 | size = n_dp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 350 | break; |
| 351 | default: |
| 352 | BUG(); |
| 353 | } |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 354 | |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 355 | for (i = 0, reg = DDI_BUF_TRANS(port); i < size; i++) { |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 356 | I915_WRITE(reg, ddi_translations[i].trans1); |
| 357 | reg += 4; |
| 358 | I915_WRITE(reg, ddi_translations[i].trans2); |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 359 | reg += 4; |
| 360 | } |
Damien Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 361 | |
Imre Deak | faa0cdb | 2015-04-17 19:31:22 +0300 | [diff] [blame] | 362 | if (!supports_hdmi) |
Damien Lespiau | ce3b7e9 | 2014-08-04 15:04:43 +0100 | [diff] [blame] | 363 | return; |
| 364 | |
Damien Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 365 | /* Choose a good default if VBT is badly populated */ |
| 366 | if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN || |
| 367 | hdmi_level >= n_hdmi_entries) |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame] | 368 | hdmi_level = hdmi_default_entry; |
Damien Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 369 | |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 370 | /* Entry 9 is for HDMI: */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 371 | I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans1); |
| 372 | reg += 4; |
| 373 | I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans2); |
| 374 | reg += 4; |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /* Program DDI buffers translations for DP. By default, program ports A-D in DP |
| 378 | * mode and port E for FDI. |
| 379 | */ |
| 380 | void intel_prepare_ddi(struct drm_device *dev) |
| 381 | { |
Imre Deak | faa0cdb | 2015-04-17 19:31:22 +0300 | [diff] [blame] | 382 | struct intel_encoder *intel_encoder; |
Damien Lespiau | b403745 | 2014-08-04 22:01:33 +0100 | [diff] [blame] | 383 | bool visited[I915_MAX_PORTS] = { 0, }; |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 384 | |
Paulo Zanoni | 0d536cb | 2012-11-23 16:46:41 -0200 | [diff] [blame] | 385 | if (!HAS_DDI(dev)) |
| 386 | return; |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 387 | |
Imre Deak | faa0cdb | 2015-04-17 19:31:22 +0300 | [diff] [blame] | 388 | for_each_intel_encoder(dev, intel_encoder) { |
| 389 | struct intel_digital_port *intel_dig_port; |
| 390 | enum port port; |
| 391 | bool supports_hdmi; |
| 392 | |
| 393 | ddi_get_encoder_port(intel_encoder, &intel_dig_port, &port); |
| 394 | |
| 395 | if (visited[port]) |
Damien Lespiau | b403745 | 2014-08-04 22:01:33 +0100 | [diff] [blame] | 396 | continue; |
| 397 | |
Imre Deak | faa0cdb | 2015-04-17 19:31:22 +0300 | [diff] [blame] | 398 | supports_hdmi = intel_dig_port && |
| 399 | intel_dig_port_supports_hdmi(intel_dig_port); |
| 400 | |
| 401 | intel_prepare_ddi_buffers(dev, port, supports_hdmi); |
| 402 | visited[port] = true; |
Damien Lespiau | b403745 | 2014-08-04 22:01:33 +0100 | [diff] [blame] | 403 | } |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 404 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 405 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 406 | static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, |
| 407 | enum port port) |
| 408 | { |
| 409 | uint32_t reg = DDI_BUF_CTL(port); |
| 410 | int i; |
| 411 | |
Vandana Kannan | 3449ca8 | 2015-03-27 14:19:09 +0200 | [diff] [blame] | 412 | for (i = 0; i < 16; i++) { |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 413 | udelay(1); |
| 414 | if (I915_READ(reg) & DDI_BUF_IS_IDLE) |
| 415 | return; |
| 416 | } |
| 417 | DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port)); |
| 418 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 419 | |
| 420 | /* Starting with Haswell, different DDI ports can work in FDI mode for |
| 421 | * connection to the PCH-located connectors. For this, it is necessary to train |
| 422 | * both the DDI port and PCH receiver for the desired DDI buffer settings. |
| 423 | * |
| 424 | * The recommended port to work in FDI mode is DDI E, which we use here. Also, |
| 425 | * please note that when FDI mode is active on DDI E, it shares 2 lines with |
| 426 | * DDI A (which is used for eDP) |
| 427 | */ |
| 428 | |
| 429 | void hsw_fdi_link_train(struct drm_crtc *crtc) |
| 430 | { |
| 431 | struct drm_device *dev = crtc->dev; |
| 432 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 433 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 434 | u32 temp, i, rx_ctl_val; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 435 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 436 | /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the |
| 437 | * mode set "sequence for CRT port" document: |
| 438 | * - TP1 to TP2 time with the default value |
| 439 | * - FDI delay to 90h |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 440 | * |
| 441 | * WaFDIAutoLinkSetTimingOverrride:hsw |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 442 | */ |
| 443 | I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) | |
| 444 | FDI_RX_PWRDN_LANE0_VAL(2) | |
| 445 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 446 | |
| 447 | /* Enable the PCH Receiver FDI PLL */ |
Damien Lespiau | 3e68320 | 2012-12-11 18:48:29 +0000 | [diff] [blame] | 448 | 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] | 449 | FDI_RX_PLL_ENABLE | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 450 | FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 451 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 452 | POSTING_READ(_FDI_RXA_CTL); |
| 453 | udelay(220); |
| 454 | |
| 455 | /* Switch from Rawclk to PCDclk */ |
| 456 | rx_ctl_val |= FDI_PCDCLK; |
| 457 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 458 | |
| 459 | /* Configure Port Clock Select */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 460 | I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config->ddi_pll_sel); |
| 461 | WARN_ON(intel_crtc->config->ddi_pll_sel != PORT_CLK_SEL_SPLL); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 462 | |
| 463 | /* Start the training iterating through available voltages and emphasis, |
| 464 | * testing each value twice. */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 465 | for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) { |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 466 | /* Configure DP_TP_CTL with auto-training */ |
| 467 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 468 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 469 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 470 | DP_TP_CTL_LINK_TRAIN_PAT1 | |
| 471 | DP_TP_CTL_ENABLE); |
| 472 | |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 473 | /* Configure and enable DDI_BUF_CTL for DDI E with next voltage. |
| 474 | * DDI E does not support port reversal, the functionality is |
| 475 | * achieved on the PCH side in FDI_RX_CTL, so no need to set the |
| 476 | * port reversal bit */ |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 477 | I915_WRITE(DDI_BUF_CTL(PORT_E), |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 478 | DDI_BUF_CTL_ENABLE | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 479 | ((intel_crtc->config->fdi_lanes - 1) << 1) | |
Sonika Jindal | c5fe6a0 | 2014-08-11 08:57:36 +0530 | [diff] [blame] | 480 | DDI_BUF_TRANS_SELECT(i / 2)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 481 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 482 | |
| 483 | udelay(600); |
| 484 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 485 | /* Program PCH FDI Receiver TU */ |
| 486 | I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64)); |
Eugeni Dodonov | 4acf518 | 2012-07-04 20:15:16 -0300 | [diff] [blame] | 487 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 488 | /* Enable PCH FDI Receiver with auto-training */ |
| 489 | rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO; |
| 490 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 491 | POSTING_READ(_FDI_RXA_CTL); |
| 492 | |
| 493 | /* Wait for FDI receiver lane calibration */ |
| 494 | udelay(30); |
| 495 | |
| 496 | /* Unset FDI_RX_MISC pwrdn lanes */ |
| 497 | temp = I915_READ(_FDI_RXA_MISC); |
| 498 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 499 | I915_WRITE(_FDI_RXA_MISC, temp); |
| 500 | POSTING_READ(_FDI_RXA_MISC); |
| 501 | |
| 502 | /* Wait for FDI auto training time */ |
| 503 | udelay(5); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 504 | |
| 505 | temp = I915_READ(DP_TP_STATUS(PORT_E)); |
| 506 | if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 507 | DRM_DEBUG_KMS("FDI link training done on step %d\n", i); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 508 | |
| 509 | /* Enable normal pixel sending for FDI */ |
| 510 | I915_WRITE(DP_TP_CTL(PORT_E), |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 511 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 512 | DP_TP_CTL_LINK_TRAIN_NORMAL | |
| 513 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 514 | DP_TP_CTL_ENABLE); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 515 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 516 | return; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 517 | } |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 518 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 519 | temp = I915_READ(DDI_BUF_CTL(PORT_E)); |
| 520 | temp &= ~DDI_BUF_CTL_ENABLE; |
| 521 | I915_WRITE(DDI_BUF_CTL(PORT_E), temp); |
| 522 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
| 523 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 524 | /* Disable DP_TP_CTL and FDI_RX_CTL and retry */ |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 525 | temp = I915_READ(DP_TP_CTL(PORT_E)); |
| 526 | temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 527 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 528 | I915_WRITE(DP_TP_CTL(PORT_E), temp); |
| 529 | POSTING_READ(DP_TP_CTL(PORT_E)); |
| 530 | |
| 531 | intel_wait_ddi_buf_idle(dev_priv, PORT_E); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 532 | |
| 533 | rx_ctl_val &= ~FDI_RX_ENABLE; |
| 534 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 535 | POSTING_READ(_FDI_RXA_CTL); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 536 | |
| 537 | /* Reset FDI_RX_MISC pwrdn lanes */ |
| 538 | temp = I915_READ(_FDI_RXA_MISC); |
| 539 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 540 | temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
| 541 | I915_WRITE(_FDI_RXA_MISC, temp); |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 542 | POSTING_READ(_FDI_RXA_MISC); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 543 | } |
| 544 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 545 | DRM_ERROR("FDI link training failed!\n"); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 546 | } |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 547 | |
Dave Airlie | 44905a27 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 548 | void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder) |
| 549 | { |
| 550 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 551 | struct intel_digital_port *intel_dig_port = |
| 552 | enc_to_dig_port(&encoder->base); |
| 553 | |
| 554 | intel_dp->DP = intel_dig_port->saved_port_bits | |
Sonika Jindal | c5fe6a0 | 2014-08-11 08:57:36 +0530 | [diff] [blame] | 555 | DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0); |
Dave Airlie | 44905a27 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 556 | intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count); |
| 557 | |
| 558 | } |
| 559 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 560 | static struct intel_encoder * |
| 561 | intel_ddi_get_crtc_encoder(struct drm_crtc *crtc) |
| 562 | { |
| 563 | struct drm_device *dev = crtc->dev; |
| 564 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 565 | struct intel_encoder *intel_encoder, *ret = NULL; |
| 566 | int num_encoders = 0; |
| 567 | |
| 568 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 569 | ret = intel_encoder; |
| 570 | num_encoders++; |
| 571 | } |
| 572 | |
| 573 | if (num_encoders != 1) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 574 | WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders, |
| 575 | pipe_name(intel_crtc->pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 576 | |
| 577 | BUG_ON(ret == NULL); |
| 578 | return ret; |
| 579 | } |
| 580 | |
Satheeshakrishna M | bcddf61 | 2014-08-22 09:49:10 +0530 | [diff] [blame] | 581 | struct intel_encoder * |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 582 | intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 583 | { |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 584 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
| 585 | struct intel_encoder *ret = NULL; |
| 586 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 587 | struct drm_connector *connector; |
| 588 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 589 | int num_encoders = 0; |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 590 | int i; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 591 | |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 592 | state = crtc_state->base.state; |
| 593 | |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 594 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 595 | if (connector_state->crtc != crtc_state->base.crtc) |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 596 | continue; |
| 597 | |
Ander Conselvan de Oliveira | da3ced2 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 598 | ret = to_intel_encoder(connector_state->best_encoder); |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 599 | num_encoders++; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders, |
| 603 | pipe_name(crtc->pipe)); |
| 604 | |
| 605 | BUG_ON(ret == NULL); |
| 606 | return ret; |
| 607 | } |
| 608 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 609 | #define LC_FREQ 2700 |
Damien Lespiau | 2789339 | 2014-09-04 12:27:23 +0100 | [diff] [blame] | 610 | #define LC_FREQ_2K U64_C(LC_FREQ * 2000) |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 611 | |
| 612 | #define P_MIN 2 |
| 613 | #define P_MAX 64 |
| 614 | #define P_INC 2 |
| 615 | |
| 616 | /* Constraints for PLL good behavior */ |
| 617 | #define REF_MIN 48 |
| 618 | #define REF_MAX 400 |
| 619 | #define VCO_MIN 2400 |
| 620 | #define VCO_MAX 4800 |
| 621 | |
Damien Lespiau | 2789339 | 2014-09-04 12:27:23 +0100 | [diff] [blame] | 622 | #define abs_diff(a, b) ({ \ |
| 623 | typeof(a) __a = (a); \ |
| 624 | typeof(b) __b = (b); \ |
| 625 | (void) (&__a == &__b); \ |
| 626 | __a > __b ? (__a - __b) : (__b - __a); }) |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 627 | |
| 628 | struct wrpll_rnp { |
| 629 | unsigned p, n2, r2; |
| 630 | }; |
| 631 | |
| 632 | static unsigned wrpll_get_budget_for_freq(int clock) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 633 | { |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 634 | unsigned budget; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 635 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 636 | switch (clock) { |
| 637 | case 25175000: |
| 638 | case 25200000: |
| 639 | case 27000000: |
| 640 | case 27027000: |
| 641 | case 37762500: |
| 642 | case 37800000: |
| 643 | case 40500000: |
| 644 | case 40541000: |
| 645 | case 54000000: |
| 646 | case 54054000: |
| 647 | case 59341000: |
| 648 | case 59400000: |
| 649 | case 72000000: |
| 650 | case 74176000: |
| 651 | case 74250000: |
| 652 | case 81000000: |
| 653 | case 81081000: |
| 654 | case 89012000: |
| 655 | case 89100000: |
| 656 | case 108000000: |
| 657 | case 108108000: |
| 658 | case 111264000: |
| 659 | case 111375000: |
| 660 | case 148352000: |
| 661 | case 148500000: |
| 662 | case 162000000: |
| 663 | case 162162000: |
| 664 | case 222525000: |
| 665 | case 222750000: |
| 666 | case 296703000: |
| 667 | case 297000000: |
| 668 | budget = 0; |
| 669 | break; |
| 670 | case 233500000: |
| 671 | case 245250000: |
| 672 | case 247750000: |
| 673 | case 253250000: |
| 674 | case 298000000: |
| 675 | budget = 1500; |
| 676 | break; |
| 677 | case 169128000: |
| 678 | case 169500000: |
| 679 | case 179500000: |
| 680 | case 202000000: |
| 681 | budget = 2000; |
| 682 | break; |
| 683 | case 256250000: |
| 684 | case 262500000: |
| 685 | case 270000000: |
| 686 | case 272500000: |
| 687 | case 273750000: |
| 688 | case 280750000: |
| 689 | case 281250000: |
| 690 | case 286000000: |
| 691 | case 291750000: |
| 692 | budget = 4000; |
| 693 | break; |
| 694 | case 267250000: |
| 695 | case 268500000: |
| 696 | budget = 5000; |
| 697 | break; |
| 698 | default: |
| 699 | budget = 1000; |
| 700 | break; |
| 701 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 702 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 703 | return budget; |
| 704 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 705 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 706 | static void wrpll_update_rnp(uint64_t freq2k, unsigned budget, |
| 707 | unsigned r2, unsigned n2, unsigned p, |
| 708 | struct wrpll_rnp *best) |
| 709 | { |
| 710 | uint64_t a, b, c, d, diff, diff_best; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 711 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 712 | /* No best (r,n,p) yet */ |
| 713 | if (best->p == 0) { |
| 714 | best->p = p; |
| 715 | best->n2 = n2; |
| 716 | best->r2 = r2; |
| 717 | return; |
| 718 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 719 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 720 | /* |
| 721 | * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to |
| 722 | * freq2k. |
| 723 | * |
| 724 | * delta = 1e6 * |
| 725 | * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) / |
| 726 | * freq2k; |
| 727 | * |
| 728 | * and we would like delta <= budget. |
| 729 | * |
| 730 | * If the discrepancy is above the PPM-based budget, always prefer to |
| 731 | * improve upon the previous solution. However, if you're within the |
| 732 | * budget, try to maximize Ref * VCO, that is N / (P * R^2). |
| 733 | */ |
| 734 | a = freq2k * budget * p * r2; |
| 735 | b = freq2k * budget * best->p * best->r2; |
Damien Lespiau | 2789339 | 2014-09-04 12:27:23 +0100 | [diff] [blame] | 736 | diff = abs_diff(freq2k * p * r2, LC_FREQ_2K * n2); |
| 737 | diff_best = abs_diff(freq2k * best->p * best->r2, |
| 738 | LC_FREQ_2K * best->n2); |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 739 | c = 1000000 * diff; |
| 740 | d = 1000000 * diff_best; |
| 741 | |
| 742 | if (a < c && b < d) { |
| 743 | /* If both are above the budget, pick the closer */ |
| 744 | if (best->p * best->r2 * diff < p * r2 * diff_best) { |
| 745 | best->p = p; |
| 746 | best->n2 = n2; |
| 747 | best->r2 = r2; |
| 748 | } |
| 749 | } else if (a >= c && b < d) { |
| 750 | /* If A is below the threshold but B is above it? Update. */ |
| 751 | best->p = p; |
| 752 | best->n2 = n2; |
| 753 | best->r2 = r2; |
| 754 | } else if (a >= c && b >= d) { |
| 755 | /* Both are below the limit, so pick the higher n2/(r2*r2) */ |
| 756 | if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) { |
| 757 | best->p = p; |
| 758 | best->n2 = n2; |
| 759 | best->r2 = r2; |
| 760 | } |
| 761 | } |
| 762 | /* Otherwise a < c && b >= d, do nothing */ |
| 763 | } |
| 764 | |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 765 | static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv, |
| 766 | int reg) |
| 767 | { |
| 768 | int refclk = LC_FREQ; |
| 769 | int n, p, r; |
| 770 | u32 wrpll; |
| 771 | |
| 772 | wrpll = I915_READ(reg); |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 773 | switch (wrpll & WRPLL_PLL_REF_MASK) { |
| 774 | case WRPLL_PLL_SSC: |
| 775 | case WRPLL_PLL_NON_SSC: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 776 | /* |
| 777 | * We could calculate spread here, but our checking |
| 778 | * code only cares about 5% accuracy, and spread is a max of |
| 779 | * 0.5% downspread. |
| 780 | */ |
| 781 | refclk = 135; |
| 782 | break; |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 783 | case WRPLL_PLL_LCPLL: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 784 | refclk = LC_FREQ; |
| 785 | break; |
| 786 | default: |
| 787 | WARN(1, "bad wrpll refclk\n"); |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | r = wrpll & WRPLL_DIVIDER_REF_MASK; |
| 792 | p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT; |
| 793 | n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT; |
| 794 | |
Jesse Barnes | 20f0ec1 | 2014-01-22 12:58:04 -0800 | [diff] [blame] | 795 | /* Convert to KHz, p & r have a fixed point portion */ |
| 796 | return (refclk * n * 100) / (p * r); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 797 | } |
| 798 | |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 799 | static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv, |
| 800 | uint32_t dpll) |
| 801 | { |
| 802 | uint32_t cfgcr1_reg, cfgcr2_reg; |
| 803 | uint32_t cfgcr1_val, cfgcr2_val; |
| 804 | uint32_t p0, p1, p2, dco_freq; |
| 805 | |
| 806 | cfgcr1_reg = GET_CFG_CR1_REG(dpll); |
| 807 | cfgcr2_reg = GET_CFG_CR2_REG(dpll); |
| 808 | |
| 809 | cfgcr1_val = I915_READ(cfgcr1_reg); |
| 810 | cfgcr2_val = I915_READ(cfgcr2_reg); |
| 811 | |
| 812 | p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK; |
| 813 | p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK; |
| 814 | |
| 815 | if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1)) |
| 816 | p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8; |
| 817 | else |
| 818 | p1 = 1; |
| 819 | |
| 820 | |
| 821 | switch (p0) { |
| 822 | case DPLL_CFGCR2_PDIV_1: |
| 823 | p0 = 1; |
| 824 | break; |
| 825 | case DPLL_CFGCR2_PDIV_2: |
| 826 | p0 = 2; |
| 827 | break; |
| 828 | case DPLL_CFGCR2_PDIV_3: |
| 829 | p0 = 3; |
| 830 | break; |
| 831 | case DPLL_CFGCR2_PDIV_7: |
| 832 | p0 = 7; |
| 833 | break; |
| 834 | } |
| 835 | |
| 836 | switch (p2) { |
| 837 | case DPLL_CFGCR2_KDIV_5: |
| 838 | p2 = 5; |
| 839 | break; |
| 840 | case DPLL_CFGCR2_KDIV_2: |
| 841 | p2 = 2; |
| 842 | break; |
| 843 | case DPLL_CFGCR2_KDIV_3: |
| 844 | p2 = 3; |
| 845 | break; |
| 846 | case DPLL_CFGCR2_KDIV_1: |
| 847 | p2 = 1; |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000; |
| 852 | |
| 853 | dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 * |
| 854 | 1000) / 0x8000; |
| 855 | |
| 856 | return dco_freq / (p0 * p1 * p2 * 5); |
| 857 | } |
| 858 | |
| 859 | |
| 860 | static void skl_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 861 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 862 | { |
| 863 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 864 | int link_clock = 0; |
| 865 | uint32_t dpll_ctl1, dpll; |
| 866 | |
Damien Lespiau | 134ffa4 | 2014-11-14 17:24:34 +0000 | [diff] [blame] | 867 | dpll = pipe_config->ddi_pll_sel; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 868 | |
| 869 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 870 | |
| 871 | if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) { |
| 872 | link_clock = skl_calc_wrpll_link(dev_priv, dpll); |
| 873 | } else { |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 874 | link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll); |
| 875 | link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll); |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 876 | |
| 877 | switch (link_clock) { |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 878 | case DPLL_CTRL1_LINK_RATE_810: |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 879 | link_clock = 81000; |
| 880 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 881 | case DPLL_CTRL1_LINK_RATE_1080: |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 882 | link_clock = 108000; |
| 883 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 884 | case DPLL_CTRL1_LINK_RATE_1350: |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 885 | link_clock = 135000; |
| 886 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 887 | case DPLL_CTRL1_LINK_RATE_1620: |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 888 | link_clock = 162000; |
| 889 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 890 | case DPLL_CTRL1_LINK_RATE_2160: |
Sonika Jindal | a8f3ef6 | 2015-03-05 10:02:30 +0530 | [diff] [blame] | 891 | link_clock = 216000; |
| 892 | break; |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 893 | case DPLL_CTRL1_LINK_RATE_2700: |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 894 | link_clock = 270000; |
| 895 | break; |
| 896 | default: |
| 897 | WARN(1, "Unsupported link rate\n"); |
| 898 | break; |
| 899 | } |
| 900 | link_clock *= 2; |
| 901 | } |
| 902 | |
| 903 | pipe_config->port_clock = link_clock; |
| 904 | |
| 905 | if (pipe_config->has_dp_encoder) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 906 | pipe_config->base.adjusted_mode.crtc_clock = |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 907 | intel_dotclock_calculate(pipe_config->port_clock, |
| 908 | &pipe_config->dp_m_n); |
| 909 | else |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 910 | pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 913 | static void hsw_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 914 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 915 | { |
| 916 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 917 | int link_clock = 0; |
| 918 | u32 val, pll; |
| 919 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 920 | val = pipe_config->ddi_pll_sel; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 921 | switch (val & PORT_CLK_SEL_MASK) { |
| 922 | case PORT_CLK_SEL_LCPLL_810: |
| 923 | link_clock = 81000; |
| 924 | break; |
| 925 | case PORT_CLK_SEL_LCPLL_1350: |
| 926 | link_clock = 135000; |
| 927 | break; |
| 928 | case PORT_CLK_SEL_LCPLL_2700: |
| 929 | link_clock = 270000; |
| 930 | break; |
| 931 | case PORT_CLK_SEL_WRPLL1: |
| 932 | link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1); |
| 933 | break; |
| 934 | case PORT_CLK_SEL_WRPLL2: |
| 935 | link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2); |
| 936 | break; |
| 937 | case PORT_CLK_SEL_SPLL: |
| 938 | pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK; |
| 939 | if (pll == SPLL_PLL_FREQ_810MHz) |
| 940 | link_clock = 81000; |
| 941 | else if (pll == SPLL_PLL_FREQ_1350MHz) |
| 942 | link_clock = 135000; |
| 943 | else if (pll == SPLL_PLL_FREQ_2700MHz) |
| 944 | link_clock = 270000; |
| 945 | else { |
| 946 | WARN(1, "bad spll freq\n"); |
| 947 | return; |
| 948 | } |
| 949 | break; |
| 950 | default: |
| 951 | WARN(1, "bad port clock sel\n"); |
| 952 | return; |
| 953 | } |
| 954 | |
| 955 | pipe_config->port_clock = link_clock * 2; |
| 956 | |
| 957 | if (pipe_config->has_pch_encoder) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 958 | pipe_config->base.adjusted_mode.crtc_clock = |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 959 | intel_dotclock_calculate(pipe_config->port_clock, |
| 960 | &pipe_config->fdi_m_n); |
| 961 | else if (pipe_config->has_dp_encoder) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 962 | pipe_config->base.adjusted_mode.crtc_clock = |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 963 | intel_dotclock_calculate(pipe_config->port_clock, |
| 964 | &pipe_config->dp_m_n); |
| 965 | else |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 966 | pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 969 | static int bxt_calc_pll_link(struct drm_i915_private *dev_priv, |
| 970 | enum intel_dpll_id dpll) |
| 971 | { |
| 972 | /* FIXME formula not available in bspec */ |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | static void bxt_ddi_clock_get(struct intel_encoder *encoder, |
| 977 | struct intel_crtc_state *pipe_config) |
| 978 | { |
| 979 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 980 | enum port port = intel_ddi_get_encoder_port(encoder); |
| 981 | uint32_t dpll = port; |
| 982 | |
| 983 | pipe_config->port_clock = |
| 984 | bxt_calc_pll_link(dev_priv, dpll); |
| 985 | |
| 986 | if (pipe_config->has_dp_encoder) |
| 987 | pipe_config->base.adjusted_mode.crtc_clock = |
| 988 | intel_dotclock_calculate(pipe_config->port_clock, |
| 989 | &pipe_config->dp_m_n); |
| 990 | else |
| 991 | pipe_config->base.adjusted_mode.crtc_clock = |
| 992 | pipe_config->port_clock; |
| 993 | } |
| 994 | |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 995 | void intel_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 996 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 997 | { |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 998 | struct drm_device *dev = encoder->base.dev; |
| 999 | |
| 1000 | if (INTEL_INFO(dev)->gen <= 8) |
| 1001 | hsw_ddi_clock_get(encoder, pipe_config); |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 1002 | else if (IS_SKYLAKE(dev)) |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 1003 | skl_ddi_clock_get(encoder, pipe_config); |
Satheeshakrishna M | 977bb38 | 2014-08-22 09:49:12 +0530 | [diff] [blame] | 1004 | else if (IS_BROXTON(dev)) |
| 1005 | bxt_ddi_clock_get(encoder, pipe_config); |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 1006 | } |
| 1007 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 1008 | static void |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 1009 | hsw_ddi_calculate_wrpll(int clock /* in Hz */, |
| 1010 | unsigned *r2_out, unsigned *n2_out, unsigned *p_out) |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 1011 | { |
| 1012 | uint64_t freq2k; |
| 1013 | unsigned p, n2, r2; |
| 1014 | struct wrpll_rnp best = { 0, 0, 0 }; |
| 1015 | unsigned budget; |
| 1016 | |
| 1017 | freq2k = clock / 100; |
| 1018 | |
| 1019 | budget = wrpll_get_budget_for_freq(clock); |
| 1020 | |
| 1021 | /* Special case handling for 540 pixel clock: bypass WR PLL entirely |
| 1022 | * and directly pass the LC PLL to it. */ |
| 1023 | if (freq2k == 5400000) { |
| 1024 | *n2_out = 2; |
| 1025 | *p_out = 1; |
| 1026 | *r2_out = 2; |
| 1027 | return; |
| 1028 | } |
| 1029 | |
| 1030 | /* |
| 1031 | * Ref = LC_FREQ / R, where Ref is the actual reference input seen by |
| 1032 | * the WR PLL. |
| 1033 | * |
| 1034 | * We want R so that REF_MIN <= Ref <= REF_MAX. |
| 1035 | * Injecting R2 = 2 * R gives: |
| 1036 | * REF_MAX * r2 > LC_FREQ * 2 and |
| 1037 | * REF_MIN * r2 < LC_FREQ * 2 |
| 1038 | * |
| 1039 | * Which means the desired boundaries for r2 are: |
| 1040 | * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN |
| 1041 | * |
| 1042 | */ |
| 1043 | for (r2 = LC_FREQ * 2 / REF_MAX + 1; |
| 1044 | r2 <= LC_FREQ * 2 / REF_MIN; |
| 1045 | r2++) { |
| 1046 | |
| 1047 | /* |
| 1048 | * VCO = N * Ref, that is: VCO = N * LC_FREQ / R |
| 1049 | * |
| 1050 | * Once again we want VCO_MIN <= VCO <= VCO_MAX. |
| 1051 | * Injecting R2 = 2 * R and N2 = 2 * N, we get: |
| 1052 | * VCO_MAX * r2 > n2 * LC_FREQ and |
| 1053 | * VCO_MIN * r2 < n2 * LC_FREQ) |
| 1054 | * |
| 1055 | * Which means the desired boundaries for n2 are: |
| 1056 | * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ |
| 1057 | */ |
| 1058 | for (n2 = VCO_MIN * r2 / LC_FREQ + 1; |
| 1059 | n2 <= VCO_MAX * r2 / LC_FREQ; |
| 1060 | n2++) { |
| 1061 | |
| 1062 | for (p = P_MIN; p <= P_MAX; p += P_INC) |
| 1063 | wrpll_update_rnp(freq2k, budget, |
| 1064 | r2, n2, p, &best); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | *n2_out = best.n2; |
| 1069 | *p_out = best.p; |
| 1070 | *r2_out = best.r2; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1071 | } |
| 1072 | |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1073 | static bool |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 1074 | hsw_ddi_pll_select(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1075 | struct intel_crtc_state *crtc_state, |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 1076 | struct intel_encoder *intel_encoder, |
| 1077 | int clock) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1078 | { |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 1079 | if (intel_encoder->type == INTEL_OUTPUT_HDMI) { |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 1080 | struct intel_shared_dpll *pll; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 1081 | uint32_t val; |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 1082 | unsigned p, n2, r2; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1083 | |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 1084 | hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1085 | |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 1086 | val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1087 | WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) | |
| 1088 | WRPLL_DIVIDER_POST(p); |
| 1089 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 1090 | memset(&crtc_state->dpll_hw_state, 0, |
| 1091 | sizeof(crtc_state->dpll_hw_state)); |
| 1092 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1093 | crtc_state->dpll_hw_state.wrpll = val; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 1094 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1095 | pll = intel_get_shared_dpll(intel_crtc, crtc_state); |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 1096 | if (pll == NULL) { |
| 1097 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 1098 | pipe_name(intel_crtc->pipe)); |
Paulo Zanoni | 0694001 | 2013-10-30 18:27:43 -0200 | [diff] [blame] | 1099 | return false; |
| 1100 | } |
| 1101 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1102 | crtc_state->ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1103 | } |
| 1104 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1105 | return true; |
| 1106 | } |
| 1107 | |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1108 | struct skl_wrpll_params { |
| 1109 | uint32_t dco_fraction; |
| 1110 | uint32_t dco_integer; |
| 1111 | uint32_t qdiv_ratio; |
| 1112 | uint32_t qdiv_mode; |
| 1113 | uint32_t kdiv; |
| 1114 | uint32_t pdiv; |
| 1115 | uint32_t central_freq; |
| 1116 | }; |
| 1117 | |
| 1118 | static void |
| 1119 | skl_ddi_calculate_wrpll(int clock /* in Hz */, |
| 1120 | struct skl_wrpll_params *wrpll_params) |
| 1121 | { |
| 1122 | uint64_t afe_clock = clock * 5; /* AFE Clock is 5x Pixel clock */ |
Damien Lespiau | 21318cc | 2014-11-14 14:20:27 +0000 | [diff] [blame] | 1123 | uint64_t dco_central_freq[3] = {8400000000ULL, |
| 1124 | 9000000000ULL, |
| 1125 | 9600000000ULL}; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1126 | uint32_t min_dco_deviation = 400; |
| 1127 | uint32_t min_dco_index = 3; |
| 1128 | uint32_t P0[4] = {1, 2, 3, 7}; |
| 1129 | uint32_t P2[4] = {1, 2, 3, 5}; |
| 1130 | bool found = false; |
| 1131 | uint32_t candidate_p = 0; |
| 1132 | uint32_t candidate_p0[3] = {0}, candidate_p1[3] = {0}; |
| 1133 | uint32_t candidate_p2[3] = {0}; |
| 1134 | uint32_t dco_central_freq_deviation[3]; |
| 1135 | uint32_t i, P1, k, dco_count; |
| 1136 | bool retry_with_odd = false; |
| 1137 | uint64_t dco_freq; |
| 1138 | |
| 1139 | /* Determine P0, P1 or P2 */ |
| 1140 | for (dco_count = 0; dco_count < 3; dco_count++) { |
| 1141 | found = false; |
| 1142 | candidate_p = |
| 1143 | div64_u64(dco_central_freq[dco_count], afe_clock); |
| 1144 | if (retry_with_odd == false) |
| 1145 | candidate_p = (candidate_p % 2 == 0 ? |
| 1146 | candidate_p : candidate_p + 1); |
| 1147 | |
| 1148 | for (P1 = 1; P1 < candidate_p; P1++) { |
| 1149 | for (i = 0; i < 4; i++) { |
| 1150 | if (!(P0[i] != 1 || P1 == 1)) |
| 1151 | continue; |
| 1152 | |
| 1153 | for (k = 0; k < 4; k++) { |
| 1154 | if (P1 != 1 && P2[k] != 2) |
| 1155 | continue; |
| 1156 | |
| 1157 | if (candidate_p == P0[i] * P1 * P2[k]) { |
| 1158 | /* Found possible P0, P1, P2 */ |
| 1159 | found = true; |
| 1160 | candidate_p0[dco_count] = P0[i]; |
| 1161 | candidate_p1[dco_count] = P1; |
| 1162 | candidate_p2[dco_count] = P2[k]; |
| 1163 | goto found; |
| 1164 | } |
| 1165 | |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | found: |
| 1171 | if (found) { |
| 1172 | dco_central_freq_deviation[dco_count] = |
| 1173 | div64_u64(10000 * |
| 1174 | abs_diff((candidate_p * afe_clock), |
| 1175 | dco_central_freq[dco_count]), |
| 1176 | dco_central_freq[dco_count]); |
| 1177 | |
| 1178 | if (dco_central_freq_deviation[dco_count] < |
| 1179 | min_dco_deviation) { |
| 1180 | min_dco_deviation = |
| 1181 | dco_central_freq_deviation[dco_count]; |
| 1182 | min_dco_index = dco_count; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | if (min_dco_index > 2 && dco_count == 2) { |
| 1187 | retry_with_odd = true; |
| 1188 | dco_count = 0; |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | if (min_dco_index > 2) { |
| 1193 | WARN(1, "No valid values found for the given pixel clock\n"); |
| 1194 | } else { |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1195 | wrpll_params->central_freq = dco_central_freq[min_dco_index]; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1196 | |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1197 | switch (dco_central_freq[min_dco_index]) { |
| 1198 | case 9600000000ULL: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1199 | wrpll_params->central_freq = 0; |
| 1200 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1201 | case 9000000000ULL: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1202 | wrpll_params->central_freq = 1; |
| 1203 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1204 | case 8400000000ULL: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1205 | wrpll_params->central_freq = 3; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1206 | } |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1207 | |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1208 | switch (candidate_p0[min_dco_index]) { |
| 1209 | case 1: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1210 | wrpll_params->pdiv = 0; |
| 1211 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1212 | case 2: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1213 | wrpll_params->pdiv = 1; |
| 1214 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1215 | case 3: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1216 | wrpll_params->pdiv = 2; |
| 1217 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1218 | case 7: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1219 | wrpll_params->pdiv = 4; |
| 1220 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1221 | default: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1222 | WARN(1, "Incorrect PDiv\n"); |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1223 | } |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1224 | |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1225 | switch (candidate_p2[min_dco_index]) { |
| 1226 | case 5: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1227 | wrpll_params->kdiv = 0; |
| 1228 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1229 | case 2: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1230 | wrpll_params->kdiv = 1; |
| 1231 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1232 | case 3: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1233 | wrpll_params->kdiv = 2; |
| 1234 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1235 | case 1: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1236 | wrpll_params->kdiv = 3; |
| 1237 | break; |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1238 | default: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1239 | WARN(1, "Incorrect KDiv\n"); |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1240 | } |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1241 | |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1242 | wrpll_params->qdiv_ratio = candidate_p1[min_dco_index]; |
| 1243 | wrpll_params->qdiv_mode = |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1244 | (wrpll_params->qdiv_ratio == 1) ? 0 : 1; |
| 1245 | |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1246 | dco_freq = candidate_p0[min_dco_index] * |
| 1247 | candidate_p1[min_dco_index] * |
| 1248 | candidate_p2[min_dco_index] * afe_clock; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1249 | |
| 1250 | /* |
Damien Lespiau | ebf7ed1 | 2015-05-07 18:38:37 +0100 | [diff] [blame] | 1251 | * Intermediate values are in Hz. |
| 1252 | * Divide by MHz to match bsepc |
| 1253 | */ |
| 1254 | wrpll_params->dco_integer = div_u64(dco_freq, (24 * MHz(1))); |
| 1255 | wrpll_params->dco_fraction = |
| 1256 | div_u64(((div_u64(dco_freq, 24) - |
| 1257 | wrpll_params->dco_integer * MHz(1)) * 0x8000), MHz(1)); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1258 | |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | |
| 1263 | static bool |
| 1264 | skl_ddi_pll_select(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1265 | struct intel_crtc_state *crtc_state, |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1266 | struct intel_encoder *intel_encoder, |
| 1267 | int clock) |
| 1268 | { |
| 1269 | struct intel_shared_dpll *pll; |
| 1270 | uint32_t ctrl1, cfgcr1, cfgcr2; |
| 1271 | |
| 1272 | /* |
| 1273 | * See comment in intel_dpll_hw_state to understand why we always use 0 |
| 1274 | * as the DPLL id in this function. |
| 1275 | */ |
| 1276 | |
| 1277 | ctrl1 = DPLL_CTRL1_OVERRIDE(0); |
| 1278 | |
| 1279 | if (intel_encoder->type == INTEL_OUTPUT_HDMI) { |
| 1280 | struct skl_wrpll_params wrpll_params = { 0, }; |
| 1281 | |
| 1282 | ctrl1 |= DPLL_CTRL1_HDMI_MODE(0); |
| 1283 | |
| 1284 | skl_ddi_calculate_wrpll(clock * 1000, &wrpll_params); |
| 1285 | |
| 1286 | cfgcr1 = DPLL_CFGCR1_FREQ_ENABLE | |
| 1287 | DPLL_CFGCR1_DCO_FRACTION(wrpll_params.dco_fraction) | |
| 1288 | wrpll_params.dco_integer; |
| 1289 | |
| 1290 | cfgcr2 = DPLL_CFGCR2_QDIV_RATIO(wrpll_params.qdiv_ratio) | |
| 1291 | DPLL_CFGCR2_QDIV_MODE(wrpll_params.qdiv_mode) | |
| 1292 | DPLL_CFGCR2_KDIV(wrpll_params.kdiv) | |
| 1293 | DPLL_CFGCR2_PDIV(wrpll_params.pdiv) | |
| 1294 | wrpll_params.central_freq; |
| 1295 | } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) { |
| 1296 | struct drm_encoder *encoder = &intel_encoder->base; |
| 1297 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1298 | |
| 1299 | switch (intel_dp->link_bw) { |
| 1300 | case DP_LINK_BW_1_62: |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 1301 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, 0); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1302 | break; |
| 1303 | case DP_LINK_BW_2_7: |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 1304 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350, 0); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1305 | break; |
| 1306 | case DP_LINK_BW_5_4: |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 1307 | ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700, 0); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | cfgcr1 = cfgcr2 = 0; |
| 1312 | } else /* eDP */ |
| 1313 | return true; |
| 1314 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 1315 | memset(&crtc_state->dpll_hw_state, 0, |
| 1316 | sizeof(crtc_state->dpll_hw_state)); |
| 1317 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1318 | crtc_state->dpll_hw_state.ctrl1 = ctrl1; |
| 1319 | crtc_state->dpll_hw_state.cfgcr1 = cfgcr1; |
| 1320 | crtc_state->dpll_hw_state.cfgcr2 = cfgcr2; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1321 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1322 | pll = intel_get_shared_dpll(intel_crtc, crtc_state); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1323 | if (pll == NULL) { |
| 1324 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 1325 | pipe_name(intel_crtc->pipe)); |
| 1326 | return false; |
| 1327 | } |
| 1328 | |
| 1329 | /* shared DPLL id 0 is DPLL 1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1330 | crtc_state->ddi_pll_sel = pll->id + 1; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1331 | |
| 1332 | return true; |
| 1333 | } |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1334 | |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1335 | /* bxt clock parameters */ |
| 1336 | struct bxt_clk_div { |
| 1337 | uint32_t p1; |
| 1338 | uint32_t p2; |
| 1339 | uint32_t m2_int; |
| 1340 | uint32_t m2_frac; |
| 1341 | bool m2_frac_en; |
| 1342 | uint32_t n; |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1343 | uint32_t lanestagger; |
| 1344 | }; |
| 1345 | |
| 1346 | /* pre-calculated values for DP linkrates */ |
| 1347 | static struct bxt_clk_div bxt_dp_clk_val[7] = { |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 1348 | /* 162 */ {4, 2, 32, 1677722, 1, 1, 0xd}, |
| 1349 | /* 270 */ {4, 1, 27, 0, 0, 1, 0xd}, |
| 1350 | /* 540 */ {2, 1, 27, 0, 0, 1, 0x18}, |
| 1351 | /* 216 */ {3, 2, 32, 1677722, 1, 1, 0xd}, |
| 1352 | /* 243 */ {4, 1, 24, 1258291, 1, 1, 0xd}, |
| 1353 | /* 324 */ {4, 1, 32, 1677722, 1, 1, 0x18}, |
| 1354 | /* 432 */ {3, 1, 32, 1677722, 1, 1, 0x18} |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1355 | }; |
| 1356 | |
| 1357 | static bool |
| 1358 | bxt_ddi_pll_select(struct intel_crtc *intel_crtc, |
| 1359 | struct intel_crtc_state *crtc_state, |
| 1360 | struct intel_encoder *intel_encoder, |
| 1361 | int clock) |
| 1362 | { |
| 1363 | struct intel_shared_dpll *pll; |
| 1364 | struct bxt_clk_div clk_div = {0}; |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 1365 | int vco = 0; |
| 1366 | uint32_t prop_coef, int_coef, gain_ctl, targ_cnt; |
| 1367 | uint32_t dcoampovr_en_h, dco_amp; |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1368 | |
| 1369 | if (intel_encoder->type == INTEL_OUTPUT_HDMI) { |
| 1370 | intel_clock_t best_clock; |
| 1371 | |
| 1372 | /* Calculate HDMI div */ |
| 1373 | /* |
| 1374 | * FIXME: tie the following calculation into |
| 1375 | * i9xx_crtc_compute_clock |
| 1376 | */ |
| 1377 | if (!bxt_find_best_dpll(crtc_state, clock, &best_clock)) { |
| 1378 | DRM_DEBUG_DRIVER("no PLL dividers found for clock %d pipe %c\n", |
| 1379 | clock, pipe_name(intel_crtc->pipe)); |
| 1380 | return false; |
| 1381 | } |
| 1382 | |
| 1383 | clk_div.p1 = best_clock.p1; |
| 1384 | clk_div.p2 = best_clock.p2; |
| 1385 | WARN_ON(best_clock.m1 != 2); |
| 1386 | clk_div.n = best_clock.n; |
| 1387 | clk_div.m2_int = best_clock.m2 >> 22; |
| 1388 | clk_div.m2_frac = best_clock.m2 & ((1 << 22) - 1); |
| 1389 | clk_div.m2_frac_en = clk_div.m2_frac != 0; |
| 1390 | |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 1391 | vco = best_clock.vco; |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1392 | if (clock > 270000) |
| 1393 | clk_div.lanestagger = 0x18; |
| 1394 | else if (clock > 135000) |
| 1395 | clk_div.lanestagger = 0x0d; |
| 1396 | else if (clock > 67000) |
| 1397 | clk_div.lanestagger = 0x07; |
| 1398 | else if (clock > 33000) |
| 1399 | clk_div.lanestagger = 0x04; |
| 1400 | else |
| 1401 | clk_div.lanestagger = 0x02; |
| 1402 | } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT || |
| 1403 | intel_encoder->type == INTEL_OUTPUT_EDP) { |
| 1404 | struct drm_encoder *encoder = &intel_encoder->base; |
| 1405 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1406 | |
| 1407 | switch (intel_dp->link_bw) { |
| 1408 | case DP_LINK_BW_1_62: |
| 1409 | clk_div = bxt_dp_clk_val[0]; |
| 1410 | break; |
| 1411 | case DP_LINK_BW_2_7: |
| 1412 | clk_div = bxt_dp_clk_val[1]; |
| 1413 | break; |
| 1414 | case DP_LINK_BW_5_4: |
| 1415 | clk_div = bxt_dp_clk_val[2]; |
| 1416 | break; |
| 1417 | default: |
| 1418 | clk_div = bxt_dp_clk_val[0]; |
| 1419 | DRM_ERROR("Unknown link rate\n"); |
| 1420 | } |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 1421 | vco = clock * 10 / 2 * clk_div.p1 * clk_div.p2; |
| 1422 | } |
| 1423 | |
| 1424 | dco_amp = 15; |
| 1425 | dcoampovr_en_h = 0; |
| 1426 | if (vco >= 6200000 && vco <= 6480000) { |
| 1427 | prop_coef = 4; |
| 1428 | int_coef = 9; |
| 1429 | gain_ctl = 3; |
| 1430 | targ_cnt = 8; |
| 1431 | } else if ((vco > 5400000 && vco < 6200000) || |
| 1432 | (vco >= 4800000 && vco < 5400000)) { |
| 1433 | prop_coef = 5; |
| 1434 | int_coef = 11; |
| 1435 | gain_ctl = 3; |
| 1436 | targ_cnt = 9; |
| 1437 | if (vco >= 4800000 && vco < 5400000) |
| 1438 | dcoampovr_en_h = 1; |
| 1439 | } else if (vco == 5400000) { |
| 1440 | prop_coef = 3; |
| 1441 | int_coef = 8; |
| 1442 | gain_ctl = 1; |
| 1443 | targ_cnt = 9; |
| 1444 | } else { |
| 1445 | DRM_ERROR("Invalid VCO\n"); |
| 1446 | return false; |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1447 | } |
| 1448 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 1449 | memset(&crtc_state->dpll_hw_state, 0, |
| 1450 | sizeof(crtc_state->dpll_hw_state)); |
| 1451 | |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1452 | crtc_state->dpll_hw_state.ebb0 = |
| 1453 | PORT_PLL_P1(clk_div.p1) | PORT_PLL_P2(clk_div.p2); |
| 1454 | crtc_state->dpll_hw_state.pll0 = clk_div.m2_int; |
| 1455 | crtc_state->dpll_hw_state.pll1 = PORT_PLL_N(clk_div.n); |
| 1456 | crtc_state->dpll_hw_state.pll2 = clk_div.m2_frac; |
| 1457 | |
| 1458 | if (clk_div.m2_frac_en) |
| 1459 | crtc_state->dpll_hw_state.pll3 = |
| 1460 | PORT_PLL_M2_FRAC_ENABLE; |
| 1461 | |
| 1462 | crtc_state->dpll_hw_state.pll6 = |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 1463 | prop_coef | PORT_PLL_INT_COEFF(int_coef); |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1464 | crtc_state->dpll_hw_state.pll6 |= |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 1465 | PORT_PLL_GAIN_CTL(gain_ctl); |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1466 | |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 1467 | crtc_state->dpll_hw_state.pll8 = targ_cnt; |
| 1468 | |
| 1469 | if (dcoampovr_en_h) |
| 1470 | crtc_state->dpll_hw_state.pll10 = PORT_PLL_DCO_AMP_OVR_EN_H; |
| 1471 | |
| 1472 | crtc_state->dpll_hw_state.pll10 |= PORT_PLL_DCO_AMP(dco_amp); |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1473 | |
| 1474 | crtc_state->dpll_hw_state.pcsdw12 = |
| 1475 | LANESTAGGER_STRAP_OVRD | clk_div.lanestagger; |
| 1476 | |
| 1477 | pll = intel_get_shared_dpll(intel_crtc, crtc_state); |
| 1478 | if (pll == NULL) { |
| 1479 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 1480 | pipe_name(intel_crtc->pipe)); |
| 1481 | return false; |
| 1482 | } |
| 1483 | |
| 1484 | /* shared DPLL id 0 is DPLL A */ |
| 1485 | crtc_state->ddi_pll_sel = pll->id; |
| 1486 | |
| 1487 | return true; |
| 1488 | } |
| 1489 | |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1490 | /* |
| 1491 | * Tries to find a *shared* PLL for the CRTC and store it in |
| 1492 | * intel_crtc->ddi_pll_sel. |
| 1493 | * |
| 1494 | * For private DPLLs, compute_config() should do the selection for us. This |
| 1495 | * function should be folded into compute_config() eventually. |
| 1496 | */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1497 | bool intel_ddi_pll_select(struct intel_crtc *intel_crtc, |
| 1498 | struct intel_crtc_state *crtc_state) |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1499 | { |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1500 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 1501 | struct intel_encoder *intel_encoder = |
Ander Conselvan de Oliveira | 3165c07 | 2015-03-20 16:18:12 +0200 | [diff] [blame] | 1502 | intel_ddi_get_crtc_new_encoder(crtc_state); |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1503 | int clock = crtc_state->port_clock; |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1504 | |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1505 | if (IS_SKYLAKE(dev)) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1506 | return skl_ddi_pll_select(intel_crtc, crtc_state, |
| 1507 | intel_encoder, clock); |
Satheeshakrishna M | d683f3b | 2014-08-22 09:49:08 +0530 | [diff] [blame] | 1508 | else if (IS_BROXTON(dev)) |
| 1509 | return bxt_ddi_pll_select(intel_crtc, crtc_state, |
| 1510 | intel_encoder, clock); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1511 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1512 | return hsw_ddi_pll_select(intel_crtc, crtc_state, |
| 1513 | intel_encoder, clock); |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1514 | } |
| 1515 | |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1516 | void intel_ddi_set_pipe_settings(struct drm_crtc *crtc) |
| 1517 | { |
| 1518 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1519 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1520 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1521 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1522 | int type = intel_encoder->type; |
| 1523 | uint32_t temp; |
| 1524 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1525 | 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] | 1526 | temp = TRANS_MSA_SYNC_CLK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1527 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1528 | case 18: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1529 | temp |= TRANS_MSA_6_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1530 | break; |
| 1531 | case 24: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1532 | temp |= TRANS_MSA_8_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1533 | break; |
| 1534 | case 30: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1535 | temp |= TRANS_MSA_10_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1536 | break; |
| 1537 | case 36: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1538 | temp |= TRANS_MSA_12_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1539 | break; |
| 1540 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 1541 | BUG(); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1542 | } |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1543 | I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1544 | } |
| 1545 | } |
| 1546 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1547 | void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state) |
| 1548 | { |
| 1549 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1550 | struct drm_device *dev = crtc->dev; |
| 1551 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1552 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1553 | uint32_t temp; |
| 1554 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1555 | if (state == true) |
| 1556 | temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC; |
| 1557 | else |
| 1558 | temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC; |
| 1559 | I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); |
| 1560 | } |
| 1561 | |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 1562 | void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1563 | { |
| 1564 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1565 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1566 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 1567 | struct drm_device *dev = crtc->dev; |
| 1568 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1569 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1570 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1571 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1572 | int type = intel_encoder->type; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1573 | uint32_t temp; |
| 1574 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1575 | /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */ |
| 1576 | temp = TRANS_DDI_FUNC_ENABLE; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1577 | temp |= TRANS_DDI_SELECT_PORT(port); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1578 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1579 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1580 | case 18: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1581 | temp |= TRANS_DDI_BPC_6; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1582 | break; |
| 1583 | case 24: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1584 | temp |= TRANS_DDI_BPC_8; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1585 | break; |
| 1586 | case 30: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1587 | temp |= TRANS_DDI_BPC_10; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1588 | break; |
| 1589 | case 36: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1590 | temp |= TRANS_DDI_BPC_12; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1591 | break; |
| 1592 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 1593 | BUG(); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1594 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1595 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1596 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1597 | temp |= TRANS_DDI_PVSYNC; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1598 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1599 | temp |= TRANS_DDI_PHSYNC; |
Paulo Zanoni | f63eb7c4 | 2012-08-08 14:15:28 -0300 | [diff] [blame] | 1600 | |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 1601 | if (cpu_transcoder == TRANSCODER_EDP) { |
| 1602 | switch (pipe) { |
| 1603 | case PIPE_A: |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 1604 | /* On Haswell, can only use the always-on power well for |
| 1605 | * eDP when not using the panel fitter, and when not |
| 1606 | * using motion blur mitigation (which we don't |
| 1607 | * support). */ |
Daniel Vetter | fabf6e5 | 2014-05-29 14:10:22 +0200 | [diff] [blame] | 1608 | if (IS_HASWELL(dev) && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1609 | (intel_crtc->config->pch_pfit.enabled || |
| 1610 | intel_crtc->config->pch_pfit.force_thru)) |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 1611 | temp |= TRANS_DDI_EDP_INPUT_A_ONOFF; |
| 1612 | else |
| 1613 | temp |= TRANS_DDI_EDP_INPUT_A_ON; |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 1614 | break; |
| 1615 | case PIPE_B: |
| 1616 | temp |= TRANS_DDI_EDP_INPUT_B_ONOFF; |
| 1617 | break; |
| 1618 | case PIPE_C: |
| 1619 | temp |= TRANS_DDI_EDP_INPUT_C_ONOFF; |
| 1620 | break; |
| 1621 | default: |
| 1622 | BUG(); |
| 1623 | break; |
| 1624 | } |
| 1625 | } |
| 1626 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1627 | if (type == INTEL_OUTPUT_HDMI) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1628 | if (intel_crtc->config->has_hdmi_sink) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1629 | temp |= TRANS_DDI_MODE_SELECT_HDMI; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1630 | else |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1631 | temp |= TRANS_DDI_MODE_SELECT_DVI; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1632 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1633 | } else if (type == INTEL_OUTPUT_ANALOG) { |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1634 | temp |= TRANS_DDI_MODE_SELECT_FDI; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1635 | temp |= (intel_crtc->config->fdi_lanes - 1) << 1; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1636 | |
| 1637 | } else if (type == INTEL_OUTPUT_DISPLAYPORT || |
| 1638 | type == INTEL_OUTPUT_EDP) { |
| 1639 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1640 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1641 | if (intel_dp->is_mst) { |
| 1642 | temp |= TRANS_DDI_MODE_SELECT_DP_MST; |
| 1643 | } else |
| 1644 | temp |= TRANS_DDI_MODE_SELECT_DP_SST; |
| 1645 | |
| 1646 | temp |= DDI_PORT_WIDTH(intel_dp->lane_count); |
| 1647 | } else if (type == INTEL_OUTPUT_DP_MST) { |
| 1648 | struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp; |
| 1649 | |
| 1650 | if (intel_dp->is_mst) { |
| 1651 | temp |= TRANS_DDI_MODE_SELECT_DP_MST; |
| 1652 | } else |
| 1653 | temp |= TRANS_DDI_MODE_SELECT_DP_SST; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1654 | |
Daniel Vetter | 17aa6be | 2013-04-30 14:01:40 +0200 | [diff] [blame] | 1655 | temp |= DDI_PORT_WIDTH(intel_dp->lane_count); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1656 | } else { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1657 | WARN(1, "Invalid encoder type %d for pipe %c\n", |
| 1658 | intel_encoder->type, pipe_name(pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1659 | } |
| 1660 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1661 | I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1662 | } |
| 1663 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1664 | void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv, |
| 1665 | enum transcoder cpu_transcoder) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1666 | { |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1667 | uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1668 | uint32_t val = I915_READ(reg); |
| 1669 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1670 | 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] | 1671 | val |= TRANS_DDI_PORT_NONE; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1672 | I915_WRITE(reg, val); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1673 | } |
| 1674 | |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1675 | bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector) |
| 1676 | { |
| 1677 | struct drm_device *dev = intel_connector->base.dev; |
| 1678 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1679 | struct intel_encoder *intel_encoder = intel_connector->encoder; |
| 1680 | int type = intel_connector->base.connector_type; |
| 1681 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1682 | enum pipe pipe = 0; |
| 1683 | enum transcoder cpu_transcoder; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1684 | enum intel_display_power_domain power_domain; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1685 | uint32_t tmp; |
| 1686 | |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1687 | power_domain = intel_display_port_power_domain(intel_encoder); |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1688 | if (!intel_display_power_is_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1689 | return false; |
| 1690 | |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1691 | if (!intel_encoder->get_hw_state(intel_encoder, &pipe)) |
| 1692 | return false; |
| 1693 | |
| 1694 | if (port == PORT_A) |
| 1695 | cpu_transcoder = TRANSCODER_EDP; |
| 1696 | else |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1697 | cpu_transcoder = (enum transcoder) pipe; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1698 | |
| 1699 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1700 | |
| 1701 | switch (tmp & TRANS_DDI_MODE_SELECT_MASK) { |
| 1702 | case TRANS_DDI_MODE_SELECT_HDMI: |
| 1703 | case TRANS_DDI_MODE_SELECT_DVI: |
| 1704 | return (type == DRM_MODE_CONNECTOR_HDMIA); |
| 1705 | |
| 1706 | case TRANS_DDI_MODE_SELECT_DP_SST: |
| 1707 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 1708 | return true; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1709 | return (type == DRM_MODE_CONNECTOR_DisplayPort); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1710 | case TRANS_DDI_MODE_SELECT_DP_MST: |
| 1711 | /* if the transcoder is in MST state then |
| 1712 | * connector isn't connected */ |
| 1713 | return false; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1714 | |
| 1715 | case TRANS_DDI_MODE_SELECT_FDI: |
| 1716 | return (type == DRM_MODE_CONNECTOR_VGA); |
| 1717 | |
| 1718 | default: |
| 1719 | return false; |
| 1720 | } |
| 1721 | } |
| 1722 | |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1723 | bool intel_ddi_get_hw_state(struct intel_encoder *encoder, |
| 1724 | enum pipe *pipe) |
| 1725 | { |
| 1726 | struct drm_device *dev = encoder->base.dev; |
| 1727 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1728 | enum port port = intel_ddi_get_encoder_port(encoder); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1729 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1730 | u32 tmp; |
| 1731 | int i; |
| 1732 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1733 | power_domain = intel_display_port_power_domain(encoder); |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1734 | if (!intel_display_power_is_enabled(dev_priv, power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1735 | return false; |
| 1736 | |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1737 | tmp = I915_READ(DDI_BUF_CTL(port)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1738 | |
| 1739 | if (!(tmp & DDI_BUF_CTL_ENABLE)) |
| 1740 | return false; |
| 1741 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1742 | if (port == PORT_A) { |
| 1743 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1744 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1745 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 1746 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 1747 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 1748 | *pipe = PIPE_A; |
| 1749 | break; |
| 1750 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 1751 | *pipe = PIPE_B; |
| 1752 | break; |
| 1753 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 1754 | *pipe = PIPE_C; |
| 1755 | break; |
| 1756 | } |
| 1757 | |
| 1758 | return true; |
| 1759 | } else { |
| 1760 | for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) { |
| 1761 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(i)); |
| 1762 | |
| 1763 | if ((tmp & TRANS_DDI_PORT_MASK) |
| 1764 | == TRANS_DDI_SELECT_PORT(port)) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1765 | if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST) |
| 1766 | return false; |
| 1767 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1768 | *pipe = i; |
| 1769 | return true; |
| 1770 | } |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1771 | } |
| 1772 | } |
| 1773 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1774 | 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] | 1775 | |
Jesse Barnes | 22f9fe5 | 2013-04-02 10:03:55 -0700 | [diff] [blame] | 1776 | return false; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1777 | } |
| 1778 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1779 | void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1780 | { |
| 1781 | struct drm_crtc *crtc = &intel_crtc->base; |
| 1782 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1783 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 1784 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1785 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1786 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1787 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1788 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1789 | TRANS_CLK_SEL_PORT(port)); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1793 | { |
| 1794 | struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1795 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1796 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1797 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1798 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1799 | TRANS_CLK_SEL_DISABLED); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1800 | } |
| 1801 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1802 | void bxt_ddi_vswing_sequence(struct drm_device *dev, u32 level, |
| 1803 | enum port port, int type) |
| 1804 | { |
| 1805 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1806 | const struct bxt_ddi_buf_trans *ddi_translations; |
| 1807 | u32 n_entries, i; |
| 1808 | uint32_t val; |
| 1809 | |
| 1810 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
| 1811 | n_entries = ARRAY_SIZE(bxt_ddi_translations_dp); |
| 1812 | ddi_translations = bxt_ddi_translations_dp; |
| 1813 | } else if (type == INTEL_OUTPUT_HDMI) { |
| 1814 | n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi); |
| 1815 | ddi_translations = bxt_ddi_translations_hdmi; |
| 1816 | } else { |
| 1817 | DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n", |
| 1818 | type); |
| 1819 | return; |
| 1820 | } |
| 1821 | |
| 1822 | /* Check if default value has to be used */ |
| 1823 | if (level >= n_entries || |
| 1824 | (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) { |
| 1825 | for (i = 0; i < n_entries; i++) { |
| 1826 | if (ddi_translations[i].default_index) { |
| 1827 | level = i; |
| 1828 | break; |
| 1829 | } |
| 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | /* |
| 1834 | * While we write to the group register to program all lanes at once we |
| 1835 | * can read only lane registers and we pick lanes 0/1 for that. |
| 1836 | */ |
| 1837 | val = I915_READ(BXT_PORT_PCS_DW10_LN01(port)); |
| 1838 | val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT); |
| 1839 | I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val); |
| 1840 | |
| 1841 | val = I915_READ(BXT_PORT_TX_DW2_LN0(port)); |
| 1842 | val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE); |
| 1843 | val |= ddi_translations[level].margin << MARGIN_000_SHIFT | |
| 1844 | ddi_translations[level].scale << UNIQ_TRANS_SCALE_SHIFT; |
| 1845 | I915_WRITE(BXT_PORT_TX_DW2_GRP(port), val); |
| 1846 | |
| 1847 | val = I915_READ(BXT_PORT_TX_DW3_LN0(port)); |
| 1848 | val &= ~UNIQE_TRANGE_EN_METHOD; |
| 1849 | if (ddi_translations[level].enable) |
| 1850 | val |= UNIQE_TRANGE_EN_METHOD; |
| 1851 | I915_WRITE(BXT_PORT_TX_DW3_GRP(port), val); |
| 1852 | |
| 1853 | val = I915_READ(BXT_PORT_TX_DW4_LN0(port)); |
| 1854 | val &= ~DE_EMPHASIS; |
| 1855 | val |= ddi_translations[level].deemphasis << DEEMPH_SHIFT; |
| 1856 | I915_WRITE(BXT_PORT_TX_DW4_GRP(port), val); |
| 1857 | |
| 1858 | val = I915_READ(BXT_PORT_PCS_DW10_LN01(port)); |
| 1859 | val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT; |
| 1860 | I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val); |
| 1861 | } |
| 1862 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1863 | static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1864 | { |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1865 | struct drm_encoder *encoder = &intel_encoder->base; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1866 | struct drm_device *dev = encoder->dev; |
| 1867 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1868 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1869 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1870 | int type = intel_encoder->type; |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1871 | int hdmi_level; |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1872 | |
| 1873 | if (type == INTEL_OUTPUT_EDP) { |
| 1874 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1875 | intel_edp_panel_on(intel_dp); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1876 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1877 | |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1878 | if (IS_SKYLAKE(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1879 | uint32_t dpll = crtc->config->ddi_pll_sel; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1880 | uint32_t val; |
| 1881 | |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1882 | /* |
| 1883 | * DPLL0 is used for eDP and is the only "private" DPLL (as |
| 1884 | * opposed to shared) on SKL |
| 1885 | */ |
| 1886 | if (type == INTEL_OUTPUT_EDP) { |
| 1887 | WARN_ON(dpll != SKL_DPLL0); |
| 1888 | |
| 1889 | val = I915_READ(DPLL_CTRL1); |
| 1890 | |
| 1891 | val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) | |
| 1892 | DPLL_CTRL1_SSC(dpll) | |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 1893 | DPLL_CTRL1_LINK_RATE_MASK(dpll)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1894 | val |= crtc->config->dpll_hw_state.ctrl1 << (dpll * 6); |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1895 | |
| 1896 | I915_WRITE(DPLL_CTRL1, val); |
| 1897 | POSTING_READ(DPLL_CTRL1); |
| 1898 | } |
| 1899 | |
| 1900 | /* DDI -> PLL mapping */ |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1901 | val = I915_READ(DPLL_CTRL2); |
| 1902 | |
| 1903 | val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) | |
| 1904 | DPLL_CTRL2_DDI_CLK_SEL_MASK(port)); |
| 1905 | val |= (DPLL_CTRL2_DDI_CLK_SEL(dpll, port) | |
| 1906 | DPLL_CTRL2_DDI_SEL_OVERRIDE(port)); |
| 1907 | |
| 1908 | I915_WRITE(DPLL_CTRL2, val); |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1909 | |
Satheeshakrishna M | 1ab2338 | 2014-08-22 09:49:06 +0530 | [diff] [blame] | 1910 | } else if (INTEL_INFO(dev)->gen < 9) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1911 | WARN_ON(crtc->config->ddi_pll_sel == PORT_CLK_SEL_NONE); |
| 1912 | I915_WRITE(PORT_CLK_SEL(port), crtc->config->ddi_pll_sel); |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1913 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1914 | |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1915 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1916 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1917 | |
Dave Airlie | 44905a27 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 1918 | intel_ddi_init_dp_buf_reg(intel_encoder); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1919 | |
| 1920 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 1921 | intel_dp_start_link_train(intel_dp); |
| 1922 | intel_dp_complete_link_train(intel_dp); |
Vandana Kannan | 23f08d8 | 2014-11-13 14:55:22 +0000 | [diff] [blame] | 1923 | if (port != PORT_A || INTEL_INFO(dev)->gen >= 9) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 1924 | intel_dp_stop_link_train(intel_dp); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1925 | } else if (type == INTEL_OUTPUT_HDMI) { |
| 1926 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 1927 | |
Vandana Kannan | 96fb9f9 | 2014-11-18 15:45:27 +0530 | [diff] [blame] | 1928 | if (IS_BROXTON(dev)) { |
| 1929 | hdmi_level = dev_priv->vbt. |
| 1930 | ddi_port_info[port].hdmi_level_shift; |
| 1931 | bxt_ddi_vswing_sequence(dev, hdmi_level, port, |
| 1932 | INTEL_OUTPUT_HDMI); |
| 1933 | } |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1934 | intel_hdmi->set_infoframes(encoder, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1935 | crtc->config->has_hdmi_sink, |
| 1936 | &crtc->config->base.adjusted_mode); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1937 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1938 | } |
| 1939 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1940 | static void intel_ddi_post_disable(struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1941 | { |
| 1942 | struct drm_encoder *encoder = &intel_encoder->base; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1943 | struct drm_device *dev = encoder->dev; |
| 1944 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1945 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1946 | int type = intel_encoder->type; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1947 | uint32_t val; |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1948 | bool wait = false; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1949 | |
| 1950 | val = I915_READ(DDI_BUF_CTL(port)); |
| 1951 | if (val & DDI_BUF_CTL_ENABLE) { |
| 1952 | val &= ~DDI_BUF_CTL_ENABLE; |
| 1953 | I915_WRITE(DDI_BUF_CTL(port), val); |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1954 | wait = true; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1955 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1956 | |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1957 | val = I915_READ(DP_TP_CTL(port)); |
| 1958 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 1959 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 1960 | I915_WRITE(DP_TP_CTL(port), val); |
| 1961 | |
| 1962 | if (wait) |
| 1963 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 1964 | |
Jani Nikula | 76bb80e | 2013-11-15 15:29:57 +0200 | [diff] [blame] | 1965 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1966 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Jani Nikula | 76bb80e | 2013-11-15 15:29:57 +0200 | [diff] [blame] | 1967 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 1968 | intel_edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1969 | intel_edp_panel_off(intel_dp); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1970 | } |
| 1971 | |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1972 | if (IS_SKYLAKE(dev)) |
| 1973 | I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) | |
| 1974 | DPLL_CTRL2_DDI_CLK_OFF(port))); |
Satheeshakrishna M | 1ab2338 | 2014-08-22 09:49:06 +0530 | [diff] [blame] | 1975 | else if (INTEL_INFO(dev)->gen < 9) |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1976 | I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1977 | } |
| 1978 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1979 | static void intel_enable_ddi(struct intel_encoder *intel_encoder) |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1980 | { |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1981 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1982 | struct drm_crtc *crtc = encoder->crtc; |
| 1983 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1984 | struct drm_device *dev = encoder->dev; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1985 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1986 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1987 | int type = intel_encoder->type; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1988 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1989 | if (type == INTEL_OUTPUT_HDMI) { |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1990 | struct intel_digital_port *intel_dig_port = |
| 1991 | enc_to_dig_port(encoder); |
| 1992 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1993 | /* In HDMI/DVI mode, the port width, and swing/emphasis values |
| 1994 | * are ignored so nothing special needs to be done besides |
| 1995 | * enabling the port. |
| 1996 | */ |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1997 | I915_WRITE(DDI_BUF_CTL(port), |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 1998 | intel_dig_port->saved_port_bits | |
| 1999 | DDI_BUF_CTL_ENABLE); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 2000 | } else if (type == INTEL_OUTPUT_EDP) { |
| 2001 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 2002 | |
Vandana Kannan | 23f08d8 | 2014-11-13 14:55:22 +0000 | [diff] [blame] | 2003 | if (port == PORT_A && INTEL_INFO(dev)->gen < 9) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 2004 | intel_dp_stop_link_train(intel_dp); |
| 2005 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2006 | intel_edp_backlight_on(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 2007 | intel_psr_enable(intel_dp); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 2008 | intel_edp_drrs_enable(intel_dp); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 2009 | } |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 2010 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2011 | if (intel_crtc->config->has_audio) { |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 2012 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 2013 | intel_audio_codec_enable(intel_encoder); |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 2014 | } |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 2015 | } |
| 2016 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2017 | static void intel_disable_ddi(struct intel_encoder *intel_encoder) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 2018 | { |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 2019 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 2020 | struct drm_crtc *crtc = encoder->crtc; |
| 2021 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 2022 | int type = intel_encoder->type; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 2023 | struct drm_device *dev = encoder->dev; |
| 2024 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 2025 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2026 | if (intel_crtc->config->has_audio) { |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 2027 | intel_audio_codec_disable(intel_encoder); |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 2028 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
| 2029 | } |
Paulo Zanoni | 2831d842 | 2013-03-06 20:03:09 -0300 | [diff] [blame] | 2030 | |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 2031 | if (type == INTEL_OUTPUT_EDP) { |
| 2032 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 2033 | |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 2034 | intel_edp_drrs_disable(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 2035 | intel_psr_disable(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 2036 | intel_edp_backlight_off(intel_dp); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 2037 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 2038 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 2039 | |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 2040 | static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv, |
| 2041 | struct intel_shared_dpll *pll) |
| 2042 | { |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 2043 | I915_WRITE(WRPLL_CTL(pll->id), pll->config.hw_state.wrpll); |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 2044 | POSTING_READ(WRPLL_CTL(pll->id)); |
| 2045 | udelay(20); |
| 2046 | } |
| 2047 | |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 2048 | static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv, |
| 2049 | struct intel_shared_dpll *pll) |
| 2050 | { |
| 2051 | uint32_t val; |
| 2052 | |
| 2053 | val = I915_READ(WRPLL_CTL(pll->id)); |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 2054 | I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE); |
| 2055 | POSTING_READ(WRPLL_CTL(pll->id)); |
| 2056 | } |
| 2057 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 2058 | static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, |
| 2059 | struct intel_shared_dpll *pll, |
| 2060 | struct intel_dpll_hw_state *hw_state) |
| 2061 | { |
| 2062 | uint32_t val; |
| 2063 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 2064 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 2065 | return false; |
| 2066 | |
| 2067 | val = I915_READ(WRPLL_CTL(pll->id)); |
| 2068 | hw_state->wrpll = val; |
| 2069 | |
| 2070 | return val & WRPLL_PLL_ENABLE; |
| 2071 | } |
| 2072 | |
Damien Lespiau | ca1381b | 2014-07-15 15:05:33 +0100 | [diff] [blame] | 2073 | static const char * const hsw_ddi_pll_names[] = { |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 2074 | "WRPLL 1", |
| 2075 | "WRPLL 2", |
| 2076 | }; |
| 2077 | |
Damien Lespiau | 143b307 | 2014-07-29 18:06:19 +0100 | [diff] [blame] | 2078 | static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 2079 | { |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 2080 | int i; |
| 2081 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 2082 | dev_priv->num_shared_dpll = 2; |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 2083 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 2084 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 2085 | dev_priv->shared_dplls[i].id = i; |
| 2086 | dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i]; |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 2087 | dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable; |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 2088 | dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 2089 | dev_priv->shared_dplls[i].get_hw_state = |
| 2090 | hsw_ddi_pll_get_hw_state; |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 2091 | } |
Damien Lespiau | 143b307 | 2014-07-29 18:06:19 +0100 | [diff] [blame] | 2092 | } |
| 2093 | |
Satheeshakrishna M | d1a2dc7 | 2014-11-13 14:55:18 +0000 | [diff] [blame] | 2094 | static const char * const skl_ddi_pll_names[] = { |
| 2095 | "DPLL 1", |
| 2096 | "DPLL 2", |
| 2097 | "DPLL 3", |
| 2098 | }; |
| 2099 | |
| 2100 | struct skl_dpll_regs { |
| 2101 | u32 ctl, cfgcr1, cfgcr2; |
| 2102 | }; |
| 2103 | |
| 2104 | /* this array is indexed by the *shared* pll id */ |
| 2105 | static const struct skl_dpll_regs skl_dpll_regs[3] = { |
| 2106 | { |
| 2107 | /* DPLL 1 */ |
| 2108 | .ctl = LCPLL2_CTL, |
| 2109 | .cfgcr1 = DPLL1_CFGCR1, |
| 2110 | .cfgcr2 = DPLL1_CFGCR2, |
| 2111 | }, |
| 2112 | { |
| 2113 | /* DPLL 2 */ |
| 2114 | .ctl = WRPLL_CTL1, |
| 2115 | .cfgcr1 = DPLL2_CFGCR1, |
| 2116 | .cfgcr2 = DPLL2_CFGCR2, |
| 2117 | }, |
| 2118 | { |
| 2119 | /* DPLL 3 */ |
| 2120 | .ctl = WRPLL_CTL2, |
| 2121 | .cfgcr1 = DPLL3_CFGCR1, |
| 2122 | .cfgcr2 = DPLL3_CFGCR2, |
| 2123 | }, |
| 2124 | }; |
| 2125 | |
| 2126 | static void skl_ddi_pll_enable(struct drm_i915_private *dev_priv, |
| 2127 | struct intel_shared_dpll *pll) |
| 2128 | { |
| 2129 | uint32_t val; |
| 2130 | unsigned int dpll; |
| 2131 | const struct skl_dpll_regs *regs = skl_dpll_regs; |
| 2132 | |
| 2133 | /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */ |
| 2134 | dpll = pll->id + 1; |
| 2135 | |
| 2136 | val = I915_READ(DPLL_CTRL1); |
| 2137 | |
| 2138 | val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) | DPLL_CTRL1_SSC(dpll) | |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 2139 | DPLL_CTRL1_LINK_RATE_MASK(dpll)); |
Satheeshakrishna M | d1a2dc7 | 2014-11-13 14:55:18 +0000 | [diff] [blame] | 2140 | val |= pll->config.hw_state.ctrl1 << (dpll * 6); |
| 2141 | |
| 2142 | I915_WRITE(DPLL_CTRL1, val); |
| 2143 | POSTING_READ(DPLL_CTRL1); |
| 2144 | |
| 2145 | I915_WRITE(regs[pll->id].cfgcr1, pll->config.hw_state.cfgcr1); |
| 2146 | I915_WRITE(regs[pll->id].cfgcr2, pll->config.hw_state.cfgcr2); |
| 2147 | POSTING_READ(regs[pll->id].cfgcr1); |
| 2148 | POSTING_READ(regs[pll->id].cfgcr2); |
| 2149 | |
| 2150 | /* the enable bit is always bit 31 */ |
| 2151 | I915_WRITE(regs[pll->id].ctl, |
| 2152 | I915_READ(regs[pll->id].ctl) | LCPLL_PLL_ENABLE); |
| 2153 | |
| 2154 | if (wait_for(I915_READ(DPLL_STATUS) & DPLL_LOCK(dpll), 5)) |
| 2155 | DRM_ERROR("DPLL %d not locked\n", dpll); |
| 2156 | } |
| 2157 | |
| 2158 | static void skl_ddi_pll_disable(struct drm_i915_private *dev_priv, |
| 2159 | struct intel_shared_dpll *pll) |
| 2160 | { |
| 2161 | const struct skl_dpll_regs *regs = skl_dpll_regs; |
| 2162 | |
| 2163 | /* the enable bit is always bit 31 */ |
| 2164 | I915_WRITE(regs[pll->id].ctl, |
| 2165 | I915_READ(regs[pll->id].ctl) & ~LCPLL_PLL_ENABLE); |
| 2166 | POSTING_READ(regs[pll->id].ctl); |
| 2167 | } |
| 2168 | |
| 2169 | static bool skl_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, |
| 2170 | struct intel_shared_dpll *pll, |
| 2171 | struct intel_dpll_hw_state *hw_state) |
| 2172 | { |
| 2173 | uint32_t val; |
| 2174 | unsigned int dpll; |
| 2175 | const struct skl_dpll_regs *regs = skl_dpll_regs; |
| 2176 | |
| 2177 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
| 2178 | return false; |
| 2179 | |
| 2180 | /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */ |
| 2181 | dpll = pll->id + 1; |
| 2182 | |
| 2183 | val = I915_READ(regs[pll->id].ctl); |
| 2184 | if (!(val & LCPLL_PLL_ENABLE)) |
| 2185 | return false; |
| 2186 | |
| 2187 | val = I915_READ(DPLL_CTRL1); |
| 2188 | hw_state->ctrl1 = (val >> (dpll * 6)) & 0x3f; |
| 2189 | |
| 2190 | /* avoid reading back stale values if HDMI mode is not enabled */ |
| 2191 | if (val & DPLL_CTRL1_HDMI_MODE(dpll)) { |
| 2192 | hw_state->cfgcr1 = I915_READ(regs[pll->id].cfgcr1); |
| 2193 | hw_state->cfgcr2 = I915_READ(regs[pll->id].cfgcr2); |
| 2194 | } |
| 2195 | |
| 2196 | return true; |
| 2197 | } |
| 2198 | |
| 2199 | static void skl_shared_dplls_init(struct drm_i915_private *dev_priv) |
| 2200 | { |
| 2201 | int i; |
| 2202 | |
| 2203 | dev_priv->num_shared_dpll = 3; |
| 2204 | |
| 2205 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 2206 | dev_priv->shared_dplls[i].id = i; |
| 2207 | dev_priv->shared_dplls[i].name = skl_ddi_pll_names[i]; |
| 2208 | dev_priv->shared_dplls[i].disable = skl_ddi_pll_disable; |
| 2209 | dev_priv->shared_dplls[i].enable = skl_ddi_pll_enable; |
| 2210 | dev_priv->shared_dplls[i].get_hw_state = |
| 2211 | skl_ddi_pll_get_hw_state; |
| 2212 | } |
| 2213 | } |
| 2214 | |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 2215 | static void broxton_phy_init(struct drm_i915_private *dev_priv, |
| 2216 | enum dpio_phy phy) |
| 2217 | { |
| 2218 | enum port port; |
| 2219 | uint32_t val; |
| 2220 | |
| 2221 | val = I915_READ(BXT_P_CR_GT_DISP_PWRON); |
| 2222 | val |= GT_DISPLAY_POWER_ON(phy); |
| 2223 | I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val); |
| 2224 | |
| 2225 | /* Considering 10ms timeout until BSpec is updated */ |
| 2226 | if (wait_for(I915_READ(BXT_PORT_CL1CM_DW0(phy)) & PHY_POWER_GOOD, 10)) |
| 2227 | DRM_ERROR("timeout during PHY%d power on\n", phy); |
| 2228 | |
| 2229 | for (port = (phy == DPIO_PHY0 ? PORT_B : PORT_A); |
| 2230 | port <= (phy == DPIO_PHY0 ? PORT_C : PORT_A); port++) { |
| 2231 | int lane; |
| 2232 | |
| 2233 | for (lane = 0; lane < 4; lane++) { |
| 2234 | val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane)); |
| 2235 | /* |
| 2236 | * Note that on CHV this flag is called UPAR, but has |
| 2237 | * the same function. |
| 2238 | */ |
| 2239 | val &= ~LATENCY_OPTIM; |
| 2240 | if (lane != 1) |
| 2241 | val |= LATENCY_OPTIM; |
| 2242 | |
| 2243 | I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val); |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | /* Program PLL Rcomp code offset */ |
| 2248 | val = I915_READ(BXT_PORT_CL1CM_DW9(phy)); |
| 2249 | val &= ~IREF0RC_OFFSET_MASK; |
| 2250 | val |= 0xE4 << IREF0RC_OFFSET_SHIFT; |
| 2251 | I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val); |
| 2252 | |
| 2253 | val = I915_READ(BXT_PORT_CL1CM_DW10(phy)); |
| 2254 | val &= ~IREF1RC_OFFSET_MASK; |
| 2255 | val |= 0xE4 << IREF1RC_OFFSET_SHIFT; |
| 2256 | I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val); |
| 2257 | |
| 2258 | /* Program power gating */ |
| 2259 | val = I915_READ(BXT_PORT_CL1CM_DW28(phy)); |
| 2260 | val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN | |
| 2261 | SUS_CLK_CONFIG; |
| 2262 | I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val); |
| 2263 | |
| 2264 | if (phy == DPIO_PHY0) { |
| 2265 | val = I915_READ(BXT_PORT_CL2CM_DW6_BC); |
| 2266 | val |= DW6_OLDO_DYN_PWR_DOWN_EN; |
| 2267 | I915_WRITE(BXT_PORT_CL2CM_DW6_BC, val); |
| 2268 | } |
| 2269 | |
| 2270 | val = I915_READ(BXT_PORT_CL1CM_DW30(phy)); |
| 2271 | val &= ~OCL2_LDOFUSE_PWR_DIS; |
| 2272 | /* |
| 2273 | * On PHY1 disable power on the second channel, since no port is |
| 2274 | * connected there. On PHY0 both channels have a port, so leave it |
| 2275 | * enabled. |
| 2276 | * TODO: port C is only connected on BXT-P, so on BXT0/1 we should |
| 2277 | * power down the second channel on PHY0 as well. |
| 2278 | */ |
| 2279 | if (phy == DPIO_PHY1) |
| 2280 | val |= OCL2_LDOFUSE_PWR_DIS; |
| 2281 | I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val); |
| 2282 | |
| 2283 | if (phy == DPIO_PHY0) { |
| 2284 | uint32_t grc_code; |
| 2285 | /* |
| 2286 | * PHY0 isn't connected to an RCOMP resistor so copy over |
| 2287 | * the corresponding calibrated value from PHY1, and disable |
| 2288 | * the automatic calibration on PHY0. |
| 2289 | */ |
| 2290 | if (wait_for(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE, |
| 2291 | 10)) |
| 2292 | DRM_ERROR("timeout waiting for PHY1 GRC\n"); |
| 2293 | |
| 2294 | val = I915_READ(BXT_PORT_REF_DW6(DPIO_PHY1)); |
| 2295 | val = (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT; |
| 2296 | grc_code = val << GRC_CODE_FAST_SHIFT | |
| 2297 | val << GRC_CODE_SLOW_SHIFT | |
| 2298 | val; |
| 2299 | I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code); |
| 2300 | |
| 2301 | val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0)); |
| 2302 | val |= GRC_DIS | GRC_RDY_OVRD; |
| 2303 | I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val); |
| 2304 | } |
| 2305 | |
| 2306 | val = I915_READ(BXT_PHY_CTL_FAMILY(phy)); |
| 2307 | val |= COMMON_RESET_DIS; |
| 2308 | I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val); |
| 2309 | } |
| 2310 | |
| 2311 | void broxton_ddi_phy_init(struct drm_device *dev) |
| 2312 | { |
| 2313 | /* Enable PHY1 first since it provides Rcomp for PHY0 */ |
| 2314 | broxton_phy_init(dev->dev_private, DPIO_PHY1); |
| 2315 | broxton_phy_init(dev->dev_private, DPIO_PHY0); |
| 2316 | } |
| 2317 | |
| 2318 | static void broxton_phy_uninit(struct drm_i915_private *dev_priv, |
| 2319 | enum dpio_phy phy) |
| 2320 | { |
| 2321 | uint32_t val; |
| 2322 | |
| 2323 | val = I915_READ(BXT_PHY_CTL_FAMILY(phy)); |
| 2324 | val &= ~COMMON_RESET_DIS; |
| 2325 | I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val); |
| 2326 | } |
| 2327 | |
| 2328 | void broxton_ddi_phy_uninit(struct drm_device *dev) |
| 2329 | { |
| 2330 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2331 | |
| 2332 | broxton_phy_uninit(dev_priv, DPIO_PHY1); |
| 2333 | broxton_phy_uninit(dev_priv, DPIO_PHY0); |
| 2334 | |
| 2335 | /* FIXME: do this in broxton_phy_uninit per phy */ |
| 2336 | I915_WRITE(BXT_P_CR_GT_DISP_PWRON, 0); |
| 2337 | } |
| 2338 | |
Satheeshakrishna M | dfb8240 | 2014-08-22 09:49:09 +0530 | [diff] [blame] | 2339 | static const char * const bxt_ddi_pll_names[] = { |
| 2340 | "PORT PLL A", |
| 2341 | "PORT PLL B", |
| 2342 | "PORT PLL C", |
| 2343 | }; |
| 2344 | |
| 2345 | static void bxt_ddi_pll_enable(struct drm_i915_private *dev_priv, |
| 2346 | struct intel_shared_dpll *pll) |
| 2347 | { |
| 2348 | uint32_t temp; |
| 2349 | enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */ |
| 2350 | |
| 2351 | temp = I915_READ(BXT_PORT_PLL_ENABLE(port)); |
| 2352 | temp &= ~PORT_PLL_REF_SEL; |
| 2353 | /* Non-SSC reference */ |
| 2354 | I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp); |
| 2355 | |
| 2356 | /* Disable 10 bit clock */ |
| 2357 | temp = I915_READ(BXT_PORT_PLL_EBB_4(port)); |
| 2358 | temp &= ~PORT_PLL_10BIT_CLK_ENABLE; |
| 2359 | I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp); |
| 2360 | |
| 2361 | /* Write P1 & P2 */ |
| 2362 | temp = I915_READ(BXT_PORT_PLL_EBB_0(port)); |
| 2363 | temp &= ~(PORT_PLL_P1_MASK | PORT_PLL_P2_MASK); |
| 2364 | temp |= pll->config.hw_state.ebb0; |
| 2365 | I915_WRITE(BXT_PORT_PLL_EBB_0(port), temp); |
| 2366 | |
| 2367 | /* Write M2 integer */ |
| 2368 | temp = I915_READ(BXT_PORT_PLL(port, 0)); |
| 2369 | temp &= ~PORT_PLL_M2_MASK; |
| 2370 | temp |= pll->config.hw_state.pll0; |
| 2371 | I915_WRITE(BXT_PORT_PLL(port, 0), temp); |
| 2372 | |
| 2373 | /* Write N */ |
| 2374 | temp = I915_READ(BXT_PORT_PLL(port, 1)); |
| 2375 | temp &= ~PORT_PLL_N_MASK; |
| 2376 | temp |= pll->config.hw_state.pll1; |
| 2377 | I915_WRITE(BXT_PORT_PLL(port, 1), temp); |
| 2378 | |
| 2379 | /* Write M2 fraction */ |
| 2380 | temp = I915_READ(BXT_PORT_PLL(port, 2)); |
| 2381 | temp &= ~PORT_PLL_M2_FRAC_MASK; |
| 2382 | temp |= pll->config.hw_state.pll2; |
| 2383 | I915_WRITE(BXT_PORT_PLL(port, 2), temp); |
| 2384 | |
| 2385 | /* Write M2 fraction enable */ |
| 2386 | temp = I915_READ(BXT_PORT_PLL(port, 3)); |
| 2387 | temp &= ~PORT_PLL_M2_FRAC_ENABLE; |
| 2388 | temp |= pll->config.hw_state.pll3; |
| 2389 | I915_WRITE(BXT_PORT_PLL(port, 3), temp); |
| 2390 | |
| 2391 | /* Write coeff */ |
| 2392 | temp = I915_READ(BXT_PORT_PLL(port, 6)); |
| 2393 | temp &= ~PORT_PLL_PROP_COEFF_MASK; |
| 2394 | temp &= ~PORT_PLL_INT_COEFF_MASK; |
| 2395 | temp &= ~PORT_PLL_GAIN_CTL_MASK; |
| 2396 | temp |= pll->config.hw_state.pll6; |
| 2397 | I915_WRITE(BXT_PORT_PLL(port, 6), temp); |
| 2398 | |
| 2399 | /* Write calibration val */ |
| 2400 | temp = I915_READ(BXT_PORT_PLL(port, 8)); |
| 2401 | temp &= ~PORT_PLL_TARGET_CNT_MASK; |
| 2402 | temp |= pll->config.hw_state.pll8; |
| 2403 | I915_WRITE(BXT_PORT_PLL(port, 8), temp); |
| 2404 | |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 2405 | temp = I915_READ(BXT_PORT_PLL(port, 9)); |
| 2406 | temp &= ~PORT_PLL_LOCK_THRESHOLD_MASK; |
| 2407 | temp |= (5 << 1); |
| 2408 | I915_WRITE(BXT_PORT_PLL(port, 9), temp); |
| 2409 | |
| 2410 | temp = I915_READ(BXT_PORT_PLL(port, 10)); |
| 2411 | temp &= ~PORT_PLL_DCO_AMP_OVR_EN_H; |
| 2412 | temp &= ~PORT_PLL_DCO_AMP_MASK; |
| 2413 | temp |= pll->config.hw_state.pll10; |
| 2414 | I915_WRITE(BXT_PORT_PLL(port, 10), temp); |
Satheeshakrishna M | dfb8240 | 2014-08-22 09:49:09 +0530 | [diff] [blame] | 2415 | |
| 2416 | /* Recalibrate with new settings */ |
| 2417 | temp = I915_READ(BXT_PORT_PLL_EBB_4(port)); |
| 2418 | temp |= PORT_PLL_RECALIBRATE; |
| 2419 | I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp); |
| 2420 | /* Enable 10 bit clock */ |
| 2421 | temp |= PORT_PLL_10BIT_CLK_ENABLE; |
| 2422 | I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp); |
| 2423 | |
| 2424 | /* Enable PLL */ |
| 2425 | temp = I915_READ(BXT_PORT_PLL_ENABLE(port)); |
| 2426 | temp |= PORT_PLL_ENABLE; |
| 2427 | I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp); |
| 2428 | POSTING_READ(BXT_PORT_PLL_ENABLE(port)); |
| 2429 | |
| 2430 | if (wait_for_atomic_us((I915_READ(BXT_PORT_PLL_ENABLE(port)) & |
| 2431 | PORT_PLL_LOCK), 200)) |
| 2432 | DRM_ERROR("PLL %d not locked\n", port); |
| 2433 | |
| 2434 | /* |
| 2435 | * While we write to the group register to program all lanes at once we |
| 2436 | * can read only lane registers and we pick lanes 0/1 for that. |
| 2437 | */ |
| 2438 | temp = I915_READ(BXT_PORT_PCS_DW12_LN01(port)); |
| 2439 | temp &= ~LANE_STAGGER_MASK; |
| 2440 | temp &= ~LANESTAGGER_STRAP_OVRD; |
| 2441 | temp |= pll->config.hw_state.pcsdw12; |
| 2442 | I915_WRITE(BXT_PORT_PCS_DW12_GRP(port), temp); |
| 2443 | } |
| 2444 | |
| 2445 | static void bxt_ddi_pll_disable(struct drm_i915_private *dev_priv, |
| 2446 | struct intel_shared_dpll *pll) |
| 2447 | { |
| 2448 | enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */ |
| 2449 | uint32_t temp; |
| 2450 | |
| 2451 | temp = I915_READ(BXT_PORT_PLL_ENABLE(port)); |
| 2452 | temp &= ~PORT_PLL_ENABLE; |
| 2453 | I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp); |
| 2454 | POSTING_READ(BXT_PORT_PLL_ENABLE(port)); |
| 2455 | } |
| 2456 | |
| 2457 | static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, |
| 2458 | struct intel_shared_dpll *pll, |
| 2459 | struct intel_dpll_hw_state *hw_state) |
| 2460 | { |
| 2461 | enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */ |
| 2462 | uint32_t val; |
| 2463 | |
| 2464 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
| 2465 | return false; |
| 2466 | |
| 2467 | val = I915_READ(BXT_PORT_PLL_ENABLE(port)); |
| 2468 | if (!(val & PORT_PLL_ENABLE)) |
| 2469 | return false; |
| 2470 | |
| 2471 | hw_state->ebb0 = I915_READ(BXT_PORT_PLL_EBB_0(port)); |
| 2472 | hw_state->pll0 = I915_READ(BXT_PORT_PLL(port, 0)); |
| 2473 | hw_state->pll1 = I915_READ(BXT_PORT_PLL(port, 1)); |
| 2474 | hw_state->pll2 = I915_READ(BXT_PORT_PLL(port, 2)); |
| 2475 | hw_state->pll3 = I915_READ(BXT_PORT_PLL(port, 3)); |
| 2476 | hw_state->pll6 = I915_READ(BXT_PORT_PLL(port, 6)); |
| 2477 | hw_state->pll8 = I915_READ(BXT_PORT_PLL(port, 8)); |
Vandana Kannan | b6dc71f | 2015-05-13 12:18:52 +0530 | [diff] [blame^] | 2478 | hw_state->pll10 = I915_READ(BXT_PORT_PLL(port, 10)); |
Satheeshakrishna M | dfb8240 | 2014-08-22 09:49:09 +0530 | [diff] [blame] | 2479 | /* |
| 2480 | * While we write to the group register to program all lanes at once we |
| 2481 | * can read only lane registers. We configure all lanes the same way, so |
| 2482 | * here just read out lanes 0/1 and output a note if lanes 2/3 differ. |
| 2483 | */ |
| 2484 | hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port)); |
| 2485 | if (I915_READ(BXT_PORT_PCS_DW12_LN23(port) != hw_state->pcsdw12)) |
| 2486 | DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n", |
| 2487 | hw_state->pcsdw12, |
| 2488 | I915_READ(BXT_PORT_PCS_DW12_LN23(port))); |
| 2489 | |
| 2490 | return true; |
| 2491 | } |
| 2492 | |
| 2493 | static void bxt_shared_dplls_init(struct drm_i915_private *dev_priv) |
| 2494 | { |
| 2495 | int i; |
| 2496 | |
| 2497 | dev_priv->num_shared_dpll = 3; |
| 2498 | |
| 2499 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 2500 | dev_priv->shared_dplls[i].id = i; |
| 2501 | dev_priv->shared_dplls[i].name = bxt_ddi_pll_names[i]; |
| 2502 | dev_priv->shared_dplls[i].disable = bxt_ddi_pll_disable; |
| 2503 | dev_priv->shared_dplls[i].enable = bxt_ddi_pll_enable; |
| 2504 | dev_priv->shared_dplls[i].get_hw_state = |
| 2505 | bxt_ddi_pll_get_hw_state; |
| 2506 | } |
| 2507 | } |
| 2508 | |
Damien Lespiau | 143b307 | 2014-07-29 18:06:19 +0100 | [diff] [blame] | 2509 | void intel_ddi_pll_init(struct drm_device *dev) |
| 2510 | { |
| 2511 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2512 | uint32_t val = I915_READ(LCPLL_CTL); |
| 2513 | |
Satheeshakrishna M | d1a2dc7 | 2014-11-13 14:55:18 +0000 | [diff] [blame] | 2514 | if (IS_SKYLAKE(dev)) |
| 2515 | skl_shared_dplls_init(dev_priv); |
Satheeshakrishna M | dfb8240 | 2014-08-22 09:49:09 +0530 | [diff] [blame] | 2516 | else if (IS_BROXTON(dev)) |
| 2517 | bxt_shared_dplls_init(dev_priv); |
Satheeshakrishna M | d1a2dc7 | 2014-11-13 14:55:18 +0000 | [diff] [blame] | 2518 | else |
| 2519 | hsw_shared_dplls_init(dev_priv); |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 2520 | |
Paulo Zanoni | b2b877f | 2013-05-03 17:23:42 -0300 | [diff] [blame] | 2521 | DRM_DEBUG_KMS("CDCLK running at %dKHz\n", |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 2522 | dev_priv->display.get_display_clock_speed(dev)); |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 2523 | |
Satheeshakrishna M | 121643c | 2014-11-13 14:55:15 +0000 | [diff] [blame] | 2524 | if (IS_SKYLAKE(dev)) { |
| 2525 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) |
| 2526 | DRM_ERROR("LCPLL1 is disabled\n"); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 2527 | } else if (IS_BROXTON(dev)) { |
| 2528 | broxton_init_cdclk(dev); |
Vandana Kannan | 5c6706e | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 2529 | broxton_ddi_phy_init(dev); |
Satheeshakrishna M | 121643c | 2014-11-13 14:55:15 +0000 | [diff] [blame] | 2530 | } else { |
| 2531 | /* |
| 2532 | * The LCPLL register should be turned on by the BIOS. For now |
| 2533 | * let's just check its state and print errors in case |
| 2534 | * something is wrong. Don't even try to turn it on. |
| 2535 | */ |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 2536 | |
Satheeshakrishna M | 121643c | 2014-11-13 14:55:15 +0000 | [diff] [blame] | 2537 | if (val & LCPLL_CD_SOURCE_FCLK) |
| 2538 | DRM_ERROR("CDCLK source is not LCPLL\n"); |
| 2539 | |
| 2540 | if (val & LCPLL_PLL_DISABLE) |
| 2541 | DRM_ERROR("LCPLL is disabled\n"); |
| 2542 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 2543 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2544 | |
| 2545 | void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder) |
| 2546 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 2547 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 2548 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2549 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 2550 | enum port port = intel_dig_port->port; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2551 | uint32_t val; |
Syam Sidhardhan | f3e227d | 2013-02-25 04:05:38 +0530 | [diff] [blame] | 2552 | bool wait = false; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2553 | |
| 2554 | if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) { |
| 2555 | val = I915_READ(DDI_BUF_CTL(port)); |
| 2556 | if (val & DDI_BUF_CTL_ENABLE) { |
| 2557 | val &= ~DDI_BUF_CTL_ENABLE; |
| 2558 | I915_WRITE(DDI_BUF_CTL(port), val); |
| 2559 | wait = true; |
| 2560 | } |
| 2561 | |
| 2562 | val = I915_READ(DP_TP_CTL(port)); |
| 2563 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 2564 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2565 | I915_WRITE(DP_TP_CTL(port), val); |
| 2566 | POSTING_READ(DP_TP_CTL(port)); |
| 2567 | |
| 2568 | if (wait) |
| 2569 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 2570 | } |
| 2571 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2572 | val = DP_TP_CTL_ENABLE | |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2573 | DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2574 | if (intel_dp->is_mst) |
| 2575 | val |= DP_TP_CTL_MODE_MST; |
| 2576 | else { |
| 2577 | val |= DP_TP_CTL_MODE_SST; |
| 2578 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 2579 | val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE; |
| 2580 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2581 | I915_WRITE(DP_TP_CTL(port), val); |
| 2582 | POSTING_READ(DP_TP_CTL(port)); |
| 2583 | |
| 2584 | intel_dp->DP |= DDI_BUF_CTL_ENABLE; |
| 2585 | I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP); |
| 2586 | POSTING_READ(DDI_BUF_CTL(port)); |
| 2587 | |
| 2588 | udelay(600); |
| 2589 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2590 | |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2591 | void intel_ddi_fdi_disable(struct drm_crtc *crtc) |
| 2592 | { |
| 2593 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 2594 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 2595 | uint32_t val; |
| 2596 | |
| 2597 | intel_ddi_post_disable(intel_encoder); |
| 2598 | |
| 2599 | val = I915_READ(_FDI_RXA_CTL); |
| 2600 | val &= ~FDI_RX_ENABLE; |
| 2601 | I915_WRITE(_FDI_RXA_CTL, val); |
| 2602 | |
| 2603 | val = I915_READ(_FDI_RXA_MISC); |
| 2604 | val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 2605 | val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
| 2606 | I915_WRITE(_FDI_RXA_MISC, val); |
| 2607 | |
| 2608 | val = I915_READ(_FDI_RXA_CTL); |
| 2609 | val &= ~FDI_PCDCLK; |
| 2610 | I915_WRITE(_FDI_RXA_CTL, val); |
| 2611 | |
| 2612 | val = I915_READ(_FDI_RXA_CTL); |
| 2613 | val &= ~FDI_RX_PLL_ENABLE; |
| 2614 | I915_WRITE(_FDI_RXA_CTL, val); |
| 2615 | } |
| 2616 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2617 | static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder) |
| 2618 | { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2619 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 2620 | int type = intel_dig_port->base.type; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2621 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2622 | if (type != INTEL_OUTPUT_DISPLAYPORT && |
| 2623 | type != INTEL_OUTPUT_EDP && |
| 2624 | type != INTEL_OUTPUT_UNKNOWN) { |
| 2625 | return; |
| 2626 | } |
| 2627 | |
| 2628 | intel_dp_hot_plug(intel_encoder); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2629 | } |
| 2630 | |
Ville Syrjälä | 6801c18 | 2013-09-24 14:24:05 +0300 | [diff] [blame] | 2631 | void intel_ddi_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2632 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2633 | { |
| 2634 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 2635 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Ander Conselvan de Oliveira | 0cb09a9 | 2015-01-30 12:17:23 +0200 | [diff] [blame] | 2636 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Daniel Vetter | bbd440f | 2014-11-20 22:33:59 +0100 | [diff] [blame] | 2637 | struct intel_hdmi *intel_hdmi; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2638 | u32 temp, flags = 0; |
| 2639 | |
| 2640 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 2641 | if (temp & TRANS_DDI_PHSYNC) |
| 2642 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2643 | else |
| 2644 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2645 | if (temp & TRANS_DDI_PVSYNC) |
| 2646 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2647 | else |
| 2648 | flags |= DRM_MODE_FLAG_NVSYNC; |
| 2649 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2650 | pipe_config->base.adjusted_mode.flags |= flags; |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 2651 | |
| 2652 | switch (temp & TRANS_DDI_BPC_MASK) { |
| 2653 | case TRANS_DDI_BPC_6: |
| 2654 | pipe_config->pipe_bpp = 18; |
| 2655 | break; |
| 2656 | case TRANS_DDI_BPC_8: |
| 2657 | pipe_config->pipe_bpp = 24; |
| 2658 | break; |
| 2659 | case TRANS_DDI_BPC_10: |
| 2660 | pipe_config->pipe_bpp = 30; |
| 2661 | break; |
| 2662 | case TRANS_DDI_BPC_12: |
| 2663 | pipe_config->pipe_bpp = 36; |
| 2664 | break; |
| 2665 | default: |
| 2666 | break; |
| 2667 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2668 | |
| 2669 | switch (temp & TRANS_DDI_MODE_SELECT_MASK) { |
| 2670 | case TRANS_DDI_MODE_SELECT_HDMI: |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 2671 | pipe_config->has_hdmi_sink = true; |
Daniel Vetter | bbd440f | 2014-11-20 22:33:59 +0100 | [diff] [blame] | 2672 | intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
| 2673 | |
| 2674 | if (intel_hdmi->infoframe_enabled(&encoder->base)) |
| 2675 | pipe_config->has_infoframe = true; |
Jesse Barnes | cbc572a | 2014-11-17 13:08:47 -0800 | [diff] [blame] | 2676 | break; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2677 | case TRANS_DDI_MODE_SELECT_DVI: |
| 2678 | case TRANS_DDI_MODE_SELECT_FDI: |
| 2679 | break; |
| 2680 | case TRANS_DDI_MODE_SELECT_DP_SST: |
| 2681 | case TRANS_DDI_MODE_SELECT_DP_MST: |
| 2682 | pipe_config->has_dp_encoder = true; |
| 2683 | intel_dp_get_m_n(intel_crtc, pipe_config); |
| 2684 | break; |
| 2685 | default: |
| 2686 | break; |
| 2687 | } |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 2688 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 2689 | if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) { |
Paulo Zanoni | a60551b | 2014-05-21 16:23:20 -0300 | [diff] [blame] | 2690 | temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 2691 | if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe)) |
Paulo Zanoni | a60551b | 2014-05-21 16:23:20 -0300 | [diff] [blame] | 2692 | pipe_config->has_audio = true; |
| 2693 | } |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2694 | |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 2695 | if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp && |
| 2696 | pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) { |
| 2697 | /* |
| 2698 | * This is a big fat ugly hack. |
| 2699 | * |
| 2700 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2701 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2702 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2703 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2704 | * max, not what it tells us to use. |
| 2705 | * |
| 2706 | * Note: This will still be broken if the eDP panel is not lit |
| 2707 | * up by the BIOS, and thus we can't get the mode at module |
| 2708 | * load. |
| 2709 | */ |
| 2710 | DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", |
| 2711 | pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp); |
| 2712 | dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp; |
| 2713 | } |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 2714 | |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 2715 | intel_ddi_clock_get(encoder, pipe_config); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2718 | static void intel_ddi_destroy(struct drm_encoder *encoder) |
| 2719 | { |
| 2720 | /* HDMI has nothing special to destroy, so we can go with this. */ |
| 2721 | intel_dp_encoder_destroy(encoder); |
| 2722 | } |
| 2723 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2724 | static bool intel_ddi_compute_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2725 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2726 | { |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2727 | int type = encoder->type; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 2728 | int port = intel_ddi_get_encoder_port(encoder); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2729 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2730 | WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n"); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2731 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 2732 | if (port == PORT_A) |
| 2733 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 2734 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2735 | if (type == INTEL_OUTPUT_HDMI) |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2736 | return intel_hdmi_compute_config(encoder, pipe_config); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2737 | else |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2738 | return intel_dp_compute_config(encoder, pipe_config); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | static const struct drm_encoder_funcs intel_ddi_funcs = { |
| 2742 | .destroy = intel_ddi_destroy, |
| 2743 | }; |
| 2744 | |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 2745 | static struct intel_connector * |
| 2746 | intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port) |
| 2747 | { |
| 2748 | struct intel_connector *connector; |
| 2749 | enum port port = intel_dig_port->port; |
| 2750 | |
Ander Conselvan de Oliveira | 9bdbd0b | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 2751 | connector = intel_connector_alloc(); |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 2752 | if (!connector) |
| 2753 | return NULL; |
| 2754 | |
| 2755 | intel_dig_port->dp.output_reg = DDI_BUF_CTL(port); |
| 2756 | if (!intel_dp_init_connector(intel_dig_port, connector)) { |
| 2757 | kfree(connector); |
| 2758 | return NULL; |
| 2759 | } |
| 2760 | |
| 2761 | return connector; |
| 2762 | } |
| 2763 | |
| 2764 | static struct intel_connector * |
| 2765 | intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port) |
| 2766 | { |
| 2767 | struct intel_connector *connector; |
| 2768 | enum port port = intel_dig_port->port; |
| 2769 | |
Ander Conselvan de Oliveira | 9bdbd0b | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 2770 | connector = intel_connector_alloc(); |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 2771 | if (!connector) |
| 2772 | return NULL; |
| 2773 | |
| 2774 | intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port); |
| 2775 | intel_hdmi_init_connector(intel_dig_port, connector); |
| 2776 | |
| 2777 | return connector; |
| 2778 | } |
| 2779 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2780 | void intel_ddi_init(struct drm_device *dev, enum port port) |
| 2781 | { |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 2782 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2783 | struct intel_digital_port *intel_dig_port; |
| 2784 | struct intel_encoder *intel_encoder; |
| 2785 | struct drm_encoder *encoder; |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2786 | bool init_hdmi, init_dp; |
| 2787 | |
| 2788 | init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi || |
| 2789 | dev_priv->vbt.ddi_port_info[port].supports_hdmi); |
| 2790 | init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp; |
| 2791 | if (!init_dp && !init_hdmi) { |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2792 | 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] | 2793 | port_name(port)); |
| 2794 | init_hdmi = true; |
| 2795 | init_dp = true; |
| 2796 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2797 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 2798 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2799 | if (!intel_dig_port) |
| 2800 | return; |
| 2801 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2802 | intel_encoder = &intel_dig_port->base; |
| 2803 | encoder = &intel_encoder->base; |
| 2804 | |
| 2805 | drm_encoder_init(dev, encoder, &intel_ddi_funcs, |
| 2806 | DRM_MODE_ENCODER_TMDS); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2807 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2808 | intel_encoder->compute_config = intel_ddi_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2809 | intel_encoder->enable = intel_enable_ddi; |
| 2810 | intel_encoder->pre_enable = intel_ddi_pre_enable; |
| 2811 | intel_encoder->disable = intel_disable_ddi; |
| 2812 | intel_encoder->post_disable = intel_ddi_post_disable; |
| 2813 | intel_encoder->get_hw_state = intel_ddi_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2814 | intel_encoder->get_config = intel_ddi_get_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2815 | |
| 2816 | intel_dig_port->port = port; |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 2817 | intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) & |
| 2818 | (DDI_BUF_PORT_REVERSAL | |
| 2819 | DDI_A_4_LANES); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2820 | |
| 2821 | intel_encoder->type = INTEL_OUTPUT_UNKNOWN; |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2822 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 2823 | intel_encoder->cloneable = 0; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2824 | intel_encoder->hot_plug = intel_ddi_hot_plug; |
| 2825 | |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2826 | if (init_dp) { |
| 2827 | if (!intel_ddi_init_dp_connector(intel_dig_port)) |
| 2828 | goto err; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 2829 | |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2830 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
| 2831 | dev_priv->hpd_irq_port[port] = intel_dig_port; |
| 2832 | } |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 2833 | |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2834 | /* In theory we don't need the encoder->type check, but leave it just in |
| 2835 | * case we have some really bad VBTs... */ |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2836 | if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) { |
| 2837 | if (!intel_ddi_init_hdmi_connector(intel_dig_port)) |
| 2838 | goto err; |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 2839 | } |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2840 | |
| 2841 | return; |
| 2842 | |
| 2843 | err: |
| 2844 | drm_encoder_cleanup(encoder); |
| 2845 | kfree(intel_dig_port); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2846 | } |