1 1.1 riastrad /* $NetBSD: intel_ddi.c,v 1.2 2021/12/18 23:45:29 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2012 Intel Corporation 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice (including the next 14 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 15 1.1 riastrad * Software. 16 1.1 riastrad * 17 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 1.1 riastrad * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 1.1 riastrad * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 1.1 riastrad * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 1.1 riastrad * IN THE SOFTWARE. 24 1.1 riastrad * 25 1.1 riastrad * Authors: 26 1.1 riastrad * Eugeni Dodonov <eugeni.dodonov (at) intel.com> 27 1.1 riastrad * 28 1.1 riastrad */ 29 1.1 riastrad 30 1.1 riastrad #include <sys/cdefs.h> 31 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: intel_ddi.c,v 1.2 2021/12/18 23:45:29 riastradh Exp $"); 32 1.1 riastrad 33 1.1 riastrad #include <drm/drm_scdc_helper.h> 34 1.1 riastrad 35 1.1 riastrad #include "i915_drv.h" 36 1.1 riastrad #include "intel_audio.h" 37 1.1 riastrad #include "intel_combo_phy.h" 38 1.1 riastrad #include "intel_connector.h" 39 1.1 riastrad #include "intel_ddi.h" 40 1.1 riastrad #include "intel_display_types.h" 41 1.1 riastrad #include "intel_dp.h" 42 1.1 riastrad #include "intel_dp_mst.h" 43 1.1 riastrad #include "intel_dp_link_training.h" 44 1.1 riastrad #include "intel_dpio_phy.h" 45 1.1 riastrad #include "intel_dsi.h" 46 1.1 riastrad #include "intel_fifo_underrun.h" 47 1.1 riastrad #include "intel_gmbus.h" 48 1.1 riastrad #include "intel_hdcp.h" 49 1.1 riastrad #include "intel_hdmi.h" 50 1.1 riastrad #include "intel_hotplug.h" 51 1.1 riastrad #include "intel_lspcon.h" 52 1.1 riastrad #include "intel_panel.h" 53 1.1 riastrad #include "intel_psr.h" 54 1.1 riastrad #include "intel_sprite.h" 55 1.1 riastrad #include "intel_tc.h" 56 1.1 riastrad #include "intel_vdsc.h" 57 1.1 riastrad 58 1.1 riastrad struct ddi_buf_trans { 59 1.1 riastrad u32 trans1; /* balance leg enable, de-emph level */ 60 1.1 riastrad u32 trans2; /* vref sel, vswing */ 61 1.1 riastrad u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */ 62 1.1 riastrad }; 63 1.1 riastrad 64 1.1 riastrad static const u8 index_to_dp_signal_levels[] = { 65 1.1 riastrad [0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0, 66 1.1 riastrad [1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1, 67 1.1 riastrad [2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2, 68 1.1 riastrad [3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3, 69 1.1 riastrad [4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0, 70 1.1 riastrad [5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1, 71 1.1 riastrad [6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2, 72 1.1 riastrad [7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0, 73 1.1 riastrad [8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1, 74 1.1 riastrad [9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0, 75 1.1 riastrad }; 76 1.1 riastrad 77 1.1 riastrad /* HDMI/DVI modes ignore everything but the last 2 items. So we share 78 1.1 riastrad * them for both DP and FDI transports, allowing those ports to 79 1.1 riastrad * automatically adapt to HDMI connections as well 80 1.1 riastrad */ 81 1.1 riastrad static const struct ddi_buf_trans hsw_ddi_translations_dp[] = { 82 1.1 riastrad { 0x00FFFFFF, 0x0006000E, 0x0 }, 83 1.1 riastrad { 0x00D75FFF, 0x0005000A, 0x0 }, 84 1.1 riastrad { 0x00C30FFF, 0x00040006, 0x0 }, 85 1.1 riastrad { 0x80AAAFFF, 0x000B0000, 0x0 }, 86 1.1 riastrad { 0x00FFFFFF, 0x0005000A, 0x0 }, 87 1.1 riastrad { 0x00D75FFF, 0x000C0004, 0x0 }, 88 1.1 riastrad { 0x80C30FFF, 0x000B0000, 0x0 }, 89 1.1 riastrad { 0x00FFFFFF, 0x00040006, 0x0 }, 90 1.1 riastrad { 0x80D75FFF, 0x000B0000, 0x0 }, 91 1.1 riastrad }; 92 1.1 riastrad 93 1.1 riastrad static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = { 94 1.1 riastrad { 0x00FFFFFF, 0x0007000E, 0x0 }, 95 1.1 riastrad { 0x00D75FFF, 0x000F000A, 0x0 }, 96 1.1 riastrad { 0x00C30FFF, 0x00060006, 0x0 }, 97 1.1 riastrad { 0x00AAAFFF, 0x001E0000, 0x0 }, 98 1.1 riastrad { 0x00FFFFFF, 0x000F000A, 0x0 }, 99 1.1 riastrad { 0x00D75FFF, 0x00160004, 0x0 }, 100 1.1 riastrad { 0x00C30FFF, 0x001E0000, 0x0 }, 101 1.1 riastrad { 0x00FFFFFF, 0x00060006, 0x0 }, 102 1.1 riastrad { 0x00D75FFF, 0x001E0000, 0x0 }, 103 1.1 riastrad }; 104 1.1 riastrad 105 1.1 riastrad static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = { 106 1.1 riastrad /* Idx NT mV d T mV d db */ 107 1.1 riastrad { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */ 108 1.1 riastrad { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */ 109 1.1 riastrad { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */ 110 1.1 riastrad { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */ 111 1.1 riastrad { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */ 112 1.1 riastrad { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */ 113 1.1 riastrad { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */ 114 1.1 riastrad { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */ 115 1.1 riastrad { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */ 116 1.1 riastrad { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */ 117 1.1 riastrad { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */ 118 1.1 riastrad { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */ 119 1.1 riastrad }; 120 1.1 riastrad 121 1.1 riastrad static const struct ddi_buf_trans bdw_ddi_translations_edp[] = { 122 1.1 riastrad { 0x00FFFFFF, 0x00000012, 0x0 }, 123 1.1 riastrad { 0x00EBAFFF, 0x00020011, 0x0 }, 124 1.1 riastrad { 0x00C71FFF, 0x0006000F, 0x0 }, 125 1.1 riastrad { 0x00AAAFFF, 0x000E000A, 0x0 }, 126 1.1 riastrad { 0x00FFFFFF, 0x00020011, 0x0 }, 127 1.1 riastrad { 0x00DB6FFF, 0x0005000F, 0x0 }, 128 1.1 riastrad { 0x00BEEFFF, 0x000A000C, 0x0 }, 129 1.1 riastrad { 0x00FFFFFF, 0x0005000F, 0x0 }, 130 1.1 riastrad { 0x00DB6FFF, 0x000A000C, 0x0 }, 131 1.1 riastrad }; 132 1.1 riastrad 133 1.1 riastrad static const struct ddi_buf_trans bdw_ddi_translations_dp[] = { 134 1.1 riastrad { 0x00FFFFFF, 0x0007000E, 0x0 }, 135 1.1 riastrad { 0x00D75FFF, 0x000E000A, 0x0 }, 136 1.1 riastrad { 0x00BEFFFF, 0x00140006, 0x0 }, 137 1.1 riastrad { 0x80B2CFFF, 0x001B0002, 0x0 }, 138 1.1 riastrad { 0x00FFFFFF, 0x000E000A, 0x0 }, 139 1.1 riastrad { 0x00DB6FFF, 0x00160005, 0x0 }, 140 1.1 riastrad { 0x80C71FFF, 0x001A0002, 0x0 }, 141 1.1 riastrad { 0x00F7DFFF, 0x00180004, 0x0 }, 142 1.1 riastrad { 0x80D75FFF, 0x001B0002, 0x0 }, 143 1.1 riastrad }; 144 1.1 riastrad 145 1.1 riastrad static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = { 146 1.1 riastrad { 0x00FFFFFF, 0x0001000E, 0x0 }, 147 1.1 riastrad { 0x00D75FFF, 0x0004000A, 0x0 }, 148 1.1 riastrad { 0x00C30FFF, 0x00070006, 0x0 }, 149 1.1 riastrad { 0x00AAAFFF, 0x000C0000, 0x0 }, 150 1.1 riastrad { 0x00FFFFFF, 0x0004000A, 0x0 }, 151 1.1 riastrad { 0x00D75FFF, 0x00090004, 0x0 }, 152 1.1 riastrad { 0x00C30FFF, 0x000C0000, 0x0 }, 153 1.1 riastrad { 0x00FFFFFF, 0x00070006, 0x0 }, 154 1.1 riastrad { 0x00D75FFF, 0x000C0000, 0x0 }, 155 1.1 riastrad }; 156 1.1 riastrad 157 1.1 riastrad static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = { 158 1.1 riastrad /* Idx NT mV d T mV df db */ 159 1.1 riastrad { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */ 160 1.1 riastrad { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */ 161 1.1 riastrad { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */ 162 1.1 riastrad { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */ 163 1.1 riastrad { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */ 164 1.1 riastrad { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */ 165 1.1 riastrad { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */ 166 1.1 riastrad { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */ 167 1.1 riastrad { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */ 168 1.1 riastrad { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */ 169 1.1 riastrad }; 170 1.1 riastrad 171 1.1 riastrad /* Skylake H and S */ 172 1.1 riastrad static const struct ddi_buf_trans skl_ddi_translations_dp[] = { 173 1.1 riastrad { 0x00002016, 0x000000A0, 0x0 }, 174 1.1 riastrad { 0x00005012, 0x0000009B, 0x0 }, 175 1.1 riastrad { 0x00007011, 0x00000088, 0x0 }, 176 1.1 riastrad { 0x80009010, 0x000000C0, 0x1 }, 177 1.1 riastrad { 0x00002016, 0x0000009B, 0x0 }, 178 1.1 riastrad { 0x00005012, 0x00000088, 0x0 }, 179 1.1 riastrad { 0x80007011, 0x000000C0, 0x1 }, 180 1.1 riastrad { 0x00002016, 0x000000DF, 0x0 }, 181 1.1 riastrad { 0x80005012, 0x000000C0, 0x1 }, 182 1.1 riastrad }; 183 1.1 riastrad 184 1.1 riastrad /* Skylake U */ 185 1.1 riastrad static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = { 186 1.1 riastrad { 0x0000201B, 0x000000A2, 0x0 }, 187 1.1 riastrad { 0x00005012, 0x00000088, 0x0 }, 188 1.1 riastrad { 0x80007011, 0x000000CD, 0x1 }, 189 1.1 riastrad { 0x80009010, 0x000000C0, 0x1 }, 190 1.1 riastrad { 0x0000201B, 0x0000009D, 0x0 }, 191 1.1 riastrad { 0x80005012, 0x000000C0, 0x1 }, 192 1.1 riastrad { 0x80007011, 0x000000C0, 0x1 }, 193 1.1 riastrad { 0x00002016, 0x00000088, 0x0 }, 194 1.1 riastrad { 0x80005012, 0x000000C0, 0x1 }, 195 1.1 riastrad }; 196 1.1 riastrad 197 1.1 riastrad /* Skylake Y */ 198 1.1 riastrad static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = { 199 1.1 riastrad { 0x00000018, 0x000000A2, 0x0 }, 200 1.1 riastrad { 0x00005012, 0x00000088, 0x0 }, 201 1.1 riastrad { 0x80007011, 0x000000CD, 0x3 }, 202 1.1 riastrad { 0x80009010, 0x000000C0, 0x3 }, 203 1.1 riastrad { 0x00000018, 0x0000009D, 0x0 }, 204 1.1 riastrad { 0x80005012, 0x000000C0, 0x3 }, 205 1.1 riastrad { 0x80007011, 0x000000C0, 0x3 }, 206 1.1 riastrad { 0x00000018, 0x00000088, 0x0 }, 207 1.1 riastrad { 0x80005012, 0x000000C0, 0x3 }, 208 1.1 riastrad }; 209 1.1 riastrad 210 1.1 riastrad /* Kabylake H and S */ 211 1.1 riastrad static const struct ddi_buf_trans kbl_ddi_translations_dp[] = { 212 1.1 riastrad { 0x00002016, 0x000000A0, 0x0 }, 213 1.1 riastrad { 0x00005012, 0x0000009B, 0x0 }, 214 1.1 riastrad { 0x00007011, 0x00000088, 0x0 }, 215 1.1 riastrad { 0x80009010, 0x000000C0, 0x1 }, 216 1.1 riastrad { 0x00002016, 0x0000009B, 0x0 }, 217 1.1 riastrad { 0x00005012, 0x00000088, 0x0 }, 218 1.1 riastrad { 0x80007011, 0x000000C0, 0x1 }, 219 1.1 riastrad { 0x00002016, 0x00000097, 0x0 }, 220 1.1 riastrad { 0x80005012, 0x000000C0, 0x1 }, 221 1.1 riastrad }; 222 1.1 riastrad 223 1.1 riastrad /* Kabylake U */ 224 1.1 riastrad static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = { 225 1.1 riastrad { 0x0000201B, 0x000000A1, 0x0 }, 226 1.1 riastrad { 0x00005012, 0x00000088, 0x0 }, 227 1.1 riastrad { 0x80007011, 0x000000CD, 0x3 }, 228 1.1 riastrad { 0x80009010, 0x000000C0, 0x3 }, 229 1.1 riastrad { 0x0000201B, 0x0000009D, 0x0 }, 230 1.1 riastrad { 0x80005012, 0x000000C0, 0x3 }, 231 1.1 riastrad { 0x80007011, 0x000000C0, 0x3 }, 232 1.1 riastrad { 0x00002016, 0x0000004F, 0x0 }, 233 1.1 riastrad { 0x80005012, 0x000000C0, 0x3 }, 234 1.1 riastrad }; 235 1.1 riastrad 236 1.1 riastrad /* Kabylake Y */ 237 1.1 riastrad static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = { 238 1.1 riastrad { 0x00001017, 0x000000A1, 0x0 }, 239 1.1 riastrad { 0x00005012, 0x00000088, 0x0 }, 240 1.1 riastrad { 0x80007011, 0x000000CD, 0x3 }, 241 1.1 riastrad { 0x8000800F, 0x000000C0, 0x3 }, 242 1.1 riastrad { 0x00001017, 0x0000009D, 0x0 }, 243 1.1 riastrad { 0x80005012, 0x000000C0, 0x3 }, 244 1.1 riastrad { 0x80007011, 0x000000C0, 0x3 }, 245 1.1 riastrad { 0x00001017, 0x0000004C, 0x0 }, 246 1.1 riastrad { 0x80005012, 0x000000C0, 0x3 }, 247 1.1 riastrad }; 248 1.1 riastrad 249 1.1 riastrad /* 250 1.1 riastrad * Skylake/Kabylake H and S 251 1.1 riastrad * eDP 1.4 low vswing translation parameters 252 1.1 riastrad */ 253 1.1 riastrad static const struct ddi_buf_trans skl_ddi_translations_edp[] = { 254 1.1 riastrad { 0x00000018, 0x000000A8, 0x0 }, 255 1.1 riastrad { 0x00004013, 0x000000A9, 0x0 }, 256 1.1 riastrad { 0x00007011, 0x000000A2, 0x0 }, 257 1.1 riastrad { 0x00009010, 0x0000009C, 0x0 }, 258 1.1 riastrad { 0x00000018, 0x000000A9, 0x0 }, 259 1.1 riastrad { 0x00006013, 0x000000A2, 0x0 }, 260 1.1 riastrad { 0x00007011, 0x000000A6, 0x0 }, 261 1.1 riastrad { 0x00000018, 0x000000AB, 0x0 }, 262 1.1 riastrad { 0x00007013, 0x0000009F, 0x0 }, 263 1.1 riastrad { 0x00000018, 0x000000DF, 0x0 }, 264 1.1 riastrad }; 265 1.1 riastrad 266 1.1 riastrad /* 267 1.1 riastrad * Skylake/Kabylake U 268 1.1 riastrad * eDP 1.4 low vswing translation parameters 269 1.1 riastrad */ 270 1.1 riastrad static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = { 271 1.1 riastrad { 0x00000018, 0x000000A8, 0x0 }, 272 1.1 riastrad { 0x00004013, 0x000000A9, 0x0 }, 273 1.1 riastrad { 0x00007011, 0x000000A2, 0x0 }, 274 1.1 riastrad { 0x00009010, 0x0000009C, 0x0 }, 275 1.1 riastrad { 0x00000018, 0x000000A9, 0x0 }, 276 1.1 riastrad { 0x00006013, 0x000000A2, 0x0 }, 277 1.1 riastrad { 0x00007011, 0x000000A6, 0x0 }, 278 1.1 riastrad { 0x00002016, 0x000000AB, 0x0 }, 279 1.1 riastrad { 0x00005013, 0x0000009F, 0x0 }, 280 1.1 riastrad { 0x00000018, 0x000000DF, 0x0 }, 281 1.1 riastrad }; 282 1.1 riastrad 283 1.1 riastrad /* 284 1.1 riastrad * Skylake/Kabylake Y 285 1.1 riastrad * eDP 1.4 low vswing translation parameters 286 1.1 riastrad */ 287 1.1 riastrad static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = { 288 1.1 riastrad { 0x00000018, 0x000000A8, 0x0 }, 289 1.1 riastrad { 0x00004013, 0x000000AB, 0x0 }, 290 1.1 riastrad { 0x00007011, 0x000000A4, 0x0 }, 291 1.1 riastrad { 0x00009010, 0x000000DF, 0x0 }, 292 1.1 riastrad { 0x00000018, 0x000000AA, 0x0 }, 293 1.1 riastrad { 0x00006013, 0x000000A4, 0x0 }, 294 1.1 riastrad { 0x00007011, 0x0000009D, 0x0 }, 295 1.1 riastrad { 0x00000018, 0x000000A0, 0x0 }, 296 1.1 riastrad { 0x00006012, 0x000000DF, 0x0 }, 297 1.1 riastrad { 0x00000018, 0x0000008A, 0x0 }, 298 1.1 riastrad }; 299 1.1 riastrad 300 1.1 riastrad /* Skylake/Kabylake U, H and S */ 301 1.1 riastrad static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = { 302 1.1 riastrad { 0x00000018, 0x000000AC, 0x0 }, 303 1.1 riastrad { 0x00005012, 0x0000009D, 0x0 }, 304 1.1 riastrad { 0x00007011, 0x00000088, 0x0 }, 305 1.1 riastrad { 0x00000018, 0x000000A1, 0x0 }, 306 1.1 riastrad { 0x00000018, 0x00000098, 0x0 }, 307 1.1 riastrad { 0x00004013, 0x00000088, 0x0 }, 308 1.1 riastrad { 0x80006012, 0x000000CD, 0x1 }, 309 1.1 riastrad { 0x00000018, 0x000000DF, 0x0 }, 310 1.1 riastrad { 0x80003015, 0x000000CD, 0x1 }, /* Default */ 311 1.1 riastrad { 0x80003015, 0x000000C0, 0x1 }, 312 1.1 riastrad { 0x80000018, 0x000000C0, 0x1 }, 313 1.1 riastrad }; 314 1.1 riastrad 315 1.1 riastrad /* Skylake/Kabylake Y */ 316 1.1 riastrad static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = { 317 1.1 riastrad { 0x00000018, 0x000000A1, 0x0 }, 318 1.1 riastrad { 0x00005012, 0x000000DF, 0x0 }, 319 1.1 riastrad { 0x80007011, 0x000000CB, 0x3 }, 320 1.1 riastrad { 0x00000018, 0x000000A4, 0x0 }, 321 1.1 riastrad { 0x00000018, 0x0000009D, 0x0 }, 322 1.1 riastrad { 0x00004013, 0x00000080, 0x0 }, 323 1.1 riastrad { 0x80006013, 0x000000C0, 0x3 }, 324 1.1 riastrad { 0x00000018, 0x0000008A, 0x0 }, 325 1.1 riastrad { 0x80003015, 0x000000C0, 0x3 }, /* Default */ 326 1.1 riastrad { 0x80003015, 0x000000C0, 0x3 }, 327 1.1 riastrad { 0x80000018, 0x000000C0, 0x3 }, 328 1.1 riastrad }; 329 1.1 riastrad 330 1.1 riastrad struct bxt_ddi_buf_trans { 331 1.1 riastrad u8 margin; /* swing value */ 332 1.1 riastrad u8 scale; /* scale value */ 333 1.1 riastrad u8 enable; /* scale enable */ 334 1.1 riastrad u8 deemphasis; 335 1.1 riastrad }; 336 1.1 riastrad 337 1.1 riastrad static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = { 338 1.1 riastrad /* Idx NT mV diff db */ 339 1.1 riastrad { 52, 0x9A, 0, 128, }, /* 0: 400 0 */ 340 1.1 riastrad { 78, 0x9A, 0, 85, }, /* 1: 400 3.5 */ 341 1.1 riastrad { 104, 0x9A, 0, 64, }, /* 2: 400 6 */ 342 1.1 riastrad { 154, 0x9A, 0, 43, }, /* 3: 400 9.5 */ 343 1.1 riastrad { 77, 0x9A, 0, 128, }, /* 4: 600 0 */ 344 1.1 riastrad { 116, 0x9A, 0, 85, }, /* 5: 600 3.5 */ 345 1.1 riastrad { 154, 0x9A, 0, 64, }, /* 6: 600 6 */ 346 1.1 riastrad { 102, 0x9A, 0, 128, }, /* 7: 800 0 */ 347 1.1 riastrad { 154, 0x9A, 0, 85, }, /* 8: 800 3.5 */ 348 1.1 riastrad { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */ 349 1.1 riastrad }; 350 1.1 riastrad 351 1.1 riastrad static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = { 352 1.1 riastrad /* Idx NT mV diff db */ 353 1.1 riastrad { 26, 0, 0, 128, }, /* 0: 200 0 */ 354 1.1 riastrad { 38, 0, 0, 112, }, /* 1: 200 1.5 */ 355 1.1 riastrad { 48, 0, 0, 96, }, /* 2: 200 4 */ 356 1.1 riastrad { 54, 0, 0, 69, }, /* 3: 200 6 */ 357 1.1 riastrad { 32, 0, 0, 128, }, /* 4: 250 0 */ 358 1.1 riastrad { 48, 0, 0, 104, }, /* 5: 250 1.5 */ 359 1.1 riastrad { 54, 0, 0, 85, }, /* 6: 250 4 */ 360 1.1 riastrad { 43, 0, 0, 128, }, /* 7: 300 0 */ 361 1.1 riastrad { 54, 0, 0, 101, }, /* 8: 300 1.5 */ 362 1.1 riastrad { 48, 0, 0, 128, }, /* 9: 300 0 */ 363 1.1 riastrad }; 364 1.1 riastrad 365 1.1 riastrad /* BSpec has 2 recommended values - entries 0 and 8. 366 1.1 riastrad * Using the entry with higher vswing. 367 1.1 riastrad */ 368 1.1 riastrad static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = { 369 1.1 riastrad /* Idx NT mV diff db */ 370 1.1 riastrad { 52, 0x9A, 0, 128, }, /* 0: 400 0 */ 371 1.1 riastrad { 52, 0x9A, 0, 85, }, /* 1: 400 3.5 */ 372 1.1 riastrad { 52, 0x9A, 0, 64, }, /* 2: 400 6 */ 373 1.1 riastrad { 42, 0x9A, 0, 43, }, /* 3: 400 9.5 */ 374 1.1 riastrad { 77, 0x9A, 0, 128, }, /* 4: 600 0 */ 375 1.1 riastrad { 77, 0x9A, 0, 85, }, /* 5: 600 3.5 */ 376 1.1 riastrad { 77, 0x9A, 0, 64, }, /* 6: 600 6 */ 377 1.1 riastrad { 102, 0x9A, 0, 128, }, /* 7: 800 0 */ 378 1.1 riastrad { 102, 0x9A, 0, 85, }, /* 8: 800 3.5 */ 379 1.1 riastrad { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */ 380 1.1 riastrad }; 381 1.1 riastrad 382 1.1 riastrad struct cnl_ddi_buf_trans { 383 1.1 riastrad u8 dw2_swing_sel; 384 1.1 riastrad u8 dw7_n_scalar; 385 1.1 riastrad u8 dw4_cursor_coeff; 386 1.1 riastrad u8 dw4_post_cursor_2; 387 1.1 riastrad u8 dw4_post_cursor_1; 388 1.1 riastrad }; 389 1.1 riastrad 390 1.1 riastrad /* Voltage Swing Programming for VccIO 0.85V for DP */ 391 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V[] = { 392 1.1 riastrad /* NT mV Trans mV db */ 393 1.1 riastrad { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 394 1.1 riastrad { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */ 395 1.1 riastrad { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */ 396 1.1 riastrad { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */ 397 1.1 riastrad { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 398 1.1 riastrad { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */ 399 1.1 riastrad { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */ 400 1.1 riastrad { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */ 401 1.1 riastrad { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */ 402 1.1 riastrad { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 403 1.1 riastrad }; 404 1.1 riastrad 405 1.1 riastrad /* Voltage Swing Programming for VccIO 0.85V for HDMI */ 406 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V[] = { 407 1.1 riastrad /* NT mV Trans mV db */ 408 1.1 riastrad { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 409 1.1 riastrad { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */ 410 1.1 riastrad { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */ 411 1.1 riastrad { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 */ 412 1.1 riastrad { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */ 413 1.1 riastrad { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */ 414 1.1 riastrad { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 415 1.1 riastrad }; 416 1.1 riastrad 417 1.1 riastrad /* Voltage Swing Programming for VccIO 0.85V for eDP */ 418 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V[] = { 419 1.1 riastrad /* NT mV Trans mV db */ 420 1.1 riastrad { 0xA, 0x66, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */ 421 1.1 riastrad { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */ 422 1.1 riastrad { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */ 423 1.1 riastrad { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */ 424 1.1 riastrad { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */ 425 1.1 riastrad { 0xA, 0x66, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */ 426 1.1 riastrad { 0xB, 0x70, 0x3C, 0x00, 0x03 }, /* 460 600 2.3 */ 427 1.1 riastrad { 0xC, 0x75, 0x3C, 0x00, 0x03 }, /* 537 700 2.3 */ 428 1.1 riastrad { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 429 1.1 riastrad }; 430 1.1 riastrad 431 1.1 riastrad /* Voltage Swing Programming for VccIO 0.95V for DP */ 432 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V[] = { 433 1.1 riastrad /* NT mV Trans mV db */ 434 1.1 riastrad { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 435 1.1 riastrad { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */ 436 1.1 riastrad { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */ 437 1.1 riastrad { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */ 438 1.1 riastrad { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 439 1.1 riastrad { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */ 440 1.1 riastrad { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */ 441 1.1 riastrad { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */ 442 1.1 riastrad { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */ 443 1.1 riastrad { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 444 1.1 riastrad }; 445 1.1 riastrad 446 1.1 riastrad /* Voltage Swing Programming for VccIO 0.95V for HDMI */ 447 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V[] = { 448 1.1 riastrad /* NT mV Trans mV db */ 449 1.1 riastrad { 0xA, 0x5C, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 450 1.1 riastrad { 0xB, 0x69, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */ 451 1.1 riastrad { 0x5, 0x76, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */ 452 1.1 riastrad { 0xA, 0x5E, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 453 1.1 riastrad { 0xB, 0x69, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */ 454 1.1 riastrad { 0xB, 0x79, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 455 1.1 riastrad { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */ 456 1.1 riastrad { 0x5, 0x76, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */ 457 1.1 riastrad { 0x6, 0x7D, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */ 458 1.1 riastrad { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */ 459 1.1 riastrad { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */ 460 1.1 riastrad }; 461 1.1 riastrad 462 1.1 riastrad /* Voltage Swing Programming for VccIO 0.95V for eDP */ 463 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V[] = { 464 1.1 riastrad /* NT mV Trans mV db */ 465 1.1 riastrad { 0xA, 0x61, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */ 466 1.1 riastrad { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */ 467 1.1 riastrad { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */ 468 1.1 riastrad { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */ 469 1.1 riastrad { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */ 470 1.1 riastrad { 0xA, 0x61, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */ 471 1.1 riastrad { 0xB, 0x68, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */ 472 1.1 riastrad { 0xC, 0x6E, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */ 473 1.1 riastrad { 0x4, 0x7F, 0x3A, 0x00, 0x05 }, /* 460 600 2.3 */ 474 1.1 riastrad { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 475 1.1 riastrad }; 476 1.1 riastrad 477 1.1 riastrad /* Voltage Swing Programming for VccIO 1.05V for DP */ 478 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V[] = { 479 1.1 riastrad /* NT mV Trans mV db */ 480 1.1 riastrad { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 481 1.1 riastrad { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */ 482 1.1 riastrad { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */ 483 1.1 riastrad { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 400 1050 8.4 */ 484 1.1 riastrad { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */ 485 1.1 riastrad { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 486 1.1 riastrad { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 550 1050 5.6 */ 487 1.1 riastrad { 0x5, 0x76, 0x3E, 0x00, 0x01 }, /* 850 900 0.5 */ 488 1.1 riastrad { 0x6, 0x7F, 0x36, 0x00, 0x09 }, /* 750 1050 2.9 */ 489 1.1 riastrad { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */ 490 1.1 riastrad }; 491 1.1 riastrad 492 1.1 riastrad /* Voltage Swing Programming for VccIO 1.05V for HDMI */ 493 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V[] = { 494 1.1 riastrad /* NT mV Trans mV db */ 495 1.1 riastrad { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 496 1.1 riastrad { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */ 497 1.1 riastrad { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */ 498 1.1 riastrad { 0xA, 0x5B, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 499 1.1 riastrad { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */ 500 1.1 riastrad { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 501 1.1 riastrad { 0x6, 0x7C, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */ 502 1.1 riastrad { 0x5, 0x70, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */ 503 1.1 riastrad { 0x6, 0x7C, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */ 504 1.1 riastrad { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */ 505 1.1 riastrad { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */ 506 1.1 riastrad }; 507 1.1 riastrad 508 1.1 riastrad /* Voltage Swing Programming for VccIO 1.05V for eDP */ 509 1.1 riastrad static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V[] = { 510 1.1 riastrad /* NT mV Trans mV db */ 511 1.1 riastrad { 0xA, 0x5E, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */ 512 1.1 riastrad { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */ 513 1.1 riastrad { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */ 514 1.1 riastrad { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */ 515 1.1 riastrad { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */ 516 1.1 riastrad { 0xA, 0x5E, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */ 517 1.1 riastrad { 0xB, 0x64, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */ 518 1.1 riastrad { 0xE, 0x6A, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */ 519 1.1 riastrad { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 520 1.1 riastrad }; 521 1.1 riastrad 522 1.1 riastrad /* icl_combo_phy_ddi_translations */ 523 1.1 riastrad static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_dp_hbr2[] = { 524 1.1 riastrad /* NT mV Trans mV db */ 525 1.1 riastrad { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 526 1.1 riastrad { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */ 527 1.1 riastrad { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */ 528 1.1 riastrad { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */ 529 1.1 riastrad { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 530 1.1 riastrad { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */ 531 1.1 riastrad { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */ 532 1.1 riastrad { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */ 533 1.1 riastrad { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */ 534 1.1 riastrad { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 535 1.1 riastrad }; 536 1.1 riastrad 537 1.1 riastrad static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr2[] = { 538 1.1 riastrad /* NT mV Trans mV db */ 539 1.1 riastrad { 0x0, 0x7F, 0x3F, 0x00, 0x00 }, /* 200 200 0.0 */ 540 1.1 riastrad { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 200 250 1.9 */ 541 1.1 riastrad { 0x1, 0x7F, 0x33, 0x00, 0x0C }, /* 200 300 3.5 */ 542 1.1 riastrad { 0x9, 0x7F, 0x31, 0x00, 0x0E }, /* 200 350 4.9 */ 543 1.1 riastrad { 0x8, 0x7F, 0x3F, 0x00, 0x00 }, /* 250 250 0.0 */ 544 1.1 riastrad { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 250 300 1.6 */ 545 1.1 riastrad { 0x9, 0x7F, 0x35, 0x00, 0x0A }, /* 250 350 2.9 */ 546 1.1 riastrad { 0x1, 0x7F, 0x3F, 0x00, 0x00 }, /* 300 300 0.0 */ 547 1.1 riastrad { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 300 350 1.3 */ 548 1.1 riastrad { 0x9, 0x7F, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 549 1.1 riastrad }; 550 1.1 riastrad 551 1.1 riastrad static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr3[] = { 552 1.1 riastrad /* NT mV Trans mV db */ 553 1.1 riastrad { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 554 1.1 riastrad { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */ 555 1.1 riastrad { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */ 556 1.1 riastrad { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */ 557 1.1 riastrad { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 558 1.1 riastrad { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */ 559 1.1 riastrad { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */ 560 1.1 riastrad { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */ 561 1.1 riastrad { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */ 562 1.1 riastrad { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 563 1.1 riastrad }; 564 1.1 riastrad 565 1.1 riastrad static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_hdmi[] = { 566 1.1 riastrad /* NT mV Trans mV db */ 567 1.1 riastrad { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 568 1.1 riastrad { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */ 569 1.1 riastrad { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */ 570 1.1 riastrad { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 ALS */ 571 1.1 riastrad { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */ 572 1.1 riastrad { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */ 573 1.1 riastrad { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 574 1.1 riastrad }; 575 1.1 riastrad 576 1.1 riastrad struct icl_mg_phy_ddi_buf_trans { 577 1.1 riastrad u32 cri_txdeemph_override_5_0; 578 1.1 riastrad u32 cri_txdeemph_override_11_6; 579 1.1 riastrad u32 cri_txdeemph_override_17_12; 580 1.1 riastrad }; 581 1.1 riastrad 582 1.1 riastrad static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations[] = { 583 1.1 riastrad /* Voltage swing pre-emphasis */ 584 1.1 riastrad { 0x0, 0x1B, 0x00 }, /* 0 0 */ 585 1.1 riastrad { 0x0, 0x23, 0x08 }, /* 0 1 */ 586 1.1 riastrad { 0x0, 0x2D, 0x12 }, /* 0 2 */ 587 1.1 riastrad { 0x0, 0x00, 0x00 }, /* 0 3 */ 588 1.1 riastrad { 0x0, 0x23, 0x00 }, /* 1 0 */ 589 1.1 riastrad { 0x0, 0x2B, 0x09 }, /* 1 1 */ 590 1.1 riastrad { 0x0, 0x2E, 0x11 }, /* 1 2 */ 591 1.1 riastrad { 0x0, 0x2F, 0x00 }, /* 2 0 */ 592 1.1 riastrad { 0x0, 0x33, 0x0C }, /* 2 1 */ 593 1.1 riastrad { 0x0, 0x00, 0x00 }, /* 3 0 */ 594 1.1 riastrad }; 595 1.1 riastrad 596 1.1 riastrad struct tgl_dkl_phy_ddi_buf_trans { 597 1.1 riastrad u32 dkl_vswing_control; 598 1.1 riastrad u32 dkl_preshoot_control; 599 1.1 riastrad u32 dkl_de_emphasis_control; 600 1.1 riastrad }; 601 1.1 riastrad 602 1.1 riastrad static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_dp_ddi_trans[] = { 603 1.1 riastrad /* VS pre-emp Non-trans mV Pre-emph dB */ 604 1.1 riastrad { 0x7, 0x0, 0x00 }, /* 0 0 400mV 0 dB */ 605 1.1 riastrad { 0x5, 0x0, 0x03 }, /* 0 1 400mV 3.5 dB */ 606 1.1 riastrad { 0x2, 0x0, 0x0b }, /* 0 2 400mV 6 dB */ 607 1.1 riastrad { 0x0, 0x0, 0x19 }, /* 0 3 400mV 9.5 dB */ 608 1.1 riastrad { 0x5, 0x0, 0x00 }, /* 1 0 600mV 0 dB */ 609 1.1 riastrad { 0x2, 0x0, 0x03 }, /* 1 1 600mV 3.5 dB */ 610 1.1 riastrad { 0x0, 0x0, 0x14 }, /* 1 2 600mV 6 dB */ 611 1.1 riastrad { 0x2, 0x0, 0x00 }, /* 2 0 800mV 0 dB */ 612 1.1 riastrad { 0x0, 0x0, 0x0B }, /* 2 1 800mV 3.5 dB */ 613 1.1 riastrad { 0x0, 0x0, 0x00 }, /* 3 0 1200mV 0 dB HDMI default */ 614 1.1 riastrad }; 615 1.1 riastrad 616 1.1 riastrad static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_hdmi_ddi_trans[] = { 617 1.1 riastrad /* HDMI Preset VS Pre-emph */ 618 1.1 riastrad { 0x7, 0x0, 0x0 }, /* 1 400mV 0dB */ 619 1.1 riastrad { 0x6, 0x0, 0x0 }, /* 2 500mV 0dB */ 620 1.1 riastrad { 0x4, 0x0, 0x0 }, /* 3 650mV 0dB */ 621 1.1 riastrad { 0x2, 0x0, 0x0 }, /* 4 800mV 0dB */ 622 1.1 riastrad { 0x0, 0x0, 0x0 }, /* 5 1000mV 0dB */ 623 1.1 riastrad { 0x0, 0x0, 0x5 }, /* 6 Full -1.5 dB */ 624 1.1 riastrad { 0x0, 0x0, 0x6 }, /* 7 Full -1.8 dB */ 625 1.1 riastrad { 0x0, 0x0, 0x7 }, /* 8 Full -2 dB */ 626 1.1 riastrad { 0x0, 0x0, 0x8 }, /* 9 Full -2.5 dB */ 627 1.1 riastrad { 0x0, 0x0, 0xA }, /* 10 Full -3 dB */ 628 1.1 riastrad }; 629 1.1 riastrad 630 1.1 riastrad static const struct ddi_buf_trans * 631 1.1 riastrad bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries) 632 1.1 riastrad { 633 1.1 riastrad if (dev_priv->vbt.edp.low_vswing) { 634 1.1 riastrad *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp); 635 1.1 riastrad return bdw_ddi_translations_edp; 636 1.1 riastrad } else { 637 1.1 riastrad *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 638 1.1 riastrad return bdw_ddi_translations_dp; 639 1.1 riastrad } 640 1.1 riastrad } 641 1.1 riastrad 642 1.1 riastrad static const struct ddi_buf_trans * 643 1.1 riastrad skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries) 644 1.1 riastrad { 645 1.1 riastrad if (IS_SKL_ULX(dev_priv)) { 646 1.1 riastrad *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp); 647 1.1 riastrad return skl_y_ddi_translations_dp; 648 1.1 riastrad } else if (IS_SKL_ULT(dev_priv)) { 649 1.1 riastrad *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp); 650 1.1 riastrad return skl_u_ddi_translations_dp; 651 1.1 riastrad } else { 652 1.1 riastrad *n_entries = ARRAY_SIZE(skl_ddi_translations_dp); 653 1.1 riastrad return skl_ddi_translations_dp; 654 1.1 riastrad } 655 1.1 riastrad } 656 1.1 riastrad 657 1.1 riastrad static const struct ddi_buf_trans * 658 1.1 riastrad kbl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries) 659 1.1 riastrad { 660 1.1 riastrad if (IS_KBL_ULX(dev_priv) || IS_CFL_ULX(dev_priv)) { 661 1.1 riastrad *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp); 662 1.1 riastrad return kbl_y_ddi_translations_dp; 663 1.1 riastrad } else if (IS_KBL_ULT(dev_priv) || IS_CFL_ULT(dev_priv)) { 664 1.1 riastrad *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp); 665 1.1 riastrad return kbl_u_ddi_translations_dp; 666 1.1 riastrad } else { 667 1.1 riastrad *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp); 668 1.1 riastrad return kbl_ddi_translations_dp; 669 1.1 riastrad } 670 1.1 riastrad } 671 1.1 riastrad 672 1.1 riastrad static const struct ddi_buf_trans * 673 1.1 riastrad skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries) 674 1.1 riastrad { 675 1.1 riastrad if (dev_priv->vbt.edp.low_vswing) { 676 1.1 riastrad if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv) || 677 1.1 riastrad IS_CFL_ULX(dev_priv)) { 678 1.1 riastrad *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp); 679 1.1 riastrad return skl_y_ddi_translations_edp; 680 1.1 riastrad } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv) || 681 1.1 riastrad IS_CFL_ULT(dev_priv)) { 682 1.1 riastrad *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp); 683 1.1 riastrad return skl_u_ddi_translations_edp; 684 1.1 riastrad } else { 685 1.1 riastrad *n_entries = ARRAY_SIZE(skl_ddi_translations_edp); 686 1.1 riastrad return skl_ddi_translations_edp; 687 1.1 riastrad } 688 1.1 riastrad } 689 1.1 riastrad 690 1.1 riastrad if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) 691 1.1 riastrad return kbl_get_buf_trans_dp(dev_priv, n_entries); 692 1.1 riastrad else 693 1.1 riastrad return skl_get_buf_trans_dp(dev_priv, n_entries); 694 1.1 riastrad } 695 1.1 riastrad 696 1.1 riastrad static const struct ddi_buf_trans * 697 1.1 riastrad skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries) 698 1.1 riastrad { 699 1.1 riastrad if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv) || 700 1.1 riastrad IS_CFL_ULX(dev_priv)) { 701 1.1 riastrad *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi); 702 1.1 riastrad return skl_y_ddi_translations_hdmi; 703 1.1 riastrad } else { 704 1.1 riastrad *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi); 705 1.1 riastrad return skl_ddi_translations_hdmi; 706 1.1 riastrad } 707 1.1 riastrad } 708 1.1 riastrad 709 1.1 riastrad static int skl_buf_trans_num_entries(enum port port, int n_entries) 710 1.1 riastrad { 711 1.1 riastrad /* Only DDIA and DDIE can select the 10th register with DP */ 712 1.1 riastrad if (port == PORT_A || port == PORT_E) 713 1.1 riastrad return min(n_entries, 10); 714 1.1 riastrad else 715 1.1 riastrad return min(n_entries, 9); 716 1.1 riastrad } 717 1.1 riastrad 718 1.1 riastrad static const struct ddi_buf_trans * 719 1.1 riastrad intel_ddi_get_buf_trans_dp(struct drm_i915_private *dev_priv, 720 1.1 riastrad enum port port, int *n_entries) 721 1.1 riastrad { 722 1.1 riastrad if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) { 723 1.1 riastrad const struct ddi_buf_trans *ddi_translations = 724 1.1 riastrad kbl_get_buf_trans_dp(dev_priv, n_entries); 725 1.1 riastrad *n_entries = skl_buf_trans_num_entries(port, *n_entries); 726 1.1 riastrad return ddi_translations; 727 1.1 riastrad } else if (IS_SKYLAKE(dev_priv)) { 728 1.1 riastrad const struct ddi_buf_trans *ddi_translations = 729 1.1 riastrad skl_get_buf_trans_dp(dev_priv, n_entries); 730 1.1 riastrad *n_entries = skl_buf_trans_num_entries(port, *n_entries); 731 1.1 riastrad return ddi_translations; 732 1.1 riastrad } else if (IS_BROADWELL(dev_priv)) { 733 1.1 riastrad *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 734 1.1 riastrad return bdw_ddi_translations_dp; 735 1.1 riastrad } else if (IS_HASWELL(dev_priv)) { 736 1.1 riastrad *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp); 737 1.1 riastrad return hsw_ddi_translations_dp; 738 1.1 riastrad } 739 1.1 riastrad 740 1.1 riastrad *n_entries = 0; 741 1.1 riastrad return NULL; 742 1.1 riastrad } 743 1.1 riastrad 744 1.1 riastrad static const struct ddi_buf_trans * 745 1.1 riastrad intel_ddi_get_buf_trans_edp(struct drm_i915_private *dev_priv, 746 1.1 riastrad enum port port, int *n_entries) 747 1.1 riastrad { 748 1.1 riastrad if (IS_GEN9_BC(dev_priv)) { 749 1.1 riastrad const struct ddi_buf_trans *ddi_translations = 750 1.1 riastrad skl_get_buf_trans_edp(dev_priv, n_entries); 751 1.1 riastrad *n_entries = skl_buf_trans_num_entries(port, *n_entries); 752 1.1 riastrad return ddi_translations; 753 1.1 riastrad } else if (IS_BROADWELL(dev_priv)) { 754 1.1 riastrad return bdw_get_buf_trans_edp(dev_priv, n_entries); 755 1.1 riastrad } else if (IS_HASWELL(dev_priv)) { 756 1.1 riastrad *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp); 757 1.1 riastrad return hsw_ddi_translations_dp; 758 1.1 riastrad } 759 1.1 riastrad 760 1.1 riastrad *n_entries = 0; 761 1.1 riastrad return NULL; 762 1.1 riastrad } 763 1.1 riastrad 764 1.1 riastrad static const struct ddi_buf_trans * 765 1.1 riastrad intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv, 766 1.1 riastrad int *n_entries) 767 1.1 riastrad { 768 1.1 riastrad if (IS_BROADWELL(dev_priv)) { 769 1.1 riastrad *n_entries = ARRAY_SIZE(bdw_ddi_translations_fdi); 770 1.1 riastrad return bdw_ddi_translations_fdi; 771 1.1 riastrad } else if (IS_HASWELL(dev_priv)) { 772 1.1 riastrad *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi); 773 1.1 riastrad return hsw_ddi_translations_fdi; 774 1.1 riastrad } 775 1.1 riastrad 776 1.1 riastrad *n_entries = 0; 777 1.1 riastrad return NULL; 778 1.1 riastrad } 779 1.1 riastrad 780 1.1 riastrad static const struct ddi_buf_trans * 781 1.1 riastrad intel_ddi_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, 782 1.1 riastrad int *n_entries) 783 1.1 riastrad { 784 1.1 riastrad if (IS_GEN9_BC(dev_priv)) { 785 1.1 riastrad return skl_get_buf_trans_hdmi(dev_priv, n_entries); 786 1.1 riastrad } else if (IS_BROADWELL(dev_priv)) { 787 1.1 riastrad *n_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); 788 1.1 riastrad return bdw_ddi_translations_hdmi; 789 1.1 riastrad } else if (IS_HASWELL(dev_priv)) { 790 1.1 riastrad *n_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); 791 1.1 riastrad return hsw_ddi_translations_hdmi; 792 1.1 riastrad } 793 1.1 riastrad 794 1.1 riastrad *n_entries = 0; 795 1.1 riastrad return NULL; 796 1.1 riastrad } 797 1.1 riastrad 798 1.1 riastrad static const struct bxt_ddi_buf_trans * 799 1.1 riastrad bxt_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries) 800 1.1 riastrad { 801 1.1 riastrad *n_entries = ARRAY_SIZE(bxt_ddi_translations_dp); 802 1.1 riastrad return bxt_ddi_translations_dp; 803 1.1 riastrad } 804 1.1 riastrad 805 1.1 riastrad static const struct bxt_ddi_buf_trans * 806 1.1 riastrad bxt_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries) 807 1.1 riastrad { 808 1.1 riastrad if (dev_priv->vbt.edp.low_vswing) { 809 1.1 riastrad *n_entries = ARRAY_SIZE(bxt_ddi_translations_edp); 810 1.1 riastrad return bxt_ddi_translations_edp; 811 1.1 riastrad } 812 1.1 riastrad 813 1.1 riastrad return bxt_get_buf_trans_dp(dev_priv, n_entries); 814 1.1 riastrad } 815 1.1 riastrad 816 1.1 riastrad static const struct bxt_ddi_buf_trans * 817 1.1 riastrad bxt_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries) 818 1.1 riastrad { 819 1.1 riastrad *n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi); 820 1.1 riastrad return bxt_ddi_translations_hdmi; 821 1.1 riastrad } 822 1.1 riastrad 823 1.1 riastrad static const struct cnl_ddi_buf_trans * 824 1.1 riastrad cnl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries) 825 1.1 riastrad { 826 1.1 riastrad u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 827 1.1 riastrad 828 1.1 riastrad if (voltage == VOLTAGE_INFO_0_85V) { 829 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V); 830 1.1 riastrad return cnl_ddi_translations_hdmi_0_85V; 831 1.1 riastrad } else if (voltage == VOLTAGE_INFO_0_95V) { 832 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V); 833 1.1 riastrad return cnl_ddi_translations_hdmi_0_95V; 834 1.1 riastrad } else if (voltage == VOLTAGE_INFO_1_05V) { 835 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V); 836 1.1 riastrad return cnl_ddi_translations_hdmi_1_05V; 837 1.1 riastrad } else { 838 1.1 riastrad *n_entries = 1; /* shut up gcc */ 839 1.1 riastrad MISSING_CASE(voltage); 840 1.1 riastrad } 841 1.1 riastrad return NULL; 842 1.1 riastrad } 843 1.1 riastrad 844 1.1 riastrad static const struct cnl_ddi_buf_trans * 845 1.1 riastrad cnl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries) 846 1.1 riastrad { 847 1.1 riastrad u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 848 1.1 riastrad 849 1.1 riastrad if (voltage == VOLTAGE_INFO_0_85V) { 850 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V); 851 1.1 riastrad return cnl_ddi_translations_dp_0_85V; 852 1.1 riastrad } else if (voltage == VOLTAGE_INFO_0_95V) { 853 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V); 854 1.1 riastrad return cnl_ddi_translations_dp_0_95V; 855 1.1 riastrad } else if (voltage == VOLTAGE_INFO_1_05V) { 856 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V); 857 1.1 riastrad return cnl_ddi_translations_dp_1_05V; 858 1.1 riastrad } else { 859 1.1 riastrad *n_entries = 1; /* shut up gcc */ 860 1.1 riastrad MISSING_CASE(voltage); 861 1.1 riastrad } 862 1.1 riastrad return NULL; 863 1.1 riastrad } 864 1.1 riastrad 865 1.1 riastrad static const struct cnl_ddi_buf_trans * 866 1.1 riastrad cnl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries) 867 1.1 riastrad { 868 1.1 riastrad u32 voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 869 1.1 riastrad 870 1.1 riastrad if (dev_priv->vbt.edp.low_vswing) { 871 1.1 riastrad if (voltage == VOLTAGE_INFO_0_85V) { 872 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V); 873 1.1 riastrad return cnl_ddi_translations_edp_0_85V; 874 1.1 riastrad } else if (voltage == VOLTAGE_INFO_0_95V) { 875 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V); 876 1.1 riastrad return cnl_ddi_translations_edp_0_95V; 877 1.1 riastrad } else if (voltage == VOLTAGE_INFO_1_05V) { 878 1.1 riastrad *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V); 879 1.1 riastrad return cnl_ddi_translations_edp_1_05V; 880 1.1 riastrad } else { 881 1.1 riastrad *n_entries = 1; /* shut up gcc */ 882 1.1 riastrad MISSING_CASE(voltage); 883 1.1 riastrad } 884 1.1 riastrad return NULL; 885 1.1 riastrad } else { 886 1.1 riastrad return cnl_get_buf_trans_dp(dev_priv, n_entries); 887 1.1 riastrad } 888 1.1 riastrad } 889 1.1 riastrad 890 1.1 riastrad static const struct cnl_ddi_buf_trans * 891 1.1 riastrad icl_get_combo_buf_trans(struct drm_i915_private *dev_priv, int type, int rate, 892 1.1 riastrad int *n_entries) 893 1.1 riastrad { 894 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) { 895 1.1 riastrad *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi); 896 1.1 riastrad return icl_combo_phy_ddi_translations_hdmi; 897 1.1 riastrad } else if (rate > 540000 && type == INTEL_OUTPUT_EDP) { 898 1.1 riastrad *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr3); 899 1.1 riastrad return icl_combo_phy_ddi_translations_edp_hbr3; 900 1.1 riastrad } else if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) { 901 1.1 riastrad *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2); 902 1.1 riastrad return icl_combo_phy_ddi_translations_edp_hbr2; 903 1.1 riastrad } 904 1.1 riastrad 905 1.1 riastrad *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_dp_hbr2); 906 1.1 riastrad return icl_combo_phy_ddi_translations_dp_hbr2; 907 1.1 riastrad } 908 1.1 riastrad 909 1.1 riastrad static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port) 910 1.1 riastrad { 911 1.1 riastrad struct ddi_vbt_port_info *port_info = &dev_priv->vbt.ddi_port_info[port]; 912 1.1 riastrad int n_entries, level, default_entry; 913 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 914 1.1 riastrad 915 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 916 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) 917 1.1 riastrad icl_get_combo_buf_trans(dev_priv, INTEL_OUTPUT_HDMI, 918 1.1 riastrad 0, &n_entries); 919 1.1 riastrad else 920 1.1 riastrad n_entries = ARRAY_SIZE(tgl_dkl_phy_hdmi_ddi_trans); 921 1.1 riastrad default_entry = n_entries - 1; 922 1.1 riastrad } else if (INTEL_GEN(dev_priv) == 11) { 923 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) 924 1.1 riastrad icl_get_combo_buf_trans(dev_priv, INTEL_OUTPUT_HDMI, 925 1.1 riastrad 0, &n_entries); 926 1.1 riastrad else 927 1.1 riastrad n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations); 928 1.1 riastrad default_entry = n_entries - 1; 929 1.1 riastrad } else if (IS_CANNONLAKE(dev_priv)) { 930 1.1 riastrad cnl_get_buf_trans_hdmi(dev_priv, &n_entries); 931 1.1 riastrad default_entry = n_entries - 1; 932 1.1 riastrad } else if (IS_GEN9_LP(dev_priv)) { 933 1.1 riastrad bxt_get_buf_trans_hdmi(dev_priv, &n_entries); 934 1.1 riastrad default_entry = n_entries - 1; 935 1.1 riastrad } else if (IS_GEN9_BC(dev_priv)) { 936 1.1 riastrad intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries); 937 1.1 riastrad default_entry = 8; 938 1.1 riastrad } else if (IS_BROADWELL(dev_priv)) { 939 1.1 riastrad intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries); 940 1.1 riastrad default_entry = 7; 941 1.1 riastrad } else if (IS_HASWELL(dev_priv)) { 942 1.1 riastrad intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries); 943 1.1 riastrad default_entry = 6; 944 1.1 riastrad } else { 945 1.1 riastrad WARN(1, "ddi translation table missing\n"); 946 1.1 riastrad return 0; 947 1.1 riastrad } 948 1.1 riastrad 949 1.1 riastrad if (WARN_ON_ONCE(n_entries == 0)) 950 1.1 riastrad return 0; 951 1.1 riastrad 952 1.1 riastrad if (port_info->hdmi_level_shift_set) 953 1.1 riastrad level = port_info->hdmi_level_shift; 954 1.1 riastrad else 955 1.1 riastrad level = default_entry; 956 1.1 riastrad 957 1.1 riastrad if (WARN_ON_ONCE(level >= n_entries)) 958 1.1 riastrad level = n_entries - 1; 959 1.1 riastrad 960 1.1 riastrad return level; 961 1.1 riastrad } 962 1.1 riastrad 963 1.1 riastrad /* 964 1.1 riastrad * Starting with Haswell, DDI port buffers must be programmed with correct 965 1.1 riastrad * values in advance. This function programs the correct values for 966 1.1 riastrad * DP/eDP/FDI use cases. 967 1.1 riastrad */ 968 1.1 riastrad static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder, 969 1.1 riastrad const struct intel_crtc_state *crtc_state) 970 1.1 riastrad { 971 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 972 1.1 riastrad u32 iboost_bit = 0; 973 1.1 riastrad int i, n_entries; 974 1.1 riastrad enum port port = encoder->port; 975 1.1 riastrad const struct ddi_buf_trans *ddi_translations; 976 1.1 riastrad 977 1.1 riastrad if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) 978 1.1 riastrad ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv, 979 1.1 riastrad &n_entries); 980 1.1 riastrad else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) 981 1.1 riastrad ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv, port, 982 1.1 riastrad &n_entries); 983 1.1 riastrad else 984 1.1 riastrad ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv, port, 985 1.1 riastrad &n_entries); 986 1.1 riastrad 987 1.1 riastrad /* If we're boosting the current, set bit 31 of trans1 */ 988 1.1 riastrad if (IS_GEN9_BC(dev_priv) && 989 1.1 riastrad dev_priv->vbt.ddi_port_info[port].dp_boost_level) 990 1.1 riastrad iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; 991 1.1 riastrad 992 1.1 riastrad for (i = 0; i < n_entries; i++) { 993 1.1 riastrad I915_WRITE(DDI_BUF_TRANS_LO(port, i), 994 1.1 riastrad ddi_translations[i].trans1 | iboost_bit); 995 1.1 riastrad I915_WRITE(DDI_BUF_TRANS_HI(port, i), 996 1.1 riastrad ddi_translations[i].trans2); 997 1.1 riastrad } 998 1.1 riastrad } 999 1.1 riastrad 1000 1.1 riastrad /* 1001 1.1 riastrad * Starting with Haswell, DDI port buffers must be programmed with correct 1002 1.1 riastrad * values in advance. This function programs the correct values for 1003 1.1 riastrad * HDMI/DVI use cases. 1004 1.1 riastrad */ 1005 1.1 riastrad static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder, 1006 1.1 riastrad int level) 1007 1.1 riastrad { 1008 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1009 1.1 riastrad u32 iboost_bit = 0; 1010 1.1 riastrad int n_entries; 1011 1.1 riastrad enum port port = encoder->port; 1012 1.1 riastrad const struct ddi_buf_trans *ddi_translations; 1013 1.1 riastrad 1014 1.1 riastrad ddi_translations = intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries); 1015 1.1 riastrad 1016 1.1 riastrad if (WARN_ON_ONCE(!ddi_translations)) 1017 1.1 riastrad return; 1018 1.1 riastrad if (WARN_ON_ONCE(level >= n_entries)) 1019 1.1 riastrad level = n_entries - 1; 1020 1.1 riastrad 1021 1.1 riastrad /* If we're boosting the current, set bit 31 of trans1 */ 1022 1.1 riastrad if (IS_GEN9_BC(dev_priv) && 1023 1.1 riastrad dev_priv->vbt.ddi_port_info[port].hdmi_boost_level) 1024 1.1 riastrad iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; 1025 1.1 riastrad 1026 1.1 riastrad /* Entry 9 is for HDMI: */ 1027 1.1 riastrad I915_WRITE(DDI_BUF_TRANS_LO(port, 9), 1028 1.1 riastrad ddi_translations[level].trans1 | iboost_bit); 1029 1.1 riastrad I915_WRITE(DDI_BUF_TRANS_HI(port, 9), 1030 1.1 riastrad ddi_translations[level].trans2); 1031 1.1 riastrad } 1032 1.1 riastrad 1033 1.1 riastrad static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, 1034 1.1 riastrad enum port port) 1035 1.1 riastrad { 1036 1.1 riastrad i915_reg_t reg = DDI_BUF_CTL(port); 1037 1.1 riastrad int i; 1038 1.1 riastrad 1039 1.1 riastrad for (i = 0; i < 16; i++) { 1040 1.1 riastrad udelay(1); 1041 1.1 riastrad if (I915_READ(reg) & DDI_BUF_IS_IDLE) 1042 1.1 riastrad return; 1043 1.1 riastrad } 1044 1.1 riastrad DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port)); 1045 1.1 riastrad } 1046 1.1 riastrad 1047 1.1 riastrad static u32 hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll) 1048 1.1 riastrad { 1049 1.1 riastrad switch (pll->info->id) { 1050 1.1 riastrad case DPLL_ID_WRPLL1: 1051 1.1 riastrad return PORT_CLK_SEL_WRPLL1; 1052 1.1 riastrad case DPLL_ID_WRPLL2: 1053 1.1 riastrad return PORT_CLK_SEL_WRPLL2; 1054 1.1 riastrad case DPLL_ID_SPLL: 1055 1.1 riastrad return PORT_CLK_SEL_SPLL; 1056 1.1 riastrad case DPLL_ID_LCPLL_810: 1057 1.1 riastrad return PORT_CLK_SEL_LCPLL_810; 1058 1.1 riastrad case DPLL_ID_LCPLL_1350: 1059 1.1 riastrad return PORT_CLK_SEL_LCPLL_1350; 1060 1.1 riastrad case DPLL_ID_LCPLL_2700: 1061 1.1 riastrad return PORT_CLK_SEL_LCPLL_2700; 1062 1.1 riastrad default: 1063 1.1 riastrad MISSING_CASE(pll->info->id); 1064 1.1 riastrad return PORT_CLK_SEL_NONE; 1065 1.1 riastrad } 1066 1.1 riastrad } 1067 1.1 riastrad 1068 1.1 riastrad static u32 icl_pll_to_ddi_clk_sel(struct intel_encoder *encoder, 1069 1.1 riastrad const struct intel_crtc_state *crtc_state) 1070 1.1 riastrad { 1071 1.1 riastrad const struct intel_shared_dpll *pll = crtc_state->shared_dpll; 1072 1.1 riastrad int clock = crtc_state->port_clock; 1073 1.1 riastrad const enum intel_dpll_id id = pll->info->id; 1074 1.1 riastrad 1075 1.1 riastrad switch (id) { 1076 1.1 riastrad default: 1077 1.1 riastrad /* 1078 1.1 riastrad * DPLL_ID_ICL_DPLL0 and DPLL_ID_ICL_DPLL1 should not be used 1079 1.1 riastrad * here, so do warn if this get passed in 1080 1.1 riastrad */ 1081 1.1 riastrad MISSING_CASE(id); 1082 1.1 riastrad return DDI_CLK_SEL_NONE; 1083 1.1 riastrad case DPLL_ID_ICL_TBTPLL: 1084 1.1 riastrad switch (clock) { 1085 1.1 riastrad case 162000: 1086 1.1 riastrad return DDI_CLK_SEL_TBT_162; 1087 1.1 riastrad case 270000: 1088 1.1 riastrad return DDI_CLK_SEL_TBT_270; 1089 1.1 riastrad case 540000: 1090 1.1 riastrad return DDI_CLK_SEL_TBT_540; 1091 1.1 riastrad case 810000: 1092 1.1 riastrad return DDI_CLK_SEL_TBT_810; 1093 1.1 riastrad default: 1094 1.1 riastrad MISSING_CASE(clock); 1095 1.1 riastrad return DDI_CLK_SEL_NONE; 1096 1.1 riastrad } 1097 1.1 riastrad case DPLL_ID_ICL_MGPLL1: 1098 1.1 riastrad case DPLL_ID_ICL_MGPLL2: 1099 1.1 riastrad case DPLL_ID_ICL_MGPLL3: 1100 1.1 riastrad case DPLL_ID_ICL_MGPLL4: 1101 1.1 riastrad case DPLL_ID_TGL_MGPLL5: 1102 1.1 riastrad case DPLL_ID_TGL_MGPLL6: 1103 1.1 riastrad return DDI_CLK_SEL_MG; 1104 1.1 riastrad } 1105 1.1 riastrad } 1106 1.1 riastrad 1107 1.1 riastrad /* Starting with Haswell, different DDI ports can work in FDI mode for 1108 1.1 riastrad * connection to the PCH-located connectors. For this, it is necessary to train 1109 1.1 riastrad * both the DDI port and PCH receiver for the desired DDI buffer settings. 1110 1.1 riastrad * 1111 1.1 riastrad * The recommended port to work in FDI mode is DDI E, which we use here. Also, 1112 1.1 riastrad * please note that when FDI mode is active on DDI E, it shares 2 lines with 1113 1.1 riastrad * DDI A (which is used for eDP) 1114 1.1 riastrad */ 1115 1.1 riastrad 1116 1.1 riastrad void hsw_fdi_link_train(struct intel_encoder *encoder, 1117 1.1 riastrad const struct intel_crtc_state *crtc_state) 1118 1.1 riastrad { 1119 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1120 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1121 1.1 riastrad u32 temp, i, rx_ctl_val, ddi_pll_sel; 1122 1.1 riastrad 1123 1.1 riastrad intel_prepare_dp_ddi_buffers(encoder, crtc_state); 1124 1.1 riastrad 1125 1.1 riastrad /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the 1126 1.1 riastrad * mode set "sequence for CRT port" document: 1127 1.1 riastrad * - TP1 to TP2 time with the default value 1128 1.1 riastrad * - FDI delay to 90h 1129 1.1 riastrad * 1130 1.1 riastrad * WaFDIAutoLinkSetTimingOverrride:hsw 1131 1.1 riastrad */ 1132 1.1 riastrad I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) | 1133 1.1 riastrad FDI_RX_PWRDN_LANE0_VAL(2) | 1134 1.1 riastrad FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); 1135 1.1 riastrad 1136 1.1 riastrad /* Enable the PCH Receiver FDI PLL */ 1137 1.1 riastrad rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE | 1138 1.1 riastrad FDI_RX_PLL_ENABLE | 1139 1.1 riastrad FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); 1140 1.1 riastrad I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); 1141 1.1 riastrad POSTING_READ(FDI_RX_CTL(PIPE_A)); 1142 1.1 riastrad udelay(220); 1143 1.1 riastrad 1144 1.1 riastrad /* Switch from Rawclk to PCDclk */ 1145 1.1 riastrad rx_ctl_val |= FDI_PCDCLK; 1146 1.1 riastrad I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); 1147 1.1 riastrad 1148 1.1 riastrad /* Configure Port Clock Select */ 1149 1.1 riastrad ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll); 1150 1.1 riastrad I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel); 1151 1.1 riastrad WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL); 1152 1.1 riastrad 1153 1.1 riastrad /* Start the training iterating through available voltages and emphasis, 1154 1.1 riastrad * testing each value twice. */ 1155 1.1 riastrad for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) { 1156 1.1 riastrad /* Configure DP_TP_CTL with auto-training */ 1157 1.1 riastrad I915_WRITE(DP_TP_CTL(PORT_E), 1158 1.1 riastrad DP_TP_CTL_FDI_AUTOTRAIN | 1159 1.1 riastrad DP_TP_CTL_ENHANCED_FRAME_ENABLE | 1160 1.1 riastrad DP_TP_CTL_LINK_TRAIN_PAT1 | 1161 1.1 riastrad DP_TP_CTL_ENABLE); 1162 1.1 riastrad 1163 1.1 riastrad /* Configure and enable DDI_BUF_CTL for DDI E with next voltage. 1164 1.1 riastrad * DDI E does not support port reversal, the functionality is 1165 1.1 riastrad * achieved on the PCH side in FDI_RX_CTL, so no need to set the 1166 1.1 riastrad * port reversal bit */ 1167 1.1 riastrad I915_WRITE(DDI_BUF_CTL(PORT_E), 1168 1.1 riastrad DDI_BUF_CTL_ENABLE | 1169 1.1 riastrad ((crtc_state->fdi_lanes - 1) << 1) | 1170 1.1 riastrad DDI_BUF_TRANS_SELECT(i / 2)); 1171 1.1 riastrad POSTING_READ(DDI_BUF_CTL(PORT_E)); 1172 1.1 riastrad 1173 1.1 riastrad udelay(600); 1174 1.1 riastrad 1175 1.1 riastrad /* Program PCH FDI Receiver TU */ 1176 1.1 riastrad I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64)); 1177 1.1 riastrad 1178 1.1 riastrad /* Enable PCH FDI Receiver with auto-training */ 1179 1.1 riastrad rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO; 1180 1.1 riastrad I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); 1181 1.1 riastrad POSTING_READ(FDI_RX_CTL(PIPE_A)); 1182 1.1 riastrad 1183 1.1 riastrad /* Wait for FDI receiver lane calibration */ 1184 1.1 riastrad udelay(30); 1185 1.1 riastrad 1186 1.1 riastrad /* Unset FDI_RX_MISC pwrdn lanes */ 1187 1.1 riastrad temp = I915_READ(FDI_RX_MISC(PIPE_A)); 1188 1.1 riastrad temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 1189 1.1 riastrad I915_WRITE(FDI_RX_MISC(PIPE_A), temp); 1190 1.1 riastrad POSTING_READ(FDI_RX_MISC(PIPE_A)); 1191 1.1 riastrad 1192 1.1 riastrad /* Wait for FDI auto training time */ 1193 1.1 riastrad udelay(5); 1194 1.1 riastrad 1195 1.1 riastrad temp = I915_READ(DP_TP_STATUS(PORT_E)); 1196 1.1 riastrad if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { 1197 1.1 riastrad DRM_DEBUG_KMS("FDI link training done on step %d\n", i); 1198 1.1 riastrad break; 1199 1.1 riastrad } 1200 1.1 riastrad 1201 1.1 riastrad /* 1202 1.1 riastrad * Leave things enabled even if we failed to train FDI. 1203 1.1 riastrad * Results in less fireworks from the state checker. 1204 1.1 riastrad */ 1205 1.1 riastrad if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) { 1206 1.1 riastrad DRM_ERROR("FDI link training failed!\n"); 1207 1.1 riastrad break; 1208 1.1 riastrad } 1209 1.1 riastrad 1210 1.1 riastrad rx_ctl_val &= ~FDI_RX_ENABLE; 1211 1.1 riastrad I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val); 1212 1.1 riastrad POSTING_READ(FDI_RX_CTL(PIPE_A)); 1213 1.1 riastrad 1214 1.1 riastrad temp = I915_READ(DDI_BUF_CTL(PORT_E)); 1215 1.1 riastrad temp &= ~DDI_BUF_CTL_ENABLE; 1216 1.1 riastrad I915_WRITE(DDI_BUF_CTL(PORT_E), temp); 1217 1.1 riastrad POSTING_READ(DDI_BUF_CTL(PORT_E)); 1218 1.1 riastrad 1219 1.1 riastrad /* Disable DP_TP_CTL and FDI_RX_CTL and retry */ 1220 1.1 riastrad temp = I915_READ(DP_TP_CTL(PORT_E)); 1221 1.1 riastrad temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 1222 1.1 riastrad temp |= DP_TP_CTL_LINK_TRAIN_PAT1; 1223 1.1 riastrad I915_WRITE(DP_TP_CTL(PORT_E), temp); 1224 1.1 riastrad POSTING_READ(DP_TP_CTL(PORT_E)); 1225 1.1 riastrad 1226 1.1 riastrad intel_wait_ddi_buf_idle(dev_priv, PORT_E); 1227 1.1 riastrad 1228 1.1 riastrad /* Reset FDI_RX_MISC pwrdn lanes */ 1229 1.1 riastrad temp = I915_READ(FDI_RX_MISC(PIPE_A)); 1230 1.1 riastrad temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 1231 1.1 riastrad temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); 1232 1.1 riastrad I915_WRITE(FDI_RX_MISC(PIPE_A), temp); 1233 1.1 riastrad POSTING_READ(FDI_RX_MISC(PIPE_A)); 1234 1.1 riastrad } 1235 1.1 riastrad 1236 1.1 riastrad /* Enable normal pixel sending for FDI */ 1237 1.1 riastrad I915_WRITE(DP_TP_CTL(PORT_E), 1238 1.1 riastrad DP_TP_CTL_FDI_AUTOTRAIN | 1239 1.1 riastrad DP_TP_CTL_LINK_TRAIN_NORMAL | 1240 1.1 riastrad DP_TP_CTL_ENHANCED_FRAME_ENABLE | 1241 1.1 riastrad DP_TP_CTL_ENABLE); 1242 1.1 riastrad } 1243 1.1 riastrad 1244 1.1 riastrad static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder) 1245 1.1 riastrad { 1246 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1247 1.1 riastrad struct intel_digital_port *intel_dig_port = 1248 1.1 riastrad enc_to_dig_port(encoder); 1249 1.1 riastrad 1250 1.1 riastrad intel_dp->DP = intel_dig_port->saved_port_bits | 1251 1.1 riastrad DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0); 1252 1.1 riastrad intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count); 1253 1.1 riastrad } 1254 1.1 riastrad 1255 1.1 riastrad static struct intel_encoder * 1256 1.1 riastrad intel_ddi_get_crtc_encoder(struct intel_crtc *crtc) 1257 1.1 riastrad { 1258 1.1 riastrad struct drm_device *dev = crtc->base.dev; 1259 1.1 riastrad struct intel_encoder *encoder, *ret = NULL; 1260 1.1 riastrad int num_encoders = 0; 1261 1.1 riastrad 1262 1.1 riastrad for_each_encoder_on_crtc(dev, &crtc->base, encoder) { 1263 1.1 riastrad ret = encoder; 1264 1.1 riastrad num_encoders++; 1265 1.1 riastrad } 1266 1.1 riastrad 1267 1.1 riastrad if (num_encoders != 1) 1268 1.1 riastrad WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders, 1269 1.1 riastrad pipe_name(crtc->pipe)); 1270 1.1 riastrad 1271 1.1 riastrad BUG_ON(ret == NULL); 1272 1.1 riastrad return ret; 1273 1.1 riastrad } 1274 1.1 riastrad 1275 1.1 riastrad static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv, 1276 1.1 riastrad i915_reg_t reg) 1277 1.1 riastrad { 1278 1.1 riastrad int refclk; 1279 1.1 riastrad int n, p, r; 1280 1.1 riastrad u32 wrpll; 1281 1.1 riastrad 1282 1.1 riastrad wrpll = I915_READ(reg); 1283 1.1 riastrad switch (wrpll & WRPLL_REF_MASK) { 1284 1.1 riastrad case WRPLL_REF_SPECIAL_HSW: 1285 1.1 riastrad /* 1286 1.1 riastrad * muxed-SSC for BDW. 1287 1.1 riastrad * non-SSC for non-ULT HSW. Check FUSE_STRAP3 1288 1.1 riastrad * for the non-SSC reference frequency. 1289 1.1 riastrad */ 1290 1.1 riastrad if (IS_HASWELL(dev_priv) && !IS_HSW_ULT(dev_priv)) { 1291 1.1 riastrad if (I915_READ(FUSE_STRAP3) & HSW_REF_CLK_SELECT) 1292 1.1 riastrad refclk = 24; 1293 1.1 riastrad else 1294 1.1 riastrad refclk = 135; 1295 1.1 riastrad break; 1296 1.1 riastrad } 1297 1.1 riastrad /* fall through */ 1298 1.1 riastrad case WRPLL_REF_PCH_SSC: 1299 1.1 riastrad /* 1300 1.1 riastrad * We could calculate spread here, but our checking 1301 1.1 riastrad * code only cares about 5% accuracy, and spread is a max of 1302 1.1 riastrad * 0.5% downspread. 1303 1.1 riastrad */ 1304 1.1 riastrad refclk = 135; 1305 1.1 riastrad break; 1306 1.1 riastrad case WRPLL_REF_LCPLL: 1307 1.1 riastrad refclk = 2700; 1308 1.1 riastrad break; 1309 1.1 riastrad default: 1310 1.1 riastrad MISSING_CASE(wrpll); 1311 1.1 riastrad return 0; 1312 1.1 riastrad } 1313 1.1 riastrad 1314 1.1 riastrad r = wrpll & WRPLL_DIVIDER_REF_MASK; 1315 1.1 riastrad p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT; 1316 1.1 riastrad n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT; 1317 1.1 riastrad 1318 1.1 riastrad /* Convert to KHz, p & r have a fixed point portion */ 1319 1.1 riastrad return (refclk * n * 100) / (p * r); 1320 1.1 riastrad } 1321 1.1 riastrad 1322 1.1 riastrad static int skl_calc_wrpll_link(const struct intel_dpll_hw_state *pll_state) 1323 1.1 riastrad { 1324 1.1 riastrad u32 p0, p1, p2, dco_freq; 1325 1.1 riastrad 1326 1.1 riastrad p0 = pll_state->cfgcr2 & DPLL_CFGCR2_PDIV_MASK; 1327 1.1 riastrad p2 = pll_state->cfgcr2 & DPLL_CFGCR2_KDIV_MASK; 1328 1.1 riastrad 1329 1.1 riastrad if (pll_state->cfgcr2 & DPLL_CFGCR2_QDIV_MODE(1)) 1330 1.1 riastrad p1 = (pll_state->cfgcr2 & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8; 1331 1.1 riastrad else 1332 1.1 riastrad p1 = 1; 1333 1.1 riastrad 1334 1.1 riastrad 1335 1.1 riastrad switch (p0) { 1336 1.1 riastrad case DPLL_CFGCR2_PDIV_1: 1337 1.1 riastrad p0 = 1; 1338 1.1 riastrad break; 1339 1.1 riastrad case DPLL_CFGCR2_PDIV_2: 1340 1.1 riastrad p0 = 2; 1341 1.1 riastrad break; 1342 1.1 riastrad case DPLL_CFGCR2_PDIV_3: 1343 1.1 riastrad p0 = 3; 1344 1.1 riastrad break; 1345 1.1 riastrad case DPLL_CFGCR2_PDIV_7: 1346 1.1 riastrad p0 = 7; 1347 1.1 riastrad break; 1348 1.1 riastrad } 1349 1.1 riastrad 1350 1.1 riastrad switch (p2) { 1351 1.1 riastrad case DPLL_CFGCR2_KDIV_5: 1352 1.1 riastrad p2 = 5; 1353 1.1 riastrad break; 1354 1.1 riastrad case DPLL_CFGCR2_KDIV_2: 1355 1.1 riastrad p2 = 2; 1356 1.1 riastrad break; 1357 1.1 riastrad case DPLL_CFGCR2_KDIV_3: 1358 1.1 riastrad p2 = 3; 1359 1.1 riastrad break; 1360 1.1 riastrad case DPLL_CFGCR2_KDIV_1: 1361 1.1 riastrad p2 = 1; 1362 1.1 riastrad break; 1363 1.1 riastrad } 1364 1.1 riastrad 1365 1.1 riastrad dco_freq = (pll_state->cfgcr1 & DPLL_CFGCR1_DCO_INTEGER_MASK) 1366 1.1 riastrad * 24 * 1000; 1367 1.1 riastrad 1368 1.1 riastrad dco_freq += (((pll_state->cfgcr1 & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) 1369 1.1 riastrad * 24 * 1000) / 0x8000; 1370 1.1 riastrad 1371 1.1 riastrad if (WARN_ON(p0 == 0 || p1 == 0 || p2 == 0)) 1372 1.1 riastrad return 0; 1373 1.1 riastrad 1374 1.1 riastrad return dco_freq / (p0 * p1 * p2 * 5); 1375 1.1 riastrad } 1376 1.1 riastrad 1377 1.1 riastrad int cnl_calc_wrpll_link(struct drm_i915_private *dev_priv, 1378 1.1 riastrad struct intel_dpll_hw_state *pll_state) 1379 1.1 riastrad { 1380 1.1 riastrad u32 p0, p1, p2, dco_freq, ref_clock; 1381 1.1 riastrad 1382 1.1 riastrad p0 = pll_state->cfgcr1 & DPLL_CFGCR1_PDIV_MASK; 1383 1.1 riastrad p2 = pll_state->cfgcr1 & DPLL_CFGCR1_KDIV_MASK; 1384 1.1 riastrad 1385 1.1 riastrad if (pll_state->cfgcr1 & DPLL_CFGCR1_QDIV_MODE(1)) 1386 1.1 riastrad p1 = (pll_state->cfgcr1 & DPLL_CFGCR1_QDIV_RATIO_MASK) >> 1387 1.1 riastrad DPLL_CFGCR1_QDIV_RATIO_SHIFT; 1388 1.1 riastrad else 1389 1.1 riastrad p1 = 1; 1390 1.1 riastrad 1391 1.1 riastrad 1392 1.1 riastrad switch (p0) { 1393 1.1 riastrad case DPLL_CFGCR1_PDIV_2: 1394 1.1 riastrad p0 = 2; 1395 1.1 riastrad break; 1396 1.1 riastrad case DPLL_CFGCR1_PDIV_3: 1397 1.1 riastrad p0 = 3; 1398 1.1 riastrad break; 1399 1.1 riastrad case DPLL_CFGCR1_PDIV_5: 1400 1.1 riastrad p0 = 5; 1401 1.1 riastrad break; 1402 1.1 riastrad case DPLL_CFGCR1_PDIV_7: 1403 1.1 riastrad p0 = 7; 1404 1.1 riastrad break; 1405 1.1 riastrad } 1406 1.1 riastrad 1407 1.1 riastrad switch (p2) { 1408 1.1 riastrad case DPLL_CFGCR1_KDIV_1: 1409 1.1 riastrad p2 = 1; 1410 1.1 riastrad break; 1411 1.1 riastrad case DPLL_CFGCR1_KDIV_2: 1412 1.1 riastrad p2 = 2; 1413 1.1 riastrad break; 1414 1.1 riastrad case DPLL_CFGCR1_KDIV_3: 1415 1.1 riastrad p2 = 3; 1416 1.1 riastrad break; 1417 1.1 riastrad } 1418 1.1 riastrad 1419 1.1 riastrad ref_clock = cnl_hdmi_pll_ref_clock(dev_priv); 1420 1.1 riastrad 1421 1.1 riastrad dco_freq = (pll_state->cfgcr0 & DPLL_CFGCR0_DCO_INTEGER_MASK) 1422 1.1 riastrad * ref_clock; 1423 1.1 riastrad 1424 1.1 riastrad dco_freq += (((pll_state->cfgcr0 & DPLL_CFGCR0_DCO_FRACTION_MASK) >> 1425 1.1 riastrad DPLL_CFGCR0_DCO_FRACTION_SHIFT) * ref_clock) / 0x8000; 1426 1.1 riastrad 1427 1.1 riastrad if (WARN_ON(p0 == 0 || p1 == 0 || p2 == 0)) 1428 1.1 riastrad return 0; 1429 1.1 riastrad 1430 1.1 riastrad return dco_freq / (p0 * p1 * p2 * 5); 1431 1.1 riastrad } 1432 1.1 riastrad 1433 1.1 riastrad static int icl_calc_tbt_pll_link(struct drm_i915_private *dev_priv, 1434 1.1 riastrad enum port port) 1435 1.1 riastrad { 1436 1.1 riastrad u32 val = I915_READ(DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK; 1437 1.1 riastrad 1438 1.1 riastrad switch (val) { 1439 1.1 riastrad case DDI_CLK_SEL_NONE: 1440 1.1 riastrad return 0; 1441 1.1 riastrad case DDI_CLK_SEL_TBT_162: 1442 1.1 riastrad return 162000; 1443 1.1 riastrad case DDI_CLK_SEL_TBT_270: 1444 1.1 riastrad return 270000; 1445 1.1 riastrad case DDI_CLK_SEL_TBT_540: 1446 1.1 riastrad return 540000; 1447 1.1 riastrad case DDI_CLK_SEL_TBT_810: 1448 1.1 riastrad return 810000; 1449 1.1 riastrad default: 1450 1.1 riastrad MISSING_CASE(val); 1451 1.1 riastrad return 0; 1452 1.1 riastrad } 1453 1.1 riastrad } 1454 1.1 riastrad 1455 1.1 riastrad static int icl_calc_mg_pll_link(struct drm_i915_private *dev_priv, 1456 1.1 riastrad const struct intel_dpll_hw_state *pll_state) 1457 1.1 riastrad { 1458 1.1 riastrad u32 m1, m2_int, m2_frac, div1, div2, ref_clock; 1459 1.1 riastrad u64 tmp; 1460 1.1 riastrad 1461 1.1 riastrad ref_clock = dev_priv->cdclk.hw.ref; 1462 1.1 riastrad 1463 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 1464 1.1 riastrad m1 = pll_state->mg_pll_div0 & DKL_PLL_DIV0_FBPREDIV_MASK; 1465 1.1 riastrad m1 = m1 >> DKL_PLL_DIV0_FBPREDIV_SHIFT; 1466 1.1 riastrad m2_int = pll_state->mg_pll_div0 & DKL_PLL_DIV0_FBDIV_INT_MASK; 1467 1.1 riastrad 1468 1.1 riastrad if (pll_state->mg_pll_bias & DKL_PLL_BIAS_FRAC_EN_H) { 1469 1.1 riastrad m2_frac = pll_state->mg_pll_bias & 1470 1.1 riastrad DKL_PLL_BIAS_FBDIV_FRAC_MASK; 1471 1.1 riastrad m2_frac = m2_frac >> DKL_PLL_BIAS_FBDIV_SHIFT; 1472 1.1 riastrad } else { 1473 1.1 riastrad m2_frac = 0; 1474 1.1 riastrad } 1475 1.1 riastrad } else { 1476 1.1 riastrad m1 = pll_state->mg_pll_div1 & MG_PLL_DIV1_FBPREDIV_MASK; 1477 1.1 riastrad m2_int = pll_state->mg_pll_div0 & MG_PLL_DIV0_FBDIV_INT_MASK; 1478 1.1 riastrad 1479 1.1 riastrad if (pll_state->mg_pll_div0 & MG_PLL_DIV0_FRACNEN_H) { 1480 1.1 riastrad m2_frac = pll_state->mg_pll_div0 & 1481 1.1 riastrad MG_PLL_DIV0_FBDIV_FRAC_MASK; 1482 1.1 riastrad m2_frac = m2_frac >> MG_PLL_DIV0_FBDIV_FRAC_SHIFT; 1483 1.1 riastrad } else { 1484 1.1 riastrad m2_frac = 0; 1485 1.1 riastrad } 1486 1.1 riastrad } 1487 1.1 riastrad 1488 1.1 riastrad switch (pll_state->mg_clktop2_hsclkctl & 1489 1.1 riastrad MG_CLKTOP2_HSCLKCTL_HSDIV_RATIO_MASK) { 1490 1.1 riastrad case MG_CLKTOP2_HSCLKCTL_HSDIV_RATIO_2: 1491 1.1 riastrad div1 = 2; 1492 1.1 riastrad break; 1493 1.1 riastrad case MG_CLKTOP2_HSCLKCTL_HSDIV_RATIO_3: 1494 1.1 riastrad div1 = 3; 1495 1.1 riastrad break; 1496 1.1 riastrad case MG_CLKTOP2_HSCLKCTL_HSDIV_RATIO_5: 1497 1.1 riastrad div1 = 5; 1498 1.1 riastrad break; 1499 1.1 riastrad case MG_CLKTOP2_HSCLKCTL_HSDIV_RATIO_7: 1500 1.1 riastrad div1 = 7; 1501 1.1 riastrad break; 1502 1.1 riastrad default: 1503 1.1 riastrad MISSING_CASE(pll_state->mg_clktop2_hsclkctl); 1504 1.1 riastrad return 0; 1505 1.1 riastrad } 1506 1.1 riastrad 1507 1.1 riastrad div2 = (pll_state->mg_clktop2_hsclkctl & 1508 1.1 riastrad MG_CLKTOP2_HSCLKCTL_DSDIV_RATIO_MASK) >> 1509 1.1 riastrad MG_CLKTOP2_HSCLKCTL_DSDIV_RATIO_SHIFT; 1510 1.1 riastrad 1511 1.1 riastrad /* div2 value of 0 is same as 1 means no div */ 1512 1.1 riastrad if (div2 == 0) 1513 1.1 riastrad div2 = 1; 1514 1.1 riastrad 1515 1.1 riastrad /* 1516 1.1 riastrad * Adjust the original formula to delay the division by 2^22 in order to 1517 1.1 riastrad * minimize possible rounding errors. 1518 1.1 riastrad */ 1519 1.1 riastrad tmp = (u64)m1 * m2_int * ref_clock + 1520 1.1 riastrad (((u64)m1 * m2_frac * ref_clock) >> 22); 1521 1.1 riastrad tmp = div_u64(tmp, 5 * div1 * div2); 1522 1.1 riastrad 1523 1.1 riastrad return tmp; 1524 1.1 riastrad } 1525 1.1 riastrad 1526 1.1 riastrad static void ddi_dotclock_get(struct intel_crtc_state *pipe_config) 1527 1.1 riastrad { 1528 1.1 riastrad int dotclock; 1529 1.1 riastrad 1530 1.1 riastrad if (pipe_config->has_pch_encoder) 1531 1.1 riastrad dotclock = intel_dotclock_calculate(pipe_config->port_clock, 1532 1.1 riastrad &pipe_config->fdi_m_n); 1533 1.1 riastrad else if (intel_crtc_has_dp_encoder(pipe_config)) 1534 1.1 riastrad dotclock = intel_dotclock_calculate(pipe_config->port_clock, 1535 1.1 riastrad &pipe_config->dp_m_n); 1536 1.1 riastrad else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24) 1537 1.1 riastrad dotclock = pipe_config->port_clock * 24 / pipe_config->pipe_bpp; 1538 1.1 riastrad else 1539 1.1 riastrad dotclock = pipe_config->port_clock; 1540 1.1 riastrad 1541 1.1 riastrad if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 && 1542 1.1 riastrad !intel_crtc_has_dp_encoder(pipe_config)) 1543 1.1 riastrad dotclock *= 2; 1544 1.1 riastrad 1545 1.1 riastrad if (pipe_config->pixel_multiplier) 1546 1.1 riastrad dotclock /= pipe_config->pixel_multiplier; 1547 1.1 riastrad 1548 1.1 riastrad pipe_config->hw.adjusted_mode.crtc_clock = dotclock; 1549 1.1 riastrad } 1550 1.1 riastrad 1551 1.1 riastrad static void icl_ddi_clock_get(struct intel_encoder *encoder, 1552 1.1 riastrad struct intel_crtc_state *pipe_config) 1553 1.1 riastrad { 1554 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1555 1.1 riastrad struct intel_dpll_hw_state *pll_state = &pipe_config->dpll_hw_state; 1556 1.1 riastrad enum port port = encoder->port; 1557 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 1558 1.1 riastrad int link_clock; 1559 1.1 riastrad 1560 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) { 1561 1.1 riastrad link_clock = cnl_calc_wrpll_link(dev_priv, pll_state); 1562 1.1 riastrad } else { 1563 1.1 riastrad enum intel_dpll_id pll_id = intel_get_shared_dpll_id(dev_priv, 1564 1.1 riastrad pipe_config->shared_dpll); 1565 1.1 riastrad 1566 1.1 riastrad if (pll_id == DPLL_ID_ICL_TBTPLL) 1567 1.1 riastrad link_clock = icl_calc_tbt_pll_link(dev_priv, port); 1568 1.1 riastrad else 1569 1.1 riastrad link_clock = icl_calc_mg_pll_link(dev_priv, pll_state); 1570 1.1 riastrad } 1571 1.1 riastrad 1572 1.1 riastrad pipe_config->port_clock = link_clock; 1573 1.1 riastrad 1574 1.1 riastrad ddi_dotclock_get(pipe_config); 1575 1.1 riastrad } 1576 1.1 riastrad 1577 1.1 riastrad static void cnl_ddi_clock_get(struct intel_encoder *encoder, 1578 1.1 riastrad struct intel_crtc_state *pipe_config) 1579 1.1 riastrad { 1580 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1581 1.1 riastrad struct intel_dpll_hw_state *pll_state = &pipe_config->dpll_hw_state; 1582 1.1 riastrad int link_clock; 1583 1.1 riastrad 1584 1.1 riastrad if (pll_state->cfgcr0 & DPLL_CFGCR0_HDMI_MODE) { 1585 1.1 riastrad link_clock = cnl_calc_wrpll_link(dev_priv, pll_state); 1586 1.1 riastrad } else { 1587 1.1 riastrad link_clock = pll_state->cfgcr0 & DPLL_CFGCR0_LINK_RATE_MASK; 1588 1.1 riastrad 1589 1.1 riastrad switch (link_clock) { 1590 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_810: 1591 1.1 riastrad link_clock = 81000; 1592 1.1 riastrad break; 1593 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_1080: 1594 1.1 riastrad link_clock = 108000; 1595 1.1 riastrad break; 1596 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_1350: 1597 1.1 riastrad link_clock = 135000; 1598 1.1 riastrad break; 1599 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_1620: 1600 1.1 riastrad link_clock = 162000; 1601 1.1 riastrad break; 1602 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_2160: 1603 1.1 riastrad link_clock = 216000; 1604 1.1 riastrad break; 1605 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_2700: 1606 1.1 riastrad link_clock = 270000; 1607 1.1 riastrad break; 1608 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_3240: 1609 1.1 riastrad link_clock = 324000; 1610 1.1 riastrad break; 1611 1.1 riastrad case DPLL_CFGCR0_LINK_RATE_4050: 1612 1.1 riastrad link_clock = 405000; 1613 1.1 riastrad break; 1614 1.1 riastrad default: 1615 1.1 riastrad WARN(1, "Unsupported link rate\n"); 1616 1.1 riastrad break; 1617 1.1 riastrad } 1618 1.1 riastrad link_clock *= 2; 1619 1.1 riastrad } 1620 1.1 riastrad 1621 1.1 riastrad pipe_config->port_clock = link_clock; 1622 1.1 riastrad 1623 1.1 riastrad ddi_dotclock_get(pipe_config); 1624 1.1 riastrad } 1625 1.1 riastrad 1626 1.1 riastrad static void skl_ddi_clock_get(struct intel_encoder *encoder, 1627 1.1 riastrad struct intel_crtc_state *pipe_config) 1628 1.1 riastrad { 1629 1.1 riastrad struct intel_dpll_hw_state *pll_state = &pipe_config->dpll_hw_state; 1630 1.1 riastrad int link_clock; 1631 1.1 riastrad 1632 1.1 riastrad /* 1633 1.1 riastrad * ctrl1 register is already shifted for each pll, just use 0 to get 1634 1.1 riastrad * the internal shift for each field 1635 1.1 riastrad */ 1636 1.1 riastrad if (pll_state->ctrl1 & DPLL_CTRL1_HDMI_MODE(0)) { 1637 1.1 riastrad link_clock = skl_calc_wrpll_link(pll_state); 1638 1.1 riastrad } else { 1639 1.1 riastrad link_clock = pll_state->ctrl1 & DPLL_CTRL1_LINK_RATE_MASK(0); 1640 1.1 riastrad link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(0); 1641 1.1 riastrad 1642 1.1 riastrad switch (link_clock) { 1643 1.1 riastrad case DPLL_CTRL1_LINK_RATE_810: 1644 1.1 riastrad link_clock = 81000; 1645 1.1 riastrad break; 1646 1.1 riastrad case DPLL_CTRL1_LINK_RATE_1080: 1647 1.1 riastrad link_clock = 108000; 1648 1.1 riastrad break; 1649 1.1 riastrad case DPLL_CTRL1_LINK_RATE_1350: 1650 1.1 riastrad link_clock = 135000; 1651 1.1 riastrad break; 1652 1.1 riastrad case DPLL_CTRL1_LINK_RATE_1620: 1653 1.1 riastrad link_clock = 162000; 1654 1.1 riastrad break; 1655 1.1 riastrad case DPLL_CTRL1_LINK_RATE_2160: 1656 1.1 riastrad link_clock = 216000; 1657 1.1 riastrad break; 1658 1.1 riastrad case DPLL_CTRL1_LINK_RATE_2700: 1659 1.1 riastrad link_clock = 270000; 1660 1.1 riastrad break; 1661 1.1 riastrad default: 1662 1.1 riastrad WARN(1, "Unsupported link rate\n"); 1663 1.1 riastrad break; 1664 1.1 riastrad } 1665 1.1 riastrad link_clock *= 2; 1666 1.1 riastrad } 1667 1.1 riastrad 1668 1.1 riastrad pipe_config->port_clock = link_clock; 1669 1.1 riastrad 1670 1.1 riastrad ddi_dotclock_get(pipe_config); 1671 1.1 riastrad } 1672 1.1 riastrad 1673 1.1 riastrad static void hsw_ddi_clock_get(struct intel_encoder *encoder, 1674 1.1 riastrad struct intel_crtc_state *pipe_config) 1675 1.1 riastrad { 1676 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1677 1.1 riastrad int link_clock = 0; 1678 1.1 riastrad u32 val, pll; 1679 1.1 riastrad 1680 1.1 riastrad val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll); 1681 1.1 riastrad switch (val & PORT_CLK_SEL_MASK) { 1682 1.1 riastrad case PORT_CLK_SEL_LCPLL_810: 1683 1.1 riastrad link_clock = 81000; 1684 1.1 riastrad break; 1685 1.1 riastrad case PORT_CLK_SEL_LCPLL_1350: 1686 1.1 riastrad link_clock = 135000; 1687 1.1 riastrad break; 1688 1.1 riastrad case PORT_CLK_SEL_LCPLL_2700: 1689 1.1 riastrad link_clock = 270000; 1690 1.1 riastrad break; 1691 1.1 riastrad case PORT_CLK_SEL_WRPLL1: 1692 1.1 riastrad link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0)); 1693 1.1 riastrad break; 1694 1.1 riastrad case PORT_CLK_SEL_WRPLL2: 1695 1.1 riastrad link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1)); 1696 1.1 riastrad break; 1697 1.1 riastrad case PORT_CLK_SEL_SPLL: 1698 1.1 riastrad pll = I915_READ(SPLL_CTL) & SPLL_FREQ_MASK; 1699 1.1 riastrad if (pll == SPLL_FREQ_810MHz) 1700 1.1 riastrad link_clock = 81000; 1701 1.1 riastrad else if (pll == SPLL_FREQ_1350MHz) 1702 1.1 riastrad link_clock = 135000; 1703 1.1 riastrad else if (pll == SPLL_FREQ_2700MHz) 1704 1.1 riastrad link_clock = 270000; 1705 1.1 riastrad else { 1706 1.1 riastrad WARN(1, "bad spll freq\n"); 1707 1.1 riastrad return; 1708 1.1 riastrad } 1709 1.1 riastrad break; 1710 1.1 riastrad default: 1711 1.1 riastrad WARN(1, "bad port clock sel\n"); 1712 1.1 riastrad return; 1713 1.1 riastrad } 1714 1.1 riastrad 1715 1.1 riastrad pipe_config->port_clock = link_clock * 2; 1716 1.1 riastrad 1717 1.1 riastrad ddi_dotclock_get(pipe_config); 1718 1.1 riastrad } 1719 1.1 riastrad 1720 1.1 riastrad static int bxt_calc_pll_link(const struct intel_dpll_hw_state *pll_state) 1721 1.1 riastrad { 1722 1.1 riastrad struct dpll clock; 1723 1.1 riastrad 1724 1.1 riastrad clock.m1 = 2; 1725 1.1 riastrad clock.m2 = (pll_state->pll0 & PORT_PLL_M2_MASK) << 22; 1726 1.1 riastrad if (pll_state->pll3 & PORT_PLL_M2_FRAC_ENABLE) 1727 1.1 riastrad clock.m2 |= pll_state->pll2 & PORT_PLL_M2_FRAC_MASK; 1728 1.1 riastrad clock.n = (pll_state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT; 1729 1.1 riastrad clock.p1 = (pll_state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT; 1730 1.1 riastrad clock.p2 = (pll_state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT; 1731 1.1 riastrad 1732 1.1 riastrad return chv_calc_dpll_params(100000, &clock); 1733 1.1 riastrad } 1734 1.1 riastrad 1735 1.1 riastrad static void bxt_ddi_clock_get(struct intel_encoder *encoder, 1736 1.1 riastrad struct intel_crtc_state *pipe_config) 1737 1.1 riastrad { 1738 1.1 riastrad pipe_config->port_clock = 1739 1.1 riastrad bxt_calc_pll_link(&pipe_config->dpll_hw_state); 1740 1.1 riastrad 1741 1.1 riastrad ddi_dotclock_get(pipe_config); 1742 1.1 riastrad } 1743 1.1 riastrad 1744 1.1 riastrad static void intel_ddi_clock_get(struct intel_encoder *encoder, 1745 1.1 riastrad struct intel_crtc_state *pipe_config) 1746 1.1 riastrad { 1747 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1748 1.1 riastrad 1749 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) 1750 1.1 riastrad icl_ddi_clock_get(encoder, pipe_config); 1751 1.1 riastrad else if (IS_CANNONLAKE(dev_priv)) 1752 1.1 riastrad cnl_ddi_clock_get(encoder, pipe_config); 1753 1.1 riastrad else if (IS_GEN9_LP(dev_priv)) 1754 1.1 riastrad bxt_ddi_clock_get(encoder, pipe_config); 1755 1.1 riastrad else if (IS_GEN9_BC(dev_priv)) 1756 1.1 riastrad skl_ddi_clock_get(encoder, pipe_config); 1757 1.1 riastrad else if (INTEL_GEN(dev_priv) <= 8) 1758 1.1 riastrad hsw_ddi_clock_get(encoder, pipe_config); 1759 1.1 riastrad } 1760 1.1 riastrad 1761 1.1 riastrad void intel_ddi_set_dp_msa(const struct intel_crtc_state *crtc_state, 1762 1.1 riastrad const struct drm_connector_state *conn_state) 1763 1.1 riastrad { 1764 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1765 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1766 1.1 riastrad enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1767 1.1 riastrad u32 temp; 1768 1.1 riastrad 1769 1.1 riastrad if (!intel_crtc_has_dp_encoder(crtc_state)) 1770 1.1 riastrad return; 1771 1.1 riastrad 1772 1.1 riastrad WARN_ON(transcoder_is_dsi(cpu_transcoder)); 1773 1.1 riastrad 1774 1.1 riastrad temp = DP_MSA_MISC_SYNC_CLOCK; 1775 1.1 riastrad 1776 1.1 riastrad switch (crtc_state->pipe_bpp) { 1777 1.1 riastrad case 18: 1778 1.1 riastrad temp |= DP_MSA_MISC_6_BPC; 1779 1.1 riastrad break; 1780 1.1 riastrad case 24: 1781 1.1 riastrad temp |= DP_MSA_MISC_8_BPC; 1782 1.1 riastrad break; 1783 1.1 riastrad case 30: 1784 1.1 riastrad temp |= DP_MSA_MISC_10_BPC; 1785 1.1 riastrad break; 1786 1.1 riastrad case 36: 1787 1.1 riastrad temp |= DP_MSA_MISC_12_BPC; 1788 1.1 riastrad break; 1789 1.1 riastrad default: 1790 1.1 riastrad MISSING_CASE(crtc_state->pipe_bpp); 1791 1.1 riastrad break; 1792 1.1 riastrad } 1793 1.1 riastrad 1794 1.1 riastrad /* nonsense combination */ 1795 1.1 riastrad WARN_ON(crtc_state->limited_color_range && 1796 1.1 riastrad crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB); 1797 1.1 riastrad 1798 1.1 riastrad if (crtc_state->limited_color_range) 1799 1.1 riastrad temp |= DP_MSA_MISC_COLOR_CEA_RGB; 1800 1.1 riastrad 1801 1.1 riastrad /* 1802 1.1 riastrad * As per DP 1.2 spec section 2.3.4.3 while sending 1803 1.1 riastrad * YCBCR 444 signals we should program MSA MISC1/0 fields with 1804 1.1 riastrad * colorspace information. 1805 1.1 riastrad */ 1806 1.1 riastrad if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) 1807 1.1 riastrad temp |= DP_MSA_MISC_COLOR_YCBCR_444_BT709; 1808 1.1 riastrad 1809 1.1 riastrad /* 1810 1.1 riastrad * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication 1811 1.1 riastrad * of Color Encoding Format and Content Color Gamut] while sending 1812 1.1 riastrad * YCBCR 420, HDR BT.2020 signals we should program MSA MISC1 fields 1813 1.1 riastrad * which indicate VSC SDP for the Pixel Encoding/Colorimetry Format. 1814 1.1 riastrad */ 1815 1.1 riastrad if (intel_dp_needs_vsc_sdp(crtc_state, conn_state)) 1816 1.1 riastrad temp |= DP_MSA_MISC_COLOR_VSC_SDP; 1817 1.1 riastrad 1818 1.1 riastrad I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp); 1819 1.1 riastrad } 1820 1.1 riastrad 1821 1.1 riastrad /* 1822 1.1 riastrad * Returns the TRANS_DDI_FUNC_CTL value based on CRTC state. 1823 1.1 riastrad * 1824 1.1 riastrad * Only intended to be used by intel_ddi_enable_transcoder_func() and 1825 1.1 riastrad * intel_ddi_config_transcoder_func(). 1826 1.1 riastrad */ 1827 1.1 riastrad static u32 1828 1.1 riastrad intel_ddi_transcoder_func_reg_val_get(const struct intel_crtc_state *crtc_state) 1829 1.1 riastrad { 1830 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1831 1.1 riastrad struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc); 1832 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1833 1.1 riastrad enum pipe pipe = crtc->pipe; 1834 1.1 riastrad enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1835 1.1 riastrad enum port port = encoder->port; 1836 1.1 riastrad u32 temp; 1837 1.1 riastrad 1838 1.1 riastrad /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */ 1839 1.1 riastrad temp = TRANS_DDI_FUNC_ENABLE; 1840 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 1841 1.1 riastrad temp |= TGL_TRANS_DDI_SELECT_PORT(port); 1842 1.1 riastrad else 1843 1.1 riastrad temp |= TRANS_DDI_SELECT_PORT(port); 1844 1.1 riastrad 1845 1.1 riastrad switch (crtc_state->pipe_bpp) { 1846 1.1 riastrad case 18: 1847 1.1 riastrad temp |= TRANS_DDI_BPC_6; 1848 1.1 riastrad break; 1849 1.1 riastrad case 24: 1850 1.1 riastrad temp |= TRANS_DDI_BPC_8; 1851 1.1 riastrad break; 1852 1.1 riastrad case 30: 1853 1.1 riastrad temp |= TRANS_DDI_BPC_10; 1854 1.1 riastrad break; 1855 1.1 riastrad case 36: 1856 1.1 riastrad temp |= TRANS_DDI_BPC_12; 1857 1.1 riastrad break; 1858 1.1 riastrad default: 1859 1.1 riastrad BUG(); 1860 1.1 riastrad } 1861 1.1 riastrad 1862 1.1 riastrad if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC) 1863 1.1 riastrad temp |= TRANS_DDI_PVSYNC; 1864 1.1 riastrad if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC) 1865 1.1 riastrad temp |= TRANS_DDI_PHSYNC; 1866 1.1 riastrad 1867 1.1 riastrad if (cpu_transcoder == TRANSCODER_EDP) { 1868 1.1 riastrad switch (pipe) { 1869 1.1 riastrad case PIPE_A: 1870 1.1 riastrad /* On Haswell, can only use the always-on power well for 1871 1.1 riastrad * eDP when not using the panel fitter, and when not 1872 1.1 riastrad * using motion blur mitigation (which we don't 1873 1.1 riastrad * support). */ 1874 1.1 riastrad if (crtc_state->pch_pfit.force_thru) 1875 1.1 riastrad temp |= TRANS_DDI_EDP_INPUT_A_ONOFF; 1876 1.1 riastrad else 1877 1.1 riastrad temp |= TRANS_DDI_EDP_INPUT_A_ON; 1878 1.1 riastrad break; 1879 1.1 riastrad case PIPE_B: 1880 1.1 riastrad temp |= TRANS_DDI_EDP_INPUT_B_ONOFF; 1881 1.1 riastrad break; 1882 1.1 riastrad case PIPE_C: 1883 1.1 riastrad temp |= TRANS_DDI_EDP_INPUT_C_ONOFF; 1884 1.1 riastrad break; 1885 1.1 riastrad default: 1886 1.1 riastrad BUG(); 1887 1.1 riastrad break; 1888 1.1 riastrad } 1889 1.1 riastrad } 1890 1.1 riastrad 1891 1.1 riastrad if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 1892 1.1 riastrad if (crtc_state->has_hdmi_sink) 1893 1.1 riastrad temp |= TRANS_DDI_MODE_SELECT_HDMI; 1894 1.1 riastrad else 1895 1.1 riastrad temp |= TRANS_DDI_MODE_SELECT_DVI; 1896 1.1 riastrad 1897 1.1 riastrad if (crtc_state->hdmi_scrambling) 1898 1.1 riastrad temp |= TRANS_DDI_HDMI_SCRAMBLING; 1899 1.1 riastrad if (crtc_state->hdmi_high_tmds_clock_ratio) 1900 1.1 riastrad temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE; 1901 1.1 riastrad } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { 1902 1.1 riastrad temp |= TRANS_DDI_MODE_SELECT_FDI; 1903 1.1 riastrad temp |= (crtc_state->fdi_lanes - 1) << 1; 1904 1.1 riastrad } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) { 1905 1.1 riastrad temp |= TRANS_DDI_MODE_SELECT_DP_MST; 1906 1.1 riastrad temp |= DDI_PORT_WIDTH(crtc_state->lane_count); 1907 1.1 riastrad 1908 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 1909 1.1 riastrad enum transcoder master; 1910 1.1 riastrad 1911 1.1 riastrad master = crtc_state->mst_master_transcoder; 1912 1.1 riastrad WARN_ON(master == INVALID_TRANSCODER); 1913 1.1 riastrad temp |= TRANS_DDI_MST_TRANSPORT_SELECT(master); 1914 1.1 riastrad } 1915 1.1 riastrad } else { 1916 1.1 riastrad temp |= TRANS_DDI_MODE_SELECT_DP_SST; 1917 1.1 riastrad temp |= DDI_PORT_WIDTH(crtc_state->lane_count); 1918 1.1 riastrad } 1919 1.1 riastrad 1920 1.1 riastrad return temp; 1921 1.1 riastrad } 1922 1.1 riastrad 1923 1.1 riastrad void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state) 1924 1.1 riastrad { 1925 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1926 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1927 1.1 riastrad enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1928 1.1 riastrad u32 temp; 1929 1.1 riastrad 1930 1.1 riastrad temp = intel_ddi_transcoder_func_reg_val_get(crtc_state); 1931 1.1 riastrad if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) 1932 1.1 riastrad temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC; 1933 1.1 riastrad I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); 1934 1.1 riastrad } 1935 1.1 riastrad 1936 1.1 riastrad /* 1937 1.1 riastrad * Same as intel_ddi_enable_transcoder_func(), but it does not set the enable 1938 1.1 riastrad * bit. 1939 1.1 riastrad */ 1940 1.1 riastrad static void 1941 1.1 riastrad intel_ddi_config_transcoder_func(const struct intel_crtc_state *crtc_state) 1942 1.1 riastrad { 1943 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1944 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1945 1.1 riastrad enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1946 1.1 riastrad u32 temp; 1947 1.1 riastrad 1948 1.1 riastrad temp = intel_ddi_transcoder_func_reg_val_get(crtc_state); 1949 1.1 riastrad temp &= ~TRANS_DDI_FUNC_ENABLE; 1950 1.1 riastrad I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp); 1951 1.1 riastrad } 1952 1.1 riastrad 1953 1.1 riastrad void intel_ddi_disable_transcoder_func(const struct intel_crtc_state *crtc_state) 1954 1.1 riastrad { 1955 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1956 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1957 1.1 riastrad enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1958 1.1 riastrad u32 val; 1959 1.1 riastrad 1960 1.1 riastrad val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); 1961 1.1 riastrad val &= ~TRANS_DDI_FUNC_ENABLE; 1962 1.1 riastrad 1963 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 1964 1.1 riastrad if (!intel_dp_mst_is_master_trans(crtc_state)) 1965 1.1 riastrad val &= ~TGL_TRANS_DDI_PORT_MASK; 1966 1.1 riastrad } else { 1967 1.1 riastrad val &= ~TRANS_DDI_PORT_MASK; 1968 1.1 riastrad } 1969 1.1 riastrad I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), val); 1970 1.1 riastrad 1971 1.1 riastrad if (dev_priv->quirks & QUIRK_INCREASE_DDI_DISABLED_TIME && 1972 1.1 riastrad intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 1973 1.1 riastrad DRM_DEBUG_KMS("Quirk Increase DDI disabled time\n"); 1974 1.1 riastrad /* Quirk time at 100ms for reliable operation */ 1975 1.1 riastrad msleep(100); 1976 1.1 riastrad } 1977 1.1 riastrad } 1978 1.1 riastrad 1979 1.1 riastrad int intel_ddi_toggle_hdcp_signalling(struct intel_encoder *intel_encoder, 1980 1.1 riastrad bool enable) 1981 1.1 riastrad { 1982 1.1 riastrad struct drm_device *dev = intel_encoder->base.dev; 1983 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 1984 1.1 riastrad intel_wakeref_t wakeref; 1985 1.1 riastrad enum pipe pipe = 0; 1986 1.1 riastrad int ret = 0; 1987 1.1 riastrad u32 tmp; 1988 1.1 riastrad 1989 1.1 riastrad wakeref = intel_display_power_get_if_enabled(dev_priv, 1990 1.1 riastrad intel_encoder->power_domain); 1991 1.1 riastrad if (WARN_ON(!wakeref)) 1992 1.1 riastrad return -ENXIO; 1993 1.1 riastrad 1994 1.1 riastrad if (WARN_ON(!intel_encoder->get_hw_state(intel_encoder, &pipe))) { 1995 1.1 riastrad ret = -EIO; 1996 1.1 riastrad goto out; 1997 1.1 riastrad } 1998 1.1 riastrad 1999 1.1 riastrad tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe)); 2000 1.1 riastrad if (enable) 2001 1.1 riastrad tmp |= TRANS_DDI_HDCP_SIGNALLING; 2002 1.1 riastrad else 2003 1.1 riastrad tmp &= ~TRANS_DDI_HDCP_SIGNALLING; 2004 1.1 riastrad I915_WRITE(TRANS_DDI_FUNC_CTL(pipe), tmp); 2005 1.1 riastrad out: 2006 1.1 riastrad intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref); 2007 1.1 riastrad return ret; 2008 1.1 riastrad } 2009 1.1 riastrad 2010 1.1 riastrad bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector) 2011 1.1 riastrad { 2012 1.1 riastrad struct drm_device *dev = intel_connector->base.dev; 2013 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 2014 1.1 riastrad struct intel_encoder *encoder = intel_connector->encoder; 2015 1.1 riastrad int type = intel_connector->base.connector_type; 2016 1.1 riastrad enum port port = encoder->port; 2017 1.1 riastrad enum transcoder cpu_transcoder; 2018 1.1 riastrad intel_wakeref_t wakeref; 2019 1.1 riastrad enum pipe pipe = 0; 2020 1.1 riastrad u32 tmp; 2021 1.1 riastrad bool ret; 2022 1.1 riastrad 2023 1.1 riastrad wakeref = intel_display_power_get_if_enabled(dev_priv, 2024 1.1 riastrad encoder->power_domain); 2025 1.1 riastrad if (!wakeref) 2026 1.1 riastrad return false; 2027 1.1 riastrad 2028 1.1 riastrad if (!encoder->get_hw_state(encoder, &pipe)) { 2029 1.1 riastrad ret = false; 2030 1.1 riastrad goto out; 2031 1.1 riastrad } 2032 1.1 riastrad 2033 1.1 riastrad if (HAS_TRANSCODER_EDP(dev_priv) && port == PORT_A) 2034 1.1 riastrad cpu_transcoder = TRANSCODER_EDP; 2035 1.1 riastrad else 2036 1.1 riastrad cpu_transcoder = (enum transcoder) pipe; 2037 1.1 riastrad 2038 1.1 riastrad tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); 2039 1.1 riastrad 2040 1.1 riastrad switch (tmp & TRANS_DDI_MODE_SELECT_MASK) { 2041 1.1 riastrad case TRANS_DDI_MODE_SELECT_HDMI: 2042 1.1 riastrad case TRANS_DDI_MODE_SELECT_DVI: 2043 1.1 riastrad ret = type == DRM_MODE_CONNECTOR_HDMIA; 2044 1.1 riastrad break; 2045 1.1 riastrad 2046 1.1 riastrad case TRANS_DDI_MODE_SELECT_DP_SST: 2047 1.1 riastrad ret = type == DRM_MODE_CONNECTOR_eDP || 2048 1.1 riastrad type == DRM_MODE_CONNECTOR_DisplayPort; 2049 1.1 riastrad break; 2050 1.1 riastrad 2051 1.1 riastrad case TRANS_DDI_MODE_SELECT_DP_MST: 2052 1.1 riastrad /* if the transcoder is in MST state then 2053 1.1 riastrad * connector isn't connected */ 2054 1.1 riastrad ret = false; 2055 1.1 riastrad break; 2056 1.1 riastrad 2057 1.1 riastrad case TRANS_DDI_MODE_SELECT_FDI: 2058 1.1 riastrad ret = type == DRM_MODE_CONNECTOR_VGA; 2059 1.1 riastrad break; 2060 1.1 riastrad 2061 1.1 riastrad default: 2062 1.1 riastrad ret = false; 2063 1.1 riastrad break; 2064 1.1 riastrad } 2065 1.1 riastrad 2066 1.1 riastrad out: 2067 1.1 riastrad intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 2068 1.1 riastrad 2069 1.1 riastrad return ret; 2070 1.1 riastrad } 2071 1.1 riastrad 2072 1.1 riastrad static void intel_ddi_get_encoder_pipes(struct intel_encoder *encoder, 2073 1.1 riastrad u8 *pipe_mask, bool *is_dp_mst) 2074 1.1 riastrad { 2075 1.1 riastrad struct drm_device *dev = encoder->base.dev; 2076 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 2077 1.1 riastrad enum port port = encoder->port; 2078 1.1 riastrad intel_wakeref_t wakeref; 2079 1.1 riastrad enum pipe p; 2080 1.1 riastrad u32 tmp; 2081 1.1 riastrad u8 mst_pipe_mask; 2082 1.1 riastrad 2083 1.1 riastrad *pipe_mask = 0; 2084 1.1 riastrad *is_dp_mst = false; 2085 1.1 riastrad 2086 1.1 riastrad wakeref = intel_display_power_get_if_enabled(dev_priv, 2087 1.1 riastrad encoder->power_domain); 2088 1.1 riastrad if (!wakeref) 2089 1.1 riastrad return; 2090 1.1 riastrad 2091 1.1 riastrad tmp = I915_READ(DDI_BUF_CTL(port)); 2092 1.1 riastrad if (!(tmp & DDI_BUF_CTL_ENABLE)) 2093 1.1 riastrad goto out; 2094 1.1 riastrad 2095 1.1 riastrad if (HAS_TRANSCODER_EDP(dev_priv) && port == PORT_A) { 2096 1.1 riastrad tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); 2097 1.1 riastrad 2098 1.1 riastrad switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 2099 1.1 riastrad default: 2100 1.1 riastrad MISSING_CASE(tmp & TRANS_DDI_EDP_INPUT_MASK); 2101 1.1 riastrad /* fallthrough */ 2102 1.1 riastrad case TRANS_DDI_EDP_INPUT_A_ON: 2103 1.1 riastrad case TRANS_DDI_EDP_INPUT_A_ONOFF: 2104 1.1 riastrad *pipe_mask = BIT(PIPE_A); 2105 1.1 riastrad break; 2106 1.1 riastrad case TRANS_DDI_EDP_INPUT_B_ONOFF: 2107 1.1 riastrad *pipe_mask = BIT(PIPE_B); 2108 1.1 riastrad break; 2109 1.1 riastrad case TRANS_DDI_EDP_INPUT_C_ONOFF: 2110 1.1 riastrad *pipe_mask = BIT(PIPE_C); 2111 1.1 riastrad break; 2112 1.1 riastrad } 2113 1.1 riastrad 2114 1.1 riastrad goto out; 2115 1.1 riastrad } 2116 1.1 riastrad 2117 1.1 riastrad mst_pipe_mask = 0; 2118 1.1 riastrad for_each_pipe(dev_priv, p) { 2119 1.1 riastrad enum transcoder cpu_transcoder = (enum transcoder)p; 2120 1.1 riastrad unsigned int port_mask, ddi_select; 2121 1.1 riastrad intel_wakeref_t trans_wakeref; 2122 1.1 riastrad 2123 1.1 riastrad trans_wakeref = intel_display_power_get_if_enabled(dev_priv, 2124 1.1 riastrad POWER_DOMAIN_TRANSCODER(cpu_transcoder)); 2125 1.1 riastrad if (!trans_wakeref) 2126 1.1 riastrad continue; 2127 1.1 riastrad 2128 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 2129 1.1 riastrad port_mask = TGL_TRANS_DDI_PORT_MASK; 2130 1.1 riastrad ddi_select = TGL_TRANS_DDI_SELECT_PORT(port); 2131 1.1 riastrad } else { 2132 1.1 riastrad port_mask = TRANS_DDI_PORT_MASK; 2133 1.1 riastrad ddi_select = TRANS_DDI_SELECT_PORT(port); 2134 1.1 riastrad } 2135 1.1 riastrad 2136 1.1 riastrad tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); 2137 1.1 riastrad intel_display_power_put(dev_priv, POWER_DOMAIN_TRANSCODER(cpu_transcoder), 2138 1.1 riastrad trans_wakeref); 2139 1.1 riastrad 2140 1.1 riastrad if ((tmp & port_mask) != ddi_select) 2141 1.1 riastrad continue; 2142 1.1 riastrad 2143 1.1 riastrad if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == 2144 1.1 riastrad TRANS_DDI_MODE_SELECT_DP_MST) 2145 1.1 riastrad mst_pipe_mask |= BIT(p); 2146 1.1 riastrad 2147 1.1 riastrad *pipe_mask |= BIT(p); 2148 1.1 riastrad } 2149 1.1 riastrad 2150 1.1 riastrad if (!*pipe_mask) 2151 1.1 riastrad DRM_DEBUG_KMS("No pipe for [ENCODER:%d:%s] found\n", 2152 1.1 riastrad encoder->base.base.id, encoder->base.name); 2153 1.1 riastrad 2154 1.1 riastrad if (!mst_pipe_mask && hweight8(*pipe_mask) > 1) { 2155 1.1 riastrad DRM_DEBUG_KMS("Multiple pipes for [ENCODER:%d:%s] (pipe_mask %02x)\n", 2156 1.1 riastrad encoder->base.base.id, encoder->base.name, 2157 1.1 riastrad *pipe_mask); 2158 1.1 riastrad *pipe_mask = BIT(ffs(*pipe_mask) - 1); 2159 1.1 riastrad } 2160 1.1 riastrad 2161 1.1 riastrad if (mst_pipe_mask && mst_pipe_mask != *pipe_mask) 2162 1.1 riastrad DRM_DEBUG_KMS("Conflicting MST and non-MST state for [ENCODER:%d:%s] (pipe_mask %02x mst_pipe_mask %02x)\n", 2163 1.1 riastrad encoder->base.base.id, encoder->base.name, 2164 1.1 riastrad *pipe_mask, mst_pipe_mask); 2165 1.1 riastrad else 2166 1.1 riastrad *is_dp_mst = mst_pipe_mask; 2167 1.1 riastrad 2168 1.1 riastrad out: 2169 1.1 riastrad if (*pipe_mask && IS_GEN9_LP(dev_priv)) { 2170 1.1 riastrad tmp = I915_READ(BXT_PHY_CTL(port)); 2171 1.1 riastrad if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK | 2172 1.1 riastrad BXT_PHY_LANE_POWERDOWN_ACK | 2173 1.1 riastrad BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED) 2174 1.1 riastrad DRM_ERROR("[ENCODER:%d:%s] enabled but PHY powered down? " 2175 1.1 riastrad "(PHY_CTL %08x)\n", encoder->base.base.id, 2176 1.1 riastrad encoder->base.name, tmp); 2177 1.1 riastrad } 2178 1.1 riastrad 2179 1.1 riastrad intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 2180 1.1 riastrad } 2181 1.1 riastrad 2182 1.1 riastrad bool intel_ddi_get_hw_state(struct intel_encoder *encoder, 2183 1.1 riastrad enum pipe *pipe) 2184 1.1 riastrad { 2185 1.1 riastrad u8 pipe_mask; 2186 1.1 riastrad bool is_mst; 2187 1.1 riastrad 2188 1.1 riastrad intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst); 2189 1.1 riastrad 2190 1.1 riastrad if (is_mst || !pipe_mask) 2191 1.1 riastrad return false; 2192 1.1 riastrad 2193 1.1 riastrad *pipe = ffs(pipe_mask) - 1; 2194 1.1 riastrad 2195 1.1 riastrad return true; 2196 1.1 riastrad } 2197 1.1 riastrad 2198 1.1 riastrad static inline enum intel_display_power_domain 2199 1.1 riastrad intel_ddi_main_link_aux_domain(struct intel_digital_port *dig_port) 2200 1.1 riastrad { 2201 1.1 riastrad /* CNL+ HW requires corresponding AUX IOs to be powered up for PSR with 2202 1.1 riastrad * DC states enabled at the same time, while for driver initiated AUX 2203 1.1 riastrad * transfers we need the same AUX IOs to be powered but with DC states 2204 1.1 riastrad * disabled. Accordingly use the AUX power domain here which leaves DC 2205 1.1 riastrad * states enabled. 2206 1.1 riastrad * However, for non-A AUX ports the corresponding non-EDP transcoders 2207 1.1 riastrad * would have already enabled power well 2 and DC_OFF. This means we can 2208 1.1 riastrad * acquire a wider POWER_DOMAIN_AUX_{B,C,D,F} reference instead of a 2209 1.1 riastrad * specific AUX_IO reference without powering up any extra wells. 2210 1.1 riastrad * Note that PSR is enabled only on Port A even though this function 2211 1.1 riastrad * returns the correct domain for other ports too. 2212 1.1 riastrad */ 2213 1.1 riastrad return dig_port->aux_ch == AUX_CH_A ? POWER_DOMAIN_AUX_IO_A : 2214 1.1 riastrad intel_aux_power_domain(dig_port); 2215 1.1 riastrad } 2216 1.1 riastrad 2217 1.1 riastrad static void intel_ddi_get_power_domains(struct intel_encoder *encoder, 2218 1.1 riastrad struct intel_crtc_state *crtc_state) 2219 1.1 riastrad { 2220 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2221 1.1 riastrad struct intel_digital_port *dig_port; 2222 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2223 1.1 riastrad 2224 1.1 riastrad /* 2225 1.1 riastrad * TODO: Add support for MST encoders. Atm, the following should never 2226 1.1 riastrad * happen since fake-MST encoders don't set their get_power_domains() 2227 1.1 riastrad * hook. 2228 1.1 riastrad */ 2229 1.1 riastrad if (WARN_ON(intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))) 2230 1.1 riastrad return; 2231 1.1 riastrad 2232 1.1 riastrad dig_port = enc_to_dig_port(encoder); 2233 1.1 riastrad intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain); 2234 1.1 riastrad 2235 1.1 riastrad /* 2236 1.1 riastrad * AUX power is only needed for (e)DP mode, and for HDMI mode on TC 2237 1.1 riastrad * ports. 2238 1.1 riastrad */ 2239 1.1 riastrad if (intel_crtc_has_dp_encoder(crtc_state) || 2240 1.1 riastrad intel_phy_is_tc(dev_priv, phy)) 2241 1.1 riastrad intel_display_power_get(dev_priv, 2242 1.1 riastrad intel_ddi_main_link_aux_domain(dig_port)); 2243 1.1 riastrad 2244 1.1 riastrad /* 2245 1.1 riastrad * VDSC power is needed when DSC is enabled 2246 1.1 riastrad */ 2247 1.1 riastrad if (crtc_state->dsc.compression_enable) 2248 1.1 riastrad intel_display_power_get(dev_priv, 2249 1.1 riastrad intel_dsc_power_domain(crtc_state)); 2250 1.1 riastrad } 2251 1.1 riastrad 2252 1.1 riastrad void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state) 2253 1.1 riastrad { 2254 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2255 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2256 1.1 riastrad struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc); 2257 1.1 riastrad enum port port = encoder->port; 2258 1.1 riastrad enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2259 1.1 riastrad 2260 1.1 riastrad if (cpu_transcoder != TRANSCODER_EDP) { 2261 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 2262 1.1 riastrad I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), 2263 1.1 riastrad TGL_TRANS_CLK_SEL_PORT(port)); 2264 1.1 riastrad else 2265 1.1 riastrad I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), 2266 1.1 riastrad TRANS_CLK_SEL_PORT(port)); 2267 1.1 riastrad } 2268 1.1 riastrad } 2269 1.1 riastrad 2270 1.1 riastrad void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state) 2271 1.1 riastrad { 2272 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 2273 1.1 riastrad enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2274 1.1 riastrad 2275 1.1 riastrad if (cpu_transcoder != TRANSCODER_EDP) { 2276 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 2277 1.1 riastrad I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), 2278 1.1 riastrad TGL_TRANS_CLK_SEL_DISABLED); 2279 1.1 riastrad else 2280 1.1 riastrad I915_WRITE(TRANS_CLK_SEL(cpu_transcoder), 2281 1.1 riastrad TRANS_CLK_SEL_DISABLED); 2282 1.1 riastrad } 2283 1.1 riastrad } 2284 1.1 riastrad 2285 1.1 riastrad static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv, 2286 1.1 riastrad enum port port, u8 iboost) 2287 1.1 riastrad { 2288 1.1 riastrad u32 tmp; 2289 1.1 riastrad 2290 1.1 riastrad tmp = I915_READ(DISPIO_CR_TX_BMU_CR0); 2291 1.1 riastrad tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port)); 2292 1.1 riastrad if (iboost) 2293 1.1 riastrad tmp |= iboost << BALANCE_LEG_SHIFT(port); 2294 1.1 riastrad else 2295 1.1 riastrad tmp |= BALANCE_LEG_DISABLE(port); 2296 1.1 riastrad I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp); 2297 1.1 riastrad } 2298 1.1 riastrad 2299 1.1 riastrad static void skl_ddi_set_iboost(struct intel_encoder *encoder, 2300 1.1 riastrad int level, enum intel_output_type type) 2301 1.1 riastrad { 2302 1.1 riastrad struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 2303 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2304 1.1 riastrad enum port port = encoder->port; 2305 1.1 riastrad u8 iboost; 2306 1.1 riastrad 2307 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) 2308 1.1 riastrad iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level; 2309 1.1 riastrad else 2310 1.1 riastrad iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level; 2311 1.1 riastrad 2312 1.1 riastrad if (iboost == 0) { 2313 1.1 riastrad const struct ddi_buf_trans *ddi_translations; 2314 1.1 riastrad int n_entries; 2315 1.1 riastrad 2316 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) 2317 1.1 riastrad ddi_translations = intel_ddi_get_buf_trans_hdmi(dev_priv, &n_entries); 2318 1.1 riastrad else if (type == INTEL_OUTPUT_EDP) 2319 1.1 riastrad ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv, port, &n_entries); 2320 1.1 riastrad else 2321 1.1 riastrad ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv, port, &n_entries); 2322 1.1 riastrad 2323 1.1 riastrad if (WARN_ON_ONCE(!ddi_translations)) 2324 1.1 riastrad return; 2325 1.1 riastrad if (WARN_ON_ONCE(level >= n_entries)) 2326 1.1 riastrad level = n_entries - 1; 2327 1.1 riastrad 2328 1.1 riastrad iboost = ddi_translations[level].i_boost; 2329 1.1 riastrad } 2330 1.1 riastrad 2331 1.1 riastrad /* Make sure that the requested I_boost is valid */ 2332 1.1 riastrad if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) { 2333 1.1 riastrad DRM_ERROR("Invalid I_boost value %u\n", iboost); 2334 1.1 riastrad return; 2335 1.1 riastrad } 2336 1.1 riastrad 2337 1.1 riastrad _skl_ddi_set_iboost(dev_priv, port, iboost); 2338 1.1 riastrad 2339 1.1 riastrad if (port == PORT_A && intel_dig_port->max_lanes == 4) 2340 1.1 riastrad _skl_ddi_set_iboost(dev_priv, PORT_E, iboost); 2341 1.1 riastrad } 2342 1.1 riastrad 2343 1.1 riastrad static void bxt_ddi_vswing_sequence(struct intel_encoder *encoder, 2344 1.1 riastrad int level, enum intel_output_type type) 2345 1.1 riastrad { 2346 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2347 1.1 riastrad const struct bxt_ddi_buf_trans *ddi_translations; 2348 1.1 riastrad enum port port = encoder->port; 2349 1.1 riastrad int n_entries; 2350 1.1 riastrad 2351 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) 2352 1.1 riastrad ddi_translations = bxt_get_buf_trans_hdmi(dev_priv, &n_entries); 2353 1.1 riastrad else if (type == INTEL_OUTPUT_EDP) 2354 1.1 riastrad ddi_translations = bxt_get_buf_trans_edp(dev_priv, &n_entries); 2355 1.1 riastrad else 2356 1.1 riastrad ddi_translations = bxt_get_buf_trans_dp(dev_priv, &n_entries); 2357 1.1 riastrad 2358 1.1 riastrad if (WARN_ON_ONCE(!ddi_translations)) 2359 1.1 riastrad return; 2360 1.1 riastrad if (WARN_ON_ONCE(level >= n_entries)) 2361 1.1 riastrad level = n_entries - 1; 2362 1.1 riastrad 2363 1.1 riastrad bxt_ddi_phy_set_signal_level(dev_priv, port, 2364 1.1 riastrad ddi_translations[level].margin, 2365 1.1 riastrad ddi_translations[level].scale, 2366 1.1 riastrad ddi_translations[level].enable, 2367 1.1 riastrad ddi_translations[level].deemphasis); 2368 1.1 riastrad } 2369 1.1 riastrad 2370 1.1 riastrad u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder) 2371 1.1 riastrad { 2372 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2373 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2374 1.1 riastrad enum port port = encoder->port; 2375 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 2376 1.1 riastrad int n_entries; 2377 1.1 riastrad 2378 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 2379 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) 2380 1.1 riastrad icl_get_combo_buf_trans(dev_priv, encoder->type, 2381 1.1 riastrad intel_dp->link_rate, &n_entries); 2382 1.1 riastrad else 2383 1.1 riastrad n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans); 2384 1.1 riastrad } else if (INTEL_GEN(dev_priv) == 11) { 2385 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) 2386 1.1 riastrad icl_get_combo_buf_trans(dev_priv, encoder->type, 2387 1.1 riastrad intel_dp->link_rate, &n_entries); 2388 1.1 riastrad else 2389 1.1 riastrad n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations); 2390 1.1 riastrad } else if (IS_CANNONLAKE(dev_priv)) { 2391 1.1 riastrad if (encoder->type == INTEL_OUTPUT_EDP) 2392 1.1 riastrad cnl_get_buf_trans_edp(dev_priv, &n_entries); 2393 1.1 riastrad else 2394 1.1 riastrad cnl_get_buf_trans_dp(dev_priv, &n_entries); 2395 1.1 riastrad } else if (IS_GEN9_LP(dev_priv)) { 2396 1.1 riastrad if (encoder->type == INTEL_OUTPUT_EDP) 2397 1.1 riastrad bxt_get_buf_trans_edp(dev_priv, &n_entries); 2398 1.1 riastrad else 2399 1.1 riastrad bxt_get_buf_trans_dp(dev_priv, &n_entries); 2400 1.1 riastrad } else { 2401 1.1 riastrad if (encoder->type == INTEL_OUTPUT_EDP) 2402 1.1 riastrad intel_ddi_get_buf_trans_edp(dev_priv, port, &n_entries); 2403 1.1 riastrad else 2404 1.1 riastrad intel_ddi_get_buf_trans_dp(dev_priv, port, &n_entries); 2405 1.1 riastrad } 2406 1.1 riastrad 2407 1.1 riastrad if (WARN_ON(n_entries < 1)) 2408 1.1 riastrad n_entries = 1; 2409 1.1 riastrad if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels))) 2410 1.1 riastrad n_entries = ARRAY_SIZE(index_to_dp_signal_levels); 2411 1.1 riastrad 2412 1.1 riastrad return index_to_dp_signal_levels[n_entries - 1] & 2413 1.1 riastrad DP_TRAIN_VOLTAGE_SWING_MASK; 2414 1.1 riastrad } 2415 1.1 riastrad 2416 1.1 riastrad /* 2417 1.1 riastrad * We assume that the full set of pre-emphasis values can be 2418 1.1 riastrad * used on all DDI platforms. Should that change we need to 2419 1.1 riastrad * rethink this code. 2420 1.1 riastrad */ 2421 1.1 riastrad u8 intel_ddi_dp_pre_emphasis_max(struct intel_encoder *encoder, u8 voltage_swing) 2422 1.1 riastrad { 2423 1.1 riastrad switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) { 2424 1.1 riastrad case DP_TRAIN_VOLTAGE_SWING_LEVEL_0: 2425 1.1 riastrad return DP_TRAIN_PRE_EMPH_LEVEL_3; 2426 1.1 riastrad case DP_TRAIN_VOLTAGE_SWING_LEVEL_1: 2427 1.1 riastrad return DP_TRAIN_PRE_EMPH_LEVEL_2; 2428 1.1 riastrad case DP_TRAIN_VOLTAGE_SWING_LEVEL_2: 2429 1.1 riastrad return DP_TRAIN_PRE_EMPH_LEVEL_1; 2430 1.1 riastrad case DP_TRAIN_VOLTAGE_SWING_LEVEL_3: 2431 1.1 riastrad default: 2432 1.1 riastrad return DP_TRAIN_PRE_EMPH_LEVEL_0; 2433 1.1 riastrad } 2434 1.1 riastrad } 2435 1.1 riastrad 2436 1.1 riastrad static void cnl_ddi_vswing_program(struct intel_encoder *encoder, 2437 1.1 riastrad int level, enum intel_output_type type) 2438 1.1 riastrad { 2439 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2440 1.1 riastrad const struct cnl_ddi_buf_trans *ddi_translations; 2441 1.1 riastrad enum port port = encoder->port; 2442 1.1 riastrad int n_entries, ln; 2443 1.1 riastrad u32 val; 2444 1.1 riastrad 2445 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) 2446 1.1 riastrad ddi_translations = cnl_get_buf_trans_hdmi(dev_priv, &n_entries); 2447 1.1 riastrad else if (type == INTEL_OUTPUT_EDP) 2448 1.1 riastrad ddi_translations = cnl_get_buf_trans_edp(dev_priv, &n_entries); 2449 1.1 riastrad else 2450 1.1 riastrad ddi_translations = cnl_get_buf_trans_dp(dev_priv, &n_entries); 2451 1.1 riastrad 2452 1.1 riastrad if (WARN_ON_ONCE(!ddi_translations)) 2453 1.1 riastrad return; 2454 1.1 riastrad if (WARN_ON_ONCE(level >= n_entries)) 2455 1.1 riastrad level = n_entries - 1; 2456 1.1 riastrad 2457 1.1 riastrad /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */ 2458 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW5_LN0(port)); 2459 1.1 riastrad val &= ~SCALING_MODE_SEL_MASK; 2460 1.1 riastrad val |= SCALING_MODE_SEL(2); 2461 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val); 2462 1.1 riastrad 2463 1.1 riastrad /* Program PORT_TX_DW2 */ 2464 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW2_LN0(port)); 2465 1.1 riastrad val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 2466 1.1 riastrad RCOMP_SCALAR_MASK); 2467 1.1 riastrad val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel); 2468 1.1 riastrad val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel); 2469 1.1 riastrad /* Rcomp scalar is fixed as 0x98 for every table entry */ 2470 1.1 riastrad val |= RCOMP_SCALAR(0x98); 2471 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW2_GRP(port), val); 2472 1.1 riastrad 2473 1.1 riastrad /* Program PORT_TX_DW4 */ 2474 1.1 riastrad /* We cannot write to GRP. It would overrite individual loadgen */ 2475 1.1 riastrad for (ln = 0; ln < 4; ln++) { 2476 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW4_LN(ln, port)); 2477 1.1 riastrad val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 2478 1.1 riastrad CURSOR_COEFF_MASK); 2479 1.1 riastrad val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1); 2480 1.1 riastrad val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2); 2481 1.1 riastrad val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff); 2482 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW4_LN(ln, port), val); 2483 1.1 riastrad } 2484 1.1 riastrad 2485 1.1 riastrad /* Program PORT_TX_DW5 */ 2486 1.1 riastrad /* All DW5 values are fixed for every table entry */ 2487 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW5_LN0(port)); 2488 1.1 riastrad val &= ~RTERM_SELECT_MASK; 2489 1.1 riastrad val |= RTERM_SELECT(6); 2490 1.1 riastrad val |= TAP3_DISABLE; 2491 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val); 2492 1.1 riastrad 2493 1.1 riastrad /* Program PORT_TX_DW7 */ 2494 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW7_LN0(port)); 2495 1.1 riastrad val &= ~N_SCALAR_MASK; 2496 1.1 riastrad val |= N_SCALAR(ddi_translations[level].dw7_n_scalar); 2497 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW7_GRP(port), val); 2498 1.1 riastrad } 2499 1.1 riastrad 2500 1.1 riastrad static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder, 2501 1.1 riastrad int level, enum intel_output_type type) 2502 1.1 riastrad { 2503 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2504 1.1 riastrad enum port port = encoder->port; 2505 1.1 riastrad int width, rate, ln; 2506 1.1 riastrad u32 val; 2507 1.1 riastrad 2508 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) { 2509 1.1 riastrad width = 4; 2510 1.1 riastrad rate = 0; /* Rate is always < than 6GHz for HDMI */ 2511 1.1 riastrad } else { 2512 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2513 1.1 riastrad 2514 1.1 riastrad width = intel_dp->lane_count; 2515 1.1 riastrad rate = intel_dp->link_rate; 2516 1.1 riastrad } 2517 1.1 riastrad 2518 1.1 riastrad /* 2519 1.1 riastrad * 1. If port type is eDP or DP, 2520 1.1 riastrad * set PORT_PCS_DW1 cmnkeeper_enable to 1b, 2521 1.1 riastrad * else clear to 0b. 2522 1.1 riastrad */ 2523 1.1 riastrad val = I915_READ(CNL_PORT_PCS_DW1_LN0(port)); 2524 1.1 riastrad if (type != INTEL_OUTPUT_HDMI) 2525 1.1 riastrad val |= COMMON_KEEPER_EN; 2526 1.1 riastrad else 2527 1.1 riastrad val &= ~COMMON_KEEPER_EN; 2528 1.1 riastrad I915_WRITE(CNL_PORT_PCS_DW1_GRP(port), val); 2529 1.1 riastrad 2530 1.1 riastrad /* 2. Program loadgen select */ 2531 1.1 riastrad /* 2532 1.1 riastrad * Program PORT_TX_DW4_LN depending on Bit rate and used lanes 2533 1.1 riastrad * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1) 2534 1.1 riastrad * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0) 2535 1.1 riastrad * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0) 2536 1.1 riastrad */ 2537 1.1 riastrad for (ln = 0; ln <= 3; ln++) { 2538 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW4_LN(ln, port)); 2539 1.1 riastrad val &= ~LOADGEN_SELECT; 2540 1.1 riastrad 2541 1.1 riastrad if ((rate <= 600000 && width == 4 && ln >= 1) || 2542 1.1 riastrad (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) { 2543 1.1 riastrad val |= LOADGEN_SELECT; 2544 1.1 riastrad } 2545 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW4_LN(ln, port), val); 2546 1.1 riastrad } 2547 1.1 riastrad 2548 1.1 riastrad /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */ 2549 1.1 riastrad val = I915_READ(CNL_PORT_CL1CM_DW5); 2550 1.1 riastrad val |= SUS_CLOCK_CONFIG; 2551 1.1 riastrad I915_WRITE(CNL_PORT_CL1CM_DW5, val); 2552 1.1 riastrad 2553 1.1 riastrad /* 4. Clear training enable to change swing values */ 2554 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW5_LN0(port)); 2555 1.1 riastrad val &= ~TX_TRAINING_EN; 2556 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val); 2557 1.1 riastrad 2558 1.1 riastrad /* 5. Program swing and de-emphasis */ 2559 1.1 riastrad cnl_ddi_vswing_program(encoder, level, type); 2560 1.1 riastrad 2561 1.1 riastrad /* 6. Set training enable to trigger update */ 2562 1.1 riastrad val = I915_READ(CNL_PORT_TX_DW5_LN0(port)); 2563 1.1 riastrad val |= TX_TRAINING_EN; 2564 1.1 riastrad I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val); 2565 1.1 riastrad } 2566 1.1 riastrad 2567 1.1 riastrad static void icl_ddi_combo_vswing_program(struct drm_i915_private *dev_priv, 2568 1.1 riastrad u32 level, enum phy phy, int type, 2569 1.1 riastrad int rate) 2570 1.1 riastrad { 2571 1.1 riastrad const struct cnl_ddi_buf_trans *ddi_translations = NULL; 2572 1.1 riastrad u32 n_entries, val; 2573 1.1 riastrad int ln; 2574 1.1 riastrad 2575 1.1 riastrad ddi_translations = icl_get_combo_buf_trans(dev_priv, type, rate, 2576 1.1 riastrad &n_entries); 2577 1.1 riastrad if (!ddi_translations) 2578 1.1 riastrad return; 2579 1.1 riastrad 2580 1.1 riastrad if (level >= n_entries) { 2581 1.1 riastrad DRM_DEBUG_KMS("DDI translation not found for level %d. Using %d instead.", level, n_entries - 1); 2582 1.1 riastrad level = n_entries - 1; 2583 1.1 riastrad } 2584 1.1 riastrad 2585 1.1 riastrad /* Set PORT_TX_DW5 */ 2586 1.1 riastrad val = I915_READ(ICL_PORT_TX_DW5_LN0(phy)); 2587 1.1 riastrad val &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK | 2588 1.1 riastrad TAP2_DISABLE | TAP3_DISABLE); 2589 1.1 riastrad val |= SCALING_MODE_SEL(0x2); 2590 1.1 riastrad val |= RTERM_SELECT(0x6); 2591 1.1 riastrad val |= TAP3_DISABLE; 2592 1.1 riastrad I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), val); 2593 1.1 riastrad 2594 1.1 riastrad /* Program PORT_TX_DW2 */ 2595 1.1 riastrad val = I915_READ(ICL_PORT_TX_DW2_LN0(phy)); 2596 1.1 riastrad val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 2597 1.1 riastrad RCOMP_SCALAR_MASK); 2598 1.1 riastrad val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel); 2599 1.1 riastrad val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel); 2600 1.1 riastrad /* Program Rcomp scalar for every table entry */ 2601 1.1 riastrad val |= RCOMP_SCALAR(0x98); 2602 1.1 riastrad I915_WRITE(ICL_PORT_TX_DW2_GRP(phy), val); 2603 1.1 riastrad 2604 1.1 riastrad /* Program PORT_TX_DW4 */ 2605 1.1 riastrad /* We cannot write to GRP. It would overwrite individual loadgen. */ 2606 1.1 riastrad for (ln = 0; ln <= 3; ln++) { 2607 1.1 riastrad val = I915_READ(ICL_PORT_TX_DW4_LN(ln, phy)); 2608 1.1 riastrad val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 2609 1.1 riastrad CURSOR_COEFF_MASK); 2610 1.1 riastrad val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1); 2611 1.1 riastrad val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2); 2612 1.1 riastrad val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff); 2613 1.1 riastrad I915_WRITE(ICL_PORT_TX_DW4_LN(ln, phy), val); 2614 1.1 riastrad } 2615 1.1 riastrad 2616 1.1 riastrad /* Program PORT_TX_DW7 */ 2617 1.1 riastrad val = I915_READ(ICL_PORT_TX_DW7_LN0(phy)); 2618 1.1 riastrad val &= ~N_SCALAR_MASK; 2619 1.1 riastrad val |= N_SCALAR(ddi_translations[level].dw7_n_scalar); 2620 1.1 riastrad I915_WRITE(ICL_PORT_TX_DW7_GRP(phy), val); 2621 1.1 riastrad } 2622 1.1 riastrad 2623 1.1 riastrad static void icl_combo_phy_ddi_vswing_sequence(struct intel_encoder *encoder, 2624 1.1 riastrad u32 level, 2625 1.1 riastrad enum intel_output_type type) 2626 1.1 riastrad { 2627 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2628 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2629 1.1 riastrad int width = 0; 2630 1.1 riastrad int rate = 0; 2631 1.1 riastrad u32 val; 2632 1.1 riastrad int ln = 0; 2633 1.1 riastrad 2634 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) { 2635 1.1 riastrad width = 4; 2636 1.1 riastrad /* Rate is always < than 6GHz for HDMI */ 2637 1.1 riastrad } else { 2638 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2639 1.1 riastrad 2640 1.1 riastrad width = intel_dp->lane_count; 2641 1.1 riastrad rate = intel_dp->link_rate; 2642 1.1 riastrad } 2643 1.1 riastrad 2644 1.1 riastrad /* 2645 1.1 riastrad * 1. If port type is eDP or DP, 2646 1.1 riastrad * set PORT_PCS_DW1 cmnkeeper_enable to 1b, 2647 1.1 riastrad * else clear to 0b. 2648 1.1 riastrad */ 2649 1.1 riastrad val = I915_READ(ICL_PORT_PCS_DW1_LN0(phy)); 2650 1.1 riastrad if (type == INTEL_OUTPUT_HDMI) 2651 1.1 riastrad val &= ~COMMON_KEEPER_EN; 2652 1.1 riastrad else 2653 1.1 riastrad val |= COMMON_KEEPER_EN; 2654 1.1 riastrad I915_WRITE(ICL_PORT_PCS_DW1_GRP(phy), val); 2655 1.1 riastrad 2656 1.1 riastrad /* 2. Program loadgen select */ 2657 1.1 riastrad /* 2658 1.1 riastrad * Program PORT_TX_DW4_LN depending on Bit rate and used lanes 2659 1.1 riastrad * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1) 2660 1.1 riastrad * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0) 2661 1.1 riastrad * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0) 2662 1.1 riastrad */ 2663 1.1 riastrad for (ln = 0; ln <= 3; ln++) { 2664 1.1 riastrad val = I915_READ(ICL_PORT_TX_DW4_LN(ln, phy)); 2665 1.1 riastrad val &= ~LOADGEN_SELECT; 2666 1.1 riastrad 2667 1.1 riastrad if ((rate <= 600000 && width == 4 && ln >= 1) || 2668 1.1 riastrad (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) { 2669 1.1 riastrad val |= LOADGEN_SELECT; 2670 1.1 riastrad } 2671 1.1 riastrad I915_WRITE(ICL_PORT_TX_DW4_LN(ln, phy), val); 2672 1.1 riastrad } 2673 1.1 riastrad 2674 1.1 riastrad /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */ 2675 1.1 riastrad val = I915_READ(ICL_PORT_CL_DW5(phy)); 2676 1.1 riastrad val |= SUS_CLOCK_CONFIG; 2677 1.1 riastrad I915_WRITE(ICL_PORT_CL_DW5(phy), val); 2678 1.1 riastrad 2679 1.1 riastrad /* 4. Clear training enable to change swing values */ 2680 1.1 riastrad val = I915_READ(ICL_PORT_TX_DW5_LN0(phy)); 2681 1.1 riastrad val &= ~TX_TRAINING_EN; 2682 1.1 riastrad I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), val); 2683 1.1 riastrad 2684 1.1 riastrad /* 5. Program swing and de-emphasis */ 2685 1.1 riastrad icl_ddi_combo_vswing_program(dev_priv, level, phy, type, rate); 2686 1.1 riastrad 2687 1.1 riastrad /* 6. Set training enable to trigger update */ 2688 1.1 riastrad val = I915_READ(ICL_PORT_TX_DW5_LN0(phy)); 2689 1.1 riastrad val |= TX_TRAINING_EN; 2690 1.1 riastrad I915_WRITE(ICL_PORT_TX_DW5_GRP(phy), val); 2691 1.1 riastrad } 2692 1.1 riastrad 2693 1.1 riastrad static void icl_mg_phy_ddi_vswing_sequence(struct intel_encoder *encoder, 2694 1.1 riastrad int link_clock, 2695 1.1 riastrad u32 level) 2696 1.1 riastrad { 2697 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2698 1.1 riastrad enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port); 2699 1.1 riastrad const struct icl_mg_phy_ddi_buf_trans *ddi_translations; 2700 1.1 riastrad u32 n_entries, val; 2701 1.1 riastrad int ln; 2702 1.1 riastrad 2703 1.1 riastrad n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations); 2704 1.1 riastrad ddi_translations = icl_mg_phy_ddi_translations; 2705 1.1 riastrad /* The table does not have values for level 3 and level 9. */ 2706 1.1 riastrad if (level >= n_entries || level == 3 || level == 9) { 2707 1.1 riastrad DRM_DEBUG_KMS("DDI translation not found for level %d. Using %d instead.", 2708 1.1 riastrad level, n_entries - 2); 2709 1.1 riastrad level = n_entries - 2; 2710 1.1 riastrad } 2711 1.1 riastrad 2712 1.1 riastrad /* Set MG_TX_LINK_PARAMS cri_use_fs32 to 0. */ 2713 1.1 riastrad for (ln = 0; ln < 2; ln++) { 2714 1.1 riastrad val = I915_READ(MG_TX1_LINK_PARAMS(ln, tc_port)); 2715 1.1 riastrad val &= ~CRI_USE_FS32; 2716 1.1 riastrad I915_WRITE(MG_TX1_LINK_PARAMS(ln, tc_port), val); 2717 1.1 riastrad 2718 1.1 riastrad val = I915_READ(MG_TX2_LINK_PARAMS(ln, tc_port)); 2719 1.1 riastrad val &= ~CRI_USE_FS32; 2720 1.1 riastrad I915_WRITE(MG_TX2_LINK_PARAMS(ln, tc_port), val); 2721 1.1 riastrad } 2722 1.1 riastrad 2723 1.1 riastrad /* Program MG_TX_SWINGCTRL with values from vswing table */ 2724 1.1 riastrad for (ln = 0; ln < 2; ln++) { 2725 1.1 riastrad val = I915_READ(MG_TX1_SWINGCTRL(ln, tc_port)); 2726 1.1 riastrad val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK; 2727 1.1 riastrad val |= CRI_TXDEEMPH_OVERRIDE_17_12( 2728 1.1 riastrad ddi_translations[level].cri_txdeemph_override_17_12); 2729 1.1 riastrad I915_WRITE(MG_TX1_SWINGCTRL(ln, tc_port), val); 2730 1.1 riastrad 2731 1.1 riastrad val = I915_READ(MG_TX2_SWINGCTRL(ln, tc_port)); 2732 1.1 riastrad val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK; 2733 1.1 riastrad val |= CRI_TXDEEMPH_OVERRIDE_17_12( 2734 1.1 riastrad ddi_translations[level].cri_txdeemph_override_17_12); 2735 1.1 riastrad I915_WRITE(MG_TX2_SWINGCTRL(ln, tc_port), val); 2736 1.1 riastrad } 2737 1.1 riastrad 2738 1.1 riastrad /* Program MG_TX_DRVCTRL with values from vswing table */ 2739 1.1 riastrad for (ln = 0; ln < 2; ln++) { 2740 1.1 riastrad val = I915_READ(MG_TX1_DRVCTRL(ln, tc_port)); 2741 1.1 riastrad val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK | 2742 1.1 riastrad CRI_TXDEEMPH_OVERRIDE_5_0_MASK); 2743 1.1 riastrad val |= CRI_TXDEEMPH_OVERRIDE_5_0( 2744 1.1 riastrad ddi_translations[level].cri_txdeemph_override_5_0) | 2745 1.1 riastrad CRI_TXDEEMPH_OVERRIDE_11_6( 2746 1.1 riastrad ddi_translations[level].cri_txdeemph_override_11_6) | 2747 1.1 riastrad CRI_TXDEEMPH_OVERRIDE_EN; 2748 1.1 riastrad I915_WRITE(MG_TX1_DRVCTRL(ln, tc_port), val); 2749 1.1 riastrad 2750 1.1 riastrad val = I915_READ(MG_TX2_DRVCTRL(ln, tc_port)); 2751 1.1 riastrad val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK | 2752 1.1 riastrad CRI_TXDEEMPH_OVERRIDE_5_0_MASK); 2753 1.1 riastrad val |= CRI_TXDEEMPH_OVERRIDE_5_0( 2754 1.1 riastrad ddi_translations[level].cri_txdeemph_override_5_0) | 2755 1.1 riastrad CRI_TXDEEMPH_OVERRIDE_11_6( 2756 1.1 riastrad ddi_translations[level].cri_txdeemph_override_11_6) | 2757 1.1 riastrad CRI_TXDEEMPH_OVERRIDE_EN; 2758 1.1 riastrad I915_WRITE(MG_TX2_DRVCTRL(ln, tc_port), val); 2759 1.1 riastrad 2760 1.1 riastrad /* FIXME: Program CRI_LOADGEN_SEL after the spec is updated */ 2761 1.1 riastrad } 2762 1.1 riastrad 2763 1.1 riastrad /* 2764 1.1 riastrad * Program MG_CLKHUB<LN, port being used> with value from frequency table 2765 1.1 riastrad * In case of Legacy mode on MG PHY, both TX1 and TX2 enabled so use the 2766 1.1 riastrad * values from table for which TX1 and TX2 enabled. 2767 1.1 riastrad */ 2768 1.1 riastrad for (ln = 0; ln < 2; ln++) { 2769 1.1 riastrad val = I915_READ(MG_CLKHUB(ln, tc_port)); 2770 1.1 riastrad if (link_clock < 300000) 2771 1.1 riastrad val |= CFG_LOW_RATE_LKREN_EN; 2772 1.1 riastrad else 2773 1.1 riastrad val &= ~CFG_LOW_RATE_LKREN_EN; 2774 1.1 riastrad I915_WRITE(MG_CLKHUB(ln, tc_port), val); 2775 1.1 riastrad } 2776 1.1 riastrad 2777 1.1 riastrad /* Program the MG_TX_DCC<LN, port being used> based on the link frequency */ 2778 1.1 riastrad for (ln = 0; ln < 2; ln++) { 2779 1.1 riastrad val = I915_READ(MG_TX1_DCC(ln, tc_port)); 2780 1.1 riastrad val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK; 2781 1.1 riastrad if (link_clock <= 500000) { 2782 1.1 riastrad val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN; 2783 1.1 riastrad } else { 2784 1.1 riastrad val |= CFG_AMI_CK_DIV_OVERRIDE_EN | 2785 1.1 riastrad CFG_AMI_CK_DIV_OVERRIDE_VAL(1); 2786 1.1 riastrad } 2787 1.1 riastrad I915_WRITE(MG_TX1_DCC(ln, tc_port), val); 2788 1.1 riastrad 2789 1.1 riastrad val = I915_READ(MG_TX2_DCC(ln, tc_port)); 2790 1.1 riastrad val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK; 2791 1.1 riastrad if (link_clock <= 500000) { 2792 1.1 riastrad val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN; 2793 1.1 riastrad } else { 2794 1.1 riastrad val |= CFG_AMI_CK_DIV_OVERRIDE_EN | 2795 1.1 riastrad CFG_AMI_CK_DIV_OVERRIDE_VAL(1); 2796 1.1 riastrad } 2797 1.1 riastrad I915_WRITE(MG_TX2_DCC(ln, tc_port), val); 2798 1.1 riastrad } 2799 1.1 riastrad 2800 1.1 riastrad /* Program MG_TX_PISO_READLOAD with values from vswing table */ 2801 1.1 riastrad for (ln = 0; ln < 2; ln++) { 2802 1.1 riastrad val = I915_READ(MG_TX1_PISO_READLOAD(ln, tc_port)); 2803 1.1 riastrad val |= CRI_CALCINIT; 2804 1.1 riastrad I915_WRITE(MG_TX1_PISO_READLOAD(ln, tc_port), val); 2805 1.1 riastrad 2806 1.1 riastrad val = I915_READ(MG_TX2_PISO_READLOAD(ln, tc_port)); 2807 1.1 riastrad val |= CRI_CALCINIT; 2808 1.1 riastrad I915_WRITE(MG_TX2_PISO_READLOAD(ln, tc_port), val); 2809 1.1 riastrad } 2810 1.1 riastrad } 2811 1.1 riastrad 2812 1.1 riastrad static void icl_ddi_vswing_sequence(struct intel_encoder *encoder, 2813 1.1 riastrad int link_clock, 2814 1.1 riastrad u32 level, 2815 1.1 riastrad enum intel_output_type type) 2816 1.1 riastrad { 2817 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2818 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2819 1.1 riastrad 2820 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) 2821 1.1 riastrad icl_combo_phy_ddi_vswing_sequence(encoder, level, type); 2822 1.1 riastrad else 2823 1.1 riastrad icl_mg_phy_ddi_vswing_sequence(encoder, link_clock, level); 2824 1.1 riastrad } 2825 1.1 riastrad 2826 1.1 riastrad static void 2827 1.1 riastrad tgl_dkl_phy_ddi_vswing_sequence(struct intel_encoder *encoder, int link_clock, 2828 1.1 riastrad u32 level) 2829 1.1 riastrad { 2830 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2831 1.1 riastrad enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port); 2832 1.1 riastrad const struct tgl_dkl_phy_ddi_buf_trans *ddi_translations; 2833 1.1 riastrad u32 n_entries, val, ln, dpcnt_mask, dpcnt_val; 2834 1.1 riastrad 2835 1.1 riastrad if (encoder->type == INTEL_OUTPUT_HDMI) { 2836 1.1 riastrad n_entries = ARRAY_SIZE(tgl_dkl_phy_hdmi_ddi_trans); 2837 1.1 riastrad ddi_translations = tgl_dkl_phy_hdmi_ddi_trans; 2838 1.1 riastrad } else { 2839 1.1 riastrad n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans); 2840 1.1 riastrad ddi_translations = tgl_dkl_phy_dp_ddi_trans; 2841 1.1 riastrad } 2842 1.1 riastrad 2843 1.1 riastrad if (level >= n_entries) 2844 1.1 riastrad level = n_entries - 1; 2845 1.1 riastrad 2846 1.1 riastrad dpcnt_mask = (DKL_TX_PRESHOOT_COEFF_MASK | 2847 1.1 riastrad DKL_TX_DE_EMPAHSIS_COEFF_MASK | 2848 1.1 riastrad DKL_TX_VSWING_CONTROL_MASK); 2849 1.1 riastrad dpcnt_val = DKL_TX_VSWING_CONTROL(ddi_translations[level].dkl_vswing_control); 2850 1.1 riastrad dpcnt_val |= DKL_TX_DE_EMPHASIS_COEFF(ddi_translations[level].dkl_de_emphasis_control); 2851 1.1 riastrad dpcnt_val |= DKL_TX_PRESHOOT_COEFF(ddi_translations[level].dkl_preshoot_control); 2852 1.1 riastrad 2853 1.1 riastrad for (ln = 0; ln < 2; ln++) { 2854 1.1 riastrad I915_WRITE(HIP_INDEX_REG(tc_port), HIP_INDEX_VAL(tc_port, ln)); 2855 1.1 riastrad 2856 1.1 riastrad I915_WRITE(DKL_TX_PMD_LANE_SUS(tc_port), 0); 2857 1.1 riastrad 2858 1.1 riastrad /* All the registers are RMW */ 2859 1.1 riastrad val = I915_READ(DKL_TX_DPCNTL0(tc_port)); 2860 1.1 riastrad val &= ~dpcnt_mask; 2861 1.1 riastrad val |= dpcnt_val; 2862 1.1 riastrad I915_WRITE(DKL_TX_DPCNTL0(tc_port), val); 2863 1.1 riastrad 2864 1.1 riastrad val = I915_READ(DKL_TX_DPCNTL1(tc_port)); 2865 1.1 riastrad val &= ~dpcnt_mask; 2866 1.1 riastrad val |= dpcnt_val; 2867 1.1 riastrad I915_WRITE(DKL_TX_DPCNTL1(tc_port), val); 2868 1.1 riastrad 2869 1.1 riastrad val = I915_READ(DKL_TX_DPCNTL2(tc_port)); 2870 1.1 riastrad val &= ~DKL_TX_DP20BITMODE; 2871 1.1 riastrad I915_WRITE(DKL_TX_DPCNTL2(tc_port), val); 2872 1.1 riastrad } 2873 1.1 riastrad } 2874 1.1 riastrad 2875 1.1 riastrad static void tgl_ddi_vswing_sequence(struct intel_encoder *encoder, 2876 1.1 riastrad int link_clock, 2877 1.1 riastrad u32 level, 2878 1.1 riastrad enum intel_output_type type) 2879 1.1 riastrad { 2880 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2881 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2882 1.1 riastrad 2883 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) 2884 1.1 riastrad icl_combo_phy_ddi_vswing_sequence(encoder, level, type); 2885 1.1 riastrad else 2886 1.1 riastrad tgl_dkl_phy_ddi_vswing_sequence(encoder, link_clock, level); 2887 1.1 riastrad } 2888 1.1 riastrad 2889 1.1 riastrad static u32 translate_signal_level(int signal_levels) 2890 1.1 riastrad { 2891 1.1 riastrad int i; 2892 1.1 riastrad 2893 1.1 riastrad for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) { 2894 1.1 riastrad if (index_to_dp_signal_levels[i] == signal_levels) 2895 1.1 riastrad return i; 2896 1.1 riastrad } 2897 1.1 riastrad 2898 1.1 riastrad WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n", 2899 1.1 riastrad signal_levels); 2900 1.1 riastrad 2901 1.1 riastrad return 0; 2902 1.1 riastrad } 2903 1.1 riastrad 2904 1.1 riastrad static u32 intel_ddi_dp_level(struct intel_dp *intel_dp) 2905 1.1 riastrad { 2906 1.1 riastrad u8 train_set = intel_dp->train_set[0]; 2907 1.1 riastrad int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | 2908 1.1 riastrad DP_TRAIN_PRE_EMPHASIS_MASK); 2909 1.1 riastrad 2910 1.1 riastrad return translate_signal_level(signal_levels); 2911 1.1 riastrad } 2912 1.1 riastrad 2913 1.1 riastrad u32 bxt_signal_levels(struct intel_dp *intel_dp) 2914 1.1 riastrad { 2915 1.1 riastrad struct intel_digital_port *dport = dp_to_dig_port(intel_dp); 2916 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev); 2917 1.1 riastrad struct intel_encoder *encoder = &dport->base; 2918 1.1 riastrad int level = intel_ddi_dp_level(intel_dp); 2919 1.1 riastrad 2920 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 2921 1.1 riastrad tgl_ddi_vswing_sequence(encoder, intel_dp->link_rate, 2922 1.1 riastrad level, encoder->type); 2923 1.1 riastrad else if (INTEL_GEN(dev_priv) >= 11) 2924 1.1 riastrad icl_ddi_vswing_sequence(encoder, intel_dp->link_rate, 2925 1.1 riastrad level, encoder->type); 2926 1.1 riastrad else if (IS_CANNONLAKE(dev_priv)) 2927 1.1 riastrad cnl_ddi_vswing_sequence(encoder, level, encoder->type); 2928 1.1 riastrad else 2929 1.1 riastrad bxt_ddi_vswing_sequence(encoder, level, encoder->type); 2930 1.1 riastrad 2931 1.1 riastrad return 0; 2932 1.1 riastrad } 2933 1.1 riastrad 2934 1.1 riastrad u32 ddi_signal_levels(struct intel_dp *intel_dp) 2935 1.1 riastrad { 2936 1.1 riastrad struct intel_digital_port *dport = dp_to_dig_port(intel_dp); 2937 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev); 2938 1.1 riastrad struct intel_encoder *encoder = &dport->base; 2939 1.1 riastrad int level = intel_ddi_dp_level(intel_dp); 2940 1.1 riastrad 2941 1.1 riastrad if (IS_GEN9_BC(dev_priv)) 2942 1.1 riastrad skl_ddi_set_iboost(encoder, level, encoder->type); 2943 1.1 riastrad 2944 1.1 riastrad return DDI_BUF_TRANS_SELECT(level); 2945 1.1 riastrad } 2946 1.1 riastrad 2947 1.1 riastrad static inline 2948 1.1 riastrad u32 icl_dpclka_cfgcr0_clk_off(struct drm_i915_private *dev_priv, 2949 1.1 riastrad enum phy phy) 2950 1.1 riastrad { 2951 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) { 2952 1.1 riastrad return ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 2953 1.1 riastrad } else if (intel_phy_is_tc(dev_priv, phy)) { 2954 1.1 riastrad enum tc_port tc_port = intel_port_to_tc(dev_priv, 2955 1.1 riastrad (enum port)phy); 2956 1.1 riastrad 2957 1.1 riastrad return ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port); 2958 1.1 riastrad } 2959 1.1 riastrad 2960 1.1 riastrad return 0; 2961 1.1 riastrad } 2962 1.1 riastrad 2963 1.1 riastrad static void icl_map_plls_to_ports(struct intel_encoder *encoder, 2964 1.1 riastrad const struct intel_crtc_state *crtc_state) 2965 1.1 riastrad { 2966 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2967 1.1 riastrad struct intel_shared_dpll *pll = crtc_state->shared_dpll; 2968 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2969 1.1 riastrad u32 val; 2970 1.1 riastrad 2971 1.1 riastrad mutex_lock(&dev_priv->dpll_lock); 2972 1.1 riastrad 2973 1.1 riastrad val = I915_READ(ICL_DPCLKA_CFGCR0); 2974 1.1 riastrad WARN_ON((val & icl_dpclka_cfgcr0_clk_off(dev_priv, phy)) == 0); 2975 1.1 riastrad 2976 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) { 2977 1.1 riastrad /* 2978 1.1 riastrad * Even though this register references DDIs, note that we 2979 1.1 riastrad * want to pass the PHY rather than the port (DDI). For 2980 1.1 riastrad * ICL, port=phy in all cases so it doesn't matter, but for 2981 1.1 riastrad * EHL the bspec notes the following: 2982 1.1 riastrad * 2983 1.1 riastrad * "DDID clock tied to DDIA clock, so DPCLKA_CFGCR0 DDIA 2984 1.1 riastrad * Clock Select chooses the PLL for both DDIA and DDID and 2985 1.1 riastrad * drives port A in all cases." 2986 1.1 riastrad */ 2987 1.1 riastrad val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy); 2988 1.1 riastrad val |= ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy); 2989 1.1 riastrad I915_WRITE(ICL_DPCLKA_CFGCR0, val); 2990 1.1 riastrad POSTING_READ(ICL_DPCLKA_CFGCR0); 2991 1.1 riastrad } 2992 1.1 riastrad 2993 1.1 riastrad val &= ~icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 2994 1.1 riastrad I915_WRITE(ICL_DPCLKA_CFGCR0, val); 2995 1.1 riastrad 2996 1.1 riastrad mutex_unlock(&dev_priv->dpll_lock); 2997 1.1 riastrad } 2998 1.1 riastrad 2999 1.1 riastrad static void icl_unmap_plls_to_ports(struct intel_encoder *encoder) 3000 1.1 riastrad { 3001 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3002 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3003 1.1 riastrad u32 val; 3004 1.1 riastrad 3005 1.1 riastrad mutex_lock(&dev_priv->dpll_lock); 3006 1.1 riastrad 3007 1.1 riastrad val = I915_READ(ICL_DPCLKA_CFGCR0); 3008 1.1 riastrad val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 3009 1.1 riastrad I915_WRITE(ICL_DPCLKA_CFGCR0, val); 3010 1.1 riastrad 3011 1.1 riastrad mutex_unlock(&dev_priv->dpll_lock); 3012 1.1 riastrad } 3013 1.1 riastrad 3014 1.1 riastrad static void icl_sanitize_port_clk_off(struct drm_i915_private *dev_priv, 3015 1.1 riastrad u32 port_mask, bool ddi_clk_needed) 3016 1.1 riastrad { 3017 1.1 riastrad enum port port; 3018 1.1 riastrad u32 val; 3019 1.1 riastrad 3020 1.1 riastrad val = I915_READ(ICL_DPCLKA_CFGCR0); 3021 1.1 riastrad for_each_port_masked(port, port_mask) { 3022 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 3023 1.1 riastrad bool ddi_clk_off = val & icl_dpclka_cfgcr0_clk_off(dev_priv, 3024 1.1 riastrad phy); 3025 1.1 riastrad 3026 1.1 riastrad if (ddi_clk_needed == !ddi_clk_off) 3027 1.1 riastrad continue; 3028 1.1 riastrad 3029 1.1 riastrad /* 3030 1.1 riastrad * Punt on the case now where clock is gated, but it would 3031 1.1 riastrad * be needed by the port. Something else is really broken then. 3032 1.1 riastrad */ 3033 1.1 riastrad if (WARN_ON(ddi_clk_needed)) 3034 1.1 riastrad continue; 3035 1.1 riastrad 3036 1.1 riastrad DRM_NOTE("PHY %c is disabled/in DSI mode with an ungated DDI clock, gate it\n", 3037 1.1 riastrad phy_name(phy)); 3038 1.1 riastrad val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 3039 1.1 riastrad I915_WRITE(ICL_DPCLKA_CFGCR0, val); 3040 1.1 riastrad } 3041 1.1 riastrad } 3042 1.1 riastrad 3043 1.1 riastrad void icl_sanitize_encoder_pll_mapping(struct intel_encoder *encoder) 3044 1.1 riastrad { 3045 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3046 1.1 riastrad u32 port_mask; 3047 1.1 riastrad bool ddi_clk_needed; 3048 1.1 riastrad 3049 1.1 riastrad /* 3050 1.1 riastrad * In case of DP MST, we sanitize the primary encoder only, not the 3051 1.1 riastrad * virtual ones. 3052 1.1 riastrad */ 3053 1.1 riastrad if (encoder->type == INTEL_OUTPUT_DP_MST) 3054 1.1 riastrad return; 3055 1.1 riastrad 3056 1.1 riastrad if (!encoder->base.crtc && intel_encoder_is_dp(encoder)) { 3057 1.1 riastrad u8 pipe_mask; 3058 1.1 riastrad bool is_mst; 3059 1.1 riastrad 3060 1.1 riastrad intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst); 3061 1.1 riastrad /* 3062 1.1 riastrad * In the unlikely case that BIOS enables DP in MST mode, just 3063 1.1 riastrad * warn since our MST HW readout is incomplete. 3064 1.1 riastrad */ 3065 1.1 riastrad if (WARN_ON(is_mst)) 3066 1.1 riastrad return; 3067 1.1 riastrad } 3068 1.1 riastrad 3069 1.1 riastrad port_mask = BIT(encoder->port); 3070 1.1 riastrad ddi_clk_needed = encoder->base.crtc; 3071 1.1 riastrad 3072 1.1 riastrad if (encoder->type == INTEL_OUTPUT_DSI) { 3073 1.1 riastrad struct intel_encoder *other_encoder; 3074 1.1 riastrad 3075 1.1 riastrad port_mask = intel_dsi_encoder_ports(encoder); 3076 1.1 riastrad /* 3077 1.1 riastrad * Sanity check that we haven't incorrectly registered another 3078 1.1 riastrad * encoder using any of the ports of this DSI encoder. 3079 1.1 riastrad */ 3080 1.1 riastrad for_each_intel_encoder(&dev_priv->drm, other_encoder) { 3081 1.1 riastrad if (other_encoder == encoder) 3082 1.1 riastrad continue; 3083 1.1 riastrad 3084 1.1 riastrad if (WARN_ON(port_mask & BIT(other_encoder->port))) 3085 1.1 riastrad return; 3086 1.1 riastrad } 3087 1.1 riastrad /* 3088 1.1 riastrad * For DSI we keep the ddi clocks gated 3089 1.1 riastrad * except during enable/disable sequence. 3090 1.1 riastrad */ 3091 1.1 riastrad ddi_clk_needed = false; 3092 1.1 riastrad } 3093 1.1 riastrad 3094 1.1 riastrad icl_sanitize_port_clk_off(dev_priv, port_mask, ddi_clk_needed); 3095 1.1 riastrad } 3096 1.1 riastrad 3097 1.1 riastrad static void intel_ddi_clk_select(struct intel_encoder *encoder, 3098 1.1 riastrad const struct intel_crtc_state *crtc_state) 3099 1.1 riastrad { 3100 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3101 1.1 riastrad enum port port = encoder->port; 3102 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 3103 1.1 riastrad u32 val; 3104 1.1 riastrad const struct intel_shared_dpll *pll = crtc_state->shared_dpll; 3105 1.1 riastrad 3106 1.1 riastrad if (WARN_ON(!pll)) 3107 1.1 riastrad return; 3108 1.1 riastrad 3109 1.1 riastrad mutex_lock(&dev_priv->dpll_lock); 3110 1.1 riastrad 3111 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) { 3112 1.1 riastrad if (!intel_phy_is_combo(dev_priv, phy)) 3113 1.1 riastrad I915_WRITE(DDI_CLK_SEL(port), 3114 1.1 riastrad icl_pll_to_ddi_clk_sel(encoder, crtc_state)); 3115 1.1 riastrad else if (IS_ELKHARTLAKE(dev_priv) && port >= PORT_C) 3116 1.1 riastrad /* 3117 1.1 riastrad * MG does not exist but the programming is required 3118 1.1 riastrad * to ungate DDIC and DDID 3119 1.1 riastrad */ 3120 1.1 riastrad I915_WRITE(DDI_CLK_SEL(port), DDI_CLK_SEL_MG); 3121 1.1 riastrad } else if (IS_CANNONLAKE(dev_priv)) { 3122 1.1 riastrad /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */ 3123 1.1 riastrad val = I915_READ(DPCLKA_CFGCR0); 3124 1.1 riastrad val &= ~DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); 3125 1.1 riastrad val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, port); 3126 1.1 riastrad I915_WRITE(DPCLKA_CFGCR0, val); 3127 1.1 riastrad 3128 1.1 riastrad /* 3129 1.1 riastrad * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI. 3130 1.1 riastrad * This step and the step before must be done with separate 3131 1.1 riastrad * register writes. 3132 1.1 riastrad */ 3133 1.1 riastrad val = I915_READ(DPCLKA_CFGCR0); 3134 1.1 riastrad val &= ~DPCLKA_CFGCR0_DDI_CLK_OFF(port); 3135 1.1 riastrad I915_WRITE(DPCLKA_CFGCR0, val); 3136 1.1 riastrad } else if (IS_GEN9_BC(dev_priv)) { 3137 1.1 riastrad /* DDI -> PLL mapping */ 3138 1.1 riastrad val = I915_READ(DPLL_CTRL2); 3139 1.1 riastrad 3140 1.1 riastrad val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) | 3141 1.1 riastrad DPLL_CTRL2_DDI_CLK_SEL_MASK(port)); 3142 1.1 riastrad val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->info->id, port) | 3143 1.1 riastrad DPLL_CTRL2_DDI_SEL_OVERRIDE(port)); 3144 1.1 riastrad 3145 1.1 riastrad I915_WRITE(DPLL_CTRL2, val); 3146 1.1 riastrad 3147 1.1 riastrad } else if (INTEL_GEN(dev_priv) < 9) { 3148 1.1 riastrad I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll)); 3149 1.1 riastrad } 3150 1.1 riastrad 3151 1.1 riastrad mutex_unlock(&dev_priv->dpll_lock); 3152 1.1 riastrad } 3153 1.1 riastrad 3154 1.1 riastrad static void intel_ddi_clk_disable(struct intel_encoder *encoder) 3155 1.1 riastrad { 3156 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3157 1.1 riastrad enum port port = encoder->port; 3158 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 3159 1.1 riastrad 3160 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) { 3161 1.1 riastrad if (!intel_phy_is_combo(dev_priv, phy) || 3162 1.1 riastrad (IS_ELKHARTLAKE(dev_priv) && port >= PORT_C)) 3163 1.1 riastrad I915_WRITE(DDI_CLK_SEL(port), DDI_CLK_SEL_NONE); 3164 1.1 riastrad } else if (IS_CANNONLAKE(dev_priv)) { 3165 1.1 riastrad I915_WRITE(DPCLKA_CFGCR0, I915_READ(DPCLKA_CFGCR0) | 3166 1.1 riastrad DPCLKA_CFGCR0_DDI_CLK_OFF(port)); 3167 1.1 riastrad } else if (IS_GEN9_BC(dev_priv)) { 3168 1.1 riastrad I915_WRITE(DPLL_CTRL2, I915_READ(DPLL_CTRL2) | 3169 1.1 riastrad DPLL_CTRL2_DDI_CLK_OFF(port)); 3170 1.1 riastrad } else if (INTEL_GEN(dev_priv) < 9) { 3171 1.1 riastrad I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE); 3172 1.1 riastrad } 3173 1.1 riastrad } 3174 1.1 riastrad 3175 1.1 riastrad static void 3176 1.1 riastrad icl_program_mg_dp_mode(struct intel_digital_port *intel_dig_port, 3177 1.1 riastrad const struct intel_crtc_state *crtc_state) 3178 1.1 riastrad { 3179 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev); 3180 1.1 riastrad enum tc_port tc_port = intel_port_to_tc(dev_priv, intel_dig_port->base.port); 3181 1.1 riastrad u32 ln0, ln1, pin_assignment; 3182 1.1 riastrad u8 width; 3183 1.1 riastrad 3184 1.1 riastrad if (intel_dig_port->tc_mode == TC_PORT_TBT_ALT) 3185 1.1 riastrad return; 3186 1.1 riastrad 3187 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 3188 1.1 riastrad I915_WRITE(HIP_INDEX_REG(tc_port), HIP_INDEX_VAL(tc_port, 0x0)); 3189 1.1 riastrad ln0 = I915_READ(DKL_DP_MODE(tc_port)); 3190 1.1 riastrad I915_WRITE(HIP_INDEX_REG(tc_port), HIP_INDEX_VAL(tc_port, 0x1)); 3191 1.1 riastrad ln1 = I915_READ(DKL_DP_MODE(tc_port)); 3192 1.1 riastrad } else { 3193 1.1 riastrad ln0 = I915_READ(MG_DP_MODE(0, tc_port)); 3194 1.1 riastrad ln1 = I915_READ(MG_DP_MODE(1, tc_port)); 3195 1.1 riastrad } 3196 1.1 riastrad 3197 1.1 riastrad ln0 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X1_MODE); 3198 1.1 riastrad ln1 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE); 3199 1.1 riastrad 3200 1.1 riastrad /* DPPATC */ 3201 1.1 riastrad pin_assignment = intel_tc_port_get_pin_assignment_mask(intel_dig_port); 3202 1.1 riastrad width = crtc_state->lane_count; 3203 1.1 riastrad 3204 1.1 riastrad switch (pin_assignment) { 3205 1.1 riastrad case 0x0: 3206 1.1 riastrad WARN_ON(intel_dig_port->tc_mode != TC_PORT_LEGACY); 3207 1.1 riastrad if (width == 1) { 3208 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 3209 1.1 riastrad } else { 3210 1.1 riastrad ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 3211 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 3212 1.1 riastrad } 3213 1.1 riastrad break; 3214 1.1 riastrad case 0x1: 3215 1.1 riastrad if (width == 4) { 3216 1.1 riastrad ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 3217 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 3218 1.1 riastrad } 3219 1.1 riastrad break; 3220 1.1 riastrad case 0x2: 3221 1.1 riastrad if (width == 2) { 3222 1.1 riastrad ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 3223 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 3224 1.1 riastrad } 3225 1.1 riastrad break; 3226 1.1 riastrad case 0x3: 3227 1.1 riastrad case 0x5: 3228 1.1 riastrad if (width == 1) { 3229 1.1 riastrad ln0 |= MG_DP_MODE_CFG_DP_X1_MODE; 3230 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 3231 1.1 riastrad } else { 3232 1.1 riastrad ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 3233 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 3234 1.1 riastrad } 3235 1.1 riastrad break; 3236 1.1 riastrad case 0x4: 3237 1.1 riastrad case 0x6: 3238 1.1 riastrad if (width == 1) { 3239 1.1 riastrad ln0 |= MG_DP_MODE_CFG_DP_X1_MODE; 3240 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 3241 1.1 riastrad } else { 3242 1.1 riastrad ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 3243 1.1 riastrad ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 3244 1.1 riastrad } 3245 1.1 riastrad break; 3246 1.1 riastrad default: 3247 1.1 riastrad MISSING_CASE(pin_assignment); 3248 1.1 riastrad } 3249 1.1 riastrad 3250 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 3251 1.1 riastrad I915_WRITE(HIP_INDEX_REG(tc_port), HIP_INDEX_VAL(tc_port, 0x0)); 3252 1.1 riastrad I915_WRITE(DKL_DP_MODE(tc_port), ln0); 3253 1.1 riastrad I915_WRITE(HIP_INDEX_REG(tc_port), HIP_INDEX_VAL(tc_port, 0x1)); 3254 1.1 riastrad I915_WRITE(DKL_DP_MODE(tc_port), ln1); 3255 1.1 riastrad } else { 3256 1.1 riastrad I915_WRITE(MG_DP_MODE(0, tc_port), ln0); 3257 1.1 riastrad I915_WRITE(MG_DP_MODE(1, tc_port), ln1); 3258 1.1 riastrad } 3259 1.1 riastrad } 3260 1.1 riastrad 3261 1.1 riastrad static void intel_dp_sink_set_fec_ready(struct intel_dp *intel_dp, 3262 1.1 riastrad const struct intel_crtc_state *crtc_state) 3263 1.1 riastrad { 3264 1.1 riastrad if (!crtc_state->fec_enable) 3265 1.1 riastrad return; 3266 1.1 riastrad 3267 1.1 riastrad if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_FEC_CONFIGURATION, DP_FEC_READY) <= 0) 3268 1.1 riastrad DRM_DEBUG_KMS("Failed to set FEC_READY in the sink\n"); 3269 1.1 riastrad } 3270 1.1 riastrad 3271 1.1 riastrad static void intel_ddi_enable_fec(struct intel_encoder *encoder, 3272 1.1 riastrad const struct intel_crtc_state *crtc_state) 3273 1.1 riastrad { 3274 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3275 1.1 riastrad struct intel_dp *intel_dp; 3276 1.1 riastrad u32 val; 3277 1.1 riastrad 3278 1.1 riastrad if (!crtc_state->fec_enable) 3279 1.1 riastrad return; 3280 1.1 riastrad 3281 1.1 riastrad intel_dp = enc_to_intel_dp(encoder); 3282 1.1 riastrad val = I915_READ(intel_dp->regs.dp_tp_ctl); 3283 1.1 riastrad val |= DP_TP_CTL_FEC_ENABLE; 3284 1.1 riastrad I915_WRITE(intel_dp->regs.dp_tp_ctl, val); 3285 1.1 riastrad 3286 1.1 riastrad if (intel_de_wait_for_set(dev_priv, intel_dp->regs.dp_tp_status, 3287 1.1 riastrad DP_TP_STATUS_FEC_ENABLE_LIVE, 1)) 3288 1.1 riastrad DRM_ERROR("Timed out waiting for FEC Enable Status\n"); 3289 1.1 riastrad } 3290 1.1 riastrad 3291 1.1 riastrad static void intel_ddi_disable_fec_state(struct intel_encoder *encoder, 3292 1.1 riastrad const struct intel_crtc_state *crtc_state) 3293 1.1 riastrad { 3294 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3295 1.1 riastrad struct intel_dp *intel_dp; 3296 1.1 riastrad u32 val; 3297 1.1 riastrad 3298 1.1 riastrad if (!crtc_state->fec_enable) 3299 1.1 riastrad return; 3300 1.1 riastrad 3301 1.1 riastrad intel_dp = enc_to_intel_dp(encoder); 3302 1.1 riastrad val = I915_READ(intel_dp->regs.dp_tp_ctl); 3303 1.1 riastrad val &= ~DP_TP_CTL_FEC_ENABLE; 3304 1.1 riastrad I915_WRITE(intel_dp->regs.dp_tp_ctl, val); 3305 1.1 riastrad POSTING_READ(intel_dp->regs.dp_tp_ctl); 3306 1.1 riastrad } 3307 1.1 riastrad 3308 1.1 riastrad static void 3309 1.1 riastrad tgl_clear_psr2_transcoder_exitline(const struct intel_crtc_state *cstate) 3310 1.1 riastrad { 3311 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(cstate->uapi.crtc->dev); 3312 1.1 riastrad u32 val; 3313 1.1 riastrad 3314 1.1 riastrad if (!cstate->dc3co_exitline) 3315 1.1 riastrad return; 3316 1.1 riastrad 3317 1.1 riastrad val = I915_READ(EXITLINE(cstate->cpu_transcoder)); 3318 1.1 riastrad val &= ~(EXITLINE_MASK | EXITLINE_ENABLE); 3319 1.1 riastrad I915_WRITE(EXITLINE(cstate->cpu_transcoder), val); 3320 1.1 riastrad } 3321 1.1 riastrad 3322 1.1 riastrad static void 3323 1.1 riastrad tgl_set_psr2_transcoder_exitline(const struct intel_crtc_state *cstate) 3324 1.1 riastrad { 3325 1.1 riastrad u32 val, exit_scanlines; 3326 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(cstate->uapi.crtc->dev); 3327 1.1 riastrad 3328 1.1 riastrad if (!cstate->dc3co_exitline) 3329 1.1 riastrad return; 3330 1.1 riastrad 3331 1.1 riastrad exit_scanlines = cstate->dc3co_exitline; 3332 1.1 riastrad exit_scanlines <<= EXITLINE_SHIFT; 3333 1.1 riastrad val = I915_READ(EXITLINE(cstate->cpu_transcoder)); 3334 1.1 riastrad val &= ~(EXITLINE_MASK | EXITLINE_ENABLE); 3335 1.1 riastrad val |= exit_scanlines; 3336 1.1 riastrad val |= EXITLINE_ENABLE; 3337 1.1 riastrad I915_WRITE(EXITLINE(cstate->cpu_transcoder), val); 3338 1.1 riastrad } 3339 1.1 riastrad 3340 1.1 riastrad static void tgl_dc3co_exitline_compute_config(struct intel_encoder *encoder, 3341 1.1 riastrad struct intel_crtc_state *cstate) 3342 1.1 riastrad { 3343 1.1 riastrad u32 exit_scanlines; 3344 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(cstate->uapi.crtc->dev); 3345 1.1 riastrad u32 crtc_vdisplay = cstate->hw.adjusted_mode.crtc_vdisplay; 3346 1.1 riastrad 3347 1.1 riastrad cstate->dc3co_exitline = 0; 3348 1.1 riastrad 3349 1.1 riastrad if (!(dev_priv->csr.allowed_dc_mask & DC_STATE_EN_DC3CO)) 3350 1.1 riastrad return; 3351 1.1 riastrad 3352 1.1 riastrad /* B.Specs:49196 DC3CO only works with pipeA and DDIA.*/ 3353 1.1 riastrad if (to_intel_crtc(cstate->uapi.crtc)->pipe != PIPE_A || 3354 1.1 riastrad encoder->port != PORT_A) 3355 1.1 riastrad return; 3356 1.1 riastrad 3357 1.1 riastrad if (!cstate->has_psr2 || !cstate->hw.active) 3358 1.1 riastrad return; 3359 1.1 riastrad 3360 1.1 riastrad /* 3361 1.1 riastrad * DC3CO Exit time 200us B.Spec 49196 3362 1.1 riastrad * PSR2 transcoder Early Exit scanlines = ROUNDUP(200 / line time) + 1 3363 1.1 riastrad */ 3364 1.1 riastrad exit_scanlines = 3365 1.1 riastrad intel_usecs_to_scanlines(&cstate->hw.adjusted_mode, 200) + 1; 3366 1.1 riastrad 3367 1.1 riastrad if (WARN_ON(exit_scanlines > crtc_vdisplay)) 3368 1.1 riastrad return; 3369 1.1 riastrad 3370 1.1 riastrad cstate->dc3co_exitline = crtc_vdisplay - exit_scanlines; 3371 1.1 riastrad DRM_DEBUG_KMS("DC3CO exit scanlines %d\n", cstate->dc3co_exitline); 3372 1.1 riastrad } 3373 1.1 riastrad 3374 1.1 riastrad static void tgl_dc3co_exitline_get_config(struct intel_crtc_state *crtc_state) 3375 1.1 riastrad { 3376 1.1 riastrad u32 val; 3377 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 3378 1.1 riastrad 3379 1.1 riastrad if (INTEL_GEN(dev_priv) < 12) 3380 1.1 riastrad return; 3381 1.1 riastrad 3382 1.1 riastrad val = I915_READ(EXITLINE(crtc_state->cpu_transcoder)); 3383 1.1 riastrad 3384 1.1 riastrad if (val & EXITLINE_ENABLE) 3385 1.1 riastrad crtc_state->dc3co_exitline = val & EXITLINE_MASK; 3386 1.1 riastrad } 3387 1.1 riastrad 3388 1.1 riastrad static void tgl_ddi_pre_enable_dp(struct intel_encoder *encoder, 3389 1.1 riastrad const struct intel_crtc_state *crtc_state, 3390 1.1 riastrad const struct drm_connector_state *conn_state) 3391 1.1 riastrad { 3392 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3393 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3394 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3395 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3396 1.1 riastrad bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3397 1.1 riastrad int level = intel_ddi_dp_level(intel_dp); 3398 1.1 riastrad enum transcoder transcoder = crtc_state->cpu_transcoder; 3399 1.1 riastrad 3400 1.1 riastrad tgl_set_psr2_transcoder_exitline(crtc_state); 3401 1.1 riastrad intel_dp_set_link_params(intel_dp, crtc_state->port_clock, 3402 1.1 riastrad crtc_state->lane_count, is_mst); 3403 1.1 riastrad 3404 1.1 riastrad intel_dp->regs.dp_tp_ctl = TGL_DP_TP_CTL(transcoder); 3405 1.1 riastrad intel_dp->regs.dp_tp_status = TGL_DP_TP_STATUS(transcoder); 3406 1.1 riastrad 3407 1.1 riastrad /* 3408 1.1 riastrad * 1. Enable Power Wells 3409 1.1 riastrad * 3410 1.1 riastrad * This was handled at the beginning of intel_atomic_commit_tail(), 3411 1.1 riastrad * before we called down into this function. 3412 1.1 riastrad */ 3413 1.1 riastrad 3414 1.1 riastrad /* 2. Enable Panel Power if PPS is required */ 3415 1.1 riastrad intel_edp_panel_on(intel_dp); 3416 1.1 riastrad 3417 1.1 riastrad /* 3418 1.1 riastrad * 3. For non-TBT Type-C ports, set FIA lane count 3419 1.1 riastrad * (DFLEXDPSP.DPX4TXLATC) 3420 1.1 riastrad * 3421 1.1 riastrad * This was done before tgl_ddi_pre_enable_dp by 3422 1.1 riastrad * hsw_crtc_enable()->intel_encoders_pre_pll_enable(). 3423 1.1 riastrad */ 3424 1.1 riastrad 3425 1.1 riastrad /* 3426 1.1 riastrad * 4. Enable the port PLL. 3427 1.1 riastrad * 3428 1.1 riastrad * The PLL enabling itself was already done before this function by 3429 1.1 riastrad * hsw_crtc_enable()->intel_enable_shared_dpll(). We need only 3430 1.1 riastrad * configure the PLL to port mapping here. 3431 1.1 riastrad */ 3432 1.1 riastrad intel_ddi_clk_select(encoder, crtc_state); 3433 1.1 riastrad 3434 1.1 riastrad /* 5. If IO power is controlled through PWR_WELL_CTL, Enable IO Power */ 3435 1.1 riastrad if (!intel_phy_is_tc(dev_priv, phy) || 3436 1.1 riastrad dig_port->tc_mode != TC_PORT_TBT_ALT) 3437 1.1 riastrad intel_display_power_get(dev_priv, 3438 1.1 riastrad dig_port->ddi_io_power_domain); 3439 1.1 riastrad 3440 1.1 riastrad /* 6. Program DP_MODE */ 3441 1.1 riastrad icl_program_mg_dp_mode(dig_port, crtc_state); 3442 1.1 riastrad 3443 1.1 riastrad /* 3444 1.1 riastrad * 7. The rest of the below are substeps under the bspec's "Enable and 3445 1.1 riastrad * Train Display Port" step. Note that steps that are specific to 3446 1.1 riastrad * MST will be handled by intel_mst_pre_enable_dp() before/after it 3447 1.1 riastrad * calls into this function. Also intel_mst_pre_enable_dp() only calls 3448 1.1 riastrad * us when active_mst_links==0, so any steps designated for "single 3449 1.1 riastrad * stream or multi-stream master transcoder" can just be performed 3450 1.1 riastrad * unconditionally here. 3451 1.1 riastrad */ 3452 1.1 riastrad 3453 1.1 riastrad /* 3454 1.1 riastrad * 7.a Configure Transcoder Clock Select to direct the Port clock to the 3455 1.1 riastrad * Transcoder. 3456 1.1 riastrad */ 3457 1.1 riastrad intel_ddi_enable_pipe_clock(crtc_state); 3458 1.1 riastrad 3459 1.1 riastrad /* 3460 1.1 riastrad * 7.b Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST 3461 1.1 riastrad * Transport Select 3462 1.1 riastrad */ 3463 1.1 riastrad intel_ddi_config_transcoder_func(crtc_state); 3464 1.1 riastrad 3465 1.1 riastrad /* 3466 1.1 riastrad * 7.c Configure & enable DP_TP_CTL with link training pattern 1 3467 1.1 riastrad * selected 3468 1.1 riastrad * 3469 1.1 riastrad * This will be handled by the intel_dp_start_link_train() farther 3470 1.1 riastrad * down this function. 3471 1.1 riastrad */ 3472 1.1 riastrad 3473 1.1 riastrad /* 7.e Configure voltage swing and related IO settings */ 3474 1.1 riastrad tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, level, 3475 1.1 riastrad encoder->type); 3476 1.1 riastrad 3477 1.1 riastrad /* 3478 1.1 riastrad * 7.f Combo PHY: Configure PORT_CL_DW10 Static Power Down to power up 3479 1.1 riastrad * the used lanes of the DDI. 3480 1.1 riastrad */ 3481 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) { 3482 1.1 riastrad bool lane_reversal = 3483 1.1 riastrad dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL; 3484 1.1 riastrad 3485 1.1 riastrad intel_combo_phy_power_up_lanes(dev_priv, phy, false, 3486 1.1 riastrad crtc_state->lane_count, 3487 1.1 riastrad lane_reversal); 3488 1.1 riastrad } 3489 1.1 riastrad 3490 1.1 riastrad /* 3491 1.1 riastrad * 7.g Configure and enable DDI_BUF_CTL 3492 1.1 riastrad * 7.h Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout 3493 1.1 riastrad * after 500 us. 3494 1.1 riastrad * 3495 1.1 riastrad * We only configure what the register value will be here. Actual 3496 1.1 riastrad * enabling happens during link training farther down. 3497 1.1 riastrad */ 3498 1.1 riastrad intel_ddi_init_dp_buf_reg(encoder); 3499 1.1 riastrad 3500 1.1 riastrad if (!is_mst) 3501 1.1 riastrad intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 3502 1.1 riastrad 3503 1.1 riastrad intel_dp_sink_set_decompression_state(intel_dp, crtc_state, true); 3504 1.1 riastrad /* 3505 1.1 riastrad * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit 3506 1.1 riastrad * in the FEC_CONFIGURATION register to 1 before initiating link 3507 1.1 riastrad * training 3508 1.1 riastrad */ 3509 1.1 riastrad intel_dp_sink_set_fec_ready(intel_dp, crtc_state); 3510 1.1 riastrad 3511 1.1 riastrad /* 3512 1.1 riastrad * 7.i Follow DisplayPort specification training sequence (see notes for 3513 1.1 riastrad * failure handling) 3514 1.1 riastrad * 7.j If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle 3515 1.1 riastrad * Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent) 3516 1.1 riastrad * (timeout after 800 us) 3517 1.1 riastrad */ 3518 1.1 riastrad intel_dp_start_link_train(intel_dp); 3519 1.1 riastrad 3520 1.1 riastrad /* 7.k Set DP_TP_CTL link training to Normal */ 3521 1.1 riastrad if (!is_trans_port_sync_mode(crtc_state)) 3522 1.1 riastrad intel_dp_stop_link_train(intel_dp); 3523 1.1 riastrad 3524 1.1 riastrad /* 7.l Configure and enable FEC if needed */ 3525 1.1 riastrad intel_ddi_enable_fec(encoder, crtc_state); 3526 1.1 riastrad intel_dsc_enable(encoder, crtc_state); 3527 1.1 riastrad } 3528 1.1 riastrad 3529 1.1 riastrad static void hsw_ddi_pre_enable_dp(struct intel_encoder *encoder, 3530 1.1 riastrad const struct intel_crtc_state *crtc_state, 3531 1.1 riastrad const struct drm_connector_state *conn_state) 3532 1.1 riastrad { 3533 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3534 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3535 1.1 riastrad enum port port = encoder->port; 3536 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 3537 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3538 1.1 riastrad bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3539 1.1 riastrad int level = intel_ddi_dp_level(intel_dp); 3540 1.1 riastrad 3541 1.1 riastrad if (INTEL_GEN(dev_priv) < 11) 3542 1.1 riastrad WARN_ON(is_mst && (port == PORT_A || port == PORT_E)); 3543 1.1 riastrad else 3544 1.1 riastrad WARN_ON(is_mst && port == PORT_A); 3545 1.1 riastrad 3546 1.1 riastrad intel_dp_set_link_params(intel_dp, crtc_state->port_clock, 3547 1.1 riastrad crtc_state->lane_count, is_mst); 3548 1.1 riastrad 3549 1.1 riastrad intel_dp->regs.dp_tp_ctl = DP_TP_CTL(port); 3550 1.1 riastrad intel_dp->regs.dp_tp_status = DP_TP_STATUS(port); 3551 1.1 riastrad 3552 1.1 riastrad intel_edp_panel_on(intel_dp); 3553 1.1 riastrad 3554 1.1 riastrad intel_ddi_clk_select(encoder, crtc_state); 3555 1.1 riastrad 3556 1.1 riastrad if (!intel_phy_is_tc(dev_priv, phy) || 3557 1.1 riastrad dig_port->tc_mode != TC_PORT_TBT_ALT) 3558 1.1 riastrad intel_display_power_get(dev_priv, 3559 1.1 riastrad dig_port->ddi_io_power_domain); 3560 1.1 riastrad 3561 1.1 riastrad icl_program_mg_dp_mode(dig_port, crtc_state); 3562 1.1 riastrad 3563 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) 3564 1.1 riastrad icl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3565 1.1 riastrad level, encoder->type); 3566 1.1 riastrad else if (IS_CANNONLAKE(dev_priv)) 3567 1.1 riastrad cnl_ddi_vswing_sequence(encoder, level, encoder->type); 3568 1.1 riastrad else if (IS_GEN9_LP(dev_priv)) 3569 1.1 riastrad bxt_ddi_vswing_sequence(encoder, level, encoder->type); 3570 1.1 riastrad else 3571 1.1 riastrad intel_prepare_dp_ddi_buffers(encoder, crtc_state); 3572 1.1 riastrad 3573 1.1 riastrad if (intel_phy_is_combo(dev_priv, phy)) { 3574 1.1 riastrad bool lane_reversal = 3575 1.1 riastrad dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL; 3576 1.1 riastrad 3577 1.1 riastrad intel_combo_phy_power_up_lanes(dev_priv, phy, false, 3578 1.1 riastrad crtc_state->lane_count, 3579 1.1 riastrad lane_reversal); 3580 1.1 riastrad } 3581 1.1 riastrad 3582 1.1 riastrad intel_ddi_init_dp_buf_reg(encoder); 3583 1.1 riastrad if (!is_mst) 3584 1.1 riastrad intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 3585 1.1 riastrad intel_dp_sink_set_decompression_state(intel_dp, crtc_state, 3586 1.1 riastrad true); 3587 1.1 riastrad intel_dp_sink_set_fec_ready(intel_dp, crtc_state); 3588 1.1 riastrad intel_dp_start_link_train(intel_dp); 3589 1.1 riastrad if ((port != PORT_A || INTEL_GEN(dev_priv) >= 9) && 3590 1.1 riastrad !is_trans_port_sync_mode(crtc_state)) 3591 1.1 riastrad intel_dp_stop_link_train(intel_dp); 3592 1.1 riastrad 3593 1.1 riastrad intel_ddi_enable_fec(encoder, crtc_state); 3594 1.1 riastrad 3595 1.1 riastrad if (!is_mst) 3596 1.1 riastrad intel_ddi_enable_pipe_clock(crtc_state); 3597 1.1 riastrad 3598 1.1 riastrad intel_dsc_enable(encoder, crtc_state); 3599 1.1 riastrad } 3600 1.1 riastrad 3601 1.1 riastrad static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder, 3602 1.1 riastrad const struct intel_crtc_state *crtc_state, 3603 1.1 riastrad const struct drm_connector_state *conn_state) 3604 1.1 riastrad { 3605 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3606 1.1 riastrad 3607 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 3608 1.1 riastrad tgl_ddi_pre_enable_dp(encoder, crtc_state, conn_state); 3609 1.1 riastrad else 3610 1.1 riastrad hsw_ddi_pre_enable_dp(encoder, crtc_state, conn_state); 3611 1.1 riastrad 3612 1.1 riastrad /* MST will call a setting of MSA after an allocating of Virtual Channel 3613 1.1 riastrad * from MST encoder pre_enable callback. 3614 1.1 riastrad */ 3615 1.1 riastrad if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) 3616 1.1 riastrad intel_ddi_set_dp_msa(crtc_state, conn_state); 3617 1.1 riastrad } 3618 1.1 riastrad 3619 1.1 riastrad static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder, 3620 1.1 riastrad const struct intel_crtc_state *crtc_state, 3621 1.1 riastrad const struct drm_connector_state *conn_state) 3622 1.1 riastrad { 3623 1.1 riastrad struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); 3624 1.1 riastrad struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi; 3625 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3626 1.1 riastrad enum port port = encoder->port; 3627 1.1 riastrad int level = intel_ddi_hdmi_level(dev_priv, port); 3628 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3629 1.1 riastrad 3630 1.1 riastrad intel_dp_dual_mode_set_tmds_output(intel_hdmi, true); 3631 1.1 riastrad intel_ddi_clk_select(encoder, crtc_state); 3632 1.1 riastrad 3633 1.1 riastrad intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain); 3634 1.1 riastrad 3635 1.1 riastrad icl_program_mg_dp_mode(dig_port, crtc_state); 3636 1.1 riastrad 3637 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 3638 1.1 riastrad tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3639 1.1 riastrad level, INTEL_OUTPUT_HDMI); 3640 1.1 riastrad else if (INTEL_GEN(dev_priv) == 11) 3641 1.1 riastrad icl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3642 1.1 riastrad level, INTEL_OUTPUT_HDMI); 3643 1.1 riastrad else if (IS_CANNONLAKE(dev_priv)) 3644 1.1 riastrad cnl_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI); 3645 1.1 riastrad else if (IS_GEN9_LP(dev_priv)) 3646 1.1 riastrad bxt_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI); 3647 1.1 riastrad else 3648 1.1 riastrad intel_prepare_hdmi_ddi_buffers(encoder, level); 3649 1.1 riastrad 3650 1.1 riastrad if (IS_GEN9_BC(dev_priv)) 3651 1.1 riastrad skl_ddi_set_iboost(encoder, level, INTEL_OUTPUT_HDMI); 3652 1.1 riastrad 3653 1.1 riastrad intel_ddi_enable_pipe_clock(crtc_state); 3654 1.1 riastrad 3655 1.1 riastrad intel_dig_port->set_infoframes(encoder, 3656 1.1 riastrad crtc_state->has_infoframe, 3657 1.1 riastrad crtc_state, conn_state); 3658 1.1 riastrad } 3659 1.1 riastrad 3660 1.1 riastrad static void intel_ddi_pre_enable(struct intel_encoder *encoder, 3661 1.1 riastrad const struct intel_crtc_state *crtc_state, 3662 1.1 riastrad const struct drm_connector_state *conn_state) 3663 1.1 riastrad { 3664 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3665 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3666 1.1 riastrad enum pipe pipe = crtc->pipe; 3667 1.1 riastrad 3668 1.1 riastrad /* 3669 1.1 riastrad * When called from DP MST code: 3670 1.1 riastrad * - conn_state will be NULL 3671 1.1 riastrad * - encoder will be the main encoder (ie. mst->primary) 3672 1.1 riastrad * - the main connector associated with this port 3673 1.1 riastrad * won't be active or linked to a crtc 3674 1.1 riastrad * - crtc_state will be the state of the first stream to 3675 1.1 riastrad * be activated on this port, and it may not be the same 3676 1.1 riastrad * stream that will be deactivated last, but each stream 3677 1.1 riastrad * should have a state that is identical when it comes to 3678 1.1 riastrad * the DP link parameteres 3679 1.1 riastrad */ 3680 1.1 riastrad 3681 1.1 riastrad WARN_ON(crtc_state->has_pch_encoder); 3682 1.1 riastrad 3683 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) 3684 1.1 riastrad icl_map_plls_to_ports(encoder, crtc_state); 3685 1.1 riastrad 3686 1.1 riastrad intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 3687 1.1 riastrad 3688 1.1 riastrad if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 3689 1.1 riastrad intel_ddi_pre_enable_hdmi(encoder, crtc_state, conn_state); 3690 1.1 riastrad } else { 3691 1.1 riastrad struct intel_lspcon *lspcon = 3692 1.1 riastrad enc_to_intel_lspcon(encoder); 3693 1.1 riastrad 3694 1.1 riastrad intel_ddi_pre_enable_dp(encoder, crtc_state, conn_state); 3695 1.1 riastrad if (lspcon->active) { 3696 1.1 riastrad struct intel_digital_port *dig_port = 3697 1.1 riastrad enc_to_dig_port(encoder); 3698 1.1 riastrad 3699 1.1 riastrad dig_port->set_infoframes(encoder, 3700 1.1 riastrad crtc_state->has_infoframe, 3701 1.1 riastrad crtc_state, conn_state); 3702 1.1 riastrad } 3703 1.1 riastrad } 3704 1.1 riastrad } 3705 1.1 riastrad 3706 1.1 riastrad static void intel_disable_ddi_buf(struct intel_encoder *encoder, 3707 1.1 riastrad const struct intel_crtc_state *crtc_state) 3708 1.1 riastrad { 3709 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3710 1.1 riastrad enum port port = encoder->port; 3711 1.1 riastrad bool wait = false; 3712 1.1 riastrad u32 val; 3713 1.1 riastrad 3714 1.1 riastrad val = I915_READ(DDI_BUF_CTL(port)); 3715 1.1 riastrad if (val & DDI_BUF_CTL_ENABLE) { 3716 1.1 riastrad val &= ~DDI_BUF_CTL_ENABLE; 3717 1.1 riastrad I915_WRITE(DDI_BUF_CTL(port), val); 3718 1.1 riastrad wait = true; 3719 1.1 riastrad } 3720 1.1 riastrad 3721 1.1 riastrad if (intel_crtc_has_dp_encoder(crtc_state)) { 3722 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3723 1.1 riastrad 3724 1.1 riastrad val = I915_READ(intel_dp->regs.dp_tp_ctl); 3725 1.1 riastrad val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 3726 1.1 riastrad val |= DP_TP_CTL_LINK_TRAIN_PAT1; 3727 1.1 riastrad I915_WRITE(intel_dp->regs.dp_tp_ctl, val); 3728 1.1 riastrad } 3729 1.1 riastrad 3730 1.1 riastrad /* Disable FEC in DP Sink */ 3731 1.1 riastrad intel_ddi_disable_fec_state(encoder, crtc_state); 3732 1.1 riastrad 3733 1.1 riastrad if (wait) 3734 1.1 riastrad intel_wait_ddi_buf_idle(dev_priv, port); 3735 1.1 riastrad } 3736 1.1 riastrad 3737 1.1 riastrad static void intel_ddi_post_disable_dp(struct intel_encoder *encoder, 3738 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 3739 1.1 riastrad const struct drm_connector_state *old_conn_state) 3740 1.1 riastrad { 3741 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3742 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3743 1.1 riastrad struct intel_dp *intel_dp = &dig_port->dp; 3744 1.1 riastrad bool is_mst = intel_crtc_has_type(old_crtc_state, 3745 1.1 riastrad INTEL_OUTPUT_DP_MST); 3746 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3747 1.1 riastrad 3748 1.1 riastrad /* 3749 1.1 riastrad * Power down sink before disabling the port, otherwise we end 3750 1.1 riastrad * up getting interrupts from the sink on detecting link loss. 3751 1.1 riastrad */ 3752 1.1 riastrad intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 3753 1.1 riastrad 3754 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) { 3755 1.1 riastrad if (is_mst) { 3756 1.1 riastrad enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 3757 1.1 riastrad u32 val; 3758 1.1 riastrad 3759 1.1 riastrad val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); 3760 1.1 riastrad val &= ~TGL_TRANS_DDI_PORT_MASK; 3761 1.1 riastrad I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), val); 3762 1.1 riastrad } 3763 1.1 riastrad } else { 3764 1.1 riastrad if (!is_mst) 3765 1.1 riastrad intel_ddi_disable_pipe_clock(old_crtc_state); 3766 1.1 riastrad } 3767 1.1 riastrad 3768 1.1 riastrad intel_disable_ddi_buf(encoder, old_crtc_state); 3769 1.1 riastrad 3770 1.1 riastrad /* 3771 1.1 riastrad * From TGL spec: "If single stream or multi-stream master transcoder: 3772 1.1 riastrad * Configure Transcoder Clock select to direct no clock to the 3773 1.1 riastrad * transcoder" 3774 1.1 riastrad */ 3775 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 3776 1.1 riastrad intel_ddi_disable_pipe_clock(old_crtc_state); 3777 1.1 riastrad 3778 1.1 riastrad intel_edp_panel_vdd_on(intel_dp); 3779 1.1 riastrad intel_edp_panel_off(intel_dp); 3780 1.1 riastrad 3781 1.1 riastrad if (!intel_phy_is_tc(dev_priv, phy) || 3782 1.1 riastrad dig_port->tc_mode != TC_PORT_TBT_ALT) 3783 1.1 riastrad intel_display_power_put_unchecked(dev_priv, 3784 1.1 riastrad dig_port->ddi_io_power_domain); 3785 1.1 riastrad 3786 1.1 riastrad intel_ddi_clk_disable(encoder); 3787 1.1 riastrad tgl_clear_psr2_transcoder_exitline(old_crtc_state); 3788 1.1 riastrad } 3789 1.1 riastrad 3790 1.1 riastrad static void intel_ddi_post_disable_hdmi(struct intel_encoder *encoder, 3791 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 3792 1.1 riastrad const struct drm_connector_state *old_conn_state) 3793 1.1 riastrad { 3794 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3795 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3796 1.1 riastrad struct intel_hdmi *intel_hdmi = &dig_port->hdmi; 3797 1.1 riastrad 3798 1.1 riastrad dig_port->set_infoframes(encoder, false, 3799 1.1 riastrad old_crtc_state, old_conn_state); 3800 1.1 riastrad 3801 1.1 riastrad intel_ddi_disable_pipe_clock(old_crtc_state); 3802 1.1 riastrad 3803 1.1 riastrad intel_disable_ddi_buf(encoder, old_crtc_state); 3804 1.1 riastrad 3805 1.1 riastrad intel_display_power_put_unchecked(dev_priv, 3806 1.1 riastrad dig_port->ddi_io_power_domain); 3807 1.1 riastrad 3808 1.1 riastrad intel_ddi_clk_disable(encoder); 3809 1.1 riastrad 3810 1.1 riastrad intel_dp_dual_mode_set_tmds_output(intel_hdmi, false); 3811 1.1 riastrad } 3812 1.1 riastrad 3813 1.1 riastrad static void icl_disable_transcoder_port_sync(const struct intel_crtc_state *old_crtc_state) 3814 1.1 riastrad { 3815 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->uapi.crtc); 3816 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3817 1.1 riastrad 3818 1.1 riastrad if (old_crtc_state->master_transcoder == INVALID_TRANSCODER) 3819 1.1 riastrad return; 3820 1.1 riastrad 3821 1.1 riastrad DRM_DEBUG_KMS("Disabling Transcoder Port Sync on Slave Transcoder %s\n", 3822 1.1 riastrad transcoder_name(old_crtc_state->cpu_transcoder)); 3823 1.1 riastrad 3824 1.1 riastrad I915_WRITE(TRANS_DDI_FUNC_CTL2(old_crtc_state->cpu_transcoder), 0); 3825 1.1 riastrad } 3826 1.1 riastrad 3827 1.1 riastrad static void intel_ddi_post_disable(struct intel_encoder *encoder, 3828 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 3829 1.1 riastrad const struct drm_connector_state *old_conn_state) 3830 1.1 riastrad { 3831 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3832 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3833 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3834 1.1 riastrad bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 3835 1.1 riastrad 3836 1.1 riastrad if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) { 3837 1.1 riastrad intel_crtc_vblank_off(old_crtc_state); 3838 1.1 riastrad 3839 1.1 riastrad intel_disable_pipe(old_crtc_state); 3840 1.1 riastrad 3841 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) 3842 1.1 riastrad icl_disable_transcoder_port_sync(old_crtc_state); 3843 1.1 riastrad 3844 1.1 riastrad intel_ddi_disable_transcoder_func(old_crtc_state); 3845 1.1 riastrad 3846 1.1 riastrad intel_dsc_disable(old_crtc_state); 3847 1.1 riastrad 3848 1.1 riastrad if (INTEL_GEN(dev_priv) >= 9) 3849 1.1 riastrad skl_scaler_disable(old_crtc_state); 3850 1.1 riastrad else 3851 1.1 riastrad ilk_pfit_disable(old_crtc_state); 3852 1.1 riastrad } 3853 1.1 riastrad 3854 1.1 riastrad /* 3855 1.1 riastrad * When called from DP MST code: 3856 1.1 riastrad * - old_conn_state will be NULL 3857 1.1 riastrad * - encoder will be the main encoder (ie. mst->primary) 3858 1.1 riastrad * - the main connector associated with this port 3859 1.1 riastrad * won't be active or linked to a crtc 3860 1.1 riastrad * - old_crtc_state will be the state of the last stream to 3861 1.1 riastrad * be deactivated on this port, and it may not be the same 3862 1.1 riastrad * stream that was activated last, but each stream 3863 1.1 riastrad * should have a state that is identical when it comes to 3864 1.1 riastrad * the DP link parameteres 3865 1.1 riastrad */ 3866 1.1 riastrad 3867 1.1 riastrad if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI)) 3868 1.1 riastrad intel_ddi_post_disable_hdmi(encoder, 3869 1.1 riastrad old_crtc_state, old_conn_state); 3870 1.1 riastrad else 3871 1.1 riastrad intel_ddi_post_disable_dp(encoder, 3872 1.1 riastrad old_crtc_state, old_conn_state); 3873 1.1 riastrad 3874 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) 3875 1.1 riastrad icl_unmap_plls_to_ports(encoder); 3876 1.1 riastrad 3877 1.1 riastrad if (intel_crtc_has_dp_encoder(old_crtc_state) || is_tc_port) 3878 1.1 riastrad intel_display_power_put_unchecked(dev_priv, 3879 1.1 riastrad intel_ddi_main_link_aux_domain(dig_port)); 3880 1.1 riastrad 3881 1.1 riastrad if (is_tc_port) 3882 1.1 riastrad intel_tc_port_put_link(dig_port); 3883 1.1 riastrad } 3884 1.1 riastrad 3885 1.1 riastrad void intel_ddi_fdi_post_disable(struct intel_encoder *encoder, 3886 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 3887 1.1 riastrad const struct drm_connector_state *old_conn_state) 3888 1.1 riastrad { 3889 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3890 1.1 riastrad u32 val; 3891 1.1 riastrad 3892 1.1 riastrad /* 3893 1.1 riastrad * Bspec lists this as both step 13 (before DDI_BUF_CTL disable) 3894 1.1 riastrad * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN, 3895 1.1 riastrad * step 13 is the correct place for it. Step 18 is where it was 3896 1.1 riastrad * originally before the BUN. 3897 1.1 riastrad */ 3898 1.1 riastrad val = I915_READ(FDI_RX_CTL(PIPE_A)); 3899 1.1 riastrad val &= ~FDI_RX_ENABLE; 3900 1.1 riastrad I915_WRITE(FDI_RX_CTL(PIPE_A), val); 3901 1.1 riastrad 3902 1.1 riastrad intel_disable_ddi_buf(encoder, old_crtc_state); 3903 1.1 riastrad intel_ddi_clk_disable(encoder); 3904 1.1 riastrad 3905 1.1 riastrad val = I915_READ(FDI_RX_MISC(PIPE_A)); 3906 1.1 riastrad val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 3907 1.1 riastrad val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); 3908 1.1 riastrad I915_WRITE(FDI_RX_MISC(PIPE_A), val); 3909 1.1 riastrad 3910 1.1 riastrad val = I915_READ(FDI_RX_CTL(PIPE_A)); 3911 1.1 riastrad val &= ~FDI_PCDCLK; 3912 1.1 riastrad I915_WRITE(FDI_RX_CTL(PIPE_A), val); 3913 1.1 riastrad 3914 1.1 riastrad val = I915_READ(FDI_RX_CTL(PIPE_A)); 3915 1.1 riastrad val &= ~FDI_RX_PLL_ENABLE; 3916 1.1 riastrad I915_WRITE(FDI_RX_CTL(PIPE_A), val); 3917 1.1 riastrad } 3918 1.1 riastrad 3919 1.1 riastrad static void intel_enable_ddi_dp(struct intel_encoder *encoder, 3920 1.1 riastrad const struct intel_crtc_state *crtc_state, 3921 1.1 riastrad const struct drm_connector_state *conn_state) 3922 1.1 riastrad { 3923 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3924 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3925 1.1 riastrad enum port port = encoder->port; 3926 1.1 riastrad 3927 1.1 riastrad if (port == PORT_A && INTEL_GEN(dev_priv) < 9) 3928 1.1 riastrad intel_dp_stop_link_train(intel_dp); 3929 1.1 riastrad 3930 1.1 riastrad intel_edp_backlight_on(crtc_state, conn_state); 3931 1.1 riastrad intel_psr_enable(intel_dp, crtc_state); 3932 1.1 riastrad intel_dp_vsc_enable(intel_dp, crtc_state, conn_state); 3933 1.1 riastrad intel_dp_hdr_metadata_enable(intel_dp, crtc_state, conn_state); 3934 1.1 riastrad intel_edp_drrs_enable(intel_dp, crtc_state); 3935 1.1 riastrad 3936 1.1 riastrad if (crtc_state->has_audio) 3937 1.1 riastrad intel_audio_codec_enable(encoder, crtc_state, conn_state); 3938 1.1 riastrad } 3939 1.1 riastrad 3940 1.1 riastrad static i915_reg_t 3941 1.1 riastrad gen9_chicken_trans_reg_by_port(struct drm_i915_private *dev_priv, 3942 1.1 riastrad enum port port) 3943 1.1 riastrad { 3944 1.1 riastrad static const enum transcoder trans[] = { 3945 1.1 riastrad [PORT_A] = TRANSCODER_EDP, 3946 1.1 riastrad [PORT_B] = TRANSCODER_A, 3947 1.1 riastrad [PORT_C] = TRANSCODER_B, 3948 1.1 riastrad [PORT_D] = TRANSCODER_C, 3949 1.1 riastrad [PORT_E] = TRANSCODER_A, 3950 1.1 riastrad }; 3951 1.1 riastrad 3952 1.1 riastrad WARN_ON(INTEL_GEN(dev_priv) < 9); 3953 1.1 riastrad 3954 1.1 riastrad if (WARN_ON(port < PORT_A || port > PORT_E)) 3955 1.1 riastrad port = PORT_A; 3956 1.1 riastrad 3957 1.1 riastrad return CHICKEN_TRANS(trans[port]); 3958 1.1 riastrad } 3959 1.1 riastrad 3960 1.1 riastrad static void intel_enable_ddi_hdmi(struct intel_encoder *encoder, 3961 1.1 riastrad const struct intel_crtc_state *crtc_state, 3962 1.1 riastrad const struct drm_connector_state *conn_state) 3963 1.1 riastrad { 3964 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3965 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3966 1.1 riastrad struct drm_connector *connector = conn_state->connector; 3967 1.1 riastrad enum port port = encoder->port; 3968 1.1 riastrad 3969 1.1 riastrad if (!intel_hdmi_handle_sink_scrambling(encoder, connector, 3970 1.1 riastrad crtc_state->hdmi_high_tmds_clock_ratio, 3971 1.1 riastrad crtc_state->hdmi_scrambling)) 3972 1.1 riastrad DRM_ERROR("[CONNECTOR:%d:%s] Failed to configure sink scrambling/TMDS bit clock ratio\n", 3973 1.1 riastrad connector->base.id, connector->name); 3974 1.1 riastrad 3975 1.1 riastrad /* Display WA #1143: skl,kbl,cfl */ 3976 1.1 riastrad if (IS_GEN9_BC(dev_priv)) { 3977 1.1 riastrad /* 3978 1.1 riastrad * For some reason these chicken bits have been 3979 1.1 riastrad * stuffed into a transcoder register, event though 3980 1.1 riastrad * the bits affect a specific DDI port rather than 3981 1.1 riastrad * a specific transcoder. 3982 1.1 riastrad */ 3983 1.1 riastrad i915_reg_t reg = gen9_chicken_trans_reg_by_port(dev_priv, port); 3984 1.1 riastrad u32 val; 3985 1.1 riastrad 3986 1.1 riastrad val = I915_READ(reg); 3987 1.1 riastrad 3988 1.1 riastrad if (port == PORT_E) 3989 1.1 riastrad val |= DDIE_TRAINING_OVERRIDE_ENABLE | 3990 1.1 riastrad DDIE_TRAINING_OVERRIDE_VALUE; 3991 1.1 riastrad else 3992 1.1 riastrad val |= DDI_TRAINING_OVERRIDE_ENABLE | 3993 1.1 riastrad DDI_TRAINING_OVERRIDE_VALUE; 3994 1.1 riastrad 3995 1.1 riastrad I915_WRITE(reg, val); 3996 1.1 riastrad POSTING_READ(reg); 3997 1.1 riastrad 3998 1.1 riastrad udelay(1); 3999 1.1 riastrad 4000 1.1 riastrad if (port == PORT_E) 4001 1.1 riastrad val &= ~(DDIE_TRAINING_OVERRIDE_ENABLE | 4002 1.1 riastrad DDIE_TRAINING_OVERRIDE_VALUE); 4003 1.1 riastrad else 4004 1.1 riastrad val &= ~(DDI_TRAINING_OVERRIDE_ENABLE | 4005 1.1 riastrad DDI_TRAINING_OVERRIDE_VALUE); 4006 1.1 riastrad 4007 1.1 riastrad I915_WRITE(reg, val); 4008 1.1 riastrad } 4009 1.1 riastrad 4010 1.1 riastrad /* In HDMI/DVI mode, the port width, and swing/emphasis values 4011 1.1 riastrad * are ignored so nothing special needs to be done besides 4012 1.1 riastrad * enabling the port. 4013 1.1 riastrad */ 4014 1.1 riastrad I915_WRITE(DDI_BUF_CTL(port), 4015 1.1 riastrad dig_port->saved_port_bits | DDI_BUF_CTL_ENABLE); 4016 1.1 riastrad 4017 1.1 riastrad if (crtc_state->has_audio) 4018 1.1 riastrad intel_audio_codec_enable(encoder, crtc_state, conn_state); 4019 1.1 riastrad } 4020 1.1 riastrad 4021 1.1 riastrad static void intel_enable_ddi(struct intel_encoder *encoder, 4022 1.1 riastrad const struct intel_crtc_state *crtc_state, 4023 1.1 riastrad const struct drm_connector_state *conn_state) 4024 1.1 riastrad { 4025 1.1 riastrad if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) 4026 1.1 riastrad intel_enable_ddi_hdmi(encoder, crtc_state, conn_state); 4027 1.1 riastrad else 4028 1.1 riastrad intel_enable_ddi_dp(encoder, crtc_state, conn_state); 4029 1.1 riastrad 4030 1.1 riastrad /* Enable hdcp if it's desired */ 4031 1.1 riastrad if (conn_state->content_protection == 4032 1.1 riastrad DRM_MODE_CONTENT_PROTECTION_DESIRED) 4033 1.1 riastrad intel_hdcp_enable(to_intel_connector(conn_state->connector), 4034 1.1 riastrad crtc_state->cpu_transcoder, 4035 1.1 riastrad (u8)conn_state->hdcp_content_type); 4036 1.1 riastrad } 4037 1.1 riastrad 4038 1.1 riastrad static void intel_disable_ddi_dp(struct intel_encoder *encoder, 4039 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 4040 1.1 riastrad const struct drm_connector_state *old_conn_state) 4041 1.1 riastrad { 4042 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4043 1.1 riastrad 4044 1.1 riastrad intel_dp->link_trained = false; 4045 1.1 riastrad 4046 1.1 riastrad if (old_crtc_state->has_audio) 4047 1.1 riastrad intel_audio_codec_disable(encoder, 4048 1.1 riastrad old_crtc_state, old_conn_state); 4049 1.1 riastrad 4050 1.1 riastrad intel_edp_drrs_disable(intel_dp, old_crtc_state); 4051 1.1 riastrad intel_psr_disable(intel_dp, old_crtc_state); 4052 1.1 riastrad intel_edp_backlight_off(old_conn_state); 4053 1.1 riastrad /* Disable the decompression in DP Sink */ 4054 1.1 riastrad intel_dp_sink_set_decompression_state(intel_dp, old_crtc_state, 4055 1.1 riastrad false); 4056 1.1 riastrad } 4057 1.1 riastrad 4058 1.1 riastrad static void intel_disable_ddi_hdmi(struct intel_encoder *encoder, 4059 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 4060 1.1 riastrad const struct drm_connector_state *old_conn_state) 4061 1.1 riastrad { 4062 1.1 riastrad struct drm_connector *connector = old_conn_state->connector; 4063 1.1 riastrad 4064 1.1 riastrad if (old_crtc_state->has_audio) 4065 1.1 riastrad intel_audio_codec_disable(encoder, 4066 1.1 riastrad old_crtc_state, old_conn_state); 4067 1.1 riastrad 4068 1.1 riastrad if (!intel_hdmi_handle_sink_scrambling(encoder, connector, 4069 1.1 riastrad false, false)) 4070 1.1 riastrad DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Failed to reset sink scrambling/TMDS bit clock ratio\n", 4071 1.1 riastrad connector->base.id, connector->name); 4072 1.1 riastrad } 4073 1.1 riastrad 4074 1.1 riastrad static void intel_disable_ddi(struct intel_encoder *encoder, 4075 1.1 riastrad const struct intel_crtc_state *old_crtc_state, 4076 1.1 riastrad const struct drm_connector_state *old_conn_state) 4077 1.1 riastrad { 4078 1.1 riastrad intel_hdcp_disable(to_intel_connector(old_conn_state->connector)); 4079 1.1 riastrad 4080 1.1 riastrad if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI)) 4081 1.1 riastrad intel_disable_ddi_hdmi(encoder, old_crtc_state, old_conn_state); 4082 1.1 riastrad else 4083 1.1 riastrad intel_disable_ddi_dp(encoder, old_crtc_state, old_conn_state); 4084 1.1 riastrad } 4085 1.1 riastrad 4086 1.1 riastrad static void intel_ddi_update_pipe_dp(struct intel_encoder *encoder, 4087 1.1 riastrad const struct intel_crtc_state *crtc_state, 4088 1.1 riastrad const struct drm_connector_state *conn_state) 4089 1.1 riastrad { 4090 1.1 riastrad struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4091 1.1 riastrad 4092 1.1 riastrad intel_ddi_set_dp_msa(crtc_state, conn_state); 4093 1.1 riastrad 4094 1.1 riastrad intel_psr_update(intel_dp, crtc_state); 4095 1.1 riastrad intel_edp_drrs_enable(intel_dp, crtc_state); 4096 1.1 riastrad 4097 1.1 riastrad intel_panel_update_backlight(encoder, crtc_state, conn_state); 4098 1.1 riastrad } 4099 1.1 riastrad 4100 1.1 riastrad static void intel_ddi_update_pipe(struct intel_encoder *encoder, 4101 1.1 riastrad const struct intel_crtc_state *crtc_state, 4102 1.1 riastrad const struct drm_connector_state *conn_state) 4103 1.1 riastrad { 4104 1.1 riastrad struct intel_connector *connector = 4105 1.1 riastrad to_intel_connector(conn_state->connector); 4106 1.1 riastrad struct intel_hdcp *hdcp = &connector->hdcp; 4107 1.1 riastrad bool content_protection_type_changed = 4108 1.1 riastrad (conn_state->hdcp_content_type != hdcp->content_type && 4109 1.1 riastrad conn_state->content_protection != 4110 1.1 riastrad DRM_MODE_CONTENT_PROTECTION_UNDESIRED); 4111 1.1 riastrad 4112 1.1 riastrad if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) 4113 1.1 riastrad intel_ddi_update_pipe_dp(encoder, crtc_state, conn_state); 4114 1.1 riastrad 4115 1.1 riastrad /* 4116 1.1 riastrad * During the HDCP encryption session if Type change is requested, 4117 1.1 riastrad * disable the HDCP and reenable it with new TYPE value. 4118 1.1 riastrad */ 4119 1.1 riastrad if (conn_state->content_protection == 4120 1.1 riastrad DRM_MODE_CONTENT_PROTECTION_UNDESIRED || 4121 1.1 riastrad content_protection_type_changed) 4122 1.1 riastrad intel_hdcp_disable(connector); 4123 1.1 riastrad 4124 1.1 riastrad /* 4125 1.1 riastrad * Mark the hdcp state as DESIRED after the hdcp disable of type 4126 1.1 riastrad * change procedure. 4127 1.1 riastrad */ 4128 1.1 riastrad if (content_protection_type_changed) { 4129 1.1 riastrad mutex_lock(&hdcp->mutex); 4130 1.1 riastrad hdcp->value = DRM_MODE_CONTENT_PROTECTION_DESIRED; 4131 1.1 riastrad schedule_work(&hdcp->prop_work); 4132 1.1 riastrad mutex_unlock(&hdcp->mutex); 4133 1.1 riastrad } 4134 1.1 riastrad 4135 1.1 riastrad if (conn_state->content_protection == 4136 1.1 riastrad DRM_MODE_CONTENT_PROTECTION_DESIRED || 4137 1.1 riastrad content_protection_type_changed) 4138 1.1 riastrad intel_hdcp_enable(connector, 4139 1.1 riastrad crtc_state->cpu_transcoder, 4140 1.1 riastrad (u8)conn_state->hdcp_content_type); 4141 1.1 riastrad } 4142 1.1 riastrad 4143 1.1 riastrad static void 4144 1.1 riastrad intel_ddi_update_prepare(struct intel_atomic_state *state, 4145 1.1 riastrad struct intel_encoder *encoder, 4146 1.1 riastrad struct intel_crtc *crtc) 4147 1.1 riastrad { 4148 1.1 riastrad struct intel_crtc_state *crtc_state = 4149 1.1 riastrad crtc ? intel_atomic_get_new_crtc_state(state, crtc) : NULL; 4150 1.1 riastrad int required_lanes = crtc_state ? crtc_state->lane_count : 1; 4151 1.1 riastrad 4152 1.1 riastrad WARN_ON(crtc && crtc->active); 4153 1.1 riastrad 4154 1.1 riastrad intel_tc_port_get_link(enc_to_dig_port(encoder), 4155 1.1 riastrad required_lanes); 4156 1.1 riastrad if (crtc_state && crtc_state->hw.active) 4157 1.1 riastrad intel_update_active_dpll(state, crtc, encoder); 4158 1.1 riastrad } 4159 1.1 riastrad 4160 1.1 riastrad static void 4161 1.1 riastrad intel_ddi_update_complete(struct intel_atomic_state *state, 4162 1.1 riastrad struct intel_encoder *encoder, 4163 1.1 riastrad struct intel_crtc *crtc) 4164 1.1 riastrad { 4165 1.1 riastrad intel_tc_port_put_link(enc_to_dig_port(encoder)); 4166 1.1 riastrad } 4167 1.1 riastrad 4168 1.1 riastrad static void 4169 1.1 riastrad intel_ddi_pre_pll_enable(struct intel_encoder *encoder, 4170 1.1 riastrad const struct intel_crtc_state *crtc_state, 4171 1.1 riastrad const struct drm_connector_state *conn_state) 4172 1.1 riastrad { 4173 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4174 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4175 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 4176 1.1 riastrad bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 4177 1.1 riastrad 4178 1.1 riastrad if (is_tc_port) 4179 1.1 riastrad intel_tc_port_get_link(dig_port, crtc_state->lane_count); 4180 1.1 riastrad 4181 1.1 riastrad if (intel_crtc_has_dp_encoder(crtc_state) || is_tc_port) 4182 1.1 riastrad intel_display_power_get(dev_priv, 4183 1.1 riastrad intel_ddi_main_link_aux_domain(dig_port)); 4184 1.1 riastrad 4185 1.1 riastrad if (is_tc_port && dig_port->tc_mode != TC_PORT_TBT_ALT) 4186 1.1 riastrad /* 4187 1.1 riastrad * Program the lane count for static/dynamic connections on 4188 1.1 riastrad * Type-C ports. Skip this step for TBT. 4189 1.1 riastrad */ 4190 1.1 riastrad intel_tc_port_set_fia_lane_count(dig_port, crtc_state->lane_count); 4191 1.1 riastrad else if (IS_GEN9_LP(dev_priv)) 4192 1.1 riastrad bxt_ddi_phy_set_lane_optim_mask(encoder, 4193 1.1 riastrad crtc_state->lane_lat_optim_mask); 4194 1.1 riastrad } 4195 1.1 riastrad 4196 1.1 riastrad static void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp) 4197 1.1 riastrad { 4198 1.1 riastrad struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp); 4199 1.1 riastrad struct drm_i915_private *dev_priv = 4200 1.1 riastrad to_i915(intel_dig_port->base.base.dev); 4201 1.1 riastrad enum port port = intel_dig_port->base.port; 4202 1.1 riastrad u32 dp_tp_ctl, ddi_buf_ctl; 4203 1.1 riastrad bool wait = false; 4204 1.1 riastrad 4205 1.1 riastrad dp_tp_ctl = I915_READ(intel_dp->regs.dp_tp_ctl); 4206 1.1 riastrad 4207 1.1 riastrad if (dp_tp_ctl & DP_TP_CTL_ENABLE) { 4208 1.1 riastrad ddi_buf_ctl = I915_READ(DDI_BUF_CTL(port)); 4209 1.1 riastrad if (ddi_buf_ctl & DDI_BUF_CTL_ENABLE) { 4210 1.1 riastrad I915_WRITE(DDI_BUF_CTL(port), 4211 1.1 riastrad ddi_buf_ctl & ~DDI_BUF_CTL_ENABLE); 4212 1.1 riastrad wait = true; 4213 1.1 riastrad } 4214 1.1 riastrad 4215 1.1 riastrad dp_tp_ctl &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 4216 1.1 riastrad dp_tp_ctl |= DP_TP_CTL_LINK_TRAIN_PAT1; 4217 1.1 riastrad I915_WRITE(intel_dp->regs.dp_tp_ctl, dp_tp_ctl); 4218 1.1 riastrad POSTING_READ(intel_dp->regs.dp_tp_ctl); 4219 1.1 riastrad 4220 1.1 riastrad if (wait) 4221 1.1 riastrad intel_wait_ddi_buf_idle(dev_priv, port); 4222 1.1 riastrad } 4223 1.1 riastrad 4224 1.1 riastrad dp_tp_ctl = DP_TP_CTL_ENABLE | 4225 1.1 riastrad DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE; 4226 1.1 riastrad if (intel_dp->link_mst) 4227 1.1 riastrad dp_tp_ctl |= DP_TP_CTL_MODE_MST; 4228 1.1 riastrad else { 4229 1.1 riastrad dp_tp_ctl |= DP_TP_CTL_MODE_SST; 4230 1.1 riastrad if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) 4231 1.1 riastrad dp_tp_ctl |= DP_TP_CTL_ENHANCED_FRAME_ENABLE; 4232 1.1 riastrad } 4233 1.1 riastrad I915_WRITE(intel_dp->regs.dp_tp_ctl, dp_tp_ctl); 4234 1.1 riastrad POSTING_READ(intel_dp->regs.dp_tp_ctl); 4235 1.1 riastrad 4236 1.1 riastrad intel_dp->DP |= DDI_BUF_CTL_ENABLE; 4237 1.1 riastrad I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP); 4238 1.1 riastrad POSTING_READ(DDI_BUF_CTL(port)); 4239 1.1 riastrad 4240 1.1 riastrad udelay(600); 4241 1.1 riastrad } 4242 1.1 riastrad 4243 1.1 riastrad static bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv, 4244 1.1 riastrad enum transcoder cpu_transcoder) 4245 1.1 riastrad { 4246 1.1 riastrad if (cpu_transcoder == TRANSCODER_EDP) 4247 1.1 riastrad return false; 4248 1.1 riastrad 4249 1.1 riastrad if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) 4250 1.1 riastrad return false; 4251 1.1 riastrad 4252 1.1 riastrad return I915_READ(HSW_AUD_PIN_ELD_CP_VLD) & 4253 1.1 riastrad AUDIO_OUTPUT_ENABLE(cpu_transcoder); 4254 1.1 riastrad } 4255 1.1 riastrad 4256 1.1 riastrad void intel_ddi_compute_min_voltage_level(struct drm_i915_private *dev_priv, 4257 1.1 riastrad struct intel_crtc_state *crtc_state) 4258 1.1 riastrad { 4259 1.1 riastrad if (IS_ELKHARTLAKE(dev_priv) && crtc_state->port_clock > 594000) 4260 1.1 riastrad crtc_state->min_voltage_level = 3; 4261 1.1 riastrad else if (INTEL_GEN(dev_priv) >= 11 && crtc_state->port_clock > 594000) 4262 1.1 riastrad crtc_state->min_voltage_level = 1; 4263 1.1 riastrad else if (IS_CANNONLAKE(dev_priv) && crtc_state->port_clock > 594000) 4264 1.1 riastrad crtc_state->min_voltage_level = 2; 4265 1.1 riastrad } 4266 1.1 riastrad 4267 1.1 riastrad void intel_ddi_get_config(struct intel_encoder *encoder, 4268 1.1 riastrad struct intel_crtc_state *pipe_config) 4269 1.1 riastrad { 4270 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4271 1.1 riastrad struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 4272 1.1 riastrad enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; 4273 1.1 riastrad u32 temp, flags = 0; 4274 1.1 riastrad 4275 1.1 riastrad /* XXX: DSI transcoder paranoia */ 4276 1.1 riastrad if (WARN_ON(transcoder_is_dsi(cpu_transcoder))) 4277 1.1 riastrad return; 4278 1.1 riastrad 4279 1.1 riastrad intel_dsc_get_config(encoder, pipe_config); 4280 1.1 riastrad 4281 1.1 riastrad temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); 4282 1.1 riastrad if (temp & TRANS_DDI_PHSYNC) 4283 1.1 riastrad flags |= DRM_MODE_FLAG_PHSYNC; 4284 1.1 riastrad else 4285 1.1 riastrad flags |= DRM_MODE_FLAG_NHSYNC; 4286 1.1 riastrad if (temp & TRANS_DDI_PVSYNC) 4287 1.1 riastrad flags |= DRM_MODE_FLAG_PVSYNC; 4288 1.1 riastrad else 4289 1.1 riastrad flags |= DRM_MODE_FLAG_NVSYNC; 4290 1.1 riastrad 4291 1.1 riastrad pipe_config->hw.adjusted_mode.flags |= flags; 4292 1.1 riastrad 4293 1.1 riastrad switch (temp & TRANS_DDI_BPC_MASK) { 4294 1.1 riastrad case TRANS_DDI_BPC_6: 4295 1.1 riastrad pipe_config->pipe_bpp = 18; 4296 1.1 riastrad break; 4297 1.1 riastrad case TRANS_DDI_BPC_8: 4298 1.1 riastrad pipe_config->pipe_bpp = 24; 4299 1.1 riastrad break; 4300 1.1 riastrad case TRANS_DDI_BPC_10: 4301 1.1 riastrad pipe_config->pipe_bpp = 30; 4302 1.1 riastrad break; 4303 1.1 riastrad case TRANS_DDI_BPC_12: 4304 1.1 riastrad pipe_config->pipe_bpp = 36; 4305 1.1 riastrad break; 4306 1.1 riastrad default: 4307 1.1 riastrad break; 4308 1.1 riastrad } 4309 1.1 riastrad 4310 1.1 riastrad switch (temp & TRANS_DDI_MODE_SELECT_MASK) { 4311 1.1 riastrad case TRANS_DDI_MODE_SELECT_HDMI: 4312 1.1 riastrad pipe_config->has_hdmi_sink = true; 4313 1.1 riastrad 4314 1.1 riastrad pipe_config->infoframes.enable |= 4315 1.1 riastrad intel_hdmi_infoframes_enabled(encoder, pipe_config); 4316 1.1 riastrad 4317 1.1 riastrad if (pipe_config->infoframes.enable) 4318 1.1 riastrad pipe_config->has_infoframe = true; 4319 1.1 riastrad 4320 1.1 riastrad if (temp & TRANS_DDI_HDMI_SCRAMBLING) 4321 1.1 riastrad pipe_config->hdmi_scrambling = true; 4322 1.1 riastrad if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE) 4323 1.1 riastrad pipe_config->hdmi_high_tmds_clock_ratio = true; 4324 1.1 riastrad /* fall through */ 4325 1.1 riastrad case TRANS_DDI_MODE_SELECT_DVI: 4326 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI); 4327 1.1 riastrad pipe_config->lane_count = 4; 4328 1.1 riastrad break; 4329 1.1 riastrad case TRANS_DDI_MODE_SELECT_FDI: 4330 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG); 4331 1.1 riastrad break; 4332 1.1 riastrad case TRANS_DDI_MODE_SELECT_DP_SST: 4333 1.1 riastrad if (encoder->type == INTEL_OUTPUT_EDP) 4334 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP); 4335 1.1 riastrad else 4336 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_DP); 4337 1.1 riastrad pipe_config->lane_count = 4338 1.1 riastrad ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; 4339 1.1 riastrad intel_dp_get_m_n(intel_crtc, pipe_config); 4340 1.1 riastrad 4341 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) { 4342 1.1 riastrad i915_reg_t dp_tp_ctl; 4343 1.1 riastrad 4344 1.1 riastrad if (IS_GEN(dev_priv, 11)) 4345 1.1 riastrad dp_tp_ctl = DP_TP_CTL(encoder->port); 4346 1.1 riastrad else 4347 1.1 riastrad dp_tp_ctl = TGL_DP_TP_CTL(pipe_config->cpu_transcoder); 4348 1.1 riastrad 4349 1.1 riastrad pipe_config->fec_enable = 4350 1.1 riastrad I915_READ(dp_tp_ctl) & DP_TP_CTL_FEC_ENABLE; 4351 1.1 riastrad 4352 1.1 riastrad DRM_DEBUG_KMS("[ENCODER:%d:%s] Fec status: %u\n", 4353 1.1 riastrad encoder->base.base.id, encoder->base.name, 4354 1.1 riastrad pipe_config->fec_enable); 4355 1.1 riastrad } 4356 1.1 riastrad 4357 1.1 riastrad break; 4358 1.1 riastrad case TRANS_DDI_MODE_SELECT_DP_MST: 4359 1.1 riastrad pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST); 4360 1.1 riastrad pipe_config->lane_count = 4361 1.1 riastrad ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; 4362 1.1 riastrad 4363 1.1 riastrad if (INTEL_GEN(dev_priv) >= 12) 4364 1.1 riastrad pipe_config->mst_master_transcoder = 4365 1.1 riastrad REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK, temp); 4366 1.1 riastrad 4367 1.1 riastrad intel_dp_get_m_n(intel_crtc, pipe_config); 4368 1.1 riastrad break; 4369 1.1 riastrad default: 4370 1.1 riastrad break; 4371 1.1 riastrad } 4372 1.1 riastrad 4373 1.1 riastrad if (encoder->type == INTEL_OUTPUT_EDP) 4374 1.1 riastrad tgl_dc3co_exitline_get_config(pipe_config); 4375 1.1 riastrad 4376 1.1 riastrad pipe_config->has_audio = 4377 1.1 riastrad intel_ddi_is_audio_enabled(dev_priv, cpu_transcoder); 4378 1.1 riastrad 4379 1.1 riastrad if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp && 4380 1.1 riastrad pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { 4381 1.1 riastrad /* 4382 1.1 riastrad * This is a big fat ugly hack. 4383 1.1 riastrad * 4384 1.1 riastrad * Some machines in UEFI boot mode provide us a VBT that has 18 4385 1.1 riastrad * bpp and 1.62 GHz link bandwidth for eDP, which for reasons 4386 1.1 riastrad * unknown we fail to light up. Yet the same BIOS boots up with 4387 1.1 riastrad * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as 4388 1.1 riastrad * max, not what it tells us to use. 4389 1.1 riastrad * 4390 1.1 riastrad * Note: This will still be broken if the eDP panel is not lit 4391 1.1 riastrad * up by the BIOS, and thus we can't get the mode at module 4392 1.1 riastrad * load. 4393 1.1 riastrad */ 4394 1.1 riastrad DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", 4395 1.1 riastrad pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); 4396 1.1 riastrad dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; 4397 1.1 riastrad } 4398 1.1 riastrad 4399 1.1 riastrad intel_ddi_clock_get(encoder, pipe_config); 4400 1.1 riastrad 4401 1.1 riastrad if (IS_GEN9_LP(dev_priv)) 4402 1.1 riastrad pipe_config->lane_lat_optim_mask = 4403 1.1 riastrad bxt_ddi_phy_get_lane_lat_optim_mask(encoder); 4404 1.1 riastrad 4405 1.1 riastrad intel_ddi_compute_min_voltage_level(dev_priv, pipe_config); 4406 1.1 riastrad 4407 1.1 riastrad intel_hdmi_read_gcp_infoframe(encoder, pipe_config); 4408 1.1 riastrad 4409 1.1 riastrad intel_read_infoframe(encoder, pipe_config, 4410 1.1 riastrad HDMI_INFOFRAME_TYPE_AVI, 4411 1.1 riastrad &pipe_config->infoframes.avi); 4412 1.1 riastrad intel_read_infoframe(encoder, pipe_config, 4413 1.1 riastrad HDMI_INFOFRAME_TYPE_SPD, 4414 1.1 riastrad &pipe_config->infoframes.spd); 4415 1.1 riastrad intel_read_infoframe(encoder, pipe_config, 4416 1.1 riastrad HDMI_INFOFRAME_TYPE_VENDOR, 4417 1.1 riastrad &pipe_config->infoframes.hdmi); 4418 1.1 riastrad intel_read_infoframe(encoder, pipe_config, 4419 1.1 riastrad HDMI_INFOFRAME_TYPE_DRM, 4420 1.1 riastrad &pipe_config->infoframes.drm); 4421 1.1 riastrad } 4422 1.1 riastrad 4423 1.1 riastrad static enum intel_output_type 4424 1.1 riastrad intel_ddi_compute_output_type(struct intel_encoder *encoder, 4425 1.1 riastrad struct intel_crtc_state *crtc_state, 4426 1.1 riastrad struct drm_connector_state *conn_state) 4427 1.1 riastrad { 4428 1.1 riastrad switch (conn_state->connector->connector_type) { 4429 1.1 riastrad case DRM_MODE_CONNECTOR_HDMIA: 4430 1.1 riastrad return INTEL_OUTPUT_HDMI; 4431 1.1 riastrad case DRM_MODE_CONNECTOR_eDP: 4432 1.1 riastrad return INTEL_OUTPUT_EDP; 4433 1.1 riastrad case DRM_MODE_CONNECTOR_DisplayPort: 4434 1.1 riastrad return INTEL_OUTPUT_DP; 4435 1.1 riastrad default: 4436 1.1 riastrad MISSING_CASE(conn_state->connector->connector_type); 4437 1.1 riastrad return INTEL_OUTPUT_UNUSED; 4438 1.1 riastrad } 4439 1.1 riastrad } 4440 1.1 riastrad 4441 1.1 riastrad static int intel_ddi_compute_config(struct intel_encoder *encoder, 4442 1.1 riastrad struct intel_crtc_state *pipe_config, 4443 1.1 riastrad struct drm_connector_state *conn_state) 4444 1.1 riastrad { 4445 1.1 riastrad struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 4446 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4447 1.1 riastrad enum port port = encoder->port; 4448 1.1 riastrad int ret; 4449 1.1 riastrad 4450 1.1 riastrad if (HAS_TRANSCODER_EDP(dev_priv) && port == PORT_A) 4451 1.1 riastrad pipe_config->cpu_transcoder = TRANSCODER_EDP; 4452 1.1 riastrad 4453 1.1 riastrad if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) { 4454 1.1 riastrad ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state); 4455 1.1 riastrad } else { 4456 1.1 riastrad ret = intel_dp_compute_config(encoder, pipe_config, conn_state); 4457 1.1 riastrad tgl_dc3co_exitline_compute_config(encoder, pipe_config); 4458 1.1 riastrad } 4459 1.1 riastrad 4460 1.1 riastrad if (ret) 4461 1.1 riastrad return ret; 4462 1.1 riastrad 4463 1.1 riastrad if (IS_HASWELL(dev_priv) && crtc->pipe == PIPE_A && 4464 1.1 riastrad pipe_config->cpu_transcoder == TRANSCODER_EDP) 4465 1.1 riastrad pipe_config->pch_pfit.force_thru = 4466 1.1 riastrad pipe_config->pch_pfit.enabled || 4467 1.1 riastrad pipe_config->crc_enabled; 4468 1.1 riastrad 4469 1.1 riastrad if (IS_GEN9_LP(dev_priv)) 4470 1.1 riastrad pipe_config->lane_lat_optim_mask = 4471 1.1 riastrad bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count); 4472 1.1 riastrad 4473 1.1 riastrad intel_ddi_compute_min_voltage_level(dev_priv, pipe_config); 4474 1.1 riastrad 4475 1.1 riastrad return 0; 4476 1.1 riastrad } 4477 1.1 riastrad 4478 1.1 riastrad static void intel_ddi_encoder_destroy(struct drm_encoder *encoder) 4479 1.1 riastrad { 4480 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder)); 4481 1.1 riastrad 4482 1.1 riastrad intel_dp_encoder_flush_work(encoder); 4483 1.1 riastrad 4484 1.1 riastrad drm_encoder_cleanup(encoder); 4485 1.1 riastrad kfree(dig_port); 4486 1.1 riastrad } 4487 1.1 riastrad 4488 1.1 riastrad static const struct drm_encoder_funcs intel_ddi_funcs = { 4489 1.1 riastrad .reset = intel_dp_encoder_reset, 4490 1.1 riastrad .destroy = intel_ddi_encoder_destroy, 4491 1.1 riastrad }; 4492 1.1 riastrad 4493 1.1 riastrad static struct intel_connector * 4494 1.1 riastrad intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port) 4495 1.1 riastrad { 4496 1.1 riastrad struct intel_connector *connector; 4497 1.1 riastrad enum port port = intel_dig_port->base.port; 4498 1.1 riastrad 4499 1.1 riastrad connector = intel_connector_alloc(); 4500 1.1 riastrad if (!connector) 4501 1.1 riastrad return NULL; 4502 1.1 riastrad 4503 1.1 riastrad intel_dig_port->dp.output_reg = DDI_BUF_CTL(port); 4504 1.1 riastrad intel_dig_port->dp.prepare_link_retrain = 4505 1.1 riastrad intel_ddi_prepare_link_retrain; 4506 1.1 riastrad 4507 1.1 riastrad if (!intel_dp_init_connector(intel_dig_port, connector)) { 4508 1.1 riastrad kfree(connector); 4509 1.1 riastrad return NULL; 4510 1.1 riastrad } 4511 1.1 riastrad 4512 1.1 riastrad return connector; 4513 1.1 riastrad } 4514 1.1 riastrad 4515 1.1 riastrad static int modeset_pipe(struct drm_crtc *crtc, 4516 1.1 riastrad struct drm_modeset_acquire_ctx *ctx) 4517 1.1 riastrad { 4518 1.1 riastrad struct drm_atomic_state *state; 4519 1.1 riastrad struct drm_crtc_state *crtc_state; 4520 1.1 riastrad int ret; 4521 1.1 riastrad 4522 1.1 riastrad state = drm_atomic_state_alloc(crtc->dev); 4523 1.1 riastrad if (!state) 4524 1.1 riastrad return -ENOMEM; 4525 1.1 riastrad 4526 1.1 riastrad state->acquire_ctx = ctx; 4527 1.1 riastrad 4528 1.1 riastrad crtc_state = drm_atomic_get_crtc_state(state, crtc); 4529 1.1 riastrad if (IS_ERR(crtc_state)) { 4530 1.1 riastrad ret = PTR_ERR(crtc_state); 4531 1.1 riastrad goto out; 4532 1.1 riastrad } 4533 1.1 riastrad 4534 1.1 riastrad crtc_state->connectors_changed = true; 4535 1.1 riastrad 4536 1.1 riastrad ret = drm_atomic_commit(state); 4537 1.1 riastrad out: 4538 1.1 riastrad drm_atomic_state_put(state); 4539 1.1 riastrad 4540 1.1 riastrad return ret; 4541 1.1 riastrad } 4542 1.1 riastrad 4543 1.1 riastrad static int intel_hdmi_reset_link(struct intel_encoder *encoder, 4544 1.1 riastrad struct drm_modeset_acquire_ctx *ctx) 4545 1.1 riastrad { 4546 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4547 1.1 riastrad struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder); 4548 1.1 riastrad struct intel_connector *connector = hdmi->attached_connector; 4549 1.1 riastrad struct i2c_adapter *adapter = 4550 1.1 riastrad intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus); 4551 1.1 riastrad struct drm_connector_state *conn_state; 4552 1.1 riastrad struct intel_crtc_state *crtc_state; 4553 1.1 riastrad struct intel_crtc *crtc; 4554 1.1 riastrad u8 config; 4555 1.1 riastrad int ret; 4556 1.1 riastrad 4557 1.1 riastrad if (!connector || connector->base.status != connector_status_connected) 4558 1.1 riastrad return 0; 4559 1.1 riastrad 4560 1.1 riastrad ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, 4561 1.1 riastrad ctx); 4562 1.1 riastrad if (ret) 4563 1.1 riastrad return ret; 4564 1.1 riastrad 4565 1.1 riastrad conn_state = connector->base.state; 4566 1.1 riastrad 4567 1.1 riastrad crtc = to_intel_crtc(conn_state->crtc); 4568 1.1 riastrad if (!crtc) 4569 1.1 riastrad return 0; 4570 1.1 riastrad 4571 1.1 riastrad ret = drm_modeset_lock(&crtc->base.mutex, ctx); 4572 1.1 riastrad if (ret) 4573 1.1 riastrad return ret; 4574 1.1 riastrad 4575 1.1 riastrad crtc_state = to_intel_crtc_state(crtc->base.state); 4576 1.1 riastrad 4577 1.1 riastrad WARN_ON(!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)); 4578 1.1 riastrad 4579 1.1 riastrad if (!crtc_state->hw.active) 4580 1.1 riastrad return 0; 4581 1.1 riastrad 4582 1.1 riastrad if (!crtc_state->hdmi_high_tmds_clock_ratio && 4583 1.1 riastrad !crtc_state->hdmi_scrambling) 4584 1.1 riastrad return 0; 4585 1.1 riastrad 4586 1.1 riastrad if (conn_state->commit && 4587 1.1 riastrad !try_wait_for_completion(&conn_state->commit->hw_done)) 4588 1.1 riastrad return 0; 4589 1.1 riastrad 4590 1.1 riastrad ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config); 4591 1.1 riastrad if (ret < 0) { 4592 1.1 riastrad DRM_ERROR("Failed to read TMDS config: %d\n", ret); 4593 1.1 riastrad return 0; 4594 1.1 riastrad } 4595 1.1 riastrad 4596 1.1 riastrad if (!!(config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) == 4597 1.1 riastrad crtc_state->hdmi_high_tmds_clock_ratio && 4598 1.1 riastrad !!(config & SCDC_SCRAMBLING_ENABLE) == 4599 1.1 riastrad crtc_state->hdmi_scrambling) 4600 1.1 riastrad return 0; 4601 1.1 riastrad 4602 1.1 riastrad /* 4603 1.1 riastrad * HDMI 2.0 says that one should not send scrambled data 4604 1.1 riastrad * prior to configuring the sink scrambling, and that 4605 1.1 riastrad * TMDS clock/data transmission should be suspended when 4606 1.1 riastrad * changing the TMDS clock rate in the sink. So let's 4607 1.1 riastrad * just do a full modeset here, even though some sinks 4608 1.1 riastrad * would be perfectly happy if were to just reconfigure 4609 1.1 riastrad * the SCDC settings on the fly. 4610 1.1 riastrad */ 4611 1.1 riastrad return modeset_pipe(&crtc->base, ctx); 4612 1.1 riastrad } 4613 1.1 riastrad 4614 1.1 riastrad static enum intel_hotplug_state 4615 1.1 riastrad intel_ddi_hotplug(struct intel_encoder *encoder, 4616 1.1 riastrad struct intel_connector *connector, 4617 1.1 riastrad bool irq_received) 4618 1.1 riastrad { 4619 1.1 riastrad struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4620 1.1 riastrad struct drm_modeset_acquire_ctx ctx; 4621 1.1 riastrad enum intel_hotplug_state state; 4622 1.1 riastrad int ret; 4623 1.1 riastrad 4624 1.1 riastrad state = intel_encoder_hotplug(encoder, connector, irq_received); 4625 1.1 riastrad 4626 1.1 riastrad drm_modeset_acquire_init(&ctx, 0); 4627 1.1 riastrad 4628 1.1 riastrad for (;;) { 4629 1.1 riastrad if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) 4630 1.1 riastrad ret = intel_hdmi_reset_link(encoder, &ctx); 4631 1.1 riastrad else 4632 1.1 riastrad ret = intel_dp_retrain_link(encoder, &ctx); 4633 1.1 riastrad 4634 1.1 riastrad if (ret == -EDEADLK) { 4635 1.1 riastrad drm_modeset_backoff(&ctx); 4636 1.1 riastrad continue; 4637 1.1 riastrad } 4638 1.1 riastrad 4639 1.1 riastrad break; 4640 1.1 riastrad } 4641 1.1 riastrad 4642 1.1 riastrad drm_modeset_drop_locks(&ctx); 4643 1.1 riastrad drm_modeset_acquire_fini(&ctx); 4644 1.1 riastrad WARN(ret, "Acquiring modeset locks failed with %i\n", ret); 4645 1.1 riastrad 4646 1.1 riastrad /* 4647 1.1 riastrad * Unpowered type-c dongles can take some time to boot and be 4648 1.1 riastrad * responsible, so here giving some time to those dongles to power up 4649 1.1 riastrad * and then retrying the probe. 4650 1.1 riastrad * 4651 1.1 riastrad * On many platforms the HDMI live state signal is known to be 4652 1.1 riastrad * unreliable, so we can't use it to detect if a sink is connected or 4653 1.1 riastrad * not. Instead we detect if it's connected based on whether we can 4654 1.1 riastrad * read the EDID or not. That in turn has a problem during disconnect, 4655 1.1 riastrad * since the HPD interrupt may be raised before the DDC lines get 4656 1.1 riastrad * disconnected (due to how the required length of DDC vs. HPD 4657 1.1 riastrad * connector pins are specified) and so we'll still be able to get a 4658 1.1 riastrad * valid EDID. To solve this schedule another detection cycle if this 4659 1.1 riastrad * time around we didn't detect any change in the sink's connection 4660 1.1 riastrad * status. 4661 1.1 riastrad */ 4662 1.1 riastrad if (state == INTEL_HOTPLUG_UNCHANGED && irq_received && 4663 1.1 riastrad !dig_port->dp.is_mst) 4664 1.1 riastrad state = INTEL_HOTPLUG_RETRY; 4665 1.1 riastrad 4666 1.1 riastrad return state; 4667 1.1 riastrad } 4668 1.1 riastrad 4669 1.1 riastrad static struct intel_connector * 4670 1.1 riastrad intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port) 4671 1.1 riastrad { 4672 1.1 riastrad struct intel_connector *connector; 4673 1.1 riastrad enum port port = intel_dig_port->base.port; 4674 1.1 riastrad 4675 1.1 riastrad connector = intel_connector_alloc(); 4676 1.1 riastrad if (!connector) 4677 1.1 riastrad return NULL; 4678 1.1 riastrad 4679 1.1 riastrad intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port); 4680 1.1 riastrad intel_hdmi_init_connector(intel_dig_port, connector); 4681 1.1 riastrad 4682 1.1 riastrad return connector; 4683 1.1 riastrad } 4684 1.1 riastrad 4685 1.1 riastrad static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dport) 4686 1.1 riastrad { 4687 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev); 4688 1.1 riastrad 4689 1.1 riastrad if (dport->base.port != PORT_A) 4690 1.1 riastrad return false; 4691 1.1 riastrad 4692 1.1 riastrad if (dport->saved_port_bits & DDI_A_4_LANES) 4693 1.1 riastrad return false; 4694 1.1 riastrad 4695 1.1 riastrad /* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only 4696 1.1 riastrad * supported configuration 4697 1.1 riastrad */ 4698 1.1 riastrad if (IS_GEN9_LP(dev_priv)) 4699 1.1 riastrad return true; 4700 1.1 riastrad 4701 1.1 riastrad /* Cannonlake: Most of SKUs don't support DDI_E, and the only 4702 1.1 riastrad * one who does also have a full A/E split called 4703 1.1 riastrad * DDI_F what makes DDI_E useless. However for this 4704 1.1 riastrad * case let's trust VBT info. 4705 1.1 riastrad */ 4706 1.1 riastrad if (IS_CANNONLAKE(dev_priv) && 4707 1.1 riastrad !intel_bios_is_port_present(dev_priv, PORT_E)) 4708 1.1 riastrad return true; 4709 1.1 riastrad 4710 1.1 riastrad return false; 4711 1.1 riastrad } 4712 1.1 riastrad 4713 1.1 riastrad static int 4714 1.1 riastrad intel_ddi_max_lanes(struct intel_digital_port *intel_dport) 4715 1.1 riastrad { 4716 1.1 riastrad struct drm_i915_private *dev_priv = to_i915(intel_dport->base.base.dev); 4717 1.1 riastrad enum port port = intel_dport->base.port; 4718 1.1 riastrad int max_lanes = 4; 4719 1.1 riastrad 4720 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) 4721 1.1 riastrad return max_lanes; 4722 1.1 riastrad 4723 1.1 riastrad if (port == PORT_A || port == PORT_E) { 4724 1.1 riastrad if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) 4725 1.1 riastrad max_lanes = port == PORT_A ? 4 : 0; 4726 1.1 riastrad else 4727 1.1 riastrad /* Both A and E share 2 lanes */ 4728 1.1 riastrad max_lanes = 2; 4729 1.1 riastrad } 4730 1.1 riastrad 4731 1.1 riastrad /* 4732 1.1 riastrad * Some BIOS might fail to set this bit on port A if eDP 4733 1.1 riastrad * wasn't lit up at boot. Force this bit set when needed 4734 1.1 riastrad * so we use the proper lane count for our calculations. 4735 1.1 riastrad */ 4736 1.1 riastrad if (intel_ddi_a_force_4_lanes(intel_dport)) { 4737 1.1 riastrad DRM_DEBUG_KMS("Forcing DDI_A_4_LANES for port A\n"); 4738 1.1 riastrad intel_dport->saved_port_bits |= DDI_A_4_LANES; 4739 1.1 riastrad max_lanes = 4; 4740 1.1 riastrad } 4741 1.1 riastrad 4742 1.1 riastrad return max_lanes; 4743 1.1 riastrad } 4744 1.1 riastrad 4745 1.1 riastrad void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port) 4746 1.1 riastrad { 4747 1.1 riastrad struct ddi_vbt_port_info *port_info = 4748 1.1 riastrad &dev_priv->vbt.ddi_port_info[port]; 4749 1.1 riastrad struct intel_digital_port *intel_dig_port; 4750 1.1 riastrad struct intel_encoder *encoder; 4751 1.1 riastrad bool init_hdmi, init_dp, init_lspcon = false; 4752 1.1 riastrad enum phy phy = intel_port_to_phy(dev_priv, port); 4753 1.1 riastrad 4754 1.1 riastrad init_hdmi = port_info->supports_dvi || port_info->supports_hdmi; 4755 1.1 riastrad init_dp = port_info->supports_dp; 4756 1.1 riastrad 4757 1.1 riastrad if (intel_bios_is_lspcon_present(dev_priv, port)) { 4758 1.1 riastrad /* 4759 1.1 riastrad * Lspcon device needs to be driven with DP connector 4760 1.1 riastrad * with special detection sequence. So make sure DP 4761 1.1 riastrad * is initialized before lspcon. 4762 1.1 riastrad */ 4763 1.1 riastrad init_dp = true; 4764 1.1 riastrad init_lspcon = true; 4765 1.1 riastrad init_hdmi = false; 4766 1.1 riastrad DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port)); 4767 1.1 riastrad } 4768 1.1 riastrad 4769 1.1 riastrad if (!init_dp && !init_hdmi) { 4770 1.1 riastrad DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n", 4771 1.1 riastrad port_name(port)); 4772 1.1 riastrad return; 4773 1.1 riastrad } 4774 1.1 riastrad 4775 1.1 riastrad intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL); 4776 1.1 riastrad if (!intel_dig_port) 4777 1.1 riastrad return; 4778 1.1 riastrad 4779 1.1 riastrad encoder = &intel_dig_port->base; 4780 1.1 riastrad 4781 1.1 riastrad drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs, 4782 1.1 riastrad DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port)); 4783 1.1 riastrad 4784 1.1 riastrad encoder->hotplug = intel_ddi_hotplug; 4785 1.1 riastrad encoder->compute_output_type = intel_ddi_compute_output_type; 4786 1.1 riastrad encoder->compute_config = intel_ddi_compute_config; 4787 1.1 riastrad encoder->enable = intel_enable_ddi; 4788 1.1 riastrad encoder->pre_pll_enable = intel_ddi_pre_pll_enable; 4789 1.1 riastrad encoder->pre_enable = intel_ddi_pre_enable; 4790 1.1 riastrad encoder->disable = intel_disable_ddi; 4791 1.1 riastrad encoder->post_disable = intel_ddi_post_disable; 4792 1.1 riastrad encoder->update_pipe = intel_ddi_update_pipe; 4793 1.1 riastrad encoder->get_hw_state = intel_ddi_get_hw_state; 4794 1.1 riastrad encoder->get_config = intel_ddi_get_config; 4795 1.1 riastrad encoder->suspend = intel_dp_encoder_suspend; 4796 1.1 riastrad encoder->get_power_domains = intel_ddi_get_power_domains; 4797 1.1 riastrad 4798 1.1 riastrad encoder->type = INTEL_OUTPUT_DDI; 4799 1.1 riastrad encoder->power_domain = intel_port_to_power_domain(port); 4800 1.1 riastrad encoder->port = port; 4801 1.1 riastrad encoder->cloneable = 0; 4802 1.1 riastrad encoder->pipe_mask = ~0; 4803 1.1 riastrad 4804 1.1 riastrad if (INTEL_GEN(dev_priv) >= 11) 4805 1.1 riastrad intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) & 4806 1.1 riastrad DDI_BUF_PORT_REVERSAL; 4807 1.1 riastrad else 4808 1.1 riastrad intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) & 4809 1.1 riastrad (DDI_BUF_PORT_REVERSAL | DDI_A_4_LANES); 4810 1.1 riastrad 4811 1.1 riastrad intel_dig_port->dp.output_reg = INVALID_MMIO_REG; 4812 1.1 riastrad intel_dig_port->max_lanes = intel_ddi_max_lanes(intel_dig_port); 4813 1.1 riastrad intel_dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port); 4814 1.1 riastrad 4815 1.1 riastrad if (intel_phy_is_tc(dev_priv, phy)) { 4816 1.1 riastrad bool is_legacy = !port_info->supports_typec_usb && 4817 1.1 riastrad !port_info->supports_tbt; 4818 1.1 riastrad 4819 1.1 riastrad intel_tc_port_init(intel_dig_port, is_legacy); 4820 1.1 riastrad 4821 1.1 riastrad encoder->update_prepare = intel_ddi_update_prepare; 4822 1.1 riastrad encoder->update_complete = intel_ddi_update_complete; 4823 1.1 riastrad } 4824 1.1 riastrad 4825 1.1 riastrad WARN_ON(port > PORT_I); 4826 1.1 riastrad intel_dig_port->ddi_io_power_domain = POWER_DOMAIN_PORT_DDI_A_IO + 4827 1.1 riastrad port - PORT_A; 4828 1.1 riastrad 4829 1.1 riastrad if (init_dp) { 4830 1.1 riastrad if (!intel_ddi_init_dp_connector(intel_dig_port)) 4831 1.1 riastrad goto err; 4832 1.1 riastrad 4833 1.1 riastrad intel_dig_port->hpd_pulse = intel_dp_hpd_pulse; 4834 1.1 riastrad } 4835 1.1 riastrad 4836 1.1 riastrad /* In theory we don't need the encoder->type check, but leave it just in 4837 1.1 riastrad * case we have some really bad VBTs... */ 4838 1.1 riastrad if (encoder->type != INTEL_OUTPUT_EDP && init_hdmi) { 4839 1.1 riastrad if (!intel_ddi_init_hdmi_connector(intel_dig_port)) 4840 1.1 riastrad goto err; 4841 1.1 riastrad } 4842 1.1 riastrad 4843 1.1 riastrad if (init_lspcon) { 4844 1.1 riastrad if (lspcon_init(intel_dig_port)) 4845 1.1 riastrad /* TODO: handle hdmi info frame part */ 4846 1.1 riastrad DRM_DEBUG_KMS("LSPCON init success on port %c\n", 4847 1.1 riastrad port_name(port)); 4848 1.1 riastrad else 4849 1.1 riastrad /* 4850 1.1 riastrad * LSPCON init faied, but DP init was success, so 4851 1.1 riastrad * lets try to drive as DP++ port. 4852 1.1 riastrad */ 4853 1.1 riastrad DRM_ERROR("LSPCON init failed on port %c\n", 4854 1.1 riastrad port_name(port)); 4855 1.1 riastrad } 4856 1.1 riastrad 4857 1.1 riastrad intel_infoframe_init(intel_dig_port); 4858 1.1 riastrad 4859 1.1 riastrad return; 4860 1.1 riastrad 4861 1.1 riastrad err: 4862 1.1 riastrad drm_encoder_cleanup(&encoder->base); 4863 1.1 riastrad kfree(intel_dig_port); 4864 1.1 riastrad } 4865