1379bc100SJani Nikula /* 2379bc100SJani Nikula * Copyright © 2012 Intel Corporation 3379bc100SJani Nikula * 4379bc100SJani Nikula * Permission is hereby granted, free of charge, to any person obtaining a 5379bc100SJani Nikula * copy of this software and associated documentation files (the "Software"), 6379bc100SJani Nikula * to deal in the Software without restriction, including without limitation 7379bc100SJani Nikula * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8379bc100SJani Nikula * and/or sell copies of the Software, and to permit persons to whom the 9379bc100SJani Nikula * Software is furnished to do so, subject to the following conditions: 10379bc100SJani Nikula * 11379bc100SJani Nikula * The above copyright notice and this permission notice (including the next 12379bc100SJani Nikula * paragraph) shall be included in all copies or substantial portions of the 13379bc100SJani Nikula * Software. 14379bc100SJani Nikula * 15379bc100SJani Nikula * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16379bc100SJani Nikula * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17379bc100SJani Nikula * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18379bc100SJani Nikula * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19379bc100SJani Nikula * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20379bc100SJani Nikula * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21379bc100SJani Nikula * IN THE SOFTWARE. 22379bc100SJani Nikula * 23379bc100SJani Nikula * Authors: 24379bc100SJani Nikula * Eugeni Dodonov <eugeni.dodonov@intel.com> 25379bc100SJani Nikula * 26379bc100SJani Nikula */ 27379bc100SJani Nikula 28379bc100SJani Nikula #include <drm/drm_scdc_helper.h> 29379bc100SJani Nikula 30379bc100SJani Nikula #include "i915_drv.h" 31379bc100SJani Nikula #include "intel_audio.h" 32379bc100SJani Nikula #include "intel_combo_phy.h" 33379bc100SJani Nikula #include "intel_connector.h" 34379bc100SJani Nikula #include "intel_ddi.h" 351d455f8dSJani Nikula #include "intel_display_types.h" 36379bc100SJani Nikula #include "intel_dp.h" 37c59053dcSJosé Roberto de Souza #include "intel_dp_mst.h" 38379bc100SJani Nikula #include "intel_dp_link_training.h" 39379bc100SJani Nikula #include "intel_dpio_phy.h" 40379bc100SJani Nikula #include "intel_dsi.h" 41379bc100SJani Nikula #include "intel_fifo_underrun.h" 42379bc100SJani Nikula #include "intel_gmbus.h" 43379bc100SJani Nikula #include "intel_hdcp.h" 44379bc100SJani Nikula #include "intel_hdmi.h" 45379bc100SJani Nikula #include "intel_hotplug.h" 46379bc100SJani Nikula #include "intel_lspcon.h" 47379bc100SJani Nikula #include "intel_panel.h" 48379bc100SJani Nikula #include "intel_psr.h" 49bdacf087SAnshuman Gupta #include "intel_sprite.h" 50bc85328fSImre Deak #include "intel_tc.h" 51379bc100SJani Nikula #include "intel_vdsc.h" 52379bc100SJani Nikula 53379bc100SJani Nikula struct ddi_buf_trans { 54379bc100SJani Nikula u32 trans1; /* balance leg enable, de-emph level */ 55379bc100SJani Nikula u32 trans2; /* vref sel, vswing */ 56379bc100SJani Nikula u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */ 57379bc100SJani Nikula }; 58379bc100SJani Nikula 59379bc100SJani Nikula static const u8 index_to_dp_signal_levels[] = { 60379bc100SJani Nikula [0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0, 61379bc100SJani Nikula [1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1, 62379bc100SJani Nikula [2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2, 63379bc100SJani Nikula [3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3, 64379bc100SJani Nikula [4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0, 65379bc100SJani Nikula [5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1, 66379bc100SJani Nikula [6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2, 67379bc100SJani Nikula [7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0, 68379bc100SJani Nikula [8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1, 69379bc100SJani Nikula [9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0, 70379bc100SJani Nikula }; 71379bc100SJani Nikula 72379bc100SJani Nikula /* HDMI/DVI modes ignore everything but the last 2 items. So we share 73379bc100SJani Nikula * them for both DP and FDI transports, allowing those ports to 74379bc100SJani Nikula * automatically adapt to HDMI connections as well 75379bc100SJani Nikula */ 76379bc100SJani Nikula static const struct ddi_buf_trans hsw_ddi_translations_dp[] = { 77379bc100SJani Nikula { 0x00FFFFFF, 0x0006000E, 0x0 }, 78379bc100SJani Nikula { 0x00D75FFF, 0x0005000A, 0x0 }, 79379bc100SJani Nikula { 0x00C30FFF, 0x00040006, 0x0 }, 80379bc100SJani Nikula { 0x80AAAFFF, 0x000B0000, 0x0 }, 81379bc100SJani Nikula { 0x00FFFFFF, 0x0005000A, 0x0 }, 82379bc100SJani Nikula { 0x00D75FFF, 0x000C0004, 0x0 }, 83379bc100SJani Nikula { 0x80C30FFF, 0x000B0000, 0x0 }, 84379bc100SJani Nikula { 0x00FFFFFF, 0x00040006, 0x0 }, 85379bc100SJani Nikula { 0x80D75FFF, 0x000B0000, 0x0 }, 86379bc100SJani Nikula }; 87379bc100SJani Nikula 88379bc100SJani Nikula static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = { 89379bc100SJani Nikula { 0x00FFFFFF, 0x0007000E, 0x0 }, 90379bc100SJani Nikula { 0x00D75FFF, 0x000F000A, 0x0 }, 91379bc100SJani Nikula { 0x00C30FFF, 0x00060006, 0x0 }, 92379bc100SJani Nikula { 0x00AAAFFF, 0x001E0000, 0x0 }, 93379bc100SJani Nikula { 0x00FFFFFF, 0x000F000A, 0x0 }, 94379bc100SJani Nikula { 0x00D75FFF, 0x00160004, 0x0 }, 95379bc100SJani Nikula { 0x00C30FFF, 0x001E0000, 0x0 }, 96379bc100SJani Nikula { 0x00FFFFFF, 0x00060006, 0x0 }, 97379bc100SJani Nikula { 0x00D75FFF, 0x001E0000, 0x0 }, 98379bc100SJani Nikula }; 99379bc100SJani Nikula 100379bc100SJani Nikula static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = { 101379bc100SJani Nikula /* Idx NT mV d T mV d db */ 102379bc100SJani Nikula { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */ 103379bc100SJani Nikula { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */ 104379bc100SJani Nikula { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */ 105379bc100SJani Nikula { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */ 106379bc100SJani Nikula { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */ 107379bc100SJani Nikula { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */ 108379bc100SJani Nikula { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */ 109379bc100SJani Nikula { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */ 110379bc100SJani Nikula { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */ 111379bc100SJani Nikula { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */ 112379bc100SJani Nikula { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */ 113379bc100SJani Nikula { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */ 114379bc100SJani Nikula }; 115379bc100SJani Nikula 116379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_edp[] = { 117379bc100SJani Nikula { 0x00FFFFFF, 0x00000012, 0x0 }, 118379bc100SJani Nikula { 0x00EBAFFF, 0x00020011, 0x0 }, 119379bc100SJani Nikula { 0x00C71FFF, 0x0006000F, 0x0 }, 120379bc100SJani Nikula { 0x00AAAFFF, 0x000E000A, 0x0 }, 121379bc100SJani Nikula { 0x00FFFFFF, 0x00020011, 0x0 }, 122379bc100SJani Nikula { 0x00DB6FFF, 0x0005000F, 0x0 }, 123379bc100SJani Nikula { 0x00BEEFFF, 0x000A000C, 0x0 }, 124379bc100SJani Nikula { 0x00FFFFFF, 0x0005000F, 0x0 }, 125379bc100SJani Nikula { 0x00DB6FFF, 0x000A000C, 0x0 }, 126379bc100SJani Nikula }; 127379bc100SJani Nikula 128379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_dp[] = { 129379bc100SJani Nikula { 0x00FFFFFF, 0x0007000E, 0x0 }, 130379bc100SJani Nikula { 0x00D75FFF, 0x000E000A, 0x0 }, 131379bc100SJani Nikula { 0x00BEFFFF, 0x00140006, 0x0 }, 132379bc100SJani Nikula { 0x80B2CFFF, 0x001B0002, 0x0 }, 133379bc100SJani Nikula { 0x00FFFFFF, 0x000E000A, 0x0 }, 134379bc100SJani Nikula { 0x00DB6FFF, 0x00160005, 0x0 }, 135379bc100SJani Nikula { 0x80C71FFF, 0x001A0002, 0x0 }, 136379bc100SJani Nikula { 0x00F7DFFF, 0x00180004, 0x0 }, 137379bc100SJani Nikula { 0x80D75FFF, 0x001B0002, 0x0 }, 138379bc100SJani Nikula }; 139379bc100SJani Nikula 140379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = { 141379bc100SJani Nikula { 0x00FFFFFF, 0x0001000E, 0x0 }, 142379bc100SJani Nikula { 0x00D75FFF, 0x0004000A, 0x0 }, 143379bc100SJani Nikula { 0x00C30FFF, 0x00070006, 0x0 }, 144379bc100SJani Nikula { 0x00AAAFFF, 0x000C0000, 0x0 }, 145379bc100SJani Nikula { 0x00FFFFFF, 0x0004000A, 0x0 }, 146379bc100SJani Nikula { 0x00D75FFF, 0x00090004, 0x0 }, 147379bc100SJani Nikula { 0x00C30FFF, 0x000C0000, 0x0 }, 148379bc100SJani Nikula { 0x00FFFFFF, 0x00070006, 0x0 }, 149379bc100SJani Nikula { 0x00D75FFF, 0x000C0000, 0x0 }, 150379bc100SJani Nikula }; 151379bc100SJani Nikula 152379bc100SJani Nikula static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = { 153379bc100SJani Nikula /* Idx NT mV d T mV df db */ 154379bc100SJani Nikula { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */ 155379bc100SJani Nikula { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */ 156379bc100SJani Nikula { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */ 157379bc100SJani Nikula { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */ 158379bc100SJani Nikula { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */ 159379bc100SJani Nikula { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */ 160379bc100SJani Nikula { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */ 161379bc100SJani Nikula { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */ 162379bc100SJani Nikula { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */ 163379bc100SJani Nikula { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */ 164379bc100SJani Nikula }; 165379bc100SJani Nikula 166379bc100SJani Nikula /* Skylake H and S */ 167379bc100SJani Nikula static const struct ddi_buf_trans skl_ddi_translations_dp[] = { 168379bc100SJani Nikula { 0x00002016, 0x000000A0, 0x0 }, 169379bc100SJani Nikula { 0x00005012, 0x0000009B, 0x0 }, 170379bc100SJani Nikula { 0x00007011, 0x00000088, 0x0 }, 171379bc100SJani Nikula { 0x80009010, 0x000000C0, 0x1 }, 172379bc100SJani Nikula { 0x00002016, 0x0000009B, 0x0 }, 173379bc100SJani Nikula { 0x00005012, 0x00000088, 0x0 }, 174379bc100SJani Nikula { 0x80007011, 0x000000C0, 0x1 }, 175379bc100SJani Nikula { 0x00002016, 0x000000DF, 0x0 }, 176379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x1 }, 177379bc100SJani Nikula }; 178379bc100SJani Nikula 179379bc100SJani Nikula /* Skylake U */ 180379bc100SJani Nikula static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = { 181379bc100SJani Nikula { 0x0000201B, 0x000000A2, 0x0 }, 182379bc100SJani Nikula { 0x00005012, 0x00000088, 0x0 }, 183379bc100SJani Nikula { 0x80007011, 0x000000CD, 0x1 }, 184379bc100SJani Nikula { 0x80009010, 0x000000C0, 0x1 }, 185379bc100SJani Nikula { 0x0000201B, 0x0000009D, 0x0 }, 186379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x1 }, 187379bc100SJani Nikula { 0x80007011, 0x000000C0, 0x1 }, 188379bc100SJani Nikula { 0x00002016, 0x00000088, 0x0 }, 189379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x1 }, 190379bc100SJani Nikula }; 191379bc100SJani Nikula 192379bc100SJani Nikula /* Skylake Y */ 193379bc100SJani Nikula static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = { 194379bc100SJani Nikula { 0x00000018, 0x000000A2, 0x0 }, 195379bc100SJani Nikula { 0x00005012, 0x00000088, 0x0 }, 196379bc100SJani Nikula { 0x80007011, 0x000000CD, 0x3 }, 197379bc100SJani Nikula { 0x80009010, 0x000000C0, 0x3 }, 198379bc100SJani Nikula { 0x00000018, 0x0000009D, 0x0 }, 199379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x3 }, 200379bc100SJani Nikula { 0x80007011, 0x000000C0, 0x3 }, 201379bc100SJani Nikula { 0x00000018, 0x00000088, 0x0 }, 202379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x3 }, 203379bc100SJani Nikula }; 204379bc100SJani Nikula 205379bc100SJani Nikula /* Kabylake H and S */ 206379bc100SJani Nikula static const struct ddi_buf_trans kbl_ddi_translations_dp[] = { 207379bc100SJani Nikula { 0x00002016, 0x000000A0, 0x0 }, 208379bc100SJani Nikula { 0x00005012, 0x0000009B, 0x0 }, 209379bc100SJani Nikula { 0x00007011, 0x00000088, 0x0 }, 210379bc100SJani Nikula { 0x80009010, 0x000000C0, 0x1 }, 211379bc100SJani Nikula { 0x00002016, 0x0000009B, 0x0 }, 212379bc100SJani Nikula { 0x00005012, 0x00000088, 0x0 }, 213379bc100SJani Nikula { 0x80007011, 0x000000C0, 0x1 }, 214379bc100SJani Nikula { 0x00002016, 0x00000097, 0x0 }, 215379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x1 }, 216379bc100SJani Nikula }; 217379bc100SJani Nikula 218379bc100SJani Nikula /* Kabylake U */ 219379bc100SJani Nikula static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = { 220379bc100SJani Nikula { 0x0000201B, 0x000000A1, 0x0 }, 221379bc100SJani Nikula { 0x00005012, 0x00000088, 0x0 }, 222379bc100SJani Nikula { 0x80007011, 0x000000CD, 0x3 }, 223379bc100SJani Nikula { 0x80009010, 0x000000C0, 0x3 }, 224379bc100SJani Nikula { 0x0000201B, 0x0000009D, 0x0 }, 225379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x3 }, 226379bc100SJani Nikula { 0x80007011, 0x000000C0, 0x3 }, 227379bc100SJani Nikula { 0x00002016, 0x0000004F, 0x0 }, 228379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x3 }, 229379bc100SJani Nikula }; 230379bc100SJani Nikula 231379bc100SJani Nikula /* Kabylake Y */ 232379bc100SJani Nikula static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = { 233379bc100SJani Nikula { 0x00001017, 0x000000A1, 0x0 }, 234379bc100SJani Nikula { 0x00005012, 0x00000088, 0x0 }, 235379bc100SJani Nikula { 0x80007011, 0x000000CD, 0x3 }, 236379bc100SJani Nikula { 0x8000800F, 0x000000C0, 0x3 }, 237379bc100SJani Nikula { 0x00001017, 0x0000009D, 0x0 }, 238379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x3 }, 239379bc100SJani Nikula { 0x80007011, 0x000000C0, 0x3 }, 240379bc100SJani Nikula { 0x00001017, 0x0000004C, 0x0 }, 241379bc100SJani Nikula { 0x80005012, 0x000000C0, 0x3 }, 242379bc100SJani Nikula }; 243379bc100SJani Nikula 244379bc100SJani Nikula /* 245379bc100SJani Nikula * Skylake/Kabylake H and S 246379bc100SJani Nikula * eDP 1.4 low vswing translation parameters 247379bc100SJani Nikula */ 248379bc100SJani Nikula static const struct ddi_buf_trans skl_ddi_translations_edp[] = { 249379bc100SJani Nikula { 0x00000018, 0x000000A8, 0x0 }, 250379bc100SJani Nikula { 0x00004013, 0x000000A9, 0x0 }, 251379bc100SJani Nikula { 0x00007011, 0x000000A2, 0x0 }, 252379bc100SJani Nikula { 0x00009010, 0x0000009C, 0x0 }, 253379bc100SJani Nikula { 0x00000018, 0x000000A9, 0x0 }, 254379bc100SJani Nikula { 0x00006013, 0x000000A2, 0x0 }, 255379bc100SJani Nikula { 0x00007011, 0x000000A6, 0x0 }, 256379bc100SJani Nikula { 0x00000018, 0x000000AB, 0x0 }, 257379bc100SJani Nikula { 0x00007013, 0x0000009F, 0x0 }, 258379bc100SJani Nikula { 0x00000018, 0x000000DF, 0x0 }, 259379bc100SJani Nikula }; 260379bc100SJani Nikula 261379bc100SJani Nikula /* 262379bc100SJani Nikula * Skylake/Kabylake U 263379bc100SJani Nikula * eDP 1.4 low vswing translation parameters 264379bc100SJani Nikula */ 265379bc100SJani Nikula static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = { 266379bc100SJani Nikula { 0x00000018, 0x000000A8, 0x0 }, 267379bc100SJani Nikula { 0x00004013, 0x000000A9, 0x0 }, 268379bc100SJani Nikula { 0x00007011, 0x000000A2, 0x0 }, 269379bc100SJani Nikula { 0x00009010, 0x0000009C, 0x0 }, 270379bc100SJani Nikula { 0x00000018, 0x000000A9, 0x0 }, 271379bc100SJani Nikula { 0x00006013, 0x000000A2, 0x0 }, 272379bc100SJani Nikula { 0x00007011, 0x000000A6, 0x0 }, 273379bc100SJani Nikula { 0x00002016, 0x000000AB, 0x0 }, 274379bc100SJani Nikula { 0x00005013, 0x0000009F, 0x0 }, 275379bc100SJani Nikula { 0x00000018, 0x000000DF, 0x0 }, 276379bc100SJani Nikula }; 277379bc100SJani Nikula 278379bc100SJani Nikula /* 279379bc100SJani Nikula * Skylake/Kabylake Y 280379bc100SJani Nikula * eDP 1.4 low vswing translation parameters 281379bc100SJani Nikula */ 282379bc100SJani Nikula static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = { 283379bc100SJani Nikula { 0x00000018, 0x000000A8, 0x0 }, 284379bc100SJani Nikula { 0x00004013, 0x000000AB, 0x0 }, 285379bc100SJani Nikula { 0x00007011, 0x000000A4, 0x0 }, 286379bc100SJani Nikula { 0x00009010, 0x000000DF, 0x0 }, 287379bc100SJani Nikula { 0x00000018, 0x000000AA, 0x0 }, 288379bc100SJani Nikula { 0x00006013, 0x000000A4, 0x0 }, 289379bc100SJani Nikula { 0x00007011, 0x0000009D, 0x0 }, 290379bc100SJani Nikula { 0x00000018, 0x000000A0, 0x0 }, 291379bc100SJani Nikula { 0x00006012, 0x000000DF, 0x0 }, 292379bc100SJani Nikula { 0x00000018, 0x0000008A, 0x0 }, 293379bc100SJani Nikula }; 294379bc100SJani Nikula 295379bc100SJani Nikula /* Skylake/Kabylake U, H and S */ 296379bc100SJani Nikula static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = { 297379bc100SJani Nikula { 0x00000018, 0x000000AC, 0x0 }, 298379bc100SJani Nikula { 0x00005012, 0x0000009D, 0x0 }, 299379bc100SJani Nikula { 0x00007011, 0x00000088, 0x0 }, 300379bc100SJani Nikula { 0x00000018, 0x000000A1, 0x0 }, 301379bc100SJani Nikula { 0x00000018, 0x00000098, 0x0 }, 302379bc100SJani Nikula { 0x00004013, 0x00000088, 0x0 }, 303379bc100SJani Nikula { 0x80006012, 0x000000CD, 0x1 }, 304379bc100SJani Nikula { 0x00000018, 0x000000DF, 0x0 }, 305379bc100SJani Nikula { 0x80003015, 0x000000CD, 0x1 }, /* Default */ 306379bc100SJani Nikula { 0x80003015, 0x000000C0, 0x1 }, 307379bc100SJani Nikula { 0x80000018, 0x000000C0, 0x1 }, 308379bc100SJani Nikula }; 309379bc100SJani Nikula 310379bc100SJani Nikula /* Skylake/Kabylake Y */ 311379bc100SJani Nikula static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = { 312379bc100SJani Nikula { 0x00000018, 0x000000A1, 0x0 }, 313379bc100SJani Nikula { 0x00005012, 0x000000DF, 0x0 }, 314379bc100SJani Nikula { 0x80007011, 0x000000CB, 0x3 }, 315379bc100SJani Nikula { 0x00000018, 0x000000A4, 0x0 }, 316379bc100SJani Nikula { 0x00000018, 0x0000009D, 0x0 }, 317379bc100SJani Nikula { 0x00004013, 0x00000080, 0x0 }, 318379bc100SJani Nikula { 0x80006013, 0x000000C0, 0x3 }, 319379bc100SJani Nikula { 0x00000018, 0x0000008A, 0x0 }, 320379bc100SJani Nikula { 0x80003015, 0x000000C0, 0x3 }, /* Default */ 321379bc100SJani Nikula { 0x80003015, 0x000000C0, 0x3 }, 322379bc100SJani Nikula { 0x80000018, 0x000000C0, 0x3 }, 323379bc100SJani Nikula }; 324379bc100SJani Nikula 325379bc100SJani Nikula struct bxt_ddi_buf_trans { 326379bc100SJani Nikula u8 margin; /* swing value */ 327379bc100SJani Nikula u8 scale; /* scale value */ 328379bc100SJani Nikula u8 enable; /* scale enable */ 329379bc100SJani Nikula u8 deemphasis; 330379bc100SJani Nikula }; 331379bc100SJani Nikula 332379bc100SJani Nikula static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = { 333379bc100SJani Nikula /* Idx NT mV diff db */ 334379bc100SJani Nikula { 52, 0x9A, 0, 128, }, /* 0: 400 0 */ 335379bc100SJani Nikula { 78, 0x9A, 0, 85, }, /* 1: 400 3.5 */ 336379bc100SJani Nikula { 104, 0x9A, 0, 64, }, /* 2: 400 6 */ 337379bc100SJani Nikula { 154, 0x9A, 0, 43, }, /* 3: 400 9.5 */ 338379bc100SJani Nikula { 77, 0x9A, 0, 128, }, /* 4: 600 0 */ 339379bc100SJani Nikula { 116, 0x9A, 0, 85, }, /* 5: 600 3.5 */ 340379bc100SJani Nikula { 154, 0x9A, 0, 64, }, /* 6: 600 6 */ 341379bc100SJani Nikula { 102, 0x9A, 0, 128, }, /* 7: 800 0 */ 342379bc100SJani Nikula { 154, 0x9A, 0, 85, }, /* 8: 800 3.5 */ 343379bc100SJani Nikula { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */ 344379bc100SJani Nikula }; 345379bc100SJani Nikula 346379bc100SJani Nikula static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = { 347379bc100SJani Nikula /* Idx NT mV diff db */ 348379bc100SJani Nikula { 26, 0, 0, 128, }, /* 0: 200 0 */ 349379bc100SJani Nikula { 38, 0, 0, 112, }, /* 1: 200 1.5 */ 350379bc100SJani Nikula { 48, 0, 0, 96, }, /* 2: 200 4 */ 351379bc100SJani Nikula { 54, 0, 0, 69, }, /* 3: 200 6 */ 352379bc100SJani Nikula { 32, 0, 0, 128, }, /* 4: 250 0 */ 353379bc100SJani Nikula { 48, 0, 0, 104, }, /* 5: 250 1.5 */ 354379bc100SJani Nikula { 54, 0, 0, 85, }, /* 6: 250 4 */ 355379bc100SJani Nikula { 43, 0, 0, 128, }, /* 7: 300 0 */ 356379bc100SJani Nikula { 54, 0, 0, 101, }, /* 8: 300 1.5 */ 357379bc100SJani Nikula { 48, 0, 0, 128, }, /* 9: 300 0 */ 358379bc100SJani Nikula }; 359379bc100SJani Nikula 360379bc100SJani Nikula /* BSpec has 2 recommended values - entries 0 and 8. 361379bc100SJani Nikula * Using the entry with higher vswing. 362379bc100SJani Nikula */ 363379bc100SJani Nikula static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = { 364379bc100SJani Nikula /* Idx NT mV diff db */ 365379bc100SJani Nikula { 52, 0x9A, 0, 128, }, /* 0: 400 0 */ 366379bc100SJani Nikula { 52, 0x9A, 0, 85, }, /* 1: 400 3.5 */ 367379bc100SJani Nikula { 52, 0x9A, 0, 64, }, /* 2: 400 6 */ 368379bc100SJani Nikula { 42, 0x9A, 0, 43, }, /* 3: 400 9.5 */ 369379bc100SJani Nikula { 77, 0x9A, 0, 128, }, /* 4: 600 0 */ 370379bc100SJani Nikula { 77, 0x9A, 0, 85, }, /* 5: 600 3.5 */ 371379bc100SJani Nikula { 77, 0x9A, 0, 64, }, /* 6: 600 6 */ 372379bc100SJani Nikula { 102, 0x9A, 0, 128, }, /* 7: 800 0 */ 373379bc100SJani Nikula { 102, 0x9A, 0, 85, }, /* 8: 800 3.5 */ 374379bc100SJani Nikula { 154, 0x9A, 1, 128, }, /* 9: 1200 0 */ 375379bc100SJani Nikula }; 376379bc100SJani Nikula 377379bc100SJani Nikula struct cnl_ddi_buf_trans { 378379bc100SJani Nikula u8 dw2_swing_sel; 379379bc100SJani Nikula u8 dw7_n_scalar; 380379bc100SJani Nikula u8 dw4_cursor_coeff; 381379bc100SJani Nikula u8 dw4_post_cursor_2; 382379bc100SJani Nikula u8 dw4_post_cursor_1; 383379bc100SJani Nikula }; 384379bc100SJani Nikula 385379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.85V for DP */ 386379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V[] = { 387379bc100SJani Nikula /* NT mV Trans mV db */ 388379bc100SJani Nikula { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 389379bc100SJani Nikula { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */ 390379bc100SJani Nikula { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */ 391379bc100SJani Nikula { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */ 392379bc100SJani Nikula { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 393379bc100SJani Nikula { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */ 394379bc100SJani Nikula { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */ 395379bc100SJani Nikula { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */ 396379bc100SJani Nikula { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */ 397379bc100SJani Nikula { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 398379bc100SJani Nikula }; 399379bc100SJani Nikula 400379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.85V for HDMI */ 401379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V[] = { 402379bc100SJani Nikula /* NT mV Trans mV db */ 403379bc100SJani Nikula { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 404379bc100SJani Nikula { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */ 405379bc100SJani Nikula { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */ 406379bc100SJani Nikula { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 */ 407379bc100SJani Nikula { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */ 408379bc100SJani Nikula { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */ 409379bc100SJani Nikula { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 410379bc100SJani Nikula }; 411379bc100SJani Nikula 412379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.85V for eDP */ 413379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V[] = { 414379bc100SJani Nikula /* NT mV Trans mV db */ 415379bc100SJani Nikula { 0xA, 0x66, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */ 416379bc100SJani Nikula { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */ 417379bc100SJani Nikula { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */ 418379bc100SJani Nikula { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */ 419379bc100SJani Nikula { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */ 420379bc100SJani Nikula { 0xA, 0x66, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */ 421379bc100SJani Nikula { 0xB, 0x70, 0x3C, 0x00, 0x03 }, /* 460 600 2.3 */ 422379bc100SJani Nikula { 0xC, 0x75, 0x3C, 0x00, 0x03 }, /* 537 700 2.3 */ 423379bc100SJani Nikula { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 424379bc100SJani Nikula }; 425379bc100SJani Nikula 426379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.95V for DP */ 427379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V[] = { 428379bc100SJani Nikula /* NT mV Trans mV db */ 429379bc100SJani Nikula { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 430379bc100SJani Nikula { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */ 431379bc100SJani Nikula { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */ 432379bc100SJani Nikula { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */ 433379bc100SJani Nikula { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 434379bc100SJani Nikula { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */ 435379bc100SJani Nikula { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */ 436379bc100SJani Nikula { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */ 437379bc100SJani Nikula { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */ 438379bc100SJani Nikula { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 439379bc100SJani Nikula }; 440379bc100SJani Nikula 441379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.95V for HDMI */ 442379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V[] = { 443379bc100SJani Nikula /* NT mV Trans mV db */ 444379bc100SJani Nikula { 0xA, 0x5C, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 445379bc100SJani Nikula { 0xB, 0x69, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */ 446379bc100SJani Nikula { 0x5, 0x76, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */ 447379bc100SJani Nikula { 0xA, 0x5E, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 448379bc100SJani Nikula { 0xB, 0x69, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */ 449379bc100SJani Nikula { 0xB, 0x79, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 450379bc100SJani Nikula { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */ 451379bc100SJani Nikula { 0x5, 0x76, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */ 452379bc100SJani Nikula { 0x6, 0x7D, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */ 453379bc100SJani Nikula { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */ 454379bc100SJani Nikula { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */ 455379bc100SJani Nikula }; 456379bc100SJani Nikula 457379bc100SJani Nikula /* Voltage Swing Programming for VccIO 0.95V for eDP */ 458379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V[] = { 459379bc100SJani Nikula /* NT mV Trans mV db */ 460379bc100SJani Nikula { 0xA, 0x61, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */ 461379bc100SJani Nikula { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */ 462379bc100SJani Nikula { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */ 463379bc100SJani Nikula { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */ 464379bc100SJani Nikula { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */ 465379bc100SJani Nikula { 0xA, 0x61, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */ 466379bc100SJani Nikula { 0xB, 0x68, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */ 467379bc100SJani Nikula { 0xC, 0x6E, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */ 468379bc100SJani Nikula { 0x4, 0x7F, 0x3A, 0x00, 0x05 }, /* 460 600 2.3 */ 469379bc100SJani Nikula { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 470379bc100SJani Nikula }; 471379bc100SJani Nikula 472379bc100SJani Nikula /* Voltage Swing Programming for VccIO 1.05V for DP */ 473379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V[] = { 474379bc100SJani Nikula /* NT mV Trans mV db */ 475379bc100SJani Nikula { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 476379bc100SJani Nikula { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */ 477379bc100SJani Nikula { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */ 478379bc100SJani Nikula { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 400 1050 8.4 */ 479379bc100SJani Nikula { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */ 480379bc100SJani Nikula { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 481379bc100SJani Nikula { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 550 1050 5.6 */ 482379bc100SJani Nikula { 0x5, 0x76, 0x3E, 0x00, 0x01 }, /* 850 900 0.5 */ 483379bc100SJani Nikula { 0x6, 0x7F, 0x36, 0x00, 0x09 }, /* 750 1050 2.9 */ 484379bc100SJani Nikula { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */ 485379bc100SJani Nikula }; 486379bc100SJani Nikula 487379bc100SJani Nikula /* Voltage Swing Programming for VccIO 1.05V for HDMI */ 488379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V[] = { 489379bc100SJani Nikula /* NT mV Trans mV db */ 490379bc100SJani Nikula { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 491379bc100SJani Nikula { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */ 492379bc100SJani Nikula { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */ 493379bc100SJani Nikula { 0xA, 0x5B, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 494379bc100SJani Nikula { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */ 495379bc100SJani Nikula { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 496379bc100SJani Nikula { 0x6, 0x7C, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */ 497379bc100SJani Nikula { 0x5, 0x70, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */ 498379bc100SJani Nikula { 0x6, 0x7C, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */ 499379bc100SJani Nikula { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */ 500379bc100SJani Nikula { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */ 501379bc100SJani Nikula }; 502379bc100SJani Nikula 503379bc100SJani Nikula /* Voltage Swing Programming for VccIO 1.05V for eDP */ 504379bc100SJani Nikula static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V[] = { 505379bc100SJani Nikula /* NT mV Trans mV db */ 506379bc100SJani Nikula { 0xA, 0x5E, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */ 507379bc100SJani Nikula { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */ 508379bc100SJani Nikula { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */ 509379bc100SJani Nikula { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */ 510379bc100SJani Nikula { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */ 511379bc100SJani Nikula { 0xA, 0x5E, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */ 512379bc100SJani Nikula { 0xB, 0x64, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */ 513379bc100SJani Nikula { 0xE, 0x6A, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */ 514379bc100SJani Nikula { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */ 515379bc100SJani Nikula }; 516379bc100SJani Nikula 517379bc100SJani Nikula /* icl_combo_phy_ddi_translations */ 518379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_dp_hbr2[] = { 519379bc100SJani Nikula /* NT mV Trans mV db */ 520379bc100SJani Nikula { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 521379bc100SJani Nikula { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */ 522379bc100SJani Nikula { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */ 523379bc100SJani Nikula { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */ 524379bc100SJani Nikula { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 525379bc100SJani Nikula { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */ 526379bc100SJani Nikula { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */ 527379bc100SJani Nikula { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */ 528379bc100SJani Nikula { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */ 529379bc100SJani Nikula { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 530379bc100SJani Nikula }; 531379bc100SJani Nikula 532379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr2[] = { 533379bc100SJani Nikula /* NT mV Trans mV db */ 534379bc100SJani Nikula { 0x0, 0x7F, 0x3F, 0x00, 0x00 }, /* 200 200 0.0 */ 535379bc100SJani Nikula { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 200 250 1.9 */ 536379bc100SJani Nikula { 0x1, 0x7F, 0x33, 0x00, 0x0C }, /* 200 300 3.5 */ 537379bc100SJani Nikula { 0x9, 0x7F, 0x31, 0x00, 0x0E }, /* 200 350 4.9 */ 538379bc100SJani Nikula { 0x8, 0x7F, 0x3F, 0x00, 0x00 }, /* 250 250 0.0 */ 539379bc100SJani Nikula { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 250 300 1.6 */ 540379bc100SJani Nikula { 0x9, 0x7F, 0x35, 0x00, 0x0A }, /* 250 350 2.9 */ 541379bc100SJani Nikula { 0x1, 0x7F, 0x3F, 0x00, 0x00 }, /* 300 300 0.0 */ 542379bc100SJani Nikula { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 300 350 1.3 */ 543379bc100SJani Nikula { 0x9, 0x7F, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 544379bc100SJani Nikula }; 545379bc100SJani Nikula 546379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_edp_hbr3[] = { 547379bc100SJani Nikula /* NT mV Trans mV db */ 548379bc100SJani Nikula { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 549379bc100SJani Nikula { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */ 550379bc100SJani Nikula { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */ 551379bc100SJani Nikula { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */ 552379bc100SJani Nikula { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 553379bc100SJani Nikula { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */ 554379bc100SJani Nikula { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */ 555379bc100SJani Nikula { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */ 556379bc100SJani Nikula { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */ 557379bc100SJani Nikula { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 558379bc100SJani Nikula }; 559379bc100SJani Nikula 560379bc100SJani Nikula static const struct cnl_ddi_buf_trans icl_combo_phy_ddi_translations_hdmi[] = { 561379bc100SJani Nikula /* NT mV Trans mV db */ 562379bc100SJani Nikula { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */ 563379bc100SJani Nikula { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */ 564379bc100SJani Nikula { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */ 565379bc100SJani Nikula { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 ALS */ 566379bc100SJani Nikula { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */ 567379bc100SJani Nikula { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */ 568379bc100SJani Nikula { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */ 569379bc100SJani Nikula }; 570379bc100SJani Nikula 571a2ae2010SJosé Roberto de Souza static const struct cnl_ddi_buf_trans ehl_combo_phy_ddi_translations_dp[] = { 572b42d5a67SJosé Roberto de Souza /* NT mV Trans mV db */ 573b42d5a67SJosé Roberto de Souza { 0xA, 0x33, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 574b42d5a67SJosé Roberto de Souza { 0xA, 0x47, 0x36, 0x00, 0x09 }, /* 350 500 3.1 */ 575b42d5a67SJosé Roberto de Souza { 0xC, 0x64, 0x30, 0x00, 0x0F }, /* 350 700 6.0 */ 576b42d5a67SJosé Roberto de Souza { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 350 900 8.2 */ 577b42d5a67SJosé Roberto de Souza { 0xA, 0x46, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 578b42d5a67SJosé Roberto de Souza { 0xC, 0x64, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */ 579b42d5a67SJosé Roberto de Souza { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */ 580b42d5a67SJosé Roberto de Souza { 0xC, 0x61, 0x3F, 0x00, 0x00 }, /* 650 700 0.6 */ 581b42d5a67SJosé Roberto de Souza { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 600 900 3.5 */ 582b42d5a67SJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 583b42d5a67SJosé Roberto de Souza }; 584b42d5a67SJosé Roberto de Souza 585379bc100SJani Nikula struct icl_mg_phy_ddi_buf_trans { 586379bc100SJani Nikula u32 cri_txdeemph_override_11_6; 5879f7ffa29SJosé Roberto de Souza u32 cri_txdeemph_override_5_0; 588379bc100SJani Nikula u32 cri_txdeemph_override_17_12; 589379bc100SJani Nikula }; 590379bc100SJani Nikula 5919f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations_rbr_hbr[] = { 592379bc100SJani Nikula /* Voltage swing pre-emphasis */ 5939f7ffa29SJosé Roberto de Souza { 0x18, 0x00, 0x00 }, /* 0 0 */ 5949f7ffa29SJosé Roberto de Souza { 0x1D, 0x00, 0x05 }, /* 0 1 */ 5959f7ffa29SJosé Roberto de Souza { 0x24, 0x00, 0x0C }, /* 0 2 */ 5969f7ffa29SJosé Roberto de Souza { 0x2B, 0x00, 0x14 }, /* 0 3 */ 5979f7ffa29SJosé Roberto de Souza { 0x21, 0x00, 0x00 }, /* 1 0 */ 5989f7ffa29SJosé Roberto de Souza { 0x2B, 0x00, 0x08 }, /* 1 1 */ 5999f7ffa29SJosé Roberto de Souza { 0x30, 0x00, 0x0F }, /* 1 2 */ 6009f7ffa29SJosé Roberto de Souza { 0x31, 0x00, 0x03 }, /* 2 0 */ 6019f7ffa29SJosé Roberto de Souza { 0x34, 0x00, 0x0B }, /* 2 1 */ 6029f7ffa29SJosé Roberto de Souza { 0x3F, 0x00, 0x00 }, /* 3 0 */ 6039f7ffa29SJosé Roberto de Souza }; 6049f7ffa29SJosé Roberto de Souza 6059f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations_hbr2_hbr3[] = { 6069f7ffa29SJosé Roberto de Souza /* Voltage swing pre-emphasis */ 6079f7ffa29SJosé Roberto de Souza { 0x18, 0x00, 0x00 }, /* 0 0 */ 6089f7ffa29SJosé Roberto de Souza { 0x1D, 0x00, 0x05 }, /* 0 1 */ 6099f7ffa29SJosé Roberto de Souza { 0x24, 0x00, 0x0C }, /* 0 2 */ 6109f7ffa29SJosé Roberto de Souza { 0x2B, 0x00, 0x14 }, /* 0 3 */ 6119f7ffa29SJosé Roberto de Souza { 0x26, 0x00, 0x00 }, /* 1 0 */ 6129f7ffa29SJosé Roberto de Souza { 0x2C, 0x00, 0x07 }, /* 1 1 */ 6139f7ffa29SJosé Roberto de Souza { 0x33, 0x00, 0x0C }, /* 1 2 */ 6149f7ffa29SJosé Roberto de Souza { 0x2E, 0x00, 0x00 }, /* 2 0 */ 6159f7ffa29SJosé Roberto de Souza { 0x36, 0x00, 0x09 }, /* 2 1 */ 6169f7ffa29SJosé Roberto de Souza { 0x3F, 0x00, 0x00 }, /* 3 0 */ 6179f7ffa29SJosé Roberto de Souza }; 6189f7ffa29SJosé Roberto de Souza 6199f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans icl_mg_phy_ddi_translations_hdmi[] = { 6209f7ffa29SJosé Roberto de Souza /* HDMI Preset VS Pre-emph */ 6219f7ffa29SJosé Roberto de Souza { 0x1A, 0x0, 0x0 }, /* 1 400mV 0dB */ 6229f7ffa29SJosé Roberto de Souza { 0x20, 0x0, 0x0 }, /* 2 500mV 0dB */ 6239f7ffa29SJosé Roberto de Souza { 0x29, 0x0, 0x0 }, /* 3 650mV 0dB */ 6249f7ffa29SJosé Roberto de Souza { 0x32, 0x0, 0x0 }, /* 4 800mV 0dB */ 6259f7ffa29SJosé Roberto de Souza { 0x3F, 0x0, 0x0 }, /* 5 1000mV 0dB */ 6269f7ffa29SJosé Roberto de Souza { 0x3A, 0x0, 0x5 }, /* 6 Full -1.5 dB */ 6279f7ffa29SJosé Roberto de Souza { 0x39, 0x0, 0x6 }, /* 7 Full -1.8 dB */ 6289f7ffa29SJosé Roberto de Souza { 0x38, 0x0, 0x7 }, /* 8 Full -2 dB */ 6299f7ffa29SJosé Roberto de Souza { 0x37, 0x0, 0x8 }, /* 9 Full -2.5 dB */ 6309f7ffa29SJosé Roberto de Souza { 0x36, 0x0, 0x9 }, /* 10 Full -3 dB */ 631379bc100SJani Nikula }; 632379bc100SJani Nikula 633978c3e53SClinton A Taylor struct tgl_dkl_phy_ddi_buf_trans { 634978c3e53SClinton A Taylor u32 dkl_vswing_control; 635978c3e53SClinton A Taylor u32 dkl_preshoot_control; 636978c3e53SClinton A Taylor u32 dkl_de_emphasis_control; 637978c3e53SClinton A Taylor }; 638978c3e53SClinton A Taylor 639362bfb99SMatt Roper static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_dp_ddi_trans[] = { 640978c3e53SClinton A Taylor /* VS pre-emp Non-trans mV Pre-emph dB */ 641978c3e53SClinton A Taylor { 0x7, 0x0, 0x00 }, /* 0 0 400mV 0 dB */ 642250a353cSJosé Roberto de Souza { 0x5, 0x0, 0x05 }, /* 0 1 400mV 3.5 dB */ 643250a353cSJosé Roberto de Souza { 0x2, 0x0, 0x0B }, /* 0 2 400mV 6 dB */ 6449fa67699SJosé Roberto de Souza { 0x0, 0x0, 0x18 }, /* 0 3 400mV 9.5 dB */ 6459fa67699SJosé Roberto de Souza { 0x5, 0x0, 0x00 }, /* 1 0 600mV 0 dB */ 6469fa67699SJosé Roberto de Souza { 0x2, 0x0, 0x08 }, /* 1 1 600mV 3.5 dB */ 6479fa67699SJosé Roberto de Souza { 0x0, 0x0, 0x14 }, /* 1 2 600mV 6 dB */ 6489fa67699SJosé Roberto de Souza { 0x2, 0x0, 0x00 }, /* 2 0 800mV 0 dB */ 6499fa67699SJosé Roberto de Souza { 0x0, 0x0, 0x0B }, /* 2 1 800mV 3.5 dB */ 6509fa67699SJosé Roberto de Souza { 0x0, 0x0, 0x00 }, /* 3 0 1200mV 0 dB HDMI default */ 6519fa67699SJosé Roberto de Souza }; 6529fa67699SJosé Roberto de Souza 6539fa67699SJosé Roberto de Souza static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_dp_ddi_trans_hbr2[] = { 6549fa67699SJosé Roberto de Souza /* VS pre-emp Non-trans mV Pre-emph dB */ 6559fa67699SJosé Roberto de Souza { 0x7, 0x0, 0x00 }, /* 0 0 400mV 0 dB */ 6569fa67699SJosé Roberto de Souza { 0x5, 0x0, 0x05 }, /* 0 1 400mV 3.5 dB */ 6579fa67699SJosé Roberto de Souza { 0x2, 0x0, 0x0B }, /* 0 2 400mV 6 dB */ 658978c3e53SClinton A Taylor { 0x0, 0x0, 0x19 }, /* 0 3 400mV 9.5 dB */ 659978c3e53SClinton A Taylor { 0x5, 0x0, 0x00 }, /* 1 0 600mV 0 dB */ 660250a353cSJosé Roberto de Souza { 0x2, 0x0, 0x08 }, /* 1 1 600mV 3.5 dB */ 661978c3e53SClinton A Taylor { 0x0, 0x0, 0x14 }, /* 1 2 600mV 6 dB */ 662978c3e53SClinton A Taylor { 0x2, 0x0, 0x00 }, /* 2 0 800mV 0 dB */ 663978c3e53SClinton A Taylor { 0x0, 0x0, 0x0B }, /* 2 1 800mV 3.5 dB */ 664978c3e53SClinton A Taylor { 0x0, 0x0, 0x00 }, /* 3 0 1200mV 0 dB HDMI default */ 665978c3e53SClinton A Taylor }; 666978c3e53SClinton A Taylor 667362bfb99SMatt Roper static const struct tgl_dkl_phy_ddi_buf_trans tgl_dkl_phy_hdmi_ddi_trans[] = { 668362bfb99SMatt Roper /* HDMI Preset VS Pre-emph */ 669362bfb99SMatt Roper { 0x7, 0x0, 0x0 }, /* 1 400mV 0dB */ 670362bfb99SMatt Roper { 0x6, 0x0, 0x0 }, /* 2 500mV 0dB */ 671362bfb99SMatt Roper { 0x4, 0x0, 0x0 }, /* 3 650mV 0dB */ 672362bfb99SMatt Roper { 0x2, 0x0, 0x0 }, /* 4 800mV 0dB */ 673362bfb99SMatt Roper { 0x0, 0x0, 0x0 }, /* 5 1000mV 0dB */ 674362bfb99SMatt Roper { 0x0, 0x0, 0x5 }, /* 6 Full -1.5 dB */ 675362bfb99SMatt Roper { 0x0, 0x0, 0x6 }, /* 7 Full -1.8 dB */ 676362bfb99SMatt Roper { 0x0, 0x0, 0x7 }, /* 8 Full -2 dB */ 677362bfb99SMatt Roper { 0x0, 0x0, 0x8 }, /* 9 Full -2.5 dB */ 678362bfb99SMatt Roper { 0x0, 0x0, 0xA }, /* 10 Full -3 dB */ 679362bfb99SMatt Roper }; 680362bfb99SMatt Roper 681bd3cf6f7SJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_dp_hbr[] = { 682bd3cf6f7SJosé Roberto de Souza /* NT mV Trans mV db */ 683bd3cf6f7SJosé Roberto de Souza { 0xA, 0x32, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 684bd3cf6f7SJosé Roberto de Souza { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */ 685bd3cf6f7SJosé Roberto de Souza { 0xC, 0x71, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */ 686bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7D, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */ 687bd3cf6f7SJosé Roberto de Souza { 0xA, 0x4C, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 688bd3cf6f7SJosé Roberto de Souza { 0xC, 0x73, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */ 689bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */ 690bd3cf6f7SJosé Roberto de Souza { 0xC, 0x6C, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */ 691bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */ 692bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 693bd3cf6f7SJosé Roberto de Souza }; 694bd3cf6f7SJosé Roberto de Souza 695bd3cf6f7SJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_dp_hbr2[] = { 696bd3cf6f7SJosé Roberto de Souza /* NT mV Trans mV db */ 697bd3cf6f7SJosé Roberto de Souza { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 698bd3cf6f7SJosé Roberto de Souza { 0xA, 0x4F, 0x37, 0x00, 0x08 }, /* 350 500 3.1 */ 699bd3cf6f7SJosé Roberto de Souza { 0xC, 0x63, 0x2F, 0x00, 0x10 }, /* 350 700 6.0 */ 700bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7F, 0x2B, 0x00, 0x14 }, /* 350 900 8.2 */ 701bd3cf6f7SJosé Roberto de Souza { 0xA, 0x47, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 702bd3cf6f7SJosé Roberto de Souza { 0xC, 0x63, 0x34, 0x00, 0x0B }, /* 500 700 2.9 */ 703bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7F, 0x2F, 0x00, 0x10 }, /* 500 900 5.1 */ 704bd3cf6f7SJosé Roberto de Souza { 0xC, 0x61, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */ 705bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7B, 0x35, 0x00, 0x0A }, /* 600 900 3.5 */ 706bd3cf6f7SJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 707bd3cf6f7SJosé Roberto de Souza }; 708bd3cf6f7SJosé Roberto de Souza 70904dfb1acSJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_uy_combo_phy_ddi_translations_dp_hbr2[] = { 71004dfb1acSJosé Roberto de Souza /* NT mV Trans mV db */ 71104dfb1acSJosé Roberto de Souza { 0xA, 0x35, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */ 71204dfb1acSJosé Roberto de Souza { 0xA, 0x4F, 0x36, 0x00, 0x09 }, /* 350 500 3.1 */ 71304dfb1acSJosé Roberto de Souza { 0xC, 0x60, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */ 71404dfb1acSJosé Roberto de Souza { 0xC, 0x7F, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */ 71504dfb1acSJosé Roberto de Souza { 0xC, 0x47, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */ 71604dfb1acSJosé Roberto de Souza { 0xC, 0x6F, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */ 71704dfb1acSJosé Roberto de Souza { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 500 900 5.1 */ 71804dfb1acSJosé Roberto de Souza { 0x6, 0x60, 0x3C, 0x00, 0x03 }, /* 650 700 0.6 */ 71904dfb1acSJosé Roberto de Souza { 0x6, 0x7F, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */ 72004dfb1acSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */ 72104dfb1acSJosé Roberto de Souza }; 72204dfb1acSJosé Roberto de Souza 72381619f4aSJosé Roberto de Souza /* 72481619f4aSJosé Roberto de Souza * Cloned the HOBL entry to comply with the voltage and pre-emphasis entries 72581619f4aSJosé Roberto de Souza * that DisplayPort specification requires 72681619f4aSJosé Roberto de Souza */ 72781619f4aSJosé Roberto de Souza static const struct cnl_ddi_buf_trans tgl_combo_phy_ddi_translations_edp_hbr2_hobl[] = { 72881619f4aSJosé Roberto de Souza /* VS pre-emp */ 72981619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 0 0 */ 73081619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 0 1 */ 73181619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 0 2 */ 73281619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 0 3 */ 73381619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1 0 */ 73481619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1 1 */ 73581619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1 2 */ 73681619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 2 0 */ 73781619f4aSJosé Roberto de Souza { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 2 1 */ 73881619f4aSJosé Roberto de Souza }; 73981619f4aSJosé Roberto de Souza 74081619f4aSJosé Roberto de Souza static bool is_hobl_buf_trans(const struct cnl_ddi_buf_trans *table) 74181619f4aSJosé Roberto de Souza { 74281619f4aSJosé Roberto de Souza return table == tgl_combo_phy_ddi_translations_edp_hbr2_hobl; 74381619f4aSJosé Roberto de Souza } 74481619f4aSJosé Roberto de Souza 745379bc100SJani Nikula static const struct ddi_buf_trans * 746a8143150SJosé Roberto de Souza bdw_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 747379bc100SJani Nikula { 748a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 749a8143150SJosé Roberto de Souza 750379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 751379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp); 752379bc100SJani Nikula return bdw_ddi_translations_edp; 753379bc100SJani Nikula } else { 754379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 755379bc100SJani Nikula return bdw_ddi_translations_dp; 756379bc100SJani Nikula } 757379bc100SJani Nikula } 758379bc100SJani Nikula 759379bc100SJani Nikula static const struct ddi_buf_trans * 760a8143150SJosé Roberto de Souza skl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 761379bc100SJani Nikula { 762a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 763a8143150SJosé Roberto de Souza 764379bc100SJani Nikula if (IS_SKL_ULX(dev_priv)) { 765379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp); 766379bc100SJani Nikula return skl_y_ddi_translations_dp; 767379bc100SJani Nikula } else if (IS_SKL_ULT(dev_priv)) { 768379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp); 769379bc100SJani Nikula return skl_u_ddi_translations_dp; 770379bc100SJani Nikula } else { 771379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_ddi_translations_dp); 772379bc100SJani Nikula return skl_ddi_translations_dp; 773379bc100SJani Nikula } 774379bc100SJani Nikula } 775379bc100SJani Nikula 776379bc100SJani Nikula static const struct ddi_buf_trans * 777a8143150SJosé Roberto de Souza kbl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 778379bc100SJani Nikula { 779a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 780a8143150SJosé Roberto de Souza 7815f4ae270SChris Wilson if (IS_KBL_ULX(dev_priv) || 7825f4ae270SChris Wilson IS_CFL_ULX(dev_priv) || 7835f4ae270SChris Wilson IS_CML_ULX(dev_priv)) { 784379bc100SJani Nikula *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp); 785379bc100SJani Nikula return kbl_y_ddi_translations_dp; 7865f4ae270SChris Wilson } else if (IS_KBL_ULT(dev_priv) || 7875f4ae270SChris Wilson IS_CFL_ULT(dev_priv) || 7885f4ae270SChris Wilson IS_CML_ULT(dev_priv)) { 789379bc100SJani Nikula *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp); 790379bc100SJani Nikula return kbl_u_ddi_translations_dp; 791379bc100SJani Nikula } else { 792379bc100SJani Nikula *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp); 793379bc100SJani Nikula return kbl_ddi_translations_dp; 794379bc100SJani Nikula } 795379bc100SJani Nikula } 796379bc100SJani Nikula 797379bc100SJani Nikula static const struct ddi_buf_trans * 798a8143150SJosé Roberto de Souza skl_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 799379bc100SJani Nikula { 800a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 801a8143150SJosé Roberto de Souza 802379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 8035f4ae270SChris Wilson if (IS_SKL_ULX(dev_priv) || 8045f4ae270SChris Wilson IS_KBL_ULX(dev_priv) || 8055f4ae270SChris Wilson IS_CFL_ULX(dev_priv) || 8065f4ae270SChris Wilson IS_CML_ULX(dev_priv)) { 807379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp); 808379bc100SJani Nikula return skl_y_ddi_translations_edp; 8095f4ae270SChris Wilson } else if (IS_SKL_ULT(dev_priv) || 8105f4ae270SChris Wilson IS_KBL_ULT(dev_priv) || 8115f4ae270SChris Wilson IS_CFL_ULT(dev_priv) || 8125f4ae270SChris Wilson IS_CML_ULT(dev_priv)) { 813379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp); 814379bc100SJani Nikula return skl_u_ddi_translations_edp; 815379bc100SJani Nikula } else { 816379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_ddi_translations_edp); 817379bc100SJani Nikula return skl_ddi_translations_edp; 818379bc100SJani Nikula } 819379bc100SJani Nikula } 820379bc100SJani Nikula 8215f4ae270SChris Wilson if (IS_KABYLAKE(dev_priv) || 8225f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) || 8235f4ae270SChris Wilson IS_COMETLAKE(dev_priv)) 824a8143150SJosé Roberto de Souza return kbl_get_buf_trans_dp(encoder, n_entries); 825379bc100SJani Nikula else 826a8143150SJosé Roberto de Souza return skl_get_buf_trans_dp(encoder, n_entries); 827379bc100SJani Nikula } 828379bc100SJani Nikula 829379bc100SJani Nikula static const struct ddi_buf_trans * 830379bc100SJani Nikula skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries) 831379bc100SJani Nikula { 8325f4ae270SChris Wilson if (IS_SKL_ULX(dev_priv) || 8335f4ae270SChris Wilson IS_KBL_ULX(dev_priv) || 8345f4ae270SChris Wilson IS_CFL_ULX(dev_priv) || 8355f4ae270SChris Wilson IS_CML_ULX(dev_priv)) { 836379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi); 837379bc100SJani Nikula return skl_y_ddi_translations_hdmi; 838379bc100SJani Nikula } else { 839379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi); 840379bc100SJani Nikula return skl_ddi_translations_hdmi; 841379bc100SJani Nikula } 842379bc100SJani Nikula } 843379bc100SJani Nikula 844379bc100SJani Nikula static int skl_buf_trans_num_entries(enum port port, int n_entries) 845379bc100SJani Nikula { 846379bc100SJani Nikula /* Only DDIA and DDIE can select the 10th register with DP */ 847379bc100SJani Nikula if (port == PORT_A || port == PORT_E) 848379bc100SJani Nikula return min(n_entries, 10); 849379bc100SJani Nikula else 850379bc100SJani Nikula return min(n_entries, 9); 851379bc100SJani Nikula } 852379bc100SJani Nikula 853379bc100SJani Nikula static const struct ddi_buf_trans * 854f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 855379bc100SJani Nikula { 856a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 857a8143150SJosé Roberto de Souza 8585f4ae270SChris Wilson if (IS_KABYLAKE(dev_priv) || 8595f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) || 8605f4ae270SChris Wilson IS_COMETLAKE(dev_priv)) { 861379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations = 862a8143150SJosé Roberto de Souza kbl_get_buf_trans_dp(encoder, n_entries); 863f0e86e05SJosé Roberto de Souza *n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries); 864379bc100SJani Nikula return ddi_translations; 865379bc100SJani Nikula } else if (IS_SKYLAKE(dev_priv)) { 866379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations = 867a8143150SJosé Roberto de Souza skl_get_buf_trans_dp(encoder, n_entries); 868f0e86e05SJosé Roberto de Souza *n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries); 869379bc100SJani Nikula return ddi_translations; 870379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 871379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 872379bc100SJani Nikula return bdw_ddi_translations_dp; 873379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 874379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp); 875379bc100SJani Nikula return hsw_ddi_translations_dp; 876379bc100SJani Nikula } 877379bc100SJani Nikula 878379bc100SJani Nikula *n_entries = 0; 879379bc100SJani Nikula return NULL; 880379bc100SJani Nikula } 881379bc100SJani Nikula 882379bc100SJani Nikula static const struct ddi_buf_trans * 883f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 884379bc100SJani Nikula { 885a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 886a8143150SJosé Roberto de Souza 887379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) { 888379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations = 889a8143150SJosé Roberto de Souza skl_get_buf_trans_edp(encoder, n_entries); 890f0e86e05SJosé Roberto de Souza *n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries); 891379bc100SJani Nikula return ddi_translations; 892379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 893a8143150SJosé Roberto de Souza return bdw_get_buf_trans_edp(encoder, n_entries); 894379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 895379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp); 896379bc100SJani Nikula return hsw_ddi_translations_dp; 897379bc100SJani Nikula } 898379bc100SJani Nikula 899379bc100SJani Nikula *n_entries = 0; 900379bc100SJani Nikula return NULL; 901379bc100SJani Nikula } 902379bc100SJani Nikula 903379bc100SJani Nikula static const struct ddi_buf_trans * 904379bc100SJani Nikula intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv, 905379bc100SJani Nikula int *n_entries) 906379bc100SJani Nikula { 907379bc100SJani Nikula if (IS_BROADWELL(dev_priv)) { 908379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_fdi); 909379bc100SJani Nikula return bdw_ddi_translations_fdi; 910379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 911379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi); 912379bc100SJani Nikula return hsw_ddi_translations_fdi; 913379bc100SJani Nikula } 914379bc100SJani Nikula 915379bc100SJani Nikula *n_entries = 0; 916379bc100SJani Nikula return NULL; 917379bc100SJani Nikula } 918379bc100SJani Nikula 919379bc100SJani Nikula static const struct ddi_buf_trans * 920a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(struct intel_encoder *encoder, 921379bc100SJani Nikula int *n_entries) 922379bc100SJani Nikula { 923a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 924a8143150SJosé Roberto de Souza 925379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) { 926379bc100SJani Nikula return skl_get_buf_trans_hdmi(dev_priv, n_entries); 927379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 928379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); 929379bc100SJani Nikula return bdw_ddi_translations_hdmi; 930379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 931379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); 932379bc100SJani Nikula return hsw_ddi_translations_hdmi; 933379bc100SJani Nikula } 934379bc100SJani Nikula 935379bc100SJani Nikula *n_entries = 0; 936379bc100SJani Nikula return NULL; 937379bc100SJani Nikula } 938379bc100SJani Nikula 939379bc100SJani Nikula static const struct bxt_ddi_buf_trans * 940a8143150SJosé Roberto de Souza bxt_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 941379bc100SJani Nikula { 942379bc100SJani Nikula *n_entries = ARRAY_SIZE(bxt_ddi_translations_dp); 943379bc100SJani Nikula return bxt_ddi_translations_dp; 944379bc100SJani Nikula } 945379bc100SJani Nikula 946379bc100SJani Nikula static const struct bxt_ddi_buf_trans * 947a8143150SJosé Roberto de Souza bxt_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 948379bc100SJani Nikula { 949a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 950a8143150SJosé Roberto de Souza 951379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 952379bc100SJani Nikula *n_entries = ARRAY_SIZE(bxt_ddi_translations_edp); 953379bc100SJani Nikula return bxt_ddi_translations_edp; 954379bc100SJani Nikula } 955379bc100SJani Nikula 956a8143150SJosé Roberto de Souza return bxt_get_buf_trans_dp(encoder, n_entries); 957379bc100SJani Nikula } 958379bc100SJani Nikula 959379bc100SJani Nikula static const struct bxt_ddi_buf_trans * 960a8143150SJosé Roberto de Souza bxt_get_buf_trans_hdmi(struct intel_encoder *encoder, int *n_entries) 961379bc100SJani Nikula { 962379bc100SJani Nikula *n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi); 963379bc100SJani Nikula return bxt_ddi_translations_hdmi; 964379bc100SJani Nikula } 965379bc100SJani Nikula 966379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 967a8143150SJosé Roberto de Souza cnl_get_buf_trans_hdmi(struct intel_encoder *encoder, int *n_entries) 968379bc100SJani Nikula { 969a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 970f7960e7fSJani Nikula u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 971379bc100SJani Nikula 972379bc100SJani Nikula if (voltage == VOLTAGE_INFO_0_85V) { 973379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V); 974379bc100SJani Nikula return cnl_ddi_translations_hdmi_0_85V; 975379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_0_95V) { 976379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V); 977379bc100SJani Nikula return cnl_ddi_translations_hdmi_0_95V; 978379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_1_05V) { 979379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V); 980379bc100SJani Nikula return cnl_ddi_translations_hdmi_1_05V; 981379bc100SJani Nikula } else { 982379bc100SJani Nikula *n_entries = 1; /* shut up gcc */ 983379bc100SJani Nikula MISSING_CASE(voltage); 984379bc100SJani Nikula } 985379bc100SJani Nikula return NULL; 986379bc100SJani Nikula } 987379bc100SJani Nikula 988379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 989a8143150SJosé Roberto de Souza cnl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 990379bc100SJani Nikula { 991a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 992f7960e7fSJani Nikula u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 993379bc100SJani Nikula 994379bc100SJani Nikula if (voltage == VOLTAGE_INFO_0_85V) { 995379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V); 996379bc100SJani Nikula return cnl_ddi_translations_dp_0_85V; 997379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_0_95V) { 998379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V); 999379bc100SJani Nikula return cnl_ddi_translations_dp_0_95V; 1000379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_1_05V) { 1001379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V); 1002379bc100SJani Nikula return cnl_ddi_translations_dp_1_05V; 1003379bc100SJani Nikula } else { 1004379bc100SJani Nikula *n_entries = 1; /* shut up gcc */ 1005379bc100SJani Nikula MISSING_CASE(voltage); 1006379bc100SJani Nikula } 1007379bc100SJani Nikula return NULL; 1008379bc100SJani Nikula } 1009379bc100SJani Nikula 1010379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 1011a8143150SJosé Roberto de Souza cnl_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 1012379bc100SJani Nikula { 1013a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1014f7960e7fSJani Nikula u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 1015379bc100SJani Nikula 1016379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 1017379bc100SJani Nikula if (voltage == VOLTAGE_INFO_0_85V) { 1018379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V); 1019379bc100SJani Nikula return cnl_ddi_translations_edp_0_85V; 1020379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_0_95V) { 1021379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V); 1022379bc100SJani Nikula return cnl_ddi_translations_edp_0_95V; 1023379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_1_05V) { 1024379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V); 1025379bc100SJani Nikula return cnl_ddi_translations_edp_1_05V; 1026379bc100SJani Nikula } else { 1027379bc100SJani Nikula *n_entries = 1; /* shut up gcc */ 1028379bc100SJani Nikula MISSING_CASE(voltage); 1029379bc100SJani Nikula } 1030379bc100SJani Nikula return NULL; 1031379bc100SJani Nikula } else { 1032a8143150SJosé Roberto de Souza return cnl_get_buf_trans_dp(encoder, n_entries); 1033379bc100SJani Nikula } 1034379bc100SJani Nikula } 1035379bc100SJani Nikula 1036379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 1037a8143150SJosé Roberto de Souza icl_get_combo_buf_trans(struct intel_encoder *encoder, int type, int rate, 10384a8134d5SMatt Roper int *n_entries) 1039379bc100SJani Nikula { 1040a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1041a8143150SJosé Roberto de Souza 1042379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) { 1043379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi); 1044379bc100SJani Nikula return icl_combo_phy_ddi_translations_hdmi; 1045379bc100SJani Nikula } else if (rate > 540000 && type == INTEL_OUTPUT_EDP) { 1046379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr3); 1047379bc100SJani Nikula return icl_combo_phy_ddi_translations_edp_hbr3; 1048379bc100SJani Nikula } else if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) { 1049379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2); 1050379bc100SJani Nikula return icl_combo_phy_ddi_translations_edp_hbr2; 1051379bc100SJani Nikula } 1052379bc100SJani Nikula 1053379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_dp_hbr2); 1054379bc100SJani Nikula return icl_combo_phy_ddi_translations_dp_hbr2; 1055379bc100SJani Nikula } 1056379bc100SJani Nikula 10579f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans * 1058a8143150SJosé Roberto de Souza icl_get_mg_buf_trans(struct intel_encoder *encoder, int type, int rate, 10599f7ffa29SJosé Roberto de Souza int *n_entries) 10609f7ffa29SJosé Roberto de Souza { 10619f7ffa29SJosé Roberto de Souza if (type == INTEL_OUTPUT_HDMI) { 10629f7ffa29SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_hdmi); 10639f7ffa29SJosé Roberto de Souza return icl_mg_phy_ddi_translations_hdmi; 10649f7ffa29SJosé Roberto de Souza } else if (rate > 270000) { 10659f7ffa29SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_hbr2_hbr3); 10669f7ffa29SJosé Roberto de Souza return icl_mg_phy_ddi_translations_hbr2_hbr3; 10679f7ffa29SJosé Roberto de Souza } 10689f7ffa29SJosé Roberto de Souza 10699f7ffa29SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_rbr_hbr); 10709f7ffa29SJosé Roberto de Souza return icl_mg_phy_ddi_translations_rbr_hbr; 10719f7ffa29SJosé Roberto de Souza } 10729f7ffa29SJosé Roberto de Souza 1073bd3cf6f7SJosé Roberto de Souza static const struct cnl_ddi_buf_trans * 1074a8143150SJosé Roberto de Souza ehl_get_combo_buf_trans(struct intel_encoder *encoder, int type, int rate, 1075b42d5a67SJosé Roberto de Souza int *n_entries) 1076b42d5a67SJosé Roberto de Souza { 1077a2ae2010SJosé Roberto de Souza if (type != INTEL_OUTPUT_HDMI && type != INTEL_OUTPUT_EDP) { 1078a2ae2010SJosé Roberto de Souza *n_entries = ARRAY_SIZE(ehl_combo_phy_ddi_translations_dp); 1079a2ae2010SJosé Roberto de Souza return ehl_combo_phy_ddi_translations_dp; 1080b42d5a67SJosé Roberto de Souza } 1081b42d5a67SJosé Roberto de Souza 1082a8143150SJosé Roberto de Souza return icl_get_combo_buf_trans(encoder, type, rate, n_entries); 1083b42d5a67SJosé Roberto de Souza } 1084b42d5a67SJosé Roberto de Souza 1085b42d5a67SJosé Roberto de Souza static const struct cnl_ddi_buf_trans * 1086a8143150SJosé Roberto de Souza tgl_get_combo_buf_trans(struct intel_encoder *encoder, int type, int rate, 1087bd3cf6f7SJosé Roberto de Souza int *n_entries) 1088bd3cf6f7SJosé Roberto de Souza { 108981619f4aSJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 109081619f4aSJosé Roberto de Souza 1091*a8c90bc1SJosé Roberto de Souza switch (type) { 1092*a8c90bc1SJosé Roberto de Souza case INTEL_OUTPUT_HDMI: 1093*a8c90bc1SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi); 1094*a8c90bc1SJosé Roberto de Souza return icl_combo_phy_ddi_translations_hdmi; 1095*a8c90bc1SJosé Roberto de Souza case INTEL_OUTPUT_EDP: 1096*a8c90bc1SJosé Roberto de Souza if (dev_priv->vbt.edp.hobl) { 109781619f4aSJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 109881619f4aSJosé Roberto de Souza 109981619f4aSJosé Roberto de Souza if (!intel_dp->hobl_failed && rate <= 540000) { 110081619f4aSJosé Roberto de Souza /* Same table applies to TGL, RKL and DG1 */ 110181619f4aSJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_edp_hbr2_hobl); 110281619f4aSJosé Roberto de Souza return tgl_combo_phy_ddi_translations_edp_hbr2_hobl; 110381619f4aSJosé Roberto de Souza } 110481619f4aSJosé Roberto de Souza } 110581619f4aSJosé Roberto de Souza 1106*a8c90bc1SJosé Roberto de Souza if (rate > 540000) { 1107*a8c90bc1SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr3); 1108*a8c90bc1SJosé Roberto de Souza return icl_combo_phy_ddi_translations_edp_hbr3; 1109*a8c90bc1SJosé Roberto de Souza } else if (dev_priv->vbt.edp.low_vswing) { 1110*a8c90bc1SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2); 1111*a8c90bc1SJosé Roberto de Souza return icl_combo_phy_ddi_translations_edp_hbr2; 1112*a8c90bc1SJosé Roberto de Souza } 1113*a8c90bc1SJosé Roberto de Souza /* fall through */ 1114*a8c90bc1SJosé Roberto de Souza default: 1115*a8c90bc1SJosé Roberto de Souza /* All combo DP and eDP ports that do not support low_vswing */ 1116*a8c90bc1SJosé Roberto de Souza if (rate > 270000) { 111704dfb1acSJosé Roberto de Souza if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) { 111804dfb1acSJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_uy_combo_phy_ddi_translations_dp_hbr2); 111904dfb1acSJosé Roberto de Souza return tgl_uy_combo_phy_ddi_translations_dp_hbr2; 112004dfb1acSJosé Roberto de Souza } 112104dfb1acSJosé Roberto de Souza 1122bd3cf6f7SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr2); 1123bd3cf6f7SJosé Roberto de Souza return tgl_combo_phy_ddi_translations_dp_hbr2; 1124bd3cf6f7SJosé Roberto de Souza } 1125bd3cf6f7SJosé Roberto de Souza 1126bd3cf6f7SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr); 1127bd3cf6f7SJosé Roberto de Souza return tgl_combo_phy_ddi_translations_dp_hbr; 1128bd3cf6f7SJosé Roberto de Souza } 1129*a8c90bc1SJosé Roberto de Souza } 1130bd3cf6f7SJosé Roberto de Souza 11319fa67699SJosé Roberto de Souza static const struct tgl_dkl_phy_ddi_buf_trans * 1132a8143150SJosé Roberto de Souza tgl_get_dkl_buf_trans(struct intel_encoder *encoder, int type, int rate, 11339fa67699SJosé Roberto de Souza int *n_entries) 11349fa67699SJosé Roberto de Souza { 11359fa67699SJosé Roberto de Souza if (type == INTEL_OUTPUT_HDMI) { 11369fa67699SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_dkl_phy_hdmi_ddi_trans); 11379fa67699SJosé Roberto de Souza return tgl_dkl_phy_hdmi_ddi_trans; 11389fa67699SJosé Roberto de Souza } else if (rate > 270000) { 11399fa67699SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans_hbr2); 11409fa67699SJosé Roberto de Souza return tgl_dkl_phy_dp_ddi_trans_hbr2; 11419fa67699SJosé Roberto de Souza } 11429fa67699SJosé Roberto de Souza 11439fa67699SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans); 11449fa67699SJosé Roberto de Souza return tgl_dkl_phy_dp_ddi_trans; 11459fa67699SJosé Roberto de Souza } 11469fa67699SJosé Roberto de Souza 11470aed3bdeSJani Nikula static int intel_ddi_hdmi_level(struct intel_encoder *encoder) 1148379bc100SJani Nikula { 11490aed3bdeSJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1150379bc100SJani Nikula int n_entries, level, default_entry; 11510aed3bdeSJani Nikula enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 1152379bc100SJani Nikula 1153978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 1154978c3e53SClinton A Taylor if (intel_phy_is_combo(dev_priv, phy)) 1155a8143150SJosé Roberto de Souza tgl_get_combo_buf_trans(encoder, INTEL_OUTPUT_HDMI, 1156978c3e53SClinton A Taylor 0, &n_entries); 1157978c3e53SClinton A Taylor else 1158a8143150SJosé Roberto de Souza tgl_get_dkl_buf_trans(encoder, INTEL_OUTPUT_HDMI, 0, 11599fa67699SJosé Roberto de Souza &n_entries); 1160978c3e53SClinton A Taylor default_entry = n_entries - 1; 1161978c3e53SClinton A Taylor } else if (INTEL_GEN(dev_priv) == 11) { 1162d8fe2ab6SMatt Roper if (intel_phy_is_combo(dev_priv, phy)) 1163a8143150SJosé Roberto de Souza icl_get_combo_buf_trans(encoder, INTEL_OUTPUT_HDMI, 1164379bc100SJani Nikula 0, &n_entries); 1165379bc100SJani Nikula else 1166a8143150SJosé Roberto de Souza icl_get_mg_buf_trans(encoder, INTEL_OUTPUT_HDMI, 0, 11679f7ffa29SJosé Roberto de Souza &n_entries); 1168379bc100SJani Nikula default_entry = n_entries - 1; 1169379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 1170a8143150SJosé Roberto de Souza cnl_get_buf_trans_hdmi(encoder, &n_entries); 1171379bc100SJani Nikula default_entry = n_entries - 1; 1172379bc100SJani Nikula } else if (IS_GEN9_LP(dev_priv)) { 1173a8143150SJosé Roberto de Souza bxt_get_buf_trans_hdmi(encoder, &n_entries); 1174379bc100SJani Nikula default_entry = n_entries - 1; 1175379bc100SJani Nikula } else if (IS_GEN9_BC(dev_priv)) { 1176a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1177379bc100SJani Nikula default_entry = 8; 1178379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 1179a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1180379bc100SJani Nikula default_entry = 7; 1181379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 1182a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1183379bc100SJani Nikula default_entry = 6; 1184379bc100SJani Nikula } else { 11851de143ccSPankaj Bharadiya drm_WARN(&dev_priv->drm, 1, "ddi translation table missing\n"); 1186379bc100SJani Nikula return 0; 1187379bc100SJani Nikula } 1188379bc100SJani Nikula 11891de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, n_entries == 0)) 1190379bc100SJani Nikula return 0; 11917a0073d6SJani Nikula 11920aed3bdeSJani Nikula level = intel_bios_hdmi_level_shift(encoder); 11930aed3bdeSJani Nikula if (level < 0) 11947a0073d6SJani Nikula level = default_entry; 11957a0073d6SJani Nikula 11961de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 1197379bc100SJani Nikula level = n_entries - 1; 1198379bc100SJani Nikula 1199379bc100SJani Nikula return level; 1200379bc100SJani Nikula } 1201379bc100SJani Nikula 1202379bc100SJani Nikula /* 1203379bc100SJani Nikula * Starting with Haswell, DDI port buffers must be programmed with correct 1204379bc100SJani Nikula * values in advance. This function programs the correct values for 1205379bc100SJani Nikula * DP/eDP/FDI use cases. 1206379bc100SJani Nikula */ 1207379bc100SJani Nikula static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder, 1208379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 1209379bc100SJani Nikula { 1210379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1211379bc100SJani Nikula u32 iboost_bit = 0; 1212379bc100SJani Nikula int i, n_entries; 1213379bc100SJani Nikula enum port port = encoder->port; 1214379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations; 1215379bc100SJani Nikula 1216379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) 1217379bc100SJani Nikula ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv, 1218379bc100SJani Nikula &n_entries); 1219379bc100SJani Nikula else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) 1220f0e86e05SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_edp(encoder, 1221379bc100SJani Nikula &n_entries); 1222379bc100SJani Nikula else 1223f0e86e05SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_dp(encoder, 1224379bc100SJani Nikula &n_entries); 1225379bc100SJani Nikula 1226379bc100SJani Nikula /* If we're boosting the current, set bit 31 of trans1 */ 1227605a1872SJani Nikula if (IS_GEN9_BC(dev_priv) && intel_bios_dp_boost_level(encoder)) 1228379bc100SJani Nikula iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; 1229379bc100SJani Nikula 1230379bc100SJani Nikula for (i = 0; i < n_entries; i++) { 1231f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, i), 1232379bc100SJani Nikula ddi_translations[i].trans1 | iboost_bit); 1233f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, i), 1234379bc100SJani Nikula ddi_translations[i].trans2); 1235379bc100SJani Nikula } 1236379bc100SJani Nikula } 1237379bc100SJani Nikula 1238379bc100SJani Nikula /* 1239379bc100SJani Nikula * Starting with Haswell, DDI port buffers must be programmed with correct 1240379bc100SJani Nikula * values in advance. This function programs the correct values for 1241379bc100SJani Nikula * HDMI/DVI use cases. 1242379bc100SJani Nikula */ 1243379bc100SJani Nikula static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder, 1244379bc100SJani Nikula int level) 1245379bc100SJani Nikula { 1246379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1247379bc100SJani Nikula u32 iboost_bit = 0; 1248379bc100SJani Nikula int n_entries; 1249379bc100SJani Nikula enum port port = encoder->port; 1250379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations; 1251379bc100SJani Nikula 1252a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1253379bc100SJani Nikula 12541de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 1255379bc100SJani Nikula return; 12561de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 1257379bc100SJani Nikula level = n_entries - 1; 1258379bc100SJani Nikula 1259379bc100SJani Nikula /* If we're boosting the current, set bit 31 of trans1 */ 126001a60883SJani Nikula if (IS_GEN9_BC(dev_priv) && intel_bios_hdmi_boost_level(encoder)) 1261379bc100SJani Nikula iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; 1262379bc100SJani Nikula 1263379bc100SJani Nikula /* Entry 9 is for HDMI: */ 1264f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, 9), 1265379bc100SJani Nikula ddi_translations[level].trans1 | iboost_bit); 1266f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, 9), 1267379bc100SJani Nikula ddi_translations[level].trans2); 1268379bc100SJani Nikula } 1269379bc100SJani Nikula 1270379bc100SJani Nikula static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, 1271379bc100SJani Nikula enum port port) 1272379bc100SJani Nikula { 12735a2ad99bSManasi Navare if (IS_BROXTON(dev_priv)) { 12745a2ad99bSManasi Navare udelay(16); 1275379bc100SJani Nikula return; 1276379bc100SJani Nikula } 12775a2ad99bSManasi Navare 12785a2ad99bSManasi Navare if (wait_for_us((intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 12795a2ad99bSManasi Navare DDI_BUF_IS_IDLE), 8)) 12805a2ad99bSManasi Navare drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get idle\n", 128147bdb1caSJani Nikula port_name(port)); 1282379bc100SJani Nikula } 1283379bc100SJani Nikula 1284e828da30SManasi Navare static void intel_wait_ddi_buf_active(struct drm_i915_private *dev_priv, 1285e828da30SManasi Navare enum port port) 1286e828da30SManasi Navare { 1287e828da30SManasi Navare /* Wait > 518 usecs for DDI_BUF_CTL to be non idle */ 1288e828da30SManasi Navare if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { 1289e828da30SManasi Navare usleep_range(518, 1000); 1290e828da30SManasi Navare return; 1291e828da30SManasi Navare } 1292e828da30SManasi Navare 1293e828da30SManasi Navare if (wait_for_us(!(intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 1294e828da30SManasi Navare DDI_BUF_IS_IDLE), 500)) 1295e828da30SManasi Navare drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get active\n", 1296e828da30SManasi Navare port_name(port)); 1297e828da30SManasi Navare } 1298e828da30SManasi Navare 1299379bc100SJani Nikula static u32 hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll) 1300379bc100SJani Nikula { 1301379bc100SJani Nikula switch (pll->info->id) { 1302379bc100SJani Nikula case DPLL_ID_WRPLL1: 1303379bc100SJani Nikula return PORT_CLK_SEL_WRPLL1; 1304379bc100SJani Nikula case DPLL_ID_WRPLL2: 1305379bc100SJani Nikula return PORT_CLK_SEL_WRPLL2; 1306379bc100SJani Nikula case DPLL_ID_SPLL: 1307379bc100SJani Nikula return PORT_CLK_SEL_SPLL; 1308379bc100SJani Nikula case DPLL_ID_LCPLL_810: 1309379bc100SJani Nikula return PORT_CLK_SEL_LCPLL_810; 1310379bc100SJani Nikula case DPLL_ID_LCPLL_1350: 1311379bc100SJani Nikula return PORT_CLK_SEL_LCPLL_1350; 1312379bc100SJani Nikula case DPLL_ID_LCPLL_2700: 1313379bc100SJani Nikula return PORT_CLK_SEL_LCPLL_2700; 1314379bc100SJani Nikula default: 1315379bc100SJani Nikula MISSING_CASE(pll->info->id); 1316379bc100SJani Nikula return PORT_CLK_SEL_NONE; 1317379bc100SJani Nikula } 1318379bc100SJani Nikula } 1319379bc100SJani Nikula 1320379bc100SJani Nikula static u32 icl_pll_to_ddi_clk_sel(struct intel_encoder *encoder, 1321379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 1322379bc100SJani Nikula { 1323379bc100SJani Nikula const struct intel_shared_dpll *pll = crtc_state->shared_dpll; 1324379bc100SJani Nikula int clock = crtc_state->port_clock; 1325379bc100SJani Nikula const enum intel_dpll_id id = pll->info->id; 1326379bc100SJani Nikula 1327379bc100SJani Nikula switch (id) { 1328379bc100SJani Nikula default: 1329379bc100SJani Nikula /* 1330379bc100SJani Nikula * DPLL_ID_ICL_DPLL0 and DPLL_ID_ICL_DPLL1 should not be used 1331379bc100SJani Nikula * here, so do warn if this get passed in 1332379bc100SJani Nikula */ 1333379bc100SJani Nikula MISSING_CASE(id); 1334379bc100SJani Nikula return DDI_CLK_SEL_NONE; 1335379bc100SJani Nikula case DPLL_ID_ICL_TBTPLL: 1336379bc100SJani Nikula switch (clock) { 1337379bc100SJani Nikula case 162000: 1338379bc100SJani Nikula return DDI_CLK_SEL_TBT_162; 1339379bc100SJani Nikula case 270000: 1340379bc100SJani Nikula return DDI_CLK_SEL_TBT_270; 1341379bc100SJani Nikula case 540000: 1342379bc100SJani Nikula return DDI_CLK_SEL_TBT_540; 1343379bc100SJani Nikula case 810000: 1344379bc100SJani Nikula return DDI_CLK_SEL_TBT_810; 1345379bc100SJani Nikula default: 1346379bc100SJani Nikula MISSING_CASE(clock); 1347379bc100SJani Nikula return DDI_CLK_SEL_NONE; 1348379bc100SJani Nikula } 1349379bc100SJani Nikula case DPLL_ID_ICL_MGPLL1: 1350379bc100SJani Nikula case DPLL_ID_ICL_MGPLL2: 1351379bc100SJani Nikula case DPLL_ID_ICL_MGPLL3: 1352379bc100SJani Nikula case DPLL_ID_ICL_MGPLL4: 13536677c3b1SJosé Roberto de Souza case DPLL_ID_TGL_MGPLL5: 13546677c3b1SJosé Roberto de Souza case DPLL_ID_TGL_MGPLL6: 1355379bc100SJani Nikula return DDI_CLK_SEL_MG; 1356379bc100SJani Nikula } 1357379bc100SJani Nikula } 1358379bc100SJani Nikula 1359379bc100SJani Nikula /* Starting with Haswell, different DDI ports can work in FDI mode for 1360379bc100SJani Nikula * connection to the PCH-located connectors. For this, it is necessary to train 1361379bc100SJani Nikula * both the DDI port and PCH receiver for the desired DDI buffer settings. 1362379bc100SJani Nikula * 1363379bc100SJani Nikula * The recommended port to work in FDI mode is DDI E, which we use here. Also, 1364379bc100SJani Nikula * please note that when FDI mode is active on DDI E, it shares 2 lines with 1365379bc100SJani Nikula * DDI A (which is used for eDP) 1366379bc100SJani Nikula */ 1367379bc100SJani Nikula 13686a6d79deSVille Syrjälä void hsw_fdi_link_train(struct intel_encoder *encoder, 1369379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 1370379bc100SJani Nikula { 13716a6d79deSVille Syrjälä struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 13726a6d79deSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1373379bc100SJani Nikula u32 temp, i, rx_ctl_val, ddi_pll_sel; 1374379bc100SJani Nikula 1375379bc100SJani Nikula intel_prepare_dp_ddi_buffers(encoder, crtc_state); 1376379bc100SJani Nikula 1377379bc100SJani Nikula /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the 1378379bc100SJani Nikula * mode set "sequence for CRT port" document: 1379379bc100SJani Nikula * - TP1 to TP2 time with the default value 1380379bc100SJani Nikula * - FDI delay to 90h 1381379bc100SJani Nikula * 1382379bc100SJani Nikula * WaFDIAutoLinkSetTimingOverrride:hsw 1383379bc100SJani Nikula */ 1384f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), 1385f7960e7fSJani Nikula FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2) | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); 1386379bc100SJani Nikula 1387379bc100SJani Nikula /* Enable the PCH Receiver FDI PLL */ 1388379bc100SJani Nikula rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE | 1389379bc100SJani Nikula FDI_RX_PLL_ENABLE | 1390379bc100SJani Nikula FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); 1391f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1392f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A)); 1393379bc100SJani Nikula udelay(220); 1394379bc100SJani Nikula 1395379bc100SJani Nikula /* Switch from Rawclk to PCDclk */ 1396379bc100SJani Nikula rx_ctl_val |= FDI_PCDCLK; 1397f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1398379bc100SJani Nikula 1399379bc100SJani Nikula /* Configure Port Clock Select */ 1400379bc100SJani Nikula ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll); 1401f7960e7fSJani Nikula intel_de_write(dev_priv, PORT_CLK_SEL(PORT_E), ddi_pll_sel); 14021de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, ddi_pll_sel != PORT_CLK_SEL_SPLL); 1403379bc100SJani Nikula 1404379bc100SJani Nikula /* Start the training iterating through available voltages and emphasis, 1405379bc100SJani Nikula * testing each value twice. */ 1406379bc100SJani Nikula for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) { 1407379bc100SJani Nikula /* Configure DP_TP_CTL with auto-training */ 1408f7960e7fSJani Nikula intel_de_write(dev_priv, DP_TP_CTL(PORT_E), 14097db8736dSVille Syrjälä DP_TP_CTL_FDI_AUTOTRAIN | 14107db8736dSVille Syrjälä DP_TP_CTL_ENHANCED_FRAME_ENABLE | 14117db8736dSVille Syrjälä DP_TP_CTL_LINK_TRAIN_PAT1 | 14127db8736dSVille Syrjälä DP_TP_CTL_ENABLE); 1413379bc100SJani Nikula 1414379bc100SJani Nikula /* Configure and enable DDI_BUF_CTL for DDI E with next voltage. 1415379bc100SJani Nikula * DDI E does not support port reversal, the functionality is 1416379bc100SJani Nikula * achieved on the PCH side in FDI_RX_CTL, so no need to set the 1417379bc100SJani Nikula * port reversal bit */ 1418f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(PORT_E), 1419f7960e7fSJani Nikula DDI_BUF_CTL_ENABLE | ((crtc_state->fdi_lanes - 1) << 1) | DDI_BUF_TRANS_SELECT(i / 2)); 1420f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DDI_BUF_CTL(PORT_E)); 1421379bc100SJani Nikula 1422379bc100SJani Nikula udelay(600); 1423379bc100SJani Nikula 1424379bc100SJani Nikula /* Program PCH FDI Receiver TU */ 1425f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64)); 1426379bc100SJani Nikula 1427379bc100SJani Nikula /* Enable PCH FDI Receiver with auto-training */ 1428379bc100SJani Nikula rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO; 1429f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1430f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A)); 1431379bc100SJani Nikula 1432379bc100SJani Nikula /* Wait for FDI receiver lane calibration */ 1433379bc100SJani Nikula udelay(30); 1434379bc100SJani Nikula 1435379bc100SJani Nikula /* Unset FDI_RX_MISC pwrdn lanes */ 1436f7960e7fSJani Nikula temp = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1437379bc100SJani Nikula temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 1438f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), temp); 1439f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1440379bc100SJani Nikula 1441379bc100SJani Nikula /* Wait for FDI auto training time */ 1442379bc100SJani Nikula udelay(5); 1443379bc100SJani Nikula 1444f7960e7fSJani Nikula temp = intel_de_read(dev_priv, DP_TP_STATUS(PORT_E)); 1445379bc100SJani Nikula if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { 144647bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 144747bdb1caSJani Nikula "FDI link training done on step %d\n", i); 1448379bc100SJani Nikula break; 1449379bc100SJani Nikula } 1450379bc100SJani Nikula 1451379bc100SJani Nikula /* 1452379bc100SJani Nikula * Leave things enabled even if we failed to train FDI. 1453379bc100SJani Nikula * Results in less fireworks from the state checker. 1454379bc100SJani Nikula */ 1455379bc100SJani Nikula if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) { 145647bdb1caSJani Nikula drm_err(&dev_priv->drm, "FDI link training failed!\n"); 1457379bc100SJani Nikula break; 1458379bc100SJani Nikula } 1459379bc100SJani Nikula 1460379bc100SJani Nikula rx_ctl_val &= ~FDI_RX_ENABLE; 1461f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1462f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A)); 1463379bc100SJani Nikula 1464f7960e7fSJani Nikula temp = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_E)); 1465379bc100SJani Nikula temp &= ~DDI_BUF_CTL_ENABLE; 1466f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(PORT_E), temp); 1467f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DDI_BUF_CTL(PORT_E)); 1468379bc100SJani Nikula 1469379bc100SJani Nikula /* Disable DP_TP_CTL and FDI_RX_CTL and retry */ 1470f7960e7fSJani Nikula temp = intel_de_read(dev_priv, DP_TP_CTL(PORT_E)); 1471379bc100SJani Nikula temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 1472379bc100SJani Nikula temp |= DP_TP_CTL_LINK_TRAIN_PAT1; 1473f7960e7fSJani Nikula intel_de_write(dev_priv, DP_TP_CTL(PORT_E), temp); 1474f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DP_TP_CTL(PORT_E)); 1475379bc100SJani Nikula 1476379bc100SJani Nikula intel_wait_ddi_buf_idle(dev_priv, PORT_E); 1477379bc100SJani Nikula 1478379bc100SJani Nikula /* Reset FDI_RX_MISC pwrdn lanes */ 1479f7960e7fSJani Nikula temp = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1480379bc100SJani Nikula temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 1481379bc100SJani Nikula temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); 1482f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), temp); 1483f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1484379bc100SJani Nikula } 1485379bc100SJani Nikula 1486379bc100SJani Nikula /* Enable normal pixel sending for FDI */ 1487f7960e7fSJani Nikula intel_de_write(dev_priv, DP_TP_CTL(PORT_E), 14887db8736dSVille Syrjälä DP_TP_CTL_FDI_AUTOTRAIN | 14897db8736dSVille Syrjälä DP_TP_CTL_LINK_TRAIN_NORMAL | 14907db8736dSVille Syrjälä DP_TP_CTL_ENHANCED_FRAME_ENABLE | 14917db8736dSVille Syrjälä DP_TP_CTL_ENABLE); 1492379bc100SJani Nikula } 1493379bc100SJani Nikula 1494379bc100SJani Nikula static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder) 1495379bc100SJani Nikula { 1496b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 14977801f3b7SLucas De Marchi struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 1498379bc100SJani Nikula 14997801f3b7SLucas De Marchi intel_dp->DP = dig_port->saved_port_bits | 1500379bc100SJani Nikula DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0); 1501379bc100SJani Nikula intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count); 1502379bc100SJani Nikula } 1503379bc100SJani Nikula 1504379bc100SJani Nikula static int icl_calc_tbt_pll_link(struct drm_i915_private *dev_priv, 1505379bc100SJani Nikula enum port port) 1506379bc100SJani Nikula { 1507f7960e7fSJani Nikula u32 val = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK; 1508379bc100SJani Nikula 1509379bc100SJani Nikula switch (val) { 1510379bc100SJani Nikula case DDI_CLK_SEL_NONE: 1511379bc100SJani Nikula return 0; 1512379bc100SJani Nikula case DDI_CLK_SEL_TBT_162: 1513379bc100SJani Nikula return 162000; 1514379bc100SJani Nikula case DDI_CLK_SEL_TBT_270: 1515379bc100SJani Nikula return 270000; 1516379bc100SJani Nikula case DDI_CLK_SEL_TBT_540: 1517379bc100SJani Nikula return 540000; 1518379bc100SJani Nikula case DDI_CLK_SEL_TBT_810: 1519379bc100SJani Nikula return 810000; 1520379bc100SJani Nikula default: 1521379bc100SJani Nikula MISSING_CASE(val); 1522379bc100SJani Nikula return 0; 1523379bc100SJani Nikula } 1524379bc100SJani Nikula } 1525379bc100SJani Nikula 1526379bc100SJani Nikula static void ddi_dotclock_get(struct intel_crtc_state *pipe_config) 1527379bc100SJani Nikula { 1528379bc100SJani Nikula int dotclock; 1529379bc100SJani Nikula 1530379bc100SJani Nikula if (pipe_config->has_pch_encoder) 1531379bc100SJani Nikula dotclock = intel_dotclock_calculate(pipe_config->port_clock, 1532379bc100SJani Nikula &pipe_config->fdi_m_n); 1533379bc100SJani Nikula else if (intel_crtc_has_dp_encoder(pipe_config)) 1534379bc100SJani Nikula dotclock = intel_dotclock_calculate(pipe_config->port_clock, 1535379bc100SJani Nikula &pipe_config->dp_m_n); 15362969a78aSImre Deak else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24) 15372969a78aSImre Deak dotclock = pipe_config->port_clock * 24 / pipe_config->pipe_bpp; 1538379bc100SJani Nikula else 1539379bc100SJani Nikula dotclock = pipe_config->port_clock; 1540379bc100SJani Nikula 1541379bc100SJani Nikula if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 && 1542379bc100SJani Nikula !intel_crtc_has_dp_encoder(pipe_config)) 1543379bc100SJani Nikula dotclock *= 2; 1544379bc100SJani Nikula 1545379bc100SJani Nikula if (pipe_config->pixel_multiplier) 1546379bc100SJani Nikula dotclock /= pipe_config->pixel_multiplier; 1547379bc100SJani Nikula 15481326a92cSMaarten Lankhorst pipe_config->hw.adjusted_mode.crtc_clock = dotclock; 1549379bc100SJani Nikula } 1550379bc100SJani Nikula 1551379bc100SJani Nikula static void intel_ddi_clock_get(struct intel_encoder *encoder, 1552379bc100SJani Nikula struct intel_crtc_state *pipe_config) 1553379bc100SJani Nikula { 1554379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 155556ed441aSMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 1556379bc100SJani Nikula 155756ed441aSMatt Roper if (intel_phy_is_tc(dev_priv, phy) && 155845e4728bSImre Deak intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll) == 155945e4728bSImre Deak DPLL_ID_ICL_TBTPLL) 156045e4728bSImre Deak pipe_config->port_clock = icl_calc_tbt_pll_link(dev_priv, 156145e4728bSImre Deak encoder->port); 156245e4728bSImre Deak else 1563b953eb21SImre Deak pipe_config->port_clock = 1564b953eb21SImre Deak intel_dpll_get_freq(dev_priv, pipe_config->shared_dpll); 156545e4728bSImre Deak 156645e4728bSImre Deak ddi_dotclock_get(pipe_config); 1567379bc100SJani Nikula } 1568379bc100SJani Nikula 15690c06fa15SGwan-gyeong Mun void intel_ddi_set_dp_msa(const struct intel_crtc_state *crtc_state, 15700c06fa15SGwan-gyeong Mun const struct drm_connector_state *conn_state) 1571379bc100SJani Nikula { 15722225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1573379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1574379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1575379bc100SJani Nikula u32 temp; 1576379bc100SJani Nikula 1577379bc100SJani Nikula if (!intel_crtc_has_dp_encoder(crtc_state)) 1578379bc100SJani Nikula return; 1579379bc100SJani Nikula 15801de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder)); 1581379bc100SJani Nikula 15823e706dffSVille Syrjälä temp = DP_MSA_MISC_SYNC_CLOCK; 1583379bc100SJani Nikula 1584379bc100SJani Nikula switch (crtc_state->pipe_bpp) { 1585379bc100SJani Nikula case 18: 15863e706dffSVille Syrjälä temp |= DP_MSA_MISC_6_BPC; 1587379bc100SJani Nikula break; 1588379bc100SJani Nikula case 24: 15893e706dffSVille Syrjälä temp |= DP_MSA_MISC_8_BPC; 1590379bc100SJani Nikula break; 1591379bc100SJani Nikula case 30: 15923e706dffSVille Syrjälä temp |= DP_MSA_MISC_10_BPC; 1593379bc100SJani Nikula break; 1594379bc100SJani Nikula case 36: 15953e706dffSVille Syrjälä temp |= DP_MSA_MISC_12_BPC; 1596379bc100SJani Nikula break; 1597379bc100SJani Nikula default: 1598379bc100SJani Nikula MISSING_CASE(crtc_state->pipe_bpp); 1599379bc100SJani Nikula break; 1600379bc100SJani Nikula } 1601379bc100SJani Nikula 1602cae154fcSVille Syrjälä /* nonsense combination */ 16031de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range && 1604cae154fcSVille Syrjälä crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB); 1605cae154fcSVille Syrjälä 1606cae154fcSVille Syrjälä if (crtc_state->limited_color_range) 16073e706dffSVille Syrjälä temp |= DP_MSA_MISC_COLOR_CEA_RGB; 1608cae154fcSVille Syrjälä 1609379bc100SJani Nikula /* 1610379bc100SJani Nikula * As per DP 1.2 spec section 2.3.4.3 while sending 1611379bc100SJani Nikula * YCBCR 444 signals we should program MSA MISC1/0 fields with 1612646d3dc8SVille Syrjälä * colorspace information. 1613379bc100SJani Nikula */ 1614379bc100SJani Nikula if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) 16153e706dffSVille Syrjälä temp |= DP_MSA_MISC_COLOR_YCBCR_444_BT709; 1616646d3dc8SVille Syrjälä 1617379bc100SJani Nikula /* 1618379bc100SJani Nikula * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication 1619379bc100SJani Nikula * of Color Encoding Format and Content Color Gamut] while sending 16200c06fa15SGwan-gyeong Mun * YCBCR 420, HDR BT.2020 signals we should program MSA MISC1 fields 16210c06fa15SGwan-gyeong Mun * which indicate VSC SDP for the Pixel Encoding/Colorimetry Format. 1622379bc100SJani Nikula */ 1623bd8c9ccaSGwan-gyeong Mun if (intel_dp_needs_vsc_sdp(crtc_state, conn_state)) 16243e706dffSVille Syrjälä temp |= DP_MSA_MISC_COLOR_VSC_SDP; 16250c06fa15SGwan-gyeong Mun 1626f7960e7fSJani Nikula intel_de_write(dev_priv, TRANS_MSA_MISC(cpu_transcoder), temp); 1627379bc100SJani Nikula } 1628379bc100SJani Nikula 1629dc5b8ed5SVille Syrjälä static u32 bdw_trans_port_sync_master_select(enum transcoder master_transcoder) 1630dc5b8ed5SVille Syrjälä { 1631dc5b8ed5SVille Syrjälä if (master_transcoder == TRANSCODER_EDP) 1632dc5b8ed5SVille Syrjälä return 0; 1633dc5b8ed5SVille Syrjälä else 1634dc5b8ed5SVille Syrjälä return master_transcoder + 1; 1635dc5b8ed5SVille Syrjälä } 1636dc5b8ed5SVille Syrjälä 163799389390SJosé Roberto de Souza /* 163899389390SJosé Roberto de Souza * Returns the TRANS_DDI_FUNC_CTL value based on CRTC state. 163999389390SJosé Roberto de Souza * 164099389390SJosé Roberto de Souza * Only intended to be used by intel_ddi_enable_transcoder_func() and 164199389390SJosé Roberto de Souza * intel_ddi_config_transcoder_func(). 164299389390SJosé Roberto de Souza */ 164399389390SJosé Roberto de Souza static u32 1644eed22a46SVille Syrjälä intel_ddi_transcoder_func_reg_val_get(struct intel_encoder *encoder, 1645eed22a46SVille Syrjälä const struct intel_crtc_state *crtc_state) 1646379bc100SJani Nikula { 16472225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1648379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1649379bc100SJani Nikula enum pipe pipe = crtc->pipe; 1650379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1651379bc100SJani Nikula enum port port = encoder->port; 1652379bc100SJani Nikula u32 temp; 1653379bc100SJani Nikula 1654379bc100SJani Nikula /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */ 1655379bc100SJani Nikula temp = TRANS_DDI_FUNC_ENABLE; 1656df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) 1657df16b636SMahesh Kumar temp |= TGL_TRANS_DDI_SELECT_PORT(port); 1658df16b636SMahesh Kumar else 1659379bc100SJani Nikula temp |= TRANS_DDI_SELECT_PORT(port); 1660379bc100SJani Nikula 1661379bc100SJani Nikula switch (crtc_state->pipe_bpp) { 1662379bc100SJani Nikula case 18: 1663379bc100SJani Nikula temp |= TRANS_DDI_BPC_6; 1664379bc100SJani Nikula break; 1665379bc100SJani Nikula case 24: 1666379bc100SJani Nikula temp |= TRANS_DDI_BPC_8; 1667379bc100SJani Nikula break; 1668379bc100SJani Nikula case 30: 1669379bc100SJani Nikula temp |= TRANS_DDI_BPC_10; 1670379bc100SJani Nikula break; 1671379bc100SJani Nikula case 36: 1672379bc100SJani Nikula temp |= TRANS_DDI_BPC_12; 1673379bc100SJani Nikula break; 1674379bc100SJani Nikula default: 1675379bc100SJani Nikula BUG(); 1676379bc100SJani Nikula } 1677379bc100SJani Nikula 16781326a92cSMaarten Lankhorst if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC) 1679379bc100SJani Nikula temp |= TRANS_DDI_PVSYNC; 16801326a92cSMaarten Lankhorst if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC) 1681379bc100SJani Nikula temp |= TRANS_DDI_PHSYNC; 1682379bc100SJani Nikula 1683379bc100SJani Nikula if (cpu_transcoder == TRANSCODER_EDP) { 1684379bc100SJani Nikula switch (pipe) { 1685379bc100SJani Nikula case PIPE_A: 1686379bc100SJani Nikula /* On Haswell, can only use the always-on power well for 1687379bc100SJani Nikula * eDP when not using the panel fitter, and when not 1688379bc100SJani Nikula * using motion blur mitigation (which we don't 1689379bc100SJani Nikula * support). */ 1690379bc100SJani Nikula if (crtc_state->pch_pfit.force_thru) 1691379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_A_ONOFF; 1692379bc100SJani Nikula else 1693379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_A_ON; 1694379bc100SJani Nikula break; 1695379bc100SJani Nikula case PIPE_B: 1696379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_B_ONOFF; 1697379bc100SJani Nikula break; 1698379bc100SJani Nikula case PIPE_C: 1699379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_C_ONOFF; 1700379bc100SJani Nikula break; 1701379bc100SJani Nikula default: 1702379bc100SJani Nikula BUG(); 1703379bc100SJani Nikula break; 1704379bc100SJani Nikula } 1705379bc100SJani Nikula } 1706379bc100SJani Nikula 1707379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 1708379bc100SJani Nikula if (crtc_state->has_hdmi_sink) 1709379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_HDMI; 1710379bc100SJani Nikula else 1711379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_DVI; 1712379bc100SJani Nikula 1713379bc100SJani Nikula if (crtc_state->hdmi_scrambling) 1714379bc100SJani Nikula temp |= TRANS_DDI_HDMI_SCRAMBLING; 1715379bc100SJani Nikula if (crtc_state->hdmi_high_tmds_clock_ratio) 1716379bc100SJani Nikula temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE; 1717379bc100SJani Nikula } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { 1718379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_FDI; 1719379bc100SJani Nikula temp |= (crtc_state->fdi_lanes - 1) << 1; 1720379bc100SJani Nikula } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) { 1721379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_DP_MST; 1722379bc100SJani Nikula temp |= DDI_PORT_WIDTH(crtc_state->lane_count); 1723b3545e08SLucas De Marchi 17246671c367SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 17256671c367SJosé Roberto de Souza enum transcoder master; 17266671c367SJosé Roberto de Souza 17276671c367SJosé Roberto de Souza master = crtc_state->mst_master_transcoder; 17281de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 17291de143ccSPankaj Bharadiya master == INVALID_TRANSCODER); 17306671c367SJosé Roberto de Souza temp |= TRANS_DDI_MST_TRANSPORT_SELECT(master); 17316671c367SJosé Roberto de Souza } 1732379bc100SJani Nikula } else { 1733379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_DP_SST; 1734379bc100SJani Nikula temp |= DDI_PORT_WIDTH(crtc_state->lane_count); 1735379bc100SJani Nikula } 1736379bc100SJani Nikula 1737dc5b8ed5SVille Syrjälä if (IS_GEN_RANGE(dev_priv, 8, 10) && 1738dc5b8ed5SVille Syrjälä crtc_state->master_transcoder != INVALID_TRANSCODER) { 1739dc5b8ed5SVille Syrjälä u8 master_select = 1740dc5b8ed5SVille Syrjälä bdw_trans_port_sync_master_select(crtc_state->master_transcoder); 1741dc5b8ed5SVille Syrjälä 1742dc5b8ed5SVille Syrjälä temp |= TRANS_DDI_PORT_SYNC_ENABLE | 1743dc5b8ed5SVille Syrjälä TRANS_DDI_PORT_SYNC_MASTER_SELECT(master_select); 1744dc5b8ed5SVille Syrjälä } 1745dc5b8ed5SVille Syrjälä 174699389390SJosé Roberto de Souza return temp; 174799389390SJosé Roberto de Souza } 174899389390SJosé Roberto de Souza 1749eed22a46SVille Syrjälä void intel_ddi_enable_transcoder_func(struct intel_encoder *encoder, 1750eed22a46SVille Syrjälä const struct intel_crtc_state *crtc_state) 175199389390SJosé Roberto de Souza { 17522225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 175399389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 175499389390SJosé Roberto de Souza enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 175599389390SJosé Roberto de Souza 1756589a4cd6SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) { 1757589a4cd6SVille Syrjälä enum transcoder master_transcoder = crtc_state->master_transcoder; 1758589a4cd6SVille Syrjälä u32 ctl2 = 0; 1759589a4cd6SVille Syrjälä 1760589a4cd6SVille Syrjälä if (master_transcoder != INVALID_TRANSCODER) { 1761dc5b8ed5SVille Syrjälä u8 master_select = 1762dc5b8ed5SVille Syrjälä bdw_trans_port_sync_master_select(master_transcoder); 1763589a4cd6SVille Syrjälä 1764589a4cd6SVille Syrjälä ctl2 |= PORT_SYNC_MODE_ENABLE | 1765d4d7d9caSVille Syrjälä PORT_SYNC_MODE_MASTER_SELECT(master_select); 1766589a4cd6SVille Syrjälä } 1767589a4cd6SVille Syrjälä 1768589a4cd6SVille Syrjälä intel_de_write(dev_priv, 1769589a4cd6SVille Syrjälä TRANS_DDI_FUNC_CTL2(cpu_transcoder), ctl2); 1770589a4cd6SVille Syrjälä } 1771589a4cd6SVille Syrjälä 1772580fbdc5SImre Deak intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), 1773580fbdc5SImre Deak intel_ddi_transcoder_func_reg_val_get(encoder, 1774580fbdc5SImre Deak crtc_state)); 177599389390SJosé Roberto de Souza } 177699389390SJosé Roberto de Souza 177799389390SJosé Roberto de Souza /* 177899389390SJosé Roberto de Souza * Same as intel_ddi_enable_transcoder_func(), but it does not set the enable 177999389390SJosé Roberto de Souza * bit. 178099389390SJosé Roberto de Souza */ 178199389390SJosé Roberto de Souza static void 1782eed22a46SVille Syrjälä intel_ddi_config_transcoder_func(struct intel_encoder *encoder, 1783eed22a46SVille Syrjälä const struct intel_crtc_state *crtc_state) 178499389390SJosé Roberto de Souza { 17852225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 178699389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 178799389390SJosé Roberto de Souza enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1788589a4cd6SVille Syrjälä u32 ctl; 178999389390SJosé Roberto de Souza 1790eed22a46SVille Syrjälä ctl = intel_ddi_transcoder_func_reg_val_get(encoder, crtc_state); 1791589a4cd6SVille Syrjälä ctl &= ~TRANS_DDI_FUNC_ENABLE; 1792589a4cd6SVille Syrjälä intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl); 1793379bc100SJani Nikula } 1794379bc100SJani Nikula 1795379bc100SJani Nikula void intel_ddi_disable_transcoder_func(const struct intel_crtc_state *crtc_state) 1796379bc100SJani Nikula { 17972225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1798379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1799379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1800589a4cd6SVille Syrjälä u32 ctl; 1801c59053dcSJosé Roberto de Souza 1802589a4cd6SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 1803589a4cd6SVille Syrjälä intel_de_write(dev_priv, 1804589a4cd6SVille Syrjälä TRANS_DDI_FUNC_CTL2(cpu_transcoder), 0); 1805589a4cd6SVille Syrjälä 1806589a4cd6SVille Syrjälä ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 1807dc5b8ed5SVille Syrjälä 1808589a4cd6SVille Syrjälä ctl &= ~TRANS_DDI_FUNC_ENABLE; 1809379bc100SJani Nikula 1810dc5b8ed5SVille Syrjälä if (IS_GEN_RANGE(dev_priv, 8, 10)) 1811dc5b8ed5SVille Syrjälä ctl &= ~(TRANS_DDI_PORT_SYNC_ENABLE | 1812dc5b8ed5SVille Syrjälä TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK); 1813dc5b8ed5SVille Syrjälä 1814df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) { 1815919e4f07SJosé Roberto de Souza if (!intel_dp_mst_is_master_trans(crtc_state)) { 1816589a4cd6SVille Syrjälä ctl &= ~(TGL_TRANS_DDI_PORT_MASK | 1817919e4f07SJosé Roberto de Souza TRANS_DDI_MODE_SELECT_MASK); 1818919e4f07SJosé Roberto de Souza } 1819df16b636SMahesh Kumar } else { 1820589a4cd6SVille Syrjälä ctl &= ~(TRANS_DDI_PORT_MASK | TRANS_DDI_MODE_SELECT_MASK); 1821df16b636SMahesh Kumar } 1822dc5b8ed5SVille Syrjälä 1823589a4cd6SVille Syrjälä intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl); 1824379bc100SJani Nikula 1825379bc100SJani Nikula if (dev_priv->quirks & QUIRK_INCREASE_DDI_DISABLED_TIME && 1826379bc100SJani Nikula intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 182747bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 182847bdb1caSJani Nikula "Quirk Increase DDI disabled time\n"); 1829379bc100SJani Nikula /* Quirk time at 100ms for reliable operation */ 1830379bc100SJani Nikula msleep(100); 1831379bc100SJani Nikula } 1832379bc100SJani Nikula } 1833379bc100SJani Nikula 1834379bc100SJani Nikula int intel_ddi_toggle_hdcp_signalling(struct intel_encoder *intel_encoder, 1835379bc100SJani Nikula bool enable) 1836379bc100SJani Nikula { 1837379bc100SJani Nikula struct drm_device *dev = intel_encoder->base.dev; 1838379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1839379bc100SJani Nikula intel_wakeref_t wakeref; 1840379bc100SJani Nikula enum pipe pipe = 0; 1841379bc100SJani Nikula int ret = 0; 1842379bc100SJani Nikula u32 tmp; 1843379bc100SJani Nikula 1844379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1845379bc100SJani Nikula intel_encoder->power_domain); 18461de143ccSPankaj Bharadiya if (drm_WARN_ON(dev, !wakeref)) 1847379bc100SJani Nikula return -ENXIO; 1848379bc100SJani Nikula 18491de143ccSPankaj Bharadiya if (drm_WARN_ON(dev, 18501de143ccSPankaj Bharadiya !intel_encoder->get_hw_state(intel_encoder, &pipe))) { 1851379bc100SJani Nikula ret = -EIO; 1852379bc100SJani Nikula goto out; 1853379bc100SJani Nikula } 1854379bc100SJani Nikula 1855f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe)); 1856379bc100SJani Nikula if (enable) 1857379bc100SJani Nikula tmp |= TRANS_DDI_HDCP_SIGNALLING; 1858379bc100SJani Nikula else 1859379bc100SJani Nikula tmp &= ~TRANS_DDI_HDCP_SIGNALLING; 1860f7960e7fSJani Nikula intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(pipe), tmp); 1861379bc100SJani Nikula out: 1862379bc100SJani Nikula intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref); 1863379bc100SJani Nikula return ret; 1864379bc100SJani Nikula } 1865379bc100SJani Nikula 1866379bc100SJani Nikula bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector) 1867379bc100SJani Nikula { 1868379bc100SJani Nikula struct drm_device *dev = intel_connector->base.dev; 1869379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1870fa7edcd2SVille Syrjälä struct intel_encoder *encoder = intel_attached_encoder(intel_connector); 1871379bc100SJani Nikula int type = intel_connector->base.connector_type; 1872379bc100SJani Nikula enum port port = encoder->port; 1873379bc100SJani Nikula enum transcoder cpu_transcoder; 1874379bc100SJani Nikula intel_wakeref_t wakeref; 1875379bc100SJani Nikula enum pipe pipe = 0; 1876379bc100SJani Nikula u32 tmp; 1877379bc100SJani Nikula bool ret; 1878379bc100SJani Nikula 1879379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1880379bc100SJani Nikula encoder->power_domain); 1881379bc100SJani Nikula if (!wakeref) 1882379bc100SJani Nikula return false; 1883379bc100SJani Nikula 1884379bc100SJani Nikula if (!encoder->get_hw_state(encoder, &pipe)) { 1885379bc100SJani Nikula ret = false; 1886379bc100SJani Nikula goto out; 1887379bc100SJani Nikula } 1888379bc100SJani Nikula 188910cf8e75SVille Syrjälä if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) 1890379bc100SJani Nikula cpu_transcoder = TRANSCODER_EDP; 1891379bc100SJani Nikula else 1892379bc100SJani Nikula cpu_transcoder = (enum transcoder) pipe; 1893379bc100SJani Nikula 1894f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 1895379bc100SJani Nikula 1896379bc100SJani Nikula switch (tmp & TRANS_DDI_MODE_SELECT_MASK) { 1897379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_HDMI: 1898379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DVI: 1899379bc100SJani Nikula ret = type == DRM_MODE_CONNECTOR_HDMIA; 1900379bc100SJani Nikula break; 1901379bc100SJani Nikula 1902379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_SST: 1903379bc100SJani Nikula ret = type == DRM_MODE_CONNECTOR_eDP || 1904379bc100SJani Nikula type == DRM_MODE_CONNECTOR_DisplayPort; 1905379bc100SJani Nikula break; 1906379bc100SJani Nikula 1907379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_MST: 1908379bc100SJani Nikula /* if the transcoder is in MST state then 1909379bc100SJani Nikula * connector isn't connected */ 1910379bc100SJani Nikula ret = false; 1911379bc100SJani Nikula break; 1912379bc100SJani Nikula 1913379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_FDI: 1914379bc100SJani Nikula ret = type == DRM_MODE_CONNECTOR_VGA; 1915379bc100SJani Nikula break; 1916379bc100SJani Nikula 1917379bc100SJani Nikula default: 1918379bc100SJani Nikula ret = false; 1919379bc100SJani Nikula break; 1920379bc100SJani Nikula } 1921379bc100SJani Nikula 1922379bc100SJani Nikula out: 1923379bc100SJani Nikula intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 1924379bc100SJani Nikula 1925379bc100SJani Nikula return ret; 1926379bc100SJani Nikula } 1927379bc100SJani Nikula 1928379bc100SJani Nikula static void intel_ddi_get_encoder_pipes(struct intel_encoder *encoder, 1929379bc100SJani Nikula u8 *pipe_mask, bool *is_dp_mst) 1930379bc100SJani Nikula { 1931379bc100SJani Nikula struct drm_device *dev = encoder->base.dev; 1932379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1933379bc100SJani Nikula enum port port = encoder->port; 1934379bc100SJani Nikula intel_wakeref_t wakeref; 1935379bc100SJani Nikula enum pipe p; 1936379bc100SJani Nikula u32 tmp; 1937379bc100SJani Nikula u8 mst_pipe_mask; 1938379bc100SJani Nikula 1939379bc100SJani Nikula *pipe_mask = 0; 1940379bc100SJani Nikula *is_dp_mst = false; 1941379bc100SJani Nikula 1942379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1943379bc100SJani Nikula encoder->power_domain); 1944379bc100SJani Nikula if (!wakeref) 1945379bc100SJani Nikula return; 1946379bc100SJani Nikula 1947f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 1948379bc100SJani Nikula if (!(tmp & DDI_BUF_CTL_ENABLE)) 1949379bc100SJani Nikula goto out; 1950379bc100SJani Nikula 195110cf8e75SVille Syrjälä if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) { 1952f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, 1953f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); 1954379bc100SJani Nikula 1955379bc100SJani Nikula switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 1956379bc100SJani Nikula default: 1957379bc100SJani Nikula MISSING_CASE(tmp & TRANS_DDI_EDP_INPUT_MASK); 1958379bc100SJani Nikula /* fallthrough */ 1959379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_A_ON: 1960379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_A_ONOFF: 1961379bc100SJani Nikula *pipe_mask = BIT(PIPE_A); 1962379bc100SJani Nikula break; 1963379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_B_ONOFF: 1964379bc100SJani Nikula *pipe_mask = BIT(PIPE_B); 1965379bc100SJani Nikula break; 1966379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_C_ONOFF: 1967379bc100SJani Nikula *pipe_mask = BIT(PIPE_C); 1968379bc100SJani Nikula break; 1969379bc100SJani Nikula } 1970379bc100SJani Nikula 1971379bc100SJani Nikula goto out; 1972379bc100SJani Nikula } 1973379bc100SJani Nikula 1974379bc100SJani Nikula mst_pipe_mask = 0; 1975379bc100SJani Nikula for_each_pipe(dev_priv, p) { 1976379bc100SJani Nikula enum transcoder cpu_transcoder = (enum transcoder)p; 1977df16b636SMahesh Kumar unsigned int port_mask, ddi_select; 19786aa3bef1SJosé Roberto de Souza intel_wakeref_t trans_wakeref; 19796aa3bef1SJosé Roberto de Souza 19806aa3bef1SJosé Roberto de Souza trans_wakeref = intel_display_power_get_if_enabled(dev_priv, 19816aa3bef1SJosé Roberto de Souza POWER_DOMAIN_TRANSCODER(cpu_transcoder)); 19826aa3bef1SJosé Roberto de Souza if (!trans_wakeref) 19836aa3bef1SJosé Roberto de Souza continue; 1984df16b636SMahesh Kumar 1985df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) { 1986df16b636SMahesh Kumar port_mask = TGL_TRANS_DDI_PORT_MASK; 1987df16b636SMahesh Kumar ddi_select = TGL_TRANS_DDI_SELECT_PORT(port); 1988df16b636SMahesh Kumar } else { 1989df16b636SMahesh Kumar port_mask = TRANS_DDI_PORT_MASK; 1990df16b636SMahesh Kumar ddi_select = TRANS_DDI_SELECT_PORT(port); 1991df16b636SMahesh Kumar } 1992379bc100SJani Nikula 1993f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, 1994f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(cpu_transcoder)); 19956aa3bef1SJosé Roberto de Souza intel_display_power_put(dev_priv, POWER_DOMAIN_TRANSCODER(cpu_transcoder), 19966aa3bef1SJosé Roberto de Souza trans_wakeref); 1997379bc100SJani Nikula 1998df16b636SMahesh Kumar if ((tmp & port_mask) != ddi_select) 1999379bc100SJani Nikula continue; 2000379bc100SJani Nikula 2001379bc100SJani Nikula if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == 2002379bc100SJani Nikula TRANS_DDI_MODE_SELECT_DP_MST) 2003379bc100SJani Nikula mst_pipe_mask |= BIT(p); 2004379bc100SJani Nikula 2005379bc100SJani Nikula *pipe_mask |= BIT(p); 2006379bc100SJani Nikula } 2007379bc100SJani Nikula 2008379bc100SJani Nikula if (!*pipe_mask) 200947bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 201047bdb1caSJani Nikula "No pipe for [ENCODER:%d:%s] found\n", 201166a990ddSVille Syrjälä encoder->base.base.id, encoder->base.name); 2012379bc100SJani Nikula 2013379bc100SJani Nikula if (!mst_pipe_mask && hweight8(*pipe_mask) > 1) { 201447bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 201547bdb1caSJani Nikula "Multiple pipes for [ENCODER:%d:%s] (pipe_mask %02x)\n", 201666a990ddSVille Syrjälä encoder->base.base.id, encoder->base.name, 201766a990ddSVille Syrjälä *pipe_mask); 2018379bc100SJani Nikula *pipe_mask = BIT(ffs(*pipe_mask) - 1); 2019379bc100SJani Nikula } 2020379bc100SJani Nikula 2021379bc100SJani Nikula if (mst_pipe_mask && mst_pipe_mask != *pipe_mask) 202247bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 202347bdb1caSJani Nikula "Conflicting MST and non-MST state for [ENCODER:%d:%s] (pipe_mask %02x mst_pipe_mask %02x)\n", 202466a990ddSVille Syrjälä encoder->base.base.id, encoder->base.name, 202566a990ddSVille Syrjälä *pipe_mask, mst_pipe_mask); 2026379bc100SJani Nikula else 2027379bc100SJani Nikula *is_dp_mst = mst_pipe_mask; 2028379bc100SJani Nikula 2029379bc100SJani Nikula out: 2030379bc100SJani Nikula if (*pipe_mask && IS_GEN9_LP(dev_priv)) { 2031f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, BXT_PHY_CTL(port)); 2032379bc100SJani Nikula if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK | 2033379bc100SJani Nikula BXT_PHY_LANE_POWERDOWN_ACK | 2034379bc100SJani Nikula BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED) 203547bdb1caSJani Nikula drm_err(&dev_priv->drm, 203647bdb1caSJani Nikula "[ENCODER:%d:%s] enabled but PHY powered down? (PHY_CTL %08x)\n", 203747bdb1caSJani Nikula encoder->base.base.id, encoder->base.name, tmp); 2038379bc100SJani Nikula } 2039379bc100SJani Nikula 2040379bc100SJani Nikula intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 2041379bc100SJani Nikula } 2042379bc100SJani Nikula 2043379bc100SJani Nikula bool intel_ddi_get_hw_state(struct intel_encoder *encoder, 2044379bc100SJani Nikula enum pipe *pipe) 2045379bc100SJani Nikula { 2046379bc100SJani Nikula u8 pipe_mask; 2047379bc100SJani Nikula bool is_mst; 2048379bc100SJani Nikula 2049379bc100SJani Nikula intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst); 2050379bc100SJani Nikula 2051379bc100SJani Nikula if (is_mst || !pipe_mask) 2052379bc100SJani Nikula return false; 2053379bc100SJani Nikula 2054379bc100SJani Nikula *pipe = ffs(pipe_mask) - 1; 2055379bc100SJani Nikula 2056379bc100SJani Nikula return true; 2057379bc100SJani Nikula } 2058379bc100SJani Nikula 205981b55ef1SJani Nikula static enum intel_display_power_domain 2060379bc100SJani Nikula intel_ddi_main_link_aux_domain(struct intel_digital_port *dig_port) 2061379bc100SJani Nikula { 2062379bc100SJani Nikula /* CNL+ HW requires corresponding AUX IOs to be powered up for PSR with 2063379bc100SJani Nikula * DC states enabled at the same time, while for driver initiated AUX 2064379bc100SJani Nikula * transfers we need the same AUX IOs to be powered but with DC states 2065379bc100SJani Nikula * disabled. Accordingly use the AUX power domain here which leaves DC 2066379bc100SJani Nikula * states enabled. 2067379bc100SJani Nikula * However, for non-A AUX ports the corresponding non-EDP transcoders 2068379bc100SJani Nikula * would have already enabled power well 2 and DC_OFF. This means we can 2069379bc100SJani Nikula * acquire a wider POWER_DOMAIN_AUX_{B,C,D,F} reference instead of a 2070379bc100SJani Nikula * specific AUX_IO reference without powering up any extra wells. 2071379bc100SJani Nikula * Note that PSR is enabled only on Port A even though this function 2072379bc100SJani Nikula * returns the correct domain for other ports too. 2073379bc100SJani Nikula */ 2074379bc100SJani Nikula return dig_port->aux_ch == AUX_CH_A ? POWER_DOMAIN_AUX_IO_A : 2075379bc100SJani Nikula intel_aux_power_domain(dig_port); 2076379bc100SJani Nikula } 2077379bc100SJani Nikula 2078379bc100SJani Nikula static void intel_ddi_get_power_domains(struct intel_encoder *encoder, 2079379bc100SJani Nikula struct intel_crtc_state *crtc_state) 2080379bc100SJani Nikula { 2081379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2082379bc100SJani Nikula struct intel_digital_port *dig_port; 2083d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2084379bc100SJani Nikula 2085379bc100SJani Nikula /* 2086379bc100SJani Nikula * TODO: Add support for MST encoders. Atm, the following should never 2087379bc100SJani Nikula * happen since fake-MST encoders don't set their get_power_domains() 2088379bc100SJani Nikula * hook. 2089379bc100SJani Nikula */ 20901de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, 20911de143ccSPankaj Bharadiya intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))) 2092379bc100SJani Nikula return; 2093379bc100SJani Nikula 2094b7d02c3aSVille Syrjälä dig_port = enc_to_dig_port(encoder); 2095f77a2db2SImre Deak 2096f77a2db2SImre Deak if (!intel_phy_is_tc(dev_priv, phy) || 2097f77a2db2SImre Deak dig_port->tc_mode != TC_PORT_TBT_ALT) 2098f77a2db2SImre Deak intel_display_power_get(dev_priv, 2099f77a2db2SImre Deak dig_port->ddi_io_power_domain); 2100379bc100SJani Nikula 2101379bc100SJani Nikula /* 2102379bc100SJani Nikula * AUX power is only needed for (e)DP mode, and for HDMI mode on TC 2103379bc100SJani Nikula * ports. 2104379bc100SJani Nikula */ 2105379bc100SJani Nikula if (intel_crtc_has_dp_encoder(crtc_state) || 2106d8fe2ab6SMatt Roper intel_phy_is_tc(dev_priv, phy)) 2107379bc100SJani Nikula intel_display_power_get(dev_priv, 2108379bc100SJani Nikula intel_ddi_main_link_aux_domain(dig_port)); 2109379bc100SJani Nikula 2110379bc100SJani Nikula /* 2111379bc100SJani Nikula * VDSC power is needed when DSC is enabled 2112379bc100SJani Nikula */ 2113010663a6SJani Nikula if (crtc_state->dsc.compression_enable) 2114379bc100SJani Nikula intel_display_power_get(dev_priv, 2115379bc100SJani Nikula intel_dsc_power_domain(crtc_state)); 2116379bc100SJani Nikula } 2117379bc100SJani Nikula 211802a715c3SVille Syrjälä void intel_ddi_enable_pipe_clock(struct intel_encoder *encoder, 211902a715c3SVille Syrjälä const struct intel_crtc_state *crtc_state) 2120379bc100SJani Nikula { 21212225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2122379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2123379bc100SJani Nikula enum port port = encoder->port; 2124379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2125379bc100SJani Nikula 2126df16b636SMahesh Kumar if (cpu_transcoder != TRANSCODER_EDP) { 2127df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) 2128f7960e7fSJani Nikula intel_de_write(dev_priv, 2129f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2130df16b636SMahesh Kumar TGL_TRANS_CLK_SEL_PORT(port)); 2131df16b636SMahesh Kumar else 2132f7960e7fSJani Nikula intel_de_write(dev_priv, 2133f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2134379bc100SJani Nikula TRANS_CLK_SEL_PORT(port)); 2135379bc100SJani Nikula } 2136df16b636SMahesh Kumar } 2137379bc100SJani Nikula 2138379bc100SJani Nikula void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state) 2139379bc100SJani Nikula { 21402225f3c6SMaarten Lankhorst struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 2141379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2142379bc100SJani Nikula 2143df16b636SMahesh Kumar if (cpu_transcoder != TRANSCODER_EDP) { 2144df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) 2145f7960e7fSJani Nikula intel_de_write(dev_priv, 2146f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2147df16b636SMahesh Kumar TGL_TRANS_CLK_SEL_DISABLED); 2148df16b636SMahesh Kumar else 2149f7960e7fSJani Nikula intel_de_write(dev_priv, 2150f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2151379bc100SJani Nikula TRANS_CLK_SEL_DISABLED); 2152379bc100SJani Nikula } 2153df16b636SMahesh Kumar } 2154379bc100SJani Nikula 2155379bc100SJani Nikula static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv, 2156379bc100SJani Nikula enum port port, u8 iboost) 2157379bc100SJani Nikula { 2158379bc100SJani Nikula u32 tmp; 2159379bc100SJani Nikula 2160f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, DISPIO_CR_TX_BMU_CR0); 2161379bc100SJani Nikula tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port)); 2162379bc100SJani Nikula if (iboost) 2163379bc100SJani Nikula tmp |= iboost << BALANCE_LEG_SHIFT(port); 2164379bc100SJani Nikula else 2165379bc100SJani Nikula tmp |= BALANCE_LEG_DISABLE(port); 2166f7960e7fSJani Nikula intel_de_write(dev_priv, DISPIO_CR_TX_BMU_CR0, tmp); 2167379bc100SJani Nikula } 2168379bc100SJani Nikula 2169379bc100SJani Nikula static void skl_ddi_set_iboost(struct intel_encoder *encoder, 2170379bc100SJani Nikula int level, enum intel_output_type type) 2171379bc100SJani Nikula { 21727801f3b7SLucas De Marchi struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 2173379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2174379bc100SJani Nikula u8 iboost; 2175379bc100SJani Nikula 2176379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 217701a60883SJani Nikula iboost = intel_bios_hdmi_boost_level(encoder); 2178379bc100SJani Nikula else 2179605a1872SJani Nikula iboost = intel_bios_dp_boost_level(encoder); 2180379bc100SJani Nikula 2181379bc100SJani Nikula if (iboost == 0) { 2182379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations; 2183379bc100SJani Nikula int n_entries; 2184379bc100SJani Nikula 2185379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2186a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 2187379bc100SJani Nikula else if (type == INTEL_OUTPUT_EDP) 2188a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_edp(encoder, 2189a8143150SJosé Roberto de Souza &n_entries); 2190379bc100SJani Nikula else 2191a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_dp(encoder, 2192a8143150SJosé Roberto de Souza &n_entries); 2193379bc100SJani Nikula 21941de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 2195379bc100SJani Nikula return; 21961de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 2197379bc100SJani Nikula level = n_entries - 1; 2198379bc100SJani Nikula 2199379bc100SJani Nikula iboost = ddi_translations[level].i_boost; 2200379bc100SJani Nikula } 2201379bc100SJani Nikula 2202379bc100SJani Nikula /* Make sure that the requested I_boost is valid */ 2203379bc100SJani Nikula if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) { 220447bdb1caSJani Nikula drm_err(&dev_priv->drm, "Invalid I_boost value %u\n", iboost); 2205379bc100SJani Nikula return; 2206379bc100SJani Nikula } 2207379bc100SJani Nikula 2208f0e86e05SJosé Roberto de Souza _skl_ddi_set_iboost(dev_priv, encoder->port, iboost); 2209379bc100SJani Nikula 2210f0e86e05SJosé Roberto de Souza if (encoder->port == PORT_A && dig_port->max_lanes == 4) 2211379bc100SJani Nikula _skl_ddi_set_iboost(dev_priv, PORT_E, iboost); 2212379bc100SJani Nikula } 2213379bc100SJani Nikula 2214379bc100SJani Nikula static void bxt_ddi_vswing_sequence(struct intel_encoder *encoder, 2215379bc100SJani Nikula int level, enum intel_output_type type) 2216379bc100SJani Nikula { 2217379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2218379bc100SJani Nikula const struct bxt_ddi_buf_trans *ddi_translations; 2219379bc100SJani Nikula enum port port = encoder->port; 2220379bc100SJani Nikula int n_entries; 2221379bc100SJani Nikula 2222379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2223a8143150SJosé Roberto de Souza ddi_translations = bxt_get_buf_trans_hdmi(encoder, &n_entries); 2224379bc100SJani Nikula else if (type == INTEL_OUTPUT_EDP) 2225a8143150SJosé Roberto de Souza ddi_translations = bxt_get_buf_trans_edp(encoder, &n_entries); 2226379bc100SJani Nikula else 2227a8143150SJosé Roberto de Souza ddi_translations = bxt_get_buf_trans_dp(encoder, &n_entries); 2228379bc100SJani Nikula 22291de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 2230379bc100SJani Nikula return; 22311de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 2232379bc100SJani Nikula level = n_entries - 1; 2233379bc100SJani Nikula 2234379bc100SJani Nikula bxt_ddi_phy_set_signal_level(dev_priv, port, 2235379bc100SJani Nikula ddi_translations[level].margin, 2236379bc100SJani Nikula ddi_translations[level].scale, 2237379bc100SJani Nikula ddi_translations[level].enable, 2238379bc100SJani Nikula ddi_translations[level].deemphasis); 2239379bc100SJani Nikula } 2240379bc100SJani Nikula 224153de0a20SVille Syrjälä static u8 intel_ddi_dp_voltage_max(struct intel_dp *intel_dp) 2242379bc100SJani Nikula { 224353de0a20SVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2244379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2245379bc100SJani Nikula enum port port = encoder->port; 2246d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 2247379bc100SJani Nikula int n_entries; 2248379bc100SJani Nikula 2249978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 2250978c3e53SClinton A Taylor if (intel_phy_is_combo(dev_priv, phy)) 2251a8143150SJosé Roberto de Souza tgl_get_combo_buf_trans(encoder, encoder->type, 2252978c3e53SClinton A Taylor intel_dp->link_rate, &n_entries); 2253978c3e53SClinton A Taylor else 2254a8143150SJosé Roberto de Souza tgl_get_dkl_buf_trans(encoder, encoder->type, 22559fa67699SJosé Roberto de Souza intel_dp->link_rate, &n_entries); 2256978c3e53SClinton A Taylor } else if (INTEL_GEN(dev_priv) == 11) { 2257b42d5a67SJosé Roberto de Souza if (IS_ELKHARTLAKE(dev_priv)) 2258a8143150SJosé Roberto de Souza ehl_get_combo_buf_trans(encoder, encoder->type, 2259b42d5a67SJosé Roberto de Souza intel_dp->link_rate, &n_entries); 2260b42d5a67SJosé Roberto de Souza else if (intel_phy_is_combo(dev_priv, phy)) 2261a8143150SJosé Roberto de Souza icl_get_combo_buf_trans(encoder, encoder->type, 2262379bc100SJani Nikula intel_dp->link_rate, &n_entries); 2263379bc100SJani Nikula else 2264a8143150SJosé Roberto de Souza icl_get_mg_buf_trans(encoder, encoder->type, 22659f7ffa29SJosé Roberto de Souza intel_dp->link_rate, &n_entries); 2266379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 2267379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 2268a8143150SJosé Roberto de Souza cnl_get_buf_trans_edp(encoder, &n_entries); 2269379bc100SJani Nikula else 2270a8143150SJosé Roberto de Souza cnl_get_buf_trans_dp(encoder, &n_entries); 2271379bc100SJani Nikula } else if (IS_GEN9_LP(dev_priv)) { 2272379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 2273a8143150SJosé Roberto de Souza bxt_get_buf_trans_edp(encoder, &n_entries); 2274379bc100SJani Nikula else 2275a8143150SJosé Roberto de Souza bxt_get_buf_trans_dp(encoder, &n_entries); 2276379bc100SJani Nikula } else { 2277379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 2278f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_edp(encoder, &n_entries); 2279379bc100SJani Nikula else 2280f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_dp(encoder, &n_entries); 2281379bc100SJani Nikula } 2282379bc100SJani Nikula 22831de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, n_entries < 1)) 2284379bc100SJani Nikula n_entries = 1; 22851de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, 22861de143ccSPankaj Bharadiya n_entries > ARRAY_SIZE(index_to_dp_signal_levels))) 2287379bc100SJani Nikula n_entries = ARRAY_SIZE(index_to_dp_signal_levels); 2288379bc100SJani Nikula 2289379bc100SJani Nikula return index_to_dp_signal_levels[n_entries - 1] & 2290379bc100SJani Nikula DP_TRAIN_VOLTAGE_SWING_MASK; 2291379bc100SJani Nikula } 2292379bc100SJani Nikula 2293379bc100SJani Nikula /* 2294379bc100SJani Nikula * We assume that the full set of pre-emphasis values can be 2295379bc100SJani Nikula * used on all DDI platforms. Should that change we need to 2296379bc100SJani Nikula * rethink this code. 2297379bc100SJani Nikula */ 229853de0a20SVille Syrjälä static u8 intel_ddi_dp_preemph_max(struct intel_dp *intel_dp) 2299379bc100SJani Nikula { 2300379bc100SJani Nikula return DP_TRAIN_PRE_EMPH_LEVEL_3; 2301379bc100SJani Nikula } 2302379bc100SJani Nikula 2303379bc100SJani Nikula static void cnl_ddi_vswing_program(struct intel_encoder *encoder, 2304379bc100SJani Nikula int level, enum intel_output_type type) 2305379bc100SJani Nikula { 2306379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2307379bc100SJani Nikula const struct cnl_ddi_buf_trans *ddi_translations; 2308379bc100SJani Nikula enum port port = encoder->port; 2309379bc100SJani Nikula int n_entries, ln; 2310379bc100SJani Nikula u32 val; 2311379bc100SJani Nikula 2312379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2313a8143150SJosé Roberto de Souza ddi_translations = cnl_get_buf_trans_hdmi(encoder, &n_entries); 2314379bc100SJani Nikula else if (type == INTEL_OUTPUT_EDP) 2315a8143150SJosé Roberto de Souza ddi_translations = cnl_get_buf_trans_edp(encoder, &n_entries); 2316379bc100SJani Nikula else 2317a8143150SJosé Roberto de Souza ddi_translations = cnl_get_buf_trans_dp(encoder, &n_entries); 2318379bc100SJani Nikula 23191de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 2320379bc100SJani Nikula return; 23211de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 2322379bc100SJani Nikula level = n_entries - 1; 2323379bc100SJani Nikula 2324379bc100SJani Nikula /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */ 2325f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2326379bc100SJani Nikula val &= ~SCALING_MODE_SEL_MASK; 2327379bc100SJani Nikula val |= SCALING_MODE_SEL(2); 2328f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2329379bc100SJani Nikula 2330379bc100SJani Nikula /* Program PORT_TX_DW2 */ 2331f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW2_LN0(port)); 2332379bc100SJani Nikula val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 2333379bc100SJani Nikula RCOMP_SCALAR_MASK); 2334379bc100SJani Nikula val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel); 2335379bc100SJani Nikula val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel); 2336379bc100SJani Nikula /* Rcomp scalar is fixed as 0x98 for every table entry */ 2337379bc100SJani Nikula val |= RCOMP_SCALAR(0x98); 2338f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW2_GRP(port), val); 2339379bc100SJani Nikula 2340379bc100SJani Nikula /* Program PORT_TX_DW4 */ 2341379bc100SJani Nikula /* We cannot write to GRP. It would overrite individual loadgen */ 2342379bc100SJani Nikula for (ln = 0; ln < 4; ln++) { 2343f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port)); 2344379bc100SJani Nikula val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 2345379bc100SJani Nikula CURSOR_COEFF_MASK); 2346379bc100SJani Nikula val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1); 2347379bc100SJani Nikula val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2); 2348379bc100SJani Nikula val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff); 2349f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val); 2350379bc100SJani Nikula } 2351379bc100SJani Nikula 2352379bc100SJani Nikula /* Program PORT_TX_DW5 */ 2353379bc100SJani Nikula /* All DW5 values are fixed for every table entry */ 2354f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2355379bc100SJani Nikula val &= ~RTERM_SELECT_MASK; 2356379bc100SJani Nikula val |= RTERM_SELECT(6); 2357379bc100SJani Nikula val |= TAP3_DISABLE; 2358f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2359379bc100SJani Nikula 2360379bc100SJani Nikula /* Program PORT_TX_DW7 */ 2361f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW7_LN0(port)); 2362379bc100SJani Nikula val &= ~N_SCALAR_MASK; 2363379bc100SJani Nikula val |= N_SCALAR(ddi_translations[level].dw7_n_scalar); 2364f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW7_GRP(port), val); 2365379bc100SJani Nikula } 2366379bc100SJani Nikula 2367379bc100SJani Nikula static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder, 2368379bc100SJani Nikula int level, enum intel_output_type type) 2369379bc100SJani Nikula { 2370379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2371379bc100SJani Nikula enum port port = encoder->port; 2372379bc100SJani Nikula int width, rate, ln; 2373379bc100SJani Nikula u32 val; 2374379bc100SJani Nikula 2375379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) { 2376379bc100SJani Nikula width = 4; 2377379bc100SJani Nikula rate = 0; /* Rate is always < than 6GHz for HDMI */ 2378379bc100SJani Nikula } else { 2379b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2380379bc100SJani Nikula 2381379bc100SJani Nikula width = intel_dp->lane_count; 2382379bc100SJani Nikula rate = intel_dp->link_rate; 2383379bc100SJani Nikula } 2384379bc100SJani Nikula 2385379bc100SJani Nikula /* 2386379bc100SJani Nikula * 1. If port type is eDP or DP, 2387379bc100SJani Nikula * set PORT_PCS_DW1 cmnkeeper_enable to 1b, 2388379bc100SJani Nikula * else clear to 0b. 2389379bc100SJani Nikula */ 2390f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_PCS_DW1_LN0(port)); 2391379bc100SJani Nikula if (type != INTEL_OUTPUT_HDMI) 2392379bc100SJani Nikula val |= COMMON_KEEPER_EN; 2393379bc100SJani Nikula else 2394379bc100SJani Nikula val &= ~COMMON_KEEPER_EN; 2395f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_PCS_DW1_GRP(port), val); 2396379bc100SJani Nikula 2397379bc100SJani Nikula /* 2. Program loadgen select */ 2398379bc100SJani Nikula /* 2399379bc100SJani Nikula * Program PORT_TX_DW4_LN depending on Bit rate and used lanes 2400379bc100SJani Nikula * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1) 2401379bc100SJani Nikula * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0) 2402379bc100SJani Nikula * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0) 2403379bc100SJani Nikula */ 2404379bc100SJani Nikula for (ln = 0; ln <= 3; ln++) { 2405f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port)); 2406379bc100SJani Nikula val &= ~LOADGEN_SELECT; 2407379bc100SJani Nikula 2408379bc100SJani Nikula if ((rate <= 600000 && width == 4 && ln >= 1) || 2409379bc100SJani Nikula (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) { 2410379bc100SJani Nikula val |= LOADGEN_SELECT; 2411379bc100SJani Nikula } 2412f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val); 2413379bc100SJani Nikula } 2414379bc100SJani Nikula 2415379bc100SJani Nikula /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */ 2416f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_CL1CM_DW5); 2417379bc100SJani Nikula val |= SUS_CLOCK_CONFIG; 2418f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_CL1CM_DW5, val); 2419379bc100SJani Nikula 2420379bc100SJani Nikula /* 4. Clear training enable to change swing values */ 2421f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2422379bc100SJani Nikula val &= ~TX_TRAINING_EN; 2423f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2424379bc100SJani Nikula 2425379bc100SJani Nikula /* 5. Program swing and de-emphasis */ 2426379bc100SJani Nikula cnl_ddi_vswing_program(encoder, level, type); 2427379bc100SJani Nikula 2428379bc100SJani Nikula /* 6. Set training enable to trigger update */ 2429f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2430379bc100SJani Nikula val |= TX_TRAINING_EN; 2431f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2432379bc100SJani Nikula } 2433379bc100SJani Nikula 2434a8143150SJosé Roberto de Souza static void icl_ddi_combo_vswing_program(struct intel_encoder *encoder, 2435f0e86e05SJosé Roberto de Souza u32 level, int type, int rate) 2436379bc100SJani Nikula { 2437a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2438f0e86e05SJosé Roberto de Souza enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2439379bc100SJani Nikula const struct cnl_ddi_buf_trans *ddi_translations = NULL; 2440379bc100SJani Nikula u32 n_entries, val; 2441379bc100SJani Nikula int ln; 2442379bc100SJani Nikula 2443bd3cf6f7SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 2444a8143150SJosé Roberto de Souza ddi_translations = tgl_get_combo_buf_trans(encoder, type, rate, 2445bd3cf6f7SJosé Roberto de Souza &n_entries); 2446b42d5a67SJosé Roberto de Souza else if (IS_ELKHARTLAKE(dev_priv)) 2447a8143150SJosé Roberto de Souza ddi_translations = ehl_get_combo_buf_trans(encoder, type, rate, 2448b42d5a67SJosé Roberto de Souza &n_entries); 2449bd3cf6f7SJosé Roberto de Souza else 2450a8143150SJosé Roberto de Souza ddi_translations = icl_get_combo_buf_trans(encoder, type, rate, 24514a8134d5SMatt Roper &n_entries); 2452379bc100SJani Nikula if (!ddi_translations) 2453379bc100SJani Nikula return; 2454379bc100SJani Nikula 2455379bc100SJani Nikula if (level >= n_entries) { 245647bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 245747bdb1caSJani Nikula "DDI translation not found for level %d. Using %d instead.", 245847bdb1caSJani Nikula level, n_entries - 1); 2459379bc100SJani Nikula level = n_entries - 1; 2460379bc100SJani Nikula } 2461379bc100SJani Nikula 246281619f4aSJosé Roberto de Souza if (type == INTEL_OUTPUT_EDP) { 246381619f4aSJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 246481619f4aSJosé Roberto de Souza 246581619f4aSJosé Roberto de Souza val = EDP4K2K_MODE_OVRD_EN | EDP4K2K_MODE_OVRD_OPTIMIZED; 246681619f4aSJosé Roberto de Souza intel_dp->hobl_active = is_hobl_buf_trans(ddi_translations); 246781619f4aSJosé Roberto de Souza intel_de_rmw(dev_priv, ICL_PORT_CL_DW10(phy), val, 246881619f4aSJosé Roberto de Souza intel_dp->hobl_active ? val : 0); 246981619f4aSJosé Roberto de Souza } 247081619f4aSJosé Roberto de Souza 2471379bc100SJani Nikula /* Set PORT_TX_DW5 */ 2472f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 2473379bc100SJani Nikula val &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK | 2474379bc100SJani Nikula TAP2_DISABLE | TAP3_DISABLE); 2475379bc100SJani Nikula val |= SCALING_MODE_SEL(0x2); 2476379bc100SJani Nikula val |= RTERM_SELECT(0x6); 2477379bc100SJani Nikula val |= TAP3_DISABLE; 2478f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val); 2479379bc100SJani Nikula 2480379bc100SJani Nikula /* Program PORT_TX_DW2 */ 2481f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN0(phy)); 2482379bc100SJani Nikula val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 2483379bc100SJani Nikula RCOMP_SCALAR_MASK); 2484379bc100SJani Nikula val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel); 2485379bc100SJani Nikula val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel); 2486379bc100SJani Nikula /* Program Rcomp scalar for every table entry */ 2487379bc100SJani Nikula val |= RCOMP_SCALAR(0x98); 2488f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), val); 2489379bc100SJani Nikula 2490379bc100SJani Nikula /* Program PORT_TX_DW4 */ 2491379bc100SJani Nikula /* We cannot write to GRP. It would overwrite individual loadgen. */ 2492379bc100SJani Nikula for (ln = 0; ln <= 3; ln++) { 2493f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy)); 2494379bc100SJani Nikula val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 2495379bc100SJani Nikula CURSOR_COEFF_MASK); 2496379bc100SJani Nikula val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1); 2497379bc100SJani Nikula val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2); 2498379bc100SJani Nikula val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff); 2499f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val); 2500379bc100SJani Nikula } 2501379bc100SJani Nikula 2502379bc100SJani Nikula /* Program PORT_TX_DW7 */ 2503f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW7_LN0(phy)); 2504379bc100SJani Nikula val &= ~N_SCALAR_MASK; 2505379bc100SJani Nikula val |= N_SCALAR(ddi_translations[level].dw7_n_scalar); 2506f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW7_GRP(phy), val); 2507379bc100SJani Nikula } 2508379bc100SJani Nikula 2509379bc100SJani Nikula static void icl_combo_phy_ddi_vswing_sequence(struct intel_encoder *encoder, 2510379bc100SJani Nikula u32 level, 2511379bc100SJani Nikula enum intel_output_type type) 2512379bc100SJani Nikula { 2513379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2514dc867bc7SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2515379bc100SJani Nikula int width = 0; 2516379bc100SJani Nikula int rate = 0; 2517379bc100SJani Nikula u32 val; 2518379bc100SJani Nikula int ln = 0; 2519379bc100SJani Nikula 2520379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) { 2521379bc100SJani Nikula width = 4; 2522379bc100SJani Nikula /* Rate is always < than 6GHz for HDMI */ 2523379bc100SJani Nikula } else { 2524b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2525379bc100SJani Nikula 2526379bc100SJani Nikula width = intel_dp->lane_count; 2527379bc100SJani Nikula rate = intel_dp->link_rate; 2528379bc100SJani Nikula } 2529379bc100SJani Nikula 2530379bc100SJani Nikula /* 2531379bc100SJani Nikula * 1. If port type is eDP or DP, 2532379bc100SJani Nikula * set PORT_PCS_DW1 cmnkeeper_enable to 1b, 2533379bc100SJani Nikula * else clear to 0b. 2534379bc100SJani Nikula */ 2535f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN0(phy)); 2536379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2537379bc100SJani Nikula val &= ~COMMON_KEEPER_EN; 2538379bc100SJani Nikula else 2539379bc100SJani Nikula val |= COMMON_KEEPER_EN; 2540f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), val); 2541379bc100SJani Nikula 2542379bc100SJani Nikula /* 2. Program loadgen select */ 2543379bc100SJani Nikula /* 2544379bc100SJani Nikula * Program PORT_TX_DW4_LN depending on Bit rate and used lanes 2545379bc100SJani Nikula * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1) 2546379bc100SJani Nikula * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0) 2547379bc100SJani Nikula * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0) 2548379bc100SJani Nikula */ 2549379bc100SJani Nikula for (ln = 0; ln <= 3; ln++) { 2550f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy)); 2551379bc100SJani Nikula val &= ~LOADGEN_SELECT; 2552379bc100SJani Nikula 2553379bc100SJani Nikula if ((rate <= 600000 && width == 4 && ln >= 1) || 2554379bc100SJani Nikula (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) { 2555379bc100SJani Nikula val |= LOADGEN_SELECT; 2556379bc100SJani Nikula } 2557f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val); 2558379bc100SJani Nikula } 2559379bc100SJani Nikula 2560379bc100SJani Nikula /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */ 2561f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_CL_DW5(phy)); 2562379bc100SJani Nikula val |= SUS_CLOCK_CONFIG; 2563f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_CL_DW5(phy), val); 2564379bc100SJani Nikula 2565379bc100SJani Nikula /* 4. Clear training enable to change swing values */ 2566f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 2567379bc100SJani Nikula val &= ~TX_TRAINING_EN; 2568f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val); 2569379bc100SJani Nikula 2570379bc100SJani Nikula /* 5. Program swing and de-emphasis */ 2571f0e86e05SJosé Roberto de Souza icl_ddi_combo_vswing_program(encoder, level, type, rate); 2572379bc100SJani Nikula 2573379bc100SJani Nikula /* 6. Set training enable to trigger update */ 2574f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 2575379bc100SJani Nikula val |= TX_TRAINING_EN; 2576f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val); 2577379bc100SJani Nikula } 2578379bc100SJani Nikula 2579379bc100SJani Nikula static void icl_mg_phy_ddi_vswing_sequence(struct intel_encoder *encoder, 25809f7ffa29SJosé Roberto de Souza int link_clock, u32 level, 25819f7ffa29SJosé Roberto de Souza enum intel_output_type type) 2582379bc100SJani Nikula { 2583379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2584f21e8b80SJosé Roberto de Souza enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port); 2585379bc100SJani Nikula const struct icl_mg_phy_ddi_buf_trans *ddi_translations; 2586379bc100SJani Nikula u32 n_entries, val; 25879f7ffa29SJosé Roberto de Souza int ln, rate = 0; 2588379bc100SJani Nikula 25899f7ffa29SJosé Roberto de Souza if (type != INTEL_OUTPUT_HDMI) { 25909f7ffa29SJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 25919f7ffa29SJosé Roberto de Souza 25929f7ffa29SJosé Roberto de Souza rate = intel_dp->link_rate; 25939f7ffa29SJosé Roberto de Souza } 25949f7ffa29SJosé Roberto de Souza 2595a8143150SJosé Roberto de Souza ddi_translations = icl_get_mg_buf_trans(encoder, type, rate, 25969f7ffa29SJosé Roberto de Souza &n_entries); 2597379bc100SJani Nikula /* The table does not have values for level 3 and level 9. */ 2598379bc100SJani Nikula if (level >= n_entries || level == 3 || level == 9) { 259947bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 260047bdb1caSJani Nikula "DDI translation not found for level %d. Using %d instead.", 2601379bc100SJani Nikula level, n_entries - 2); 2602379bc100SJani Nikula level = n_entries - 2; 2603379bc100SJani Nikula } 2604379bc100SJani Nikula 2605379bc100SJani Nikula /* Set MG_TX_LINK_PARAMS cri_use_fs32 to 0. */ 2606379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2607f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port)); 2608379bc100SJani Nikula val &= ~CRI_USE_FS32; 2609f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port), val); 2610379bc100SJani Nikula 2611f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port)); 2612379bc100SJani Nikula val &= ~CRI_USE_FS32; 2613f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port), val); 2614379bc100SJani Nikula } 2615379bc100SJani Nikula 2616379bc100SJani Nikula /* Program MG_TX_SWINGCTRL with values from vswing table */ 2617379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2618f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port)); 2619379bc100SJani Nikula val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK; 2620379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_17_12( 2621379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_17_12); 2622f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port), val); 2623379bc100SJani Nikula 2624f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port)); 2625379bc100SJani Nikula val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK; 2626379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_17_12( 2627379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_17_12); 2628f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port), val); 2629379bc100SJani Nikula } 2630379bc100SJani Nikula 2631379bc100SJani Nikula /* Program MG_TX_DRVCTRL with values from vswing table */ 2632379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2633f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_DRVCTRL(ln, tc_port)); 2634379bc100SJani Nikula val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK | 2635379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_5_0_MASK); 2636379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_5_0( 2637379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_5_0) | 2638379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_11_6( 2639379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_11_6) | 2640379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_EN; 2641f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_DRVCTRL(ln, tc_port), val); 2642379bc100SJani Nikula 2643f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_DRVCTRL(ln, tc_port)); 2644379bc100SJani Nikula val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK | 2645379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_5_0_MASK); 2646379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_5_0( 2647379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_5_0) | 2648379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_11_6( 2649379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_11_6) | 2650379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_EN; 2651f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_DRVCTRL(ln, tc_port), val); 2652379bc100SJani Nikula 2653379bc100SJani Nikula /* FIXME: Program CRI_LOADGEN_SEL after the spec is updated */ 2654379bc100SJani Nikula } 2655379bc100SJani Nikula 2656379bc100SJani Nikula /* 2657379bc100SJani Nikula * Program MG_CLKHUB<LN, port being used> with value from frequency table 2658379bc100SJani Nikula * In case of Legacy mode on MG PHY, both TX1 and TX2 enabled so use the 2659379bc100SJani Nikula * values from table for which TX1 and TX2 enabled. 2660379bc100SJani Nikula */ 2661379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2662f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_CLKHUB(ln, tc_port)); 2663379bc100SJani Nikula if (link_clock < 300000) 2664379bc100SJani Nikula val |= CFG_LOW_RATE_LKREN_EN; 2665379bc100SJani Nikula else 2666379bc100SJani Nikula val &= ~CFG_LOW_RATE_LKREN_EN; 2667f7960e7fSJani Nikula intel_de_write(dev_priv, MG_CLKHUB(ln, tc_port), val); 2668379bc100SJani Nikula } 2669379bc100SJani Nikula 2670379bc100SJani Nikula /* Program the MG_TX_DCC<LN, port being used> based on the link frequency */ 2671379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2672f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_DCC(ln, tc_port)); 2673379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK; 2674379bc100SJani Nikula if (link_clock <= 500000) { 2675379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN; 2676379bc100SJani Nikula } else { 2677379bc100SJani Nikula val |= CFG_AMI_CK_DIV_OVERRIDE_EN | 2678379bc100SJani Nikula CFG_AMI_CK_DIV_OVERRIDE_VAL(1); 2679379bc100SJani Nikula } 2680f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_DCC(ln, tc_port), val); 2681379bc100SJani Nikula 2682f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_DCC(ln, tc_port)); 2683379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK; 2684379bc100SJani Nikula if (link_clock <= 500000) { 2685379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN; 2686379bc100SJani Nikula } else { 2687379bc100SJani Nikula val |= CFG_AMI_CK_DIV_OVERRIDE_EN | 2688379bc100SJani Nikula CFG_AMI_CK_DIV_OVERRIDE_VAL(1); 2689379bc100SJani Nikula } 2690f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_DCC(ln, tc_port), val); 2691379bc100SJani Nikula } 2692379bc100SJani Nikula 2693379bc100SJani Nikula /* Program MG_TX_PISO_READLOAD with values from vswing table */ 2694379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2695f7960e7fSJani Nikula val = intel_de_read(dev_priv, 2696f7960e7fSJani Nikula MG_TX1_PISO_READLOAD(ln, tc_port)); 2697379bc100SJani Nikula val |= CRI_CALCINIT; 2698f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_PISO_READLOAD(ln, tc_port), 2699f7960e7fSJani Nikula val); 2700379bc100SJani Nikula 2701f7960e7fSJani Nikula val = intel_de_read(dev_priv, 2702f7960e7fSJani Nikula MG_TX2_PISO_READLOAD(ln, tc_port)); 2703379bc100SJani Nikula val |= CRI_CALCINIT; 2704f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_PISO_READLOAD(ln, tc_port), 2705f7960e7fSJani Nikula val); 2706379bc100SJani Nikula } 2707379bc100SJani Nikula } 2708379bc100SJani Nikula 2709379bc100SJani Nikula static void icl_ddi_vswing_sequence(struct intel_encoder *encoder, 2710379bc100SJani Nikula int link_clock, 2711379bc100SJani Nikula u32 level, 2712379bc100SJani Nikula enum intel_output_type type) 2713379bc100SJani Nikula { 2714379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2715d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2716379bc100SJani Nikula 2717d8fe2ab6SMatt Roper if (intel_phy_is_combo(dev_priv, phy)) 2718379bc100SJani Nikula icl_combo_phy_ddi_vswing_sequence(encoder, level, type); 2719379bc100SJani Nikula else 27209f7ffa29SJosé Roberto de Souza icl_mg_phy_ddi_vswing_sequence(encoder, link_clock, level, 27219f7ffa29SJosé Roberto de Souza type); 2722379bc100SJani Nikula } 2723379bc100SJani Nikula 2724978c3e53SClinton A Taylor static void 2725978c3e53SClinton A Taylor tgl_dkl_phy_ddi_vswing_sequence(struct intel_encoder *encoder, int link_clock, 272694641eb6SVandita Kulkarni u32 level, enum intel_output_type type) 2727978c3e53SClinton A Taylor { 2728978c3e53SClinton A Taylor struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2729978c3e53SClinton A Taylor enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port); 2730978c3e53SClinton A Taylor const struct tgl_dkl_phy_ddi_buf_trans *ddi_translations; 2731978c3e53SClinton A Taylor u32 n_entries, val, ln, dpcnt_mask, dpcnt_val; 27329fa67699SJosé Roberto de Souza int rate = 0; 2733978c3e53SClinton A Taylor 273494641eb6SVandita Kulkarni if (type == INTEL_OUTPUT_HDMI) { 27359fa67699SJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 27369fa67699SJosé Roberto de Souza 27379fa67699SJosé Roberto de Souza rate = intel_dp->link_rate; 2738362bfb99SMatt Roper } 2739978c3e53SClinton A Taylor 2740a8143150SJosé Roberto de Souza ddi_translations = tgl_get_dkl_buf_trans(encoder, encoder->type, rate, 27419fa67699SJosé Roberto de Souza &n_entries); 27429fa67699SJosé Roberto de Souza 2743978c3e53SClinton A Taylor if (level >= n_entries) 2744978c3e53SClinton A Taylor level = n_entries - 1; 2745978c3e53SClinton A Taylor 2746978c3e53SClinton A Taylor dpcnt_mask = (DKL_TX_PRESHOOT_COEFF_MASK | 2747978c3e53SClinton A Taylor DKL_TX_DE_EMPAHSIS_COEFF_MASK | 2748978c3e53SClinton A Taylor DKL_TX_VSWING_CONTROL_MASK); 2749978c3e53SClinton A Taylor dpcnt_val = DKL_TX_VSWING_CONTROL(ddi_translations[level].dkl_vswing_control); 2750978c3e53SClinton A Taylor dpcnt_val |= DKL_TX_DE_EMPHASIS_COEFF(ddi_translations[level].dkl_de_emphasis_control); 2751978c3e53SClinton A Taylor dpcnt_val |= DKL_TX_PRESHOOT_COEFF(ddi_translations[level].dkl_preshoot_control); 2752978c3e53SClinton A Taylor 2753978c3e53SClinton A Taylor for (ln = 0; ln < 2; ln++) { 2754f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 2755f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, ln)); 2756978c3e53SClinton A Taylor 2757f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_PMD_LANE_SUS(tc_port), 0); 27582d69c42eSJosé Roberto de Souza 2759978c3e53SClinton A Taylor /* All the registers are RMW */ 2760f7960e7fSJani Nikula val = intel_de_read(dev_priv, DKL_TX_DPCNTL0(tc_port)); 2761978c3e53SClinton A Taylor val &= ~dpcnt_mask; 2762978c3e53SClinton A Taylor val |= dpcnt_val; 2763f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_DPCNTL0(tc_port), val); 2764978c3e53SClinton A Taylor 2765f7960e7fSJani Nikula val = intel_de_read(dev_priv, DKL_TX_DPCNTL1(tc_port)); 2766978c3e53SClinton A Taylor val &= ~dpcnt_mask; 2767978c3e53SClinton A Taylor val |= dpcnt_val; 2768f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_DPCNTL1(tc_port), val); 2769978c3e53SClinton A Taylor 2770f7960e7fSJani Nikula val = intel_de_read(dev_priv, DKL_TX_DPCNTL2(tc_port)); 2771978c3e53SClinton A Taylor val &= ~DKL_TX_DP20BITMODE; 2772f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_DPCNTL2(tc_port), val); 2773978c3e53SClinton A Taylor } 2774978c3e53SClinton A Taylor } 2775978c3e53SClinton A Taylor 2776978c3e53SClinton A Taylor static void tgl_ddi_vswing_sequence(struct intel_encoder *encoder, 2777978c3e53SClinton A Taylor int link_clock, 2778978c3e53SClinton A Taylor u32 level, 2779978c3e53SClinton A Taylor enum intel_output_type type) 2780978c3e53SClinton A Taylor { 2781978c3e53SClinton A Taylor struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2782978c3e53SClinton A Taylor enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2783978c3e53SClinton A Taylor 2784978c3e53SClinton A Taylor if (intel_phy_is_combo(dev_priv, phy)) 2785978c3e53SClinton A Taylor icl_combo_phy_ddi_vswing_sequence(encoder, level, type); 2786978c3e53SClinton A Taylor else 278794641eb6SVandita Kulkarni tgl_dkl_phy_ddi_vswing_sequence(encoder, link_clock, level, type); 2788978c3e53SClinton A Taylor } 2789978c3e53SClinton A Taylor 27908b4f2137SPankaj Bharadiya static u32 translate_signal_level(struct intel_dp *intel_dp, int signal_levels) 2791379bc100SJani Nikula { 27928b4f2137SPankaj Bharadiya struct drm_i915_private *i915 = dp_to_i915(intel_dp); 2793379bc100SJani Nikula int i; 2794379bc100SJani Nikula 2795379bc100SJani Nikula for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) { 2796379bc100SJani Nikula if (index_to_dp_signal_levels[i] == signal_levels) 2797379bc100SJani Nikula return i; 2798379bc100SJani Nikula } 2799379bc100SJani Nikula 28008b4f2137SPankaj Bharadiya drm_WARN(&i915->drm, 1, 28018b4f2137SPankaj Bharadiya "Unsupported voltage swing/pre-emphasis level: 0x%x\n", 2802379bc100SJani Nikula signal_levels); 2803379bc100SJani Nikula 2804379bc100SJani Nikula return 0; 2805379bc100SJani Nikula } 2806379bc100SJani Nikula 2807379bc100SJani Nikula static u32 intel_ddi_dp_level(struct intel_dp *intel_dp) 2808379bc100SJani Nikula { 2809379bc100SJani Nikula u8 train_set = intel_dp->train_set[0]; 2810379bc100SJani Nikula int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | 2811379bc100SJani Nikula DP_TRAIN_PRE_EMPHASIS_MASK); 2812379bc100SJani Nikula 28138b4f2137SPankaj Bharadiya return translate_signal_level(intel_dp, signal_levels); 2814379bc100SJani Nikula } 2815379bc100SJani Nikula 2816fb83f72cSVille Syrjälä static void 2817fb83f72cSVille Syrjälä tgl_set_signal_levels(struct intel_dp *intel_dp) 2818379bc100SJani Nikula { 2819fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2820379bc100SJani Nikula int level = intel_ddi_dp_level(intel_dp); 2821379bc100SJani Nikula 2822978c3e53SClinton A Taylor tgl_ddi_vswing_sequence(encoder, intel_dp->link_rate, 2823978c3e53SClinton A Taylor level, encoder->type); 2824379bc100SJani Nikula } 2825379bc100SJani Nikula 2826fb83f72cSVille Syrjälä static void 2827fb83f72cSVille Syrjälä icl_set_signal_levels(struct intel_dp *intel_dp) 2828379bc100SJani Nikula { 2829fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2830379bc100SJani Nikula int level = intel_ddi_dp_level(intel_dp); 2831379bc100SJani Nikula 2832fb83f72cSVille Syrjälä icl_ddi_vswing_sequence(encoder, intel_dp->link_rate, 2833fb83f72cSVille Syrjälä level, encoder->type); 2834fb83f72cSVille Syrjälä } 2835fb83f72cSVille Syrjälä 2836fb83f72cSVille Syrjälä static void 2837fb83f72cSVille Syrjälä cnl_set_signal_levels(struct intel_dp *intel_dp) 2838fb83f72cSVille Syrjälä { 2839fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2840fb83f72cSVille Syrjälä int level = intel_ddi_dp_level(intel_dp); 2841fb83f72cSVille Syrjälä 2842fb83f72cSVille Syrjälä cnl_ddi_vswing_sequence(encoder, level, encoder->type); 2843fb83f72cSVille Syrjälä } 2844fb83f72cSVille Syrjälä 2845fb83f72cSVille Syrjälä static void 2846fb83f72cSVille Syrjälä bxt_set_signal_levels(struct intel_dp *intel_dp) 2847fb83f72cSVille Syrjälä { 2848fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2849fb83f72cSVille Syrjälä int level = intel_ddi_dp_level(intel_dp); 2850fb83f72cSVille Syrjälä 2851fb83f72cSVille Syrjälä bxt_ddi_vswing_sequence(encoder, level, encoder->type); 2852fb83f72cSVille Syrjälä } 2853fb83f72cSVille Syrjälä 2854fb83f72cSVille Syrjälä static void 2855fb83f72cSVille Syrjälä hsw_set_signal_levels(struct intel_dp *intel_dp) 2856fb83f72cSVille Syrjälä { 2857fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2858fb83f72cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2859fb83f72cSVille Syrjälä int level = intel_ddi_dp_level(intel_dp); 2860fb83f72cSVille Syrjälä enum port port = encoder->port; 2861fb83f72cSVille Syrjälä u32 signal_levels; 2862fb83f72cSVille Syrjälä 2863fb83f72cSVille Syrjälä signal_levels = DDI_BUF_TRANS_SELECT(level); 2864fb83f72cSVille Syrjälä 2865fb83f72cSVille Syrjälä drm_dbg_kms(&dev_priv->drm, "Using signal levels %08x\n", 2866fb83f72cSVille Syrjälä signal_levels); 2867fb83f72cSVille Syrjälä 2868fb83f72cSVille Syrjälä intel_dp->DP &= ~DDI_BUF_EMP_MASK; 2869fb83f72cSVille Syrjälä intel_dp->DP |= signal_levels; 2870fb83f72cSVille Syrjälä 2871379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) 2872379bc100SJani Nikula skl_ddi_set_iboost(encoder, level, encoder->type); 2873379bc100SJani Nikula 2874fb83f72cSVille Syrjälä intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP); 2875fb83f72cSVille Syrjälä intel_de_posting_read(dev_priv, DDI_BUF_CTL(port)); 2876379bc100SJani Nikula } 2877379bc100SJani Nikula 287881b55ef1SJani Nikula static u32 icl_dpclka_cfgcr0_clk_off(struct drm_i915_private *dev_priv, 2879befa372bSMatt Roper enum phy phy) 2880379bc100SJani Nikula { 2881cd803bb4SMatt Roper if (IS_ROCKETLAKE(dev_priv)) { 2882cd803bb4SMatt Roper return RKL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 2883cd803bb4SMatt Roper } else if (intel_phy_is_combo(dev_priv, phy)) { 2884befa372bSMatt Roper return ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 2885befa372bSMatt Roper } else if (intel_phy_is_tc(dev_priv, phy)) { 2886befa372bSMatt Roper enum tc_port tc_port = intel_port_to_tc(dev_priv, 2887befa372bSMatt Roper (enum port)phy); 2888379bc100SJani Nikula 2889379bc100SJani Nikula return ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port); 2890379bc100SJani Nikula } 2891379bc100SJani Nikula 2892379bc100SJani Nikula return 0; 2893379bc100SJani Nikula } 2894379bc100SJani Nikula 2895379bc100SJani Nikula static void icl_map_plls_to_ports(struct intel_encoder *encoder, 2896379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 2897379bc100SJani Nikula { 2898379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2899379bc100SJani Nikula struct intel_shared_dpll *pll = crtc_state->shared_dpll; 2900befa372bSMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2901379bc100SJani Nikula u32 val; 2902379bc100SJani Nikula 2903353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 2904379bc100SJani Nikula 2905f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 29061de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 29071de143ccSPankaj Bharadiya (val & icl_dpclka_cfgcr0_clk_off(dev_priv, phy)) == 0); 2908379bc100SJani Nikula 2909befa372bSMatt Roper if (intel_phy_is_combo(dev_priv, phy)) { 2910cd803bb4SMatt Roper u32 mask, sel; 2911cd803bb4SMatt Roper 2912cd803bb4SMatt Roper if (IS_ROCKETLAKE(dev_priv)) { 2913cd803bb4SMatt Roper mask = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy); 2914cd803bb4SMatt Roper sel = RKL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy); 2915cd803bb4SMatt Roper } else { 2916cd803bb4SMatt Roper mask = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy); 2917cd803bb4SMatt Roper sel = ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy); 2918cd803bb4SMatt Roper } 2919cd803bb4SMatt Roper 2920befa372bSMatt Roper /* 2921befa372bSMatt Roper * Even though this register references DDIs, note that we 2922befa372bSMatt Roper * want to pass the PHY rather than the port (DDI). For 2923befa372bSMatt Roper * ICL, port=phy in all cases so it doesn't matter, but for 2924befa372bSMatt Roper * EHL the bspec notes the following: 2925befa372bSMatt Roper * 2926befa372bSMatt Roper * "DDID clock tied to DDIA clock, so DPCLKA_CFGCR0 DDIA 2927befa372bSMatt Roper * Clock Select chooses the PLL for both DDIA and DDID and 2928befa372bSMatt Roper * drives port A in all cases." 2929befa372bSMatt Roper */ 2930cd803bb4SMatt Roper val &= ~mask; 2931cd803bb4SMatt Roper val |= sel; 2932f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 2933f7960e7fSJani Nikula intel_de_posting_read(dev_priv, ICL_DPCLKA_CFGCR0); 2934379bc100SJani Nikula } 2935379bc100SJani Nikula 2936befa372bSMatt Roper val &= ~icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 2937f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 2938379bc100SJani Nikula 2939353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 2940379bc100SJani Nikula } 2941379bc100SJani Nikula 2942379bc100SJani Nikula static void icl_unmap_plls_to_ports(struct intel_encoder *encoder) 2943379bc100SJani Nikula { 2944379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2945befa372bSMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2946379bc100SJani Nikula u32 val; 2947379bc100SJani Nikula 2948353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 2949379bc100SJani Nikula 2950f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 2951befa372bSMatt Roper val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 2952f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 2953379bc100SJani Nikula 2954353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 2955379bc100SJani Nikula } 2956379bc100SJani Nikula 29575956f440SLucas De Marchi static void icl_sanitize_port_clk_off(struct drm_i915_private *dev_priv, 29585956f440SLucas De Marchi u32 port_mask, bool ddi_clk_needed) 29595956f440SLucas De Marchi { 29605956f440SLucas De Marchi enum port port; 29615956f440SLucas De Marchi u32 val; 29625956f440SLucas De Marchi 2963f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 29645956f440SLucas De Marchi for_each_port_masked(port, port_mask) { 29655956f440SLucas De Marchi enum phy phy = intel_port_to_phy(dev_priv, port); 296641ba19fcSLucas De Marchi bool ddi_clk_off = val & icl_dpclka_cfgcr0_clk_off(dev_priv, 296741ba19fcSLucas De Marchi phy); 29685956f440SLucas De Marchi 296941ba19fcSLucas De Marchi if (ddi_clk_needed == !ddi_clk_off) 29705956f440SLucas De Marchi continue; 29715956f440SLucas De Marchi 29725956f440SLucas De Marchi /* 29735956f440SLucas De Marchi * Punt on the case now where clock is gated, but it would 29745956f440SLucas De Marchi * be needed by the port. Something else is really broken then. 29755956f440SLucas De Marchi */ 29761de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, ddi_clk_needed)) 29775956f440SLucas De Marchi continue; 29785956f440SLucas De Marchi 297947bdb1caSJani Nikula drm_notice(&dev_priv->drm, 298047bdb1caSJani Nikula "PHY %c is disabled/in DSI mode with an ungated DDI clock, gate it\n", 2981d6f970f0SLucas De Marchi phy_name(phy)); 29825956f440SLucas De Marchi val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 2983f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 29845956f440SLucas De Marchi } 29855956f440SLucas De Marchi } 29865956f440SLucas De Marchi 2987379bc100SJani Nikula void icl_sanitize_encoder_pll_mapping(struct intel_encoder *encoder) 2988379bc100SJani Nikula { 2989379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2990379bc100SJani Nikula u32 port_mask; 2991379bc100SJani Nikula bool ddi_clk_needed; 2992379bc100SJani Nikula 2993379bc100SJani Nikula /* 2994379bc100SJani Nikula * In case of DP MST, we sanitize the primary encoder only, not the 2995379bc100SJani Nikula * virtual ones. 2996379bc100SJani Nikula */ 2997379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_DP_MST) 2998379bc100SJani Nikula return; 2999379bc100SJani Nikula 3000379bc100SJani Nikula if (!encoder->base.crtc && intel_encoder_is_dp(encoder)) { 3001379bc100SJani Nikula u8 pipe_mask; 3002379bc100SJani Nikula bool is_mst; 3003379bc100SJani Nikula 3004379bc100SJani Nikula intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst); 3005379bc100SJani Nikula /* 3006379bc100SJani Nikula * In the unlikely case that BIOS enables DP in MST mode, just 3007379bc100SJani Nikula * warn since our MST HW readout is incomplete. 3008379bc100SJani Nikula */ 30091de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, is_mst)) 3010379bc100SJani Nikula return; 3011379bc100SJani Nikula } 3012379bc100SJani Nikula 3013379bc100SJani Nikula port_mask = BIT(encoder->port); 3014379bc100SJani Nikula ddi_clk_needed = encoder->base.crtc; 3015379bc100SJani Nikula 3016379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_DSI) { 3017379bc100SJani Nikula struct intel_encoder *other_encoder; 3018379bc100SJani Nikula 3019379bc100SJani Nikula port_mask = intel_dsi_encoder_ports(encoder); 3020379bc100SJani Nikula /* 3021379bc100SJani Nikula * Sanity check that we haven't incorrectly registered another 3022379bc100SJani Nikula * encoder using any of the ports of this DSI encoder. 3023379bc100SJani Nikula */ 3024379bc100SJani Nikula for_each_intel_encoder(&dev_priv->drm, other_encoder) { 3025379bc100SJani Nikula if (other_encoder == encoder) 3026379bc100SJani Nikula continue; 3027379bc100SJani Nikula 30281de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, 30291de143ccSPankaj Bharadiya port_mask & BIT(other_encoder->port))) 3030379bc100SJani Nikula return; 3031379bc100SJani Nikula } 3032379bc100SJani Nikula /* 3033379bc100SJani Nikula * For DSI we keep the ddi clocks gated 3034379bc100SJani Nikula * except during enable/disable sequence. 3035379bc100SJani Nikula */ 3036379bc100SJani Nikula ddi_clk_needed = false; 3037379bc100SJani Nikula } 3038379bc100SJani Nikula 30395956f440SLucas De Marchi icl_sanitize_port_clk_off(dev_priv, port_mask, ddi_clk_needed); 3040379bc100SJani Nikula } 3041379bc100SJani Nikula 3042379bc100SJani Nikula static void intel_ddi_clk_select(struct intel_encoder *encoder, 3043379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3044379bc100SJani Nikula { 3045379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3046379bc100SJani Nikula enum port port = encoder->port; 3047d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 3048379bc100SJani Nikula u32 val; 3049379bc100SJani Nikula const struct intel_shared_dpll *pll = crtc_state->shared_dpll; 3050379bc100SJani Nikula 30511de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, !pll)) 3052379bc100SJani Nikula return; 3053379bc100SJani Nikula 3054353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 3055379bc100SJani Nikula 3056379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) { 3057d8fe2ab6SMatt Roper if (!intel_phy_is_combo(dev_priv, phy)) 3058f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_CLK_SEL(port), 3059379bc100SJani Nikula icl_pll_to_ddi_clk_sel(encoder, crtc_state)); 3060c2052d6eSJosé Roberto de Souza else if (IS_ELKHARTLAKE(dev_priv) && port >= PORT_C) 3061c2052d6eSJosé Roberto de Souza /* 3062c2052d6eSJosé Roberto de Souza * MG does not exist but the programming is required 3063c2052d6eSJosé Roberto de Souza * to ungate DDIC and DDID 3064c2052d6eSJosé Roberto de Souza */ 3065f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_CLK_SEL(port), 3066f7960e7fSJani Nikula DDI_CLK_SEL_MG); 3067379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 3068379bc100SJani Nikula /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */ 3069f7960e7fSJani Nikula val = intel_de_read(dev_priv, DPCLKA_CFGCR0); 3070379bc100SJani Nikula val &= ~DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); 3071379bc100SJani Nikula val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, port); 3072f7960e7fSJani Nikula intel_de_write(dev_priv, DPCLKA_CFGCR0, val); 3073379bc100SJani Nikula 3074379bc100SJani Nikula /* 3075379bc100SJani Nikula * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI. 3076379bc100SJani Nikula * This step and the step before must be done with separate 3077379bc100SJani Nikula * register writes. 3078379bc100SJani Nikula */ 3079f7960e7fSJani Nikula val = intel_de_read(dev_priv, DPCLKA_CFGCR0); 3080379bc100SJani Nikula val &= ~DPCLKA_CFGCR0_DDI_CLK_OFF(port); 3081f7960e7fSJani Nikula intel_de_write(dev_priv, DPCLKA_CFGCR0, val); 3082379bc100SJani Nikula } else if (IS_GEN9_BC(dev_priv)) { 3083379bc100SJani Nikula /* DDI -> PLL mapping */ 3084f7960e7fSJani Nikula val = intel_de_read(dev_priv, DPLL_CTRL2); 3085379bc100SJani Nikula 3086379bc100SJani Nikula val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) | 3087379bc100SJani Nikula DPLL_CTRL2_DDI_CLK_SEL_MASK(port)); 3088379bc100SJani Nikula val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->info->id, port) | 3089379bc100SJani Nikula DPLL_CTRL2_DDI_SEL_OVERRIDE(port)); 3090379bc100SJani Nikula 3091f7960e7fSJani Nikula intel_de_write(dev_priv, DPLL_CTRL2, val); 3092379bc100SJani Nikula 3093379bc100SJani Nikula } else if (INTEL_GEN(dev_priv) < 9) { 3094f7960e7fSJani Nikula intel_de_write(dev_priv, PORT_CLK_SEL(port), 3095f7960e7fSJani Nikula hsw_pll_to_ddi_pll_sel(pll)); 3096379bc100SJani Nikula } 3097379bc100SJani Nikula 3098353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 3099379bc100SJani Nikula } 3100379bc100SJani Nikula 3101379bc100SJani Nikula static void intel_ddi_clk_disable(struct intel_encoder *encoder) 3102379bc100SJani Nikula { 3103379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3104379bc100SJani Nikula enum port port = encoder->port; 3105d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 3106379bc100SJani Nikula 3107379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) { 3108c2052d6eSJosé Roberto de Souza if (!intel_phy_is_combo(dev_priv, phy) || 3109c2052d6eSJosé Roberto de Souza (IS_ELKHARTLAKE(dev_priv) && port >= PORT_C)) 3110f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_CLK_SEL(port), 3111f7960e7fSJani Nikula DDI_CLK_SEL_NONE); 3112379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 3113f7960e7fSJani Nikula intel_de_write(dev_priv, DPCLKA_CFGCR0, 3114f7960e7fSJani Nikula intel_de_read(dev_priv, DPCLKA_CFGCR0) | DPCLKA_CFGCR0_DDI_CLK_OFF(port)); 3115379bc100SJani Nikula } else if (IS_GEN9_BC(dev_priv)) { 3116f7960e7fSJani Nikula intel_de_write(dev_priv, DPLL_CTRL2, 3117f7960e7fSJani Nikula intel_de_read(dev_priv, DPLL_CTRL2) | DPLL_CTRL2_DDI_CLK_OFF(port)); 3118379bc100SJani Nikula } else if (INTEL_GEN(dev_priv) < 9) { 3119f7960e7fSJani Nikula intel_de_write(dev_priv, PORT_CLK_SEL(port), 3120f7960e7fSJani Nikula PORT_CLK_SEL_NONE); 3121379bc100SJani Nikula } 3122379bc100SJani Nikula } 3123379bc100SJani Nikula 31248aaf5cbdSJosé Roberto de Souza static void 31257801f3b7SLucas De Marchi icl_program_mg_dp_mode(struct intel_digital_port *dig_port, 31263b51be4eSClinton A Taylor const struct intel_crtc_state *crtc_state) 3127379bc100SJani Nikula { 31287801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 31297801f3b7SLucas De Marchi enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port); 31303b51be4eSClinton A Taylor u32 ln0, ln1, pin_assignment; 31313b51be4eSClinton A Taylor u8 width; 3132379bc100SJani Nikula 31337801f3b7SLucas De Marchi if (dig_port->tc_mode == TC_PORT_TBT_ALT) 3134379bc100SJani Nikula return; 3135379bc100SJani Nikula 3136978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 3137f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3138f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x0)); 3139f7960e7fSJani Nikula ln0 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port)); 3140f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3141f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x1)); 3142f7960e7fSJani Nikula ln1 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port)); 3143978c3e53SClinton A Taylor } else { 3144f7960e7fSJani Nikula ln0 = intel_de_read(dev_priv, MG_DP_MODE(0, tc_port)); 3145f7960e7fSJani Nikula ln1 = intel_de_read(dev_priv, MG_DP_MODE(1, tc_port)); 3146978c3e53SClinton A Taylor } 3147379bc100SJani Nikula 31484f72a8eeSKhaled Almahallawy ln0 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE); 3149379bc100SJani Nikula ln1 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE); 3150379bc100SJani Nikula 31513b51be4eSClinton A Taylor /* DPPATC */ 31527801f3b7SLucas De Marchi pin_assignment = intel_tc_port_get_pin_assignment_mask(dig_port); 31533b51be4eSClinton A Taylor width = crtc_state->lane_count; 3154379bc100SJani Nikula 31553b51be4eSClinton A Taylor switch (pin_assignment) { 31563b51be4eSClinton A Taylor case 0x0: 31571de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 31587801f3b7SLucas De Marchi dig_port->tc_mode != TC_PORT_LEGACY); 31593b51be4eSClinton A Taylor if (width == 1) { 3160379bc100SJani Nikula ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 31613b51be4eSClinton A Taylor } else { 31623b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 31633b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 3164379bc100SJani Nikula } 3165379bc100SJani Nikula break; 31663b51be4eSClinton A Taylor case 0x1: 31673b51be4eSClinton A Taylor if (width == 4) { 31683b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 31693b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 31703b51be4eSClinton A Taylor } 3171379bc100SJani Nikula break; 31723b51be4eSClinton A Taylor case 0x2: 31733b51be4eSClinton A Taylor if (width == 2) { 31743b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 31753b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 31763b51be4eSClinton A Taylor } 31773b51be4eSClinton A Taylor break; 31783b51be4eSClinton A Taylor case 0x3: 31793b51be4eSClinton A Taylor case 0x5: 31803b51be4eSClinton A Taylor if (width == 1) { 31813b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X1_MODE; 31823b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 31833b51be4eSClinton A Taylor } else { 31843b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 31853b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 31863b51be4eSClinton A Taylor } 31873b51be4eSClinton A Taylor break; 31883b51be4eSClinton A Taylor case 0x4: 31893b51be4eSClinton A Taylor case 0x6: 31903b51be4eSClinton A Taylor if (width == 1) { 31913b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X1_MODE; 31923b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 31933b51be4eSClinton A Taylor } else { 31943b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 31953b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 31963b51be4eSClinton A Taylor } 31973b51be4eSClinton A Taylor break; 3198379bc100SJani Nikula default: 31993b51be4eSClinton A Taylor MISSING_CASE(pin_assignment); 3200379bc100SJani Nikula } 3201379bc100SJani Nikula 3202978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 3203f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3204f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x0)); 3205f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln0); 3206f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3207f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x1)); 3208f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln1); 3209978c3e53SClinton A Taylor } else { 3210f7960e7fSJani Nikula intel_de_write(dev_priv, MG_DP_MODE(0, tc_port), ln0); 3211f7960e7fSJani Nikula intel_de_write(dev_priv, MG_DP_MODE(1, tc_port), ln1); 3212379bc100SJani Nikula } 3213978c3e53SClinton A Taylor } 3214379bc100SJani Nikula 3215379bc100SJani Nikula static void intel_dp_sink_set_fec_ready(struct intel_dp *intel_dp, 3216379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3217379bc100SJani Nikula { 321847bdb1caSJani Nikula struct drm_i915_private *i915 = dp_to_i915(intel_dp); 321947bdb1caSJani Nikula 3220379bc100SJani Nikula if (!crtc_state->fec_enable) 3221379bc100SJani Nikula return; 3222379bc100SJani Nikula 3223379bc100SJani Nikula if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_FEC_CONFIGURATION, DP_FEC_READY) <= 0) 322447bdb1caSJani Nikula drm_dbg_kms(&i915->drm, 322547bdb1caSJani Nikula "Failed to set FEC_READY in the sink\n"); 3226379bc100SJani Nikula } 3227379bc100SJani Nikula 3228379bc100SJani Nikula static void intel_ddi_enable_fec(struct intel_encoder *encoder, 3229379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3230379bc100SJani Nikula { 3231379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 32324444df6eSLucas De Marchi struct intel_dp *intel_dp; 3233379bc100SJani Nikula u32 val; 3234379bc100SJani Nikula 3235379bc100SJani Nikula if (!crtc_state->fec_enable) 3236379bc100SJani Nikula return; 3237379bc100SJani Nikula 3238b7d02c3aSVille Syrjälä intel_dp = enc_to_intel_dp(encoder); 3239f7960e7fSJani Nikula val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3240379bc100SJani Nikula val |= DP_TP_CTL_FEC_ENABLE; 3241f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 3242379bc100SJani Nikula 32434444df6eSLucas De Marchi if (intel_de_wait_for_set(dev_priv, intel_dp->regs.dp_tp_status, 32444cb3b44dSDaniele Ceraolo Spurio DP_TP_STATUS_FEC_ENABLE_LIVE, 1)) 324547bdb1caSJani Nikula drm_err(&dev_priv->drm, 324647bdb1caSJani Nikula "Timed out waiting for FEC Enable Status\n"); 3247379bc100SJani Nikula } 3248379bc100SJani Nikula 3249379bc100SJani Nikula static void intel_ddi_disable_fec_state(struct intel_encoder *encoder, 3250379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3251379bc100SJani Nikula { 3252379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 32534444df6eSLucas De Marchi struct intel_dp *intel_dp; 3254379bc100SJani Nikula u32 val; 3255379bc100SJani Nikula 3256379bc100SJani Nikula if (!crtc_state->fec_enable) 3257379bc100SJani Nikula return; 3258379bc100SJani Nikula 3259b7d02c3aSVille Syrjälä intel_dp = enc_to_intel_dp(encoder); 3260f7960e7fSJani Nikula val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3261379bc100SJani Nikula val &= ~DP_TP_CTL_FEC_ENABLE; 3262f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 3263f7960e7fSJani Nikula intel_de_posting_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3264379bc100SJani Nikula } 3265379bc100SJani Nikula 3266ede9771dSVille Syrjälä static void tgl_ddi_pre_enable_dp(struct intel_atomic_state *state, 3267ede9771dSVille Syrjälä struct intel_encoder *encoder, 326899389390SJosé Roberto de Souza const struct intel_crtc_state *crtc_state, 326999389390SJosé Roberto de Souza const struct drm_connector_state *conn_state) 327099389390SJosé Roberto de Souza { 3271b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 327299389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 327399389390SJosé Roberto de Souza enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3274b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 327599389390SJosé Roberto de Souza bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 327699389390SJosé Roberto de Souza int level = intel_ddi_dp_level(intel_dp); 32774444df6eSLucas De Marchi enum transcoder transcoder = crtc_state->cpu_transcoder; 327899389390SJosé Roberto de Souza 327999389390SJosé Roberto de Souza intel_dp_set_link_params(intel_dp, crtc_state->port_clock, 328099389390SJosé Roberto de Souza crtc_state->lane_count, is_mst); 328199389390SJosé Roberto de Souza 32824444df6eSLucas De Marchi intel_dp->regs.dp_tp_ctl = TGL_DP_TP_CTL(transcoder); 32834444df6eSLucas De Marchi intel_dp->regs.dp_tp_status = TGL_DP_TP_STATUS(transcoder); 32844444df6eSLucas De Marchi 32855e19c0b0SMatt Roper /* 32865e19c0b0SMatt Roper * 1. Enable Power Wells 32875e19c0b0SMatt Roper * 32885e19c0b0SMatt Roper * This was handled at the beginning of intel_atomic_commit_tail(), 32895e19c0b0SMatt Roper * before we called down into this function. 32905e19c0b0SMatt Roper */ 329199389390SJosé Roberto de Souza 32925e19c0b0SMatt Roper /* 2. Enable Panel Power if PPS is required */ 329399389390SJosé Roberto de Souza intel_edp_panel_on(intel_dp); 329499389390SJosé Roberto de Souza 329599389390SJosé Roberto de Souza /* 32965e19c0b0SMatt Roper * 3. For non-TBT Type-C ports, set FIA lane count 32975e19c0b0SMatt Roper * (DFLEXDPSP.DPX4TXLATC) 32985e19c0b0SMatt Roper * 32995e19c0b0SMatt Roper * This was done before tgl_ddi_pre_enable_dp by 33001e98f88cSLucas De Marchi * hsw_crtc_enable()->intel_encoders_pre_pll_enable(). 330199389390SJosé Roberto de Souza */ 330299389390SJosé Roberto de Souza 33035e19c0b0SMatt Roper /* 33045e19c0b0SMatt Roper * 4. Enable the port PLL. 33055e19c0b0SMatt Roper * 33065e19c0b0SMatt Roper * The PLL enabling itself was already done before this function by 33071e98f88cSLucas De Marchi * hsw_crtc_enable()->intel_enable_shared_dpll(). We need only 33085e19c0b0SMatt Roper * configure the PLL to port mapping here. 33095e19c0b0SMatt Roper */ 33106171e58bSClinton A Taylor intel_ddi_clk_select(encoder, crtc_state); 33116171e58bSClinton A Taylor 33125e19c0b0SMatt Roper /* 5. If IO power is controlled through PWR_WELL_CTL, Enable IO Power */ 331399389390SJosé Roberto de Souza if (!intel_phy_is_tc(dev_priv, phy) || 331499389390SJosé Roberto de Souza dig_port->tc_mode != TC_PORT_TBT_ALT) 331599389390SJosé Roberto de Souza intel_display_power_get(dev_priv, 331699389390SJosé Roberto de Souza dig_port->ddi_io_power_domain); 331799389390SJosé Roberto de Souza 33185e19c0b0SMatt Roper /* 6. Program DP_MODE */ 33193b51be4eSClinton A Taylor icl_program_mg_dp_mode(dig_port, crtc_state); 332099389390SJosé Roberto de Souza 332199389390SJosé Roberto de Souza /* 33225e19c0b0SMatt Roper * 7. The rest of the below are substeps under the bspec's "Enable and 33235e19c0b0SMatt Roper * Train Display Port" step. Note that steps that are specific to 33245e19c0b0SMatt Roper * MST will be handled by intel_mst_pre_enable_dp() before/after it 33255e19c0b0SMatt Roper * calls into this function. Also intel_mst_pre_enable_dp() only calls 33265e19c0b0SMatt Roper * us when active_mst_links==0, so any steps designated for "single 33275e19c0b0SMatt Roper * stream or multi-stream master transcoder" can just be performed 33285e19c0b0SMatt Roper * unconditionally here. 33295e19c0b0SMatt Roper */ 33305e19c0b0SMatt Roper 33315e19c0b0SMatt Roper /* 33325e19c0b0SMatt Roper * 7.a Configure Transcoder Clock Select to direct the Port clock to the 33335e19c0b0SMatt Roper * Transcoder. 333499389390SJosé Roberto de Souza */ 333502a715c3SVille Syrjälä intel_ddi_enable_pipe_clock(encoder, crtc_state); 333699389390SJosé Roberto de Souza 33375e19c0b0SMatt Roper /* 33385e19c0b0SMatt Roper * 7.b Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST 33395e19c0b0SMatt Roper * Transport Select 33405e19c0b0SMatt Roper */ 3341eed22a46SVille Syrjälä intel_ddi_config_transcoder_func(encoder, crtc_state); 334299389390SJosé Roberto de Souza 33435e19c0b0SMatt Roper /* 33445e19c0b0SMatt Roper * 7.c Configure & enable DP_TP_CTL with link training pattern 1 33455e19c0b0SMatt Roper * selected 33465e19c0b0SMatt Roper * 33475e19c0b0SMatt Roper * This will be handled by the intel_dp_start_link_train() farther 33485e19c0b0SMatt Roper * down this function. 33495e19c0b0SMatt Roper */ 33505e19c0b0SMatt Roper 33515e19c0b0SMatt Roper /* 7.e Configure voltage swing and related IO settings */ 3352978c3e53SClinton A Taylor tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, level, 335399389390SJosé Roberto de Souza encoder->type); 335499389390SJosé Roberto de Souza 33555e19c0b0SMatt Roper /* 33565e19c0b0SMatt Roper * 7.f Combo PHY: Configure PORT_CL_DW10 Static Power Down to power up 33575e19c0b0SMatt Roper * the used lanes of the DDI. 33585e19c0b0SMatt Roper */ 335999389390SJosé Roberto de Souza if (intel_phy_is_combo(dev_priv, phy)) { 336099389390SJosé Roberto de Souza bool lane_reversal = 336199389390SJosé Roberto de Souza dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL; 336299389390SJosé Roberto de Souza 336399389390SJosé Roberto de Souza intel_combo_phy_power_up_lanes(dev_priv, phy, false, 336499389390SJosé Roberto de Souza crtc_state->lane_count, 336599389390SJosé Roberto de Souza lane_reversal); 336699389390SJosé Roberto de Souza } 336799389390SJosé Roberto de Souza 33685e19c0b0SMatt Roper /* 33695e19c0b0SMatt Roper * 7.g Configure and enable DDI_BUF_CTL 33705e19c0b0SMatt Roper * 7.h Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout 33715e19c0b0SMatt Roper * after 500 us. 33725e19c0b0SMatt Roper * 33735e19c0b0SMatt Roper * We only configure what the register value will be here. Actual 33745e19c0b0SMatt Roper * enabling happens during link training farther down. 33755e19c0b0SMatt Roper */ 337699389390SJosé Roberto de Souza intel_ddi_init_dp_buf_reg(encoder); 337799389390SJosé Roberto de Souza 337899389390SJosé Roberto de Souza if (!is_mst) 337999389390SJosé Roberto de Souza intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 338099389390SJosé Roberto de Souza 338199389390SJosé Roberto de Souza intel_dp_sink_set_decompression_state(intel_dp, crtc_state, true); 338299389390SJosé Roberto de Souza /* 338399389390SJosé Roberto de Souza * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit 338499389390SJosé Roberto de Souza * in the FEC_CONFIGURATION register to 1 before initiating link 338599389390SJosé Roberto de Souza * training 338699389390SJosé Roberto de Souza */ 338799389390SJosé Roberto de Souza intel_dp_sink_set_fec_ready(intel_dp, crtc_state); 33885e19c0b0SMatt Roper 33895e19c0b0SMatt Roper /* 33905e19c0b0SMatt Roper * 7.i Follow DisplayPort specification training sequence (see notes for 33915e19c0b0SMatt Roper * failure handling) 33925e19c0b0SMatt Roper * 7.j If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle 33935e19c0b0SMatt Roper * Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent) 33945e19c0b0SMatt Roper * (timeout after 800 us) 33955e19c0b0SMatt Roper */ 339699389390SJosé Roberto de Souza intel_dp_start_link_train(intel_dp); 339799389390SJosé Roberto de Souza 33985e19c0b0SMatt Roper /* 7.k Set DP_TP_CTL link training to Normal */ 3399eadf6f91SManasi Navare if (!is_trans_port_sync_mode(crtc_state)) 340099389390SJosé Roberto de Souza intel_dp_stop_link_train(intel_dp); 340199389390SJosé Roberto de Souza 34025e19c0b0SMatt Roper /* 7.l Configure and enable FEC if needed */ 340399389390SJosé Roberto de Souza intel_ddi_enable_fec(encoder, crtc_state); 340499389390SJosé Roberto de Souza intel_dsc_enable(encoder, crtc_state); 340599389390SJosé Roberto de Souza } 340699389390SJosé Roberto de Souza 3407ede9771dSVille Syrjälä static void hsw_ddi_pre_enable_dp(struct intel_atomic_state *state, 3408ede9771dSVille Syrjälä struct intel_encoder *encoder, 3409379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3410379bc100SJani Nikula const struct drm_connector_state *conn_state) 3411379bc100SJani Nikula { 3412b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3413379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3414379bc100SJani Nikula enum port port = encoder->port; 3415dc867bc7SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 3416b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3417379bc100SJani Nikula bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3418379bc100SJani Nikula int level = intel_ddi_dp_level(intel_dp); 3419379bc100SJani Nikula 3420542dfab5SJosé Roberto de Souza if (INTEL_GEN(dev_priv) < 11) 34211de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 34221de143ccSPankaj Bharadiya is_mst && (port == PORT_A || port == PORT_E)); 3423542dfab5SJosé Roberto de Souza else 34241de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, is_mst && port == PORT_A); 3425379bc100SJani Nikula 3426379bc100SJani Nikula intel_dp_set_link_params(intel_dp, crtc_state->port_clock, 3427379bc100SJani Nikula crtc_state->lane_count, is_mst); 3428379bc100SJani Nikula 3429379bc100SJani Nikula intel_edp_panel_on(intel_dp); 3430379bc100SJani Nikula 3431379bc100SJani Nikula intel_ddi_clk_select(encoder, crtc_state); 3432379bc100SJani Nikula 3433d8fe2ab6SMatt Roper if (!intel_phy_is_tc(dev_priv, phy) || 34343b2ed431SImre Deak dig_port->tc_mode != TC_PORT_TBT_ALT) 34353b2ed431SImre Deak intel_display_power_get(dev_priv, 34363b2ed431SImre Deak dig_port->ddi_io_power_domain); 3437379bc100SJani Nikula 34383b51be4eSClinton A Taylor icl_program_mg_dp_mode(dig_port, crtc_state); 3439379bc100SJani Nikula 3440379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 3441379bc100SJani Nikula icl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3442379bc100SJani Nikula level, encoder->type); 3443379bc100SJani Nikula else if (IS_CANNONLAKE(dev_priv)) 3444379bc100SJani Nikula cnl_ddi_vswing_sequence(encoder, level, encoder->type); 3445379bc100SJani Nikula else if (IS_GEN9_LP(dev_priv)) 3446379bc100SJani Nikula bxt_ddi_vswing_sequence(encoder, level, encoder->type); 3447379bc100SJani Nikula else 3448379bc100SJani Nikula intel_prepare_dp_ddi_buffers(encoder, crtc_state); 3449379bc100SJani Nikula 3450d8fe2ab6SMatt Roper if (intel_phy_is_combo(dev_priv, phy)) { 3451379bc100SJani Nikula bool lane_reversal = 3452379bc100SJani Nikula dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL; 3453379bc100SJani Nikula 3454dc867bc7SMatt Roper intel_combo_phy_power_up_lanes(dev_priv, phy, false, 3455379bc100SJani Nikula crtc_state->lane_count, 3456379bc100SJani Nikula lane_reversal); 3457379bc100SJani Nikula } 3458379bc100SJani Nikula 3459379bc100SJani Nikula intel_ddi_init_dp_buf_reg(encoder); 3460379bc100SJani Nikula if (!is_mst) 3461379bc100SJani Nikula intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 3462379bc100SJani Nikula intel_dp_sink_set_decompression_state(intel_dp, crtc_state, 3463379bc100SJani Nikula true); 3464379bc100SJani Nikula intel_dp_sink_set_fec_ready(intel_dp, crtc_state); 3465379bc100SJani Nikula intel_dp_start_link_train(intel_dp); 3466eadf6f91SManasi Navare if ((port != PORT_A || INTEL_GEN(dev_priv) >= 9) && 3467eadf6f91SManasi Navare !is_trans_port_sync_mode(crtc_state)) 3468379bc100SJani Nikula intel_dp_stop_link_train(intel_dp); 3469379bc100SJani Nikula 3470379bc100SJani Nikula intel_ddi_enable_fec(encoder, crtc_state); 3471379bc100SJani Nikula 3472379bc100SJani Nikula if (!is_mst) 347302a715c3SVille Syrjälä intel_ddi_enable_pipe_clock(encoder, crtc_state); 3474379bc100SJani Nikula 3475379bc100SJani Nikula intel_dsc_enable(encoder, crtc_state); 3476379bc100SJani Nikula } 3477379bc100SJani Nikula 3478ede9771dSVille Syrjälä static void intel_ddi_pre_enable_dp(struct intel_atomic_state *state, 3479ede9771dSVille Syrjälä struct intel_encoder *encoder, 348099389390SJosé Roberto de Souza const struct intel_crtc_state *crtc_state, 348199389390SJosé Roberto de Souza const struct drm_connector_state *conn_state) 348299389390SJosé Roberto de Souza { 348399389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 348499389390SJosé Roberto de Souza 348599389390SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 3486ede9771dSVille Syrjälä tgl_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state); 348799389390SJosé Roberto de Souza else 3488ede9771dSVille Syrjälä hsw_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state); 34890c06fa15SGwan-gyeong Mun 3490bd8c9ccaSGwan-gyeong Mun /* MST will call a setting of MSA after an allocating of Virtual Channel 3491bd8c9ccaSGwan-gyeong Mun * from MST encoder pre_enable callback. 3492bd8c9ccaSGwan-gyeong Mun */ 34931fc1e8d4SJosé Roberto de Souza if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) { 34940c06fa15SGwan-gyeong Mun intel_ddi_set_dp_msa(crtc_state, conn_state); 34951c9d2eb2SJani Nikula 34961c9d2eb2SJani Nikula intel_dp_set_m_n(crtc_state, M1_N1); 349799389390SJosé Roberto de Souza } 34981fc1e8d4SJosé Roberto de Souza } 349999389390SJosé Roberto de Souza 3500ede9771dSVille Syrjälä static void intel_ddi_pre_enable_hdmi(struct intel_atomic_state *state, 3501ede9771dSVille Syrjälä struct intel_encoder *encoder, 3502379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3503379bc100SJani Nikula const struct drm_connector_state *conn_state) 3504379bc100SJani Nikula { 35050ba7ffeaSLucas De Marchi struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 35060ba7ffeaSLucas De Marchi struct intel_hdmi *intel_hdmi = &dig_port->hdmi; 3507379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 35080aed3bdeSJani Nikula int level = intel_ddi_hdmi_level(encoder); 3509379bc100SJani Nikula 3510379bc100SJani Nikula intel_dp_dual_mode_set_tmds_output(intel_hdmi, true); 3511379bc100SJani Nikula intel_ddi_clk_select(encoder, crtc_state); 3512379bc100SJani Nikula 3513379bc100SJani Nikula intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain); 3514379bc100SJani Nikula 35153b51be4eSClinton A Taylor icl_program_mg_dp_mode(dig_port, crtc_state); 3516379bc100SJani Nikula 3517978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) 3518978c3e53SClinton A Taylor tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3519978c3e53SClinton A Taylor level, INTEL_OUTPUT_HDMI); 3520978c3e53SClinton A Taylor else if (INTEL_GEN(dev_priv) == 11) 3521379bc100SJani Nikula icl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3522379bc100SJani Nikula level, INTEL_OUTPUT_HDMI); 3523379bc100SJani Nikula else if (IS_CANNONLAKE(dev_priv)) 3524379bc100SJani Nikula cnl_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI); 3525379bc100SJani Nikula else if (IS_GEN9_LP(dev_priv)) 3526379bc100SJani Nikula bxt_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI); 3527379bc100SJani Nikula else 3528379bc100SJani Nikula intel_prepare_hdmi_ddi_buffers(encoder, level); 3529379bc100SJani Nikula 3530379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) 3531379bc100SJani Nikula skl_ddi_set_iboost(encoder, level, INTEL_OUTPUT_HDMI); 3532379bc100SJani Nikula 353302a715c3SVille Syrjälä intel_ddi_enable_pipe_clock(encoder, crtc_state); 3534379bc100SJani Nikula 35350ba7ffeaSLucas De Marchi dig_port->set_infoframes(encoder, 3536379bc100SJani Nikula crtc_state->has_infoframe, 3537379bc100SJani Nikula crtc_state, conn_state); 3538379bc100SJani Nikula } 3539379bc100SJani Nikula 3540ede9771dSVille Syrjälä static void intel_ddi_pre_enable(struct intel_atomic_state *state, 3541ede9771dSVille Syrjälä struct intel_encoder *encoder, 3542379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3543379bc100SJani Nikula const struct drm_connector_state *conn_state) 3544379bc100SJani Nikula { 35452225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3546379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3547379bc100SJani Nikula enum pipe pipe = crtc->pipe; 3548379bc100SJani Nikula 3549379bc100SJani Nikula /* 3550379bc100SJani Nikula * When called from DP MST code: 3551379bc100SJani Nikula * - conn_state will be NULL 3552379bc100SJani Nikula * - encoder will be the main encoder (ie. mst->primary) 3553379bc100SJani Nikula * - the main connector associated with this port 3554379bc100SJani Nikula * won't be active or linked to a crtc 3555379bc100SJani Nikula * - crtc_state will be the state of the first stream to 3556379bc100SJani Nikula * be activated on this port, and it may not be the same 3557379bc100SJani Nikula * stream that will be deactivated last, but each stream 3558379bc100SJani Nikula * should have a state that is identical when it comes to 3559379bc100SJani Nikula * the DP link parameteres 3560379bc100SJani Nikula */ 3561379bc100SJani Nikula 35621de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, crtc_state->has_pch_encoder); 3563379bc100SJani Nikula 3564379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 3565379bc100SJani Nikula icl_map_plls_to_ports(encoder, crtc_state); 3566379bc100SJani Nikula 3567379bc100SJani Nikula intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 3568379bc100SJani Nikula 3569379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 3570ede9771dSVille Syrjälä intel_ddi_pre_enable_hdmi(state, encoder, crtc_state, 3571ede9771dSVille Syrjälä conn_state); 3572379bc100SJani Nikula } else { 3573379bc100SJani Nikula struct intel_lspcon *lspcon = 3574b7d02c3aSVille Syrjälä enc_to_intel_lspcon(encoder); 3575379bc100SJani Nikula 3576ede9771dSVille Syrjälä intel_ddi_pre_enable_dp(state, encoder, crtc_state, 3577ede9771dSVille Syrjälä conn_state); 3578379bc100SJani Nikula if (lspcon->active) { 3579379bc100SJani Nikula struct intel_digital_port *dig_port = 3580b7d02c3aSVille Syrjälä enc_to_dig_port(encoder); 3581379bc100SJani Nikula 3582379bc100SJani Nikula dig_port->set_infoframes(encoder, 3583379bc100SJani Nikula crtc_state->has_infoframe, 3584379bc100SJani Nikula crtc_state, conn_state); 3585379bc100SJani Nikula } 3586379bc100SJani Nikula } 3587379bc100SJani Nikula } 3588379bc100SJani Nikula 3589379bc100SJani Nikula static void intel_disable_ddi_buf(struct intel_encoder *encoder, 3590379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3591379bc100SJani Nikula { 3592379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3593379bc100SJani Nikula enum port port = encoder->port; 3594379bc100SJani Nikula bool wait = false; 3595379bc100SJani Nikula u32 val; 3596379bc100SJani Nikula 3597f7960e7fSJani Nikula val = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 3598379bc100SJani Nikula if (val & DDI_BUF_CTL_ENABLE) { 3599379bc100SJani Nikula val &= ~DDI_BUF_CTL_ENABLE; 3600f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), val); 3601379bc100SJani Nikula wait = true; 3602379bc100SJani Nikula } 3603379bc100SJani Nikula 3604e468ff06SLucas De Marchi if (intel_crtc_has_dp_encoder(crtc_state)) { 3605b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 36064444df6eSLucas De Marchi 3607f7960e7fSJani Nikula val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3608379bc100SJani Nikula val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 3609379bc100SJani Nikula val |= DP_TP_CTL_LINK_TRAIN_PAT1; 3610f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 3611e468ff06SLucas De Marchi } 3612379bc100SJani Nikula 3613379bc100SJani Nikula /* Disable FEC in DP Sink */ 3614379bc100SJani Nikula intel_ddi_disable_fec_state(encoder, crtc_state); 3615379bc100SJani Nikula 3616379bc100SJani Nikula if (wait) 3617379bc100SJani Nikula intel_wait_ddi_buf_idle(dev_priv, port); 3618379bc100SJani Nikula } 3619379bc100SJani Nikula 3620ede9771dSVille Syrjälä static void intel_ddi_post_disable_dp(struct intel_atomic_state *state, 3621ede9771dSVille Syrjälä struct intel_encoder *encoder, 3622379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3623379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3624379bc100SJani Nikula { 3625379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3626b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3627379bc100SJani Nikula struct intel_dp *intel_dp = &dig_port->dp; 3628379bc100SJani Nikula bool is_mst = intel_crtc_has_type(old_crtc_state, 3629379bc100SJani Nikula INTEL_OUTPUT_DP_MST); 3630d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3631379bc100SJani Nikula 3632c980216dSImre Deak if (!is_mst) 3633c980216dSImre Deak intel_dp_set_infoframes(encoder, false, 3634c980216dSImre Deak old_crtc_state, old_conn_state); 3635fa37a213SGwan-gyeong Mun 3636379bc100SJani Nikula /* 3637379bc100SJani Nikula * Power down sink before disabling the port, otherwise we end 3638379bc100SJani Nikula * up getting interrupts from the sink on detecting link loss. 3639379bc100SJani Nikula */ 3640379bc100SJani Nikula intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 364178eaaba3SJosé Roberto de Souza 3642c59053dcSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 3643c59053dcSJosé Roberto de Souza if (is_mst) { 3644c59053dcSJosé Roberto de Souza enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 3645c59053dcSJosé Roberto de Souza u32 val; 3646c59053dcSJosé Roberto de Souza 3647f7960e7fSJani Nikula val = intel_de_read(dev_priv, 3648f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(cpu_transcoder)); 3649919e4f07SJosé Roberto de Souza val &= ~(TGL_TRANS_DDI_PORT_MASK | 3650919e4f07SJosé Roberto de Souza TRANS_DDI_MODE_SELECT_MASK); 3651f7960e7fSJani Nikula intel_de_write(dev_priv, 3652f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(cpu_transcoder), 3653f7960e7fSJani Nikula val); 3654c59053dcSJosé Roberto de Souza } 3655c59053dcSJosé Roberto de Souza } else { 3656c59053dcSJosé Roberto de Souza if (!is_mst) 365750a7efb2SJosé Roberto de Souza intel_ddi_disable_pipe_clock(old_crtc_state); 3658c59053dcSJosé Roberto de Souza } 3659379bc100SJani Nikula 3660379bc100SJani Nikula intel_disable_ddi_buf(encoder, old_crtc_state); 3661379bc100SJani Nikula 36623ca8f191SJosé Roberto de Souza /* 36633ca8f191SJosé Roberto de Souza * From TGL spec: "If single stream or multi-stream master transcoder: 36643ca8f191SJosé Roberto de Souza * Configure Transcoder Clock select to direct no clock to the 36653ca8f191SJosé Roberto de Souza * transcoder" 36663ca8f191SJosé Roberto de Souza */ 36673ca8f191SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 36683ca8f191SJosé Roberto de Souza intel_ddi_disable_pipe_clock(old_crtc_state); 36693ca8f191SJosé Roberto de Souza 3670379bc100SJani Nikula intel_edp_panel_vdd_on(intel_dp); 3671379bc100SJani Nikula intel_edp_panel_off(intel_dp); 3672379bc100SJani Nikula 3673d8fe2ab6SMatt Roper if (!intel_phy_is_tc(dev_priv, phy) || 36743b2ed431SImre Deak dig_port->tc_mode != TC_PORT_TBT_ALT) 3675379bc100SJani Nikula intel_display_power_put_unchecked(dev_priv, 3676379bc100SJani Nikula dig_port->ddi_io_power_domain); 3677379bc100SJani Nikula 3678379bc100SJani Nikula intel_ddi_clk_disable(encoder); 3679379bc100SJani Nikula } 3680379bc100SJani Nikula 3681ede9771dSVille Syrjälä static void intel_ddi_post_disable_hdmi(struct intel_atomic_state *state, 3682ede9771dSVille Syrjälä struct intel_encoder *encoder, 3683379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3684379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3685379bc100SJani Nikula { 3686379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3687b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3688379bc100SJani Nikula struct intel_hdmi *intel_hdmi = &dig_port->hdmi; 3689379bc100SJani Nikula 3690379bc100SJani Nikula dig_port->set_infoframes(encoder, false, 3691379bc100SJani Nikula old_crtc_state, old_conn_state); 3692379bc100SJani Nikula 3693379bc100SJani Nikula intel_ddi_disable_pipe_clock(old_crtc_state); 3694379bc100SJani Nikula 3695379bc100SJani Nikula intel_disable_ddi_buf(encoder, old_crtc_state); 3696379bc100SJani Nikula 3697379bc100SJani Nikula intel_display_power_put_unchecked(dev_priv, 3698379bc100SJani Nikula dig_port->ddi_io_power_domain); 3699379bc100SJani Nikula 3700379bc100SJani Nikula intel_ddi_clk_disable(encoder); 3701379bc100SJani Nikula 3702379bc100SJani Nikula intel_dp_dual_mode_set_tmds_output(intel_hdmi, false); 3703379bc100SJani Nikula } 3704379bc100SJani Nikula 3705ede9771dSVille Syrjälä static void intel_ddi_post_disable(struct intel_atomic_state *state, 3706ede9771dSVille Syrjälä struct intel_encoder *encoder, 3707379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3708379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3709379bc100SJani Nikula { 3710379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3711b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 371217bef9baSVille Syrjälä enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 371317bef9baSVille Syrjälä bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 3714379bc100SJani Nikula 37157829c92bSVille Syrjälä if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) { 3716773b4b54SVille Syrjälä intel_crtc_vblank_off(old_crtc_state); 3717773b4b54SVille Syrjälä 3718773b4b54SVille Syrjälä intel_disable_pipe(old_crtc_state); 3719773b4b54SVille Syrjälä 3720773b4b54SVille Syrjälä intel_ddi_disable_transcoder_func(old_crtc_state); 3721773b4b54SVille Syrjälä 3722773b4b54SVille Syrjälä intel_dsc_disable(old_crtc_state); 3723773b4b54SVille Syrjälä 3724773b4b54SVille Syrjälä if (INTEL_GEN(dev_priv) >= 9) 3725f6df4d46SLucas De Marchi skl_scaler_disable(old_crtc_state); 3726773b4b54SVille Syrjälä else 37279eae5e27SLucas De Marchi ilk_pfit_disable(old_crtc_state); 37287829c92bSVille Syrjälä } 3729773b4b54SVille Syrjälä 3730379bc100SJani Nikula /* 3731379bc100SJani Nikula * When called from DP MST code: 3732379bc100SJani Nikula * - old_conn_state will be NULL 3733379bc100SJani Nikula * - encoder will be the main encoder (ie. mst->primary) 3734379bc100SJani Nikula * - the main connector associated with this port 3735379bc100SJani Nikula * won't be active or linked to a crtc 3736379bc100SJani Nikula * - old_crtc_state will be the state of the last stream to 3737379bc100SJani Nikula * be deactivated on this port, and it may not be the same 3738379bc100SJani Nikula * stream that was activated last, but each stream 3739379bc100SJani Nikula * should have a state that is identical when it comes to 3740379bc100SJani Nikula * the DP link parameteres 3741379bc100SJani Nikula */ 3742379bc100SJani Nikula 3743379bc100SJani Nikula if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI)) 3744ede9771dSVille Syrjälä intel_ddi_post_disable_hdmi(state, encoder, old_crtc_state, 3745ede9771dSVille Syrjälä old_conn_state); 3746379bc100SJani Nikula else 3747ede9771dSVille Syrjälä intel_ddi_post_disable_dp(state, encoder, old_crtc_state, 3748ede9771dSVille Syrjälä old_conn_state); 3749379bc100SJani Nikula 3750379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 3751379bc100SJani Nikula icl_unmap_plls_to_ports(encoder); 375217bef9baSVille Syrjälä 375317bef9baSVille Syrjälä if (intel_crtc_has_dp_encoder(old_crtc_state) || is_tc_port) 375417bef9baSVille Syrjälä intel_display_power_put_unchecked(dev_priv, 375517bef9baSVille Syrjälä intel_ddi_main_link_aux_domain(dig_port)); 375617bef9baSVille Syrjälä 375717bef9baSVille Syrjälä if (is_tc_port) 375817bef9baSVille Syrjälä intel_tc_port_put_link(dig_port); 3759379bc100SJani Nikula } 3760379bc100SJani Nikula 3761ede9771dSVille Syrjälä void intel_ddi_fdi_post_disable(struct intel_atomic_state *state, 3762ede9771dSVille Syrjälä struct intel_encoder *encoder, 3763379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3764379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3765379bc100SJani Nikula { 3766379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3767379bc100SJani Nikula u32 val; 3768379bc100SJani Nikula 3769379bc100SJani Nikula /* 3770379bc100SJani Nikula * Bspec lists this as both step 13 (before DDI_BUF_CTL disable) 3771379bc100SJani Nikula * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN, 3772379bc100SJani Nikula * step 13 is the correct place for it. Step 18 is where it was 3773379bc100SJani Nikula * originally before the BUN. 3774379bc100SJani Nikula */ 3775f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A)); 3776379bc100SJani Nikula val &= ~FDI_RX_ENABLE; 3777f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val); 3778379bc100SJani Nikula 3779379bc100SJani Nikula intel_disable_ddi_buf(encoder, old_crtc_state); 3780379bc100SJani Nikula intel_ddi_clk_disable(encoder); 3781379bc100SJani Nikula 3782f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A)); 3783379bc100SJani Nikula val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 3784379bc100SJani Nikula val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); 3785f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), val); 3786379bc100SJani Nikula 3787f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A)); 3788379bc100SJani Nikula val &= ~FDI_PCDCLK; 3789f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val); 3790379bc100SJani Nikula 3791f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A)); 3792379bc100SJani Nikula val &= ~FDI_RX_PLL_ENABLE; 3793f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val); 3794379bc100SJani Nikula } 3795379bc100SJani Nikula 3796d82a855aSVille Syrjälä static void trans_port_sync_stop_link_train(struct intel_atomic_state *state, 3797d82a855aSVille Syrjälä struct intel_encoder *encoder, 3798d82a855aSVille Syrjälä const struct intel_crtc_state *crtc_state) 3799d82a855aSVille Syrjälä { 3800d82a855aSVille Syrjälä const struct drm_connector_state *conn_state; 3801d82a855aSVille Syrjälä struct drm_connector *conn; 3802d82a855aSVille Syrjälä int i; 3803d82a855aSVille Syrjälä 3804d82a855aSVille Syrjälä if (!crtc_state->sync_mode_slaves_mask) 3805d82a855aSVille Syrjälä return; 3806d82a855aSVille Syrjälä 3807d82a855aSVille Syrjälä for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 3808d82a855aSVille Syrjälä struct intel_encoder *slave_encoder = 3809d82a855aSVille Syrjälä to_intel_encoder(conn_state->best_encoder); 3810d82a855aSVille Syrjälä struct intel_crtc *slave_crtc = to_intel_crtc(conn_state->crtc); 3811d82a855aSVille Syrjälä const struct intel_crtc_state *slave_crtc_state; 3812d82a855aSVille Syrjälä 3813d82a855aSVille Syrjälä if (!slave_crtc) 3814d82a855aSVille Syrjälä continue; 3815d82a855aSVille Syrjälä 3816d82a855aSVille Syrjälä slave_crtc_state = 3817d82a855aSVille Syrjälä intel_atomic_get_new_crtc_state(state, slave_crtc); 3818d82a855aSVille Syrjälä 3819d82a855aSVille Syrjälä if (slave_crtc_state->master_transcoder != 3820d82a855aSVille Syrjälä crtc_state->cpu_transcoder) 3821d82a855aSVille Syrjälä continue; 3822d82a855aSVille Syrjälä 3823d82a855aSVille Syrjälä intel_dp_stop_link_train(enc_to_intel_dp(slave_encoder)); 3824d82a855aSVille Syrjälä } 3825d82a855aSVille Syrjälä 3826d82a855aSVille Syrjälä usleep_range(200, 400); 3827d82a855aSVille Syrjälä 3828d82a855aSVille Syrjälä intel_dp_stop_link_train(enc_to_intel_dp(encoder)); 3829d82a855aSVille Syrjälä } 3830d82a855aSVille Syrjälä 3831ede9771dSVille Syrjälä static void intel_enable_ddi_dp(struct intel_atomic_state *state, 3832ede9771dSVille Syrjälä struct intel_encoder *encoder, 3833379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3834379bc100SJani Nikula const struct drm_connector_state *conn_state) 3835379bc100SJani Nikula { 3836379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3837b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3838379bc100SJani Nikula enum port port = encoder->port; 3839379bc100SJani Nikula 3840379bc100SJani Nikula if (port == PORT_A && INTEL_GEN(dev_priv) < 9) 3841379bc100SJani Nikula intel_dp_stop_link_train(intel_dp); 3842379bc100SJani Nikula 3843379bc100SJani Nikula intel_edp_backlight_on(crtc_state, conn_state); 38447a00e68bSGwan-gyeong Mun intel_psr_enable(intel_dp, crtc_state, conn_state); 38451bf3657cSGwan-gyeong Mun intel_dp_set_infoframes(encoder, true, crtc_state, conn_state); 3846379bc100SJani Nikula intel_edp_drrs_enable(intel_dp, crtc_state); 3847379bc100SJani Nikula 3848379bc100SJani Nikula if (crtc_state->has_audio) 3849379bc100SJani Nikula intel_audio_codec_enable(encoder, crtc_state, conn_state); 3850d82a855aSVille Syrjälä 3851d82a855aSVille Syrjälä trans_port_sync_stop_link_train(state, encoder, crtc_state); 3852379bc100SJani Nikula } 3853379bc100SJani Nikula 3854379bc100SJani Nikula static i915_reg_t 3855379bc100SJani Nikula gen9_chicken_trans_reg_by_port(struct drm_i915_private *dev_priv, 3856379bc100SJani Nikula enum port port) 3857379bc100SJani Nikula { 385812c4d4c1SVille Syrjälä static const enum transcoder trans[] = { 385912c4d4c1SVille Syrjälä [PORT_A] = TRANSCODER_EDP, 386012c4d4c1SVille Syrjälä [PORT_B] = TRANSCODER_A, 386112c4d4c1SVille Syrjälä [PORT_C] = TRANSCODER_B, 386212c4d4c1SVille Syrjälä [PORT_D] = TRANSCODER_C, 386312c4d4c1SVille Syrjälä [PORT_E] = TRANSCODER_A, 3864379bc100SJani Nikula }; 3865379bc100SJani Nikula 38661de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, INTEL_GEN(dev_priv) < 9); 3867379bc100SJani Nikula 38681de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, port < PORT_A || port > PORT_E)) 3869379bc100SJani Nikula port = PORT_A; 3870379bc100SJani Nikula 387112c4d4c1SVille Syrjälä return CHICKEN_TRANS(trans[port]); 3872379bc100SJani Nikula } 3873379bc100SJani Nikula 3874ede9771dSVille Syrjälä static void intel_enable_ddi_hdmi(struct intel_atomic_state *state, 3875ede9771dSVille Syrjälä struct intel_encoder *encoder, 3876379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3877379bc100SJani Nikula const struct drm_connector_state *conn_state) 3878379bc100SJani Nikula { 3879379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3880b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3881379bc100SJani Nikula struct drm_connector *connector = conn_state->connector; 3882379bc100SJani Nikula enum port port = encoder->port; 3883379bc100SJani Nikula 3884379bc100SJani Nikula if (!intel_hdmi_handle_sink_scrambling(encoder, connector, 3885379bc100SJani Nikula crtc_state->hdmi_high_tmds_clock_ratio, 3886379bc100SJani Nikula crtc_state->hdmi_scrambling)) 388747bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 388847bdb1caSJani Nikula "[CONNECTOR:%d:%s] Failed to configure sink scrambling/TMDS bit clock ratio\n", 3889379bc100SJani Nikula connector->base.id, connector->name); 3890379bc100SJani Nikula 3891379bc100SJani Nikula /* Display WA #1143: skl,kbl,cfl */ 3892379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) { 3893379bc100SJani Nikula /* 3894379bc100SJani Nikula * For some reason these chicken bits have been 3895379bc100SJani Nikula * stuffed into a transcoder register, event though 3896379bc100SJani Nikula * the bits affect a specific DDI port rather than 3897379bc100SJani Nikula * a specific transcoder. 3898379bc100SJani Nikula */ 3899379bc100SJani Nikula i915_reg_t reg = gen9_chicken_trans_reg_by_port(dev_priv, port); 3900379bc100SJani Nikula u32 val; 3901379bc100SJani Nikula 3902f7960e7fSJani Nikula val = intel_de_read(dev_priv, reg); 3903379bc100SJani Nikula 3904379bc100SJani Nikula if (port == PORT_E) 3905379bc100SJani Nikula val |= DDIE_TRAINING_OVERRIDE_ENABLE | 3906379bc100SJani Nikula DDIE_TRAINING_OVERRIDE_VALUE; 3907379bc100SJani Nikula else 3908379bc100SJani Nikula val |= DDI_TRAINING_OVERRIDE_ENABLE | 3909379bc100SJani Nikula DDI_TRAINING_OVERRIDE_VALUE; 3910379bc100SJani Nikula 3911f7960e7fSJani Nikula intel_de_write(dev_priv, reg, val); 3912f7960e7fSJani Nikula intel_de_posting_read(dev_priv, reg); 3913379bc100SJani Nikula 3914379bc100SJani Nikula udelay(1); 3915379bc100SJani Nikula 3916379bc100SJani Nikula if (port == PORT_E) 3917379bc100SJani Nikula val &= ~(DDIE_TRAINING_OVERRIDE_ENABLE | 3918379bc100SJani Nikula DDIE_TRAINING_OVERRIDE_VALUE); 3919379bc100SJani Nikula else 3920379bc100SJani Nikula val &= ~(DDI_TRAINING_OVERRIDE_ENABLE | 3921379bc100SJani Nikula DDI_TRAINING_OVERRIDE_VALUE); 3922379bc100SJani Nikula 3923f7960e7fSJani Nikula intel_de_write(dev_priv, reg, val); 3924379bc100SJani Nikula } 3925379bc100SJani Nikula 3926379bc100SJani Nikula /* In HDMI/DVI mode, the port width, and swing/emphasis values 3927379bc100SJani Nikula * are ignored so nothing special needs to be done besides 3928379bc100SJani Nikula * enabling the port. 3929379bc100SJani Nikula */ 3930f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), 3931379bc100SJani Nikula dig_port->saved_port_bits | DDI_BUF_CTL_ENABLE); 3932379bc100SJani Nikula 3933379bc100SJani Nikula if (crtc_state->has_audio) 3934379bc100SJani Nikula intel_audio_codec_enable(encoder, crtc_state, conn_state); 3935379bc100SJani Nikula } 3936379bc100SJani Nikula 3937ede9771dSVille Syrjälä static void intel_enable_ddi(struct intel_atomic_state *state, 3938ede9771dSVille Syrjälä struct intel_encoder *encoder, 3939379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3940379bc100SJani Nikula const struct drm_connector_state *conn_state) 3941379bc100SJani Nikula { 39428b4f2137SPankaj Bharadiya drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder); 394321fd23acSJani Nikula 3944eed22a46SVille Syrjälä intel_ddi_enable_transcoder_func(encoder, crtc_state); 39457c2fedd7SVille Syrjälä 394621fd23acSJani Nikula intel_enable_pipe(crtc_state); 394721fd23acSJani Nikula 394821fd23acSJani Nikula intel_crtc_vblank_on(crtc_state); 394921fd23acSJani Nikula 3950379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) 3951ede9771dSVille Syrjälä intel_enable_ddi_hdmi(state, encoder, crtc_state, conn_state); 3952379bc100SJani Nikula else 3953ede9771dSVille Syrjälä intel_enable_ddi_dp(state, encoder, crtc_state, conn_state); 3954379bc100SJani Nikula 3955379bc100SJani Nikula /* Enable hdcp if it's desired */ 3956379bc100SJani Nikula if (conn_state->content_protection == 3957379bc100SJani Nikula DRM_MODE_CONTENT_PROTECTION_DESIRED) 3958d456512cSRamalingam C intel_hdcp_enable(to_intel_connector(conn_state->connector), 395967e1d5edSVille Syrjälä crtc_state->cpu_transcoder, 3960d456512cSRamalingam C (u8)conn_state->hdcp_content_type); 3961379bc100SJani Nikula } 3962379bc100SJani Nikula 3963ede9771dSVille Syrjälä static void intel_disable_ddi_dp(struct intel_atomic_state *state, 3964ede9771dSVille Syrjälä struct intel_encoder *encoder, 3965379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3966379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3967379bc100SJani Nikula { 3968b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3969379bc100SJani Nikula 3970379bc100SJani Nikula intel_dp->link_trained = false; 3971379bc100SJani Nikula 3972379bc100SJani Nikula if (old_crtc_state->has_audio) 3973379bc100SJani Nikula intel_audio_codec_disable(encoder, 3974379bc100SJani Nikula old_crtc_state, old_conn_state); 3975379bc100SJani Nikula 3976379bc100SJani Nikula intel_edp_drrs_disable(intel_dp, old_crtc_state); 3977379bc100SJani Nikula intel_psr_disable(intel_dp, old_crtc_state); 3978379bc100SJani Nikula intel_edp_backlight_off(old_conn_state); 3979379bc100SJani Nikula /* Disable the decompression in DP Sink */ 3980379bc100SJani Nikula intel_dp_sink_set_decompression_state(intel_dp, old_crtc_state, 3981379bc100SJani Nikula false); 3982379bc100SJani Nikula } 3983379bc100SJani Nikula 3984ede9771dSVille Syrjälä static void intel_disable_ddi_hdmi(struct intel_atomic_state *state, 3985ede9771dSVille Syrjälä struct intel_encoder *encoder, 3986379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3987379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3988379bc100SJani Nikula { 398947bdb1caSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev); 3990379bc100SJani Nikula struct drm_connector *connector = old_conn_state->connector; 3991379bc100SJani Nikula 3992379bc100SJani Nikula if (old_crtc_state->has_audio) 3993379bc100SJani Nikula intel_audio_codec_disable(encoder, 3994379bc100SJani Nikula old_crtc_state, old_conn_state); 3995379bc100SJani Nikula 3996379bc100SJani Nikula if (!intel_hdmi_handle_sink_scrambling(encoder, connector, 3997379bc100SJani Nikula false, false)) 399847bdb1caSJani Nikula drm_dbg_kms(&i915->drm, 399947bdb1caSJani Nikula "[CONNECTOR:%d:%s] Failed to reset sink scrambling/TMDS bit clock ratio\n", 4000379bc100SJani Nikula connector->base.id, connector->name); 4001379bc100SJani Nikula } 4002379bc100SJani Nikula 4003ede9771dSVille Syrjälä static void intel_disable_ddi(struct intel_atomic_state *state, 4004ede9771dSVille Syrjälä struct intel_encoder *encoder, 4005379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 4006379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 4007379bc100SJani Nikula { 4008379bc100SJani Nikula intel_hdcp_disable(to_intel_connector(old_conn_state->connector)); 4009379bc100SJani Nikula 4010379bc100SJani Nikula if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI)) 4011ede9771dSVille Syrjälä intel_disable_ddi_hdmi(state, encoder, old_crtc_state, 4012ede9771dSVille Syrjälä old_conn_state); 4013379bc100SJani Nikula else 4014ede9771dSVille Syrjälä intel_disable_ddi_dp(state, encoder, old_crtc_state, 4015ede9771dSVille Syrjälä old_conn_state); 4016379bc100SJani Nikula } 4017379bc100SJani Nikula 4018ede9771dSVille Syrjälä static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state, 4019ede9771dSVille Syrjälä struct intel_encoder *encoder, 4020379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 4021379bc100SJani Nikula const struct drm_connector_state *conn_state) 4022379bc100SJani Nikula { 4023b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4024379bc100SJani Nikula 40250c06fa15SGwan-gyeong Mun intel_ddi_set_dp_msa(crtc_state, conn_state); 4026379bc100SJani Nikula 40277a00e68bSGwan-gyeong Mun intel_psr_update(intel_dp, crtc_state, conn_state); 402876d45d06SGwan-gyeong Mun intel_dp_set_infoframes(encoder, true, crtc_state, conn_state); 40298040fefaSJosé Roberto de Souza intel_edp_drrs_update(intel_dp, crtc_state); 4030379bc100SJani Nikula 4031ede9771dSVille Syrjälä intel_panel_update_backlight(state, encoder, crtc_state, conn_state); 4032379bc100SJani Nikula } 4033379bc100SJani Nikula 4034ede9771dSVille Syrjälä static void intel_ddi_update_pipe(struct intel_atomic_state *state, 4035ede9771dSVille Syrjälä struct intel_encoder *encoder, 4036379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 4037379bc100SJani Nikula const struct drm_connector_state *conn_state) 4038379bc100SJani Nikula { 4039d456512cSRamalingam C 4040379bc100SJani Nikula if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) 4041ede9771dSVille Syrjälä intel_ddi_update_pipe_dp(state, encoder, crtc_state, 4042ede9771dSVille Syrjälä conn_state); 4043379bc100SJani Nikula 4044ede9771dSVille Syrjälä intel_hdcp_update_pipe(state, encoder, crtc_state, conn_state); 4045379bc100SJani Nikula } 4046379bc100SJani Nikula 4047379bc100SJani Nikula static void 404824a7bfe0SImre Deak intel_ddi_update_prepare(struct intel_atomic_state *state, 404924a7bfe0SImre Deak struct intel_encoder *encoder, 405024a7bfe0SImre Deak struct intel_crtc *crtc) 405124a7bfe0SImre Deak { 405224a7bfe0SImre Deak struct intel_crtc_state *crtc_state = 405324a7bfe0SImre Deak crtc ? intel_atomic_get_new_crtc_state(state, crtc) : NULL; 405424a7bfe0SImre Deak int required_lanes = crtc_state ? crtc_state->lane_count : 1; 405524a7bfe0SImre Deak 40568b4f2137SPankaj Bharadiya drm_WARN_ON(state->base.dev, crtc && crtc->active); 405724a7bfe0SImre Deak 4058b7d02c3aSVille Syrjälä intel_tc_port_get_link(enc_to_dig_port(encoder), 4059b7d02c3aSVille Syrjälä required_lanes); 40601326a92cSMaarten Lankhorst if (crtc_state && crtc_state->hw.active) 406124a7bfe0SImre Deak intel_update_active_dpll(state, crtc, encoder); 406224a7bfe0SImre Deak } 406324a7bfe0SImre Deak 406424a7bfe0SImre Deak static void 406524a7bfe0SImre Deak intel_ddi_update_complete(struct intel_atomic_state *state, 406624a7bfe0SImre Deak struct intel_encoder *encoder, 406724a7bfe0SImre Deak struct intel_crtc *crtc) 406824a7bfe0SImre Deak { 4069b7d02c3aSVille Syrjälä intel_tc_port_put_link(enc_to_dig_port(encoder)); 407024a7bfe0SImre Deak } 407124a7bfe0SImre Deak 407224a7bfe0SImre Deak static void 4073ede9771dSVille Syrjälä intel_ddi_pre_pll_enable(struct intel_atomic_state *state, 4074ede9771dSVille Syrjälä struct intel_encoder *encoder, 4075379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 4076379bc100SJani Nikula const struct drm_connector_state *conn_state) 4077379bc100SJani Nikula { 4078379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4079b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4080d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 4081d8fe2ab6SMatt Roper bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 4082379bc100SJani Nikula 408324a7bfe0SImre Deak if (is_tc_port) 408424a7bfe0SImre Deak intel_tc_port_get_link(dig_port, crtc_state->lane_count); 408524a7bfe0SImre Deak 408624a7bfe0SImre Deak if (intel_crtc_has_dp_encoder(crtc_state) || is_tc_port) 4087379bc100SJani Nikula intel_display_power_get(dev_priv, 4088379bc100SJani Nikula intel_ddi_main_link_aux_domain(dig_port)); 4089379bc100SJani Nikula 40909d44dcb9SLucas De Marchi if (is_tc_port && dig_port->tc_mode != TC_PORT_TBT_ALT) 40919d44dcb9SLucas De Marchi /* 40929d44dcb9SLucas De Marchi * Program the lane count for static/dynamic connections on 40939d44dcb9SLucas De Marchi * Type-C ports. Skip this step for TBT. 40949d44dcb9SLucas De Marchi */ 40959d44dcb9SLucas De Marchi intel_tc_port_set_fia_lane_count(dig_port, crtc_state->lane_count); 40969d44dcb9SLucas De Marchi else if (IS_GEN9_LP(dev_priv)) 4097379bc100SJani Nikula bxt_ddi_phy_set_lane_optim_mask(encoder, 4098379bc100SJani Nikula crtc_state->lane_lat_optim_mask); 4099379bc100SJani Nikula } 4100379bc100SJani Nikula 4101379bc100SJani Nikula static void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp) 4102379bc100SJani Nikula { 41037801f3b7SLucas De Marchi struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 41047801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 41057801f3b7SLucas De Marchi enum port port = dig_port->base.port; 410635ac28a8SLucas De Marchi u32 dp_tp_ctl, ddi_buf_ctl; 4107379bc100SJani Nikula bool wait = false; 4108379bc100SJani Nikula 4109f7960e7fSJani Nikula dp_tp_ctl = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 411035ac28a8SLucas De Marchi 411135ac28a8SLucas De Marchi if (dp_tp_ctl & DP_TP_CTL_ENABLE) { 4112f7960e7fSJani Nikula ddi_buf_ctl = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 411335ac28a8SLucas De Marchi if (ddi_buf_ctl & DDI_BUF_CTL_ENABLE) { 4114f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), 411535ac28a8SLucas De Marchi ddi_buf_ctl & ~DDI_BUF_CTL_ENABLE); 4116379bc100SJani Nikula wait = true; 4117379bc100SJani Nikula } 4118379bc100SJani Nikula 411935ac28a8SLucas De Marchi dp_tp_ctl &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 412035ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_LINK_TRAIN_PAT1; 4121f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, dp_tp_ctl); 4122f7960e7fSJani Nikula intel_de_posting_read(dev_priv, intel_dp->regs.dp_tp_ctl); 4123379bc100SJani Nikula 4124379bc100SJani Nikula if (wait) 4125379bc100SJani Nikula intel_wait_ddi_buf_idle(dev_priv, port); 4126379bc100SJani Nikula } 4127379bc100SJani Nikula 4128963501bdSImre Deak dp_tp_ctl = DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_PAT1; 4129379bc100SJani Nikula if (intel_dp->link_mst) 413035ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_MODE_MST; 4131379bc100SJani Nikula else { 413235ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_MODE_SST; 4133379bc100SJani Nikula if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) 413435ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_ENHANCED_FRAME_ENABLE; 4135379bc100SJani Nikula } 4136f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, dp_tp_ctl); 4137f7960e7fSJani Nikula intel_de_posting_read(dev_priv, intel_dp->regs.dp_tp_ctl); 4138379bc100SJani Nikula 4139379bc100SJani Nikula intel_dp->DP |= DDI_BUF_CTL_ENABLE; 4140f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP); 4141f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DDI_BUF_CTL(port)); 4142379bc100SJani Nikula 4143e828da30SManasi Navare intel_wait_ddi_buf_active(dev_priv, port); 4144379bc100SJani Nikula } 4145379bc100SJani Nikula 4146eee3f911SVille Syrjälä static void intel_ddi_set_link_train(struct intel_dp *intel_dp, 4147eee3f911SVille Syrjälä u8 dp_train_pat) 4148eee3f911SVille Syrjälä { 4149eee3f911SVille Syrjälä struct drm_i915_private *dev_priv = dp_to_i915(intel_dp); 4150eee3f911SVille Syrjälä u8 train_pat_mask = drm_dp_training_pattern_mask(intel_dp->dpcd); 4151eee3f911SVille Syrjälä u32 temp; 4152eee3f911SVille Syrjälä 4153eee3f911SVille Syrjälä temp = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 4154eee3f911SVille Syrjälä 4155eee3f911SVille Syrjälä temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; 4156eee3f911SVille Syrjälä switch (dp_train_pat & train_pat_mask) { 4157eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_DISABLE: 4158eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; 4159eee3f911SVille Syrjälä break; 4160eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_1: 4161eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT1; 4162eee3f911SVille Syrjälä break; 4163eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_2: 4164eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT2; 4165eee3f911SVille Syrjälä break; 4166eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_3: 4167eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT3; 4168eee3f911SVille Syrjälä break; 4169eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_4: 4170eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT4; 4171eee3f911SVille Syrjälä break; 4172eee3f911SVille Syrjälä } 4173eee3f911SVille Syrjälä 4174eee3f911SVille Syrjälä intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, temp); 4175eee3f911SVille Syrjälä } 4176eee3f911SVille Syrjälä 41778fdda385SVille Syrjälä static void intel_ddi_set_idle_link_train(struct intel_dp *intel_dp) 41788fdda385SVille Syrjälä { 41798fdda385SVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 41808fdda385SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 41818fdda385SVille Syrjälä enum port port = encoder->port; 41828fdda385SVille Syrjälä u32 val; 41838fdda385SVille Syrjälä 41848fdda385SVille Syrjälä val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 41858fdda385SVille Syrjälä val &= ~DP_TP_CTL_LINK_TRAIN_MASK; 41868fdda385SVille Syrjälä val |= DP_TP_CTL_LINK_TRAIN_IDLE; 41878fdda385SVille Syrjälä intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 41888fdda385SVille Syrjälä 41898fdda385SVille Syrjälä /* 41908fdda385SVille Syrjälä * Until TGL on PORT_A we can have only eDP in SST mode. There the only 41918fdda385SVille Syrjälä * reason we need to set idle transmission mode is to work around a HW 41928fdda385SVille Syrjälä * issue where we enable the pipe while not in idle link-training mode. 41938fdda385SVille Syrjälä * In this case there is requirement to wait for a minimum number of 41948fdda385SVille Syrjälä * idle patterns to be sent. 41958fdda385SVille Syrjälä */ 41968fdda385SVille Syrjälä if (port == PORT_A && INTEL_GEN(dev_priv) < 12) 41978fdda385SVille Syrjälä return; 41988fdda385SVille Syrjälä 41998fdda385SVille Syrjälä if (intel_de_wait_for_set(dev_priv, intel_dp->regs.dp_tp_status, 42008fdda385SVille Syrjälä DP_TP_STATUS_IDLE_DONE, 1)) 42018fdda385SVille Syrjälä drm_err(&dev_priv->drm, 42028fdda385SVille Syrjälä "Timed out waiting for DP idle patterns\n"); 42038fdda385SVille Syrjälä } 42048fdda385SVille Syrjälä 4205379bc100SJani Nikula static bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv, 4206379bc100SJani Nikula enum transcoder cpu_transcoder) 4207379bc100SJani Nikula { 4208379bc100SJani Nikula if (cpu_transcoder == TRANSCODER_EDP) 4209379bc100SJani Nikula return false; 4210379bc100SJani Nikula 4211379bc100SJani Nikula if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) 4212379bc100SJani Nikula return false; 4213379bc100SJani Nikula 4214f7960e7fSJani Nikula return intel_de_read(dev_priv, HSW_AUD_PIN_ELD_CP_VLD) & 4215379bc100SJani Nikula AUDIO_OUTPUT_ENABLE(cpu_transcoder); 4216379bc100SJani Nikula } 4217379bc100SJani Nikula 4218379bc100SJani Nikula void intel_ddi_compute_min_voltage_level(struct drm_i915_private *dev_priv, 4219379bc100SJani Nikula struct intel_crtc_state *crtc_state) 4220379bc100SJani Nikula { 42210fde0b1dSMatt Roper if (INTEL_GEN(dev_priv) >= 12 && crtc_state->port_clock > 594000) 42220fde0b1dSMatt Roper crtc_state->min_voltage_level = 2; 42230fde0b1dSMatt Roper else if (IS_ELKHARTLAKE(dev_priv) && crtc_state->port_clock > 594000) 42249d5fd37eSMatt Roper crtc_state->min_voltage_level = 3; 42259d5fd37eSMatt Roper else if (INTEL_GEN(dev_priv) >= 11 && crtc_state->port_clock > 594000) 4226379bc100SJani Nikula crtc_state->min_voltage_level = 1; 4227379bc100SJani Nikula else if (IS_CANNONLAKE(dev_priv) && crtc_state->port_clock > 594000) 4228379bc100SJani Nikula crtc_state->min_voltage_level = 2; 4229379bc100SJani Nikula } 4230379bc100SJani Nikula 4231dc5b8ed5SVille Syrjälä static enum transcoder bdw_transcoder_master_readout(struct drm_i915_private *dev_priv, 423202d8ea47SVille Syrjälä enum transcoder cpu_transcoder) 423302d8ea47SVille Syrjälä { 4234dc5b8ed5SVille Syrjälä u32 master_select; 423502d8ea47SVille Syrjälä 4236dc5b8ed5SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) { 4237dc5b8ed5SVille Syrjälä u32 ctl2 = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL2(cpu_transcoder)); 423802d8ea47SVille Syrjälä 423902d8ea47SVille Syrjälä if ((ctl2 & PORT_SYNC_MODE_ENABLE) == 0) 424002d8ea47SVille Syrjälä return INVALID_TRANSCODER; 424102d8ea47SVille Syrjälä 4242d4d7d9caSVille Syrjälä master_select = REG_FIELD_GET(PORT_SYNC_MODE_MASTER_SELECT_MASK, ctl2); 4243dc5b8ed5SVille Syrjälä } else { 4244dc5b8ed5SVille Syrjälä u32 ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 4245dc5b8ed5SVille Syrjälä 4246dc5b8ed5SVille Syrjälä if ((ctl & TRANS_DDI_PORT_SYNC_ENABLE) == 0) 4247dc5b8ed5SVille Syrjälä return INVALID_TRANSCODER; 4248dc5b8ed5SVille Syrjälä 4249dc5b8ed5SVille Syrjälä master_select = REG_FIELD_GET(TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK, ctl); 4250dc5b8ed5SVille Syrjälä } 425102d8ea47SVille Syrjälä 425202d8ea47SVille Syrjälä if (master_select == 0) 425302d8ea47SVille Syrjälä return TRANSCODER_EDP; 425402d8ea47SVille Syrjälä else 425502d8ea47SVille Syrjälä return master_select - 1; 425602d8ea47SVille Syrjälä } 425702d8ea47SVille Syrjälä 4258dc5b8ed5SVille Syrjälä static void bdw_get_trans_port_sync_config(struct intel_crtc_state *crtc_state) 425902d8ea47SVille Syrjälä { 426002d8ea47SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 426102d8ea47SVille Syrjälä u32 transcoders = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) | 426202d8ea47SVille Syrjälä BIT(TRANSCODER_C) | BIT(TRANSCODER_D); 426302d8ea47SVille Syrjälä enum transcoder cpu_transcoder; 426402d8ea47SVille Syrjälä 426502d8ea47SVille Syrjälä crtc_state->master_transcoder = 4266dc5b8ed5SVille Syrjälä bdw_transcoder_master_readout(dev_priv, crtc_state->cpu_transcoder); 426702d8ea47SVille Syrjälä 426802d8ea47SVille Syrjälä for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) { 426902d8ea47SVille Syrjälä enum intel_display_power_domain power_domain; 427002d8ea47SVille Syrjälä intel_wakeref_t trans_wakeref; 427102d8ea47SVille Syrjälä 427202d8ea47SVille Syrjälä power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 427302d8ea47SVille Syrjälä trans_wakeref = intel_display_power_get_if_enabled(dev_priv, 427402d8ea47SVille Syrjälä power_domain); 427502d8ea47SVille Syrjälä 427602d8ea47SVille Syrjälä if (!trans_wakeref) 427702d8ea47SVille Syrjälä continue; 427802d8ea47SVille Syrjälä 4279dc5b8ed5SVille Syrjälä if (bdw_transcoder_master_readout(dev_priv, cpu_transcoder) == 428002d8ea47SVille Syrjälä crtc_state->cpu_transcoder) 428102d8ea47SVille Syrjälä crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder); 428202d8ea47SVille Syrjälä 428302d8ea47SVille Syrjälä intel_display_power_put(dev_priv, power_domain, trans_wakeref); 428402d8ea47SVille Syrjälä } 428502d8ea47SVille Syrjälä 428602d8ea47SVille Syrjälä drm_WARN_ON(&dev_priv->drm, 428702d8ea47SVille Syrjälä crtc_state->master_transcoder != INVALID_TRANSCODER && 428802d8ea47SVille Syrjälä crtc_state->sync_mode_slaves_mask); 428902d8ea47SVille Syrjälä } 429002d8ea47SVille Syrjälä 4291379bc100SJani Nikula void intel_ddi_get_config(struct intel_encoder *encoder, 4292379bc100SJani Nikula struct intel_crtc_state *pipe_config) 4293379bc100SJani Nikula { 4294379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 42952225f3c6SMaarten Lankhorst struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 4296379bc100SJani Nikula enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; 4297edcb9028SJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4298379bc100SJani Nikula u32 temp, flags = 0; 4299379bc100SJani Nikula 4300379bc100SJani Nikula /* XXX: DSI transcoder paranoia */ 43011de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder))) 4302379bc100SJani Nikula return; 4303379bc100SJani Nikula 4304fbacb15eSJani Nikula intel_dsc_get_config(encoder, pipe_config); 4305fbacb15eSJani Nikula 4306f7960e7fSJani Nikula temp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 4307379bc100SJani Nikula if (temp & TRANS_DDI_PHSYNC) 4308379bc100SJani Nikula flags |= DRM_MODE_FLAG_PHSYNC; 4309379bc100SJani Nikula else 4310379bc100SJani Nikula flags |= DRM_MODE_FLAG_NHSYNC; 4311379bc100SJani Nikula if (temp & TRANS_DDI_PVSYNC) 4312379bc100SJani Nikula flags |= DRM_MODE_FLAG_PVSYNC; 4313379bc100SJani Nikula else 4314379bc100SJani Nikula flags |= DRM_MODE_FLAG_NVSYNC; 4315379bc100SJani Nikula 43161326a92cSMaarten Lankhorst pipe_config->hw.adjusted_mode.flags |= flags; 4317379bc100SJani Nikula 4318379bc100SJani Nikula switch (temp & TRANS_DDI_BPC_MASK) { 4319379bc100SJani Nikula case TRANS_DDI_BPC_6: 4320379bc100SJani Nikula pipe_config->pipe_bpp = 18; 4321379bc100SJani Nikula break; 4322379bc100SJani Nikula case TRANS_DDI_BPC_8: 4323379bc100SJani Nikula pipe_config->pipe_bpp = 24; 4324379bc100SJani Nikula break; 4325379bc100SJani Nikula case TRANS_DDI_BPC_10: 4326379bc100SJani Nikula pipe_config->pipe_bpp = 30; 4327379bc100SJani Nikula break; 4328379bc100SJani Nikula case TRANS_DDI_BPC_12: 4329379bc100SJani Nikula pipe_config->pipe_bpp = 36; 4330379bc100SJani Nikula break; 4331379bc100SJani Nikula default: 4332379bc100SJani Nikula break; 4333379bc100SJani Nikula } 4334379bc100SJani Nikula 4335379bc100SJani Nikula switch (temp & TRANS_DDI_MODE_SELECT_MASK) { 4336379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_HDMI: 4337379bc100SJani Nikula pipe_config->has_hdmi_sink = true; 4338379bc100SJani Nikula 4339379bc100SJani Nikula pipe_config->infoframes.enable |= 4340379bc100SJani Nikula intel_hdmi_infoframes_enabled(encoder, pipe_config); 4341379bc100SJani Nikula 4342379bc100SJani Nikula if (pipe_config->infoframes.enable) 4343379bc100SJani Nikula pipe_config->has_infoframe = true; 4344379bc100SJani Nikula 4345379bc100SJani Nikula if (temp & TRANS_DDI_HDMI_SCRAMBLING) 4346379bc100SJani Nikula pipe_config->hdmi_scrambling = true; 4347379bc100SJani Nikula if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE) 4348379bc100SJani Nikula pipe_config->hdmi_high_tmds_clock_ratio = true; 4349379bc100SJani Nikula /* fall through */ 4350379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DVI: 4351379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI); 4352379bc100SJani Nikula pipe_config->lane_count = 4; 4353379bc100SJani Nikula break; 4354379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_FDI: 4355379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG); 4356379bc100SJani Nikula break; 4357379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_SST: 4358379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 4359379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP); 4360379bc100SJani Nikula else 4361379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_DP); 4362379bc100SJani Nikula pipe_config->lane_count = 4363379bc100SJani Nikula ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; 4364379bc100SJani Nikula intel_dp_get_m_n(intel_crtc, pipe_config); 43658aa940c8SMaarten Lankhorst 43668aa940c8SMaarten Lankhorst if (INTEL_GEN(dev_priv) >= 11) { 43678aa940c8SMaarten Lankhorst i915_reg_t dp_tp_ctl; 43688aa940c8SMaarten Lankhorst 43698aa940c8SMaarten Lankhorst if (IS_GEN(dev_priv, 11)) 43708aa940c8SMaarten Lankhorst dp_tp_ctl = DP_TP_CTL(encoder->port); 43718aa940c8SMaarten Lankhorst else 43728aa940c8SMaarten Lankhorst dp_tp_ctl = TGL_DP_TP_CTL(pipe_config->cpu_transcoder); 43738aa940c8SMaarten Lankhorst 43748aa940c8SMaarten Lankhorst pipe_config->fec_enable = 4375f7960e7fSJani Nikula intel_de_read(dev_priv, dp_tp_ctl) & DP_TP_CTL_FEC_ENABLE; 43768aa940c8SMaarten Lankhorst 437747bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 437847bdb1caSJani Nikula "[ENCODER:%d:%s] Fec status: %u\n", 43798aa940c8SMaarten Lankhorst encoder->base.base.id, encoder->base.name, 43808aa940c8SMaarten Lankhorst pipe_config->fec_enable); 43818aa940c8SMaarten Lankhorst } 43828aa940c8SMaarten Lankhorst 4383dee66f3eSGwan-gyeong Mun pipe_config->infoframes.enable |= 4384dee66f3eSGwan-gyeong Mun intel_hdmi_infoframes_enabled(encoder, pipe_config); 4385dee66f3eSGwan-gyeong Mun 4386379bc100SJani Nikula break; 4387379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_MST: 4388379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST); 4389379bc100SJani Nikula pipe_config->lane_count = 4390379bc100SJani Nikula ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; 43916671c367SJosé Roberto de Souza 43926671c367SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 43936671c367SJosé Roberto de Souza pipe_config->mst_master_transcoder = 43946671c367SJosé Roberto de Souza REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK, temp); 43956671c367SJosé Roberto de Souza 4396379bc100SJani Nikula intel_dp_get_m_n(intel_crtc, pipe_config); 4397dee66f3eSGwan-gyeong Mun 4398dee66f3eSGwan-gyeong Mun pipe_config->infoframes.enable |= 4399dee66f3eSGwan-gyeong Mun intel_hdmi_infoframes_enabled(encoder, pipe_config); 4400379bc100SJani Nikula break; 4401379bc100SJani Nikula default: 4402379bc100SJani Nikula break; 4403379bc100SJani Nikula } 4404379bc100SJani Nikula 4405f153478dSImre Deak if (INTEL_GEN(dev_priv) >= 12) { 4406f153478dSImre Deak enum transcoder transcoder = 4407f153478dSImre Deak intel_dp_mst_is_slave_trans(pipe_config) ? 4408f153478dSImre Deak pipe_config->mst_master_transcoder : 4409f153478dSImre Deak pipe_config->cpu_transcoder; 4410f153478dSImre Deak 4411f153478dSImre Deak intel_dp->regs.dp_tp_ctl = TGL_DP_TP_CTL(transcoder); 4412f153478dSImre Deak intel_dp->regs.dp_tp_status = TGL_DP_TP_STATUS(transcoder); 4413f153478dSImre Deak } 4414f153478dSImre Deak 4415379bc100SJani Nikula pipe_config->has_audio = 4416379bc100SJani Nikula intel_ddi_is_audio_enabled(dev_priv, cpu_transcoder); 4417379bc100SJani Nikula 4418379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp && 4419379bc100SJani Nikula pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { 4420379bc100SJani Nikula /* 4421379bc100SJani Nikula * This is a big fat ugly hack. 4422379bc100SJani Nikula * 4423379bc100SJani Nikula * Some machines in UEFI boot mode provide us a VBT that has 18 4424379bc100SJani Nikula * bpp and 1.62 GHz link bandwidth for eDP, which for reasons 4425379bc100SJani Nikula * unknown we fail to light up. Yet the same BIOS boots up with 4426379bc100SJani Nikula * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as 4427379bc100SJani Nikula * max, not what it tells us to use. 4428379bc100SJani Nikula * 4429379bc100SJani Nikula * Note: This will still be broken if the eDP panel is not lit 4430379bc100SJani Nikula * up by the BIOS, and thus we can't get the mode at module 4431379bc100SJani Nikula * load. 4432379bc100SJani Nikula */ 443347bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 443447bdb1caSJani Nikula "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", 4435379bc100SJani Nikula pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); 4436379bc100SJani Nikula dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; 4437379bc100SJani Nikula } 4438379bc100SJani Nikula 4439379bc100SJani Nikula intel_ddi_clock_get(encoder, pipe_config); 4440379bc100SJani Nikula 4441379bc100SJani Nikula if (IS_GEN9_LP(dev_priv)) 4442379bc100SJani Nikula pipe_config->lane_lat_optim_mask = 4443379bc100SJani Nikula bxt_ddi_phy_get_lane_lat_optim_mask(encoder); 4444379bc100SJani Nikula 4445379bc100SJani Nikula intel_ddi_compute_min_voltage_level(dev_priv, pipe_config); 4446379bc100SJani Nikula 4447379bc100SJani Nikula intel_hdmi_read_gcp_infoframe(encoder, pipe_config); 4448379bc100SJani Nikula 4449379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4450379bc100SJani Nikula HDMI_INFOFRAME_TYPE_AVI, 4451379bc100SJani Nikula &pipe_config->infoframes.avi); 4452379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4453379bc100SJani Nikula HDMI_INFOFRAME_TYPE_SPD, 4454379bc100SJani Nikula &pipe_config->infoframes.spd); 4455379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4456379bc100SJani Nikula HDMI_INFOFRAME_TYPE_VENDOR, 4457379bc100SJani Nikula &pipe_config->infoframes.hdmi); 4458379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4459379bc100SJani Nikula HDMI_INFOFRAME_TYPE_DRM, 4460379bc100SJani Nikula &pipe_config->infoframes.drm); 446102d8ea47SVille Syrjälä 4462dc5b8ed5SVille Syrjälä if (INTEL_GEN(dev_priv) >= 8) 4463dc5b8ed5SVille Syrjälä bdw_get_trans_port_sync_config(pipe_config); 4464dee66f3eSGwan-gyeong Mun 4465dee66f3eSGwan-gyeong Mun intel_read_dp_sdp(encoder, pipe_config, HDMI_PACKET_TYPE_GAMUT_METADATA); 44662c3928e4SGwan-gyeong Mun intel_read_dp_sdp(encoder, pipe_config, DP_SDP_VSC); 4467379bc100SJani Nikula } 4468379bc100SJani Nikula 4469379bc100SJani Nikula static enum intel_output_type 4470379bc100SJani Nikula intel_ddi_compute_output_type(struct intel_encoder *encoder, 4471379bc100SJani Nikula struct intel_crtc_state *crtc_state, 4472379bc100SJani Nikula struct drm_connector_state *conn_state) 4473379bc100SJani Nikula { 4474379bc100SJani Nikula switch (conn_state->connector->connector_type) { 4475379bc100SJani Nikula case DRM_MODE_CONNECTOR_HDMIA: 4476379bc100SJani Nikula return INTEL_OUTPUT_HDMI; 4477379bc100SJani Nikula case DRM_MODE_CONNECTOR_eDP: 4478379bc100SJani Nikula return INTEL_OUTPUT_EDP; 4479379bc100SJani Nikula case DRM_MODE_CONNECTOR_DisplayPort: 4480379bc100SJani Nikula return INTEL_OUTPUT_DP; 4481379bc100SJani Nikula default: 4482379bc100SJani Nikula MISSING_CASE(conn_state->connector->connector_type); 4483379bc100SJani Nikula return INTEL_OUTPUT_UNUSED; 4484379bc100SJani Nikula } 4485379bc100SJani Nikula } 4486379bc100SJani Nikula 4487379bc100SJani Nikula static int intel_ddi_compute_config(struct intel_encoder *encoder, 4488379bc100SJani Nikula struct intel_crtc_state *pipe_config, 4489379bc100SJani Nikula struct drm_connector_state *conn_state) 4490379bc100SJani Nikula { 44912225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 4492379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4493379bc100SJani Nikula enum port port = encoder->port; 4494379bc100SJani Nikula int ret; 4495379bc100SJani Nikula 449610cf8e75SVille Syrjälä if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) 4497379bc100SJani Nikula pipe_config->cpu_transcoder = TRANSCODER_EDP; 4498379bc100SJani Nikula 4499bdacf087SAnshuman Gupta if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) { 4500379bc100SJani Nikula ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state); 4501bdacf087SAnshuman Gupta } else { 4502379bc100SJani Nikula ret = intel_dp_compute_config(encoder, pipe_config, conn_state); 4503bdacf087SAnshuman Gupta } 4504bdacf087SAnshuman Gupta 4505379bc100SJani Nikula if (ret) 4506379bc100SJani Nikula return ret; 4507379bc100SJani Nikula 4508379bc100SJani Nikula if (IS_HASWELL(dev_priv) && crtc->pipe == PIPE_A && 4509379bc100SJani Nikula pipe_config->cpu_transcoder == TRANSCODER_EDP) 4510379bc100SJani Nikula pipe_config->pch_pfit.force_thru = 4511379bc100SJani Nikula pipe_config->pch_pfit.enabled || 4512379bc100SJani Nikula pipe_config->crc_enabled; 4513379bc100SJani Nikula 4514379bc100SJani Nikula if (IS_GEN9_LP(dev_priv)) 4515379bc100SJani Nikula pipe_config->lane_lat_optim_mask = 4516379bc100SJani Nikula bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count); 4517379bc100SJani Nikula 4518379bc100SJani Nikula intel_ddi_compute_min_voltage_level(dev_priv, pipe_config); 4519379bc100SJani Nikula 4520379bc100SJani Nikula return 0; 4521379bc100SJani Nikula } 4522379bc100SJani Nikula 4523b50a1aa6SManasi Navare static bool mode_equal(const struct drm_display_mode *mode1, 4524b50a1aa6SManasi Navare const struct drm_display_mode *mode2) 4525b50a1aa6SManasi Navare { 4526b50a1aa6SManasi Navare return drm_mode_match(mode1, mode2, 4527b50a1aa6SManasi Navare DRM_MODE_MATCH_TIMINGS | 4528b50a1aa6SManasi Navare DRM_MODE_MATCH_FLAGS | 4529b50a1aa6SManasi Navare DRM_MODE_MATCH_3D_FLAGS) && 4530b50a1aa6SManasi Navare mode1->clock == mode2->clock; /* we want an exact match */ 4531b50a1aa6SManasi Navare } 4532b50a1aa6SManasi Navare 4533b50a1aa6SManasi Navare static bool m_n_equal(const struct intel_link_m_n *m_n_1, 4534b50a1aa6SManasi Navare const struct intel_link_m_n *m_n_2) 4535b50a1aa6SManasi Navare { 4536b50a1aa6SManasi Navare return m_n_1->tu == m_n_2->tu && 4537b50a1aa6SManasi Navare m_n_1->gmch_m == m_n_2->gmch_m && 4538b50a1aa6SManasi Navare m_n_1->gmch_n == m_n_2->gmch_n && 4539b50a1aa6SManasi Navare m_n_1->link_m == m_n_2->link_m && 4540b50a1aa6SManasi Navare m_n_1->link_n == m_n_2->link_n; 4541b50a1aa6SManasi Navare } 4542b50a1aa6SManasi Navare 4543b50a1aa6SManasi Navare static bool crtcs_port_sync_compatible(const struct intel_crtc_state *crtc_state1, 4544b50a1aa6SManasi Navare const struct intel_crtc_state *crtc_state2) 4545b50a1aa6SManasi Navare { 4546b50a1aa6SManasi Navare return crtc_state1->hw.active && crtc_state2->hw.active && 4547b50a1aa6SManasi Navare crtc_state1->output_types == crtc_state2->output_types && 4548b50a1aa6SManasi Navare crtc_state1->output_format == crtc_state2->output_format && 4549b50a1aa6SManasi Navare crtc_state1->lane_count == crtc_state2->lane_count && 4550b50a1aa6SManasi Navare crtc_state1->port_clock == crtc_state2->port_clock && 4551b50a1aa6SManasi Navare mode_equal(&crtc_state1->hw.adjusted_mode, 4552b50a1aa6SManasi Navare &crtc_state2->hw.adjusted_mode) && 4553b50a1aa6SManasi Navare m_n_equal(&crtc_state1->dp_m_n, &crtc_state2->dp_m_n); 4554b50a1aa6SManasi Navare } 4555b50a1aa6SManasi Navare 4556b50a1aa6SManasi Navare static u8 4557b50a1aa6SManasi Navare intel_ddi_port_sync_transcoders(const struct intel_crtc_state *ref_crtc_state, 4558b50a1aa6SManasi Navare int tile_group_id) 4559b50a1aa6SManasi Navare { 4560b50a1aa6SManasi Navare struct drm_connector *connector; 4561b50a1aa6SManasi Navare const struct drm_connector_state *conn_state; 4562b50a1aa6SManasi Navare struct drm_i915_private *dev_priv = to_i915(ref_crtc_state->uapi.crtc->dev); 4563b50a1aa6SManasi Navare struct intel_atomic_state *state = 4564b50a1aa6SManasi Navare to_intel_atomic_state(ref_crtc_state->uapi.state); 4565b50a1aa6SManasi Navare u8 transcoders = 0; 4566b50a1aa6SManasi Navare int i; 4567b50a1aa6SManasi Navare 4568dc5b8ed5SVille Syrjälä /* 4569dc5b8ed5SVille Syrjälä * We don't enable port sync on BDW due to missing w/as and 4570dc5b8ed5SVille Syrjälä * due to not having adjusted the modeset sequence appropriately. 4571dc5b8ed5SVille Syrjälä */ 4572dc5b8ed5SVille Syrjälä if (INTEL_GEN(dev_priv) < 9) 4573b50a1aa6SManasi Navare return 0; 4574b50a1aa6SManasi Navare 4575b50a1aa6SManasi Navare if (!intel_crtc_has_type(ref_crtc_state, INTEL_OUTPUT_DP)) 4576b50a1aa6SManasi Navare return 0; 4577b50a1aa6SManasi Navare 4578b50a1aa6SManasi Navare for_each_new_connector_in_state(&state->base, connector, conn_state, i) { 4579b50a1aa6SManasi Navare struct intel_crtc *crtc = to_intel_crtc(conn_state->crtc); 4580b50a1aa6SManasi Navare const struct intel_crtc_state *crtc_state; 4581b50a1aa6SManasi Navare 4582b50a1aa6SManasi Navare if (!crtc) 4583b50a1aa6SManasi Navare continue; 4584b50a1aa6SManasi Navare 4585b50a1aa6SManasi Navare if (!connector->has_tile || 4586b50a1aa6SManasi Navare connector->tile_group->id != 4587b50a1aa6SManasi Navare tile_group_id) 4588b50a1aa6SManasi Navare continue; 4589b50a1aa6SManasi Navare crtc_state = intel_atomic_get_new_crtc_state(state, 4590b50a1aa6SManasi Navare crtc); 4591b50a1aa6SManasi Navare if (!crtcs_port_sync_compatible(ref_crtc_state, 4592b50a1aa6SManasi Navare crtc_state)) 4593b50a1aa6SManasi Navare continue; 4594b50a1aa6SManasi Navare transcoders |= BIT(crtc_state->cpu_transcoder); 4595b50a1aa6SManasi Navare } 4596b50a1aa6SManasi Navare 4597b50a1aa6SManasi Navare return transcoders; 4598b50a1aa6SManasi Navare } 4599b50a1aa6SManasi Navare 4600b50a1aa6SManasi Navare static int intel_ddi_compute_config_late(struct intel_encoder *encoder, 4601b50a1aa6SManasi Navare struct intel_crtc_state *crtc_state, 4602b50a1aa6SManasi Navare struct drm_connector_state *conn_state) 4603b50a1aa6SManasi Navare { 460447bdb1caSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev); 4605b50a1aa6SManasi Navare struct drm_connector *connector = conn_state->connector; 4606b50a1aa6SManasi Navare u8 port_sync_transcoders = 0; 4607b50a1aa6SManasi Navare 460847bdb1caSJani Nikula drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] [CRTC:%d:%s]", 4609b50a1aa6SManasi Navare encoder->base.base.id, encoder->base.name, 4610b50a1aa6SManasi Navare crtc_state->uapi.crtc->base.id, crtc_state->uapi.crtc->name); 4611b50a1aa6SManasi Navare 4612b50a1aa6SManasi Navare if (connector->has_tile) 4613b50a1aa6SManasi Navare port_sync_transcoders = intel_ddi_port_sync_transcoders(crtc_state, 4614b50a1aa6SManasi Navare connector->tile_group->id); 4615b50a1aa6SManasi Navare 4616b50a1aa6SManasi Navare /* 4617b50a1aa6SManasi Navare * EDP Transcoders cannot be ensalved 4618b50a1aa6SManasi Navare * make them a master always when present 4619b50a1aa6SManasi Navare */ 4620b50a1aa6SManasi Navare if (port_sync_transcoders & BIT(TRANSCODER_EDP)) 4621b50a1aa6SManasi Navare crtc_state->master_transcoder = TRANSCODER_EDP; 4622b50a1aa6SManasi Navare else 4623b50a1aa6SManasi Navare crtc_state->master_transcoder = ffs(port_sync_transcoders) - 1; 4624b50a1aa6SManasi Navare 4625b50a1aa6SManasi Navare if (crtc_state->master_transcoder == crtc_state->cpu_transcoder) { 4626b50a1aa6SManasi Navare crtc_state->master_transcoder = INVALID_TRANSCODER; 4627b50a1aa6SManasi Navare crtc_state->sync_mode_slaves_mask = 4628b50a1aa6SManasi Navare port_sync_transcoders & ~BIT(crtc_state->cpu_transcoder); 4629b50a1aa6SManasi Navare } 4630b50a1aa6SManasi Navare 4631b50a1aa6SManasi Navare return 0; 4632b50a1aa6SManasi Navare } 4633b50a1aa6SManasi Navare 4634379bc100SJani Nikula static void intel_ddi_encoder_destroy(struct drm_encoder *encoder) 4635379bc100SJani Nikula { 4636b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder)); 4637379bc100SJani Nikula 4638379bc100SJani Nikula intel_dp_encoder_flush_work(encoder); 4639379bc100SJani Nikula 4640379bc100SJani Nikula drm_encoder_cleanup(encoder); 4641379bc100SJani Nikula kfree(dig_port); 4642379bc100SJani Nikula } 4643379bc100SJani Nikula 4644379bc100SJani Nikula static const struct drm_encoder_funcs intel_ddi_funcs = { 464532691b58SImre Deak .reset = intel_dp_encoder_reset, 4646379bc100SJani Nikula .destroy = intel_ddi_encoder_destroy, 4647379bc100SJani Nikula }; 4648379bc100SJani Nikula 4649379bc100SJani Nikula static struct intel_connector * 46507801f3b7SLucas De Marchi intel_ddi_init_dp_connector(struct intel_digital_port *dig_port) 4651379bc100SJani Nikula { 46527801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 4653379bc100SJani Nikula struct intel_connector *connector; 46547801f3b7SLucas De Marchi enum port port = dig_port->base.port; 4655379bc100SJani Nikula 4656379bc100SJani Nikula connector = intel_connector_alloc(); 4657379bc100SJani Nikula if (!connector) 4658379bc100SJani Nikula return NULL; 4659379bc100SJani Nikula 46607801f3b7SLucas De Marchi dig_port->dp.output_reg = DDI_BUF_CTL(port); 46617801f3b7SLucas De Marchi dig_port->dp.prepare_link_retrain = intel_ddi_prepare_link_retrain; 46627801f3b7SLucas De Marchi dig_port->dp.set_link_train = intel_ddi_set_link_train; 46637801f3b7SLucas De Marchi dig_port->dp.set_idle_link_train = intel_ddi_set_idle_link_train; 4664eee3f911SVille Syrjälä 4665fb83f72cSVille Syrjälä if (INTEL_GEN(dev_priv) >= 12) 46667801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = tgl_set_signal_levels; 4667fb83f72cSVille Syrjälä else if (INTEL_GEN(dev_priv) >= 11) 46687801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = icl_set_signal_levels; 4669fb83f72cSVille Syrjälä else if (IS_CANNONLAKE(dev_priv)) 46707801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = cnl_set_signal_levels; 4671fb83f72cSVille Syrjälä else if (IS_GEN9_LP(dev_priv)) 46727801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = bxt_set_signal_levels; 4673fb83f72cSVille Syrjälä else 46747801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = hsw_set_signal_levels; 4675fb83f72cSVille Syrjälä 46767801f3b7SLucas De Marchi dig_port->dp.voltage_max = intel_ddi_dp_voltage_max; 46777801f3b7SLucas De Marchi dig_port->dp.preemph_max = intel_ddi_dp_preemph_max; 467853de0a20SVille Syrjälä 4679edcb9028SJosé Roberto de Souza if (INTEL_GEN(dev_priv) < 12) { 46807801f3b7SLucas De Marchi dig_port->dp.regs.dp_tp_ctl = DP_TP_CTL(port); 46817801f3b7SLucas De Marchi dig_port->dp.regs.dp_tp_status = DP_TP_STATUS(port); 4682edcb9028SJosé Roberto de Souza } 4683379bc100SJani Nikula 46847801f3b7SLucas De Marchi if (!intel_dp_init_connector(dig_port, connector)) { 4685379bc100SJani Nikula kfree(connector); 4686379bc100SJani Nikula return NULL; 4687379bc100SJani Nikula } 4688379bc100SJani Nikula 4689379bc100SJani Nikula return connector; 4690379bc100SJani Nikula } 4691379bc100SJani Nikula 4692379bc100SJani Nikula static int modeset_pipe(struct drm_crtc *crtc, 4693379bc100SJani Nikula struct drm_modeset_acquire_ctx *ctx) 4694379bc100SJani Nikula { 4695379bc100SJani Nikula struct drm_atomic_state *state; 4696379bc100SJani Nikula struct drm_crtc_state *crtc_state; 4697379bc100SJani Nikula int ret; 4698379bc100SJani Nikula 4699379bc100SJani Nikula state = drm_atomic_state_alloc(crtc->dev); 4700379bc100SJani Nikula if (!state) 4701379bc100SJani Nikula return -ENOMEM; 4702379bc100SJani Nikula 4703379bc100SJani Nikula state->acquire_ctx = ctx; 4704379bc100SJani Nikula 4705379bc100SJani Nikula crtc_state = drm_atomic_get_crtc_state(state, crtc); 4706379bc100SJani Nikula if (IS_ERR(crtc_state)) { 4707379bc100SJani Nikula ret = PTR_ERR(crtc_state); 4708379bc100SJani Nikula goto out; 4709379bc100SJani Nikula } 4710379bc100SJani Nikula 4711379bc100SJani Nikula crtc_state->connectors_changed = true; 4712379bc100SJani Nikula 4713379bc100SJani Nikula ret = drm_atomic_commit(state); 4714379bc100SJani Nikula out: 4715379bc100SJani Nikula drm_atomic_state_put(state); 4716379bc100SJani Nikula 4717379bc100SJani Nikula return ret; 4718379bc100SJani Nikula } 4719379bc100SJani Nikula 4720379bc100SJani Nikula static int intel_hdmi_reset_link(struct intel_encoder *encoder, 4721379bc100SJani Nikula struct drm_modeset_acquire_ctx *ctx) 4722379bc100SJani Nikula { 4723379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4724b7d02c3aSVille Syrjälä struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder); 4725379bc100SJani Nikula struct intel_connector *connector = hdmi->attached_connector; 4726379bc100SJani Nikula struct i2c_adapter *adapter = 4727379bc100SJani Nikula intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus); 4728379bc100SJani Nikula struct drm_connector_state *conn_state; 4729379bc100SJani Nikula struct intel_crtc_state *crtc_state; 4730379bc100SJani Nikula struct intel_crtc *crtc; 4731379bc100SJani Nikula u8 config; 4732379bc100SJani Nikula int ret; 4733379bc100SJani Nikula 4734379bc100SJani Nikula if (!connector || connector->base.status != connector_status_connected) 4735379bc100SJani Nikula return 0; 4736379bc100SJani Nikula 4737379bc100SJani Nikula ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, 4738379bc100SJani Nikula ctx); 4739379bc100SJani Nikula if (ret) 4740379bc100SJani Nikula return ret; 4741379bc100SJani Nikula 4742379bc100SJani Nikula conn_state = connector->base.state; 4743379bc100SJani Nikula 4744379bc100SJani Nikula crtc = to_intel_crtc(conn_state->crtc); 4745379bc100SJani Nikula if (!crtc) 4746379bc100SJani Nikula return 0; 4747379bc100SJani Nikula 4748379bc100SJani Nikula ret = drm_modeset_lock(&crtc->base.mutex, ctx); 4749379bc100SJani Nikula if (ret) 4750379bc100SJani Nikula return ret; 4751379bc100SJani Nikula 4752379bc100SJani Nikula crtc_state = to_intel_crtc_state(crtc->base.state); 4753379bc100SJani Nikula 47541de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 47551de143ccSPankaj Bharadiya !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)); 4756379bc100SJani Nikula 47571326a92cSMaarten Lankhorst if (!crtc_state->hw.active) 4758379bc100SJani Nikula return 0; 4759379bc100SJani Nikula 4760379bc100SJani Nikula if (!crtc_state->hdmi_high_tmds_clock_ratio && 4761379bc100SJani Nikula !crtc_state->hdmi_scrambling) 4762379bc100SJani Nikula return 0; 4763379bc100SJani Nikula 4764379bc100SJani Nikula if (conn_state->commit && 4765379bc100SJani Nikula !try_wait_for_completion(&conn_state->commit->hw_done)) 4766379bc100SJani Nikula return 0; 4767379bc100SJani Nikula 4768379bc100SJani Nikula ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config); 4769379bc100SJani Nikula if (ret < 0) { 477047bdb1caSJani Nikula drm_err(&dev_priv->drm, "Failed to read TMDS config: %d\n", 477147bdb1caSJani Nikula ret); 4772379bc100SJani Nikula return 0; 4773379bc100SJani Nikula } 4774379bc100SJani Nikula 4775379bc100SJani Nikula if (!!(config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) == 4776379bc100SJani Nikula crtc_state->hdmi_high_tmds_clock_ratio && 4777379bc100SJani Nikula !!(config & SCDC_SCRAMBLING_ENABLE) == 4778379bc100SJani Nikula crtc_state->hdmi_scrambling) 4779379bc100SJani Nikula return 0; 4780379bc100SJani Nikula 4781379bc100SJani Nikula /* 4782379bc100SJani Nikula * HDMI 2.0 says that one should not send scrambled data 4783379bc100SJani Nikula * prior to configuring the sink scrambling, and that 4784379bc100SJani Nikula * TMDS clock/data transmission should be suspended when 4785379bc100SJani Nikula * changing the TMDS clock rate in the sink. So let's 4786379bc100SJani Nikula * just do a full modeset here, even though some sinks 4787379bc100SJani Nikula * would be perfectly happy if were to just reconfigure 4788379bc100SJani Nikula * the SCDC settings on the fly. 4789379bc100SJani Nikula */ 4790379bc100SJani Nikula return modeset_pipe(&crtc->base, ctx); 4791379bc100SJani Nikula } 4792379bc100SJani Nikula 47933944709dSImre Deak static enum intel_hotplug_state 47943944709dSImre Deak intel_ddi_hotplug(struct intel_encoder *encoder, 47958c8919c7SImre Deak struct intel_connector *connector) 4796379bc100SJani Nikula { 4797b4df5405SImre Deak struct drm_i915_private *i915 = to_i915(encoder->base.dev); 4798b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4799b4df5405SImre Deak enum phy phy = intel_port_to_phy(i915, encoder->port); 4800b4df5405SImre Deak bool is_tc = intel_phy_is_tc(i915, phy); 4801379bc100SJani Nikula struct drm_modeset_acquire_ctx ctx; 48023944709dSImre Deak enum intel_hotplug_state state; 4803379bc100SJani Nikula int ret; 4804379bc100SJani Nikula 48058c8919c7SImre Deak state = intel_encoder_hotplug(encoder, connector); 4806379bc100SJani Nikula 4807379bc100SJani Nikula drm_modeset_acquire_init(&ctx, 0); 4808379bc100SJani Nikula 4809379bc100SJani Nikula for (;;) { 4810379bc100SJani Nikula if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) 4811379bc100SJani Nikula ret = intel_hdmi_reset_link(encoder, &ctx); 4812379bc100SJani Nikula else 4813379bc100SJani Nikula ret = intel_dp_retrain_link(encoder, &ctx); 4814379bc100SJani Nikula 4815379bc100SJani Nikula if (ret == -EDEADLK) { 4816379bc100SJani Nikula drm_modeset_backoff(&ctx); 4817379bc100SJani Nikula continue; 4818379bc100SJani Nikula } 4819379bc100SJani Nikula 4820379bc100SJani Nikula break; 4821379bc100SJani Nikula } 4822379bc100SJani Nikula 4823379bc100SJani Nikula drm_modeset_drop_locks(&ctx); 4824379bc100SJani Nikula drm_modeset_acquire_fini(&ctx); 48253a47ae20SPankaj Bharadiya drm_WARN(encoder->base.dev, ret, 48263a47ae20SPankaj Bharadiya "Acquiring modeset locks failed with %i\n", ret); 4827379bc100SJani Nikula 4828bb80c925SJosé Roberto de Souza /* 4829bb80c925SJosé Roberto de Souza * Unpowered type-c dongles can take some time to boot and be 4830bb80c925SJosé Roberto de Souza * responsible, so here giving some time to those dongles to power up 4831bb80c925SJosé Roberto de Souza * and then retrying the probe. 4832bb80c925SJosé Roberto de Souza * 4833bb80c925SJosé Roberto de Souza * On many platforms the HDMI live state signal is known to be 4834bb80c925SJosé Roberto de Souza * unreliable, so we can't use it to detect if a sink is connected or 4835bb80c925SJosé Roberto de Souza * not. Instead we detect if it's connected based on whether we can 4836bb80c925SJosé Roberto de Souza * read the EDID or not. That in turn has a problem during disconnect, 4837bb80c925SJosé Roberto de Souza * since the HPD interrupt may be raised before the DDC lines get 4838bb80c925SJosé Roberto de Souza * disconnected (due to how the required length of DDC vs. HPD 4839bb80c925SJosé Roberto de Souza * connector pins are specified) and so we'll still be able to get a 4840bb80c925SJosé Roberto de Souza * valid EDID. To solve this schedule another detection cycle if this 4841bb80c925SJosé Roberto de Souza * time around we didn't detect any change in the sink's connection 4842bb80c925SJosé Roberto de Souza * status. 4843b4df5405SImre Deak * 4844b4df5405SImre Deak * Type-c connectors which get their HPD signal deasserted then 4845b4df5405SImre Deak * reasserted, without unplugging/replugging the sink from the 4846b4df5405SImre Deak * connector, introduce a delay until the AUX channel communication 4847b4df5405SImre Deak * becomes functional. Retry the detection for 5 seconds on type-c 4848b4df5405SImre Deak * connectors to account for this delay. 4849bb80c925SJosé Roberto de Souza */ 4850b4df5405SImre Deak if (state == INTEL_HOTPLUG_UNCHANGED && 4851b4df5405SImre Deak connector->hotplug_retries < (is_tc ? 5 : 1) && 4852bb80c925SJosé Roberto de Souza !dig_port->dp.is_mst) 4853bb80c925SJosé Roberto de Souza state = INTEL_HOTPLUG_RETRY; 4854bb80c925SJosé Roberto de Souza 48553944709dSImre Deak return state; 4856379bc100SJani Nikula } 4857379bc100SJani Nikula 4858edc0e09cSVille Syrjälä static bool lpt_digital_port_connected(struct intel_encoder *encoder) 4859edc0e09cSVille Syrjälä { 4860edc0e09cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4861c7e8a3d6SVille Syrjälä u32 bit = dev_priv->hotplug.pch_hpd[encoder->hpd_pin]; 4862edc0e09cSVille Syrjälä 4863edc0e09cSVille Syrjälä return intel_de_read(dev_priv, SDEISR) & bit; 4864edc0e09cSVille Syrjälä } 4865edc0e09cSVille Syrjälä 4866edc0e09cSVille Syrjälä static bool hsw_digital_port_connected(struct intel_encoder *encoder) 4867edc0e09cSVille Syrjälä { 4868edc0e09cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4869c7e8a3d6SVille Syrjälä u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin]; 4870edc0e09cSVille Syrjälä 4871c7e8a3d6SVille Syrjälä return intel_de_read(dev_priv, DEISR) & bit; 4872edc0e09cSVille Syrjälä } 4873edc0e09cSVille Syrjälä 4874edc0e09cSVille Syrjälä static bool bdw_digital_port_connected(struct intel_encoder *encoder) 4875edc0e09cSVille Syrjälä { 4876edc0e09cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4877c7e8a3d6SVille Syrjälä u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin]; 4878edc0e09cSVille Syrjälä 4879edc0e09cSVille Syrjälä return intel_de_read(dev_priv, GEN8_DE_PORT_ISR) & bit; 4880edc0e09cSVille Syrjälä } 4881edc0e09cSVille Syrjälä 4882379bc100SJani Nikula static struct intel_connector * 48837801f3b7SLucas De Marchi intel_ddi_init_hdmi_connector(struct intel_digital_port *dig_port) 4884379bc100SJani Nikula { 4885379bc100SJani Nikula struct intel_connector *connector; 48867801f3b7SLucas De Marchi enum port port = dig_port->base.port; 4887379bc100SJani Nikula 4888379bc100SJani Nikula connector = intel_connector_alloc(); 4889379bc100SJani Nikula if (!connector) 4890379bc100SJani Nikula return NULL; 4891379bc100SJani Nikula 48927801f3b7SLucas De Marchi dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port); 48937801f3b7SLucas De Marchi intel_hdmi_init_connector(dig_port, connector); 4894379bc100SJani Nikula 4895379bc100SJani Nikula return connector; 4896379bc100SJani Nikula } 4897379bc100SJani Nikula 48987801f3b7SLucas De Marchi static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dig_port) 4899379bc100SJani Nikula { 49007801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 4901379bc100SJani Nikula 49027801f3b7SLucas De Marchi if (dig_port->base.port != PORT_A) 4903379bc100SJani Nikula return false; 4904379bc100SJani Nikula 49057801f3b7SLucas De Marchi if (dig_port->saved_port_bits & DDI_A_4_LANES) 4906379bc100SJani Nikula return false; 4907379bc100SJani Nikula 4908379bc100SJani Nikula /* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only 4909379bc100SJani Nikula * supported configuration 4910379bc100SJani Nikula */ 4911379bc100SJani Nikula if (IS_GEN9_LP(dev_priv)) 4912379bc100SJani Nikula return true; 4913379bc100SJani Nikula 4914379bc100SJani Nikula /* Cannonlake: Most of SKUs don't support DDI_E, and the only 4915379bc100SJani Nikula * one who does also have a full A/E split called 4916379bc100SJani Nikula * DDI_F what makes DDI_E useless. However for this 4917379bc100SJani Nikula * case let's trust VBT info. 4918379bc100SJani Nikula */ 4919379bc100SJani Nikula if (IS_CANNONLAKE(dev_priv) && 4920379bc100SJani Nikula !intel_bios_is_port_present(dev_priv, PORT_E)) 4921379bc100SJani Nikula return true; 4922379bc100SJani Nikula 4923379bc100SJani Nikula return false; 4924379bc100SJani Nikula } 4925379bc100SJani Nikula 4926379bc100SJani Nikula static int 49277801f3b7SLucas De Marchi intel_ddi_max_lanes(struct intel_digital_port *dig_port) 4928379bc100SJani Nikula { 49297801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 49307801f3b7SLucas De Marchi enum port port = dig_port->base.port; 4931379bc100SJani Nikula int max_lanes = 4; 4932379bc100SJani Nikula 4933379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 4934379bc100SJani Nikula return max_lanes; 4935379bc100SJani Nikula 4936379bc100SJani Nikula if (port == PORT_A || port == PORT_E) { 4937f7960e7fSJani Nikula if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) 4938379bc100SJani Nikula max_lanes = port == PORT_A ? 4 : 0; 4939379bc100SJani Nikula else 4940379bc100SJani Nikula /* Both A and E share 2 lanes */ 4941379bc100SJani Nikula max_lanes = 2; 4942379bc100SJani Nikula } 4943379bc100SJani Nikula 4944379bc100SJani Nikula /* 4945379bc100SJani Nikula * Some BIOS might fail to set this bit on port A if eDP 4946379bc100SJani Nikula * wasn't lit up at boot. Force this bit set when needed 4947379bc100SJani Nikula * so we use the proper lane count for our calculations. 4948379bc100SJani Nikula */ 49497801f3b7SLucas De Marchi if (intel_ddi_a_force_4_lanes(dig_port)) { 495047bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 495147bdb1caSJani Nikula "Forcing DDI_A_4_LANES for port A\n"); 49527801f3b7SLucas De Marchi dig_port->saved_port_bits |= DDI_A_4_LANES; 4953379bc100SJani Nikula max_lanes = 4; 4954379bc100SJani Nikula } 4955379bc100SJani Nikula 4956379bc100SJani Nikula return max_lanes; 4957379bc100SJani Nikula } 4958379bc100SJani Nikula 4959ddff9a60SMatt Roper static bool hti_uses_phy(struct drm_i915_private *i915, enum phy phy) 4960ddff9a60SMatt Roper { 4961ddff9a60SMatt Roper return i915->hti_state & HDPORT_ENABLED && 4962ddff9a60SMatt Roper (i915->hti_state & HDPORT_PHY_USED_DP(phy) || 4963ddff9a60SMatt Roper i915->hti_state & HDPORT_PHY_USED_HDMI(phy)); 4964ddff9a60SMatt Roper } 4965ddff9a60SMatt Roper 4966379bc100SJani Nikula void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port) 4967379bc100SJani Nikula { 49687801f3b7SLucas De Marchi struct intel_digital_port *dig_port; 496970dfbc29SLucas De Marchi struct intel_encoder *encoder; 4970379bc100SJani Nikula bool init_hdmi, init_dp, init_lspcon = false; 4971d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 4972379bc100SJani Nikula 4973ddff9a60SMatt Roper /* 4974ddff9a60SMatt Roper * On platforms with HTI (aka HDPORT), if it's enabled at boot it may 4975ddff9a60SMatt Roper * have taken over some of the PHYs and made them unavailable to the 4976ddff9a60SMatt Roper * driver. In that case we should skip initializing the corresponding 4977ddff9a60SMatt Roper * outputs. 4978ddff9a60SMatt Roper */ 4979ddff9a60SMatt Roper if (hti_uses_phy(dev_priv, phy)) { 4980ddff9a60SMatt Roper drm_dbg_kms(&dev_priv->drm, "PORT %c / PHY %c reserved by HTI\n", 4981ddff9a60SMatt Roper port_name(port), phy_name(phy)); 4982ddff9a60SMatt Roper return; 4983ddff9a60SMatt Roper } 4984ddff9a60SMatt Roper 4985c5faae5aSJani Nikula init_hdmi = intel_bios_port_supports_dvi(dev_priv, port) || 4986c5faae5aSJani Nikula intel_bios_port_supports_hdmi(dev_priv, port); 4987c5faae5aSJani Nikula init_dp = intel_bios_port_supports_dp(dev_priv, port); 4988379bc100SJani Nikula 4989379bc100SJani Nikula if (intel_bios_is_lspcon_present(dev_priv, port)) { 4990379bc100SJani Nikula /* 4991379bc100SJani Nikula * Lspcon device needs to be driven with DP connector 4992379bc100SJani Nikula * with special detection sequence. So make sure DP 4993379bc100SJani Nikula * is initialized before lspcon. 4994379bc100SJani Nikula */ 4995379bc100SJani Nikula init_dp = true; 4996379bc100SJani Nikula init_lspcon = true; 4997379bc100SJani Nikula init_hdmi = false; 499847bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, "VBT says port %c has lspcon\n", 499947bdb1caSJani Nikula port_name(port)); 5000379bc100SJani Nikula } 5001379bc100SJani Nikula 5002379bc100SJani Nikula if (!init_dp && !init_hdmi) { 500347bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 500447bdb1caSJani Nikula "VBT says port %c is not DVI/HDMI/DP compatible, respect it\n", 5005379bc100SJani Nikula port_name(port)); 5006379bc100SJani Nikula return; 5007379bc100SJani Nikula } 5008379bc100SJani Nikula 50097801f3b7SLucas De Marchi dig_port = kzalloc(sizeof(*dig_port), GFP_KERNEL); 50107801f3b7SLucas De Marchi if (!dig_port) 5011379bc100SJani Nikula return; 5012379bc100SJani Nikula 50137801f3b7SLucas De Marchi encoder = &dig_port->base; 5014379bc100SJani Nikula 501570dfbc29SLucas De Marchi drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs, 5016379bc100SJani Nikula DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port)); 5017379bc100SJani Nikula 501870dfbc29SLucas De Marchi encoder->hotplug = intel_ddi_hotplug; 501970dfbc29SLucas De Marchi encoder->compute_output_type = intel_ddi_compute_output_type; 502070dfbc29SLucas De Marchi encoder->compute_config = intel_ddi_compute_config; 5021b50a1aa6SManasi Navare encoder->compute_config_late = intel_ddi_compute_config_late; 502270dfbc29SLucas De Marchi encoder->enable = intel_enable_ddi; 502370dfbc29SLucas De Marchi encoder->pre_pll_enable = intel_ddi_pre_pll_enable; 502470dfbc29SLucas De Marchi encoder->pre_enable = intel_ddi_pre_enable; 502570dfbc29SLucas De Marchi encoder->disable = intel_disable_ddi; 502670dfbc29SLucas De Marchi encoder->post_disable = intel_ddi_post_disable; 502770dfbc29SLucas De Marchi encoder->update_pipe = intel_ddi_update_pipe; 502870dfbc29SLucas De Marchi encoder->get_hw_state = intel_ddi_get_hw_state; 502970dfbc29SLucas De Marchi encoder->get_config = intel_ddi_get_config; 503070dfbc29SLucas De Marchi encoder->suspend = intel_dp_encoder_suspend; 503170dfbc29SLucas De Marchi encoder->get_power_domains = intel_ddi_get_power_domains; 503270dfbc29SLucas De Marchi 503370dfbc29SLucas De Marchi encoder->type = INTEL_OUTPUT_DDI; 503470dfbc29SLucas De Marchi encoder->power_domain = intel_port_to_power_domain(port); 503570dfbc29SLucas De Marchi encoder->port = port; 503670dfbc29SLucas De Marchi encoder->cloneable = 0; 503770dfbc29SLucas De Marchi encoder->pipe_mask = ~0; 5038379bc100SJani Nikula 5039379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 50407801f3b7SLucas De Marchi dig_port->saved_port_bits = 50417801f3b7SLucas De Marchi intel_de_read(dev_priv, DDI_BUF_CTL(port)) 50427801f3b7SLucas De Marchi & DDI_BUF_PORT_REVERSAL; 5043379bc100SJani Nikula else 50447801f3b7SLucas De Marchi dig_port->saved_port_bits = 50457801f3b7SLucas De Marchi intel_de_read(dev_priv, DDI_BUF_CTL(port)) 50467801f3b7SLucas De Marchi & (DDI_BUF_PORT_REVERSAL | DDI_A_4_LANES); 504770dfbc29SLucas De Marchi 50487801f3b7SLucas De Marchi dig_port->dp.output_reg = INVALID_MMIO_REG; 50497801f3b7SLucas De Marchi dig_port->max_lanes = intel_ddi_max_lanes(dig_port); 50507801f3b7SLucas De Marchi dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port); 5051379bc100SJani Nikula 5052d8fe2ab6SMatt Roper if (intel_phy_is_tc(dev_priv, phy)) { 5053c5faae5aSJani Nikula bool is_legacy = 5054c5faae5aSJani Nikula !intel_bios_port_supports_typec_usb(dev_priv, port) && 5055c5faae5aSJani Nikula !intel_bios_port_supports_tbt(dev_priv, port); 5056379bc100SJani Nikula 50577801f3b7SLucas De Marchi intel_tc_port_init(dig_port, is_legacy); 505824a7bfe0SImre Deak 505970dfbc29SLucas De Marchi encoder->update_prepare = intel_ddi_update_prepare; 506070dfbc29SLucas De Marchi encoder->update_complete = intel_ddi_update_complete; 5061ab7bc4e1SImre Deak } 5062ab7bc4e1SImre Deak 50631de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, port > PORT_I); 50647801f3b7SLucas De Marchi dig_port->ddi_io_power_domain = POWER_DOMAIN_PORT_DDI_A_IO + 5065327f8d8cSLucas De Marchi port - PORT_A; 5066379bc100SJani Nikula 5067379bc100SJani Nikula if (init_dp) { 50687801f3b7SLucas De Marchi if (!intel_ddi_init_dp_connector(dig_port)) 5069379bc100SJani Nikula goto err; 5070379bc100SJani Nikula 50717801f3b7SLucas De Marchi dig_port->hpd_pulse = intel_dp_hpd_pulse; 5072379bc100SJani Nikula } 5073379bc100SJani Nikula 5074379bc100SJani Nikula /* In theory we don't need the encoder->type check, but leave it just in 5075379bc100SJani Nikula * case we have some really bad VBTs... */ 507670dfbc29SLucas De Marchi if (encoder->type != INTEL_OUTPUT_EDP && init_hdmi) { 50777801f3b7SLucas De Marchi if (!intel_ddi_init_hdmi_connector(dig_port)) 5078379bc100SJani Nikula goto err; 5079379bc100SJani Nikula } 5080379bc100SJani Nikula 5081379bc100SJani Nikula if (init_lspcon) { 50827801f3b7SLucas De Marchi if (lspcon_init(dig_port)) 5083379bc100SJani Nikula /* TODO: handle hdmi info frame part */ 508447bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 508547bdb1caSJani Nikula "LSPCON init success on port %c\n", 5086379bc100SJani Nikula port_name(port)); 5087379bc100SJani Nikula else 5088379bc100SJani Nikula /* 5089379bc100SJani Nikula * LSPCON init faied, but DP init was success, so 5090379bc100SJani Nikula * lets try to drive as DP++ port. 5091379bc100SJani Nikula */ 509247bdb1caSJani Nikula drm_err(&dev_priv->drm, 509347bdb1caSJani Nikula "LSPCON init failed on port %c\n", 5094379bc100SJani Nikula port_name(port)); 5095379bc100SJani Nikula } 5096379bc100SJani Nikula 5097edc0e09cSVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) { 5098edc0e09cSVille Syrjälä if (intel_phy_is_tc(dev_priv, phy)) 50997801f3b7SLucas De Marchi dig_port->connected = intel_tc_port_connected; 5100edc0e09cSVille Syrjälä else 51017801f3b7SLucas De Marchi dig_port->connected = lpt_digital_port_connected; 5102c7e8a3d6SVille Syrjälä } else if (INTEL_GEN(dev_priv) >= 8) { 5103c7e8a3d6SVille Syrjälä if (port == PORT_A || IS_GEN9_LP(dev_priv)) 51047801f3b7SLucas De Marchi dig_port->connected = bdw_digital_port_connected; 5105edc0e09cSVille Syrjälä else 51067801f3b7SLucas De Marchi dig_port->connected = lpt_digital_port_connected; 5107edc0e09cSVille Syrjälä } else { 5108c7e8a3d6SVille Syrjälä if (port == PORT_A) 51097801f3b7SLucas De Marchi dig_port->connected = hsw_digital_port_connected; 5110edc0e09cSVille Syrjälä else 51117801f3b7SLucas De Marchi dig_port->connected = lpt_digital_port_connected; 5112edc0e09cSVille Syrjälä } 5113edc0e09cSVille Syrjälä 51147801f3b7SLucas De Marchi intel_infoframe_init(dig_port); 5115379bc100SJani Nikula 5116379bc100SJani Nikula return; 5117379bc100SJani Nikula 5118379bc100SJani Nikula err: 511970dfbc29SLucas De Marchi drm_encoder_cleanup(&encoder->base); 51207801f3b7SLucas De Marchi kfree(dig_port); 5121379bc100SJani Nikula } 5122