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