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[] = { |
| 158 | /* Idx NT mV T mV db */ |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 159 | { 0x00004014, 0x00000087 }, /* 0: 800 1000 2 */ |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
Jani Nikula | 20f4dbe | 2013-08-30 19:40:28 +0300 | [diff] [blame] | 162 | enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder) |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 163 | { |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame] | 164 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 165 | int type = intel_encoder->type; |
| 166 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 167 | if (type == INTEL_OUTPUT_DP_MST) { |
| 168 | struct intel_digital_port *intel_dig_port = enc_to_mst(encoder)->primary; |
| 169 | return intel_dig_port->port; |
| 170 | } else if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 171 | type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 172 | struct intel_digital_port *intel_dig_port = |
| 173 | enc_to_dig_port(encoder); |
| 174 | return intel_dig_port->port; |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame] | 175 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 176 | } else if (type == INTEL_OUTPUT_ANALOG) { |
| 177 | return PORT_E; |
Paulo Zanoni | 0bdee30 | 2012-10-15 15:51:38 -0300 | [diff] [blame] | 178 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 179 | } else { |
| 180 | DRM_ERROR("Invalid DDI encoder type %d\n", type); |
| 181 | BUG(); |
| 182 | } |
| 183 | } |
| 184 | |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 185 | /* |
| 186 | * Starting with Haswell, DDI port buffers must be programmed with correct |
| 187 | * 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] | 188 | * but the HDMI/DVI fields are shared among those. So we program the DDI |
| 189 | * in either FDI or DP modes only, as HDMI connections will work with both |
| 190 | * of those |
| 191 | */ |
Paulo Zanoni | ad8d270 | 2013-08-05 17:25:56 -0300 | [diff] [blame] | 192 | static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port) |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 193 | { |
| 194 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 195 | u32 reg; |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 196 | 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] | 197 | size; |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 198 | 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] | 199 | const struct ddi_buf_trans *ddi_translations_fdi; |
| 200 | const struct ddi_buf_trans *ddi_translations_dp; |
| 201 | const struct ddi_buf_trans *ddi_translations_edp; |
| 202 | const struct ddi_buf_trans *ddi_translations_hdmi; |
| 203 | const struct ddi_buf_trans *ddi_translations; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 204 | |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 205 | if (IS_SKYLAKE(dev)) { |
| 206 | ddi_translations_fdi = NULL; |
| 207 | ddi_translations_dp = skl_ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 208 | n_dp_entries = ARRAY_SIZE(skl_ddi_translations_dp); |
| 209 | if (dev_priv->vbt.edp_low_vswing) { |
| 210 | ddi_translations_edp = skl_ddi_translations_edp; |
| 211 | n_edp_entries = ARRAY_SIZE(skl_ddi_translations_edp); |
| 212 | } else { |
| 213 | ddi_translations_edp = skl_ddi_translations_dp; |
| 214 | n_edp_entries = ARRAY_SIZE(skl_ddi_translations_dp); |
| 215 | } |
| 216 | |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 217 | /* |
| 218 | * On SKL, the recommendation from the hw team is to always use |
| 219 | * a certain type of level shifter (and thus the corresponding |
| 220 | * 800mV+2dB entry). Given that's the only validated entry, we |
| 221 | * override what is in the VBT, at least until further notice. |
| 222 | */ |
| 223 | hdmi_level = 0; |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 224 | ddi_translations_hdmi = skl_ddi_translations_hdmi; |
| 225 | n_hdmi_entries = ARRAY_SIZE(skl_ddi_translations_hdmi); |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 226 | hdmi_default_entry = 0; |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 227 | } else if (IS_BROADWELL(dev)) { |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 228 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 229 | ddi_translations_dp = bdw_ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 230 | ddi_translations_edp = bdw_ddi_translations_edp; |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 231 | ddi_translations_hdmi = bdw_ddi_translations_hdmi; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 232 | n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp); |
| 233 | n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 234 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 235 | hdmi_default_entry = 7; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 236 | } else if (IS_HASWELL(dev)) { |
| 237 | ddi_translations_fdi = hsw_ddi_translations_fdi; |
| 238 | ddi_translations_dp = hsw_ddi_translations_dp; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 239 | ddi_translations_edp = hsw_ddi_translations_dp; |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 240 | ddi_translations_hdmi = hsw_ddi_translations_hdmi; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 241 | n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp); |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 242 | n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 243 | hdmi_default_entry = 6; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 244 | } else { |
| 245 | WARN(1, "ddi translation table missing\n"); |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 246 | ddi_translations_edp = bdw_ddi_translations_dp; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 247 | ddi_translations_fdi = bdw_ddi_translations_fdi; |
| 248 | ddi_translations_dp = bdw_ddi_translations_dp; |
Damien Lespiau | a26aa8b | 2014-08-01 11:07:55 +0100 | [diff] [blame] | 249 | ddi_translations_hdmi = bdw_ddi_translations_hdmi; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 250 | n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp); |
| 251 | n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp); |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 252 | n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 253 | hdmi_default_entry = 7; |
Art Runyan | e58623c | 2013-11-02 21:07:41 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 256 | switch (port) { |
| 257 | case PORT_A: |
| 258 | ddi_translations = ddi_translations_edp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 259 | size = n_edp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 260 | break; |
| 261 | case PORT_B: |
| 262 | case PORT_C: |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 263 | ddi_translations = ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 264 | size = n_dp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 265 | break; |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 266 | case PORT_D: |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 267 | if (intel_dp_is_edp(dev, PORT_D)) { |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 268 | ddi_translations = ddi_translations_edp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 269 | size = n_edp_entries; |
| 270 | } else { |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 271 | ddi_translations = ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 272 | size = n_dp_entries; |
| 273 | } |
Paulo Zanoni | 77d8d00 | 2013-11-02 21:07:45 -0700 | [diff] [blame] | 274 | break; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 275 | case PORT_E: |
Damien Lespiau | 7f88e3a | 2013-12-03 13:56:25 +0000 | [diff] [blame] | 276 | if (ddi_translations_fdi) |
| 277 | ddi_translations = ddi_translations_fdi; |
| 278 | else |
| 279 | ddi_translations = ddi_translations_dp; |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 280 | size = n_dp_entries; |
Paulo Zanoni | 300644c | 2013-11-02 21:07:42 -0700 | [diff] [blame] | 281 | break; |
| 282 | default: |
| 283 | BUG(); |
| 284 | } |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 285 | |
Sonika Jindal | 7ad14a2 | 2015-02-25 10:29:12 +0530 | [diff] [blame] | 286 | for (i = 0, reg = DDI_BUF_TRANS(port); i < size; i++) { |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 287 | I915_WRITE(reg, ddi_translations[i].trans1); |
| 288 | reg += 4; |
| 289 | I915_WRITE(reg, ddi_translations[i].trans2); |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 290 | reg += 4; |
| 291 | } |
Damien Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 292 | |
| 293 | /* Choose a good default if VBT is badly populated */ |
| 294 | if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN || |
| 295 | hdmi_level >= n_hdmi_entries) |
Damien Lespiau | 7ff4467 | 2015-03-02 16:19:36 +0000 | [diff] [blame^] | 296 | hdmi_level = hdmi_default_entry; |
Damien Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 297 | |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 298 | /* Entry 9 is for HDMI: */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 299 | I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans1); |
| 300 | reg += 4; |
| 301 | I915_WRITE(reg, ddi_translations_hdmi[hdmi_level].trans2); |
| 302 | reg += 4; |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /* Program DDI buffers translations for DP. By default, program ports A-D in DP |
| 306 | * mode and port E for FDI. |
| 307 | */ |
| 308 | void intel_prepare_ddi(struct drm_device *dev) |
| 309 | { |
| 310 | int port; |
| 311 | |
Paulo Zanoni | 0d536cb | 2012-11-23 16:46:41 -0200 | [diff] [blame] | 312 | if (!HAS_DDI(dev)) |
| 313 | return; |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 314 | |
Paulo Zanoni | ad8d270 | 2013-08-05 17:25:56 -0300 | [diff] [blame] | 315 | for (port = PORT_A; port <= PORT_E; port++) |
| 316 | intel_prepare_ddi_buffers(dev, port); |
Eugeni Dodonov | 45244b8 | 2012-05-09 15:37:20 -0300 | [diff] [blame] | 317 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 318 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 319 | static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, |
| 320 | enum port port) |
| 321 | { |
| 322 | uint32_t reg = DDI_BUF_CTL(port); |
| 323 | int i; |
| 324 | |
| 325 | for (i = 0; i < 8; i++) { |
| 326 | udelay(1); |
| 327 | if (I915_READ(reg) & DDI_BUF_IS_IDLE) |
| 328 | return; |
| 329 | } |
| 330 | DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port)); |
| 331 | } |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 332 | |
| 333 | /* Starting with Haswell, different DDI ports can work in FDI mode for |
| 334 | * connection to the PCH-located connectors. For this, it is necessary to train |
| 335 | * both the DDI port and PCH receiver for the desired DDI buffer settings. |
| 336 | * |
| 337 | * The recommended port to work in FDI mode is DDI E, which we use here. Also, |
| 338 | * please note that when FDI mode is active on DDI E, it shares 2 lines with |
| 339 | * DDI A (which is used for eDP) |
| 340 | */ |
| 341 | |
| 342 | void hsw_fdi_link_train(struct drm_crtc *crtc) |
| 343 | { |
| 344 | struct drm_device *dev = crtc->dev; |
| 345 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 346 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 347 | u32 temp, i, rx_ctl_val; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 348 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 349 | /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the |
| 350 | * mode set "sequence for CRT port" document: |
| 351 | * - TP1 to TP2 time with the default value |
| 352 | * - FDI delay to 90h |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 353 | * |
| 354 | * WaFDIAutoLinkSetTimingOverrride:hsw |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 355 | */ |
| 356 | I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) | |
| 357 | FDI_RX_PWRDN_LANE0_VAL(2) | |
| 358 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 359 | |
| 360 | /* Enable the PCH Receiver FDI PLL */ |
Damien Lespiau | 3e68320 | 2012-12-11 18:48:29 +0000 | [diff] [blame] | 361 | 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] | 362 | FDI_RX_PLL_ENABLE | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 363 | FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 364 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 365 | POSTING_READ(_FDI_RXA_CTL); |
| 366 | udelay(220); |
| 367 | |
| 368 | /* Switch from Rawclk to PCDclk */ |
| 369 | rx_ctl_val |= FDI_PCDCLK; |
| 370 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 371 | |
| 372 | /* Configure Port Clock Select */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 373 | I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config->ddi_pll_sel); |
| 374 | WARN_ON(intel_crtc->config->ddi_pll_sel != PORT_CLK_SEL_SPLL); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 375 | |
| 376 | /* Start the training iterating through available voltages and emphasis, |
| 377 | * testing each value twice. */ |
Jani Nikula | 1012205 | 2014-08-27 16:27:30 +0300 | [diff] [blame] | 378 | for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) { |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 379 | /* Configure DP_TP_CTL with auto-training */ |
| 380 | I915_WRITE(DP_TP_CTL(PORT_E), |
| 381 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 382 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 383 | DP_TP_CTL_LINK_TRAIN_PAT1 | |
| 384 | DP_TP_CTL_ENABLE); |
| 385 | |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 386 | /* Configure and enable DDI_BUF_CTL for DDI E with next voltage. |
| 387 | * DDI E does not support port reversal, the functionality is |
| 388 | * achieved on the PCH side in FDI_RX_CTL, so no need to set the |
| 389 | * port reversal bit */ |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 390 | I915_WRITE(DDI_BUF_CTL(PORT_E), |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 391 | DDI_BUF_CTL_ENABLE | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 392 | ((intel_crtc->config->fdi_lanes - 1) << 1) | |
Sonika Jindal | c5fe6a0 | 2014-08-11 08:57:36 +0530 | [diff] [blame] | 393 | DDI_BUF_TRANS_SELECT(i / 2)); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 394 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 395 | |
| 396 | udelay(600); |
| 397 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 398 | /* Program PCH FDI Receiver TU */ |
| 399 | I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64)); |
Eugeni Dodonov | 4acf518 | 2012-07-04 20:15:16 -0300 | [diff] [blame] | 400 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 401 | /* Enable PCH FDI Receiver with auto-training */ |
| 402 | rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO; |
| 403 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
| 404 | POSTING_READ(_FDI_RXA_CTL); |
| 405 | |
| 406 | /* Wait for FDI receiver lane calibration */ |
| 407 | udelay(30); |
| 408 | |
| 409 | /* Unset FDI_RX_MISC pwrdn lanes */ |
| 410 | temp = I915_READ(_FDI_RXA_MISC); |
| 411 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 412 | I915_WRITE(_FDI_RXA_MISC, temp); |
| 413 | POSTING_READ(_FDI_RXA_MISC); |
| 414 | |
| 415 | /* Wait for FDI auto training time */ |
| 416 | udelay(5); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 417 | |
| 418 | temp = I915_READ(DP_TP_STATUS(PORT_E)); |
| 419 | if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 420 | DRM_DEBUG_KMS("FDI link training done on step %d\n", i); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 421 | |
| 422 | /* Enable normal pixel sending for FDI */ |
| 423 | I915_WRITE(DP_TP_CTL(PORT_E), |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 424 | DP_TP_CTL_FDI_AUTOTRAIN | |
| 425 | DP_TP_CTL_LINK_TRAIN_NORMAL | |
| 426 | DP_TP_CTL_ENHANCED_FRAME_ENABLE | |
| 427 | DP_TP_CTL_ENABLE); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 428 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 429 | return; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 430 | } |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 431 | |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 432 | temp = I915_READ(DDI_BUF_CTL(PORT_E)); |
| 433 | temp &= ~DDI_BUF_CTL_ENABLE; |
| 434 | I915_WRITE(DDI_BUF_CTL(PORT_E), temp); |
| 435 | POSTING_READ(DDI_BUF_CTL(PORT_E)); |
| 436 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 437 | /* Disable DP_TP_CTL and FDI_RX_CTL and retry */ |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 438 | temp = I915_READ(DP_TP_CTL(PORT_E)); |
| 439 | temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 440 | temp |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 441 | I915_WRITE(DP_TP_CTL(PORT_E), temp); |
| 442 | POSTING_READ(DP_TP_CTL(PORT_E)); |
| 443 | |
| 444 | intel_wait_ddi_buf_idle(dev_priv, PORT_E); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 445 | |
| 446 | rx_ctl_val &= ~FDI_RX_ENABLE; |
| 447 | I915_WRITE(_FDI_RXA_CTL, rx_ctl_val); |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 448 | POSTING_READ(_FDI_RXA_CTL); |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 449 | |
| 450 | /* Reset FDI_RX_MISC pwrdn lanes */ |
| 451 | temp = I915_READ(_FDI_RXA_MISC); |
| 452 | temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 453 | temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
| 454 | I915_WRITE(_FDI_RXA_MISC, temp); |
Paulo Zanoni | 248138b | 2012-11-29 11:29:31 -0200 | [diff] [blame] | 455 | POSTING_READ(_FDI_RXA_MISC); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 456 | } |
| 457 | |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 458 | DRM_ERROR("FDI link training failed!\n"); |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 459 | } |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 460 | |
Dave Airlie | 44905a2 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 461 | void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder) |
| 462 | { |
| 463 | struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base); |
| 464 | struct intel_digital_port *intel_dig_port = |
| 465 | enc_to_dig_port(&encoder->base); |
| 466 | |
| 467 | intel_dp->DP = intel_dig_port->saved_port_bits | |
Sonika Jindal | c5fe6a0 | 2014-08-11 08:57:36 +0530 | [diff] [blame] | 468 | DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0); |
Dave Airlie | 44905a2 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 469 | intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count); |
| 470 | |
| 471 | } |
| 472 | |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 473 | static struct intel_encoder * |
| 474 | intel_ddi_get_crtc_encoder(struct drm_crtc *crtc) |
| 475 | { |
| 476 | struct drm_device *dev = crtc->dev; |
| 477 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 478 | struct intel_encoder *intel_encoder, *ret = NULL; |
| 479 | int num_encoders = 0; |
| 480 | |
| 481 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 482 | ret = intel_encoder; |
| 483 | num_encoders++; |
| 484 | } |
| 485 | |
| 486 | if (num_encoders != 1) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 487 | WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders, |
| 488 | pipe_name(intel_crtc->pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 489 | |
| 490 | BUG_ON(ret == NULL); |
| 491 | return ret; |
| 492 | } |
| 493 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 494 | static struct intel_encoder * |
| 495 | intel_ddi_get_crtc_new_encoder(struct intel_crtc *crtc) |
| 496 | { |
| 497 | struct drm_device *dev = crtc->base.dev; |
| 498 | struct intel_encoder *intel_encoder, *ret = NULL; |
| 499 | int num_encoders = 0; |
| 500 | |
| 501 | for_each_intel_encoder(dev, intel_encoder) { |
| 502 | if (intel_encoder->new_crtc == crtc) { |
| 503 | ret = intel_encoder; |
| 504 | num_encoders++; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders, |
| 509 | pipe_name(crtc->pipe)); |
| 510 | |
| 511 | BUG_ON(ret == NULL); |
| 512 | return ret; |
| 513 | } |
| 514 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 515 | #define LC_FREQ 2700 |
Damien Lespiau | 2789339 | 2014-09-04 12:27:23 +0100 | [diff] [blame] | 516 | #define LC_FREQ_2K U64_C(LC_FREQ * 2000) |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 517 | |
| 518 | #define P_MIN 2 |
| 519 | #define P_MAX 64 |
| 520 | #define P_INC 2 |
| 521 | |
| 522 | /* Constraints for PLL good behavior */ |
| 523 | #define REF_MIN 48 |
| 524 | #define REF_MAX 400 |
| 525 | #define VCO_MIN 2400 |
| 526 | #define VCO_MAX 4800 |
| 527 | |
Damien Lespiau | 2789339 | 2014-09-04 12:27:23 +0100 | [diff] [blame] | 528 | #define abs_diff(a, b) ({ \ |
| 529 | typeof(a) __a = (a); \ |
| 530 | typeof(b) __b = (b); \ |
| 531 | (void) (&__a == &__b); \ |
| 532 | __a > __b ? (__a - __b) : (__b - __a); }) |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 533 | |
| 534 | struct wrpll_rnp { |
| 535 | unsigned p, n2, r2; |
| 536 | }; |
| 537 | |
| 538 | static unsigned wrpll_get_budget_for_freq(int clock) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 539 | { |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 540 | unsigned budget; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 541 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 542 | switch (clock) { |
| 543 | case 25175000: |
| 544 | case 25200000: |
| 545 | case 27000000: |
| 546 | case 27027000: |
| 547 | case 37762500: |
| 548 | case 37800000: |
| 549 | case 40500000: |
| 550 | case 40541000: |
| 551 | case 54000000: |
| 552 | case 54054000: |
| 553 | case 59341000: |
| 554 | case 59400000: |
| 555 | case 72000000: |
| 556 | case 74176000: |
| 557 | case 74250000: |
| 558 | case 81000000: |
| 559 | case 81081000: |
| 560 | case 89012000: |
| 561 | case 89100000: |
| 562 | case 108000000: |
| 563 | case 108108000: |
| 564 | case 111264000: |
| 565 | case 111375000: |
| 566 | case 148352000: |
| 567 | case 148500000: |
| 568 | case 162000000: |
| 569 | case 162162000: |
| 570 | case 222525000: |
| 571 | case 222750000: |
| 572 | case 296703000: |
| 573 | case 297000000: |
| 574 | budget = 0; |
| 575 | break; |
| 576 | case 233500000: |
| 577 | case 245250000: |
| 578 | case 247750000: |
| 579 | case 253250000: |
| 580 | case 298000000: |
| 581 | budget = 1500; |
| 582 | break; |
| 583 | case 169128000: |
| 584 | case 169500000: |
| 585 | case 179500000: |
| 586 | case 202000000: |
| 587 | budget = 2000; |
| 588 | break; |
| 589 | case 256250000: |
| 590 | case 262500000: |
| 591 | case 270000000: |
| 592 | case 272500000: |
| 593 | case 273750000: |
| 594 | case 280750000: |
| 595 | case 281250000: |
| 596 | case 286000000: |
| 597 | case 291750000: |
| 598 | budget = 4000; |
| 599 | break; |
| 600 | case 267250000: |
| 601 | case 268500000: |
| 602 | budget = 5000; |
| 603 | break; |
| 604 | default: |
| 605 | budget = 1000; |
| 606 | break; |
| 607 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 608 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 609 | return budget; |
| 610 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 611 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 612 | static void wrpll_update_rnp(uint64_t freq2k, unsigned budget, |
| 613 | unsigned r2, unsigned n2, unsigned p, |
| 614 | struct wrpll_rnp *best) |
| 615 | { |
| 616 | uint64_t a, b, c, d, diff, diff_best; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 617 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 618 | /* No best (r,n,p) yet */ |
| 619 | if (best->p == 0) { |
| 620 | best->p = p; |
| 621 | best->n2 = n2; |
| 622 | best->r2 = r2; |
| 623 | return; |
| 624 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 625 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 626 | /* |
| 627 | * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to |
| 628 | * freq2k. |
| 629 | * |
| 630 | * delta = 1e6 * |
| 631 | * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) / |
| 632 | * freq2k; |
| 633 | * |
| 634 | * and we would like delta <= budget. |
| 635 | * |
| 636 | * If the discrepancy is above the PPM-based budget, always prefer to |
| 637 | * improve upon the previous solution. However, if you're within the |
| 638 | * budget, try to maximize Ref * VCO, that is N / (P * R^2). |
| 639 | */ |
| 640 | a = freq2k * budget * p * r2; |
| 641 | b = freq2k * budget * best->p * best->r2; |
Damien Lespiau | 2789339 | 2014-09-04 12:27:23 +0100 | [diff] [blame] | 642 | diff = abs_diff(freq2k * p * r2, LC_FREQ_2K * n2); |
| 643 | diff_best = abs_diff(freq2k * best->p * best->r2, |
| 644 | LC_FREQ_2K * best->n2); |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 645 | c = 1000000 * diff; |
| 646 | d = 1000000 * diff_best; |
| 647 | |
| 648 | if (a < c && b < d) { |
| 649 | /* If both are above the budget, pick the closer */ |
| 650 | if (best->p * best->r2 * diff < p * r2 * diff_best) { |
| 651 | best->p = p; |
| 652 | best->n2 = n2; |
| 653 | best->r2 = r2; |
| 654 | } |
| 655 | } else if (a >= c && b < d) { |
| 656 | /* If A is below the threshold but B is above it? Update. */ |
| 657 | best->p = p; |
| 658 | best->n2 = n2; |
| 659 | best->r2 = r2; |
| 660 | } else if (a >= c && b >= d) { |
| 661 | /* Both are below the limit, so pick the higher n2/(r2*r2) */ |
| 662 | if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) { |
| 663 | best->p = p; |
| 664 | best->n2 = n2; |
| 665 | best->r2 = r2; |
| 666 | } |
| 667 | } |
| 668 | /* Otherwise a < c && b >= d, do nothing */ |
| 669 | } |
| 670 | |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 671 | static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv, |
| 672 | int reg) |
| 673 | { |
| 674 | int refclk = LC_FREQ; |
| 675 | int n, p, r; |
| 676 | u32 wrpll; |
| 677 | |
| 678 | wrpll = I915_READ(reg); |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 679 | switch (wrpll & WRPLL_PLL_REF_MASK) { |
| 680 | case WRPLL_PLL_SSC: |
| 681 | case WRPLL_PLL_NON_SSC: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 682 | /* |
| 683 | * We could calculate spread here, but our checking |
| 684 | * code only cares about 5% accuracy, and spread is a max of |
| 685 | * 0.5% downspread. |
| 686 | */ |
| 687 | refclk = 135; |
| 688 | break; |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 689 | case WRPLL_PLL_LCPLL: |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 690 | refclk = LC_FREQ; |
| 691 | break; |
| 692 | default: |
| 693 | WARN(1, "bad wrpll refclk\n"); |
| 694 | return 0; |
| 695 | } |
| 696 | |
| 697 | r = wrpll & WRPLL_DIVIDER_REF_MASK; |
| 698 | p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT; |
| 699 | n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT; |
| 700 | |
Jesse Barnes | 20f0ec1 | 2014-01-22 12:58:04 -0800 | [diff] [blame] | 701 | /* Convert to KHz, p & r have a fixed point portion */ |
| 702 | return (refclk * n * 100) / (p * r); |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 703 | } |
| 704 | |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 705 | static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv, |
| 706 | uint32_t dpll) |
| 707 | { |
| 708 | uint32_t cfgcr1_reg, cfgcr2_reg; |
| 709 | uint32_t cfgcr1_val, cfgcr2_val; |
| 710 | uint32_t p0, p1, p2, dco_freq; |
| 711 | |
| 712 | cfgcr1_reg = GET_CFG_CR1_REG(dpll); |
| 713 | cfgcr2_reg = GET_CFG_CR2_REG(dpll); |
| 714 | |
| 715 | cfgcr1_val = I915_READ(cfgcr1_reg); |
| 716 | cfgcr2_val = I915_READ(cfgcr2_reg); |
| 717 | |
| 718 | p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK; |
| 719 | p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK; |
| 720 | |
| 721 | if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1)) |
| 722 | p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8; |
| 723 | else |
| 724 | p1 = 1; |
| 725 | |
| 726 | |
| 727 | switch (p0) { |
| 728 | case DPLL_CFGCR2_PDIV_1: |
| 729 | p0 = 1; |
| 730 | break; |
| 731 | case DPLL_CFGCR2_PDIV_2: |
| 732 | p0 = 2; |
| 733 | break; |
| 734 | case DPLL_CFGCR2_PDIV_3: |
| 735 | p0 = 3; |
| 736 | break; |
| 737 | case DPLL_CFGCR2_PDIV_7: |
| 738 | p0 = 7; |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | switch (p2) { |
| 743 | case DPLL_CFGCR2_KDIV_5: |
| 744 | p2 = 5; |
| 745 | break; |
| 746 | case DPLL_CFGCR2_KDIV_2: |
| 747 | p2 = 2; |
| 748 | break; |
| 749 | case DPLL_CFGCR2_KDIV_3: |
| 750 | p2 = 3; |
| 751 | break; |
| 752 | case DPLL_CFGCR2_KDIV_1: |
| 753 | p2 = 1; |
| 754 | break; |
| 755 | } |
| 756 | |
| 757 | dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000; |
| 758 | |
| 759 | dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 * |
| 760 | 1000) / 0x8000; |
| 761 | |
| 762 | return dco_freq / (p0 * p1 * p2 * 5); |
| 763 | } |
| 764 | |
| 765 | |
| 766 | static void skl_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 767 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 768 | { |
| 769 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 770 | int link_clock = 0; |
| 771 | uint32_t dpll_ctl1, dpll; |
| 772 | |
Damien Lespiau | 134ffa4 | 2014-11-14 17:24:34 +0000 | [diff] [blame] | 773 | dpll = pipe_config->ddi_pll_sel; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 774 | |
| 775 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 776 | |
| 777 | if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) { |
| 778 | link_clock = skl_calc_wrpll_link(dev_priv, dpll); |
| 779 | } else { |
| 780 | link_clock = dpll_ctl1 & DPLL_CRTL1_LINK_RATE_MASK(dpll); |
| 781 | link_clock >>= DPLL_CRTL1_LINK_RATE_SHIFT(dpll); |
| 782 | |
| 783 | switch (link_clock) { |
| 784 | case DPLL_CRTL1_LINK_RATE_810: |
| 785 | link_clock = 81000; |
| 786 | break; |
| 787 | case DPLL_CRTL1_LINK_RATE_1350: |
| 788 | link_clock = 135000; |
| 789 | break; |
| 790 | case DPLL_CRTL1_LINK_RATE_2700: |
| 791 | link_clock = 270000; |
| 792 | break; |
| 793 | default: |
| 794 | WARN(1, "Unsupported link rate\n"); |
| 795 | break; |
| 796 | } |
| 797 | link_clock *= 2; |
| 798 | } |
| 799 | |
| 800 | pipe_config->port_clock = link_clock; |
| 801 | |
| 802 | if (pipe_config->has_dp_encoder) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 803 | pipe_config->base.adjusted_mode.crtc_clock = |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 804 | intel_dotclock_calculate(pipe_config->port_clock, |
| 805 | &pipe_config->dp_m_n); |
| 806 | else |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 807 | pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock; |
Satheeshakrishna M | 540e732 | 2014-11-13 14:55:16 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 810 | static void hsw_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 811 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 812 | { |
| 813 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 814 | int link_clock = 0; |
| 815 | u32 val, pll; |
| 816 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 817 | val = pipe_config->ddi_pll_sel; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 818 | switch (val & PORT_CLK_SEL_MASK) { |
| 819 | case PORT_CLK_SEL_LCPLL_810: |
| 820 | link_clock = 81000; |
| 821 | break; |
| 822 | case PORT_CLK_SEL_LCPLL_1350: |
| 823 | link_clock = 135000; |
| 824 | break; |
| 825 | case PORT_CLK_SEL_LCPLL_2700: |
| 826 | link_clock = 270000; |
| 827 | break; |
| 828 | case PORT_CLK_SEL_WRPLL1: |
| 829 | link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1); |
| 830 | break; |
| 831 | case PORT_CLK_SEL_WRPLL2: |
| 832 | link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2); |
| 833 | break; |
| 834 | case PORT_CLK_SEL_SPLL: |
| 835 | pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK; |
| 836 | if (pll == SPLL_PLL_FREQ_810MHz) |
| 837 | link_clock = 81000; |
| 838 | else if (pll == SPLL_PLL_FREQ_1350MHz) |
| 839 | link_clock = 135000; |
| 840 | else if (pll == SPLL_PLL_FREQ_2700MHz) |
| 841 | link_clock = 270000; |
| 842 | else { |
| 843 | WARN(1, "bad spll freq\n"); |
| 844 | return; |
| 845 | } |
| 846 | break; |
| 847 | default: |
| 848 | WARN(1, "bad port clock sel\n"); |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | pipe_config->port_clock = link_clock * 2; |
| 853 | |
| 854 | if (pipe_config->has_pch_encoder) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 855 | pipe_config->base.adjusted_mode.crtc_clock = |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 856 | intel_dotclock_calculate(pipe_config->port_clock, |
| 857 | &pipe_config->fdi_m_n); |
| 858 | else if (pipe_config->has_dp_encoder) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 859 | pipe_config->base.adjusted_mode.crtc_clock = |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 860 | intel_dotclock_calculate(pipe_config->port_clock, |
| 861 | &pipe_config->dp_m_n); |
| 862 | else |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 863 | pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock; |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 864 | } |
| 865 | |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 866 | void intel_ddi_clock_get(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 867 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 868 | { |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 869 | struct drm_device *dev = encoder->base.dev; |
| 870 | |
| 871 | if (INTEL_INFO(dev)->gen <= 8) |
| 872 | hsw_ddi_clock_get(encoder, pipe_config); |
| 873 | else |
| 874 | skl_ddi_clock_get(encoder, pipe_config); |
Daniel Vetter | 3d51278a | 2014-07-29 20:57:08 +0200 | [diff] [blame] | 875 | } |
| 876 | |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 877 | static void |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 878 | hsw_ddi_calculate_wrpll(int clock /* in Hz */, |
| 879 | unsigned *r2_out, unsigned *n2_out, unsigned *p_out) |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 880 | { |
| 881 | uint64_t freq2k; |
| 882 | unsigned p, n2, r2; |
| 883 | struct wrpll_rnp best = { 0, 0, 0 }; |
| 884 | unsigned budget; |
| 885 | |
| 886 | freq2k = clock / 100; |
| 887 | |
| 888 | budget = wrpll_get_budget_for_freq(clock); |
| 889 | |
| 890 | /* Special case handling for 540 pixel clock: bypass WR PLL entirely |
| 891 | * and directly pass the LC PLL to it. */ |
| 892 | if (freq2k == 5400000) { |
| 893 | *n2_out = 2; |
| 894 | *p_out = 1; |
| 895 | *r2_out = 2; |
| 896 | return; |
| 897 | } |
| 898 | |
| 899 | /* |
| 900 | * Ref = LC_FREQ / R, where Ref is the actual reference input seen by |
| 901 | * the WR PLL. |
| 902 | * |
| 903 | * We want R so that REF_MIN <= Ref <= REF_MAX. |
| 904 | * Injecting R2 = 2 * R gives: |
| 905 | * REF_MAX * r2 > LC_FREQ * 2 and |
| 906 | * REF_MIN * r2 < LC_FREQ * 2 |
| 907 | * |
| 908 | * Which means the desired boundaries for r2 are: |
| 909 | * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN |
| 910 | * |
| 911 | */ |
| 912 | for (r2 = LC_FREQ * 2 / REF_MAX + 1; |
| 913 | r2 <= LC_FREQ * 2 / REF_MIN; |
| 914 | r2++) { |
| 915 | |
| 916 | /* |
| 917 | * VCO = N * Ref, that is: VCO = N * LC_FREQ / R |
| 918 | * |
| 919 | * Once again we want VCO_MIN <= VCO <= VCO_MAX. |
| 920 | * Injecting R2 = 2 * R and N2 = 2 * N, we get: |
| 921 | * VCO_MAX * r2 > n2 * LC_FREQ and |
| 922 | * VCO_MIN * r2 < n2 * LC_FREQ) |
| 923 | * |
| 924 | * Which means the desired boundaries for n2 are: |
| 925 | * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ |
| 926 | */ |
| 927 | for (n2 = VCO_MIN * r2 / LC_FREQ + 1; |
| 928 | n2 <= VCO_MAX * r2 / LC_FREQ; |
| 929 | n2++) { |
| 930 | |
| 931 | for (p = P_MIN; p <= P_MAX; p += P_INC) |
| 932 | wrpll_update_rnp(freq2k, budget, |
| 933 | r2, n2, p, &best); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | *n2_out = best.n2; |
| 938 | *p_out = best.p; |
| 939 | *r2_out = best.r2; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 940 | } |
| 941 | |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 942 | static bool |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 943 | hsw_ddi_pll_select(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 944 | struct intel_crtc_state *crtc_state, |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 945 | struct intel_encoder *intel_encoder, |
| 946 | int clock) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 947 | { |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 948 | if (intel_encoder->type == INTEL_OUTPUT_HDMI) { |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 949 | struct intel_shared_dpll *pll; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 950 | uint32_t val; |
Damien Lespiau | 1c0b85c | 2013-05-10 14:01:51 +0100 | [diff] [blame] | 951 | unsigned p, n2, r2; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 952 | |
Damien Lespiau | d664c0c | 2014-07-29 18:06:23 +0100 | [diff] [blame] | 953 | hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 954 | |
Daniel Vetter | 114fe48 | 2014-06-25 22:01:48 +0300 | [diff] [blame] | 955 | val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 956 | WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) | |
| 957 | WRPLL_DIVIDER_POST(p); |
| 958 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 959 | crtc_state->dpll_hw_state.wrpll = val; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 960 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 961 | pll = intel_get_shared_dpll(intel_crtc, crtc_state); |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 962 | if (pll == NULL) { |
| 963 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 964 | pipe_name(intel_crtc->pipe)); |
Paulo Zanoni | 0694001 | 2013-10-30 18:27:43 -0200 | [diff] [blame] | 965 | return false; |
| 966 | } |
| 967 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 968 | crtc_state->ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 969 | } |
| 970 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 971 | return true; |
| 972 | } |
| 973 | |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 974 | struct skl_wrpll_params { |
| 975 | uint32_t dco_fraction; |
| 976 | uint32_t dco_integer; |
| 977 | uint32_t qdiv_ratio; |
| 978 | uint32_t qdiv_mode; |
| 979 | uint32_t kdiv; |
| 980 | uint32_t pdiv; |
| 981 | uint32_t central_freq; |
| 982 | }; |
| 983 | |
| 984 | static void |
| 985 | skl_ddi_calculate_wrpll(int clock /* in Hz */, |
| 986 | struct skl_wrpll_params *wrpll_params) |
| 987 | { |
| 988 | uint64_t afe_clock = clock * 5; /* AFE Clock is 5x Pixel clock */ |
Damien Lespiau | 21318cc | 2014-11-14 14:20:27 +0000 | [diff] [blame] | 989 | uint64_t dco_central_freq[3] = {8400000000ULL, |
| 990 | 9000000000ULL, |
| 991 | 9600000000ULL}; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 992 | uint32_t min_dco_deviation = 400; |
| 993 | uint32_t min_dco_index = 3; |
| 994 | uint32_t P0[4] = {1, 2, 3, 7}; |
| 995 | uint32_t P2[4] = {1, 2, 3, 5}; |
| 996 | bool found = false; |
| 997 | uint32_t candidate_p = 0; |
| 998 | uint32_t candidate_p0[3] = {0}, candidate_p1[3] = {0}; |
| 999 | uint32_t candidate_p2[3] = {0}; |
| 1000 | uint32_t dco_central_freq_deviation[3]; |
| 1001 | uint32_t i, P1, k, dco_count; |
| 1002 | bool retry_with_odd = false; |
| 1003 | uint64_t dco_freq; |
| 1004 | |
| 1005 | /* Determine P0, P1 or P2 */ |
| 1006 | for (dco_count = 0; dco_count < 3; dco_count++) { |
| 1007 | found = false; |
| 1008 | candidate_p = |
| 1009 | div64_u64(dco_central_freq[dco_count], afe_clock); |
| 1010 | if (retry_with_odd == false) |
| 1011 | candidate_p = (candidate_p % 2 == 0 ? |
| 1012 | candidate_p : candidate_p + 1); |
| 1013 | |
| 1014 | for (P1 = 1; P1 < candidate_p; P1++) { |
| 1015 | for (i = 0; i < 4; i++) { |
| 1016 | if (!(P0[i] != 1 || P1 == 1)) |
| 1017 | continue; |
| 1018 | |
| 1019 | for (k = 0; k < 4; k++) { |
| 1020 | if (P1 != 1 && P2[k] != 2) |
| 1021 | continue; |
| 1022 | |
| 1023 | if (candidate_p == P0[i] * P1 * P2[k]) { |
| 1024 | /* Found possible P0, P1, P2 */ |
| 1025 | found = true; |
| 1026 | candidate_p0[dco_count] = P0[i]; |
| 1027 | candidate_p1[dco_count] = P1; |
| 1028 | candidate_p2[dco_count] = P2[k]; |
| 1029 | goto found; |
| 1030 | } |
| 1031 | |
| 1032 | } |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | found: |
| 1037 | if (found) { |
| 1038 | dco_central_freq_deviation[dco_count] = |
| 1039 | div64_u64(10000 * |
| 1040 | abs_diff((candidate_p * afe_clock), |
| 1041 | dco_central_freq[dco_count]), |
| 1042 | dco_central_freq[dco_count]); |
| 1043 | |
| 1044 | if (dco_central_freq_deviation[dco_count] < |
| 1045 | min_dco_deviation) { |
| 1046 | min_dco_deviation = |
| 1047 | dco_central_freq_deviation[dco_count]; |
| 1048 | min_dco_index = dco_count; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | if (min_dco_index > 2 && dco_count == 2) { |
| 1053 | retry_with_odd = true; |
| 1054 | dco_count = 0; |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | if (min_dco_index > 2) { |
| 1059 | WARN(1, "No valid values found for the given pixel clock\n"); |
| 1060 | } else { |
| 1061 | wrpll_params->central_freq = dco_central_freq[min_dco_index]; |
| 1062 | |
| 1063 | switch (dco_central_freq[min_dco_index]) { |
Damien Lespiau | 21318cc | 2014-11-14 14:20:27 +0000 | [diff] [blame] | 1064 | case 9600000000ULL: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1065 | wrpll_params->central_freq = 0; |
| 1066 | break; |
Damien Lespiau | 21318cc | 2014-11-14 14:20:27 +0000 | [diff] [blame] | 1067 | case 9000000000ULL: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1068 | wrpll_params->central_freq = 1; |
| 1069 | break; |
Damien Lespiau | 21318cc | 2014-11-14 14:20:27 +0000 | [diff] [blame] | 1070 | case 8400000000ULL: |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1071 | wrpll_params->central_freq = 3; |
| 1072 | } |
| 1073 | |
| 1074 | switch (candidate_p0[min_dco_index]) { |
| 1075 | case 1: |
| 1076 | wrpll_params->pdiv = 0; |
| 1077 | break; |
| 1078 | case 2: |
| 1079 | wrpll_params->pdiv = 1; |
| 1080 | break; |
| 1081 | case 3: |
| 1082 | wrpll_params->pdiv = 2; |
| 1083 | break; |
| 1084 | case 7: |
| 1085 | wrpll_params->pdiv = 4; |
| 1086 | break; |
| 1087 | default: |
| 1088 | WARN(1, "Incorrect PDiv\n"); |
| 1089 | } |
| 1090 | |
| 1091 | switch (candidate_p2[min_dco_index]) { |
| 1092 | case 5: |
| 1093 | wrpll_params->kdiv = 0; |
| 1094 | break; |
| 1095 | case 2: |
| 1096 | wrpll_params->kdiv = 1; |
| 1097 | break; |
| 1098 | case 3: |
| 1099 | wrpll_params->kdiv = 2; |
| 1100 | break; |
| 1101 | case 1: |
| 1102 | wrpll_params->kdiv = 3; |
| 1103 | break; |
| 1104 | default: |
| 1105 | WARN(1, "Incorrect KDiv\n"); |
| 1106 | } |
| 1107 | |
| 1108 | wrpll_params->qdiv_ratio = candidate_p1[min_dco_index]; |
| 1109 | wrpll_params->qdiv_mode = |
| 1110 | (wrpll_params->qdiv_ratio == 1) ? 0 : 1; |
| 1111 | |
| 1112 | dco_freq = candidate_p0[min_dco_index] * |
| 1113 | candidate_p1[min_dco_index] * |
| 1114 | candidate_p2[min_dco_index] * afe_clock; |
| 1115 | |
| 1116 | /* |
| 1117 | * Intermediate values are in Hz. |
| 1118 | * Divide by MHz to match bsepc |
| 1119 | */ |
| 1120 | wrpll_params->dco_integer = div_u64(dco_freq, (24 * MHz(1))); |
| 1121 | wrpll_params->dco_fraction = |
| 1122 | div_u64(((div_u64(dco_freq, 24) - |
| 1123 | wrpll_params->dco_integer * MHz(1)) * 0x8000), MHz(1)); |
| 1124 | |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | static bool |
| 1130 | skl_ddi_pll_select(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1131 | struct intel_crtc_state *crtc_state, |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1132 | struct intel_encoder *intel_encoder, |
| 1133 | int clock) |
| 1134 | { |
| 1135 | struct intel_shared_dpll *pll; |
| 1136 | uint32_t ctrl1, cfgcr1, cfgcr2; |
| 1137 | |
| 1138 | /* |
| 1139 | * See comment in intel_dpll_hw_state to understand why we always use 0 |
| 1140 | * as the DPLL id in this function. |
| 1141 | */ |
| 1142 | |
| 1143 | ctrl1 = DPLL_CTRL1_OVERRIDE(0); |
| 1144 | |
| 1145 | if (intel_encoder->type == INTEL_OUTPUT_HDMI) { |
| 1146 | struct skl_wrpll_params wrpll_params = { 0, }; |
| 1147 | |
| 1148 | ctrl1 |= DPLL_CTRL1_HDMI_MODE(0); |
| 1149 | |
| 1150 | skl_ddi_calculate_wrpll(clock * 1000, &wrpll_params); |
| 1151 | |
| 1152 | cfgcr1 = DPLL_CFGCR1_FREQ_ENABLE | |
| 1153 | DPLL_CFGCR1_DCO_FRACTION(wrpll_params.dco_fraction) | |
| 1154 | wrpll_params.dco_integer; |
| 1155 | |
| 1156 | cfgcr2 = DPLL_CFGCR2_QDIV_RATIO(wrpll_params.qdiv_ratio) | |
| 1157 | DPLL_CFGCR2_QDIV_MODE(wrpll_params.qdiv_mode) | |
| 1158 | DPLL_CFGCR2_KDIV(wrpll_params.kdiv) | |
| 1159 | DPLL_CFGCR2_PDIV(wrpll_params.pdiv) | |
| 1160 | wrpll_params.central_freq; |
| 1161 | } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) { |
| 1162 | struct drm_encoder *encoder = &intel_encoder->base; |
| 1163 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1164 | |
| 1165 | switch (intel_dp->link_bw) { |
| 1166 | case DP_LINK_BW_1_62: |
| 1167 | ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_810, 0); |
| 1168 | break; |
| 1169 | case DP_LINK_BW_2_7: |
| 1170 | ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_1350, 0); |
| 1171 | break; |
| 1172 | case DP_LINK_BW_5_4: |
| 1173 | ctrl1 |= DPLL_CRTL1_LINK_RATE(DPLL_CRTL1_LINK_RATE_2700, 0); |
| 1174 | break; |
| 1175 | } |
| 1176 | |
| 1177 | cfgcr1 = cfgcr2 = 0; |
| 1178 | } else /* eDP */ |
| 1179 | return true; |
| 1180 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1181 | crtc_state->dpll_hw_state.ctrl1 = ctrl1; |
| 1182 | crtc_state->dpll_hw_state.cfgcr1 = cfgcr1; |
| 1183 | crtc_state->dpll_hw_state.cfgcr2 = cfgcr2; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1184 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1185 | pll = intel_get_shared_dpll(intel_crtc, crtc_state); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1186 | if (pll == NULL) { |
| 1187 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 1188 | pipe_name(intel_crtc->pipe)); |
| 1189 | return false; |
| 1190 | } |
| 1191 | |
| 1192 | /* shared DPLL id 0 is DPLL 1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1193 | crtc_state->ddi_pll_sel = pll->id + 1; |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1194 | |
| 1195 | return true; |
| 1196 | } |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1197 | |
| 1198 | /* |
| 1199 | * Tries to find a *shared* PLL for the CRTC and store it in |
| 1200 | * intel_crtc->ddi_pll_sel. |
| 1201 | * |
| 1202 | * For private DPLLs, compute_config() should do the selection for us. This |
| 1203 | * function should be folded into compute_config() eventually. |
| 1204 | */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1205 | bool intel_ddi_pll_select(struct intel_crtc *intel_crtc, |
| 1206 | struct intel_crtc_state *crtc_state) |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1207 | { |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1208 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 1209 | struct intel_encoder *intel_encoder = |
| 1210 | intel_ddi_get_crtc_new_encoder(intel_crtc); |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1211 | int clock = crtc_state->port_clock; |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1212 | |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1213 | if (IS_SKYLAKE(dev)) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1214 | return skl_ddi_pll_select(intel_crtc, crtc_state, |
| 1215 | intel_encoder, clock); |
Satheeshakrishna M | 82d3543 | 2014-11-13 14:55:20 +0000 | [diff] [blame] | 1216 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 1217 | return hsw_ddi_pll_select(intel_crtc, crtc_state, |
| 1218 | intel_encoder, clock); |
Damien Lespiau | 0220ab6 | 2014-07-29 18:06:22 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1221 | void intel_ddi_set_pipe_settings(struct drm_crtc *crtc) |
| 1222 | { |
| 1223 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1224 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1225 | 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] | 1226 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1227 | int type = intel_encoder->type; |
| 1228 | uint32_t temp; |
| 1229 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1230 | 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] | 1231 | temp = TRANS_MSA_SYNC_CLK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1232 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1233 | case 18: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1234 | temp |= TRANS_MSA_6_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1235 | break; |
| 1236 | case 24: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1237 | temp |= TRANS_MSA_8_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1238 | break; |
| 1239 | case 30: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1240 | temp |= TRANS_MSA_10_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1241 | break; |
| 1242 | case 36: |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1243 | temp |= TRANS_MSA_12_BPC; |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1244 | break; |
| 1245 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 1246 | BUG(); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1247 | } |
Paulo Zanoni | c980979 | 2012-10-23 18:30:00 -0200 | [diff] [blame] | 1248 | I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp); |
Paulo Zanoni | dae8479 | 2012-10-15 15:51:30 -0300 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1252 | void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state) |
| 1253 | { |
| 1254 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1255 | struct drm_device *dev = crtc->dev; |
| 1256 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1257 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1258 | uint32_t temp; |
| 1259 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1260 | if (state == true) |
| 1261 | temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC; |
| 1262 | else |
| 1263 | temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC; |
| 1264 | I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); |
| 1265 | } |
| 1266 | |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 1267 | void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1268 | { |
| 1269 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1270 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1271 | struct drm_encoder *encoder = &intel_encoder->base; |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 1272 | struct drm_device *dev = crtc->dev; |
| 1273 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1274 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1275 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1276 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1277 | int type = intel_encoder->type; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1278 | uint32_t temp; |
| 1279 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1280 | /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */ |
| 1281 | temp = TRANS_DDI_FUNC_ENABLE; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1282 | temp |= TRANS_DDI_SELECT_PORT(port); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1283 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1284 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1285 | case 18: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1286 | temp |= TRANS_DDI_BPC_6; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1287 | break; |
| 1288 | case 24: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1289 | temp |= TRANS_DDI_BPC_8; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1290 | break; |
| 1291 | case 30: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1292 | temp |= TRANS_DDI_BPC_10; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1293 | break; |
| 1294 | case 36: |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1295 | temp |= TRANS_DDI_BPC_12; |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1296 | break; |
| 1297 | default: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 1298 | BUG(); |
Paulo Zanoni | dfcef25 | 2012-08-08 14:15:29 -0300 | [diff] [blame] | 1299 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1300 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1301 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1302 | temp |= TRANS_DDI_PVSYNC; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1303 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1304 | temp |= TRANS_DDI_PHSYNC; |
Paulo Zanoni | f63eb7c | 2012-08-08 14:15:28 -0300 | [diff] [blame] | 1305 | |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 1306 | if (cpu_transcoder == TRANSCODER_EDP) { |
| 1307 | switch (pipe) { |
| 1308 | case PIPE_A: |
Paulo Zanoni | c7670b1 | 2013-11-02 21:07:37 -0700 | [diff] [blame] | 1309 | /* On Haswell, can only use the always-on power well for |
| 1310 | * eDP when not using the panel fitter, and when not |
| 1311 | * using motion blur mitigation (which we don't |
| 1312 | * support). */ |
Daniel Vetter | fabf6e5 | 2014-05-29 14:10:22 +0200 | [diff] [blame] | 1313 | if (IS_HASWELL(dev) && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1314 | (intel_crtc->config->pch_pfit.enabled || |
| 1315 | intel_crtc->config->pch_pfit.force_thru)) |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 1316 | temp |= TRANS_DDI_EDP_INPUT_A_ONOFF; |
| 1317 | else |
| 1318 | temp |= TRANS_DDI_EDP_INPUT_A_ON; |
Paulo Zanoni | e6f0bfc | 2012-10-23 18:30:04 -0200 | [diff] [blame] | 1319 | break; |
| 1320 | case PIPE_B: |
| 1321 | temp |= TRANS_DDI_EDP_INPUT_B_ONOFF; |
| 1322 | break; |
| 1323 | case PIPE_C: |
| 1324 | temp |= TRANS_DDI_EDP_INPUT_C_ONOFF; |
| 1325 | break; |
| 1326 | default: |
| 1327 | BUG(); |
| 1328 | break; |
| 1329 | } |
| 1330 | } |
| 1331 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1332 | if (type == INTEL_OUTPUT_HDMI) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1333 | if (intel_crtc->config->has_hdmi_sink) |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1334 | temp |= TRANS_DDI_MODE_SELECT_HDMI; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1335 | else |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1336 | temp |= TRANS_DDI_MODE_SELECT_DVI; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1337 | |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1338 | } else if (type == INTEL_OUTPUT_ANALOG) { |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1339 | temp |= TRANS_DDI_MODE_SELECT_FDI; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1340 | temp |= (intel_crtc->config->fdi_lanes - 1) << 1; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1341 | |
| 1342 | } else if (type == INTEL_OUTPUT_DISPLAYPORT || |
| 1343 | type == INTEL_OUTPUT_EDP) { |
| 1344 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1345 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1346 | if (intel_dp->is_mst) { |
| 1347 | temp |= TRANS_DDI_MODE_SELECT_DP_MST; |
| 1348 | } else |
| 1349 | temp |= TRANS_DDI_MODE_SELECT_DP_SST; |
| 1350 | |
| 1351 | temp |= DDI_PORT_WIDTH(intel_dp->lane_count); |
| 1352 | } else if (type == INTEL_OUTPUT_DP_MST) { |
| 1353 | struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp; |
| 1354 | |
| 1355 | if (intel_dp->is_mst) { |
| 1356 | temp |= TRANS_DDI_MODE_SELECT_DP_MST; |
| 1357 | } else |
| 1358 | temp |= TRANS_DDI_MODE_SELECT_DP_SST; |
Paulo Zanoni | 7739c33 | 2012-10-15 15:51:29 -0300 | [diff] [blame] | 1359 | |
Daniel Vetter | 17aa6be | 2013-04-30 14:01:40 +0200 | [diff] [blame] | 1360 | temp |= DDI_PORT_WIDTH(intel_dp->lane_count); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1361 | } else { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1362 | WARN(1, "Invalid encoder type %d for pipe %c\n", |
| 1363 | intel_encoder->type, pipe_name(pipe)); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1364 | } |
| 1365 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1366 | I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1367 | } |
| 1368 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1369 | void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv, |
| 1370 | enum transcoder cpu_transcoder) |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1371 | { |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1372 | uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1373 | uint32_t val = I915_READ(reg); |
| 1374 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1375 | 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] | 1376 | val |= TRANS_DDI_PORT_NONE; |
Paulo Zanoni | 8d9ddbc | 2012-10-05 12:05:53 -0300 | [diff] [blame] | 1377 | I915_WRITE(reg, val); |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1378 | } |
| 1379 | |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1380 | bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector) |
| 1381 | { |
| 1382 | struct drm_device *dev = intel_connector->base.dev; |
| 1383 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1384 | struct intel_encoder *intel_encoder = intel_connector->encoder; |
| 1385 | int type = intel_connector->base.connector_type; |
| 1386 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1387 | enum pipe pipe = 0; |
| 1388 | enum transcoder cpu_transcoder; |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1389 | enum intel_display_power_domain power_domain; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1390 | uint32_t tmp; |
| 1391 | |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1392 | power_domain = intel_display_port_power_domain(intel_encoder); |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1393 | if (!intel_display_power_is_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 882244a | 2014-04-01 14:55:12 -0300 | [diff] [blame] | 1394 | return false; |
| 1395 | |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1396 | if (!intel_encoder->get_hw_state(intel_encoder, &pipe)) |
| 1397 | return false; |
| 1398 | |
| 1399 | if (port == PORT_A) |
| 1400 | cpu_transcoder = TRANSCODER_EDP; |
| 1401 | else |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1402 | cpu_transcoder = (enum transcoder) pipe; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1403 | |
| 1404 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 1405 | |
| 1406 | switch (tmp & TRANS_DDI_MODE_SELECT_MASK) { |
| 1407 | case TRANS_DDI_MODE_SELECT_HDMI: |
| 1408 | case TRANS_DDI_MODE_SELECT_DVI: |
| 1409 | return (type == DRM_MODE_CONNECTOR_HDMIA); |
| 1410 | |
| 1411 | case TRANS_DDI_MODE_SELECT_DP_SST: |
| 1412 | if (type == DRM_MODE_CONNECTOR_eDP) |
| 1413 | return true; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1414 | return (type == DRM_MODE_CONNECTOR_DisplayPort); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1415 | case TRANS_DDI_MODE_SELECT_DP_MST: |
| 1416 | /* if the transcoder is in MST state then |
| 1417 | * connector isn't connected */ |
| 1418 | return false; |
Paulo Zanoni | bcbc889 | 2012-10-26 19:05:51 -0200 | [diff] [blame] | 1419 | |
| 1420 | case TRANS_DDI_MODE_SELECT_FDI: |
| 1421 | return (type == DRM_MODE_CONNECTOR_VGA); |
| 1422 | |
| 1423 | default: |
| 1424 | return false; |
| 1425 | } |
| 1426 | } |
| 1427 | |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1428 | bool intel_ddi_get_hw_state(struct intel_encoder *encoder, |
| 1429 | enum pipe *pipe) |
| 1430 | { |
| 1431 | struct drm_device *dev = encoder->base.dev; |
| 1432 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1433 | enum port port = intel_ddi_get_encoder_port(encoder); |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1434 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1435 | u32 tmp; |
| 1436 | int i; |
| 1437 | |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1438 | power_domain = intel_display_port_power_domain(encoder); |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1439 | if (!intel_display_power_is_enabled(dev_priv, power_domain)) |
Imre Deak | 6d129be | 2014-03-05 16:20:54 +0200 | [diff] [blame] | 1440 | return false; |
| 1441 | |
Paulo Zanoni | fe43d3f | 2012-10-15 15:51:39 -0300 | [diff] [blame] | 1442 | tmp = I915_READ(DDI_BUF_CTL(port)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1443 | |
| 1444 | if (!(tmp & DDI_BUF_CTL_ENABLE)) |
| 1445 | return false; |
| 1446 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1447 | if (port == PORT_A) { |
| 1448 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1449 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1450 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 1451 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 1452 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 1453 | *pipe = PIPE_A; |
| 1454 | break; |
| 1455 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 1456 | *pipe = PIPE_B; |
| 1457 | break; |
| 1458 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 1459 | *pipe = PIPE_C; |
| 1460 | break; |
| 1461 | } |
| 1462 | |
| 1463 | return true; |
| 1464 | } else { |
| 1465 | for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) { |
| 1466 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(i)); |
| 1467 | |
| 1468 | if ((tmp & TRANS_DDI_PORT_MASK) |
| 1469 | == TRANS_DDI_SELECT_PORT(port)) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 1470 | if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST) |
| 1471 | return false; |
| 1472 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1473 | *pipe = i; |
| 1474 | return true; |
| 1475 | } |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1479 | 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] | 1480 | |
Jesse Barnes | 22f9fe5 | 2013-04-02 10:03:55 -0700 | [diff] [blame] | 1481 | return false; |
Daniel Vetter | 85234cd | 2012-07-02 13:27:29 +0200 | [diff] [blame] | 1482 | } |
| 1483 | |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1484 | void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1485 | { |
| 1486 | struct drm_crtc *crtc = &intel_crtc->base; |
| 1487 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 1488 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 1489 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1490 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1491 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1492 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1493 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1494 | TRANS_CLK_SEL_PORT(port)); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc) |
| 1498 | { |
| 1499 | 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] | 1500 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1501 | |
Paulo Zanoni | bb523fc | 2012-10-23 18:29:56 -0200 | [diff] [blame] | 1502 | if (cpu_transcoder != TRANSCODER_EDP) |
| 1503 | I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), |
| 1504 | TRANS_CLK_SEL_DISABLED); |
Paulo Zanoni | fc91463 | 2012-10-05 12:05:54 -0300 | [diff] [blame] | 1505 | } |
| 1506 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1507 | static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1508 | { |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1509 | struct drm_encoder *encoder = &intel_encoder->base; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1510 | struct drm_device *dev = encoder->dev; |
| 1511 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1512 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1513 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1514 | int type = intel_encoder->type; |
| 1515 | |
| 1516 | if (type == INTEL_OUTPUT_EDP) { |
| 1517 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1518 | intel_edp_panel_on(intel_dp); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1519 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1520 | |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1521 | if (IS_SKYLAKE(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1522 | uint32_t dpll = crtc->config->ddi_pll_sel; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1523 | uint32_t val; |
| 1524 | |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1525 | /* |
| 1526 | * DPLL0 is used for eDP and is the only "private" DPLL (as |
| 1527 | * opposed to shared) on SKL |
| 1528 | */ |
| 1529 | if (type == INTEL_OUTPUT_EDP) { |
| 1530 | WARN_ON(dpll != SKL_DPLL0); |
| 1531 | |
| 1532 | val = I915_READ(DPLL_CTRL1); |
| 1533 | |
| 1534 | val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) | |
| 1535 | DPLL_CTRL1_SSC(dpll) | |
| 1536 | DPLL_CRTL1_LINK_RATE_MASK(dpll)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1537 | val |= crtc->config->dpll_hw_state.ctrl1 << (dpll * 6); |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1538 | |
| 1539 | I915_WRITE(DPLL_CTRL1, val); |
| 1540 | POSTING_READ(DPLL_CTRL1); |
| 1541 | } |
| 1542 | |
| 1543 | /* DDI -> PLL mapping */ |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1544 | val = I915_READ(DPLL_CTRL2); |
| 1545 | |
| 1546 | val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) | |
| 1547 | DPLL_CTRL2_DDI_CLK_SEL_MASK(port)); |
| 1548 | val |= (DPLL_CTRL2_DDI_CLK_SEL(dpll, port) | |
| 1549 | DPLL_CTRL2_DDI_SEL_OVERRIDE(port)); |
| 1550 | |
| 1551 | I915_WRITE(DPLL_CTRL2, val); |
Damien Lespiau | 5416d87 | 2014-11-14 17:24:33 +0000 | [diff] [blame] | 1552 | |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1553 | } else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1554 | WARN_ON(crtc->config->ddi_pll_sel == PORT_CLK_SEL_NONE); |
| 1555 | I915_WRITE(PORT_CLK_SEL(port), crtc->config->ddi_pll_sel); |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1556 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1557 | |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1558 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1559 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1560 | |
Dave Airlie | 44905a2 | 2014-05-02 13:36:43 +1000 | [diff] [blame] | 1561 | intel_ddi_init_dp_buf_reg(intel_encoder); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1562 | |
| 1563 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); |
| 1564 | intel_dp_start_link_train(intel_dp); |
| 1565 | intel_dp_complete_link_train(intel_dp); |
Vandana Kannan | 23f08d8 | 2014-11-13 14:55:22 +0000 | [diff] [blame] | 1566 | if (port != PORT_A || INTEL_INFO(dev)->gen >= 9) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 1567 | intel_dp_stop_link_train(intel_dp); |
Daniel Vetter | 30cf6db | 2014-04-24 23:54:58 +0200 | [diff] [blame] | 1568 | } else if (type == INTEL_OUTPUT_HDMI) { |
| 1569 | struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); |
| 1570 | |
| 1571 | intel_hdmi->set_infoframes(encoder, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1572 | crtc->config->has_hdmi_sink, |
| 1573 | &crtc->config->base.adjusted_mode); |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1574 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1575 | } |
| 1576 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1577 | static void intel_ddi_post_disable(struct intel_encoder *intel_encoder) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1578 | { |
| 1579 | struct drm_encoder *encoder = &intel_encoder->base; |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1580 | struct drm_device *dev = encoder->dev; |
| 1581 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1582 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1583 | int type = intel_encoder->type; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1584 | uint32_t val; |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1585 | bool wait = false; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1586 | |
| 1587 | val = I915_READ(DDI_BUF_CTL(port)); |
| 1588 | if (val & DDI_BUF_CTL_ENABLE) { |
| 1589 | val &= ~DDI_BUF_CTL_ENABLE; |
| 1590 | I915_WRITE(DDI_BUF_CTL(port), val); |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1591 | wait = true; |
Paulo Zanoni | 2886e93 | 2012-10-05 12:06:00 -0300 | [diff] [blame] | 1592 | } |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1593 | |
Paulo Zanoni | a836bdf | 2012-10-15 15:51:32 -0300 | [diff] [blame] | 1594 | val = I915_READ(DP_TP_CTL(port)); |
| 1595 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 1596 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 1597 | I915_WRITE(DP_TP_CTL(port), val); |
| 1598 | |
| 1599 | if (wait) |
| 1600 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 1601 | |
Jani Nikula | 76bb80e | 2013-11-15 15:29:57 +0200 | [diff] [blame] | 1602 | if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) { |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1603 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
Jani Nikula | 76bb80e | 2013-11-15 15:29:57 +0200 | [diff] [blame] | 1604 | intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); |
Jani Nikula | 24f3e09 | 2014-03-17 16:43:36 +0200 | [diff] [blame] | 1605 | intel_edp_panel_vdd_on(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1606 | intel_edp_panel_off(intel_dp); |
Paulo Zanoni | 82a4d9c | 2012-10-23 18:30:07 -0200 | [diff] [blame] | 1607 | } |
| 1608 | |
Satheeshakrishna M | efa80ad | 2014-11-13 14:55:19 +0000 | [diff] [blame] | 1609 | if (IS_SKYLAKE(dev)) |
| 1610 | I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) | |
| 1611 | DPLL_CTRL2_DDI_CLK_OFF(port))); |
| 1612 | else |
| 1613 | I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE); |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 1614 | } |
| 1615 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1616 | static void intel_enable_ddi(struct intel_encoder *intel_encoder) |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1617 | { |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1618 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1619 | struct drm_crtc *crtc = encoder->crtc; |
| 1620 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1621 | struct drm_device *dev = encoder->dev; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1622 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1623 | enum port port = intel_ddi_get_encoder_port(intel_encoder); |
| 1624 | int type = intel_encoder->type; |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1625 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1626 | if (type == INTEL_OUTPUT_HDMI) { |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1627 | struct intel_digital_port *intel_dig_port = |
| 1628 | enc_to_dig_port(encoder); |
| 1629 | |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1630 | /* In HDMI/DVI mode, the port width, and swing/emphasis values |
| 1631 | * are ignored so nothing special needs to be done besides |
| 1632 | * enabling the port. |
| 1633 | */ |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 1634 | I915_WRITE(DDI_BUF_CTL(port), |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 1635 | intel_dig_port->saved_port_bits | |
| 1636 | DDI_BUF_CTL_ENABLE); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1637 | } else if (type == INTEL_OUTPUT_EDP) { |
| 1638 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1639 | |
Vandana Kannan | 23f08d8 | 2014-11-13 14:55:22 +0000 | [diff] [blame] | 1640 | if (port == PORT_A && INTEL_INFO(dev)->gen < 9) |
Imre Deak | 3ab9c63 | 2013-05-03 12:57:41 +0300 | [diff] [blame] | 1641 | intel_dp_stop_link_train(intel_dp); |
| 1642 | |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1643 | intel_edp_backlight_on(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 1644 | intel_psr_enable(intel_dp); |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 1645 | intel_edp_drrs_enable(intel_dp); |
Paulo Zanoni | 6547fef | 2012-10-15 15:51:40 -0300 | [diff] [blame] | 1646 | } |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1647 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1648 | if (intel_crtc->config->has_audio) { |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 1649 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 1650 | intel_audio_codec_enable(intel_encoder); |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1651 | } |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1652 | } |
| 1653 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 1654 | static void intel_disable_ddi(struct intel_encoder *intel_encoder) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 1655 | { |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1656 | struct drm_encoder *encoder = &intel_encoder->base; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1657 | struct drm_crtc *crtc = encoder->crtc; |
| 1658 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1659 | int type = intel_encoder->type; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 1660 | struct drm_device *dev = encoder->dev; |
| 1661 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1662 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1663 | if (intel_crtc->config->has_audio) { |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 1664 | intel_audio_codec_disable(intel_encoder); |
Paulo Zanoni | d45a0bf | 2014-05-21 17:29:31 -0300 | [diff] [blame] | 1665 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
| 1666 | } |
Paulo Zanoni | 2831d842 | 2013-03-06 20:03:09 -0300 | [diff] [blame] | 1667 | |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1668 | if (type == INTEL_OUTPUT_EDP) { |
| 1669 | struct intel_dp *intel_dp = enc_to_intel_dp(encoder); |
| 1670 | |
Vandana Kannan | c395578 | 2015-01-22 15:17:40 +0530 | [diff] [blame] | 1671 | intel_edp_drrs_disable(intel_dp); |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 1672 | intel_psr_disable(intel_dp); |
Daniel Vetter | 4be7378 | 2014-01-17 14:39:48 +0100 | [diff] [blame] | 1673 | intel_edp_backlight_off(intel_dp); |
Paulo Zanoni | d6c50ff | 2012-10-23 18:30:06 -0200 | [diff] [blame] | 1674 | } |
Eugeni Dodonov | 72662e1 | 2012-05-09 15:37:31 -0300 | [diff] [blame] | 1675 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1676 | |
Satheeshakrishna M | 121643c | 2014-11-13 14:55:15 +0000 | [diff] [blame] | 1677 | static int skl_get_cdclk_freq(struct drm_i915_private *dev_priv) |
| 1678 | { |
| 1679 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 1680 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 1681 | uint32_t linkrate; |
| 1682 | |
| 1683 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) { |
| 1684 | WARN(1, "LCPLL1 not enabled\n"); |
| 1685 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
| 1686 | } |
| 1687 | |
| 1688 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) |
| 1689 | return 540000; |
| 1690 | |
| 1691 | linkrate = (I915_READ(DPLL_CTRL1) & |
| 1692 | DPLL_CRTL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
| 1693 | |
| 1694 | if (linkrate == DPLL_CRTL1_LINK_RATE_2160 || |
| 1695 | linkrate == DPLL_CRTL1_LINK_RATE_1080) { |
| 1696 | /* vco 8640 */ |
| 1697 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 1698 | case CDCLK_FREQ_450_432: |
| 1699 | return 432000; |
| 1700 | case CDCLK_FREQ_337_308: |
| 1701 | return 308570; |
| 1702 | case CDCLK_FREQ_675_617: |
| 1703 | return 617140; |
| 1704 | default: |
| 1705 | WARN(1, "Unknown cd freq selection\n"); |
| 1706 | } |
| 1707 | } else { |
| 1708 | /* vco 8100 */ |
| 1709 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 1710 | case CDCLK_FREQ_450_432: |
| 1711 | return 450000; |
| 1712 | case CDCLK_FREQ_337_308: |
| 1713 | return 337500; |
| 1714 | case CDCLK_FREQ_675_617: |
| 1715 | return 675000; |
| 1716 | default: |
| 1717 | WARN(1, "Unknown cd freq selection\n"); |
| 1718 | } |
| 1719 | } |
| 1720 | |
| 1721 | /* error case, do as if DPLL0 isn't enabled */ |
| 1722 | return 24000; |
| 1723 | } |
| 1724 | |
Damien Lespiau | ad13d60 | 2014-07-29 18:06:24 +0100 | [diff] [blame] | 1725 | static int bdw_get_cdclk_freq(struct drm_i915_private *dev_priv) |
| 1726 | { |
| 1727 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 1728 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 1729 | |
| 1730 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 1731 | return 800000; |
| 1732 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 1733 | return 450000; |
| 1734 | else if (freq == LCPLL_CLK_FREQ_450) |
| 1735 | return 450000; |
| 1736 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 1737 | return 540000; |
| 1738 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 1739 | return 337500; |
| 1740 | else |
| 1741 | return 675000; |
| 1742 | } |
| 1743 | |
| 1744 | static int hsw_get_cdclk_freq(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1745 | { |
Paulo Zanoni | e39bf98 | 2013-11-02 21:07:36 -0700 | [diff] [blame] | 1746 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | a400664 | 2013-08-06 18:57:11 -0300 | [diff] [blame] | 1747 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
Paulo Zanoni | e39bf98 | 2013-11-02 21:07:36 -0700 | [diff] [blame] | 1748 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
Paulo Zanoni | a400664 | 2013-08-06 18:57:11 -0300 | [diff] [blame] | 1749 | |
Damien Lespiau | ad13d60 | 2014-07-29 18:06:24 +0100 | [diff] [blame] | 1750 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
Paulo Zanoni | a400664 | 2013-08-06 18:57:11 -0300 | [diff] [blame] | 1751 | return 800000; |
Damien Lespiau | ad13d60 | 2014-07-29 18:06:24 +0100 | [diff] [blame] | 1752 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
Paulo Zanoni | b2b877f | 2013-05-03 17:23:42 -0300 | [diff] [blame] | 1753 | return 450000; |
Damien Lespiau | ad13d60 | 2014-07-29 18:06:24 +0100 | [diff] [blame] | 1754 | else if (freq == LCPLL_CLK_FREQ_450) |
Paulo Zanoni | b2b877f | 2013-05-03 17:23:42 -0300 | [diff] [blame] | 1755 | return 450000; |
Damien Lespiau | 95626e7 | 2014-10-01 20:04:16 +0100 | [diff] [blame] | 1756 | else if (IS_HSW_ULT(dev)) |
Damien Lespiau | ad13d60 | 2014-07-29 18:06:24 +0100 | [diff] [blame] | 1757 | return 337500; |
| 1758 | else |
| 1759 | return 540000; |
| 1760 | } |
| 1761 | |
| 1762 | int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv) |
| 1763 | { |
| 1764 | struct drm_device *dev = dev_priv->dev; |
| 1765 | |
Satheeshakrishna M | 121643c | 2014-11-13 14:55:15 +0000 | [diff] [blame] | 1766 | if (IS_SKYLAKE(dev)) |
| 1767 | return skl_get_cdclk_freq(dev_priv); |
| 1768 | |
Damien Lespiau | ad13d60 | 2014-07-29 18:06:24 +0100 | [diff] [blame] | 1769 | if (IS_BROADWELL(dev)) |
| 1770 | return bdw_get_cdclk_freq(dev_priv); |
| 1771 | |
| 1772 | /* Haswell */ |
| 1773 | return hsw_get_cdclk_freq(dev_priv); |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1774 | } |
| 1775 | |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 1776 | static void hsw_ddi_pll_enable(struct drm_i915_private *dev_priv, |
| 1777 | struct intel_shared_dpll *pll) |
| 1778 | { |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1779 | I915_WRITE(WRPLL_CTL(pll->id), pll->config.hw_state.wrpll); |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 1780 | POSTING_READ(WRPLL_CTL(pll->id)); |
| 1781 | udelay(20); |
| 1782 | } |
| 1783 | |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 1784 | static void hsw_ddi_pll_disable(struct drm_i915_private *dev_priv, |
| 1785 | struct intel_shared_dpll *pll) |
| 1786 | { |
| 1787 | uint32_t val; |
| 1788 | |
| 1789 | val = I915_READ(WRPLL_CTL(pll->id)); |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 1790 | I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE); |
| 1791 | POSTING_READ(WRPLL_CTL(pll->id)); |
| 1792 | } |
| 1793 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 1794 | static bool hsw_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, |
| 1795 | struct intel_shared_dpll *pll, |
| 1796 | struct intel_dpll_hw_state *hw_state) |
| 1797 | { |
| 1798 | uint32_t val; |
| 1799 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1800 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 1801 | return false; |
| 1802 | |
| 1803 | val = I915_READ(WRPLL_CTL(pll->id)); |
| 1804 | hw_state->wrpll = val; |
| 1805 | |
| 1806 | return val & WRPLL_PLL_ENABLE; |
| 1807 | } |
| 1808 | |
Damien Lespiau | ca1381b | 2014-07-15 15:05:33 +0100 | [diff] [blame] | 1809 | static const char * const hsw_ddi_pll_names[] = { |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1810 | "WRPLL 1", |
| 1811 | "WRPLL 2", |
| 1812 | }; |
| 1813 | |
Damien Lespiau | 143b307 | 2014-07-29 18:06:19 +0100 | [diff] [blame] | 1814 | static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1815 | { |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1816 | int i; |
| 1817 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 1818 | dev_priv->num_shared_dpll = 2; |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1819 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 1820 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1821 | dev_priv->shared_dplls[i].id = i; |
| 1822 | dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i]; |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 1823 | dev_priv->shared_dplls[i].disable = hsw_ddi_pll_disable; |
Daniel Vetter | e0b01be | 2014-06-25 22:02:01 +0300 | [diff] [blame] | 1824 | dev_priv->shared_dplls[i].enable = hsw_ddi_pll_enable; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 1825 | dev_priv->shared_dplls[i].get_hw_state = |
| 1826 | hsw_ddi_pll_get_hw_state; |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 1827 | } |
Damien Lespiau | 143b307 | 2014-07-29 18:06:19 +0100 | [diff] [blame] | 1828 | } |
| 1829 | |
Satheeshakrishna M | d1a2dc7 | 2014-11-13 14:55:18 +0000 | [diff] [blame] | 1830 | static const char * const skl_ddi_pll_names[] = { |
| 1831 | "DPLL 1", |
| 1832 | "DPLL 2", |
| 1833 | "DPLL 3", |
| 1834 | }; |
| 1835 | |
| 1836 | struct skl_dpll_regs { |
| 1837 | u32 ctl, cfgcr1, cfgcr2; |
| 1838 | }; |
| 1839 | |
| 1840 | /* this array is indexed by the *shared* pll id */ |
| 1841 | static const struct skl_dpll_regs skl_dpll_regs[3] = { |
| 1842 | { |
| 1843 | /* DPLL 1 */ |
| 1844 | .ctl = LCPLL2_CTL, |
| 1845 | .cfgcr1 = DPLL1_CFGCR1, |
| 1846 | .cfgcr2 = DPLL1_CFGCR2, |
| 1847 | }, |
| 1848 | { |
| 1849 | /* DPLL 2 */ |
| 1850 | .ctl = WRPLL_CTL1, |
| 1851 | .cfgcr1 = DPLL2_CFGCR1, |
| 1852 | .cfgcr2 = DPLL2_CFGCR2, |
| 1853 | }, |
| 1854 | { |
| 1855 | /* DPLL 3 */ |
| 1856 | .ctl = WRPLL_CTL2, |
| 1857 | .cfgcr1 = DPLL3_CFGCR1, |
| 1858 | .cfgcr2 = DPLL3_CFGCR2, |
| 1859 | }, |
| 1860 | }; |
| 1861 | |
| 1862 | static void skl_ddi_pll_enable(struct drm_i915_private *dev_priv, |
| 1863 | struct intel_shared_dpll *pll) |
| 1864 | { |
| 1865 | uint32_t val; |
| 1866 | unsigned int dpll; |
| 1867 | const struct skl_dpll_regs *regs = skl_dpll_regs; |
| 1868 | |
| 1869 | /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */ |
| 1870 | dpll = pll->id + 1; |
| 1871 | |
| 1872 | val = I915_READ(DPLL_CTRL1); |
| 1873 | |
| 1874 | val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) | DPLL_CTRL1_SSC(dpll) | |
| 1875 | DPLL_CRTL1_LINK_RATE_MASK(dpll)); |
| 1876 | val |= pll->config.hw_state.ctrl1 << (dpll * 6); |
| 1877 | |
| 1878 | I915_WRITE(DPLL_CTRL1, val); |
| 1879 | POSTING_READ(DPLL_CTRL1); |
| 1880 | |
| 1881 | I915_WRITE(regs[pll->id].cfgcr1, pll->config.hw_state.cfgcr1); |
| 1882 | I915_WRITE(regs[pll->id].cfgcr2, pll->config.hw_state.cfgcr2); |
| 1883 | POSTING_READ(regs[pll->id].cfgcr1); |
| 1884 | POSTING_READ(regs[pll->id].cfgcr2); |
| 1885 | |
| 1886 | /* the enable bit is always bit 31 */ |
| 1887 | I915_WRITE(regs[pll->id].ctl, |
| 1888 | I915_READ(regs[pll->id].ctl) | LCPLL_PLL_ENABLE); |
| 1889 | |
| 1890 | if (wait_for(I915_READ(DPLL_STATUS) & DPLL_LOCK(dpll), 5)) |
| 1891 | DRM_ERROR("DPLL %d not locked\n", dpll); |
| 1892 | } |
| 1893 | |
| 1894 | static void skl_ddi_pll_disable(struct drm_i915_private *dev_priv, |
| 1895 | struct intel_shared_dpll *pll) |
| 1896 | { |
| 1897 | const struct skl_dpll_regs *regs = skl_dpll_regs; |
| 1898 | |
| 1899 | /* the enable bit is always bit 31 */ |
| 1900 | I915_WRITE(regs[pll->id].ctl, |
| 1901 | I915_READ(regs[pll->id].ctl) & ~LCPLL_PLL_ENABLE); |
| 1902 | POSTING_READ(regs[pll->id].ctl); |
| 1903 | } |
| 1904 | |
| 1905 | static bool skl_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv, |
| 1906 | struct intel_shared_dpll *pll, |
| 1907 | struct intel_dpll_hw_state *hw_state) |
| 1908 | { |
| 1909 | uint32_t val; |
| 1910 | unsigned int dpll; |
| 1911 | const struct skl_dpll_regs *regs = skl_dpll_regs; |
| 1912 | |
| 1913 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
| 1914 | return false; |
| 1915 | |
| 1916 | /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */ |
| 1917 | dpll = pll->id + 1; |
| 1918 | |
| 1919 | val = I915_READ(regs[pll->id].ctl); |
| 1920 | if (!(val & LCPLL_PLL_ENABLE)) |
| 1921 | return false; |
| 1922 | |
| 1923 | val = I915_READ(DPLL_CTRL1); |
| 1924 | hw_state->ctrl1 = (val >> (dpll * 6)) & 0x3f; |
| 1925 | |
| 1926 | /* avoid reading back stale values if HDMI mode is not enabled */ |
| 1927 | if (val & DPLL_CTRL1_HDMI_MODE(dpll)) { |
| 1928 | hw_state->cfgcr1 = I915_READ(regs[pll->id].cfgcr1); |
| 1929 | hw_state->cfgcr2 = I915_READ(regs[pll->id].cfgcr2); |
| 1930 | } |
| 1931 | |
| 1932 | return true; |
| 1933 | } |
| 1934 | |
| 1935 | static void skl_shared_dplls_init(struct drm_i915_private *dev_priv) |
| 1936 | { |
| 1937 | int i; |
| 1938 | |
| 1939 | dev_priv->num_shared_dpll = 3; |
| 1940 | |
| 1941 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 1942 | dev_priv->shared_dplls[i].id = i; |
| 1943 | dev_priv->shared_dplls[i].name = skl_ddi_pll_names[i]; |
| 1944 | dev_priv->shared_dplls[i].disable = skl_ddi_pll_disable; |
| 1945 | dev_priv->shared_dplls[i].enable = skl_ddi_pll_enable; |
| 1946 | dev_priv->shared_dplls[i].get_hw_state = |
| 1947 | skl_ddi_pll_get_hw_state; |
| 1948 | } |
| 1949 | } |
| 1950 | |
Damien Lespiau | 143b307 | 2014-07-29 18:06:19 +0100 | [diff] [blame] | 1951 | void intel_ddi_pll_init(struct drm_device *dev) |
| 1952 | { |
| 1953 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1954 | uint32_t val = I915_READ(LCPLL_CTL); |
| 1955 | |
Satheeshakrishna M | d1a2dc7 | 2014-11-13 14:55:18 +0000 | [diff] [blame] | 1956 | if (IS_SKYLAKE(dev)) |
| 1957 | skl_shared_dplls_init(dev_priv); |
| 1958 | else |
| 1959 | hsw_shared_dplls_init(dev_priv); |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1960 | |
Paulo Zanoni | b2b877f | 2013-05-03 17:23:42 -0300 | [diff] [blame] | 1961 | DRM_DEBUG_KMS("CDCLK running at %dKHz\n", |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1962 | intel_ddi_get_cdclk_freq(dev_priv)); |
| 1963 | |
Satheeshakrishna M | 121643c | 2014-11-13 14:55:15 +0000 | [diff] [blame] | 1964 | if (IS_SKYLAKE(dev)) { |
| 1965 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) |
| 1966 | DRM_ERROR("LCPLL1 is disabled\n"); |
| 1967 | } else { |
| 1968 | /* |
| 1969 | * The LCPLL register should be turned on by the BIOS. For now |
| 1970 | * let's just check its state and print errors in case |
| 1971 | * something is wrong. Don't even try to turn it on. |
| 1972 | */ |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1973 | |
Satheeshakrishna M | 121643c | 2014-11-13 14:55:15 +0000 | [diff] [blame] | 1974 | if (val & LCPLL_CD_SOURCE_FCLK) |
| 1975 | DRM_ERROR("CDCLK source is not LCPLL\n"); |
| 1976 | |
| 1977 | if (val & LCPLL_PLL_DISABLE) |
| 1978 | DRM_ERROR("LCPLL is disabled\n"); |
| 1979 | } |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 1980 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1981 | |
| 1982 | void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder) |
| 1983 | { |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1984 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 1985 | struct intel_dp *intel_dp = &intel_dig_port->dp; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1986 | struct drm_i915_private *dev_priv = encoder->dev->dev_private; |
Paulo Zanoni | 174edf1 | 2012-10-26 19:05:50 -0200 | [diff] [blame] | 1987 | enum port port = intel_dig_port->port; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1988 | uint32_t val; |
Syam Sidhardhan | f3e227d | 2013-02-25 04:05:38 +0530 | [diff] [blame] | 1989 | bool wait = false; |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 1990 | |
| 1991 | if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) { |
| 1992 | val = I915_READ(DDI_BUF_CTL(port)); |
| 1993 | if (val & DDI_BUF_CTL_ENABLE) { |
| 1994 | val &= ~DDI_BUF_CTL_ENABLE; |
| 1995 | I915_WRITE(DDI_BUF_CTL(port), val); |
| 1996 | wait = true; |
| 1997 | } |
| 1998 | |
| 1999 | val = I915_READ(DP_TP_CTL(port)); |
| 2000 | val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); |
| 2001 | val |= DP_TP_CTL_LINK_TRAIN_PAT1; |
| 2002 | I915_WRITE(DP_TP_CTL(port), val); |
| 2003 | POSTING_READ(DP_TP_CTL(port)); |
| 2004 | |
| 2005 | if (wait) |
| 2006 | intel_wait_ddi_buf_idle(dev_priv, port); |
| 2007 | } |
| 2008 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2009 | val = DP_TP_CTL_ENABLE | |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2010 | DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE; |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2011 | if (intel_dp->is_mst) |
| 2012 | val |= DP_TP_CTL_MODE_MST; |
| 2013 | else { |
| 2014 | val |= DP_TP_CTL_MODE_SST; |
| 2015 | if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) |
| 2016 | val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE; |
| 2017 | } |
Paulo Zanoni | c19b066 | 2012-10-15 15:51:41 -0300 | [diff] [blame] | 2018 | I915_WRITE(DP_TP_CTL(port), val); |
| 2019 | POSTING_READ(DP_TP_CTL(port)); |
| 2020 | |
| 2021 | intel_dp->DP |= DDI_BUF_CTL_ENABLE; |
| 2022 | I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP); |
| 2023 | POSTING_READ(DDI_BUF_CTL(port)); |
| 2024 | |
| 2025 | udelay(600); |
| 2026 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2027 | |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 2028 | void intel_ddi_fdi_disable(struct drm_crtc *crtc) |
| 2029 | { |
| 2030 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 2031 | struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc); |
| 2032 | uint32_t val; |
| 2033 | |
| 2034 | intel_ddi_post_disable(intel_encoder); |
| 2035 | |
| 2036 | val = I915_READ(_FDI_RXA_CTL); |
| 2037 | val &= ~FDI_RX_ENABLE; |
| 2038 | I915_WRITE(_FDI_RXA_CTL, val); |
| 2039 | |
| 2040 | val = I915_READ(_FDI_RXA_MISC); |
| 2041 | val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); |
| 2042 | val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); |
| 2043 | I915_WRITE(_FDI_RXA_MISC, val); |
| 2044 | |
| 2045 | val = I915_READ(_FDI_RXA_CTL); |
| 2046 | val &= ~FDI_PCDCLK; |
| 2047 | I915_WRITE(_FDI_RXA_CTL, val); |
| 2048 | |
| 2049 | val = I915_READ(_FDI_RXA_CTL); |
| 2050 | val &= ~FDI_RX_PLL_ENABLE; |
| 2051 | I915_WRITE(_FDI_RXA_CTL, val); |
| 2052 | } |
| 2053 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2054 | static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder) |
| 2055 | { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2056 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 2057 | int type = intel_dig_port->base.type; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2058 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 2059 | if (type != INTEL_OUTPUT_DISPLAYPORT && |
| 2060 | type != INTEL_OUTPUT_EDP && |
| 2061 | type != INTEL_OUTPUT_UNKNOWN) { |
| 2062 | return; |
| 2063 | } |
| 2064 | |
| 2065 | intel_dp_hot_plug(intel_encoder); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2066 | } |
| 2067 | |
Ville Syrjälä | 6801c18 | 2013-09-24 14:24:05 +0300 | [diff] [blame] | 2068 | void intel_ddi_get_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2069 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2070 | { |
| 2071 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 2072 | 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] | 2073 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
Daniel Vetter | bbd440f | 2014-11-20 22:33:59 +0100 | [diff] [blame] | 2074 | struct intel_hdmi *intel_hdmi; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2075 | u32 temp, flags = 0; |
| 2076 | |
| 2077 | temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
| 2078 | if (temp & TRANS_DDI_PHSYNC) |
| 2079 | flags |= DRM_MODE_FLAG_PHSYNC; |
| 2080 | else |
| 2081 | flags |= DRM_MODE_FLAG_NHSYNC; |
| 2082 | if (temp & TRANS_DDI_PVSYNC) |
| 2083 | flags |= DRM_MODE_FLAG_PVSYNC; |
| 2084 | else |
| 2085 | flags |= DRM_MODE_FLAG_NVSYNC; |
| 2086 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 2087 | pipe_config->base.adjusted_mode.flags |= flags; |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 2088 | |
| 2089 | switch (temp & TRANS_DDI_BPC_MASK) { |
| 2090 | case TRANS_DDI_BPC_6: |
| 2091 | pipe_config->pipe_bpp = 18; |
| 2092 | break; |
| 2093 | case TRANS_DDI_BPC_8: |
| 2094 | pipe_config->pipe_bpp = 24; |
| 2095 | break; |
| 2096 | case TRANS_DDI_BPC_10: |
| 2097 | pipe_config->pipe_bpp = 30; |
| 2098 | break; |
| 2099 | case TRANS_DDI_BPC_12: |
| 2100 | pipe_config->pipe_bpp = 36; |
| 2101 | break; |
| 2102 | default: |
| 2103 | break; |
| 2104 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2105 | |
| 2106 | switch (temp & TRANS_DDI_MODE_SELECT_MASK) { |
| 2107 | case TRANS_DDI_MODE_SELECT_HDMI: |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 2108 | pipe_config->has_hdmi_sink = true; |
Daniel Vetter | bbd440f | 2014-11-20 22:33:59 +0100 | [diff] [blame] | 2109 | intel_hdmi = enc_to_intel_hdmi(&encoder->base); |
| 2110 | |
| 2111 | if (intel_hdmi->infoframe_enabled(&encoder->base)) |
| 2112 | pipe_config->has_infoframe = true; |
Jesse Barnes | cbc572a | 2014-11-17 13:08:47 -0800 | [diff] [blame] | 2113 | break; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 2114 | case TRANS_DDI_MODE_SELECT_DVI: |
| 2115 | case TRANS_DDI_MODE_SELECT_FDI: |
| 2116 | break; |
| 2117 | case TRANS_DDI_MODE_SELECT_DP_SST: |
| 2118 | case TRANS_DDI_MODE_SELECT_DP_MST: |
| 2119 | pipe_config->has_dp_encoder = true; |
| 2120 | intel_dp_get_m_n(intel_crtc, pipe_config); |
| 2121 | break; |
| 2122 | default: |
| 2123 | break; |
| 2124 | } |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 2125 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 2126 | if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) { |
Paulo Zanoni | a60551b | 2014-05-21 16:23:20 -0300 | [diff] [blame] | 2127 | temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 2128 | if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe)) |
Paulo Zanoni | a60551b | 2014-05-21 16:23:20 -0300 | [diff] [blame] | 2129 | pipe_config->has_audio = true; |
| 2130 | } |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 2131 | |
Daniel Vetter | 1021442 | 2013-11-18 07:38:16 +0100 | [diff] [blame] | 2132 | if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp && |
| 2133 | pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) { |
| 2134 | /* |
| 2135 | * This is a big fat ugly hack. |
| 2136 | * |
| 2137 | * Some machines in UEFI boot mode provide us a VBT that has 18 |
| 2138 | * bpp and 1.62 GHz link bandwidth for eDP, which for reasons |
| 2139 | * unknown we fail to light up. Yet the same BIOS boots up with |
| 2140 | * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as |
| 2141 | * max, not what it tells us to use. |
| 2142 | * |
| 2143 | * Note: This will still be broken if the eDP panel is not lit |
| 2144 | * up by the BIOS, and thus we can't get the mode at module |
| 2145 | * load. |
| 2146 | */ |
| 2147 | DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", |
| 2148 | pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp); |
| 2149 | dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp; |
| 2150 | } |
Jesse Barnes | 1157855 | 2014-01-21 12:42:10 -0800 | [diff] [blame] | 2151 | |
Damien Lespiau | 22606a1 | 2014-12-12 14:26:57 +0000 | [diff] [blame] | 2152 | intel_ddi_clock_get(encoder, pipe_config); |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2155 | static void intel_ddi_destroy(struct drm_encoder *encoder) |
| 2156 | { |
| 2157 | /* HDMI has nothing special to destroy, so we can go with this. */ |
| 2158 | intel_dp_encoder_destroy(encoder); |
| 2159 | } |
| 2160 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2161 | static bool intel_ddi_compute_config(struct intel_encoder *encoder, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 2162 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2163 | { |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2164 | int type = encoder->type; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 2165 | int port = intel_ddi_get_encoder_port(encoder); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2166 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2167 | WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n"); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2168 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 2169 | if (port == PORT_A) |
| 2170 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 2171 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2172 | if (type == INTEL_OUTPUT_HDMI) |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2173 | return intel_hdmi_compute_config(encoder, pipe_config); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2174 | else |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2175 | return intel_dp_compute_config(encoder, pipe_config); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | static const struct drm_encoder_funcs intel_ddi_funcs = { |
| 2179 | .destroy = intel_ddi_destroy, |
| 2180 | }; |
| 2181 | |
Paulo Zanoni | 4a28ae5 | 2013-10-09 13:52:36 -0300 | [diff] [blame] | 2182 | static struct intel_connector * |
| 2183 | intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port) |
| 2184 | { |
| 2185 | struct intel_connector *connector; |
| 2186 | enum port port = intel_dig_port->port; |
| 2187 | |
| 2188 | connector = kzalloc(sizeof(*connector), GFP_KERNEL); |
| 2189 | if (!connector) |
| 2190 | return NULL; |
| 2191 | |
| 2192 | intel_dig_port->dp.output_reg = DDI_BUF_CTL(port); |
| 2193 | if (!intel_dp_init_connector(intel_dig_port, connector)) { |
| 2194 | kfree(connector); |
| 2195 | return NULL; |
| 2196 | } |
| 2197 | |
| 2198 | return connector; |
| 2199 | } |
| 2200 | |
| 2201 | static struct intel_connector * |
| 2202 | intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port) |
| 2203 | { |
| 2204 | struct intel_connector *connector; |
| 2205 | enum port port = intel_dig_port->port; |
| 2206 | |
| 2207 | connector = kzalloc(sizeof(*connector), GFP_KERNEL); |
| 2208 | if (!connector) |
| 2209 | return NULL; |
| 2210 | |
| 2211 | intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port); |
| 2212 | intel_hdmi_init_connector(intel_dig_port, connector); |
| 2213 | |
| 2214 | return connector; |
| 2215 | } |
| 2216 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2217 | void intel_ddi_init(struct drm_device *dev, enum port port) |
| 2218 | { |
Damien Lespiau | 876a8cd | 2012-12-11 18:48:30 +0000 | [diff] [blame] | 2219 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2220 | struct intel_digital_port *intel_dig_port; |
| 2221 | struct intel_encoder *intel_encoder; |
| 2222 | struct drm_encoder *encoder; |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2223 | bool init_hdmi, init_dp; |
| 2224 | |
| 2225 | init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi || |
| 2226 | dev_priv->vbt.ddi_port_info[port].supports_hdmi); |
| 2227 | init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp; |
| 2228 | if (!init_dp && !init_hdmi) { |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2229 | 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] | 2230 | port_name(port)); |
| 2231 | init_hdmi = true; |
| 2232 | init_dp = true; |
| 2233 | } |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2234 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 2235 | intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2236 | if (!intel_dig_port) |
| 2237 | return; |
| 2238 | |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2239 | intel_encoder = &intel_dig_port->base; |
| 2240 | encoder = &intel_encoder->base; |
| 2241 | |
| 2242 | drm_encoder_init(dev, encoder, &intel_ddi_funcs, |
| 2243 | DRM_MODE_ENCODER_TMDS); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2244 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 2245 | intel_encoder->compute_config = intel_ddi_compute_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2246 | intel_encoder->enable = intel_enable_ddi; |
| 2247 | intel_encoder->pre_enable = intel_ddi_pre_enable; |
| 2248 | intel_encoder->disable = intel_disable_ddi; |
| 2249 | intel_encoder->post_disable = intel_ddi_post_disable; |
| 2250 | intel_encoder->get_hw_state = intel_ddi_get_hw_state; |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 2251 | intel_encoder->get_config = intel_ddi_get_config; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2252 | |
| 2253 | intel_dig_port->port = port; |
Stéphane Marchesin | bcf53de | 2013-07-12 13:54:41 -0700 | [diff] [blame] | 2254 | intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) & |
| 2255 | (DDI_BUF_PORT_REVERSAL | |
| 2256 | DDI_A_4_LANES); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2257 | |
| 2258 | intel_encoder->type = INTEL_OUTPUT_UNKNOWN; |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2259 | intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2); |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 2260 | intel_encoder->cloneable = 0; |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2261 | intel_encoder->hot_plug = intel_ddi_hot_plug; |
| 2262 | |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2263 | if (init_dp) { |
| 2264 | if (!intel_ddi_init_dp_connector(intel_dig_port)) |
| 2265 | goto err; |
Dave Airlie | 13cf550 | 2014-06-18 11:29:35 +1000 | [diff] [blame] | 2266 | |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2267 | intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; |
| 2268 | dev_priv->hpd_irq_port[port] = intel_dig_port; |
| 2269 | } |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 2270 | |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 2271 | /* In theory we don't need the encoder->type check, but leave it just in |
| 2272 | * case we have some really bad VBTs... */ |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2273 | if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) { |
| 2274 | if (!intel_ddi_init_hdmi_connector(intel_dig_port)) |
| 2275 | goto err; |
Daniel Vetter | 21a8e6a | 2013-04-10 23:28:35 +0200 | [diff] [blame] | 2276 | } |
Chris Wilson | f68d697 | 2014-08-04 07:15:09 +0100 | [diff] [blame] | 2277 | |
| 2278 | return; |
| 2279 | |
| 2280 | err: |
| 2281 | drm_encoder_cleanup(encoder); |
| 2282 | kfree(intel_dig_port); |
Paulo Zanoni | 00c09d7 | 2012-10-26 19:05:52 -0200 | [diff] [blame] | 2283 | } |