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