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 709379bc100SJani Nikula static const struct ddi_buf_trans * 710a8143150SJosé Roberto de Souza bdw_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 711379bc100SJani Nikula { 712a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 713a8143150SJosé Roberto de Souza 714379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 715379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp); 716379bc100SJani Nikula return bdw_ddi_translations_edp; 717379bc100SJani Nikula } else { 718379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 719379bc100SJani Nikula return bdw_ddi_translations_dp; 720379bc100SJani Nikula } 721379bc100SJani Nikula } 722379bc100SJani Nikula 723379bc100SJani Nikula static const struct ddi_buf_trans * 724a8143150SJosé Roberto de Souza skl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 725379bc100SJani Nikula { 726a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 727a8143150SJosé Roberto de Souza 728379bc100SJani Nikula if (IS_SKL_ULX(dev_priv)) { 729379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp); 730379bc100SJani Nikula return skl_y_ddi_translations_dp; 731379bc100SJani Nikula } else if (IS_SKL_ULT(dev_priv)) { 732379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp); 733379bc100SJani Nikula return skl_u_ddi_translations_dp; 734379bc100SJani Nikula } else { 735379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_ddi_translations_dp); 736379bc100SJani Nikula return skl_ddi_translations_dp; 737379bc100SJani Nikula } 738379bc100SJani Nikula } 739379bc100SJani Nikula 740379bc100SJani Nikula static const struct ddi_buf_trans * 741a8143150SJosé Roberto de Souza kbl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 742379bc100SJani Nikula { 743a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 744a8143150SJosé Roberto de Souza 7455f4ae270SChris Wilson if (IS_KBL_ULX(dev_priv) || 7465f4ae270SChris Wilson IS_CFL_ULX(dev_priv) || 7475f4ae270SChris Wilson IS_CML_ULX(dev_priv)) { 748379bc100SJani Nikula *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp); 749379bc100SJani Nikula return kbl_y_ddi_translations_dp; 7505f4ae270SChris Wilson } else if (IS_KBL_ULT(dev_priv) || 7515f4ae270SChris Wilson IS_CFL_ULT(dev_priv) || 7525f4ae270SChris Wilson IS_CML_ULT(dev_priv)) { 753379bc100SJani Nikula *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp); 754379bc100SJani Nikula return kbl_u_ddi_translations_dp; 755379bc100SJani Nikula } else { 756379bc100SJani Nikula *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp); 757379bc100SJani Nikula return kbl_ddi_translations_dp; 758379bc100SJani Nikula } 759379bc100SJani Nikula } 760379bc100SJani Nikula 761379bc100SJani Nikula static const struct ddi_buf_trans * 762a8143150SJosé Roberto de Souza skl_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 763379bc100SJani Nikula { 764a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 765a8143150SJosé Roberto de Souza 766379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 7675f4ae270SChris Wilson if (IS_SKL_ULX(dev_priv) || 7685f4ae270SChris Wilson IS_KBL_ULX(dev_priv) || 7695f4ae270SChris Wilson IS_CFL_ULX(dev_priv) || 7705f4ae270SChris Wilson IS_CML_ULX(dev_priv)) { 771379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp); 772379bc100SJani Nikula return skl_y_ddi_translations_edp; 7735f4ae270SChris Wilson } else if (IS_SKL_ULT(dev_priv) || 7745f4ae270SChris Wilson IS_KBL_ULT(dev_priv) || 7755f4ae270SChris Wilson IS_CFL_ULT(dev_priv) || 7765f4ae270SChris Wilson IS_CML_ULT(dev_priv)) { 777379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp); 778379bc100SJani Nikula return skl_u_ddi_translations_edp; 779379bc100SJani Nikula } else { 780379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_ddi_translations_edp); 781379bc100SJani Nikula return skl_ddi_translations_edp; 782379bc100SJani Nikula } 783379bc100SJani Nikula } 784379bc100SJani Nikula 7855f4ae270SChris Wilson if (IS_KABYLAKE(dev_priv) || 7865f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) || 7875f4ae270SChris Wilson IS_COMETLAKE(dev_priv)) 788a8143150SJosé Roberto de Souza return kbl_get_buf_trans_dp(encoder, n_entries); 789379bc100SJani Nikula else 790a8143150SJosé Roberto de Souza return skl_get_buf_trans_dp(encoder, n_entries); 791379bc100SJani Nikula } 792379bc100SJani Nikula 793379bc100SJani Nikula static const struct ddi_buf_trans * 794379bc100SJani Nikula skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries) 795379bc100SJani Nikula { 7965f4ae270SChris Wilson if (IS_SKL_ULX(dev_priv) || 7975f4ae270SChris Wilson IS_KBL_ULX(dev_priv) || 7985f4ae270SChris Wilson IS_CFL_ULX(dev_priv) || 7995f4ae270SChris Wilson IS_CML_ULX(dev_priv)) { 800379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi); 801379bc100SJani Nikula return skl_y_ddi_translations_hdmi; 802379bc100SJani Nikula } else { 803379bc100SJani Nikula *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi); 804379bc100SJani Nikula return skl_ddi_translations_hdmi; 805379bc100SJani Nikula } 806379bc100SJani Nikula } 807379bc100SJani Nikula 808379bc100SJani Nikula static int skl_buf_trans_num_entries(enum port port, int n_entries) 809379bc100SJani Nikula { 810379bc100SJani Nikula /* Only DDIA and DDIE can select the 10th register with DP */ 811379bc100SJani Nikula if (port == PORT_A || port == PORT_E) 812379bc100SJani Nikula return min(n_entries, 10); 813379bc100SJani Nikula else 814379bc100SJani Nikula return min(n_entries, 9); 815379bc100SJani Nikula } 816379bc100SJani Nikula 817379bc100SJani Nikula static const struct ddi_buf_trans * 818*f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 819379bc100SJani Nikula { 820a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 821a8143150SJosé Roberto de Souza 8225f4ae270SChris Wilson if (IS_KABYLAKE(dev_priv) || 8235f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) || 8245f4ae270SChris Wilson IS_COMETLAKE(dev_priv)) { 825379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations = 826a8143150SJosé Roberto de Souza kbl_get_buf_trans_dp(encoder, n_entries); 827*f0e86e05SJosé Roberto de Souza *n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries); 828379bc100SJani Nikula return ddi_translations; 829379bc100SJani Nikula } else if (IS_SKYLAKE(dev_priv)) { 830379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations = 831a8143150SJosé Roberto de Souza skl_get_buf_trans_dp(encoder, n_entries); 832*f0e86e05SJosé Roberto de Souza *n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries); 833379bc100SJani Nikula return ddi_translations; 834379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 835379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp); 836379bc100SJani Nikula return bdw_ddi_translations_dp; 837379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 838379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp); 839379bc100SJani Nikula return hsw_ddi_translations_dp; 840379bc100SJani Nikula } 841379bc100SJani Nikula 842379bc100SJani Nikula *n_entries = 0; 843379bc100SJani Nikula return NULL; 844379bc100SJani Nikula } 845379bc100SJani Nikula 846379bc100SJani Nikula static const struct ddi_buf_trans * 847*f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 848379bc100SJani Nikula { 849a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 850a8143150SJosé Roberto de Souza 851379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) { 852379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations = 853a8143150SJosé Roberto de Souza skl_get_buf_trans_edp(encoder, n_entries); 854*f0e86e05SJosé Roberto de Souza *n_entries = skl_buf_trans_num_entries(encoder->port, *n_entries); 855379bc100SJani Nikula return ddi_translations; 856379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 857a8143150SJosé Roberto de Souza return bdw_get_buf_trans_edp(encoder, n_entries); 858379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 859379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp); 860379bc100SJani Nikula return hsw_ddi_translations_dp; 861379bc100SJani Nikula } 862379bc100SJani Nikula 863379bc100SJani Nikula *n_entries = 0; 864379bc100SJani Nikula return NULL; 865379bc100SJani Nikula } 866379bc100SJani Nikula 867379bc100SJani Nikula static const struct ddi_buf_trans * 868379bc100SJani Nikula intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv, 869379bc100SJani Nikula int *n_entries) 870379bc100SJani Nikula { 871379bc100SJani Nikula if (IS_BROADWELL(dev_priv)) { 872379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_fdi); 873379bc100SJani Nikula return bdw_ddi_translations_fdi; 874379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 875379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi); 876379bc100SJani Nikula return hsw_ddi_translations_fdi; 877379bc100SJani Nikula } 878379bc100SJani Nikula 879379bc100SJani Nikula *n_entries = 0; 880379bc100SJani Nikula return NULL; 881379bc100SJani Nikula } 882379bc100SJani Nikula 883379bc100SJani Nikula static const struct ddi_buf_trans * 884a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(struct intel_encoder *encoder, 885379bc100SJani Nikula int *n_entries) 886379bc100SJani Nikula { 887a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 888a8143150SJosé Roberto de Souza 889379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) { 890379bc100SJani Nikula return skl_get_buf_trans_hdmi(dev_priv, n_entries); 891379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 892379bc100SJani Nikula *n_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi); 893379bc100SJani Nikula return bdw_ddi_translations_hdmi; 894379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 895379bc100SJani Nikula *n_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi); 896379bc100SJani Nikula return hsw_ddi_translations_hdmi; 897379bc100SJani Nikula } 898379bc100SJani Nikula 899379bc100SJani Nikula *n_entries = 0; 900379bc100SJani Nikula return NULL; 901379bc100SJani Nikula } 902379bc100SJani Nikula 903379bc100SJani Nikula static const struct bxt_ddi_buf_trans * 904a8143150SJosé Roberto de Souza bxt_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 905379bc100SJani Nikula { 906379bc100SJani Nikula *n_entries = ARRAY_SIZE(bxt_ddi_translations_dp); 907379bc100SJani Nikula return bxt_ddi_translations_dp; 908379bc100SJani Nikula } 909379bc100SJani Nikula 910379bc100SJani Nikula static const struct bxt_ddi_buf_trans * 911a8143150SJosé Roberto de Souza bxt_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 912379bc100SJani Nikula { 913a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 914a8143150SJosé Roberto de Souza 915379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 916379bc100SJani Nikula *n_entries = ARRAY_SIZE(bxt_ddi_translations_edp); 917379bc100SJani Nikula return bxt_ddi_translations_edp; 918379bc100SJani Nikula } 919379bc100SJani Nikula 920a8143150SJosé Roberto de Souza return bxt_get_buf_trans_dp(encoder, n_entries); 921379bc100SJani Nikula } 922379bc100SJani Nikula 923379bc100SJani Nikula static const struct bxt_ddi_buf_trans * 924a8143150SJosé Roberto de Souza bxt_get_buf_trans_hdmi(struct intel_encoder *encoder, int *n_entries) 925379bc100SJani Nikula { 926379bc100SJani Nikula *n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi); 927379bc100SJani Nikula return bxt_ddi_translations_hdmi; 928379bc100SJani Nikula } 929379bc100SJani Nikula 930379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 931a8143150SJosé Roberto de Souza cnl_get_buf_trans_hdmi(struct intel_encoder *encoder, int *n_entries) 932379bc100SJani Nikula { 933a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 934f7960e7fSJani Nikula u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 935379bc100SJani Nikula 936379bc100SJani Nikula if (voltage == VOLTAGE_INFO_0_85V) { 937379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V); 938379bc100SJani Nikula return cnl_ddi_translations_hdmi_0_85V; 939379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_0_95V) { 940379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V); 941379bc100SJani Nikula return cnl_ddi_translations_hdmi_0_95V; 942379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_1_05V) { 943379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V); 944379bc100SJani Nikula return cnl_ddi_translations_hdmi_1_05V; 945379bc100SJani Nikula } else { 946379bc100SJani Nikula *n_entries = 1; /* shut up gcc */ 947379bc100SJani Nikula MISSING_CASE(voltage); 948379bc100SJani Nikula } 949379bc100SJani Nikula return NULL; 950379bc100SJani Nikula } 951379bc100SJani Nikula 952379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 953a8143150SJosé Roberto de Souza cnl_get_buf_trans_dp(struct intel_encoder *encoder, int *n_entries) 954379bc100SJani Nikula { 955a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 956f7960e7fSJani Nikula u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 957379bc100SJani Nikula 958379bc100SJani Nikula if (voltage == VOLTAGE_INFO_0_85V) { 959379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V); 960379bc100SJani Nikula return cnl_ddi_translations_dp_0_85V; 961379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_0_95V) { 962379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V); 963379bc100SJani Nikula return cnl_ddi_translations_dp_0_95V; 964379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_1_05V) { 965379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V); 966379bc100SJani Nikula return cnl_ddi_translations_dp_1_05V; 967379bc100SJani Nikula } else { 968379bc100SJani Nikula *n_entries = 1; /* shut up gcc */ 969379bc100SJani Nikula MISSING_CASE(voltage); 970379bc100SJani Nikula } 971379bc100SJani Nikula return NULL; 972379bc100SJani Nikula } 973379bc100SJani Nikula 974379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 975a8143150SJosé Roberto de Souza cnl_get_buf_trans_edp(struct intel_encoder *encoder, int *n_entries) 976379bc100SJani Nikula { 977a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 978f7960e7fSJani Nikula u32 voltage = intel_de_read(dev_priv, CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK; 979379bc100SJani Nikula 980379bc100SJani Nikula if (dev_priv->vbt.edp.low_vswing) { 981379bc100SJani Nikula if (voltage == VOLTAGE_INFO_0_85V) { 982379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V); 983379bc100SJani Nikula return cnl_ddi_translations_edp_0_85V; 984379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_0_95V) { 985379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V); 986379bc100SJani Nikula return cnl_ddi_translations_edp_0_95V; 987379bc100SJani Nikula } else if (voltage == VOLTAGE_INFO_1_05V) { 988379bc100SJani Nikula *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V); 989379bc100SJani Nikula return cnl_ddi_translations_edp_1_05V; 990379bc100SJani Nikula } else { 991379bc100SJani Nikula *n_entries = 1; /* shut up gcc */ 992379bc100SJani Nikula MISSING_CASE(voltage); 993379bc100SJani Nikula } 994379bc100SJani Nikula return NULL; 995379bc100SJani Nikula } else { 996a8143150SJosé Roberto de Souza return cnl_get_buf_trans_dp(encoder, n_entries); 997379bc100SJani Nikula } 998379bc100SJani Nikula } 999379bc100SJani Nikula 1000379bc100SJani Nikula static const struct cnl_ddi_buf_trans * 1001a8143150SJosé Roberto de Souza icl_get_combo_buf_trans(struct intel_encoder *encoder, int type, int rate, 10024a8134d5SMatt Roper int *n_entries) 1003379bc100SJani Nikula { 1004a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1005a8143150SJosé Roberto de Souza 1006379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) { 1007379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_hdmi); 1008379bc100SJani Nikula return icl_combo_phy_ddi_translations_hdmi; 1009379bc100SJani Nikula } else if (rate > 540000 && type == INTEL_OUTPUT_EDP) { 1010379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr3); 1011379bc100SJani Nikula return icl_combo_phy_ddi_translations_edp_hbr3; 1012379bc100SJani Nikula } else if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) { 1013379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_edp_hbr2); 1014379bc100SJani Nikula return icl_combo_phy_ddi_translations_edp_hbr2; 1015379bc100SJani Nikula } 1016379bc100SJani Nikula 1017379bc100SJani Nikula *n_entries = ARRAY_SIZE(icl_combo_phy_ddi_translations_dp_hbr2); 1018379bc100SJani Nikula return icl_combo_phy_ddi_translations_dp_hbr2; 1019379bc100SJani Nikula } 1020379bc100SJani Nikula 10219f7ffa29SJosé Roberto de Souza static const struct icl_mg_phy_ddi_buf_trans * 1022a8143150SJosé Roberto de Souza icl_get_mg_buf_trans(struct intel_encoder *encoder, int type, int rate, 10239f7ffa29SJosé Roberto de Souza int *n_entries) 10249f7ffa29SJosé Roberto de Souza { 10259f7ffa29SJosé Roberto de Souza if (type == INTEL_OUTPUT_HDMI) { 10269f7ffa29SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_hdmi); 10279f7ffa29SJosé Roberto de Souza return icl_mg_phy_ddi_translations_hdmi; 10289f7ffa29SJosé Roberto de Souza } else if (rate > 270000) { 10299f7ffa29SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_hbr2_hbr3); 10309f7ffa29SJosé Roberto de Souza return icl_mg_phy_ddi_translations_hbr2_hbr3; 10319f7ffa29SJosé Roberto de Souza } 10329f7ffa29SJosé Roberto de Souza 10339f7ffa29SJosé Roberto de Souza *n_entries = ARRAY_SIZE(icl_mg_phy_ddi_translations_rbr_hbr); 10349f7ffa29SJosé Roberto de Souza return icl_mg_phy_ddi_translations_rbr_hbr; 10359f7ffa29SJosé Roberto de Souza } 10369f7ffa29SJosé Roberto de Souza 1037bd3cf6f7SJosé Roberto de Souza static const struct cnl_ddi_buf_trans * 1038a8143150SJosé Roberto de Souza ehl_get_combo_buf_trans(struct intel_encoder *encoder, int type, int rate, 1039b42d5a67SJosé Roberto de Souza int *n_entries) 1040b42d5a67SJosé Roberto de Souza { 1041a2ae2010SJosé Roberto de Souza if (type != INTEL_OUTPUT_HDMI && type != INTEL_OUTPUT_EDP) { 1042a2ae2010SJosé Roberto de Souza *n_entries = ARRAY_SIZE(ehl_combo_phy_ddi_translations_dp); 1043a2ae2010SJosé Roberto de Souza return ehl_combo_phy_ddi_translations_dp; 1044b42d5a67SJosé Roberto de Souza } 1045b42d5a67SJosé Roberto de Souza 1046a8143150SJosé Roberto de Souza return icl_get_combo_buf_trans(encoder, type, rate, n_entries); 1047b42d5a67SJosé Roberto de Souza } 1048b42d5a67SJosé Roberto de Souza 1049b42d5a67SJosé Roberto de Souza static const struct cnl_ddi_buf_trans * 1050a8143150SJosé Roberto de Souza tgl_get_combo_buf_trans(struct intel_encoder *encoder, int type, int rate, 1051bd3cf6f7SJosé Roberto de Souza int *n_entries) 1052bd3cf6f7SJosé Roberto de Souza { 105370988115SJosé Roberto de Souza if (type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_EDP) { 1054a8143150SJosé Roberto de Souza return icl_get_combo_buf_trans(encoder, type, rate, n_entries); 1055bd3cf6f7SJosé Roberto de Souza } else if (rate > 270000) { 1056bd3cf6f7SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr2); 1057bd3cf6f7SJosé Roberto de Souza return tgl_combo_phy_ddi_translations_dp_hbr2; 1058bd3cf6f7SJosé Roberto de Souza } 1059bd3cf6f7SJosé Roberto de Souza 1060bd3cf6f7SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_combo_phy_ddi_translations_dp_hbr); 1061bd3cf6f7SJosé Roberto de Souza return tgl_combo_phy_ddi_translations_dp_hbr; 1062bd3cf6f7SJosé Roberto de Souza } 1063bd3cf6f7SJosé Roberto de Souza 10649fa67699SJosé Roberto de Souza static const struct tgl_dkl_phy_ddi_buf_trans * 1065a8143150SJosé Roberto de Souza tgl_get_dkl_buf_trans(struct intel_encoder *encoder, int type, int rate, 10669fa67699SJosé Roberto de Souza int *n_entries) 10679fa67699SJosé Roberto de Souza { 10689fa67699SJosé Roberto de Souza if (type == INTEL_OUTPUT_HDMI) { 10699fa67699SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_dkl_phy_hdmi_ddi_trans); 10709fa67699SJosé Roberto de Souza return tgl_dkl_phy_hdmi_ddi_trans; 10719fa67699SJosé Roberto de Souza } else if (rate > 270000) { 10729fa67699SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans_hbr2); 10739fa67699SJosé Roberto de Souza return tgl_dkl_phy_dp_ddi_trans_hbr2; 10749fa67699SJosé Roberto de Souza } 10759fa67699SJosé Roberto de Souza 10769fa67699SJosé Roberto de Souza *n_entries = ARRAY_SIZE(tgl_dkl_phy_dp_ddi_trans); 10779fa67699SJosé Roberto de Souza return tgl_dkl_phy_dp_ddi_trans; 10789fa67699SJosé Roberto de Souza } 10799fa67699SJosé Roberto de Souza 10800aed3bdeSJani Nikula static int intel_ddi_hdmi_level(struct intel_encoder *encoder) 1081379bc100SJani Nikula { 10820aed3bdeSJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1083379bc100SJani Nikula int n_entries, level, default_entry; 10840aed3bdeSJani Nikula enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 1085379bc100SJani Nikula 1086978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 1087978c3e53SClinton A Taylor if (intel_phy_is_combo(dev_priv, phy)) 1088a8143150SJosé Roberto de Souza tgl_get_combo_buf_trans(encoder, INTEL_OUTPUT_HDMI, 1089978c3e53SClinton A Taylor 0, &n_entries); 1090978c3e53SClinton A Taylor else 1091a8143150SJosé Roberto de Souza tgl_get_dkl_buf_trans(encoder, INTEL_OUTPUT_HDMI, 0, 10929fa67699SJosé Roberto de Souza &n_entries); 1093978c3e53SClinton A Taylor default_entry = n_entries - 1; 1094978c3e53SClinton A Taylor } else if (INTEL_GEN(dev_priv) == 11) { 1095d8fe2ab6SMatt Roper if (intel_phy_is_combo(dev_priv, phy)) 1096a8143150SJosé Roberto de Souza icl_get_combo_buf_trans(encoder, INTEL_OUTPUT_HDMI, 1097379bc100SJani Nikula 0, &n_entries); 1098379bc100SJani Nikula else 1099a8143150SJosé Roberto de Souza icl_get_mg_buf_trans(encoder, INTEL_OUTPUT_HDMI, 0, 11009f7ffa29SJosé Roberto de Souza &n_entries); 1101379bc100SJani Nikula default_entry = n_entries - 1; 1102379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 1103a8143150SJosé Roberto de Souza cnl_get_buf_trans_hdmi(encoder, &n_entries); 1104379bc100SJani Nikula default_entry = n_entries - 1; 1105379bc100SJani Nikula } else if (IS_GEN9_LP(dev_priv)) { 1106a8143150SJosé Roberto de Souza bxt_get_buf_trans_hdmi(encoder, &n_entries); 1107379bc100SJani Nikula default_entry = n_entries - 1; 1108379bc100SJani Nikula } else if (IS_GEN9_BC(dev_priv)) { 1109a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1110379bc100SJani Nikula default_entry = 8; 1111379bc100SJani Nikula } else if (IS_BROADWELL(dev_priv)) { 1112a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1113379bc100SJani Nikula default_entry = 7; 1114379bc100SJani Nikula } else if (IS_HASWELL(dev_priv)) { 1115a8143150SJosé Roberto de Souza intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1116379bc100SJani Nikula default_entry = 6; 1117379bc100SJani Nikula } else { 11181de143ccSPankaj Bharadiya drm_WARN(&dev_priv->drm, 1, "ddi translation table missing\n"); 1119379bc100SJani Nikula return 0; 1120379bc100SJani Nikula } 1121379bc100SJani Nikula 11221de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, n_entries == 0)) 1123379bc100SJani Nikula return 0; 11247a0073d6SJani Nikula 11250aed3bdeSJani Nikula level = intel_bios_hdmi_level_shift(encoder); 11260aed3bdeSJani Nikula if (level < 0) 11277a0073d6SJani Nikula level = default_entry; 11287a0073d6SJani Nikula 11291de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 1130379bc100SJani Nikula level = n_entries - 1; 1131379bc100SJani Nikula 1132379bc100SJani Nikula return level; 1133379bc100SJani Nikula } 1134379bc100SJani Nikula 1135379bc100SJani Nikula /* 1136379bc100SJani Nikula * Starting with Haswell, DDI port buffers must be programmed with correct 1137379bc100SJani Nikula * values in advance. This function programs the correct values for 1138379bc100SJani Nikula * DP/eDP/FDI use cases. 1139379bc100SJani Nikula */ 1140379bc100SJani Nikula static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder, 1141379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 1142379bc100SJani Nikula { 1143379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1144379bc100SJani Nikula u32 iboost_bit = 0; 1145379bc100SJani Nikula int i, n_entries; 1146379bc100SJani Nikula enum port port = encoder->port; 1147379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations; 1148379bc100SJani Nikula 1149379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) 1150379bc100SJani Nikula ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv, 1151379bc100SJani Nikula &n_entries); 1152379bc100SJani Nikula else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_EDP)) 1153*f0e86e05SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_edp(encoder, 1154379bc100SJani Nikula &n_entries); 1155379bc100SJani Nikula else 1156*f0e86e05SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_dp(encoder, 1157379bc100SJani Nikula &n_entries); 1158379bc100SJani Nikula 1159379bc100SJani Nikula /* If we're boosting the current, set bit 31 of trans1 */ 1160605a1872SJani Nikula if (IS_GEN9_BC(dev_priv) && intel_bios_dp_boost_level(encoder)) 1161379bc100SJani Nikula iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; 1162379bc100SJani Nikula 1163379bc100SJani Nikula for (i = 0; i < n_entries; i++) { 1164f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, i), 1165379bc100SJani Nikula ddi_translations[i].trans1 | iboost_bit); 1166f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, i), 1167379bc100SJani Nikula ddi_translations[i].trans2); 1168379bc100SJani Nikula } 1169379bc100SJani Nikula } 1170379bc100SJani Nikula 1171379bc100SJani Nikula /* 1172379bc100SJani Nikula * Starting with Haswell, DDI port buffers must be programmed with correct 1173379bc100SJani Nikula * values in advance. This function programs the correct values for 1174379bc100SJani Nikula * HDMI/DVI use cases. 1175379bc100SJani Nikula */ 1176379bc100SJani Nikula static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder, 1177379bc100SJani Nikula int level) 1178379bc100SJani Nikula { 1179379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 1180379bc100SJani Nikula u32 iboost_bit = 0; 1181379bc100SJani Nikula int n_entries; 1182379bc100SJani Nikula enum port port = encoder->port; 1183379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations; 1184379bc100SJani Nikula 1185a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 1186379bc100SJani Nikula 11871de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 1188379bc100SJani Nikula return; 11891de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 1190379bc100SJani Nikula level = n_entries - 1; 1191379bc100SJani Nikula 1192379bc100SJani Nikula /* If we're boosting the current, set bit 31 of trans1 */ 119301a60883SJani Nikula if (IS_GEN9_BC(dev_priv) && intel_bios_hdmi_boost_level(encoder)) 1194379bc100SJani Nikula iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE; 1195379bc100SJani Nikula 1196379bc100SJani Nikula /* Entry 9 is for HDMI: */ 1197f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_LO(port, 9), 1198379bc100SJani Nikula ddi_translations[level].trans1 | iboost_bit); 1199f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_TRANS_HI(port, 9), 1200379bc100SJani Nikula ddi_translations[level].trans2); 1201379bc100SJani Nikula } 1202379bc100SJani Nikula 1203379bc100SJani Nikula static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv, 1204379bc100SJani Nikula enum port port) 1205379bc100SJani Nikula { 12065a2ad99bSManasi Navare if (IS_BROXTON(dev_priv)) { 12075a2ad99bSManasi Navare udelay(16); 1208379bc100SJani Nikula return; 1209379bc100SJani Nikula } 12105a2ad99bSManasi Navare 12115a2ad99bSManasi Navare if (wait_for_us((intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 12125a2ad99bSManasi Navare DDI_BUF_IS_IDLE), 8)) 12135a2ad99bSManasi Navare drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get idle\n", 121447bdb1caSJani Nikula port_name(port)); 1215379bc100SJani Nikula } 1216379bc100SJani Nikula 1217e828da30SManasi Navare static void intel_wait_ddi_buf_active(struct drm_i915_private *dev_priv, 1218e828da30SManasi Navare enum port port) 1219e828da30SManasi Navare { 1220e828da30SManasi Navare /* Wait > 518 usecs for DDI_BUF_CTL to be non idle */ 1221e828da30SManasi Navare if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) { 1222e828da30SManasi Navare usleep_range(518, 1000); 1223e828da30SManasi Navare return; 1224e828da30SManasi Navare } 1225e828da30SManasi Navare 1226e828da30SManasi Navare if (wait_for_us(!(intel_de_read(dev_priv, DDI_BUF_CTL(port)) & 1227e828da30SManasi Navare DDI_BUF_IS_IDLE), 500)) 1228e828da30SManasi Navare drm_err(&dev_priv->drm, "Timeout waiting for DDI BUF %c to get active\n", 1229e828da30SManasi Navare port_name(port)); 1230e828da30SManasi Navare } 1231e828da30SManasi Navare 1232379bc100SJani Nikula static u32 hsw_pll_to_ddi_pll_sel(const struct intel_shared_dpll *pll) 1233379bc100SJani Nikula { 1234379bc100SJani Nikula switch (pll->info->id) { 1235379bc100SJani Nikula case DPLL_ID_WRPLL1: 1236379bc100SJani Nikula return PORT_CLK_SEL_WRPLL1; 1237379bc100SJani Nikula case DPLL_ID_WRPLL2: 1238379bc100SJani Nikula return PORT_CLK_SEL_WRPLL2; 1239379bc100SJani Nikula case DPLL_ID_SPLL: 1240379bc100SJani Nikula return PORT_CLK_SEL_SPLL; 1241379bc100SJani Nikula case DPLL_ID_LCPLL_810: 1242379bc100SJani Nikula return PORT_CLK_SEL_LCPLL_810; 1243379bc100SJani Nikula case DPLL_ID_LCPLL_1350: 1244379bc100SJani Nikula return PORT_CLK_SEL_LCPLL_1350; 1245379bc100SJani Nikula case DPLL_ID_LCPLL_2700: 1246379bc100SJani Nikula return PORT_CLK_SEL_LCPLL_2700; 1247379bc100SJani Nikula default: 1248379bc100SJani Nikula MISSING_CASE(pll->info->id); 1249379bc100SJani Nikula return PORT_CLK_SEL_NONE; 1250379bc100SJani Nikula } 1251379bc100SJani Nikula } 1252379bc100SJani Nikula 1253379bc100SJani Nikula static u32 icl_pll_to_ddi_clk_sel(struct intel_encoder *encoder, 1254379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 1255379bc100SJani Nikula { 1256379bc100SJani Nikula const struct intel_shared_dpll *pll = crtc_state->shared_dpll; 1257379bc100SJani Nikula int clock = crtc_state->port_clock; 1258379bc100SJani Nikula const enum intel_dpll_id id = pll->info->id; 1259379bc100SJani Nikula 1260379bc100SJani Nikula switch (id) { 1261379bc100SJani Nikula default: 1262379bc100SJani Nikula /* 1263379bc100SJani Nikula * DPLL_ID_ICL_DPLL0 and DPLL_ID_ICL_DPLL1 should not be used 1264379bc100SJani Nikula * here, so do warn if this get passed in 1265379bc100SJani Nikula */ 1266379bc100SJani Nikula MISSING_CASE(id); 1267379bc100SJani Nikula return DDI_CLK_SEL_NONE; 1268379bc100SJani Nikula case DPLL_ID_ICL_TBTPLL: 1269379bc100SJani Nikula switch (clock) { 1270379bc100SJani Nikula case 162000: 1271379bc100SJani Nikula return DDI_CLK_SEL_TBT_162; 1272379bc100SJani Nikula case 270000: 1273379bc100SJani Nikula return DDI_CLK_SEL_TBT_270; 1274379bc100SJani Nikula case 540000: 1275379bc100SJani Nikula return DDI_CLK_SEL_TBT_540; 1276379bc100SJani Nikula case 810000: 1277379bc100SJani Nikula return DDI_CLK_SEL_TBT_810; 1278379bc100SJani Nikula default: 1279379bc100SJani Nikula MISSING_CASE(clock); 1280379bc100SJani Nikula return DDI_CLK_SEL_NONE; 1281379bc100SJani Nikula } 1282379bc100SJani Nikula case DPLL_ID_ICL_MGPLL1: 1283379bc100SJani Nikula case DPLL_ID_ICL_MGPLL2: 1284379bc100SJani Nikula case DPLL_ID_ICL_MGPLL3: 1285379bc100SJani Nikula case DPLL_ID_ICL_MGPLL4: 12866677c3b1SJosé Roberto de Souza case DPLL_ID_TGL_MGPLL5: 12876677c3b1SJosé Roberto de Souza case DPLL_ID_TGL_MGPLL6: 1288379bc100SJani Nikula return DDI_CLK_SEL_MG; 1289379bc100SJani Nikula } 1290379bc100SJani Nikula } 1291379bc100SJani Nikula 1292379bc100SJani Nikula /* Starting with Haswell, different DDI ports can work in FDI mode for 1293379bc100SJani Nikula * connection to the PCH-located connectors. For this, it is necessary to train 1294379bc100SJani Nikula * both the DDI port and PCH receiver for the desired DDI buffer settings. 1295379bc100SJani Nikula * 1296379bc100SJani Nikula * The recommended port to work in FDI mode is DDI E, which we use here. Also, 1297379bc100SJani Nikula * please note that when FDI mode is active on DDI E, it shares 2 lines with 1298379bc100SJani Nikula * DDI A (which is used for eDP) 1299379bc100SJani Nikula */ 1300379bc100SJani Nikula 13016a6d79deSVille Syrjälä void hsw_fdi_link_train(struct intel_encoder *encoder, 1302379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 1303379bc100SJani Nikula { 13046a6d79deSVille Syrjälä struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 13056a6d79deSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1306379bc100SJani Nikula u32 temp, i, rx_ctl_val, ddi_pll_sel; 1307379bc100SJani Nikula 1308379bc100SJani Nikula intel_prepare_dp_ddi_buffers(encoder, crtc_state); 1309379bc100SJani Nikula 1310379bc100SJani Nikula /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the 1311379bc100SJani Nikula * mode set "sequence for CRT port" document: 1312379bc100SJani Nikula * - TP1 to TP2 time with the default value 1313379bc100SJani Nikula * - FDI delay to 90h 1314379bc100SJani Nikula * 1315379bc100SJani Nikula * WaFDIAutoLinkSetTimingOverrride:hsw 1316379bc100SJani Nikula */ 1317f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), 1318f7960e7fSJani Nikula FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2) | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); 1319379bc100SJani Nikula 1320379bc100SJani Nikula /* Enable the PCH Receiver FDI PLL */ 1321379bc100SJani Nikula rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE | 1322379bc100SJani Nikula FDI_RX_PLL_ENABLE | 1323379bc100SJani Nikula FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes); 1324f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1325f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A)); 1326379bc100SJani Nikula udelay(220); 1327379bc100SJani Nikula 1328379bc100SJani Nikula /* Switch from Rawclk to PCDclk */ 1329379bc100SJani Nikula rx_ctl_val |= FDI_PCDCLK; 1330f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1331379bc100SJani Nikula 1332379bc100SJani Nikula /* Configure Port Clock Select */ 1333379bc100SJani Nikula ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll); 1334f7960e7fSJani Nikula intel_de_write(dev_priv, PORT_CLK_SEL(PORT_E), ddi_pll_sel); 13351de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, ddi_pll_sel != PORT_CLK_SEL_SPLL); 1336379bc100SJani Nikula 1337379bc100SJani Nikula /* Start the training iterating through available voltages and emphasis, 1338379bc100SJani Nikula * testing each value twice. */ 1339379bc100SJani Nikula for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) { 1340379bc100SJani Nikula /* Configure DP_TP_CTL with auto-training */ 1341f7960e7fSJani Nikula intel_de_write(dev_priv, DP_TP_CTL(PORT_E), 13427db8736dSVille Syrjälä DP_TP_CTL_FDI_AUTOTRAIN | 13437db8736dSVille Syrjälä DP_TP_CTL_ENHANCED_FRAME_ENABLE | 13447db8736dSVille Syrjälä DP_TP_CTL_LINK_TRAIN_PAT1 | 13457db8736dSVille Syrjälä DP_TP_CTL_ENABLE); 1346379bc100SJani Nikula 1347379bc100SJani Nikula /* Configure and enable DDI_BUF_CTL for DDI E with next voltage. 1348379bc100SJani Nikula * DDI E does not support port reversal, the functionality is 1349379bc100SJani Nikula * achieved on the PCH side in FDI_RX_CTL, so no need to set the 1350379bc100SJani Nikula * port reversal bit */ 1351f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(PORT_E), 1352f7960e7fSJani Nikula DDI_BUF_CTL_ENABLE | ((crtc_state->fdi_lanes - 1) << 1) | DDI_BUF_TRANS_SELECT(i / 2)); 1353f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DDI_BUF_CTL(PORT_E)); 1354379bc100SJani Nikula 1355379bc100SJani Nikula udelay(600); 1356379bc100SJani Nikula 1357379bc100SJani Nikula /* Program PCH FDI Receiver TU */ 1358f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64)); 1359379bc100SJani Nikula 1360379bc100SJani Nikula /* Enable PCH FDI Receiver with auto-training */ 1361379bc100SJani Nikula rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO; 1362f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1363f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A)); 1364379bc100SJani Nikula 1365379bc100SJani Nikula /* Wait for FDI receiver lane calibration */ 1366379bc100SJani Nikula udelay(30); 1367379bc100SJani Nikula 1368379bc100SJani Nikula /* Unset FDI_RX_MISC pwrdn lanes */ 1369f7960e7fSJani Nikula temp = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1370379bc100SJani Nikula temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 1371f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), temp); 1372f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1373379bc100SJani Nikula 1374379bc100SJani Nikula /* Wait for FDI auto training time */ 1375379bc100SJani Nikula udelay(5); 1376379bc100SJani Nikula 1377f7960e7fSJani Nikula temp = intel_de_read(dev_priv, DP_TP_STATUS(PORT_E)); 1378379bc100SJani Nikula if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) { 137947bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 138047bdb1caSJani Nikula "FDI link training done on step %d\n", i); 1381379bc100SJani Nikula break; 1382379bc100SJani Nikula } 1383379bc100SJani Nikula 1384379bc100SJani Nikula /* 1385379bc100SJani Nikula * Leave things enabled even if we failed to train FDI. 1386379bc100SJani Nikula * Results in less fireworks from the state checker. 1387379bc100SJani Nikula */ 1388379bc100SJani Nikula if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) { 138947bdb1caSJani Nikula drm_err(&dev_priv->drm, "FDI link training failed!\n"); 1390379bc100SJani Nikula break; 1391379bc100SJani Nikula } 1392379bc100SJani Nikula 1393379bc100SJani Nikula rx_ctl_val &= ~FDI_RX_ENABLE; 1394f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), rx_ctl_val); 1395f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_CTL(PIPE_A)); 1396379bc100SJani Nikula 1397f7960e7fSJani Nikula temp = intel_de_read(dev_priv, DDI_BUF_CTL(PORT_E)); 1398379bc100SJani Nikula temp &= ~DDI_BUF_CTL_ENABLE; 1399f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(PORT_E), temp); 1400f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DDI_BUF_CTL(PORT_E)); 1401379bc100SJani Nikula 1402379bc100SJani Nikula /* Disable DP_TP_CTL and FDI_RX_CTL and retry */ 1403f7960e7fSJani Nikula temp = intel_de_read(dev_priv, DP_TP_CTL(PORT_E)); 1404379bc100SJani Nikula temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 1405379bc100SJani Nikula temp |= DP_TP_CTL_LINK_TRAIN_PAT1; 1406f7960e7fSJani Nikula intel_de_write(dev_priv, DP_TP_CTL(PORT_E), temp); 1407f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DP_TP_CTL(PORT_E)); 1408379bc100SJani Nikula 1409379bc100SJani Nikula intel_wait_ddi_buf_idle(dev_priv, PORT_E); 1410379bc100SJani Nikula 1411379bc100SJani Nikula /* Reset FDI_RX_MISC pwrdn lanes */ 1412f7960e7fSJani Nikula temp = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1413379bc100SJani Nikula temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 1414379bc100SJani Nikula temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); 1415f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), temp); 1416f7960e7fSJani Nikula intel_de_posting_read(dev_priv, FDI_RX_MISC(PIPE_A)); 1417379bc100SJani Nikula } 1418379bc100SJani Nikula 1419379bc100SJani Nikula /* Enable normal pixel sending for FDI */ 1420f7960e7fSJani Nikula intel_de_write(dev_priv, DP_TP_CTL(PORT_E), 14217db8736dSVille Syrjälä DP_TP_CTL_FDI_AUTOTRAIN | 14227db8736dSVille Syrjälä DP_TP_CTL_LINK_TRAIN_NORMAL | 14237db8736dSVille Syrjälä DP_TP_CTL_ENHANCED_FRAME_ENABLE | 14247db8736dSVille Syrjälä DP_TP_CTL_ENABLE); 1425379bc100SJani Nikula } 1426379bc100SJani Nikula 1427379bc100SJani Nikula static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder) 1428379bc100SJani Nikula { 1429b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 14307801f3b7SLucas De Marchi struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 1431379bc100SJani Nikula 14327801f3b7SLucas De Marchi intel_dp->DP = dig_port->saved_port_bits | 1433379bc100SJani Nikula DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0); 1434379bc100SJani Nikula intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count); 1435379bc100SJani Nikula } 1436379bc100SJani Nikula 1437379bc100SJani Nikula static int icl_calc_tbt_pll_link(struct drm_i915_private *dev_priv, 1438379bc100SJani Nikula enum port port) 1439379bc100SJani Nikula { 1440f7960e7fSJani Nikula u32 val = intel_de_read(dev_priv, DDI_CLK_SEL(port)) & DDI_CLK_SEL_MASK; 1441379bc100SJani Nikula 1442379bc100SJani Nikula switch (val) { 1443379bc100SJani Nikula case DDI_CLK_SEL_NONE: 1444379bc100SJani Nikula return 0; 1445379bc100SJani Nikula case DDI_CLK_SEL_TBT_162: 1446379bc100SJani Nikula return 162000; 1447379bc100SJani Nikula case DDI_CLK_SEL_TBT_270: 1448379bc100SJani Nikula return 270000; 1449379bc100SJani Nikula case DDI_CLK_SEL_TBT_540: 1450379bc100SJani Nikula return 540000; 1451379bc100SJani Nikula case DDI_CLK_SEL_TBT_810: 1452379bc100SJani Nikula return 810000; 1453379bc100SJani Nikula default: 1454379bc100SJani Nikula MISSING_CASE(val); 1455379bc100SJani Nikula return 0; 1456379bc100SJani Nikula } 1457379bc100SJani Nikula } 1458379bc100SJani Nikula 1459379bc100SJani Nikula static void ddi_dotclock_get(struct intel_crtc_state *pipe_config) 1460379bc100SJani Nikula { 1461379bc100SJani Nikula int dotclock; 1462379bc100SJani Nikula 1463379bc100SJani Nikula if (pipe_config->has_pch_encoder) 1464379bc100SJani Nikula dotclock = intel_dotclock_calculate(pipe_config->port_clock, 1465379bc100SJani Nikula &pipe_config->fdi_m_n); 1466379bc100SJani Nikula else if (intel_crtc_has_dp_encoder(pipe_config)) 1467379bc100SJani Nikula dotclock = intel_dotclock_calculate(pipe_config->port_clock, 1468379bc100SJani Nikula &pipe_config->dp_m_n); 14692969a78aSImre Deak else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp > 24) 14702969a78aSImre Deak dotclock = pipe_config->port_clock * 24 / pipe_config->pipe_bpp; 1471379bc100SJani Nikula else 1472379bc100SJani Nikula dotclock = pipe_config->port_clock; 1473379bc100SJani Nikula 1474379bc100SJani Nikula if (pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 && 1475379bc100SJani Nikula !intel_crtc_has_dp_encoder(pipe_config)) 1476379bc100SJani Nikula dotclock *= 2; 1477379bc100SJani Nikula 1478379bc100SJani Nikula if (pipe_config->pixel_multiplier) 1479379bc100SJani Nikula dotclock /= pipe_config->pixel_multiplier; 1480379bc100SJani Nikula 14811326a92cSMaarten Lankhorst pipe_config->hw.adjusted_mode.crtc_clock = dotclock; 1482379bc100SJani Nikula } 1483379bc100SJani Nikula 1484379bc100SJani Nikula static void intel_ddi_clock_get(struct intel_encoder *encoder, 1485379bc100SJani Nikula struct intel_crtc_state *pipe_config) 1486379bc100SJani Nikula { 1487379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 148856ed441aSMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 1489379bc100SJani Nikula 149056ed441aSMatt Roper if (intel_phy_is_tc(dev_priv, phy) && 149145e4728bSImre Deak intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll) == 149245e4728bSImre Deak DPLL_ID_ICL_TBTPLL) 149345e4728bSImre Deak pipe_config->port_clock = icl_calc_tbt_pll_link(dev_priv, 149445e4728bSImre Deak encoder->port); 149545e4728bSImre Deak else 1496b953eb21SImre Deak pipe_config->port_clock = 1497b953eb21SImre Deak intel_dpll_get_freq(dev_priv, pipe_config->shared_dpll); 149845e4728bSImre Deak 149945e4728bSImre Deak ddi_dotclock_get(pipe_config); 1500379bc100SJani Nikula } 1501379bc100SJani Nikula 15020c06fa15SGwan-gyeong Mun void intel_ddi_set_dp_msa(const struct intel_crtc_state *crtc_state, 15030c06fa15SGwan-gyeong Mun const struct drm_connector_state *conn_state) 1504379bc100SJani Nikula { 15052225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1506379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1507379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1508379bc100SJani Nikula u32 temp; 1509379bc100SJani Nikula 1510379bc100SJani Nikula if (!intel_crtc_has_dp_encoder(crtc_state)) 1511379bc100SJani Nikula return; 1512379bc100SJani Nikula 15131de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder)); 1514379bc100SJani Nikula 15153e706dffSVille Syrjälä temp = DP_MSA_MISC_SYNC_CLOCK; 1516379bc100SJani Nikula 1517379bc100SJani Nikula switch (crtc_state->pipe_bpp) { 1518379bc100SJani Nikula case 18: 15193e706dffSVille Syrjälä temp |= DP_MSA_MISC_6_BPC; 1520379bc100SJani Nikula break; 1521379bc100SJani Nikula case 24: 15223e706dffSVille Syrjälä temp |= DP_MSA_MISC_8_BPC; 1523379bc100SJani Nikula break; 1524379bc100SJani Nikula case 30: 15253e706dffSVille Syrjälä temp |= DP_MSA_MISC_10_BPC; 1526379bc100SJani Nikula break; 1527379bc100SJani Nikula case 36: 15283e706dffSVille Syrjälä temp |= DP_MSA_MISC_12_BPC; 1529379bc100SJani Nikula break; 1530379bc100SJani Nikula default: 1531379bc100SJani Nikula MISSING_CASE(crtc_state->pipe_bpp); 1532379bc100SJani Nikula break; 1533379bc100SJani Nikula } 1534379bc100SJani Nikula 1535cae154fcSVille Syrjälä /* nonsense combination */ 15361de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, crtc_state->limited_color_range && 1537cae154fcSVille Syrjälä crtc_state->output_format != INTEL_OUTPUT_FORMAT_RGB); 1538cae154fcSVille Syrjälä 1539cae154fcSVille Syrjälä if (crtc_state->limited_color_range) 15403e706dffSVille Syrjälä temp |= DP_MSA_MISC_COLOR_CEA_RGB; 1541cae154fcSVille Syrjälä 1542379bc100SJani Nikula /* 1543379bc100SJani Nikula * As per DP 1.2 spec section 2.3.4.3 while sending 1544379bc100SJani Nikula * YCBCR 444 signals we should program MSA MISC1/0 fields with 1545646d3dc8SVille Syrjälä * colorspace information. 1546379bc100SJani Nikula */ 1547379bc100SJani Nikula if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) 15483e706dffSVille Syrjälä temp |= DP_MSA_MISC_COLOR_YCBCR_444_BT709; 1549646d3dc8SVille Syrjälä 1550379bc100SJani Nikula /* 1551379bc100SJani Nikula * As per DP 1.4a spec section 2.2.4.3 [MSA Field for Indication 1552379bc100SJani Nikula * of Color Encoding Format and Content Color Gamut] while sending 15530c06fa15SGwan-gyeong Mun * YCBCR 420, HDR BT.2020 signals we should program MSA MISC1 fields 15540c06fa15SGwan-gyeong Mun * which indicate VSC SDP for the Pixel Encoding/Colorimetry Format. 1555379bc100SJani Nikula */ 1556bd8c9ccaSGwan-gyeong Mun if (intel_dp_needs_vsc_sdp(crtc_state, conn_state)) 15573e706dffSVille Syrjälä temp |= DP_MSA_MISC_COLOR_VSC_SDP; 15580c06fa15SGwan-gyeong Mun 1559f7960e7fSJani Nikula intel_de_write(dev_priv, TRANS_MSA_MISC(cpu_transcoder), temp); 1560379bc100SJani Nikula } 1561379bc100SJani Nikula 1562dc5b8ed5SVille Syrjälä static u32 bdw_trans_port_sync_master_select(enum transcoder master_transcoder) 1563dc5b8ed5SVille Syrjälä { 1564dc5b8ed5SVille Syrjälä if (master_transcoder == TRANSCODER_EDP) 1565dc5b8ed5SVille Syrjälä return 0; 1566dc5b8ed5SVille Syrjälä else 1567dc5b8ed5SVille Syrjälä return master_transcoder + 1; 1568dc5b8ed5SVille Syrjälä } 1569dc5b8ed5SVille Syrjälä 157099389390SJosé Roberto de Souza /* 157199389390SJosé Roberto de Souza * Returns the TRANS_DDI_FUNC_CTL value based on CRTC state. 157299389390SJosé Roberto de Souza * 157399389390SJosé Roberto de Souza * Only intended to be used by intel_ddi_enable_transcoder_func() and 157499389390SJosé Roberto de Souza * intel_ddi_config_transcoder_func(). 157599389390SJosé Roberto de Souza */ 157699389390SJosé Roberto de Souza static u32 1577eed22a46SVille Syrjälä intel_ddi_transcoder_func_reg_val_get(struct intel_encoder *encoder, 1578eed22a46SVille Syrjälä const struct intel_crtc_state *crtc_state) 1579379bc100SJani Nikula { 15802225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1581379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1582379bc100SJani Nikula enum pipe pipe = crtc->pipe; 1583379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1584379bc100SJani Nikula enum port port = encoder->port; 1585379bc100SJani Nikula u32 temp; 1586379bc100SJani Nikula 1587379bc100SJani Nikula /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */ 1588379bc100SJani Nikula temp = TRANS_DDI_FUNC_ENABLE; 1589df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) 1590df16b636SMahesh Kumar temp |= TGL_TRANS_DDI_SELECT_PORT(port); 1591df16b636SMahesh Kumar else 1592379bc100SJani Nikula temp |= TRANS_DDI_SELECT_PORT(port); 1593379bc100SJani Nikula 1594379bc100SJani Nikula switch (crtc_state->pipe_bpp) { 1595379bc100SJani Nikula case 18: 1596379bc100SJani Nikula temp |= TRANS_DDI_BPC_6; 1597379bc100SJani Nikula break; 1598379bc100SJani Nikula case 24: 1599379bc100SJani Nikula temp |= TRANS_DDI_BPC_8; 1600379bc100SJani Nikula break; 1601379bc100SJani Nikula case 30: 1602379bc100SJani Nikula temp |= TRANS_DDI_BPC_10; 1603379bc100SJani Nikula break; 1604379bc100SJani Nikula case 36: 1605379bc100SJani Nikula temp |= TRANS_DDI_BPC_12; 1606379bc100SJani Nikula break; 1607379bc100SJani Nikula default: 1608379bc100SJani Nikula BUG(); 1609379bc100SJani Nikula } 1610379bc100SJani Nikula 16111326a92cSMaarten Lankhorst if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC) 1612379bc100SJani Nikula temp |= TRANS_DDI_PVSYNC; 16131326a92cSMaarten Lankhorst if (crtc_state->hw.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC) 1614379bc100SJani Nikula temp |= TRANS_DDI_PHSYNC; 1615379bc100SJani Nikula 1616379bc100SJani Nikula if (cpu_transcoder == TRANSCODER_EDP) { 1617379bc100SJani Nikula switch (pipe) { 1618379bc100SJani Nikula case PIPE_A: 1619379bc100SJani Nikula /* On Haswell, can only use the always-on power well for 1620379bc100SJani Nikula * eDP when not using the panel fitter, and when not 1621379bc100SJani Nikula * using motion blur mitigation (which we don't 1622379bc100SJani Nikula * support). */ 1623379bc100SJani Nikula if (crtc_state->pch_pfit.force_thru) 1624379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_A_ONOFF; 1625379bc100SJani Nikula else 1626379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_A_ON; 1627379bc100SJani Nikula break; 1628379bc100SJani Nikula case PIPE_B: 1629379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_B_ONOFF; 1630379bc100SJani Nikula break; 1631379bc100SJani Nikula case PIPE_C: 1632379bc100SJani Nikula temp |= TRANS_DDI_EDP_INPUT_C_ONOFF; 1633379bc100SJani Nikula break; 1634379bc100SJani Nikula default: 1635379bc100SJani Nikula BUG(); 1636379bc100SJani Nikula break; 1637379bc100SJani Nikula } 1638379bc100SJani Nikula } 1639379bc100SJani Nikula 1640379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 1641379bc100SJani Nikula if (crtc_state->has_hdmi_sink) 1642379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_HDMI; 1643379bc100SJani Nikula else 1644379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_DVI; 1645379bc100SJani Nikula 1646379bc100SJani Nikula if (crtc_state->hdmi_scrambling) 1647379bc100SJani Nikula temp |= TRANS_DDI_HDMI_SCRAMBLING; 1648379bc100SJani Nikula if (crtc_state->hdmi_high_tmds_clock_ratio) 1649379bc100SJani Nikula temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE; 1650379bc100SJani Nikula } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { 1651379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_FDI; 1652379bc100SJani Nikula temp |= (crtc_state->fdi_lanes - 1) << 1; 1653379bc100SJani Nikula } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) { 1654379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_DP_MST; 1655379bc100SJani Nikula temp |= DDI_PORT_WIDTH(crtc_state->lane_count); 1656b3545e08SLucas De Marchi 16576671c367SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 16586671c367SJosé Roberto de Souza enum transcoder master; 16596671c367SJosé Roberto de Souza 16606671c367SJosé Roberto de Souza master = crtc_state->mst_master_transcoder; 16611de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 16621de143ccSPankaj Bharadiya master == INVALID_TRANSCODER); 16636671c367SJosé Roberto de Souza temp |= TRANS_DDI_MST_TRANSPORT_SELECT(master); 16646671c367SJosé Roberto de Souza } 1665379bc100SJani Nikula } else { 1666379bc100SJani Nikula temp |= TRANS_DDI_MODE_SELECT_DP_SST; 1667379bc100SJani Nikula temp |= DDI_PORT_WIDTH(crtc_state->lane_count); 1668379bc100SJani Nikula } 1669379bc100SJani Nikula 1670dc5b8ed5SVille Syrjälä if (IS_GEN_RANGE(dev_priv, 8, 10) && 1671dc5b8ed5SVille Syrjälä crtc_state->master_transcoder != INVALID_TRANSCODER) { 1672dc5b8ed5SVille Syrjälä u8 master_select = 1673dc5b8ed5SVille Syrjälä bdw_trans_port_sync_master_select(crtc_state->master_transcoder); 1674dc5b8ed5SVille Syrjälä 1675dc5b8ed5SVille Syrjälä temp |= TRANS_DDI_PORT_SYNC_ENABLE | 1676dc5b8ed5SVille Syrjälä TRANS_DDI_PORT_SYNC_MASTER_SELECT(master_select); 1677dc5b8ed5SVille Syrjälä } 1678dc5b8ed5SVille Syrjälä 167999389390SJosé Roberto de Souza return temp; 168099389390SJosé Roberto de Souza } 168199389390SJosé Roberto de Souza 1682eed22a46SVille Syrjälä void intel_ddi_enable_transcoder_func(struct intel_encoder *encoder, 1683eed22a46SVille Syrjälä const struct intel_crtc_state *crtc_state) 168499389390SJosé Roberto de Souza { 16852225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 168699389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 168799389390SJosé Roberto de Souza enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 168899389390SJosé Roberto de Souza 1689589a4cd6SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) { 1690589a4cd6SVille Syrjälä enum transcoder master_transcoder = crtc_state->master_transcoder; 1691589a4cd6SVille Syrjälä u32 ctl2 = 0; 1692589a4cd6SVille Syrjälä 1693589a4cd6SVille Syrjälä if (master_transcoder != INVALID_TRANSCODER) { 1694dc5b8ed5SVille Syrjälä u8 master_select = 1695dc5b8ed5SVille Syrjälä bdw_trans_port_sync_master_select(master_transcoder); 1696589a4cd6SVille Syrjälä 1697589a4cd6SVille Syrjälä ctl2 |= PORT_SYNC_MODE_ENABLE | 1698d4d7d9caSVille Syrjälä PORT_SYNC_MODE_MASTER_SELECT(master_select); 1699589a4cd6SVille Syrjälä } 1700589a4cd6SVille Syrjälä 1701589a4cd6SVille Syrjälä intel_de_write(dev_priv, 1702589a4cd6SVille Syrjälä TRANS_DDI_FUNC_CTL2(cpu_transcoder), ctl2); 1703589a4cd6SVille Syrjälä } 1704589a4cd6SVille Syrjälä 1705580fbdc5SImre Deak intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), 1706580fbdc5SImre Deak intel_ddi_transcoder_func_reg_val_get(encoder, 1707580fbdc5SImre Deak crtc_state)); 170899389390SJosé Roberto de Souza } 170999389390SJosé Roberto de Souza 171099389390SJosé Roberto de Souza /* 171199389390SJosé Roberto de Souza * Same as intel_ddi_enable_transcoder_func(), but it does not set the enable 171299389390SJosé Roberto de Souza * bit. 171399389390SJosé Roberto de Souza */ 171499389390SJosé Roberto de Souza static void 1715eed22a46SVille Syrjälä intel_ddi_config_transcoder_func(struct intel_encoder *encoder, 1716eed22a46SVille Syrjälä const struct intel_crtc_state *crtc_state) 171799389390SJosé Roberto de Souza { 17182225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 171999389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 172099389390SJosé Roberto de Souza enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1721589a4cd6SVille Syrjälä u32 ctl; 172299389390SJosé Roberto de Souza 1723eed22a46SVille Syrjälä ctl = intel_ddi_transcoder_func_reg_val_get(encoder, crtc_state); 1724589a4cd6SVille Syrjälä ctl &= ~TRANS_DDI_FUNC_ENABLE; 1725589a4cd6SVille Syrjälä intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl); 1726379bc100SJani Nikula } 1727379bc100SJani Nikula 1728379bc100SJani Nikula void intel_ddi_disable_transcoder_func(const struct intel_crtc_state *crtc_state) 1729379bc100SJani Nikula { 17302225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 1731379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 1732379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 1733589a4cd6SVille Syrjälä u32 ctl; 1734c59053dcSJosé Roberto de Souza 1735589a4cd6SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) 1736589a4cd6SVille Syrjälä intel_de_write(dev_priv, 1737589a4cd6SVille Syrjälä TRANS_DDI_FUNC_CTL2(cpu_transcoder), 0); 1738589a4cd6SVille Syrjälä 1739589a4cd6SVille Syrjälä ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 1740dc5b8ed5SVille Syrjälä 1741589a4cd6SVille Syrjälä ctl &= ~TRANS_DDI_FUNC_ENABLE; 1742379bc100SJani Nikula 1743dc5b8ed5SVille Syrjälä if (IS_GEN_RANGE(dev_priv, 8, 10)) 1744dc5b8ed5SVille Syrjälä ctl &= ~(TRANS_DDI_PORT_SYNC_ENABLE | 1745dc5b8ed5SVille Syrjälä TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK); 1746dc5b8ed5SVille Syrjälä 1747df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) { 1748919e4f07SJosé Roberto de Souza if (!intel_dp_mst_is_master_trans(crtc_state)) { 1749589a4cd6SVille Syrjälä ctl &= ~(TGL_TRANS_DDI_PORT_MASK | 1750919e4f07SJosé Roberto de Souza TRANS_DDI_MODE_SELECT_MASK); 1751919e4f07SJosé Roberto de Souza } 1752df16b636SMahesh Kumar } else { 1753589a4cd6SVille Syrjälä ctl &= ~(TRANS_DDI_PORT_MASK | TRANS_DDI_MODE_SELECT_MASK); 1754df16b636SMahesh Kumar } 1755dc5b8ed5SVille Syrjälä 1756589a4cd6SVille Syrjälä intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder), ctl); 1757379bc100SJani Nikula 1758379bc100SJani Nikula if (dev_priv->quirks & QUIRK_INCREASE_DDI_DISABLED_TIME && 1759379bc100SJani Nikula intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 176047bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 176147bdb1caSJani Nikula "Quirk Increase DDI disabled time\n"); 1762379bc100SJani Nikula /* Quirk time at 100ms for reliable operation */ 1763379bc100SJani Nikula msleep(100); 1764379bc100SJani Nikula } 1765379bc100SJani Nikula } 1766379bc100SJani Nikula 1767379bc100SJani Nikula int intel_ddi_toggle_hdcp_signalling(struct intel_encoder *intel_encoder, 1768379bc100SJani Nikula bool enable) 1769379bc100SJani Nikula { 1770379bc100SJani Nikula struct drm_device *dev = intel_encoder->base.dev; 1771379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1772379bc100SJani Nikula intel_wakeref_t wakeref; 1773379bc100SJani Nikula enum pipe pipe = 0; 1774379bc100SJani Nikula int ret = 0; 1775379bc100SJani Nikula u32 tmp; 1776379bc100SJani Nikula 1777379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1778379bc100SJani Nikula intel_encoder->power_domain); 17791de143ccSPankaj Bharadiya if (drm_WARN_ON(dev, !wakeref)) 1780379bc100SJani Nikula return -ENXIO; 1781379bc100SJani Nikula 17821de143ccSPankaj Bharadiya if (drm_WARN_ON(dev, 17831de143ccSPankaj Bharadiya !intel_encoder->get_hw_state(intel_encoder, &pipe))) { 1784379bc100SJani Nikula ret = -EIO; 1785379bc100SJani Nikula goto out; 1786379bc100SJani Nikula } 1787379bc100SJani Nikula 1788f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(pipe)); 1789379bc100SJani Nikula if (enable) 1790379bc100SJani Nikula tmp |= TRANS_DDI_HDCP_SIGNALLING; 1791379bc100SJani Nikula else 1792379bc100SJani Nikula tmp &= ~TRANS_DDI_HDCP_SIGNALLING; 1793f7960e7fSJani Nikula intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(pipe), tmp); 1794379bc100SJani Nikula out: 1795379bc100SJani Nikula intel_display_power_put(dev_priv, intel_encoder->power_domain, wakeref); 1796379bc100SJani Nikula return ret; 1797379bc100SJani Nikula } 1798379bc100SJani Nikula 1799379bc100SJani Nikula bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector) 1800379bc100SJani Nikula { 1801379bc100SJani Nikula struct drm_device *dev = intel_connector->base.dev; 1802379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1803fa7edcd2SVille Syrjälä struct intel_encoder *encoder = intel_attached_encoder(intel_connector); 1804379bc100SJani Nikula int type = intel_connector->base.connector_type; 1805379bc100SJani Nikula enum port port = encoder->port; 1806379bc100SJani Nikula enum transcoder cpu_transcoder; 1807379bc100SJani Nikula intel_wakeref_t wakeref; 1808379bc100SJani Nikula enum pipe pipe = 0; 1809379bc100SJani Nikula u32 tmp; 1810379bc100SJani Nikula bool ret; 1811379bc100SJani Nikula 1812379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1813379bc100SJani Nikula encoder->power_domain); 1814379bc100SJani Nikula if (!wakeref) 1815379bc100SJani Nikula return false; 1816379bc100SJani Nikula 1817379bc100SJani Nikula if (!encoder->get_hw_state(encoder, &pipe)) { 1818379bc100SJani Nikula ret = false; 1819379bc100SJani Nikula goto out; 1820379bc100SJani Nikula } 1821379bc100SJani Nikula 182210cf8e75SVille Syrjälä if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) 1823379bc100SJani Nikula cpu_transcoder = TRANSCODER_EDP; 1824379bc100SJani Nikula else 1825379bc100SJani Nikula cpu_transcoder = (enum transcoder) pipe; 1826379bc100SJani Nikula 1827f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 1828379bc100SJani Nikula 1829379bc100SJani Nikula switch (tmp & TRANS_DDI_MODE_SELECT_MASK) { 1830379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_HDMI: 1831379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DVI: 1832379bc100SJani Nikula ret = type == DRM_MODE_CONNECTOR_HDMIA; 1833379bc100SJani Nikula break; 1834379bc100SJani Nikula 1835379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_SST: 1836379bc100SJani Nikula ret = type == DRM_MODE_CONNECTOR_eDP || 1837379bc100SJani Nikula type == DRM_MODE_CONNECTOR_DisplayPort; 1838379bc100SJani Nikula break; 1839379bc100SJani Nikula 1840379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_MST: 1841379bc100SJani Nikula /* if the transcoder is in MST state then 1842379bc100SJani Nikula * connector isn't connected */ 1843379bc100SJani Nikula ret = false; 1844379bc100SJani Nikula break; 1845379bc100SJani Nikula 1846379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_FDI: 1847379bc100SJani Nikula ret = type == DRM_MODE_CONNECTOR_VGA; 1848379bc100SJani Nikula break; 1849379bc100SJani Nikula 1850379bc100SJani Nikula default: 1851379bc100SJani Nikula ret = false; 1852379bc100SJani Nikula break; 1853379bc100SJani Nikula } 1854379bc100SJani Nikula 1855379bc100SJani Nikula out: 1856379bc100SJani Nikula intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 1857379bc100SJani Nikula 1858379bc100SJani Nikula return ret; 1859379bc100SJani Nikula } 1860379bc100SJani Nikula 1861379bc100SJani Nikula static void intel_ddi_get_encoder_pipes(struct intel_encoder *encoder, 1862379bc100SJani Nikula u8 *pipe_mask, bool *is_dp_mst) 1863379bc100SJani Nikula { 1864379bc100SJani Nikula struct drm_device *dev = encoder->base.dev; 1865379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(dev); 1866379bc100SJani Nikula enum port port = encoder->port; 1867379bc100SJani Nikula intel_wakeref_t wakeref; 1868379bc100SJani Nikula enum pipe p; 1869379bc100SJani Nikula u32 tmp; 1870379bc100SJani Nikula u8 mst_pipe_mask; 1871379bc100SJani Nikula 1872379bc100SJani Nikula *pipe_mask = 0; 1873379bc100SJani Nikula *is_dp_mst = false; 1874379bc100SJani Nikula 1875379bc100SJani Nikula wakeref = intel_display_power_get_if_enabled(dev_priv, 1876379bc100SJani Nikula encoder->power_domain); 1877379bc100SJani Nikula if (!wakeref) 1878379bc100SJani Nikula return; 1879379bc100SJani Nikula 1880f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 1881379bc100SJani Nikula if (!(tmp & DDI_BUF_CTL_ENABLE)) 1882379bc100SJani Nikula goto out; 1883379bc100SJani Nikula 188410cf8e75SVille Syrjälä if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) { 1885f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, 1886f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); 1887379bc100SJani Nikula 1888379bc100SJani Nikula switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { 1889379bc100SJani Nikula default: 1890379bc100SJani Nikula MISSING_CASE(tmp & TRANS_DDI_EDP_INPUT_MASK); 1891379bc100SJani Nikula /* fallthrough */ 1892379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_A_ON: 1893379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_A_ONOFF: 1894379bc100SJani Nikula *pipe_mask = BIT(PIPE_A); 1895379bc100SJani Nikula break; 1896379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_B_ONOFF: 1897379bc100SJani Nikula *pipe_mask = BIT(PIPE_B); 1898379bc100SJani Nikula break; 1899379bc100SJani Nikula case TRANS_DDI_EDP_INPUT_C_ONOFF: 1900379bc100SJani Nikula *pipe_mask = BIT(PIPE_C); 1901379bc100SJani Nikula break; 1902379bc100SJani Nikula } 1903379bc100SJani Nikula 1904379bc100SJani Nikula goto out; 1905379bc100SJani Nikula } 1906379bc100SJani Nikula 1907379bc100SJani Nikula mst_pipe_mask = 0; 1908379bc100SJani Nikula for_each_pipe(dev_priv, p) { 1909379bc100SJani Nikula enum transcoder cpu_transcoder = (enum transcoder)p; 1910df16b636SMahesh Kumar unsigned int port_mask, ddi_select; 19116aa3bef1SJosé Roberto de Souza intel_wakeref_t trans_wakeref; 19126aa3bef1SJosé Roberto de Souza 19136aa3bef1SJosé Roberto de Souza trans_wakeref = intel_display_power_get_if_enabled(dev_priv, 19146aa3bef1SJosé Roberto de Souza POWER_DOMAIN_TRANSCODER(cpu_transcoder)); 19156aa3bef1SJosé Roberto de Souza if (!trans_wakeref) 19166aa3bef1SJosé Roberto de Souza continue; 1917df16b636SMahesh Kumar 1918df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) { 1919df16b636SMahesh Kumar port_mask = TGL_TRANS_DDI_PORT_MASK; 1920df16b636SMahesh Kumar ddi_select = TGL_TRANS_DDI_SELECT_PORT(port); 1921df16b636SMahesh Kumar } else { 1922df16b636SMahesh Kumar port_mask = TRANS_DDI_PORT_MASK; 1923df16b636SMahesh Kumar ddi_select = TRANS_DDI_SELECT_PORT(port); 1924df16b636SMahesh Kumar } 1925379bc100SJani Nikula 1926f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, 1927f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(cpu_transcoder)); 19286aa3bef1SJosé Roberto de Souza intel_display_power_put(dev_priv, POWER_DOMAIN_TRANSCODER(cpu_transcoder), 19296aa3bef1SJosé Roberto de Souza trans_wakeref); 1930379bc100SJani Nikula 1931df16b636SMahesh Kumar if ((tmp & port_mask) != ddi_select) 1932379bc100SJani Nikula continue; 1933379bc100SJani Nikula 1934379bc100SJani Nikula if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == 1935379bc100SJani Nikula TRANS_DDI_MODE_SELECT_DP_MST) 1936379bc100SJani Nikula mst_pipe_mask |= BIT(p); 1937379bc100SJani Nikula 1938379bc100SJani Nikula *pipe_mask |= BIT(p); 1939379bc100SJani Nikula } 1940379bc100SJani Nikula 1941379bc100SJani Nikula if (!*pipe_mask) 194247bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 194347bdb1caSJani Nikula "No pipe for [ENCODER:%d:%s] found\n", 194466a990ddSVille Syrjälä encoder->base.base.id, encoder->base.name); 1945379bc100SJani Nikula 1946379bc100SJani Nikula if (!mst_pipe_mask && hweight8(*pipe_mask) > 1) { 194747bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 194847bdb1caSJani Nikula "Multiple pipes for [ENCODER:%d:%s] (pipe_mask %02x)\n", 194966a990ddSVille Syrjälä encoder->base.base.id, encoder->base.name, 195066a990ddSVille Syrjälä *pipe_mask); 1951379bc100SJani Nikula *pipe_mask = BIT(ffs(*pipe_mask) - 1); 1952379bc100SJani Nikula } 1953379bc100SJani Nikula 1954379bc100SJani Nikula if (mst_pipe_mask && mst_pipe_mask != *pipe_mask) 195547bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 195647bdb1caSJani Nikula "Conflicting MST and non-MST state for [ENCODER:%d:%s] (pipe_mask %02x mst_pipe_mask %02x)\n", 195766a990ddSVille Syrjälä encoder->base.base.id, encoder->base.name, 195866a990ddSVille Syrjälä *pipe_mask, mst_pipe_mask); 1959379bc100SJani Nikula else 1960379bc100SJani Nikula *is_dp_mst = mst_pipe_mask; 1961379bc100SJani Nikula 1962379bc100SJani Nikula out: 1963379bc100SJani Nikula if (*pipe_mask && IS_GEN9_LP(dev_priv)) { 1964f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, BXT_PHY_CTL(port)); 1965379bc100SJani Nikula if ((tmp & (BXT_PHY_CMNLANE_POWERDOWN_ACK | 1966379bc100SJani Nikula BXT_PHY_LANE_POWERDOWN_ACK | 1967379bc100SJani Nikula BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED) 196847bdb1caSJani Nikula drm_err(&dev_priv->drm, 196947bdb1caSJani Nikula "[ENCODER:%d:%s] enabled but PHY powered down? (PHY_CTL %08x)\n", 197047bdb1caSJani Nikula encoder->base.base.id, encoder->base.name, tmp); 1971379bc100SJani Nikula } 1972379bc100SJani Nikula 1973379bc100SJani Nikula intel_display_power_put(dev_priv, encoder->power_domain, wakeref); 1974379bc100SJani Nikula } 1975379bc100SJani Nikula 1976379bc100SJani Nikula bool intel_ddi_get_hw_state(struct intel_encoder *encoder, 1977379bc100SJani Nikula enum pipe *pipe) 1978379bc100SJani Nikula { 1979379bc100SJani Nikula u8 pipe_mask; 1980379bc100SJani Nikula bool is_mst; 1981379bc100SJani Nikula 1982379bc100SJani Nikula intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst); 1983379bc100SJani Nikula 1984379bc100SJani Nikula if (is_mst || !pipe_mask) 1985379bc100SJani Nikula return false; 1986379bc100SJani Nikula 1987379bc100SJani Nikula *pipe = ffs(pipe_mask) - 1; 1988379bc100SJani Nikula 1989379bc100SJani Nikula return true; 1990379bc100SJani Nikula } 1991379bc100SJani Nikula 199281b55ef1SJani Nikula static enum intel_display_power_domain 1993379bc100SJani Nikula intel_ddi_main_link_aux_domain(struct intel_digital_port *dig_port) 1994379bc100SJani Nikula { 1995379bc100SJani Nikula /* CNL+ HW requires corresponding AUX IOs to be powered up for PSR with 1996379bc100SJani Nikula * DC states enabled at the same time, while for driver initiated AUX 1997379bc100SJani Nikula * transfers we need the same AUX IOs to be powered but with DC states 1998379bc100SJani Nikula * disabled. Accordingly use the AUX power domain here which leaves DC 1999379bc100SJani Nikula * states enabled. 2000379bc100SJani Nikula * However, for non-A AUX ports the corresponding non-EDP transcoders 2001379bc100SJani Nikula * would have already enabled power well 2 and DC_OFF. This means we can 2002379bc100SJani Nikula * acquire a wider POWER_DOMAIN_AUX_{B,C,D,F} reference instead of a 2003379bc100SJani Nikula * specific AUX_IO reference without powering up any extra wells. 2004379bc100SJani Nikula * Note that PSR is enabled only on Port A even though this function 2005379bc100SJani Nikula * returns the correct domain for other ports too. 2006379bc100SJani Nikula */ 2007379bc100SJani Nikula return dig_port->aux_ch == AUX_CH_A ? POWER_DOMAIN_AUX_IO_A : 2008379bc100SJani Nikula intel_aux_power_domain(dig_port); 2009379bc100SJani Nikula } 2010379bc100SJani Nikula 2011379bc100SJani Nikula static void intel_ddi_get_power_domains(struct intel_encoder *encoder, 2012379bc100SJani Nikula struct intel_crtc_state *crtc_state) 2013379bc100SJani Nikula { 2014379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2015379bc100SJani Nikula struct intel_digital_port *dig_port; 2016d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2017379bc100SJani Nikula 2018379bc100SJani Nikula /* 2019379bc100SJani Nikula * TODO: Add support for MST encoders. Atm, the following should never 2020379bc100SJani Nikula * happen since fake-MST encoders don't set their get_power_domains() 2021379bc100SJani Nikula * hook. 2022379bc100SJani Nikula */ 20231de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, 20241de143ccSPankaj Bharadiya intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST))) 2025379bc100SJani Nikula return; 2026379bc100SJani Nikula 2027b7d02c3aSVille Syrjälä dig_port = enc_to_dig_port(encoder); 2028f77a2db2SImre Deak 2029f77a2db2SImre Deak if (!intel_phy_is_tc(dev_priv, phy) || 2030f77a2db2SImre Deak dig_port->tc_mode != TC_PORT_TBT_ALT) 2031f77a2db2SImre Deak intel_display_power_get(dev_priv, 2032f77a2db2SImre Deak dig_port->ddi_io_power_domain); 2033379bc100SJani Nikula 2034379bc100SJani Nikula /* 2035379bc100SJani Nikula * AUX power is only needed for (e)DP mode, and for HDMI mode on TC 2036379bc100SJani Nikula * ports. 2037379bc100SJani Nikula */ 2038379bc100SJani Nikula if (intel_crtc_has_dp_encoder(crtc_state) || 2039d8fe2ab6SMatt Roper intel_phy_is_tc(dev_priv, phy)) 2040379bc100SJani Nikula intel_display_power_get(dev_priv, 2041379bc100SJani Nikula intel_ddi_main_link_aux_domain(dig_port)); 2042379bc100SJani Nikula 2043379bc100SJani Nikula /* 2044379bc100SJani Nikula * VDSC power is needed when DSC is enabled 2045379bc100SJani Nikula */ 2046010663a6SJani Nikula if (crtc_state->dsc.compression_enable) 2047379bc100SJani Nikula intel_display_power_get(dev_priv, 2048379bc100SJani Nikula intel_dsc_power_domain(crtc_state)); 2049379bc100SJani Nikula } 2050379bc100SJani Nikula 205102a715c3SVille Syrjälä void intel_ddi_enable_pipe_clock(struct intel_encoder *encoder, 205202a715c3SVille Syrjälä const struct intel_crtc_state *crtc_state) 2053379bc100SJani Nikula { 20542225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 2055379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 2056379bc100SJani Nikula enum port port = encoder->port; 2057379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2058379bc100SJani Nikula 2059df16b636SMahesh Kumar if (cpu_transcoder != TRANSCODER_EDP) { 2060df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) 2061f7960e7fSJani Nikula intel_de_write(dev_priv, 2062f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2063df16b636SMahesh Kumar TGL_TRANS_CLK_SEL_PORT(port)); 2064df16b636SMahesh Kumar else 2065f7960e7fSJani Nikula intel_de_write(dev_priv, 2066f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2067379bc100SJani Nikula TRANS_CLK_SEL_PORT(port)); 2068379bc100SJani Nikula } 2069df16b636SMahesh Kumar } 2070379bc100SJani Nikula 2071379bc100SJani Nikula void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state) 2072379bc100SJani Nikula { 20732225f3c6SMaarten Lankhorst struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 2074379bc100SJani Nikula enum transcoder cpu_transcoder = crtc_state->cpu_transcoder; 2075379bc100SJani Nikula 2076df16b636SMahesh Kumar if (cpu_transcoder != TRANSCODER_EDP) { 2077df16b636SMahesh Kumar if (INTEL_GEN(dev_priv) >= 12) 2078f7960e7fSJani Nikula intel_de_write(dev_priv, 2079f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2080df16b636SMahesh Kumar TGL_TRANS_CLK_SEL_DISABLED); 2081df16b636SMahesh Kumar else 2082f7960e7fSJani Nikula intel_de_write(dev_priv, 2083f7960e7fSJani Nikula TRANS_CLK_SEL(cpu_transcoder), 2084379bc100SJani Nikula TRANS_CLK_SEL_DISABLED); 2085379bc100SJani Nikula } 2086df16b636SMahesh Kumar } 2087379bc100SJani Nikula 2088379bc100SJani Nikula static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv, 2089379bc100SJani Nikula enum port port, u8 iboost) 2090379bc100SJani Nikula { 2091379bc100SJani Nikula u32 tmp; 2092379bc100SJani Nikula 2093f7960e7fSJani Nikula tmp = intel_de_read(dev_priv, DISPIO_CR_TX_BMU_CR0); 2094379bc100SJani Nikula tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port)); 2095379bc100SJani Nikula if (iboost) 2096379bc100SJani Nikula tmp |= iboost << BALANCE_LEG_SHIFT(port); 2097379bc100SJani Nikula else 2098379bc100SJani Nikula tmp |= BALANCE_LEG_DISABLE(port); 2099f7960e7fSJani Nikula intel_de_write(dev_priv, DISPIO_CR_TX_BMU_CR0, tmp); 2100379bc100SJani Nikula } 2101379bc100SJani Nikula 2102379bc100SJani Nikula static void skl_ddi_set_iboost(struct intel_encoder *encoder, 2103379bc100SJani Nikula int level, enum intel_output_type type) 2104379bc100SJani Nikula { 21057801f3b7SLucas De Marchi struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 2106379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2107379bc100SJani Nikula u8 iboost; 2108379bc100SJani Nikula 2109379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 211001a60883SJani Nikula iboost = intel_bios_hdmi_boost_level(encoder); 2111379bc100SJani Nikula else 2112605a1872SJani Nikula iboost = intel_bios_dp_boost_level(encoder); 2113379bc100SJani Nikula 2114379bc100SJani Nikula if (iboost == 0) { 2115379bc100SJani Nikula const struct ddi_buf_trans *ddi_translations; 2116379bc100SJani Nikula int n_entries; 2117379bc100SJani Nikula 2118379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2119a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_hdmi(encoder, &n_entries); 2120379bc100SJani Nikula else if (type == INTEL_OUTPUT_EDP) 2121a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_edp(encoder, 2122a8143150SJosé Roberto de Souza &n_entries); 2123379bc100SJani Nikula else 2124a8143150SJosé Roberto de Souza ddi_translations = intel_ddi_get_buf_trans_dp(encoder, 2125a8143150SJosé Roberto de Souza &n_entries); 2126379bc100SJani Nikula 21271de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 2128379bc100SJani Nikula return; 21291de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 2130379bc100SJani Nikula level = n_entries - 1; 2131379bc100SJani Nikula 2132379bc100SJani Nikula iboost = ddi_translations[level].i_boost; 2133379bc100SJani Nikula } 2134379bc100SJani Nikula 2135379bc100SJani Nikula /* Make sure that the requested I_boost is valid */ 2136379bc100SJani Nikula if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) { 213747bdb1caSJani Nikula drm_err(&dev_priv->drm, "Invalid I_boost value %u\n", iboost); 2138379bc100SJani Nikula return; 2139379bc100SJani Nikula } 2140379bc100SJani Nikula 2141*f0e86e05SJosé Roberto de Souza _skl_ddi_set_iboost(dev_priv, encoder->port, iboost); 2142379bc100SJani Nikula 2143*f0e86e05SJosé Roberto de Souza if (encoder->port == PORT_A && dig_port->max_lanes == 4) 2144379bc100SJani Nikula _skl_ddi_set_iboost(dev_priv, PORT_E, iboost); 2145379bc100SJani Nikula } 2146379bc100SJani Nikula 2147379bc100SJani Nikula static void bxt_ddi_vswing_sequence(struct intel_encoder *encoder, 2148379bc100SJani Nikula int level, enum intel_output_type type) 2149379bc100SJani Nikula { 2150379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2151379bc100SJani Nikula const struct bxt_ddi_buf_trans *ddi_translations; 2152379bc100SJani Nikula enum port port = encoder->port; 2153379bc100SJani Nikula int n_entries; 2154379bc100SJani Nikula 2155379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2156a8143150SJosé Roberto de Souza ddi_translations = bxt_get_buf_trans_hdmi(encoder, &n_entries); 2157379bc100SJani Nikula else if (type == INTEL_OUTPUT_EDP) 2158a8143150SJosé Roberto de Souza ddi_translations = bxt_get_buf_trans_edp(encoder, &n_entries); 2159379bc100SJani Nikula else 2160a8143150SJosé Roberto de Souza ddi_translations = bxt_get_buf_trans_dp(encoder, &n_entries); 2161379bc100SJani Nikula 21621de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 2163379bc100SJani Nikula return; 21641de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 2165379bc100SJani Nikula level = n_entries - 1; 2166379bc100SJani Nikula 2167379bc100SJani Nikula bxt_ddi_phy_set_signal_level(dev_priv, port, 2168379bc100SJani Nikula ddi_translations[level].margin, 2169379bc100SJani Nikula ddi_translations[level].scale, 2170379bc100SJani Nikula ddi_translations[level].enable, 2171379bc100SJani Nikula ddi_translations[level].deemphasis); 2172379bc100SJani Nikula } 2173379bc100SJani Nikula 217453de0a20SVille Syrjälä static u8 intel_ddi_dp_voltage_max(struct intel_dp *intel_dp) 2175379bc100SJani Nikula { 217653de0a20SVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2177379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2178379bc100SJani Nikula enum port port = encoder->port; 2179d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 2180379bc100SJani Nikula int n_entries; 2181379bc100SJani Nikula 2182978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 2183978c3e53SClinton A Taylor if (intel_phy_is_combo(dev_priv, phy)) 2184a8143150SJosé Roberto de Souza tgl_get_combo_buf_trans(encoder, encoder->type, 2185978c3e53SClinton A Taylor intel_dp->link_rate, &n_entries); 2186978c3e53SClinton A Taylor else 2187a8143150SJosé Roberto de Souza tgl_get_dkl_buf_trans(encoder, encoder->type, 21889fa67699SJosé Roberto de Souza intel_dp->link_rate, &n_entries); 2189978c3e53SClinton A Taylor } else if (INTEL_GEN(dev_priv) == 11) { 2190b42d5a67SJosé Roberto de Souza if (IS_ELKHARTLAKE(dev_priv)) 2191a8143150SJosé Roberto de Souza ehl_get_combo_buf_trans(encoder, encoder->type, 2192b42d5a67SJosé Roberto de Souza intel_dp->link_rate, &n_entries); 2193b42d5a67SJosé Roberto de Souza else if (intel_phy_is_combo(dev_priv, phy)) 2194a8143150SJosé Roberto de Souza icl_get_combo_buf_trans(encoder, encoder->type, 2195379bc100SJani Nikula intel_dp->link_rate, &n_entries); 2196379bc100SJani Nikula else 2197a8143150SJosé Roberto de Souza icl_get_mg_buf_trans(encoder, encoder->type, 21989f7ffa29SJosé Roberto de Souza intel_dp->link_rate, &n_entries); 2199379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 2200379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 2201a8143150SJosé Roberto de Souza cnl_get_buf_trans_edp(encoder, &n_entries); 2202379bc100SJani Nikula else 2203a8143150SJosé Roberto de Souza cnl_get_buf_trans_dp(encoder, &n_entries); 2204379bc100SJani Nikula } else if (IS_GEN9_LP(dev_priv)) { 2205379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 2206a8143150SJosé Roberto de Souza bxt_get_buf_trans_edp(encoder, &n_entries); 2207379bc100SJani Nikula else 2208a8143150SJosé Roberto de Souza bxt_get_buf_trans_dp(encoder, &n_entries); 2209379bc100SJani Nikula } else { 2210379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 2211*f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_edp(encoder, &n_entries); 2212379bc100SJani Nikula else 2213*f0e86e05SJosé Roberto de Souza intel_ddi_get_buf_trans_dp(encoder, &n_entries); 2214379bc100SJani Nikula } 2215379bc100SJani Nikula 22161de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, n_entries < 1)) 2217379bc100SJani Nikula n_entries = 1; 22181de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, 22191de143ccSPankaj Bharadiya n_entries > ARRAY_SIZE(index_to_dp_signal_levels))) 2220379bc100SJani Nikula n_entries = ARRAY_SIZE(index_to_dp_signal_levels); 2221379bc100SJani Nikula 2222379bc100SJani Nikula return index_to_dp_signal_levels[n_entries - 1] & 2223379bc100SJani Nikula DP_TRAIN_VOLTAGE_SWING_MASK; 2224379bc100SJani Nikula } 2225379bc100SJani Nikula 2226379bc100SJani Nikula /* 2227379bc100SJani Nikula * We assume that the full set of pre-emphasis values can be 2228379bc100SJani Nikula * used on all DDI platforms. Should that change we need to 2229379bc100SJani Nikula * rethink this code. 2230379bc100SJani Nikula */ 223153de0a20SVille Syrjälä static u8 intel_ddi_dp_preemph_max(struct intel_dp *intel_dp) 2232379bc100SJani Nikula { 2233379bc100SJani Nikula return DP_TRAIN_PRE_EMPH_LEVEL_3; 2234379bc100SJani Nikula } 2235379bc100SJani Nikula 2236379bc100SJani Nikula static void cnl_ddi_vswing_program(struct intel_encoder *encoder, 2237379bc100SJani Nikula int level, enum intel_output_type type) 2238379bc100SJani Nikula { 2239379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2240379bc100SJani Nikula const struct cnl_ddi_buf_trans *ddi_translations; 2241379bc100SJani Nikula enum port port = encoder->port; 2242379bc100SJani Nikula int n_entries, ln; 2243379bc100SJani Nikula u32 val; 2244379bc100SJani Nikula 2245379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2246a8143150SJosé Roberto de Souza ddi_translations = cnl_get_buf_trans_hdmi(encoder, &n_entries); 2247379bc100SJani Nikula else if (type == INTEL_OUTPUT_EDP) 2248a8143150SJosé Roberto de Souza ddi_translations = cnl_get_buf_trans_edp(encoder, &n_entries); 2249379bc100SJani Nikula else 2250a8143150SJosé Roberto de Souza ddi_translations = cnl_get_buf_trans_dp(encoder, &n_entries); 2251379bc100SJani Nikula 22521de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, !ddi_translations)) 2253379bc100SJani Nikula return; 22541de143ccSPankaj Bharadiya if (drm_WARN_ON_ONCE(&dev_priv->drm, level >= n_entries)) 2255379bc100SJani Nikula level = n_entries - 1; 2256379bc100SJani Nikula 2257379bc100SJani Nikula /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */ 2258f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2259379bc100SJani Nikula val &= ~SCALING_MODE_SEL_MASK; 2260379bc100SJani Nikula val |= SCALING_MODE_SEL(2); 2261f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2262379bc100SJani Nikula 2263379bc100SJani Nikula /* Program PORT_TX_DW2 */ 2264f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW2_LN0(port)); 2265379bc100SJani Nikula val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 2266379bc100SJani Nikula RCOMP_SCALAR_MASK); 2267379bc100SJani Nikula val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel); 2268379bc100SJani Nikula val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel); 2269379bc100SJani Nikula /* Rcomp scalar is fixed as 0x98 for every table entry */ 2270379bc100SJani Nikula val |= RCOMP_SCALAR(0x98); 2271f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW2_GRP(port), val); 2272379bc100SJani Nikula 2273379bc100SJani Nikula /* Program PORT_TX_DW4 */ 2274379bc100SJani Nikula /* We cannot write to GRP. It would overrite individual loadgen */ 2275379bc100SJani Nikula for (ln = 0; ln < 4; ln++) { 2276f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port)); 2277379bc100SJani Nikula val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 2278379bc100SJani Nikula CURSOR_COEFF_MASK); 2279379bc100SJani Nikula val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1); 2280379bc100SJani Nikula val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2); 2281379bc100SJani Nikula val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff); 2282f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val); 2283379bc100SJani Nikula } 2284379bc100SJani Nikula 2285379bc100SJani Nikula /* Program PORT_TX_DW5 */ 2286379bc100SJani Nikula /* All DW5 values are fixed for every table entry */ 2287f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2288379bc100SJani Nikula val &= ~RTERM_SELECT_MASK; 2289379bc100SJani Nikula val |= RTERM_SELECT(6); 2290379bc100SJani Nikula val |= TAP3_DISABLE; 2291f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2292379bc100SJani Nikula 2293379bc100SJani Nikula /* Program PORT_TX_DW7 */ 2294f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW7_LN0(port)); 2295379bc100SJani Nikula val &= ~N_SCALAR_MASK; 2296379bc100SJani Nikula val |= N_SCALAR(ddi_translations[level].dw7_n_scalar); 2297f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW7_GRP(port), val); 2298379bc100SJani Nikula } 2299379bc100SJani Nikula 2300379bc100SJani Nikula static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder, 2301379bc100SJani Nikula int level, enum intel_output_type type) 2302379bc100SJani Nikula { 2303379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2304379bc100SJani Nikula enum port port = encoder->port; 2305379bc100SJani Nikula int width, rate, ln; 2306379bc100SJani Nikula u32 val; 2307379bc100SJani Nikula 2308379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) { 2309379bc100SJani Nikula width = 4; 2310379bc100SJani Nikula rate = 0; /* Rate is always < than 6GHz for HDMI */ 2311379bc100SJani Nikula } else { 2312b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2313379bc100SJani Nikula 2314379bc100SJani Nikula width = intel_dp->lane_count; 2315379bc100SJani Nikula rate = intel_dp->link_rate; 2316379bc100SJani Nikula } 2317379bc100SJani Nikula 2318379bc100SJani Nikula /* 2319379bc100SJani Nikula * 1. If port type is eDP or DP, 2320379bc100SJani Nikula * set PORT_PCS_DW1 cmnkeeper_enable to 1b, 2321379bc100SJani Nikula * else clear to 0b. 2322379bc100SJani Nikula */ 2323f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_PCS_DW1_LN0(port)); 2324379bc100SJani Nikula if (type != INTEL_OUTPUT_HDMI) 2325379bc100SJani Nikula val |= COMMON_KEEPER_EN; 2326379bc100SJani Nikula else 2327379bc100SJani Nikula val &= ~COMMON_KEEPER_EN; 2328f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_PCS_DW1_GRP(port), val); 2329379bc100SJani Nikula 2330379bc100SJani Nikula /* 2. Program loadgen select */ 2331379bc100SJani Nikula /* 2332379bc100SJani Nikula * Program PORT_TX_DW4_LN depending on Bit rate and used lanes 2333379bc100SJani Nikula * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1) 2334379bc100SJani Nikula * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0) 2335379bc100SJani Nikula * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0) 2336379bc100SJani Nikula */ 2337379bc100SJani Nikula for (ln = 0; ln <= 3; ln++) { 2338f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW4_LN(ln, port)); 2339379bc100SJani Nikula val &= ~LOADGEN_SELECT; 2340379bc100SJani Nikula 2341379bc100SJani Nikula if ((rate <= 600000 && width == 4 && ln >= 1) || 2342379bc100SJani Nikula (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) { 2343379bc100SJani Nikula val |= LOADGEN_SELECT; 2344379bc100SJani Nikula } 2345f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW4_LN(ln, port), val); 2346379bc100SJani Nikula } 2347379bc100SJani Nikula 2348379bc100SJani Nikula /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */ 2349f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_CL1CM_DW5); 2350379bc100SJani Nikula val |= SUS_CLOCK_CONFIG; 2351f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_CL1CM_DW5, val); 2352379bc100SJani Nikula 2353379bc100SJani Nikula /* 4. Clear training enable to change swing values */ 2354f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2355379bc100SJani Nikula val &= ~TX_TRAINING_EN; 2356f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2357379bc100SJani Nikula 2358379bc100SJani Nikula /* 5. Program swing and de-emphasis */ 2359379bc100SJani Nikula cnl_ddi_vswing_program(encoder, level, type); 2360379bc100SJani Nikula 2361379bc100SJani Nikula /* 6. Set training enable to trigger update */ 2362f7960e7fSJani Nikula val = intel_de_read(dev_priv, CNL_PORT_TX_DW5_LN0(port)); 2363379bc100SJani Nikula val |= TX_TRAINING_EN; 2364f7960e7fSJani Nikula intel_de_write(dev_priv, CNL_PORT_TX_DW5_GRP(port), val); 2365379bc100SJani Nikula } 2366379bc100SJani Nikula 2367a8143150SJosé Roberto de Souza static void icl_ddi_combo_vswing_program(struct intel_encoder *encoder, 2368*f0e86e05SJosé Roberto de Souza u32 level, int type, int rate) 2369379bc100SJani Nikula { 2370a8143150SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2371*f0e86e05SJosé Roberto de Souza enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2372379bc100SJani Nikula const struct cnl_ddi_buf_trans *ddi_translations = NULL; 2373379bc100SJani Nikula u32 n_entries, val; 2374379bc100SJani Nikula int ln; 2375379bc100SJani Nikula 2376bd3cf6f7SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 2377a8143150SJosé Roberto de Souza ddi_translations = tgl_get_combo_buf_trans(encoder, type, rate, 2378bd3cf6f7SJosé Roberto de Souza &n_entries); 2379b42d5a67SJosé Roberto de Souza else if (IS_ELKHARTLAKE(dev_priv)) 2380a8143150SJosé Roberto de Souza ddi_translations = ehl_get_combo_buf_trans(encoder, type, rate, 2381b42d5a67SJosé Roberto de Souza &n_entries); 2382bd3cf6f7SJosé Roberto de Souza else 2383a8143150SJosé Roberto de Souza ddi_translations = icl_get_combo_buf_trans(encoder, type, rate, 23844a8134d5SMatt Roper &n_entries); 2385379bc100SJani Nikula if (!ddi_translations) 2386379bc100SJani Nikula return; 2387379bc100SJani Nikula 2388379bc100SJani Nikula if (level >= n_entries) { 238947bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 239047bdb1caSJani Nikula "DDI translation not found for level %d. Using %d instead.", 239147bdb1caSJani Nikula level, n_entries - 1); 2392379bc100SJani Nikula level = n_entries - 1; 2393379bc100SJani Nikula } 2394379bc100SJani Nikula 2395379bc100SJani Nikula /* Set PORT_TX_DW5 */ 2396f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 2397379bc100SJani Nikula val &= ~(SCALING_MODE_SEL_MASK | RTERM_SELECT_MASK | 2398379bc100SJani Nikula TAP2_DISABLE | TAP3_DISABLE); 2399379bc100SJani Nikula val |= SCALING_MODE_SEL(0x2); 2400379bc100SJani Nikula val |= RTERM_SELECT(0x6); 2401379bc100SJani Nikula val |= TAP3_DISABLE; 2402f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val); 2403379bc100SJani Nikula 2404379bc100SJani Nikula /* Program PORT_TX_DW2 */ 2405f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW2_LN0(phy)); 2406379bc100SJani Nikula val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK | 2407379bc100SJani Nikula RCOMP_SCALAR_MASK); 2408379bc100SJani Nikula val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel); 2409379bc100SJani Nikula val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel); 2410379bc100SJani Nikula /* Program Rcomp scalar for every table entry */ 2411379bc100SJani Nikula val |= RCOMP_SCALAR(0x98); 2412f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW2_GRP(phy), val); 2413379bc100SJani Nikula 2414379bc100SJani Nikula /* Program PORT_TX_DW4 */ 2415379bc100SJani Nikula /* We cannot write to GRP. It would overwrite individual loadgen. */ 2416379bc100SJani Nikula for (ln = 0; ln <= 3; ln++) { 2417f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy)); 2418379bc100SJani Nikula val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK | 2419379bc100SJani Nikula CURSOR_COEFF_MASK); 2420379bc100SJani Nikula val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1); 2421379bc100SJani Nikula val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2); 2422379bc100SJani Nikula val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff); 2423f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val); 2424379bc100SJani Nikula } 2425379bc100SJani Nikula 2426379bc100SJani Nikula /* Program PORT_TX_DW7 */ 2427f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW7_LN0(phy)); 2428379bc100SJani Nikula val &= ~N_SCALAR_MASK; 2429379bc100SJani Nikula val |= N_SCALAR(ddi_translations[level].dw7_n_scalar); 2430f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW7_GRP(phy), val); 2431379bc100SJani Nikula } 2432379bc100SJani Nikula 2433379bc100SJani Nikula static void icl_combo_phy_ddi_vswing_sequence(struct intel_encoder *encoder, 2434379bc100SJani Nikula u32 level, 2435379bc100SJani Nikula enum intel_output_type type) 2436379bc100SJani Nikula { 2437379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2438dc867bc7SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2439379bc100SJani Nikula int width = 0; 2440379bc100SJani Nikula int rate = 0; 2441379bc100SJani Nikula u32 val; 2442379bc100SJani Nikula int ln = 0; 2443379bc100SJani Nikula 2444379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) { 2445379bc100SJani Nikula width = 4; 2446379bc100SJani Nikula /* Rate is always < than 6GHz for HDMI */ 2447379bc100SJani Nikula } else { 2448b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 2449379bc100SJani Nikula 2450379bc100SJani Nikula width = intel_dp->lane_count; 2451379bc100SJani Nikula rate = intel_dp->link_rate; 2452379bc100SJani Nikula } 2453379bc100SJani Nikula 2454379bc100SJani Nikula /* 2455379bc100SJani Nikula * 1. If port type is eDP or DP, 2456379bc100SJani Nikula * set PORT_PCS_DW1 cmnkeeper_enable to 1b, 2457379bc100SJani Nikula * else clear to 0b. 2458379bc100SJani Nikula */ 2459f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_PCS_DW1_LN0(phy)); 2460379bc100SJani Nikula if (type == INTEL_OUTPUT_HDMI) 2461379bc100SJani Nikula val &= ~COMMON_KEEPER_EN; 2462379bc100SJani Nikula else 2463379bc100SJani Nikula val |= COMMON_KEEPER_EN; 2464f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_PCS_DW1_GRP(phy), val); 2465379bc100SJani Nikula 2466379bc100SJani Nikula /* 2. Program loadgen select */ 2467379bc100SJani Nikula /* 2468379bc100SJani Nikula * Program PORT_TX_DW4_LN depending on Bit rate and used lanes 2469379bc100SJani Nikula * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1) 2470379bc100SJani Nikula * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0) 2471379bc100SJani Nikula * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0) 2472379bc100SJani Nikula */ 2473379bc100SJani Nikula for (ln = 0; ln <= 3; ln++) { 2474f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy)); 2475379bc100SJani Nikula val &= ~LOADGEN_SELECT; 2476379bc100SJani Nikula 2477379bc100SJani Nikula if ((rate <= 600000 && width == 4 && ln >= 1) || 2478379bc100SJani Nikula (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) { 2479379bc100SJani Nikula val |= LOADGEN_SELECT; 2480379bc100SJani Nikula } 2481f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW4_LN(ln, phy), val); 2482379bc100SJani Nikula } 2483379bc100SJani Nikula 2484379bc100SJani Nikula /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */ 2485f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_CL_DW5(phy)); 2486379bc100SJani Nikula val |= SUS_CLOCK_CONFIG; 2487f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_CL_DW5(phy), val); 2488379bc100SJani Nikula 2489379bc100SJani Nikula /* 4. Clear training enable to change swing values */ 2490f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 2491379bc100SJani Nikula val &= ~TX_TRAINING_EN; 2492f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val); 2493379bc100SJani Nikula 2494379bc100SJani Nikula /* 5. Program swing and de-emphasis */ 2495*f0e86e05SJosé Roberto de Souza icl_ddi_combo_vswing_program(encoder, level, type, rate); 2496379bc100SJani Nikula 2497379bc100SJani Nikula /* 6. Set training enable to trigger update */ 2498f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_PORT_TX_DW5_LN0(phy)); 2499379bc100SJani Nikula val |= TX_TRAINING_EN; 2500f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_PORT_TX_DW5_GRP(phy), val); 2501379bc100SJani Nikula } 2502379bc100SJani Nikula 2503379bc100SJani Nikula static void icl_mg_phy_ddi_vswing_sequence(struct intel_encoder *encoder, 25049f7ffa29SJosé Roberto de Souza int link_clock, u32 level, 25059f7ffa29SJosé Roberto de Souza enum intel_output_type type) 2506379bc100SJani Nikula { 2507379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2508f21e8b80SJosé Roberto de Souza enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port); 2509379bc100SJani Nikula const struct icl_mg_phy_ddi_buf_trans *ddi_translations; 2510379bc100SJani Nikula u32 n_entries, val; 25119f7ffa29SJosé Roberto de Souza int ln, rate = 0; 2512379bc100SJani Nikula 25139f7ffa29SJosé Roberto de Souza if (type != INTEL_OUTPUT_HDMI) { 25149f7ffa29SJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 25159f7ffa29SJosé Roberto de Souza 25169f7ffa29SJosé Roberto de Souza rate = intel_dp->link_rate; 25179f7ffa29SJosé Roberto de Souza } 25189f7ffa29SJosé Roberto de Souza 2519a8143150SJosé Roberto de Souza ddi_translations = icl_get_mg_buf_trans(encoder, type, rate, 25209f7ffa29SJosé Roberto de Souza &n_entries); 2521379bc100SJani Nikula /* The table does not have values for level 3 and level 9. */ 2522379bc100SJani Nikula if (level >= n_entries || level == 3 || level == 9) { 252347bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 252447bdb1caSJani Nikula "DDI translation not found for level %d. Using %d instead.", 2525379bc100SJani Nikula level, n_entries - 2); 2526379bc100SJani Nikula level = n_entries - 2; 2527379bc100SJani Nikula } 2528379bc100SJani Nikula 2529379bc100SJani Nikula /* Set MG_TX_LINK_PARAMS cri_use_fs32 to 0. */ 2530379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2531f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port)); 2532379bc100SJani Nikula val &= ~CRI_USE_FS32; 2533f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_LINK_PARAMS(ln, tc_port), val); 2534379bc100SJani Nikula 2535f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port)); 2536379bc100SJani Nikula val &= ~CRI_USE_FS32; 2537f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_LINK_PARAMS(ln, tc_port), val); 2538379bc100SJani Nikula } 2539379bc100SJani Nikula 2540379bc100SJani Nikula /* Program MG_TX_SWINGCTRL with values from vswing table */ 2541379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2542f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port)); 2543379bc100SJani Nikula val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK; 2544379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_17_12( 2545379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_17_12); 2546f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_SWINGCTRL(ln, tc_port), val); 2547379bc100SJani Nikula 2548f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port)); 2549379bc100SJani Nikula val &= ~CRI_TXDEEMPH_OVERRIDE_17_12_MASK; 2550379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_17_12( 2551379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_17_12); 2552f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_SWINGCTRL(ln, tc_port), val); 2553379bc100SJani Nikula } 2554379bc100SJani Nikula 2555379bc100SJani Nikula /* Program MG_TX_DRVCTRL with values from vswing table */ 2556379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2557f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_DRVCTRL(ln, tc_port)); 2558379bc100SJani Nikula val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK | 2559379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_5_0_MASK); 2560379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_5_0( 2561379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_5_0) | 2562379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_11_6( 2563379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_11_6) | 2564379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_EN; 2565f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_DRVCTRL(ln, tc_port), val); 2566379bc100SJani Nikula 2567f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_DRVCTRL(ln, tc_port)); 2568379bc100SJani Nikula val &= ~(CRI_TXDEEMPH_OVERRIDE_11_6_MASK | 2569379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_5_0_MASK); 2570379bc100SJani Nikula val |= CRI_TXDEEMPH_OVERRIDE_5_0( 2571379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_5_0) | 2572379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_11_6( 2573379bc100SJani Nikula ddi_translations[level].cri_txdeemph_override_11_6) | 2574379bc100SJani Nikula CRI_TXDEEMPH_OVERRIDE_EN; 2575f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_DRVCTRL(ln, tc_port), val); 2576379bc100SJani Nikula 2577379bc100SJani Nikula /* FIXME: Program CRI_LOADGEN_SEL after the spec is updated */ 2578379bc100SJani Nikula } 2579379bc100SJani Nikula 2580379bc100SJani Nikula /* 2581379bc100SJani Nikula * Program MG_CLKHUB<LN, port being used> with value from frequency table 2582379bc100SJani Nikula * In case of Legacy mode on MG PHY, both TX1 and TX2 enabled so use the 2583379bc100SJani Nikula * values from table for which TX1 and TX2 enabled. 2584379bc100SJani Nikula */ 2585379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2586f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_CLKHUB(ln, tc_port)); 2587379bc100SJani Nikula if (link_clock < 300000) 2588379bc100SJani Nikula val |= CFG_LOW_RATE_LKREN_EN; 2589379bc100SJani Nikula else 2590379bc100SJani Nikula val &= ~CFG_LOW_RATE_LKREN_EN; 2591f7960e7fSJani Nikula intel_de_write(dev_priv, MG_CLKHUB(ln, tc_port), val); 2592379bc100SJani Nikula } 2593379bc100SJani Nikula 2594379bc100SJani Nikula /* Program the MG_TX_DCC<LN, port being used> based on the link frequency */ 2595379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2596f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX1_DCC(ln, tc_port)); 2597379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK; 2598379bc100SJani Nikula if (link_clock <= 500000) { 2599379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN; 2600379bc100SJani Nikula } else { 2601379bc100SJani Nikula val |= CFG_AMI_CK_DIV_OVERRIDE_EN | 2602379bc100SJani Nikula CFG_AMI_CK_DIV_OVERRIDE_VAL(1); 2603379bc100SJani Nikula } 2604f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_DCC(ln, tc_port), val); 2605379bc100SJani Nikula 2606f7960e7fSJani Nikula val = intel_de_read(dev_priv, MG_TX2_DCC(ln, tc_port)); 2607379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_VAL_MASK; 2608379bc100SJani Nikula if (link_clock <= 500000) { 2609379bc100SJani Nikula val &= ~CFG_AMI_CK_DIV_OVERRIDE_EN; 2610379bc100SJani Nikula } else { 2611379bc100SJani Nikula val |= CFG_AMI_CK_DIV_OVERRIDE_EN | 2612379bc100SJani Nikula CFG_AMI_CK_DIV_OVERRIDE_VAL(1); 2613379bc100SJani Nikula } 2614f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_DCC(ln, tc_port), val); 2615379bc100SJani Nikula } 2616379bc100SJani Nikula 2617379bc100SJani Nikula /* Program MG_TX_PISO_READLOAD with values from vswing table */ 2618379bc100SJani Nikula for (ln = 0; ln < 2; ln++) { 2619f7960e7fSJani Nikula val = intel_de_read(dev_priv, 2620f7960e7fSJani Nikula MG_TX1_PISO_READLOAD(ln, tc_port)); 2621379bc100SJani Nikula val |= CRI_CALCINIT; 2622f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX1_PISO_READLOAD(ln, tc_port), 2623f7960e7fSJani Nikula val); 2624379bc100SJani Nikula 2625f7960e7fSJani Nikula val = intel_de_read(dev_priv, 2626f7960e7fSJani Nikula MG_TX2_PISO_READLOAD(ln, tc_port)); 2627379bc100SJani Nikula val |= CRI_CALCINIT; 2628f7960e7fSJani Nikula intel_de_write(dev_priv, MG_TX2_PISO_READLOAD(ln, tc_port), 2629f7960e7fSJani Nikula val); 2630379bc100SJani Nikula } 2631379bc100SJani Nikula } 2632379bc100SJani Nikula 2633379bc100SJani Nikula static void icl_ddi_vswing_sequence(struct intel_encoder *encoder, 2634379bc100SJani Nikula int link_clock, 2635379bc100SJani Nikula u32 level, 2636379bc100SJani Nikula enum intel_output_type type) 2637379bc100SJani Nikula { 2638379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2639d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2640379bc100SJani Nikula 2641d8fe2ab6SMatt Roper if (intel_phy_is_combo(dev_priv, phy)) 2642379bc100SJani Nikula icl_combo_phy_ddi_vswing_sequence(encoder, level, type); 2643379bc100SJani Nikula else 26449f7ffa29SJosé Roberto de Souza icl_mg_phy_ddi_vswing_sequence(encoder, link_clock, level, 26459f7ffa29SJosé Roberto de Souza type); 2646379bc100SJani Nikula } 2647379bc100SJani Nikula 2648978c3e53SClinton A Taylor static void 2649978c3e53SClinton A Taylor tgl_dkl_phy_ddi_vswing_sequence(struct intel_encoder *encoder, int link_clock, 265094641eb6SVandita Kulkarni u32 level, enum intel_output_type type) 2651978c3e53SClinton A Taylor { 2652978c3e53SClinton A Taylor struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2653978c3e53SClinton A Taylor enum tc_port tc_port = intel_port_to_tc(dev_priv, encoder->port); 2654978c3e53SClinton A Taylor const struct tgl_dkl_phy_ddi_buf_trans *ddi_translations; 2655978c3e53SClinton A Taylor u32 n_entries, val, ln, dpcnt_mask, dpcnt_val; 26569fa67699SJosé Roberto de Souza int rate = 0; 2657978c3e53SClinton A Taylor 265894641eb6SVandita Kulkarni if (type == INTEL_OUTPUT_HDMI) { 26599fa67699SJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 26609fa67699SJosé Roberto de Souza 26619fa67699SJosé Roberto de Souza rate = intel_dp->link_rate; 2662362bfb99SMatt Roper } 2663978c3e53SClinton A Taylor 2664a8143150SJosé Roberto de Souza ddi_translations = tgl_get_dkl_buf_trans(encoder, encoder->type, rate, 26659fa67699SJosé Roberto de Souza &n_entries); 26669fa67699SJosé Roberto de Souza 2667978c3e53SClinton A Taylor if (level >= n_entries) 2668978c3e53SClinton A Taylor level = n_entries - 1; 2669978c3e53SClinton A Taylor 2670978c3e53SClinton A Taylor dpcnt_mask = (DKL_TX_PRESHOOT_COEFF_MASK | 2671978c3e53SClinton A Taylor DKL_TX_DE_EMPAHSIS_COEFF_MASK | 2672978c3e53SClinton A Taylor DKL_TX_VSWING_CONTROL_MASK); 2673978c3e53SClinton A Taylor dpcnt_val = DKL_TX_VSWING_CONTROL(ddi_translations[level].dkl_vswing_control); 2674978c3e53SClinton A Taylor dpcnt_val |= DKL_TX_DE_EMPHASIS_COEFF(ddi_translations[level].dkl_de_emphasis_control); 2675978c3e53SClinton A Taylor dpcnt_val |= DKL_TX_PRESHOOT_COEFF(ddi_translations[level].dkl_preshoot_control); 2676978c3e53SClinton A Taylor 2677978c3e53SClinton A Taylor for (ln = 0; ln < 2; ln++) { 2678f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 2679f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, ln)); 2680978c3e53SClinton A Taylor 2681f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_PMD_LANE_SUS(tc_port), 0); 26822d69c42eSJosé Roberto de Souza 2683978c3e53SClinton A Taylor /* All the registers are RMW */ 2684f7960e7fSJani Nikula val = intel_de_read(dev_priv, DKL_TX_DPCNTL0(tc_port)); 2685978c3e53SClinton A Taylor val &= ~dpcnt_mask; 2686978c3e53SClinton A Taylor val |= dpcnt_val; 2687f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_DPCNTL0(tc_port), val); 2688978c3e53SClinton A Taylor 2689f7960e7fSJani Nikula val = intel_de_read(dev_priv, DKL_TX_DPCNTL1(tc_port)); 2690978c3e53SClinton A Taylor val &= ~dpcnt_mask; 2691978c3e53SClinton A Taylor val |= dpcnt_val; 2692f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_DPCNTL1(tc_port), val); 2693978c3e53SClinton A Taylor 2694f7960e7fSJani Nikula val = intel_de_read(dev_priv, DKL_TX_DPCNTL2(tc_port)); 2695978c3e53SClinton A Taylor val &= ~DKL_TX_DP20BITMODE; 2696f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_TX_DPCNTL2(tc_port), val); 2697978c3e53SClinton A Taylor } 2698978c3e53SClinton A Taylor } 2699978c3e53SClinton A Taylor 2700978c3e53SClinton A Taylor static void tgl_ddi_vswing_sequence(struct intel_encoder *encoder, 2701978c3e53SClinton A Taylor int link_clock, 2702978c3e53SClinton A Taylor u32 level, 2703978c3e53SClinton A Taylor enum intel_output_type type) 2704978c3e53SClinton A Taylor { 2705978c3e53SClinton A Taylor struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2706978c3e53SClinton A Taylor enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2707978c3e53SClinton A Taylor 2708978c3e53SClinton A Taylor if (intel_phy_is_combo(dev_priv, phy)) 2709978c3e53SClinton A Taylor icl_combo_phy_ddi_vswing_sequence(encoder, level, type); 2710978c3e53SClinton A Taylor else 271194641eb6SVandita Kulkarni tgl_dkl_phy_ddi_vswing_sequence(encoder, link_clock, level, type); 2712978c3e53SClinton A Taylor } 2713978c3e53SClinton A Taylor 27148b4f2137SPankaj Bharadiya static u32 translate_signal_level(struct intel_dp *intel_dp, int signal_levels) 2715379bc100SJani Nikula { 27168b4f2137SPankaj Bharadiya struct drm_i915_private *i915 = dp_to_i915(intel_dp); 2717379bc100SJani Nikula int i; 2718379bc100SJani Nikula 2719379bc100SJani Nikula for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) { 2720379bc100SJani Nikula if (index_to_dp_signal_levels[i] == signal_levels) 2721379bc100SJani Nikula return i; 2722379bc100SJani Nikula } 2723379bc100SJani Nikula 27248b4f2137SPankaj Bharadiya drm_WARN(&i915->drm, 1, 27258b4f2137SPankaj Bharadiya "Unsupported voltage swing/pre-emphasis level: 0x%x\n", 2726379bc100SJani Nikula signal_levels); 2727379bc100SJani Nikula 2728379bc100SJani Nikula return 0; 2729379bc100SJani Nikula } 2730379bc100SJani Nikula 2731379bc100SJani Nikula static u32 intel_ddi_dp_level(struct intel_dp *intel_dp) 2732379bc100SJani Nikula { 2733379bc100SJani Nikula u8 train_set = intel_dp->train_set[0]; 2734379bc100SJani Nikula int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK | 2735379bc100SJani Nikula DP_TRAIN_PRE_EMPHASIS_MASK); 2736379bc100SJani Nikula 27378b4f2137SPankaj Bharadiya return translate_signal_level(intel_dp, signal_levels); 2738379bc100SJani Nikula } 2739379bc100SJani Nikula 2740fb83f72cSVille Syrjälä static void 2741fb83f72cSVille Syrjälä tgl_set_signal_levels(struct intel_dp *intel_dp) 2742379bc100SJani Nikula { 2743fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2744379bc100SJani Nikula int level = intel_ddi_dp_level(intel_dp); 2745379bc100SJani Nikula 2746978c3e53SClinton A Taylor tgl_ddi_vswing_sequence(encoder, intel_dp->link_rate, 2747978c3e53SClinton A Taylor level, encoder->type); 2748379bc100SJani Nikula } 2749379bc100SJani Nikula 2750fb83f72cSVille Syrjälä static void 2751fb83f72cSVille Syrjälä icl_set_signal_levels(struct intel_dp *intel_dp) 2752379bc100SJani Nikula { 2753fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2754379bc100SJani Nikula int level = intel_ddi_dp_level(intel_dp); 2755379bc100SJani Nikula 2756fb83f72cSVille Syrjälä icl_ddi_vswing_sequence(encoder, intel_dp->link_rate, 2757fb83f72cSVille Syrjälä level, encoder->type); 2758fb83f72cSVille Syrjälä } 2759fb83f72cSVille Syrjälä 2760fb83f72cSVille Syrjälä static void 2761fb83f72cSVille Syrjälä cnl_set_signal_levels(struct intel_dp *intel_dp) 2762fb83f72cSVille Syrjälä { 2763fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2764fb83f72cSVille Syrjälä int level = intel_ddi_dp_level(intel_dp); 2765fb83f72cSVille Syrjälä 2766fb83f72cSVille Syrjälä cnl_ddi_vswing_sequence(encoder, level, encoder->type); 2767fb83f72cSVille Syrjälä } 2768fb83f72cSVille Syrjälä 2769fb83f72cSVille Syrjälä static void 2770fb83f72cSVille Syrjälä bxt_set_signal_levels(struct intel_dp *intel_dp) 2771fb83f72cSVille Syrjälä { 2772fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2773fb83f72cSVille Syrjälä int level = intel_ddi_dp_level(intel_dp); 2774fb83f72cSVille Syrjälä 2775fb83f72cSVille Syrjälä bxt_ddi_vswing_sequence(encoder, level, encoder->type); 2776fb83f72cSVille Syrjälä } 2777fb83f72cSVille Syrjälä 2778fb83f72cSVille Syrjälä static void 2779fb83f72cSVille Syrjälä hsw_set_signal_levels(struct intel_dp *intel_dp) 2780fb83f72cSVille Syrjälä { 2781fb83f72cSVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 2782fb83f72cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2783fb83f72cSVille Syrjälä int level = intel_ddi_dp_level(intel_dp); 2784fb83f72cSVille Syrjälä enum port port = encoder->port; 2785fb83f72cSVille Syrjälä u32 signal_levels; 2786fb83f72cSVille Syrjälä 2787fb83f72cSVille Syrjälä signal_levels = DDI_BUF_TRANS_SELECT(level); 2788fb83f72cSVille Syrjälä 2789fb83f72cSVille Syrjälä drm_dbg_kms(&dev_priv->drm, "Using signal levels %08x\n", 2790fb83f72cSVille Syrjälä signal_levels); 2791fb83f72cSVille Syrjälä 2792fb83f72cSVille Syrjälä intel_dp->DP &= ~DDI_BUF_EMP_MASK; 2793fb83f72cSVille Syrjälä intel_dp->DP |= signal_levels; 2794fb83f72cSVille Syrjälä 2795379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) 2796379bc100SJani Nikula skl_ddi_set_iboost(encoder, level, encoder->type); 2797379bc100SJani Nikula 2798fb83f72cSVille Syrjälä intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP); 2799fb83f72cSVille Syrjälä intel_de_posting_read(dev_priv, DDI_BUF_CTL(port)); 2800379bc100SJani Nikula } 2801379bc100SJani Nikula 280281b55ef1SJani Nikula static u32 icl_dpclka_cfgcr0_clk_off(struct drm_i915_private *dev_priv, 2803befa372bSMatt Roper enum phy phy) 2804379bc100SJani Nikula { 2805befa372bSMatt Roper if (intel_phy_is_combo(dev_priv, phy)) { 2806befa372bSMatt Roper return ICL_DPCLKA_CFGCR0_DDI_CLK_OFF(phy); 2807befa372bSMatt Roper } else if (intel_phy_is_tc(dev_priv, phy)) { 2808befa372bSMatt Roper enum tc_port tc_port = intel_port_to_tc(dev_priv, 2809befa372bSMatt Roper (enum port)phy); 2810379bc100SJani Nikula 2811379bc100SJani Nikula return ICL_DPCLKA_CFGCR0_TC_CLK_OFF(tc_port); 2812379bc100SJani Nikula } 2813379bc100SJani Nikula 2814379bc100SJani Nikula return 0; 2815379bc100SJani Nikula } 2816379bc100SJani Nikula 2817379bc100SJani Nikula static void icl_map_plls_to_ports(struct intel_encoder *encoder, 2818379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 2819379bc100SJani Nikula { 2820379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2821379bc100SJani Nikula struct intel_shared_dpll *pll = crtc_state->shared_dpll; 2822befa372bSMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2823379bc100SJani Nikula u32 val; 2824379bc100SJani Nikula 2825353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 2826379bc100SJani Nikula 2827f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 28281de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 28291de143ccSPankaj Bharadiya (val & icl_dpclka_cfgcr0_clk_off(dev_priv, phy)) == 0); 2830379bc100SJani Nikula 2831befa372bSMatt Roper if (intel_phy_is_combo(dev_priv, phy)) { 2832befa372bSMatt Roper /* 2833befa372bSMatt Roper * Even though this register references DDIs, note that we 2834befa372bSMatt Roper * want to pass the PHY rather than the port (DDI). For 2835befa372bSMatt Roper * ICL, port=phy in all cases so it doesn't matter, but for 2836befa372bSMatt Roper * EHL the bspec notes the following: 2837befa372bSMatt Roper * 2838befa372bSMatt Roper * "DDID clock tied to DDIA clock, so DPCLKA_CFGCR0 DDIA 2839befa372bSMatt Roper * Clock Select chooses the PLL for both DDIA and DDID and 2840befa372bSMatt Roper * drives port A in all cases." 2841befa372bSMatt Roper */ 2842befa372bSMatt Roper val &= ~ICL_DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(phy); 2843befa372bSMatt Roper val |= ICL_DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, phy); 2844f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 2845f7960e7fSJani Nikula intel_de_posting_read(dev_priv, ICL_DPCLKA_CFGCR0); 2846379bc100SJani Nikula } 2847379bc100SJani Nikula 2848befa372bSMatt Roper val &= ~icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 2849f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 2850379bc100SJani Nikula 2851353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 2852379bc100SJani Nikula } 2853379bc100SJani Nikula 2854379bc100SJani Nikula static void icl_unmap_plls_to_ports(struct intel_encoder *encoder) 2855379bc100SJani Nikula { 2856379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2857befa372bSMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 2858379bc100SJani Nikula u32 val; 2859379bc100SJani Nikula 2860353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 2861379bc100SJani Nikula 2862f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 2863befa372bSMatt Roper val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 2864f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 2865379bc100SJani Nikula 2866353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 2867379bc100SJani Nikula } 2868379bc100SJani Nikula 28695956f440SLucas De Marchi static void icl_sanitize_port_clk_off(struct drm_i915_private *dev_priv, 28705956f440SLucas De Marchi u32 port_mask, bool ddi_clk_needed) 28715956f440SLucas De Marchi { 28725956f440SLucas De Marchi enum port port; 28735956f440SLucas De Marchi u32 val; 28745956f440SLucas De Marchi 2875f7960e7fSJani Nikula val = intel_de_read(dev_priv, ICL_DPCLKA_CFGCR0); 28765956f440SLucas De Marchi for_each_port_masked(port, port_mask) { 28775956f440SLucas De Marchi enum phy phy = intel_port_to_phy(dev_priv, port); 287841ba19fcSLucas De Marchi bool ddi_clk_off = val & icl_dpclka_cfgcr0_clk_off(dev_priv, 287941ba19fcSLucas De Marchi phy); 28805956f440SLucas De Marchi 288141ba19fcSLucas De Marchi if (ddi_clk_needed == !ddi_clk_off) 28825956f440SLucas De Marchi continue; 28835956f440SLucas De Marchi 28845956f440SLucas De Marchi /* 28855956f440SLucas De Marchi * Punt on the case now where clock is gated, but it would 28865956f440SLucas De Marchi * be needed by the port. Something else is really broken then. 28875956f440SLucas De Marchi */ 28881de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, ddi_clk_needed)) 28895956f440SLucas De Marchi continue; 28905956f440SLucas De Marchi 289147bdb1caSJani Nikula drm_notice(&dev_priv->drm, 289247bdb1caSJani Nikula "PHY %c is disabled/in DSI mode with an ungated DDI clock, gate it\n", 2893d6f970f0SLucas De Marchi phy_name(phy)); 28945956f440SLucas De Marchi val |= icl_dpclka_cfgcr0_clk_off(dev_priv, phy); 2895f7960e7fSJani Nikula intel_de_write(dev_priv, ICL_DPCLKA_CFGCR0, val); 28965956f440SLucas De Marchi } 28975956f440SLucas De Marchi } 28985956f440SLucas De Marchi 2899379bc100SJani Nikula void icl_sanitize_encoder_pll_mapping(struct intel_encoder *encoder) 2900379bc100SJani Nikula { 2901379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2902379bc100SJani Nikula u32 port_mask; 2903379bc100SJani Nikula bool ddi_clk_needed; 2904379bc100SJani Nikula 2905379bc100SJani Nikula /* 2906379bc100SJani Nikula * In case of DP MST, we sanitize the primary encoder only, not the 2907379bc100SJani Nikula * virtual ones. 2908379bc100SJani Nikula */ 2909379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_DP_MST) 2910379bc100SJani Nikula return; 2911379bc100SJani Nikula 2912379bc100SJani Nikula if (!encoder->base.crtc && intel_encoder_is_dp(encoder)) { 2913379bc100SJani Nikula u8 pipe_mask; 2914379bc100SJani Nikula bool is_mst; 2915379bc100SJani Nikula 2916379bc100SJani Nikula intel_ddi_get_encoder_pipes(encoder, &pipe_mask, &is_mst); 2917379bc100SJani Nikula /* 2918379bc100SJani Nikula * In the unlikely case that BIOS enables DP in MST mode, just 2919379bc100SJani Nikula * warn since our MST HW readout is incomplete. 2920379bc100SJani Nikula */ 29211de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, is_mst)) 2922379bc100SJani Nikula return; 2923379bc100SJani Nikula } 2924379bc100SJani Nikula 2925379bc100SJani Nikula port_mask = BIT(encoder->port); 2926379bc100SJani Nikula ddi_clk_needed = encoder->base.crtc; 2927379bc100SJani Nikula 2928379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_DSI) { 2929379bc100SJani Nikula struct intel_encoder *other_encoder; 2930379bc100SJani Nikula 2931379bc100SJani Nikula port_mask = intel_dsi_encoder_ports(encoder); 2932379bc100SJani Nikula /* 2933379bc100SJani Nikula * Sanity check that we haven't incorrectly registered another 2934379bc100SJani Nikula * encoder using any of the ports of this DSI encoder. 2935379bc100SJani Nikula */ 2936379bc100SJani Nikula for_each_intel_encoder(&dev_priv->drm, other_encoder) { 2937379bc100SJani Nikula if (other_encoder == encoder) 2938379bc100SJani Nikula continue; 2939379bc100SJani Nikula 29401de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, 29411de143ccSPankaj Bharadiya port_mask & BIT(other_encoder->port))) 2942379bc100SJani Nikula return; 2943379bc100SJani Nikula } 2944379bc100SJani Nikula /* 2945379bc100SJani Nikula * For DSI we keep the ddi clocks gated 2946379bc100SJani Nikula * except during enable/disable sequence. 2947379bc100SJani Nikula */ 2948379bc100SJani Nikula ddi_clk_needed = false; 2949379bc100SJani Nikula } 2950379bc100SJani Nikula 29515956f440SLucas De Marchi icl_sanitize_port_clk_off(dev_priv, port_mask, ddi_clk_needed); 2952379bc100SJani Nikula } 2953379bc100SJani Nikula 2954379bc100SJani Nikula static void intel_ddi_clk_select(struct intel_encoder *encoder, 2955379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 2956379bc100SJani Nikula { 2957379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 2958379bc100SJani Nikula enum port port = encoder->port; 2959d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 2960379bc100SJani Nikula u32 val; 2961379bc100SJani Nikula const struct intel_shared_dpll *pll = crtc_state->shared_dpll; 2962379bc100SJani Nikula 29631de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, !pll)) 2964379bc100SJani Nikula return; 2965379bc100SJani Nikula 2966353ad959SImre Deak mutex_lock(&dev_priv->dpll.lock); 2967379bc100SJani Nikula 2968379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) { 2969d8fe2ab6SMatt Roper if (!intel_phy_is_combo(dev_priv, phy)) 2970f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_CLK_SEL(port), 2971379bc100SJani Nikula icl_pll_to_ddi_clk_sel(encoder, crtc_state)); 2972c2052d6eSJosé Roberto de Souza else if (IS_ELKHARTLAKE(dev_priv) && port >= PORT_C) 2973c2052d6eSJosé Roberto de Souza /* 2974c2052d6eSJosé Roberto de Souza * MG does not exist but the programming is required 2975c2052d6eSJosé Roberto de Souza * to ungate DDIC and DDID 2976c2052d6eSJosé Roberto de Souza */ 2977f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_CLK_SEL(port), 2978f7960e7fSJani Nikula DDI_CLK_SEL_MG); 2979379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 2980379bc100SJani Nikula /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */ 2981f7960e7fSJani Nikula val = intel_de_read(dev_priv, DPCLKA_CFGCR0); 2982379bc100SJani Nikula val &= ~DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port); 2983379bc100SJani Nikula val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->info->id, port); 2984f7960e7fSJani Nikula intel_de_write(dev_priv, DPCLKA_CFGCR0, val); 2985379bc100SJani Nikula 2986379bc100SJani Nikula /* 2987379bc100SJani Nikula * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI. 2988379bc100SJani Nikula * This step and the step before must be done with separate 2989379bc100SJani Nikula * register writes. 2990379bc100SJani Nikula */ 2991f7960e7fSJani Nikula val = intel_de_read(dev_priv, DPCLKA_CFGCR0); 2992379bc100SJani Nikula val &= ~DPCLKA_CFGCR0_DDI_CLK_OFF(port); 2993f7960e7fSJani Nikula intel_de_write(dev_priv, DPCLKA_CFGCR0, val); 2994379bc100SJani Nikula } else if (IS_GEN9_BC(dev_priv)) { 2995379bc100SJani Nikula /* DDI -> PLL mapping */ 2996f7960e7fSJani Nikula val = intel_de_read(dev_priv, DPLL_CTRL2); 2997379bc100SJani Nikula 2998379bc100SJani Nikula val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) | 2999379bc100SJani Nikula DPLL_CTRL2_DDI_CLK_SEL_MASK(port)); 3000379bc100SJani Nikula val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->info->id, port) | 3001379bc100SJani Nikula DPLL_CTRL2_DDI_SEL_OVERRIDE(port)); 3002379bc100SJani Nikula 3003f7960e7fSJani Nikula intel_de_write(dev_priv, DPLL_CTRL2, val); 3004379bc100SJani Nikula 3005379bc100SJani Nikula } else if (INTEL_GEN(dev_priv) < 9) { 3006f7960e7fSJani Nikula intel_de_write(dev_priv, PORT_CLK_SEL(port), 3007f7960e7fSJani Nikula hsw_pll_to_ddi_pll_sel(pll)); 3008379bc100SJani Nikula } 3009379bc100SJani Nikula 3010353ad959SImre Deak mutex_unlock(&dev_priv->dpll.lock); 3011379bc100SJani Nikula } 3012379bc100SJani Nikula 3013379bc100SJani Nikula static void intel_ddi_clk_disable(struct intel_encoder *encoder) 3014379bc100SJani Nikula { 3015379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3016379bc100SJani Nikula enum port port = encoder->port; 3017d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 3018379bc100SJani Nikula 3019379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) { 3020c2052d6eSJosé Roberto de Souza if (!intel_phy_is_combo(dev_priv, phy) || 3021c2052d6eSJosé Roberto de Souza (IS_ELKHARTLAKE(dev_priv) && port >= PORT_C)) 3022f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_CLK_SEL(port), 3023f7960e7fSJani Nikula DDI_CLK_SEL_NONE); 3024379bc100SJani Nikula } else if (IS_CANNONLAKE(dev_priv)) { 3025f7960e7fSJani Nikula intel_de_write(dev_priv, DPCLKA_CFGCR0, 3026f7960e7fSJani Nikula intel_de_read(dev_priv, DPCLKA_CFGCR0) | DPCLKA_CFGCR0_DDI_CLK_OFF(port)); 3027379bc100SJani Nikula } else if (IS_GEN9_BC(dev_priv)) { 3028f7960e7fSJani Nikula intel_de_write(dev_priv, DPLL_CTRL2, 3029f7960e7fSJani Nikula intel_de_read(dev_priv, DPLL_CTRL2) | DPLL_CTRL2_DDI_CLK_OFF(port)); 3030379bc100SJani Nikula } else if (INTEL_GEN(dev_priv) < 9) { 3031f7960e7fSJani Nikula intel_de_write(dev_priv, PORT_CLK_SEL(port), 3032f7960e7fSJani Nikula PORT_CLK_SEL_NONE); 3033379bc100SJani Nikula } 3034379bc100SJani Nikula } 3035379bc100SJani Nikula 30368aaf5cbdSJosé Roberto de Souza static void 30377801f3b7SLucas De Marchi icl_program_mg_dp_mode(struct intel_digital_port *dig_port, 30383b51be4eSClinton A Taylor const struct intel_crtc_state *crtc_state) 3039379bc100SJani Nikula { 30407801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 30417801f3b7SLucas De Marchi enum tc_port tc_port = intel_port_to_tc(dev_priv, dig_port->base.port); 30423b51be4eSClinton A Taylor u32 ln0, ln1, pin_assignment; 30433b51be4eSClinton A Taylor u8 width; 3044379bc100SJani Nikula 30457801f3b7SLucas De Marchi if (dig_port->tc_mode == TC_PORT_TBT_ALT) 3046379bc100SJani Nikula return; 3047379bc100SJani Nikula 3048978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 3049f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3050f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x0)); 3051f7960e7fSJani Nikula ln0 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port)); 3052f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3053f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x1)); 3054f7960e7fSJani Nikula ln1 = intel_de_read(dev_priv, DKL_DP_MODE(tc_port)); 3055978c3e53SClinton A Taylor } else { 3056f7960e7fSJani Nikula ln0 = intel_de_read(dev_priv, MG_DP_MODE(0, tc_port)); 3057f7960e7fSJani Nikula ln1 = intel_de_read(dev_priv, MG_DP_MODE(1, tc_port)); 3058978c3e53SClinton A Taylor } 3059379bc100SJani Nikula 30604f72a8eeSKhaled Almahallawy ln0 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE); 3061379bc100SJani Nikula ln1 &= ~(MG_DP_MODE_CFG_DP_X1_MODE | MG_DP_MODE_CFG_DP_X2_MODE); 3062379bc100SJani Nikula 30633b51be4eSClinton A Taylor /* DPPATC */ 30647801f3b7SLucas De Marchi pin_assignment = intel_tc_port_get_pin_assignment_mask(dig_port); 30653b51be4eSClinton A Taylor width = crtc_state->lane_count; 3066379bc100SJani Nikula 30673b51be4eSClinton A Taylor switch (pin_assignment) { 30683b51be4eSClinton A Taylor case 0x0: 30691de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 30707801f3b7SLucas De Marchi dig_port->tc_mode != TC_PORT_LEGACY); 30713b51be4eSClinton A Taylor if (width == 1) { 3072379bc100SJani Nikula ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 30733b51be4eSClinton A Taylor } else { 30743b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 30753b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 3076379bc100SJani Nikula } 3077379bc100SJani Nikula break; 30783b51be4eSClinton A Taylor case 0x1: 30793b51be4eSClinton A Taylor if (width == 4) { 30803b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 30813b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 30823b51be4eSClinton A Taylor } 3083379bc100SJani Nikula break; 30843b51be4eSClinton A Taylor case 0x2: 30853b51be4eSClinton A Taylor if (width == 2) { 30863b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 30873b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 30883b51be4eSClinton A Taylor } 30893b51be4eSClinton A Taylor break; 30903b51be4eSClinton A Taylor case 0x3: 30913b51be4eSClinton A Taylor case 0x5: 30923b51be4eSClinton A Taylor if (width == 1) { 30933b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X1_MODE; 30943b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 30953b51be4eSClinton A Taylor } else { 30963b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 30973b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 30983b51be4eSClinton A Taylor } 30993b51be4eSClinton A Taylor break; 31003b51be4eSClinton A Taylor case 0x4: 31013b51be4eSClinton A Taylor case 0x6: 31023b51be4eSClinton A Taylor if (width == 1) { 31033b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X1_MODE; 31043b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X1_MODE; 31053b51be4eSClinton A Taylor } else { 31063b51be4eSClinton A Taylor ln0 |= MG_DP_MODE_CFG_DP_X2_MODE; 31073b51be4eSClinton A Taylor ln1 |= MG_DP_MODE_CFG_DP_X2_MODE; 31083b51be4eSClinton A Taylor } 31093b51be4eSClinton A Taylor break; 3110379bc100SJani Nikula default: 31113b51be4eSClinton A Taylor MISSING_CASE(pin_assignment); 3112379bc100SJani Nikula } 3113379bc100SJani Nikula 3114978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) { 3115f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3116f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x0)); 3117f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln0); 3118f7960e7fSJani Nikula intel_de_write(dev_priv, HIP_INDEX_REG(tc_port), 3119f7960e7fSJani Nikula HIP_INDEX_VAL(tc_port, 0x1)); 3120f7960e7fSJani Nikula intel_de_write(dev_priv, DKL_DP_MODE(tc_port), ln1); 3121978c3e53SClinton A Taylor } else { 3122f7960e7fSJani Nikula intel_de_write(dev_priv, MG_DP_MODE(0, tc_port), ln0); 3123f7960e7fSJani Nikula intel_de_write(dev_priv, MG_DP_MODE(1, tc_port), ln1); 3124379bc100SJani Nikula } 3125978c3e53SClinton A Taylor } 3126379bc100SJani Nikula 3127379bc100SJani Nikula static void intel_dp_sink_set_fec_ready(struct intel_dp *intel_dp, 3128379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3129379bc100SJani Nikula { 313047bdb1caSJani Nikula struct drm_i915_private *i915 = dp_to_i915(intel_dp); 313147bdb1caSJani Nikula 3132379bc100SJani Nikula if (!crtc_state->fec_enable) 3133379bc100SJani Nikula return; 3134379bc100SJani Nikula 3135379bc100SJani Nikula if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_FEC_CONFIGURATION, DP_FEC_READY) <= 0) 313647bdb1caSJani Nikula drm_dbg_kms(&i915->drm, 313747bdb1caSJani Nikula "Failed to set FEC_READY in the sink\n"); 3138379bc100SJani Nikula } 3139379bc100SJani Nikula 3140379bc100SJani Nikula static void intel_ddi_enable_fec(struct intel_encoder *encoder, 3141379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3142379bc100SJani Nikula { 3143379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 31444444df6eSLucas De Marchi struct intel_dp *intel_dp; 3145379bc100SJani Nikula u32 val; 3146379bc100SJani Nikula 3147379bc100SJani Nikula if (!crtc_state->fec_enable) 3148379bc100SJani Nikula return; 3149379bc100SJani Nikula 3150b7d02c3aSVille Syrjälä intel_dp = enc_to_intel_dp(encoder); 3151f7960e7fSJani Nikula val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3152379bc100SJani Nikula val |= DP_TP_CTL_FEC_ENABLE; 3153f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 3154379bc100SJani Nikula 31554444df6eSLucas De Marchi if (intel_de_wait_for_set(dev_priv, intel_dp->regs.dp_tp_status, 31564cb3b44dSDaniele Ceraolo Spurio DP_TP_STATUS_FEC_ENABLE_LIVE, 1)) 315747bdb1caSJani Nikula drm_err(&dev_priv->drm, 315847bdb1caSJani Nikula "Timed out waiting for FEC Enable Status\n"); 3159379bc100SJani Nikula } 3160379bc100SJani Nikula 3161379bc100SJani Nikula static void intel_ddi_disable_fec_state(struct intel_encoder *encoder, 3162379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3163379bc100SJani Nikula { 3164379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 31654444df6eSLucas De Marchi struct intel_dp *intel_dp; 3166379bc100SJani Nikula u32 val; 3167379bc100SJani Nikula 3168379bc100SJani Nikula if (!crtc_state->fec_enable) 3169379bc100SJani Nikula return; 3170379bc100SJani Nikula 3171b7d02c3aSVille Syrjälä intel_dp = enc_to_intel_dp(encoder); 3172f7960e7fSJani Nikula val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3173379bc100SJani Nikula val &= ~DP_TP_CTL_FEC_ENABLE; 3174f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 3175f7960e7fSJani Nikula intel_de_posting_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3176379bc100SJani Nikula } 3177379bc100SJani Nikula 3178ede9771dSVille Syrjälä static void tgl_ddi_pre_enable_dp(struct intel_atomic_state *state, 3179ede9771dSVille Syrjälä struct intel_encoder *encoder, 318099389390SJosé Roberto de Souza const struct intel_crtc_state *crtc_state, 318199389390SJosé Roberto de Souza const struct drm_connector_state *conn_state) 318299389390SJosé Roberto de Souza { 3183b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 318499389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 318599389390SJosé Roberto de Souza enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3186b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 318799389390SJosé Roberto de Souza bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 318899389390SJosé Roberto de Souza int level = intel_ddi_dp_level(intel_dp); 31894444df6eSLucas De Marchi enum transcoder transcoder = crtc_state->cpu_transcoder; 319099389390SJosé Roberto de Souza 319199389390SJosé Roberto de Souza intel_dp_set_link_params(intel_dp, crtc_state->port_clock, 319299389390SJosé Roberto de Souza crtc_state->lane_count, is_mst); 319399389390SJosé Roberto de Souza 31944444df6eSLucas De Marchi intel_dp->regs.dp_tp_ctl = TGL_DP_TP_CTL(transcoder); 31954444df6eSLucas De Marchi intel_dp->regs.dp_tp_status = TGL_DP_TP_STATUS(transcoder); 31964444df6eSLucas De Marchi 31975e19c0b0SMatt Roper /* 31985e19c0b0SMatt Roper * 1. Enable Power Wells 31995e19c0b0SMatt Roper * 32005e19c0b0SMatt Roper * This was handled at the beginning of intel_atomic_commit_tail(), 32015e19c0b0SMatt Roper * before we called down into this function. 32025e19c0b0SMatt Roper */ 320399389390SJosé Roberto de Souza 32045e19c0b0SMatt Roper /* 2. Enable Panel Power if PPS is required */ 320599389390SJosé Roberto de Souza intel_edp_panel_on(intel_dp); 320699389390SJosé Roberto de Souza 320799389390SJosé Roberto de Souza /* 32085e19c0b0SMatt Roper * 3. For non-TBT Type-C ports, set FIA lane count 32095e19c0b0SMatt Roper * (DFLEXDPSP.DPX4TXLATC) 32105e19c0b0SMatt Roper * 32115e19c0b0SMatt Roper * This was done before tgl_ddi_pre_enable_dp by 32121e98f88cSLucas De Marchi * hsw_crtc_enable()->intel_encoders_pre_pll_enable(). 321399389390SJosé Roberto de Souza */ 321499389390SJosé Roberto de Souza 32155e19c0b0SMatt Roper /* 32165e19c0b0SMatt Roper * 4. Enable the port PLL. 32175e19c0b0SMatt Roper * 32185e19c0b0SMatt Roper * The PLL enabling itself was already done before this function by 32191e98f88cSLucas De Marchi * hsw_crtc_enable()->intel_enable_shared_dpll(). We need only 32205e19c0b0SMatt Roper * configure the PLL to port mapping here. 32215e19c0b0SMatt Roper */ 32226171e58bSClinton A Taylor intel_ddi_clk_select(encoder, crtc_state); 32236171e58bSClinton A Taylor 32245e19c0b0SMatt Roper /* 5. If IO power is controlled through PWR_WELL_CTL, Enable IO Power */ 322599389390SJosé Roberto de Souza if (!intel_phy_is_tc(dev_priv, phy) || 322699389390SJosé Roberto de Souza dig_port->tc_mode != TC_PORT_TBT_ALT) 322799389390SJosé Roberto de Souza intel_display_power_get(dev_priv, 322899389390SJosé Roberto de Souza dig_port->ddi_io_power_domain); 322999389390SJosé Roberto de Souza 32305e19c0b0SMatt Roper /* 6. Program DP_MODE */ 32313b51be4eSClinton A Taylor icl_program_mg_dp_mode(dig_port, crtc_state); 323299389390SJosé Roberto de Souza 323399389390SJosé Roberto de Souza /* 32345e19c0b0SMatt Roper * 7. The rest of the below are substeps under the bspec's "Enable and 32355e19c0b0SMatt Roper * Train Display Port" step. Note that steps that are specific to 32365e19c0b0SMatt Roper * MST will be handled by intel_mst_pre_enable_dp() before/after it 32375e19c0b0SMatt Roper * calls into this function. Also intel_mst_pre_enable_dp() only calls 32385e19c0b0SMatt Roper * us when active_mst_links==0, so any steps designated for "single 32395e19c0b0SMatt Roper * stream or multi-stream master transcoder" can just be performed 32405e19c0b0SMatt Roper * unconditionally here. 32415e19c0b0SMatt Roper */ 32425e19c0b0SMatt Roper 32435e19c0b0SMatt Roper /* 32445e19c0b0SMatt Roper * 7.a Configure Transcoder Clock Select to direct the Port clock to the 32455e19c0b0SMatt Roper * Transcoder. 324699389390SJosé Roberto de Souza */ 324702a715c3SVille Syrjälä intel_ddi_enable_pipe_clock(encoder, crtc_state); 324899389390SJosé Roberto de Souza 32495e19c0b0SMatt Roper /* 32505e19c0b0SMatt Roper * 7.b Configure TRANS_DDI_FUNC_CTL DDI Select, DDI Mode Select & MST 32515e19c0b0SMatt Roper * Transport Select 32525e19c0b0SMatt Roper */ 3253eed22a46SVille Syrjälä intel_ddi_config_transcoder_func(encoder, crtc_state); 325499389390SJosé Roberto de Souza 32555e19c0b0SMatt Roper /* 32565e19c0b0SMatt Roper * 7.c Configure & enable DP_TP_CTL with link training pattern 1 32575e19c0b0SMatt Roper * selected 32585e19c0b0SMatt Roper * 32595e19c0b0SMatt Roper * This will be handled by the intel_dp_start_link_train() farther 32605e19c0b0SMatt Roper * down this function. 32615e19c0b0SMatt Roper */ 32625e19c0b0SMatt Roper 32635e19c0b0SMatt Roper /* 7.e Configure voltage swing and related IO settings */ 3264978c3e53SClinton A Taylor tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, level, 326599389390SJosé Roberto de Souza encoder->type); 326699389390SJosé Roberto de Souza 32675e19c0b0SMatt Roper /* 32685e19c0b0SMatt Roper * 7.f Combo PHY: Configure PORT_CL_DW10 Static Power Down to power up 32695e19c0b0SMatt Roper * the used lanes of the DDI. 32705e19c0b0SMatt Roper */ 327199389390SJosé Roberto de Souza if (intel_phy_is_combo(dev_priv, phy)) { 327299389390SJosé Roberto de Souza bool lane_reversal = 327399389390SJosé Roberto de Souza dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL; 327499389390SJosé Roberto de Souza 327599389390SJosé Roberto de Souza intel_combo_phy_power_up_lanes(dev_priv, phy, false, 327699389390SJosé Roberto de Souza crtc_state->lane_count, 327799389390SJosé Roberto de Souza lane_reversal); 327899389390SJosé Roberto de Souza } 327999389390SJosé Roberto de Souza 32805e19c0b0SMatt Roper /* 32815e19c0b0SMatt Roper * 7.g Configure and enable DDI_BUF_CTL 32825e19c0b0SMatt Roper * 7.h Wait for DDI_BUF_CTL DDI Idle Status = 0b (Not Idle), timeout 32835e19c0b0SMatt Roper * after 500 us. 32845e19c0b0SMatt Roper * 32855e19c0b0SMatt Roper * We only configure what the register value will be here. Actual 32865e19c0b0SMatt Roper * enabling happens during link training farther down. 32875e19c0b0SMatt Roper */ 328899389390SJosé Roberto de Souza intel_ddi_init_dp_buf_reg(encoder); 328999389390SJosé Roberto de Souza 329099389390SJosé Roberto de Souza if (!is_mst) 329199389390SJosé Roberto de Souza intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 329299389390SJosé Roberto de Souza 329399389390SJosé Roberto de Souza intel_dp_sink_set_decompression_state(intel_dp, crtc_state, true); 329499389390SJosé Roberto de Souza /* 329599389390SJosé Roberto de Souza * DDI FEC: "anticipates enabling FEC encoding sets the FEC_READY bit 329699389390SJosé Roberto de Souza * in the FEC_CONFIGURATION register to 1 before initiating link 329799389390SJosé Roberto de Souza * training 329899389390SJosé Roberto de Souza */ 329999389390SJosé Roberto de Souza intel_dp_sink_set_fec_ready(intel_dp, crtc_state); 33005e19c0b0SMatt Roper 33015e19c0b0SMatt Roper /* 33025e19c0b0SMatt Roper * 7.i Follow DisplayPort specification training sequence (see notes for 33035e19c0b0SMatt Roper * failure handling) 33045e19c0b0SMatt Roper * 7.j If DisplayPort multi-stream - Set DP_TP_CTL link training to Idle 33055e19c0b0SMatt Roper * Pattern, wait for 5 idle patterns (DP_TP_STATUS Min_Idles_Sent) 33065e19c0b0SMatt Roper * (timeout after 800 us) 33075e19c0b0SMatt Roper */ 330899389390SJosé Roberto de Souza intel_dp_start_link_train(intel_dp); 330999389390SJosé Roberto de Souza 33105e19c0b0SMatt Roper /* 7.k Set DP_TP_CTL link training to Normal */ 3311eadf6f91SManasi Navare if (!is_trans_port_sync_mode(crtc_state)) 331299389390SJosé Roberto de Souza intel_dp_stop_link_train(intel_dp); 331399389390SJosé Roberto de Souza 33145e19c0b0SMatt Roper /* 7.l Configure and enable FEC if needed */ 331599389390SJosé Roberto de Souza intel_ddi_enable_fec(encoder, crtc_state); 331699389390SJosé Roberto de Souza intel_dsc_enable(encoder, crtc_state); 331799389390SJosé Roberto de Souza } 331899389390SJosé Roberto de Souza 3319ede9771dSVille Syrjälä static void hsw_ddi_pre_enable_dp(struct intel_atomic_state *state, 3320ede9771dSVille Syrjälä struct intel_encoder *encoder, 3321379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3322379bc100SJani Nikula const struct drm_connector_state *conn_state) 3323379bc100SJani Nikula { 3324b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3325379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3326379bc100SJani Nikula enum port port = encoder->port; 3327dc867bc7SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 3328b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3329379bc100SJani Nikula bool is_mst = intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST); 3330379bc100SJani Nikula int level = intel_ddi_dp_level(intel_dp); 3331379bc100SJani Nikula 3332542dfab5SJosé Roberto de Souza if (INTEL_GEN(dev_priv) < 11) 33331de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 33341de143ccSPankaj Bharadiya is_mst && (port == PORT_A || port == PORT_E)); 3335542dfab5SJosé Roberto de Souza else 33361de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, is_mst && port == PORT_A); 3337379bc100SJani Nikula 3338379bc100SJani Nikula intel_dp_set_link_params(intel_dp, crtc_state->port_clock, 3339379bc100SJani Nikula crtc_state->lane_count, is_mst); 3340379bc100SJani Nikula 3341379bc100SJani Nikula intel_edp_panel_on(intel_dp); 3342379bc100SJani Nikula 3343379bc100SJani Nikula intel_ddi_clk_select(encoder, crtc_state); 3344379bc100SJani Nikula 3345d8fe2ab6SMatt Roper if (!intel_phy_is_tc(dev_priv, phy) || 33463b2ed431SImre Deak dig_port->tc_mode != TC_PORT_TBT_ALT) 33473b2ed431SImre Deak intel_display_power_get(dev_priv, 33483b2ed431SImre Deak dig_port->ddi_io_power_domain); 3349379bc100SJani Nikula 33503b51be4eSClinton A Taylor icl_program_mg_dp_mode(dig_port, crtc_state); 3351379bc100SJani Nikula 3352379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 3353379bc100SJani Nikula icl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3354379bc100SJani Nikula level, encoder->type); 3355379bc100SJani Nikula else if (IS_CANNONLAKE(dev_priv)) 3356379bc100SJani Nikula cnl_ddi_vswing_sequence(encoder, level, encoder->type); 3357379bc100SJani Nikula else if (IS_GEN9_LP(dev_priv)) 3358379bc100SJani Nikula bxt_ddi_vswing_sequence(encoder, level, encoder->type); 3359379bc100SJani Nikula else 3360379bc100SJani Nikula intel_prepare_dp_ddi_buffers(encoder, crtc_state); 3361379bc100SJani Nikula 3362d8fe2ab6SMatt Roper if (intel_phy_is_combo(dev_priv, phy)) { 3363379bc100SJani Nikula bool lane_reversal = 3364379bc100SJani Nikula dig_port->saved_port_bits & DDI_BUF_PORT_REVERSAL; 3365379bc100SJani Nikula 3366dc867bc7SMatt Roper intel_combo_phy_power_up_lanes(dev_priv, phy, false, 3367379bc100SJani Nikula crtc_state->lane_count, 3368379bc100SJani Nikula lane_reversal); 3369379bc100SJani Nikula } 3370379bc100SJani Nikula 3371379bc100SJani Nikula intel_ddi_init_dp_buf_reg(encoder); 3372379bc100SJani Nikula if (!is_mst) 3373379bc100SJani Nikula intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON); 3374379bc100SJani Nikula intel_dp_sink_set_decompression_state(intel_dp, crtc_state, 3375379bc100SJani Nikula true); 3376379bc100SJani Nikula intel_dp_sink_set_fec_ready(intel_dp, crtc_state); 3377379bc100SJani Nikula intel_dp_start_link_train(intel_dp); 3378eadf6f91SManasi Navare if ((port != PORT_A || INTEL_GEN(dev_priv) >= 9) && 3379eadf6f91SManasi Navare !is_trans_port_sync_mode(crtc_state)) 3380379bc100SJani Nikula intel_dp_stop_link_train(intel_dp); 3381379bc100SJani Nikula 3382379bc100SJani Nikula intel_ddi_enable_fec(encoder, crtc_state); 3383379bc100SJani Nikula 3384379bc100SJani Nikula if (!is_mst) 338502a715c3SVille Syrjälä intel_ddi_enable_pipe_clock(encoder, crtc_state); 3386379bc100SJani Nikula 3387379bc100SJani Nikula intel_dsc_enable(encoder, crtc_state); 3388379bc100SJani Nikula } 3389379bc100SJani Nikula 3390ede9771dSVille Syrjälä static void intel_ddi_pre_enable_dp(struct intel_atomic_state *state, 3391ede9771dSVille Syrjälä struct intel_encoder *encoder, 339299389390SJosé Roberto de Souza const struct intel_crtc_state *crtc_state, 339399389390SJosé Roberto de Souza const struct drm_connector_state *conn_state) 339499389390SJosé Roberto de Souza { 339599389390SJosé Roberto de Souza struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 339699389390SJosé Roberto de Souza 339799389390SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 3398ede9771dSVille Syrjälä tgl_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state); 339999389390SJosé Roberto de Souza else 3400ede9771dSVille Syrjälä hsw_ddi_pre_enable_dp(state, encoder, crtc_state, conn_state); 34010c06fa15SGwan-gyeong Mun 3402bd8c9ccaSGwan-gyeong Mun /* MST will call a setting of MSA after an allocating of Virtual Channel 3403bd8c9ccaSGwan-gyeong Mun * from MST encoder pre_enable callback. 3404bd8c9ccaSGwan-gyeong Mun */ 34051fc1e8d4SJosé Roberto de Souza if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DP_MST)) { 34060c06fa15SGwan-gyeong Mun intel_ddi_set_dp_msa(crtc_state, conn_state); 34071c9d2eb2SJani Nikula 34081c9d2eb2SJani Nikula intel_dp_set_m_n(crtc_state, M1_N1); 340999389390SJosé Roberto de Souza } 34101fc1e8d4SJosé Roberto de Souza } 341199389390SJosé Roberto de Souza 3412ede9771dSVille Syrjälä static void intel_ddi_pre_enable_hdmi(struct intel_atomic_state *state, 3413ede9771dSVille Syrjälä struct intel_encoder *encoder, 3414379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3415379bc100SJani Nikula const struct drm_connector_state *conn_state) 3416379bc100SJani Nikula { 34170ba7ffeaSLucas De Marchi struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 34180ba7ffeaSLucas De Marchi struct intel_hdmi *intel_hdmi = &dig_port->hdmi; 3419379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 34200aed3bdeSJani Nikula int level = intel_ddi_hdmi_level(encoder); 3421379bc100SJani Nikula 3422379bc100SJani Nikula intel_dp_dual_mode_set_tmds_output(intel_hdmi, true); 3423379bc100SJani Nikula intel_ddi_clk_select(encoder, crtc_state); 3424379bc100SJani Nikula 3425379bc100SJani Nikula intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain); 3426379bc100SJani Nikula 34273b51be4eSClinton A Taylor icl_program_mg_dp_mode(dig_port, crtc_state); 3428379bc100SJani Nikula 3429978c3e53SClinton A Taylor if (INTEL_GEN(dev_priv) >= 12) 3430978c3e53SClinton A Taylor tgl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3431978c3e53SClinton A Taylor level, INTEL_OUTPUT_HDMI); 3432978c3e53SClinton A Taylor else if (INTEL_GEN(dev_priv) == 11) 3433379bc100SJani Nikula icl_ddi_vswing_sequence(encoder, crtc_state->port_clock, 3434379bc100SJani Nikula level, INTEL_OUTPUT_HDMI); 3435379bc100SJani Nikula else if (IS_CANNONLAKE(dev_priv)) 3436379bc100SJani Nikula cnl_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI); 3437379bc100SJani Nikula else if (IS_GEN9_LP(dev_priv)) 3438379bc100SJani Nikula bxt_ddi_vswing_sequence(encoder, level, INTEL_OUTPUT_HDMI); 3439379bc100SJani Nikula else 3440379bc100SJani Nikula intel_prepare_hdmi_ddi_buffers(encoder, level); 3441379bc100SJani Nikula 3442379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) 3443379bc100SJani Nikula skl_ddi_set_iboost(encoder, level, INTEL_OUTPUT_HDMI); 3444379bc100SJani Nikula 344502a715c3SVille Syrjälä intel_ddi_enable_pipe_clock(encoder, crtc_state); 3446379bc100SJani Nikula 34470ba7ffeaSLucas De Marchi dig_port->set_infoframes(encoder, 3448379bc100SJani Nikula crtc_state->has_infoframe, 3449379bc100SJani Nikula crtc_state, conn_state); 3450379bc100SJani Nikula } 3451379bc100SJani Nikula 3452ede9771dSVille Syrjälä static void intel_ddi_pre_enable(struct intel_atomic_state *state, 3453ede9771dSVille Syrjälä struct intel_encoder *encoder, 3454379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3455379bc100SJani Nikula const struct drm_connector_state *conn_state) 3456379bc100SJani Nikula { 34572225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); 3458379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 3459379bc100SJani Nikula enum pipe pipe = crtc->pipe; 3460379bc100SJani Nikula 3461379bc100SJani Nikula /* 3462379bc100SJani Nikula * When called from DP MST code: 3463379bc100SJani Nikula * - conn_state will be NULL 3464379bc100SJani Nikula * - encoder will be the main encoder (ie. mst->primary) 3465379bc100SJani Nikula * - the main connector associated with this port 3466379bc100SJani Nikula * won't be active or linked to a crtc 3467379bc100SJani Nikula * - crtc_state will be the state of the first stream to 3468379bc100SJani Nikula * be activated on this port, and it may not be the same 3469379bc100SJani Nikula * stream that will be deactivated last, but each stream 3470379bc100SJani Nikula * should have a state that is identical when it comes to 3471379bc100SJani Nikula * the DP link parameteres 3472379bc100SJani Nikula */ 3473379bc100SJani Nikula 34741de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, crtc_state->has_pch_encoder); 3475379bc100SJani Nikula 3476379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 3477379bc100SJani Nikula icl_map_plls_to_ports(encoder, crtc_state); 3478379bc100SJani Nikula 3479379bc100SJani Nikula intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); 3480379bc100SJani Nikula 3481379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) { 3482ede9771dSVille Syrjälä intel_ddi_pre_enable_hdmi(state, encoder, crtc_state, 3483ede9771dSVille Syrjälä conn_state); 3484379bc100SJani Nikula } else { 3485379bc100SJani Nikula struct intel_lspcon *lspcon = 3486b7d02c3aSVille Syrjälä enc_to_intel_lspcon(encoder); 3487379bc100SJani Nikula 3488ede9771dSVille Syrjälä intel_ddi_pre_enable_dp(state, encoder, crtc_state, 3489ede9771dSVille Syrjälä conn_state); 3490379bc100SJani Nikula if (lspcon->active) { 3491379bc100SJani Nikula struct intel_digital_port *dig_port = 3492b7d02c3aSVille Syrjälä enc_to_dig_port(encoder); 3493379bc100SJani Nikula 3494379bc100SJani Nikula dig_port->set_infoframes(encoder, 3495379bc100SJani Nikula crtc_state->has_infoframe, 3496379bc100SJani Nikula crtc_state, conn_state); 3497379bc100SJani Nikula } 3498379bc100SJani Nikula } 3499379bc100SJani Nikula } 3500379bc100SJani Nikula 3501379bc100SJani Nikula static void intel_disable_ddi_buf(struct intel_encoder *encoder, 3502379bc100SJani Nikula const struct intel_crtc_state *crtc_state) 3503379bc100SJani Nikula { 3504379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3505379bc100SJani Nikula enum port port = encoder->port; 3506379bc100SJani Nikula bool wait = false; 3507379bc100SJani Nikula u32 val; 3508379bc100SJani Nikula 3509f7960e7fSJani Nikula val = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 3510379bc100SJani Nikula if (val & DDI_BUF_CTL_ENABLE) { 3511379bc100SJani Nikula val &= ~DDI_BUF_CTL_ENABLE; 3512f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), val); 3513379bc100SJani Nikula wait = true; 3514379bc100SJani Nikula } 3515379bc100SJani Nikula 3516e468ff06SLucas De Marchi if (intel_crtc_has_dp_encoder(crtc_state)) { 3517b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 35184444df6eSLucas De Marchi 3519f7960e7fSJani Nikula val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 3520379bc100SJani Nikula val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 3521379bc100SJani Nikula val |= DP_TP_CTL_LINK_TRAIN_PAT1; 3522f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 3523e468ff06SLucas De Marchi } 3524379bc100SJani Nikula 3525379bc100SJani Nikula /* Disable FEC in DP Sink */ 3526379bc100SJani Nikula intel_ddi_disable_fec_state(encoder, crtc_state); 3527379bc100SJani Nikula 3528379bc100SJani Nikula if (wait) 3529379bc100SJani Nikula intel_wait_ddi_buf_idle(dev_priv, port); 3530379bc100SJani Nikula } 3531379bc100SJani Nikula 3532ede9771dSVille Syrjälä static void intel_ddi_post_disable_dp(struct intel_atomic_state *state, 3533ede9771dSVille Syrjälä struct intel_encoder *encoder, 3534379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3535379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3536379bc100SJani Nikula { 3537379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3538b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3539379bc100SJani Nikula struct intel_dp *intel_dp = &dig_port->dp; 3540379bc100SJani Nikula bool is_mst = intel_crtc_has_type(old_crtc_state, 3541379bc100SJani Nikula INTEL_OUTPUT_DP_MST); 3542d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3543379bc100SJani Nikula 3544c980216dSImre Deak if (!is_mst) 3545c980216dSImre Deak intel_dp_set_infoframes(encoder, false, 3546c980216dSImre Deak old_crtc_state, old_conn_state); 3547fa37a213SGwan-gyeong Mun 3548379bc100SJani Nikula /* 3549379bc100SJani Nikula * Power down sink before disabling the port, otherwise we end 3550379bc100SJani Nikula * up getting interrupts from the sink on detecting link loss. 3551379bc100SJani Nikula */ 3552379bc100SJani Nikula intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF); 355378eaaba3SJosé Roberto de Souza 3554c59053dcSJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) { 3555c59053dcSJosé Roberto de Souza if (is_mst) { 3556c59053dcSJosé Roberto de Souza enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder; 3557c59053dcSJosé Roberto de Souza u32 val; 3558c59053dcSJosé Roberto de Souza 3559f7960e7fSJani Nikula val = intel_de_read(dev_priv, 3560f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(cpu_transcoder)); 3561919e4f07SJosé Roberto de Souza val &= ~(TGL_TRANS_DDI_PORT_MASK | 3562919e4f07SJosé Roberto de Souza TRANS_DDI_MODE_SELECT_MASK); 3563f7960e7fSJani Nikula intel_de_write(dev_priv, 3564f7960e7fSJani Nikula TRANS_DDI_FUNC_CTL(cpu_transcoder), 3565f7960e7fSJani Nikula val); 3566c59053dcSJosé Roberto de Souza } 3567c59053dcSJosé Roberto de Souza } else { 3568c59053dcSJosé Roberto de Souza if (!is_mst) 356950a7efb2SJosé Roberto de Souza intel_ddi_disable_pipe_clock(old_crtc_state); 3570c59053dcSJosé Roberto de Souza } 3571379bc100SJani Nikula 3572379bc100SJani Nikula intel_disable_ddi_buf(encoder, old_crtc_state); 3573379bc100SJani Nikula 35743ca8f191SJosé Roberto de Souza /* 35753ca8f191SJosé Roberto de Souza * From TGL spec: "If single stream or multi-stream master transcoder: 35763ca8f191SJosé Roberto de Souza * Configure Transcoder Clock select to direct no clock to the 35773ca8f191SJosé Roberto de Souza * transcoder" 35783ca8f191SJosé Roberto de Souza */ 35793ca8f191SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 35803ca8f191SJosé Roberto de Souza intel_ddi_disable_pipe_clock(old_crtc_state); 35813ca8f191SJosé Roberto de Souza 3582379bc100SJani Nikula intel_edp_panel_vdd_on(intel_dp); 3583379bc100SJani Nikula intel_edp_panel_off(intel_dp); 3584379bc100SJani Nikula 3585d8fe2ab6SMatt Roper if (!intel_phy_is_tc(dev_priv, phy) || 35863b2ed431SImre Deak dig_port->tc_mode != TC_PORT_TBT_ALT) 3587379bc100SJani Nikula intel_display_power_put_unchecked(dev_priv, 3588379bc100SJani Nikula dig_port->ddi_io_power_domain); 3589379bc100SJani Nikula 3590379bc100SJani Nikula intel_ddi_clk_disable(encoder); 3591379bc100SJani Nikula } 3592379bc100SJani Nikula 3593ede9771dSVille Syrjälä static void intel_ddi_post_disable_hdmi(struct intel_atomic_state *state, 3594ede9771dSVille Syrjälä struct intel_encoder *encoder, 3595379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3596379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3597379bc100SJani Nikula { 3598379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3599b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3600379bc100SJani Nikula struct intel_hdmi *intel_hdmi = &dig_port->hdmi; 3601379bc100SJani Nikula 3602379bc100SJani Nikula dig_port->set_infoframes(encoder, false, 3603379bc100SJani Nikula old_crtc_state, old_conn_state); 3604379bc100SJani Nikula 3605379bc100SJani Nikula intel_ddi_disable_pipe_clock(old_crtc_state); 3606379bc100SJani Nikula 3607379bc100SJani Nikula intel_disable_ddi_buf(encoder, old_crtc_state); 3608379bc100SJani Nikula 3609379bc100SJani Nikula intel_display_power_put_unchecked(dev_priv, 3610379bc100SJani Nikula dig_port->ddi_io_power_domain); 3611379bc100SJani Nikula 3612379bc100SJani Nikula intel_ddi_clk_disable(encoder); 3613379bc100SJani Nikula 3614379bc100SJani Nikula intel_dp_dual_mode_set_tmds_output(intel_hdmi, false); 3615379bc100SJani Nikula } 3616379bc100SJani Nikula 3617ede9771dSVille Syrjälä static void intel_ddi_post_disable(struct intel_atomic_state *state, 3618ede9771dSVille Syrjälä struct intel_encoder *encoder, 3619379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3620379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3621379bc100SJani Nikula { 3622379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3623b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 362417bef9baSVille Syrjälä enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 362517bef9baSVille Syrjälä bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 3626379bc100SJani Nikula 36277829c92bSVille Syrjälä if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST)) { 3628773b4b54SVille Syrjälä intel_crtc_vblank_off(old_crtc_state); 3629773b4b54SVille Syrjälä 3630773b4b54SVille Syrjälä intel_disable_pipe(old_crtc_state); 3631773b4b54SVille Syrjälä 3632773b4b54SVille Syrjälä intel_ddi_disable_transcoder_func(old_crtc_state); 3633773b4b54SVille Syrjälä 3634773b4b54SVille Syrjälä intel_dsc_disable(old_crtc_state); 3635773b4b54SVille Syrjälä 3636773b4b54SVille Syrjälä if (INTEL_GEN(dev_priv) >= 9) 3637f6df4d46SLucas De Marchi skl_scaler_disable(old_crtc_state); 3638773b4b54SVille Syrjälä else 36399eae5e27SLucas De Marchi ilk_pfit_disable(old_crtc_state); 36407829c92bSVille Syrjälä } 3641773b4b54SVille Syrjälä 3642379bc100SJani Nikula /* 3643379bc100SJani Nikula * When called from DP MST code: 3644379bc100SJani Nikula * - old_conn_state will be NULL 3645379bc100SJani Nikula * - encoder will be the main encoder (ie. mst->primary) 3646379bc100SJani Nikula * - the main connector associated with this port 3647379bc100SJani Nikula * won't be active or linked to a crtc 3648379bc100SJani Nikula * - old_crtc_state will be the state of the last stream to 3649379bc100SJani Nikula * be deactivated on this port, and it may not be the same 3650379bc100SJani Nikula * stream that was activated last, but each stream 3651379bc100SJani Nikula * should have a state that is identical when it comes to 3652379bc100SJani Nikula * the DP link parameteres 3653379bc100SJani Nikula */ 3654379bc100SJani Nikula 3655379bc100SJani Nikula if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI)) 3656ede9771dSVille Syrjälä intel_ddi_post_disable_hdmi(state, encoder, old_crtc_state, 3657ede9771dSVille Syrjälä old_conn_state); 3658379bc100SJani Nikula else 3659ede9771dSVille Syrjälä intel_ddi_post_disable_dp(state, encoder, old_crtc_state, 3660ede9771dSVille Syrjälä old_conn_state); 3661379bc100SJani Nikula 3662379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 3663379bc100SJani Nikula icl_unmap_plls_to_ports(encoder); 366417bef9baSVille Syrjälä 366517bef9baSVille Syrjälä if (intel_crtc_has_dp_encoder(old_crtc_state) || is_tc_port) 366617bef9baSVille Syrjälä intel_display_power_put_unchecked(dev_priv, 366717bef9baSVille Syrjälä intel_ddi_main_link_aux_domain(dig_port)); 366817bef9baSVille Syrjälä 366917bef9baSVille Syrjälä if (is_tc_port) 367017bef9baSVille Syrjälä intel_tc_port_put_link(dig_port); 3671379bc100SJani Nikula } 3672379bc100SJani Nikula 3673ede9771dSVille Syrjälä void intel_ddi_fdi_post_disable(struct intel_atomic_state *state, 3674ede9771dSVille Syrjälä struct intel_encoder *encoder, 3675379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3676379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3677379bc100SJani Nikula { 3678379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3679379bc100SJani Nikula u32 val; 3680379bc100SJani Nikula 3681379bc100SJani Nikula /* 3682379bc100SJani Nikula * Bspec lists this as both step 13 (before DDI_BUF_CTL disable) 3683379bc100SJani Nikula * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN, 3684379bc100SJani Nikula * step 13 is the correct place for it. Step 18 is where it was 3685379bc100SJani Nikula * originally before the BUN. 3686379bc100SJani Nikula */ 3687f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A)); 3688379bc100SJani Nikula val &= ~FDI_RX_ENABLE; 3689f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val); 3690379bc100SJani Nikula 3691379bc100SJani Nikula intel_disable_ddi_buf(encoder, old_crtc_state); 3692379bc100SJani Nikula intel_ddi_clk_disable(encoder); 3693379bc100SJani Nikula 3694f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_MISC(PIPE_A)); 3695379bc100SJani Nikula val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK); 3696379bc100SJani Nikula val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2); 3697f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_MISC(PIPE_A), val); 3698379bc100SJani Nikula 3699f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A)); 3700379bc100SJani Nikula val &= ~FDI_PCDCLK; 3701f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val); 3702379bc100SJani Nikula 3703f7960e7fSJani Nikula val = intel_de_read(dev_priv, FDI_RX_CTL(PIPE_A)); 3704379bc100SJani Nikula val &= ~FDI_RX_PLL_ENABLE; 3705f7960e7fSJani Nikula intel_de_write(dev_priv, FDI_RX_CTL(PIPE_A), val); 3706379bc100SJani Nikula } 3707379bc100SJani Nikula 3708d82a855aSVille Syrjälä static void trans_port_sync_stop_link_train(struct intel_atomic_state *state, 3709d82a855aSVille Syrjälä struct intel_encoder *encoder, 3710d82a855aSVille Syrjälä const struct intel_crtc_state *crtc_state) 3711d82a855aSVille Syrjälä { 3712d82a855aSVille Syrjälä const struct drm_connector_state *conn_state; 3713d82a855aSVille Syrjälä struct drm_connector *conn; 3714d82a855aSVille Syrjälä int i; 3715d82a855aSVille Syrjälä 3716d82a855aSVille Syrjälä if (!crtc_state->sync_mode_slaves_mask) 3717d82a855aSVille Syrjälä return; 3718d82a855aSVille Syrjälä 3719d82a855aSVille Syrjälä for_each_new_connector_in_state(&state->base, conn, conn_state, i) { 3720d82a855aSVille Syrjälä struct intel_encoder *slave_encoder = 3721d82a855aSVille Syrjälä to_intel_encoder(conn_state->best_encoder); 3722d82a855aSVille Syrjälä struct intel_crtc *slave_crtc = to_intel_crtc(conn_state->crtc); 3723d82a855aSVille Syrjälä const struct intel_crtc_state *slave_crtc_state; 3724d82a855aSVille Syrjälä 3725d82a855aSVille Syrjälä if (!slave_crtc) 3726d82a855aSVille Syrjälä continue; 3727d82a855aSVille Syrjälä 3728d82a855aSVille Syrjälä slave_crtc_state = 3729d82a855aSVille Syrjälä intel_atomic_get_new_crtc_state(state, slave_crtc); 3730d82a855aSVille Syrjälä 3731d82a855aSVille Syrjälä if (slave_crtc_state->master_transcoder != 3732d82a855aSVille Syrjälä crtc_state->cpu_transcoder) 3733d82a855aSVille Syrjälä continue; 3734d82a855aSVille Syrjälä 3735d82a855aSVille Syrjälä intel_dp_stop_link_train(enc_to_intel_dp(slave_encoder)); 3736d82a855aSVille Syrjälä } 3737d82a855aSVille Syrjälä 3738d82a855aSVille Syrjälä usleep_range(200, 400); 3739d82a855aSVille Syrjälä 3740d82a855aSVille Syrjälä intel_dp_stop_link_train(enc_to_intel_dp(encoder)); 3741d82a855aSVille Syrjälä } 3742d82a855aSVille Syrjälä 3743ede9771dSVille Syrjälä static void intel_enable_ddi_dp(struct intel_atomic_state *state, 3744ede9771dSVille Syrjälä struct intel_encoder *encoder, 3745379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3746379bc100SJani Nikula const struct drm_connector_state *conn_state) 3747379bc100SJani Nikula { 3748379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3749b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3750379bc100SJani Nikula enum port port = encoder->port; 3751379bc100SJani Nikula 3752379bc100SJani Nikula if (port == PORT_A && INTEL_GEN(dev_priv) < 9) 3753379bc100SJani Nikula intel_dp_stop_link_train(intel_dp); 3754379bc100SJani Nikula 3755379bc100SJani Nikula intel_edp_backlight_on(crtc_state, conn_state); 37567a00e68bSGwan-gyeong Mun intel_psr_enable(intel_dp, crtc_state, conn_state); 37571bf3657cSGwan-gyeong Mun intel_dp_set_infoframes(encoder, true, crtc_state, conn_state); 3758379bc100SJani Nikula intel_edp_drrs_enable(intel_dp, crtc_state); 3759379bc100SJani Nikula 3760379bc100SJani Nikula if (crtc_state->has_audio) 3761379bc100SJani Nikula intel_audio_codec_enable(encoder, crtc_state, conn_state); 3762d82a855aSVille Syrjälä 3763d82a855aSVille Syrjälä trans_port_sync_stop_link_train(state, encoder, crtc_state); 3764379bc100SJani Nikula } 3765379bc100SJani Nikula 3766379bc100SJani Nikula static i915_reg_t 3767379bc100SJani Nikula gen9_chicken_trans_reg_by_port(struct drm_i915_private *dev_priv, 3768379bc100SJani Nikula enum port port) 3769379bc100SJani Nikula { 377012c4d4c1SVille Syrjälä static const enum transcoder trans[] = { 377112c4d4c1SVille Syrjälä [PORT_A] = TRANSCODER_EDP, 377212c4d4c1SVille Syrjälä [PORT_B] = TRANSCODER_A, 377312c4d4c1SVille Syrjälä [PORT_C] = TRANSCODER_B, 377412c4d4c1SVille Syrjälä [PORT_D] = TRANSCODER_C, 377512c4d4c1SVille Syrjälä [PORT_E] = TRANSCODER_A, 3776379bc100SJani Nikula }; 3777379bc100SJani Nikula 37781de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, INTEL_GEN(dev_priv) < 9); 3779379bc100SJani Nikula 37801de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, port < PORT_A || port > PORT_E)) 3781379bc100SJani Nikula port = PORT_A; 3782379bc100SJani Nikula 378312c4d4c1SVille Syrjälä return CHICKEN_TRANS(trans[port]); 3784379bc100SJani Nikula } 3785379bc100SJani Nikula 3786ede9771dSVille Syrjälä static void intel_enable_ddi_hdmi(struct intel_atomic_state *state, 3787ede9771dSVille Syrjälä struct intel_encoder *encoder, 3788379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3789379bc100SJani Nikula const struct drm_connector_state *conn_state) 3790379bc100SJani Nikula { 3791379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3792b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3793379bc100SJani Nikula struct drm_connector *connector = conn_state->connector; 3794379bc100SJani Nikula enum port port = encoder->port; 3795379bc100SJani Nikula 3796379bc100SJani Nikula if (!intel_hdmi_handle_sink_scrambling(encoder, connector, 3797379bc100SJani Nikula crtc_state->hdmi_high_tmds_clock_ratio, 3798379bc100SJani Nikula crtc_state->hdmi_scrambling)) 379947bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 380047bdb1caSJani Nikula "[CONNECTOR:%d:%s] Failed to configure sink scrambling/TMDS bit clock ratio\n", 3801379bc100SJani Nikula connector->base.id, connector->name); 3802379bc100SJani Nikula 3803379bc100SJani Nikula /* Display WA #1143: skl,kbl,cfl */ 3804379bc100SJani Nikula if (IS_GEN9_BC(dev_priv)) { 3805379bc100SJani Nikula /* 3806379bc100SJani Nikula * For some reason these chicken bits have been 3807379bc100SJani Nikula * stuffed into a transcoder register, event though 3808379bc100SJani Nikula * the bits affect a specific DDI port rather than 3809379bc100SJani Nikula * a specific transcoder. 3810379bc100SJani Nikula */ 3811379bc100SJani Nikula i915_reg_t reg = gen9_chicken_trans_reg_by_port(dev_priv, port); 3812379bc100SJani Nikula u32 val; 3813379bc100SJani Nikula 3814f7960e7fSJani Nikula val = intel_de_read(dev_priv, reg); 3815379bc100SJani Nikula 3816379bc100SJani Nikula if (port == PORT_E) 3817379bc100SJani Nikula val |= DDIE_TRAINING_OVERRIDE_ENABLE | 3818379bc100SJani Nikula DDIE_TRAINING_OVERRIDE_VALUE; 3819379bc100SJani Nikula else 3820379bc100SJani Nikula val |= DDI_TRAINING_OVERRIDE_ENABLE | 3821379bc100SJani Nikula DDI_TRAINING_OVERRIDE_VALUE; 3822379bc100SJani Nikula 3823f7960e7fSJani Nikula intel_de_write(dev_priv, reg, val); 3824f7960e7fSJani Nikula intel_de_posting_read(dev_priv, reg); 3825379bc100SJani Nikula 3826379bc100SJani Nikula udelay(1); 3827379bc100SJani Nikula 3828379bc100SJani Nikula if (port == PORT_E) 3829379bc100SJani Nikula val &= ~(DDIE_TRAINING_OVERRIDE_ENABLE | 3830379bc100SJani Nikula DDIE_TRAINING_OVERRIDE_VALUE); 3831379bc100SJani Nikula else 3832379bc100SJani Nikula val &= ~(DDI_TRAINING_OVERRIDE_ENABLE | 3833379bc100SJani Nikula DDI_TRAINING_OVERRIDE_VALUE); 3834379bc100SJani Nikula 3835f7960e7fSJani Nikula intel_de_write(dev_priv, reg, val); 3836379bc100SJani Nikula } 3837379bc100SJani Nikula 3838379bc100SJani Nikula /* In HDMI/DVI mode, the port width, and swing/emphasis values 3839379bc100SJani Nikula * are ignored so nothing special needs to be done besides 3840379bc100SJani Nikula * enabling the port. 3841379bc100SJani Nikula */ 3842f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), 3843379bc100SJani Nikula dig_port->saved_port_bits | DDI_BUF_CTL_ENABLE); 3844379bc100SJani Nikula 3845379bc100SJani Nikula if (crtc_state->has_audio) 3846379bc100SJani Nikula intel_audio_codec_enable(encoder, crtc_state, conn_state); 3847379bc100SJani Nikula } 3848379bc100SJani Nikula 3849ede9771dSVille Syrjälä static void intel_enable_ddi(struct intel_atomic_state *state, 3850ede9771dSVille Syrjälä struct intel_encoder *encoder, 3851379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3852379bc100SJani Nikula const struct drm_connector_state *conn_state) 3853379bc100SJani Nikula { 38548b4f2137SPankaj Bharadiya drm_WARN_ON(state->base.dev, crtc_state->has_pch_encoder); 385521fd23acSJani Nikula 3856eed22a46SVille Syrjälä intel_ddi_enable_transcoder_func(encoder, crtc_state); 38577c2fedd7SVille Syrjälä 385821fd23acSJani Nikula intel_enable_pipe(crtc_state); 385921fd23acSJani Nikula 386021fd23acSJani Nikula intel_crtc_vblank_on(crtc_state); 386121fd23acSJani Nikula 3862379bc100SJani Nikula if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) 3863ede9771dSVille Syrjälä intel_enable_ddi_hdmi(state, encoder, crtc_state, conn_state); 3864379bc100SJani Nikula else 3865ede9771dSVille Syrjälä intel_enable_ddi_dp(state, encoder, crtc_state, conn_state); 3866379bc100SJani Nikula 3867379bc100SJani Nikula /* Enable hdcp if it's desired */ 3868379bc100SJani Nikula if (conn_state->content_protection == 3869379bc100SJani Nikula DRM_MODE_CONTENT_PROTECTION_DESIRED) 3870d456512cSRamalingam C intel_hdcp_enable(to_intel_connector(conn_state->connector), 387167e1d5edSVille Syrjälä crtc_state->cpu_transcoder, 3872d456512cSRamalingam C (u8)conn_state->hdcp_content_type); 3873379bc100SJani Nikula } 3874379bc100SJani Nikula 3875ede9771dSVille Syrjälä static void intel_disable_ddi_dp(struct intel_atomic_state *state, 3876ede9771dSVille Syrjälä struct intel_encoder *encoder, 3877379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3878379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3879379bc100SJani Nikula { 3880b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3881379bc100SJani Nikula 3882379bc100SJani Nikula intel_dp->link_trained = false; 3883379bc100SJani Nikula 3884379bc100SJani Nikula if (old_crtc_state->has_audio) 3885379bc100SJani Nikula intel_audio_codec_disable(encoder, 3886379bc100SJani Nikula old_crtc_state, old_conn_state); 3887379bc100SJani Nikula 3888379bc100SJani Nikula intel_edp_drrs_disable(intel_dp, old_crtc_state); 3889379bc100SJani Nikula intel_psr_disable(intel_dp, old_crtc_state); 3890379bc100SJani Nikula intel_edp_backlight_off(old_conn_state); 3891379bc100SJani Nikula /* Disable the decompression in DP Sink */ 3892379bc100SJani Nikula intel_dp_sink_set_decompression_state(intel_dp, old_crtc_state, 3893379bc100SJani Nikula false); 3894379bc100SJani Nikula } 3895379bc100SJani Nikula 3896ede9771dSVille Syrjälä static void intel_disable_ddi_hdmi(struct intel_atomic_state *state, 3897ede9771dSVille Syrjälä struct intel_encoder *encoder, 3898379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3899379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3900379bc100SJani Nikula { 390147bdb1caSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev); 3902379bc100SJani Nikula struct drm_connector *connector = old_conn_state->connector; 3903379bc100SJani Nikula 3904379bc100SJani Nikula if (old_crtc_state->has_audio) 3905379bc100SJani Nikula intel_audio_codec_disable(encoder, 3906379bc100SJani Nikula old_crtc_state, old_conn_state); 3907379bc100SJani Nikula 3908379bc100SJani Nikula if (!intel_hdmi_handle_sink_scrambling(encoder, connector, 3909379bc100SJani Nikula false, false)) 391047bdb1caSJani Nikula drm_dbg_kms(&i915->drm, 391147bdb1caSJani Nikula "[CONNECTOR:%d:%s] Failed to reset sink scrambling/TMDS bit clock ratio\n", 3912379bc100SJani Nikula connector->base.id, connector->name); 3913379bc100SJani Nikula } 3914379bc100SJani Nikula 3915ede9771dSVille Syrjälä static void intel_disable_ddi(struct intel_atomic_state *state, 3916ede9771dSVille Syrjälä struct intel_encoder *encoder, 3917379bc100SJani Nikula const struct intel_crtc_state *old_crtc_state, 3918379bc100SJani Nikula const struct drm_connector_state *old_conn_state) 3919379bc100SJani Nikula { 3920379bc100SJani Nikula intel_hdcp_disable(to_intel_connector(old_conn_state->connector)); 3921379bc100SJani Nikula 3922379bc100SJani Nikula if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_HDMI)) 3923ede9771dSVille Syrjälä intel_disable_ddi_hdmi(state, encoder, old_crtc_state, 3924ede9771dSVille Syrjälä old_conn_state); 3925379bc100SJani Nikula else 3926ede9771dSVille Syrjälä intel_disable_ddi_dp(state, encoder, old_crtc_state, 3927ede9771dSVille Syrjälä old_conn_state); 3928379bc100SJani Nikula } 3929379bc100SJani Nikula 3930ede9771dSVille Syrjälä static void intel_ddi_update_pipe_dp(struct intel_atomic_state *state, 3931ede9771dSVille Syrjälä struct intel_encoder *encoder, 3932379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3933379bc100SJani Nikula const struct drm_connector_state *conn_state) 3934379bc100SJani Nikula { 3935b7d02c3aSVille Syrjälä struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 3936379bc100SJani Nikula 39370c06fa15SGwan-gyeong Mun intel_ddi_set_dp_msa(crtc_state, conn_state); 3938379bc100SJani Nikula 39397a00e68bSGwan-gyeong Mun intel_psr_update(intel_dp, crtc_state, conn_state); 394076d45d06SGwan-gyeong Mun intel_dp_set_infoframes(encoder, true, crtc_state, conn_state); 3941379bc100SJani Nikula intel_edp_drrs_enable(intel_dp, crtc_state); 3942379bc100SJani Nikula 3943ede9771dSVille Syrjälä intel_panel_update_backlight(state, encoder, crtc_state, conn_state); 3944379bc100SJani Nikula } 3945379bc100SJani Nikula 3946ede9771dSVille Syrjälä static void intel_ddi_update_pipe(struct intel_atomic_state *state, 3947ede9771dSVille Syrjälä struct intel_encoder *encoder, 3948379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3949379bc100SJani Nikula const struct drm_connector_state *conn_state) 3950379bc100SJani Nikula { 3951d456512cSRamalingam C 3952379bc100SJani Nikula if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) 3953ede9771dSVille Syrjälä intel_ddi_update_pipe_dp(state, encoder, crtc_state, 3954ede9771dSVille Syrjälä conn_state); 3955379bc100SJani Nikula 3956ede9771dSVille Syrjälä intel_hdcp_update_pipe(state, encoder, crtc_state, conn_state); 3957379bc100SJani Nikula } 3958379bc100SJani Nikula 3959379bc100SJani Nikula static void 396024a7bfe0SImre Deak intel_ddi_update_prepare(struct intel_atomic_state *state, 396124a7bfe0SImre Deak struct intel_encoder *encoder, 396224a7bfe0SImre Deak struct intel_crtc *crtc) 396324a7bfe0SImre Deak { 396424a7bfe0SImre Deak struct intel_crtc_state *crtc_state = 396524a7bfe0SImre Deak crtc ? intel_atomic_get_new_crtc_state(state, crtc) : NULL; 396624a7bfe0SImre Deak int required_lanes = crtc_state ? crtc_state->lane_count : 1; 396724a7bfe0SImre Deak 39688b4f2137SPankaj Bharadiya drm_WARN_ON(state->base.dev, crtc && crtc->active); 396924a7bfe0SImre Deak 3970b7d02c3aSVille Syrjälä intel_tc_port_get_link(enc_to_dig_port(encoder), 3971b7d02c3aSVille Syrjälä required_lanes); 39721326a92cSMaarten Lankhorst if (crtc_state && crtc_state->hw.active) 397324a7bfe0SImre Deak intel_update_active_dpll(state, crtc, encoder); 397424a7bfe0SImre Deak } 397524a7bfe0SImre Deak 397624a7bfe0SImre Deak static void 397724a7bfe0SImre Deak intel_ddi_update_complete(struct intel_atomic_state *state, 397824a7bfe0SImre Deak struct intel_encoder *encoder, 397924a7bfe0SImre Deak struct intel_crtc *crtc) 398024a7bfe0SImre Deak { 3981b7d02c3aSVille Syrjälä intel_tc_port_put_link(enc_to_dig_port(encoder)); 398224a7bfe0SImre Deak } 398324a7bfe0SImre Deak 398424a7bfe0SImre Deak static void 3985ede9771dSVille Syrjälä intel_ddi_pre_pll_enable(struct intel_atomic_state *state, 3986ede9771dSVille Syrjälä struct intel_encoder *encoder, 3987379bc100SJani Nikula const struct intel_crtc_state *crtc_state, 3988379bc100SJani Nikula const struct drm_connector_state *conn_state) 3989379bc100SJani Nikula { 3990379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 3991b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 3992d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, encoder->port); 3993d8fe2ab6SMatt Roper bool is_tc_port = intel_phy_is_tc(dev_priv, phy); 3994379bc100SJani Nikula 399524a7bfe0SImre Deak if (is_tc_port) 399624a7bfe0SImre Deak intel_tc_port_get_link(dig_port, crtc_state->lane_count); 399724a7bfe0SImre Deak 399824a7bfe0SImre Deak if (intel_crtc_has_dp_encoder(crtc_state) || is_tc_port) 3999379bc100SJani Nikula intel_display_power_get(dev_priv, 4000379bc100SJani Nikula intel_ddi_main_link_aux_domain(dig_port)); 4001379bc100SJani Nikula 40029d44dcb9SLucas De Marchi if (is_tc_port && dig_port->tc_mode != TC_PORT_TBT_ALT) 40039d44dcb9SLucas De Marchi /* 40049d44dcb9SLucas De Marchi * Program the lane count for static/dynamic connections on 40059d44dcb9SLucas De Marchi * Type-C ports. Skip this step for TBT. 40069d44dcb9SLucas De Marchi */ 40079d44dcb9SLucas De Marchi intel_tc_port_set_fia_lane_count(dig_port, crtc_state->lane_count); 40089d44dcb9SLucas De Marchi else if (IS_GEN9_LP(dev_priv)) 4009379bc100SJani Nikula bxt_ddi_phy_set_lane_optim_mask(encoder, 4010379bc100SJani Nikula crtc_state->lane_lat_optim_mask); 4011379bc100SJani Nikula } 4012379bc100SJani Nikula 4013379bc100SJani Nikula static void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp) 4014379bc100SJani Nikula { 40157801f3b7SLucas De Marchi struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp); 40167801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 40177801f3b7SLucas De Marchi enum port port = dig_port->base.port; 401835ac28a8SLucas De Marchi u32 dp_tp_ctl, ddi_buf_ctl; 4019379bc100SJani Nikula bool wait = false; 4020379bc100SJani Nikula 4021f7960e7fSJani Nikula dp_tp_ctl = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 402235ac28a8SLucas De Marchi 402335ac28a8SLucas De Marchi if (dp_tp_ctl & DP_TP_CTL_ENABLE) { 4024f7960e7fSJani Nikula ddi_buf_ctl = intel_de_read(dev_priv, DDI_BUF_CTL(port)); 402535ac28a8SLucas De Marchi if (ddi_buf_ctl & DDI_BUF_CTL_ENABLE) { 4026f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), 402735ac28a8SLucas De Marchi ddi_buf_ctl & ~DDI_BUF_CTL_ENABLE); 4028379bc100SJani Nikula wait = true; 4029379bc100SJani Nikula } 4030379bc100SJani Nikula 403135ac28a8SLucas De Marchi dp_tp_ctl &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK); 403235ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_LINK_TRAIN_PAT1; 4033f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, dp_tp_ctl); 4034f7960e7fSJani Nikula intel_de_posting_read(dev_priv, intel_dp->regs.dp_tp_ctl); 4035379bc100SJani Nikula 4036379bc100SJani Nikula if (wait) 4037379bc100SJani Nikula intel_wait_ddi_buf_idle(dev_priv, port); 4038379bc100SJani Nikula } 4039379bc100SJani Nikula 404035ac28a8SLucas De Marchi dp_tp_ctl = DP_TP_CTL_ENABLE | 4041379bc100SJani Nikula DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE; 4042379bc100SJani Nikula if (intel_dp->link_mst) 404335ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_MODE_MST; 4044379bc100SJani Nikula else { 404535ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_MODE_SST; 4046379bc100SJani Nikula if (drm_dp_enhanced_frame_cap(intel_dp->dpcd)) 404735ac28a8SLucas De Marchi dp_tp_ctl |= DP_TP_CTL_ENHANCED_FRAME_ENABLE; 4048379bc100SJani Nikula } 4049f7960e7fSJani Nikula intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, dp_tp_ctl); 4050f7960e7fSJani Nikula intel_de_posting_read(dev_priv, intel_dp->regs.dp_tp_ctl); 4051379bc100SJani Nikula 4052379bc100SJani Nikula intel_dp->DP |= DDI_BUF_CTL_ENABLE; 4053f7960e7fSJani Nikula intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP); 4054f7960e7fSJani Nikula intel_de_posting_read(dev_priv, DDI_BUF_CTL(port)); 4055379bc100SJani Nikula 4056e828da30SManasi Navare intel_wait_ddi_buf_active(dev_priv, port); 4057379bc100SJani Nikula } 4058379bc100SJani Nikula 4059eee3f911SVille Syrjälä static void intel_ddi_set_link_train(struct intel_dp *intel_dp, 4060eee3f911SVille Syrjälä u8 dp_train_pat) 4061eee3f911SVille Syrjälä { 4062eee3f911SVille Syrjälä struct drm_i915_private *dev_priv = dp_to_i915(intel_dp); 4063eee3f911SVille Syrjälä u8 train_pat_mask = drm_dp_training_pattern_mask(intel_dp->dpcd); 4064eee3f911SVille Syrjälä enum port port = dp_to_dig_port(intel_dp)->base.port; 4065eee3f911SVille Syrjälä u32 temp; 4066eee3f911SVille Syrjälä 4067eee3f911SVille Syrjälä temp = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 4068eee3f911SVille Syrjälä 4069eee3f911SVille Syrjälä if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE) 4070eee3f911SVille Syrjälä temp |= DP_TP_CTL_SCRAMBLE_DISABLE; 4071eee3f911SVille Syrjälä else 4072eee3f911SVille Syrjälä temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE; 4073eee3f911SVille Syrjälä 4074eee3f911SVille Syrjälä temp &= ~DP_TP_CTL_LINK_TRAIN_MASK; 4075eee3f911SVille Syrjälä switch (dp_train_pat & train_pat_mask) { 4076eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_DISABLE: 4077eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_NORMAL; 4078eee3f911SVille Syrjälä break; 4079eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_1: 4080eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT1; 4081eee3f911SVille Syrjälä break; 4082eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_2: 4083eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT2; 4084eee3f911SVille Syrjälä break; 4085eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_3: 4086eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT3; 4087eee3f911SVille Syrjälä break; 4088eee3f911SVille Syrjälä case DP_TRAINING_PATTERN_4: 4089eee3f911SVille Syrjälä temp |= DP_TP_CTL_LINK_TRAIN_PAT4; 4090eee3f911SVille Syrjälä break; 4091eee3f911SVille Syrjälä } 4092eee3f911SVille Syrjälä 4093eee3f911SVille Syrjälä intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, temp); 4094eee3f911SVille Syrjälä 4095eee3f911SVille Syrjälä intel_de_write(dev_priv, DDI_BUF_CTL(port), intel_dp->DP); 4096eee3f911SVille Syrjälä intel_de_posting_read(dev_priv, DDI_BUF_CTL(port)); 4097eee3f911SVille Syrjälä } 4098eee3f911SVille Syrjälä 40998fdda385SVille Syrjälä static void intel_ddi_set_idle_link_train(struct intel_dp *intel_dp) 41008fdda385SVille Syrjälä { 41018fdda385SVille Syrjälä struct intel_encoder *encoder = &dp_to_dig_port(intel_dp)->base; 41028fdda385SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 41038fdda385SVille Syrjälä enum port port = encoder->port; 41048fdda385SVille Syrjälä u32 val; 41058fdda385SVille Syrjälä 41068fdda385SVille Syrjälä val = intel_de_read(dev_priv, intel_dp->regs.dp_tp_ctl); 41078fdda385SVille Syrjälä val &= ~DP_TP_CTL_LINK_TRAIN_MASK; 41088fdda385SVille Syrjälä val |= DP_TP_CTL_LINK_TRAIN_IDLE; 41098fdda385SVille Syrjälä intel_de_write(dev_priv, intel_dp->regs.dp_tp_ctl, val); 41108fdda385SVille Syrjälä 41118fdda385SVille Syrjälä /* 41128fdda385SVille Syrjälä * Until TGL on PORT_A we can have only eDP in SST mode. There the only 41138fdda385SVille Syrjälä * reason we need to set idle transmission mode is to work around a HW 41148fdda385SVille Syrjälä * issue where we enable the pipe while not in idle link-training mode. 41158fdda385SVille Syrjälä * In this case there is requirement to wait for a minimum number of 41168fdda385SVille Syrjälä * idle patterns to be sent. 41178fdda385SVille Syrjälä */ 41188fdda385SVille Syrjälä if (port == PORT_A && INTEL_GEN(dev_priv) < 12) 41198fdda385SVille Syrjälä return; 41208fdda385SVille Syrjälä 41218fdda385SVille Syrjälä if (intel_de_wait_for_set(dev_priv, intel_dp->regs.dp_tp_status, 41228fdda385SVille Syrjälä DP_TP_STATUS_IDLE_DONE, 1)) 41238fdda385SVille Syrjälä drm_err(&dev_priv->drm, 41248fdda385SVille Syrjälä "Timed out waiting for DP idle patterns\n"); 41258fdda385SVille Syrjälä } 41268fdda385SVille Syrjälä 4127379bc100SJani Nikula static bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv, 4128379bc100SJani Nikula enum transcoder cpu_transcoder) 4129379bc100SJani Nikula { 4130379bc100SJani Nikula if (cpu_transcoder == TRANSCODER_EDP) 4131379bc100SJani Nikula return false; 4132379bc100SJani Nikula 4133379bc100SJani Nikula if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) 4134379bc100SJani Nikula return false; 4135379bc100SJani Nikula 4136f7960e7fSJani Nikula return intel_de_read(dev_priv, HSW_AUD_PIN_ELD_CP_VLD) & 4137379bc100SJani Nikula AUDIO_OUTPUT_ENABLE(cpu_transcoder); 4138379bc100SJani Nikula } 4139379bc100SJani Nikula 4140379bc100SJani Nikula void intel_ddi_compute_min_voltage_level(struct drm_i915_private *dev_priv, 4141379bc100SJani Nikula struct intel_crtc_state *crtc_state) 4142379bc100SJani Nikula { 41430fde0b1dSMatt Roper if (INTEL_GEN(dev_priv) >= 12 && crtc_state->port_clock > 594000) 41440fde0b1dSMatt Roper crtc_state->min_voltage_level = 2; 41450fde0b1dSMatt Roper else if (IS_ELKHARTLAKE(dev_priv) && crtc_state->port_clock > 594000) 41469d5fd37eSMatt Roper crtc_state->min_voltage_level = 3; 41479d5fd37eSMatt Roper else if (INTEL_GEN(dev_priv) >= 11 && crtc_state->port_clock > 594000) 4148379bc100SJani Nikula crtc_state->min_voltage_level = 1; 4149379bc100SJani Nikula else if (IS_CANNONLAKE(dev_priv) && crtc_state->port_clock > 594000) 4150379bc100SJani Nikula crtc_state->min_voltage_level = 2; 4151379bc100SJani Nikula } 4152379bc100SJani Nikula 4153dc5b8ed5SVille Syrjälä static enum transcoder bdw_transcoder_master_readout(struct drm_i915_private *dev_priv, 415402d8ea47SVille Syrjälä enum transcoder cpu_transcoder) 415502d8ea47SVille Syrjälä { 4156dc5b8ed5SVille Syrjälä u32 master_select; 415702d8ea47SVille Syrjälä 4158dc5b8ed5SVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) { 4159dc5b8ed5SVille Syrjälä u32 ctl2 = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL2(cpu_transcoder)); 416002d8ea47SVille Syrjälä 416102d8ea47SVille Syrjälä if ((ctl2 & PORT_SYNC_MODE_ENABLE) == 0) 416202d8ea47SVille Syrjälä return INVALID_TRANSCODER; 416302d8ea47SVille Syrjälä 4164d4d7d9caSVille Syrjälä master_select = REG_FIELD_GET(PORT_SYNC_MODE_MASTER_SELECT_MASK, ctl2); 4165dc5b8ed5SVille Syrjälä } else { 4166dc5b8ed5SVille Syrjälä u32 ctl = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 4167dc5b8ed5SVille Syrjälä 4168dc5b8ed5SVille Syrjälä if ((ctl & TRANS_DDI_PORT_SYNC_ENABLE) == 0) 4169dc5b8ed5SVille Syrjälä return INVALID_TRANSCODER; 4170dc5b8ed5SVille Syrjälä 4171dc5b8ed5SVille Syrjälä master_select = REG_FIELD_GET(TRANS_DDI_PORT_SYNC_MASTER_SELECT_MASK, ctl); 4172dc5b8ed5SVille Syrjälä } 417302d8ea47SVille Syrjälä 417402d8ea47SVille Syrjälä if (master_select == 0) 417502d8ea47SVille Syrjälä return TRANSCODER_EDP; 417602d8ea47SVille Syrjälä else 417702d8ea47SVille Syrjälä return master_select - 1; 417802d8ea47SVille Syrjälä } 417902d8ea47SVille Syrjälä 4180dc5b8ed5SVille Syrjälä static void bdw_get_trans_port_sync_config(struct intel_crtc_state *crtc_state) 418102d8ea47SVille Syrjälä { 418202d8ea47SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(crtc_state->uapi.crtc->dev); 418302d8ea47SVille Syrjälä u32 transcoders = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) | 418402d8ea47SVille Syrjälä BIT(TRANSCODER_C) | BIT(TRANSCODER_D); 418502d8ea47SVille Syrjälä enum transcoder cpu_transcoder; 418602d8ea47SVille Syrjälä 418702d8ea47SVille Syrjälä crtc_state->master_transcoder = 4188dc5b8ed5SVille Syrjälä bdw_transcoder_master_readout(dev_priv, crtc_state->cpu_transcoder); 418902d8ea47SVille Syrjälä 419002d8ea47SVille Syrjälä for_each_cpu_transcoder_masked(dev_priv, cpu_transcoder, transcoders) { 419102d8ea47SVille Syrjälä enum intel_display_power_domain power_domain; 419202d8ea47SVille Syrjälä intel_wakeref_t trans_wakeref; 419302d8ea47SVille Syrjälä 419402d8ea47SVille Syrjälä power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); 419502d8ea47SVille Syrjälä trans_wakeref = intel_display_power_get_if_enabled(dev_priv, 419602d8ea47SVille Syrjälä power_domain); 419702d8ea47SVille Syrjälä 419802d8ea47SVille Syrjälä if (!trans_wakeref) 419902d8ea47SVille Syrjälä continue; 420002d8ea47SVille Syrjälä 4201dc5b8ed5SVille Syrjälä if (bdw_transcoder_master_readout(dev_priv, cpu_transcoder) == 420202d8ea47SVille Syrjälä crtc_state->cpu_transcoder) 420302d8ea47SVille Syrjälä crtc_state->sync_mode_slaves_mask |= BIT(cpu_transcoder); 420402d8ea47SVille Syrjälä 420502d8ea47SVille Syrjälä intel_display_power_put(dev_priv, power_domain, trans_wakeref); 420602d8ea47SVille Syrjälä } 420702d8ea47SVille Syrjälä 420802d8ea47SVille Syrjälä drm_WARN_ON(&dev_priv->drm, 420902d8ea47SVille Syrjälä crtc_state->master_transcoder != INVALID_TRANSCODER && 421002d8ea47SVille Syrjälä crtc_state->sync_mode_slaves_mask); 421102d8ea47SVille Syrjälä } 421202d8ea47SVille Syrjälä 4213379bc100SJani Nikula void intel_ddi_get_config(struct intel_encoder *encoder, 4214379bc100SJani Nikula struct intel_crtc_state *pipe_config) 4215379bc100SJani Nikula { 4216379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 42172225f3c6SMaarten Lankhorst struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->uapi.crtc); 4218379bc100SJani Nikula enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; 4219edcb9028SJosé Roberto de Souza struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 4220379bc100SJani Nikula u32 temp, flags = 0; 4221379bc100SJani Nikula 4222379bc100SJani Nikula /* XXX: DSI transcoder paranoia */ 42231de143ccSPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm, transcoder_is_dsi(cpu_transcoder))) 4224379bc100SJani Nikula return; 4225379bc100SJani Nikula 4226fbacb15eSJani Nikula intel_dsc_get_config(encoder, pipe_config); 4227fbacb15eSJani Nikula 4228f7960e7fSJani Nikula temp = intel_de_read(dev_priv, TRANS_DDI_FUNC_CTL(cpu_transcoder)); 4229379bc100SJani Nikula if (temp & TRANS_DDI_PHSYNC) 4230379bc100SJani Nikula flags |= DRM_MODE_FLAG_PHSYNC; 4231379bc100SJani Nikula else 4232379bc100SJani Nikula flags |= DRM_MODE_FLAG_NHSYNC; 4233379bc100SJani Nikula if (temp & TRANS_DDI_PVSYNC) 4234379bc100SJani Nikula flags |= DRM_MODE_FLAG_PVSYNC; 4235379bc100SJani Nikula else 4236379bc100SJani Nikula flags |= DRM_MODE_FLAG_NVSYNC; 4237379bc100SJani Nikula 42381326a92cSMaarten Lankhorst pipe_config->hw.adjusted_mode.flags |= flags; 4239379bc100SJani Nikula 4240379bc100SJani Nikula switch (temp & TRANS_DDI_BPC_MASK) { 4241379bc100SJani Nikula case TRANS_DDI_BPC_6: 4242379bc100SJani Nikula pipe_config->pipe_bpp = 18; 4243379bc100SJani Nikula break; 4244379bc100SJani Nikula case TRANS_DDI_BPC_8: 4245379bc100SJani Nikula pipe_config->pipe_bpp = 24; 4246379bc100SJani Nikula break; 4247379bc100SJani Nikula case TRANS_DDI_BPC_10: 4248379bc100SJani Nikula pipe_config->pipe_bpp = 30; 4249379bc100SJani Nikula break; 4250379bc100SJani Nikula case TRANS_DDI_BPC_12: 4251379bc100SJani Nikula pipe_config->pipe_bpp = 36; 4252379bc100SJani Nikula break; 4253379bc100SJani Nikula default: 4254379bc100SJani Nikula break; 4255379bc100SJani Nikula } 4256379bc100SJani Nikula 4257379bc100SJani Nikula switch (temp & TRANS_DDI_MODE_SELECT_MASK) { 4258379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_HDMI: 4259379bc100SJani Nikula pipe_config->has_hdmi_sink = true; 4260379bc100SJani Nikula 4261379bc100SJani Nikula pipe_config->infoframes.enable |= 4262379bc100SJani Nikula intel_hdmi_infoframes_enabled(encoder, pipe_config); 4263379bc100SJani Nikula 4264379bc100SJani Nikula if (pipe_config->infoframes.enable) 4265379bc100SJani Nikula pipe_config->has_infoframe = true; 4266379bc100SJani Nikula 4267379bc100SJani Nikula if (temp & TRANS_DDI_HDMI_SCRAMBLING) 4268379bc100SJani Nikula pipe_config->hdmi_scrambling = true; 4269379bc100SJani Nikula if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE) 4270379bc100SJani Nikula pipe_config->hdmi_high_tmds_clock_ratio = true; 4271379bc100SJani Nikula /* fall through */ 4272379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DVI: 4273379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI); 4274379bc100SJani Nikula pipe_config->lane_count = 4; 4275379bc100SJani Nikula break; 4276379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_FDI: 4277379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_ANALOG); 4278379bc100SJani Nikula break; 4279379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_SST: 4280379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP) 4281379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_EDP); 4282379bc100SJani Nikula else 4283379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_DP); 4284379bc100SJani Nikula pipe_config->lane_count = 4285379bc100SJani Nikula ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; 4286379bc100SJani Nikula intel_dp_get_m_n(intel_crtc, pipe_config); 42878aa940c8SMaarten Lankhorst 42888aa940c8SMaarten Lankhorst if (INTEL_GEN(dev_priv) >= 11) { 42898aa940c8SMaarten Lankhorst i915_reg_t dp_tp_ctl; 42908aa940c8SMaarten Lankhorst 42918aa940c8SMaarten Lankhorst if (IS_GEN(dev_priv, 11)) 42928aa940c8SMaarten Lankhorst dp_tp_ctl = DP_TP_CTL(encoder->port); 42938aa940c8SMaarten Lankhorst else 42948aa940c8SMaarten Lankhorst dp_tp_ctl = TGL_DP_TP_CTL(pipe_config->cpu_transcoder); 42958aa940c8SMaarten Lankhorst 42968aa940c8SMaarten Lankhorst pipe_config->fec_enable = 4297f7960e7fSJani Nikula intel_de_read(dev_priv, dp_tp_ctl) & DP_TP_CTL_FEC_ENABLE; 42988aa940c8SMaarten Lankhorst 429947bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 430047bdb1caSJani Nikula "[ENCODER:%d:%s] Fec status: %u\n", 43018aa940c8SMaarten Lankhorst encoder->base.base.id, encoder->base.name, 43028aa940c8SMaarten Lankhorst pipe_config->fec_enable); 43038aa940c8SMaarten Lankhorst } 43048aa940c8SMaarten Lankhorst 4305dee66f3eSGwan-gyeong Mun pipe_config->infoframes.enable |= 4306dee66f3eSGwan-gyeong Mun intel_hdmi_infoframes_enabled(encoder, pipe_config); 4307dee66f3eSGwan-gyeong Mun 4308379bc100SJani Nikula break; 4309379bc100SJani Nikula case TRANS_DDI_MODE_SELECT_DP_MST: 4310379bc100SJani Nikula pipe_config->output_types |= BIT(INTEL_OUTPUT_DP_MST); 4311379bc100SJani Nikula pipe_config->lane_count = 4312379bc100SJani Nikula ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1; 43136671c367SJosé Roberto de Souza 43146671c367SJosé Roberto de Souza if (INTEL_GEN(dev_priv) >= 12) 43156671c367SJosé Roberto de Souza pipe_config->mst_master_transcoder = 43166671c367SJosé Roberto de Souza REG_FIELD_GET(TRANS_DDI_MST_TRANSPORT_SELECT_MASK, temp); 43176671c367SJosé Roberto de Souza 4318379bc100SJani Nikula intel_dp_get_m_n(intel_crtc, pipe_config); 4319dee66f3eSGwan-gyeong Mun 4320dee66f3eSGwan-gyeong Mun pipe_config->infoframes.enable |= 4321dee66f3eSGwan-gyeong Mun intel_hdmi_infoframes_enabled(encoder, pipe_config); 4322379bc100SJani Nikula break; 4323379bc100SJani Nikula default: 4324379bc100SJani Nikula break; 4325379bc100SJani Nikula } 4326379bc100SJani Nikula 4327f153478dSImre Deak if (INTEL_GEN(dev_priv) >= 12) { 4328f153478dSImre Deak enum transcoder transcoder = 4329f153478dSImre Deak intel_dp_mst_is_slave_trans(pipe_config) ? 4330f153478dSImre Deak pipe_config->mst_master_transcoder : 4331f153478dSImre Deak pipe_config->cpu_transcoder; 4332f153478dSImre Deak 4333f153478dSImre Deak intel_dp->regs.dp_tp_ctl = TGL_DP_TP_CTL(transcoder); 4334f153478dSImre Deak intel_dp->regs.dp_tp_status = TGL_DP_TP_STATUS(transcoder); 4335f153478dSImre Deak } 4336f153478dSImre Deak 4337379bc100SJani Nikula pipe_config->has_audio = 4338379bc100SJani Nikula intel_ddi_is_audio_enabled(dev_priv, cpu_transcoder); 4339379bc100SJani Nikula 4340379bc100SJani Nikula if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp && 4341379bc100SJani Nikula pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) { 4342379bc100SJani Nikula /* 4343379bc100SJani Nikula * This is a big fat ugly hack. 4344379bc100SJani Nikula * 4345379bc100SJani Nikula * Some machines in UEFI boot mode provide us a VBT that has 18 4346379bc100SJani Nikula * bpp and 1.62 GHz link bandwidth for eDP, which for reasons 4347379bc100SJani Nikula * unknown we fail to light up. Yet the same BIOS boots up with 4348379bc100SJani Nikula * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as 4349379bc100SJani Nikula * max, not what it tells us to use. 4350379bc100SJani Nikula * 4351379bc100SJani Nikula * Note: This will still be broken if the eDP panel is not lit 4352379bc100SJani Nikula * up by the BIOS, and thus we can't get the mode at module 4353379bc100SJani Nikula * load. 4354379bc100SJani Nikula */ 435547bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 435647bdb1caSJani Nikula "pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n", 4357379bc100SJani Nikula pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp); 4358379bc100SJani Nikula dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp; 4359379bc100SJani Nikula } 4360379bc100SJani Nikula 4361379bc100SJani Nikula intel_ddi_clock_get(encoder, pipe_config); 4362379bc100SJani Nikula 4363379bc100SJani Nikula if (IS_GEN9_LP(dev_priv)) 4364379bc100SJani Nikula pipe_config->lane_lat_optim_mask = 4365379bc100SJani Nikula bxt_ddi_phy_get_lane_lat_optim_mask(encoder); 4366379bc100SJani Nikula 4367379bc100SJani Nikula intel_ddi_compute_min_voltage_level(dev_priv, pipe_config); 4368379bc100SJani Nikula 4369379bc100SJani Nikula intel_hdmi_read_gcp_infoframe(encoder, pipe_config); 4370379bc100SJani Nikula 4371379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4372379bc100SJani Nikula HDMI_INFOFRAME_TYPE_AVI, 4373379bc100SJani Nikula &pipe_config->infoframes.avi); 4374379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4375379bc100SJani Nikula HDMI_INFOFRAME_TYPE_SPD, 4376379bc100SJani Nikula &pipe_config->infoframes.spd); 4377379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4378379bc100SJani Nikula HDMI_INFOFRAME_TYPE_VENDOR, 4379379bc100SJani Nikula &pipe_config->infoframes.hdmi); 4380379bc100SJani Nikula intel_read_infoframe(encoder, pipe_config, 4381379bc100SJani Nikula HDMI_INFOFRAME_TYPE_DRM, 4382379bc100SJani Nikula &pipe_config->infoframes.drm); 438302d8ea47SVille Syrjälä 4384dc5b8ed5SVille Syrjälä if (INTEL_GEN(dev_priv) >= 8) 4385dc5b8ed5SVille Syrjälä bdw_get_trans_port_sync_config(pipe_config); 4386dee66f3eSGwan-gyeong Mun 4387dee66f3eSGwan-gyeong Mun intel_read_dp_sdp(encoder, pipe_config, HDMI_PACKET_TYPE_GAMUT_METADATA); 43882c3928e4SGwan-gyeong Mun intel_read_dp_sdp(encoder, pipe_config, DP_SDP_VSC); 4389379bc100SJani Nikula } 4390379bc100SJani Nikula 4391379bc100SJani Nikula static enum intel_output_type 4392379bc100SJani Nikula intel_ddi_compute_output_type(struct intel_encoder *encoder, 4393379bc100SJani Nikula struct intel_crtc_state *crtc_state, 4394379bc100SJani Nikula struct drm_connector_state *conn_state) 4395379bc100SJani Nikula { 4396379bc100SJani Nikula switch (conn_state->connector->connector_type) { 4397379bc100SJani Nikula case DRM_MODE_CONNECTOR_HDMIA: 4398379bc100SJani Nikula return INTEL_OUTPUT_HDMI; 4399379bc100SJani Nikula case DRM_MODE_CONNECTOR_eDP: 4400379bc100SJani Nikula return INTEL_OUTPUT_EDP; 4401379bc100SJani Nikula case DRM_MODE_CONNECTOR_DisplayPort: 4402379bc100SJani Nikula return INTEL_OUTPUT_DP; 4403379bc100SJani Nikula default: 4404379bc100SJani Nikula MISSING_CASE(conn_state->connector->connector_type); 4405379bc100SJani Nikula return INTEL_OUTPUT_UNUSED; 4406379bc100SJani Nikula } 4407379bc100SJani Nikula } 4408379bc100SJani Nikula 4409379bc100SJani Nikula static int intel_ddi_compute_config(struct intel_encoder *encoder, 4410379bc100SJani Nikula struct intel_crtc_state *pipe_config, 4411379bc100SJani Nikula struct drm_connector_state *conn_state) 4412379bc100SJani Nikula { 44132225f3c6SMaarten Lankhorst struct intel_crtc *crtc = to_intel_crtc(pipe_config->uapi.crtc); 4414379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4415379bc100SJani Nikula enum port port = encoder->port; 4416379bc100SJani Nikula int ret; 4417379bc100SJani Nikula 441810cf8e75SVille Syrjälä if (HAS_TRANSCODER(dev_priv, TRANSCODER_EDP) && port == PORT_A) 4419379bc100SJani Nikula pipe_config->cpu_transcoder = TRANSCODER_EDP; 4420379bc100SJani Nikula 4421bdacf087SAnshuman Gupta if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI)) { 4422379bc100SJani Nikula ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state); 4423bdacf087SAnshuman Gupta } else { 4424379bc100SJani Nikula ret = intel_dp_compute_config(encoder, pipe_config, conn_state); 4425bdacf087SAnshuman Gupta } 4426bdacf087SAnshuman Gupta 4427379bc100SJani Nikula if (ret) 4428379bc100SJani Nikula return ret; 4429379bc100SJani Nikula 4430379bc100SJani Nikula if (IS_HASWELL(dev_priv) && crtc->pipe == PIPE_A && 4431379bc100SJani Nikula pipe_config->cpu_transcoder == TRANSCODER_EDP) 4432379bc100SJani Nikula pipe_config->pch_pfit.force_thru = 4433379bc100SJani Nikula pipe_config->pch_pfit.enabled || 4434379bc100SJani Nikula pipe_config->crc_enabled; 4435379bc100SJani Nikula 4436379bc100SJani Nikula if (IS_GEN9_LP(dev_priv)) 4437379bc100SJani Nikula pipe_config->lane_lat_optim_mask = 4438379bc100SJani Nikula bxt_ddi_phy_calc_lane_lat_optim_mask(pipe_config->lane_count); 4439379bc100SJani Nikula 4440379bc100SJani Nikula intel_ddi_compute_min_voltage_level(dev_priv, pipe_config); 4441379bc100SJani Nikula 4442379bc100SJani Nikula return 0; 4443379bc100SJani Nikula } 4444379bc100SJani Nikula 4445b50a1aa6SManasi Navare static bool mode_equal(const struct drm_display_mode *mode1, 4446b50a1aa6SManasi Navare const struct drm_display_mode *mode2) 4447b50a1aa6SManasi Navare { 4448b50a1aa6SManasi Navare return drm_mode_match(mode1, mode2, 4449b50a1aa6SManasi Navare DRM_MODE_MATCH_TIMINGS | 4450b50a1aa6SManasi Navare DRM_MODE_MATCH_FLAGS | 4451b50a1aa6SManasi Navare DRM_MODE_MATCH_3D_FLAGS) && 4452b50a1aa6SManasi Navare mode1->clock == mode2->clock; /* we want an exact match */ 4453b50a1aa6SManasi Navare } 4454b50a1aa6SManasi Navare 4455b50a1aa6SManasi Navare static bool m_n_equal(const struct intel_link_m_n *m_n_1, 4456b50a1aa6SManasi Navare const struct intel_link_m_n *m_n_2) 4457b50a1aa6SManasi Navare { 4458b50a1aa6SManasi Navare return m_n_1->tu == m_n_2->tu && 4459b50a1aa6SManasi Navare m_n_1->gmch_m == m_n_2->gmch_m && 4460b50a1aa6SManasi Navare m_n_1->gmch_n == m_n_2->gmch_n && 4461b50a1aa6SManasi Navare m_n_1->link_m == m_n_2->link_m && 4462b50a1aa6SManasi Navare m_n_1->link_n == m_n_2->link_n; 4463b50a1aa6SManasi Navare } 4464b50a1aa6SManasi Navare 4465b50a1aa6SManasi Navare static bool crtcs_port_sync_compatible(const struct intel_crtc_state *crtc_state1, 4466b50a1aa6SManasi Navare const struct intel_crtc_state *crtc_state2) 4467b50a1aa6SManasi Navare { 4468b50a1aa6SManasi Navare return crtc_state1->hw.active && crtc_state2->hw.active && 4469b50a1aa6SManasi Navare crtc_state1->output_types == crtc_state2->output_types && 4470b50a1aa6SManasi Navare crtc_state1->output_format == crtc_state2->output_format && 4471b50a1aa6SManasi Navare crtc_state1->lane_count == crtc_state2->lane_count && 4472b50a1aa6SManasi Navare crtc_state1->port_clock == crtc_state2->port_clock && 4473b50a1aa6SManasi Navare mode_equal(&crtc_state1->hw.adjusted_mode, 4474b50a1aa6SManasi Navare &crtc_state2->hw.adjusted_mode) && 4475b50a1aa6SManasi Navare m_n_equal(&crtc_state1->dp_m_n, &crtc_state2->dp_m_n); 4476b50a1aa6SManasi Navare } 4477b50a1aa6SManasi Navare 4478b50a1aa6SManasi Navare static u8 4479b50a1aa6SManasi Navare intel_ddi_port_sync_transcoders(const struct intel_crtc_state *ref_crtc_state, 4480b50a1aa6SManasi Navare int tile_group_id) 4481b50a1aa6SManasi Navare { 4482b50a1aa6SManasi Navare struct drm_connector *connector; 4483b50a1aa6SManasi Navare const struct drm_connector_state *conn_state; 4484b50a1aa6SManasi Navare struct drm_i915_private *dev_priv = to_i915(ref_crtc_state->uapi.crtc->dev); 4485b50a1aa6SManasi Navare struct intel_atomic_state *state = 4486b50a1aa6SManasi Navare to_intel_atomic_state(ref_crtc_state->uapi.state); 4487b50a1aa6SManasi Navare u8 transcoders = 0; 4488b50a1aa6SManasi Navare int i; 4489b50a1aa6SManasi Navare 4490dc5b8ed5SVille Syrjälä /* 4491dc5b8ed5SVille Syrjälä * We don't enable port sync on BDW due to missing w/as and 4492dc5b8ed5SVille Syrjälä * due to not having adjusted the modeset sequence appropriately. 4493dc5b8ed5SVille Syrjälä */ 4494dc5b8ed5SVille Syrjälä if (INTEL_GEN(dev_priv) < 9) 4495b50a1aa6SManasi Navare return 0; 4496b50a1aa6SManasi Navare 4497b50a1aa6SManasi Navare if (!intel_crtc_has_type(ref_crtc_state, INTEL_OUTPUT_DP)) 4498b50a1aa6SManasi Navare return 0; 4499b50a1aa6SManasi Navare 4500b50a1aa6SManasi Navare for_each_new_connector_in_state(&state->base, connector, conn_state, i) { 4501b50a1aa6SManasi Navare struct intel_crtc *crtc = to_intel_crtc(conn_state->crtc); 4502b50a1aa6SManasi Navare const struct intel_crtc_state *crtc_state; 4503b50a1aa6SManasi Navare 4504b50a1aa6SManasi Navare if (!crtc) 4505b50a1aa6SManasi Navare continue; 4506b50a1aa6SManasi Navare 4507b50a1aa6SManasi Navare if (!connector->has_tile || 4508b50a1aa6SManasi Navare connector->tile_group->id != 4509b50a1aa6SManasi Navare tile_group_id) 4510b50a1aa6SManasi Navare continue; 4511b50a1aa6SManasi Navare crtc_state = intel_atomic_get_new_crtc_state(state, 4512b50a1aa6SManasi Navare crtc); 4513b50a1aa6SManasi Navare if (!crtcs_port_sync_compatible(ref_crtc_state, 4514b50a1aa6SManasi Navare crtc_state)) 4515b50a1aa6SManasi Navare continue; 4516b50a1aa6SManasi Navare transcoders |= BIT(crtc_state->cpu_transcoder); 4517b50a1aa6SManasi Navare } 4518b50a1aa6SManasi Navare 4519b50a1aa6SManasi Navare return transcoders; 4520b50a1aa6SManasi Navare } 4521b50a1aa6SManasi Navare 4522b50a1aa6SManasi Navare static int intel_ddi_compute_config_late(struct intel_encoder *encoder, 4523b50a1aa6SManasi Navare struct intel_crtc_state *crtc_state, 4524b50a1aa6SManasi Navare struct drm_connector_state *conn_state) 4525b50a1aa6SManasi Navare { 452647bdb1caSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev); 4527b50a1aa6SManasi Navare struct drm_connector *connector = conn_state->connector; 4528b50a1aa6SManasi Navare u8 port_sync_transcoders = 0; 4529b50a1aa6SManasi Navare 453047bdb1caSJani Nikula drm_dbg_kms(&i915->drm, "[ENCODER:%d:%s] [CRTC:%d:%s]", 4531b50a1aa6SManasi Navare encoder->base.base.id, encoder->base.name, 4532b50a1aa6SManasi Navare crtc_state->uapi.crtc->base.id, crtc_state->uapi.crtc->name); 4533b50a1aa6SManasi Navare 4534b50a1aa6SManasi Navare if (connector->has_tile) 4535b50a1aa6SManasi Navare port_sync_transcoders = intel_ddi_port_sync_transcoders(crtc_state, 4536b50a1aa6SManasi Navare connector->tile_group->id); 4537b50a1aa6SManasi Navare 4538b50a1aa6SManasi Navare /* 4539b50a1aa6SManasi Navare * EDP Transcoders cannot be ensalved 4540b50a1aa6SManasi Navare * make them a master always when present 4541b50a1aa6SManasi Navare */ 4542b50a1aa6SManasi Navare if (port_sync_transcoders & BIT(TRANSCODER_EDP)) 4543b50a1aa6SManasi Navare crtc_state->master_transcoder = TRANSCODER_EDP; 4544b50a1aa6SManasi Navare else 4545b50a1aa6SManasi Navare crtc_state->master_transcoder = ffs(port_sync_transcoders) - 1; 4546b50a1aa6SManasi Navare 4547b50a1aa6SManasi Navare if (crtc_state->master_transcoder == crtc_state->cpu_transcoder) { 4548b50a1aa6SManasi Navare crtc_state->master_transcoder = INVALID_TRANSCODER; 4549b50a1aa6SManasi Navare crtc_state->sync_mode_slaves_mask = 4550b50a1aa6SManasi Navare port_sync_transcoders & ~BIT(crtc_state->cpu_transcoder); 4551b50a1aa6SManasi Navare } 4552b50a1aa6SManasi Navare 4553b50a1aa6SManasi Navare return 0; 4554b50a1aa6SManasi Navare } 4555b50a1aa6SManasi Navare 4556379bc100SJani Nikula static void intel_ddi_encoder_destroy(struct drm_encoder *encoder) 4557379bc100SJani Nikula { 4558b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder)); 4559379bc100SJani Nikula 4560379bc100SJani Nikula intel_dp_encoder_flush_work(encoder); 4561379bc100SJani Nikula 4562379bc100SJani Nikula drm_encoder_cleanup(encoder); 4563379bc100SJani Nikula kfree(dig_port); 4564379bc100SJani Nikula } 4565379bc100SJani Nikula 4566379bc100SJani Nikula static const struct drm_encoder_funcs intel_ddi_funcs = { 456732691b58SImre Deak .reset = intel_dp_encoder_reset, 4568379bc100SJani Nikula .destroy = intel_ddi_encoder_destroy, 4569379bc100SJani Nikula }; 4570379bc100SJani Nikula 4571379bc100SJani Nikula static struct intel_connector * 45727801f3b7SLucas De Marchi intel_ddi_init_dp_connector(struct intel_digital_port *dig_port) 4573379bc100SJani Nikula { 45747801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 4575379bc100SJani Nikula struct intel_connector *connector; 45767801f3b7SLucas De Marchi enum port port = dig_port->base.port; 4577379bc100SJani Nikula 4578379bc100SJani Nikula connector = intel_connector_alloc(); 4579379bc100SJani Nikula if (!connector) 4580379bc100SJani Nikula return NULL; 4581379bc100SJani Nikula 45827801f3b7SLucas De Marchi dig_port->dp.output_reg = DDI_BUF_CTL(port); 45837801f3b7SLucas De Marchi dig_port->dp.prepare_link_retrain = intel_ddi_prepare_link_retrain; 45847801f3b7SLucas De Marchi dig_port->dp.set_link_train = intel_ddi_set_link_train; 45857801f3b7SLucas De Marchi dig_port->dp.set_idle_link_train = intel_ddi_set_idle_link_train; 4586eee3f911SVille Syrjälä 4587fb83f72cSVille Syrjälä if (INTEL_GEN(dev_priv) >= 12) 45887801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = tgl_set_signal_levels; 4589fb83f72cSVille Syrjälä else if (INTEL_GEN(dev_priv) >= 11) 45907801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = icl_set_signal_levels; 4591fb83f72cSVille Syrjälä else if (IS_CANNONLAKE(dev_priv)) 45927801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = cnl_set_signal_levels; 4593fb83f72cSVille Syrjälä else if (IS_GEN9_LP(dev_priv)) 45947801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = bxt_set_signal_levels; 4595fb83f72cSVille Syrjälä else 45967801f3b7SLucas De Marchi dig_port->dp.set_signal_levels = hsw_set_signal_levels; 4597fb83f72cSVille Syrjälä 45987801f3b7SLucas De Marchi dig_port->dp.voltage_max = intel_ddi_dp_voltage_max; 45997801f3b7SLucas De Marchi dig_port->dp.preemph_max = intel_ddi_dp_preemph_max; 460053de0a20SVille Syrjälä 4601edcb9028SJosé Roberto de Souza if (INTEL_GEN(dev_priv) < 12) { 46027801f3b7SLucas De Marchi dig_port->dp.regs.dp_tp_ctl = DP_TP_CTL(port); 46037801f3b7SLucas De Marchi dig_port->dp.regs.dp_tp_status = DP_TP_STATUS(port); 4604edcb9028SJosé Roberto de Souza } 4605379bc100SJani Nikula 46067801f3b7SLucas De Marchi if (!intel_dp_init_connector(dig_port, connector)) { 4607379bc100SJani Nikula kfree(connector); 4608379bc100SJani Nikula return NULL; 4609379bc100SJani Nikula } 4610379bc100SJani Nikula 4611379bc100SJani Nikula return connector; 4612379bc100SJani Nikula } 4613379bc100SJani Nikula 4614379bc100SJani Nikula static int modeset_pipe(struct drm_crtc *crtc, 4615379bc100SJani Nikula struct drm_modeset_acquire_ctx *ctx) 4616379bc100SJani Nikula { 4617379bc100SJani Nikula struct drm_atomic_state *state; 4618379bc100SJani Nikula struct drm_crtc_state *crtc_state; 4619379bc100SJani Nikula int ret; 4620379bc100SJani Nikula 4621379bc100SJani Nikula state = drm_atomic_state_alloc(crtc->dev); 4622379bc100SJani Nikula if (!state) 4623379bc100SJani Nikula return -ENOMEM; 4624379bc100SJani Nikula 4625379bc100SJani Nikula state->acquire_ctx = ctx; 4626379bc100SJani Nikula 4627379bc100SJani Nikula crtc_state = drm_atomic_get_crtc_state(state, crtc); 4628379bc100SJani Nikula if (IS_ERR(crtc_state)) { 4629379bc100SJani Nikula ret = PTR_ERR(crtc_state); 4630379bc100SJani Nikula goto out; 4631379bc100SJani Nikula } 4632379bc100SJani Nikula 4633379bc100SJani Nikula crtc_state->connectors_changed = true; 4634379bc100SJani Nikula 4635379bc100SJani Nikula ret = drm_atomic_commit(state); 4636379bc100SJani Nikula out: 4637379bc100SJani Nikula drm_atomic_state_put(state); 4638379bc100SJani Nikula 4639379bc100SJani Nikula return ret; 4640379bc100SJani Nikula } 4641379bc100SJani Nikula 4642379bc100SJani Nikula static int intel_hdmi_reset_link(struct intel_encoder *encoder, 4643379bc100SJani Nikula struct drm_modeset_acquire_ctx *ctx) 4644379bc100SJani Nikula { 4645379bc100SJani Nikula struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4646b7d02c3aSVille Syrjälä struct intel_hdmi *hdmi = enc_to_intel_hdmi(encoder); 4647379bc100SJani Nikula struct intel_connector *connector = hdmi->attached_connector; 4648379bc100SJani Nikula struct i2c_adapter *adapter = 4649379bc100SJani Nikula intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus); 4650379bc100SJani Nikula struct drm_connector_state *conn_state; 4651379bc100SJani Nikula struct intel_crtc_state *crtc_state; 4652379bc100SJani Nikula struct intel_crtc *crtc; 4653379bc100SJani Nikula u8 config; 4654379bc100SJani Nikula int ret; 4655379bc100SJani Nikula 4656379bc100SJani Nikula if (!connector || connector->base.status != connector_status_connected) 4657379bc100SJani Nikula return 0; 4658379bc100SJani Nikula 4659379bc100SJani Nikula ret = drm_modeset_lock(&dev_priv->drm.mode_config.connection_mutex, 4660379bc100SJani Nikula ctx); 4661379bc100SJani Nikula if (ret) 4662379bc100SJani Nikula return ret; 4663379bc100SJani Nikula 4664379bc100SJani Nikula conn_state = connector->base.state; 4665379bc100SJani Nikula 4666379bc100SJani Nikula crtc = to_intel_crtc(conn_state->crtc); 4667379bc100SJani Nikula if (!crtc) 4668379bc100SJani Nikula return 0; 4669379bc100SJani Nikula 4670379bc100SJani Nikula ret = drm_modeset_lock(&crtc->base.mutex, ctx); 4671379bc100SJani Nikula if (ret) 4672379bc100SJani Nikula return ret; 4673379bc100SJani Nikula 4674379bc100SJani Nikula crtc_state = to_intel_crtc_state(crtc->base.state); 4675379bc100SJani Nikula 46761de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, 46771de143ccSPankaj Bharadiya !intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)); 4678379bc100SJani Nikula 46791326a92cSMaarten Lankhorst if (!crtc_state->hw.active) 4680379bc100SJani Nikula return 0; 4681379bc100SJani Nikula 4682379bc100SJani Nikula if (!crtc_state->hdmi_high_tmds_clock_ratio && 4683379bc100SJani Nikula !crtc_state->hdmi_scrambling) 4684379bc100SJani Nikula return 0; 4685379bc100SJani Nikula 4686379bc100SJani Nikula if (conn_state->commit && 4687379bc100SJani Nikula !try_wait_for_completion(&conn_state->commit->hw_done)) 4688379bc100SJani Nikula return 0; 4689379bc100SJani Nikula 4690379bc100SJani Nikula ret = drm_scdc_readb(adapter, SCDC_TMDS_CONFIG, &config); 4691379bc100SJani Nikula if (ret < 0) { 469247bdb1caSJani Nikula drm_err(&dev_priv->drm, "Failed to read TMDS config: %d\n", 469347bdb1caSJani Nikula ret); 4694379bc100SJani Nikula return 0; 4695379bc100SJani Nikula } 4696379bc100SJani Nikula 4697379bc100SJani Nikula if (!!(config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) == 4698379bc100SJani Nikula crtc_state->hdmi_high_tmds_clock_ratio && 4699379bc100SJani Nikula !!(config & SCDC_SCRAMBLING_ENABLE) == 4700379bc100SJani Nikula crtc_state->hdmi_scrambling) 4701379bc100SJani Nikula return 0; 4702379bc100SJani Nikula 4703379bc100SJani Nikula /* 4704379bc100SJani Nikula * HDMI 2.0 says that one should not send scrambled data 4705379bc100SJani Nikula * prior to configuring the sink scrambling, and that 4706379bc100SJani Nikula * TMDS clock/data transmission should be suspended when 4707379bc100SJani Nikula * changing the TMDS clock rate in the sink. So let's 4708379bc100SJani Nikula * just do a full modeset here, even though some sinks 4709379bc100SJani Nikula * would be perfectly happy if were to just reconfigure 4710379bc100SJani Nikula * the SCDC settings on the fly. 4711379bc100SJani Nikula */ 4712379bc100SJani Nikula return modeset_pipe(&crtc->base, ctx); 4713379bc100SJani Nikula } 4714379bc100SJani Nikula 47153944709dSImre Deak static enum intel_hotplug_state 47163944709dSImre Deak intel_ddi_hotplug(struct intel_encoder *encoder, 47178c8919c7SImre Deak struct intel_connector *connector) 4718379bc100SJani Nikula { 4719b4df5405SImre Deak struct drm_i915_private *i915 = to_i915(encoder->base.dev); 4720b7d02c3aSVille Syrjälä struct intel_digital_port *dig_port = enc_to_dig_port(encoder); 4721b4df5405SImre Deak enum phy phy = intel_port_to_phy(i915, encoder->port); 4722b4df5405SImre Deak bool is_tc = intel_phy_is_tc(i915, phy); 4723379bc100SJani Nikula struct drm_modeset_acquire_ctx ctx; 47243944709dSImre Deak enum intel_hotplug_state state; 4725379bc100SJani Nikula int ret; 4726379bc100SJani Nikula 47278c8919c7SImre Deak state = intel_encoder_hotplug(encoder, connector); 4728379bc100SJani Nikula 4729379bc100SJani Nikula drm_modeset_acquire_init(&ctx, 0); 4730379bc100SJani Nikula 4731379bc100SJani Nikula for (;;) { 4732379bc100SJani Nikula if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA) 4733379bc100SJani Nikula ret = intel_hdmi_reset_link(encoder, &ctx); 4734379bc100SJani Nikula else 4735379bc100SJani Nikula ret = intel_dp_retrain_link(encoder, &ctx); 4736379bc100SJani Nikula 4737379bc100SJani Nikula if (ret == -EDEADLK) { 4738379bc100SJani Nikula drm_modeset_backoff(&ctx); 4739379bc100SJani Nikula continue; 4740379bc100SJani Nikula } 4741379bc100SJani Nikula 4742379bc100SJani Nikula break; 4743379bc100SJani Nikula } 4744379bc100SJani Nikula 4745379bc100SJani Nikula drm_modeset_drop_locks(&ctx); 4746379bc100SJani Nikula drm_modeset_acquire_fini(&ctx); 47473a47ae20SPankaj Bharadiya drm_WARN(encoder->base.dev, ret, 47483a47ae20SPankaj Bharadiya "Acquiring modeset locks failed with %i\n", ret); 4749379bc100SJani Nikula 4750bb80c925SJosé Roberto de Souza /* 4751bb80c925SJosé Roberto de Souza * Unpowered type-c dongles can take some time to boot and be 4752bb80c925SJosé Roberto de Souza * responsible, so here giving some time to those dongles to power up 4753bb80c925SJosé Roberto de Souza * and then retrying the probe. 4754bb80c925SJosé Roberto de Souza * 4755bb80c925SJosé Roberto de Souza * On many platforms the HDMI live state signal is known to be 4756bb80c925SJosé Roberto de Souza * unreliable, so we can't use it to detect if a sink is connected or 4757bb80c925SJosé Roberto de Souza * not. Instead we detect if it's connected based on whether we can 4758bb80c925SJosé Roberto de Souza * read the EDID or not. That in turn has a problem during disconnect, 4759bb80c925SJosé Roberto de Souza * since the HPD interrupt may be raised before the DDC lines get 4760bb80c925SJosé Roberto de Souza * disconnected (due to how the required length of DDC vs. HPD 4761bb80c925SJosé Roberto de Souza * connector pins are specified) and so we'll still be able to get a 4762bb80c925SJosé Roberto de Souza * valid EDID. To solve this schedule another detection cycle if this 4763bb80c925SJosé Roberto de Souza * time around we didn't detect any change in the sink's connection 4764bb80c925SJosé Roberto de Souza * status. 4765b4df5405SImre Deak * 4766b4df5405SImre Deak * Type-c connectors which get their HPD signal deasserted then 4767b4df5405SImre Deak * reasserted, without unplugging/replugging the sink from the 4768b4df5405SImre Deak * connector, introduce a delay until the AUX channel communication 4769b4df5405SImre Deak * becomes functional. Retry the detection for 5 seconds on type-c 4770b4df5405SImre Deak * connectors to account for this delay. 4771bb80c925SJosé Roberto de Souza */ 4772b4df5405SImre Deak if (state == INTEL_HOTPLUG_UNCHANGED && 4773b4df5405SImre Deak connector->hotplug_retries < (is_tc ? 5 : 1) && 4774bb80c925SJosé Roberto de Souza !dig_port->dp.is_mst) 4775bb80c925SJosé Roberto de Souza state = INTEL_HOTPLUG_RETRY; 4776bb80c925SJosé Roberto de Souza 47773944709dSImre Deak return state; 4778379bc100SJani Nikula } 4779379bc100SJani Nikula 4780edc0e09cSVille Syrjälä static bool lpt_digital_port_connected(struct intel_encoder *encoder) 4781edc0e09cSVille Syrjälä { 4782edc0e09cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4783c7e8a3d6SVille Syrjälä u32 bit = dev_priv->hotplug.pch_hpd[encoder->hpd_pin]; 4784edc0e09cSVille Syrjälä 4785edc0e09cSVille Syrjälä return intel_de_read(dev_priv, SDEISR) & bit; 4786edc0e09cSVille Syrjälä } 4787edc0e09cSVille Syrjälä 4788edc0e09cSVille Syrjälä static bool hsw_digital_port_connected(struct intel_encoder *encoder) 4789edc0e09cSVille Syrjälä { 4790edc0e09cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4791c7e8a3d6SVille Syrjälä u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin]; 4792edc0e09cSVille Syrjälä 4793c7e8a3d6SVille Syrjälä return intel_de_read(dev_priv, DEISR) & bit; 4794edc0e09cSVille Syrjälä } 4795edc0e09cSVille Syrjälä 4796edc0e09cSVille Syrjälä static bool bdw_digital_port_connected(struct intel_encoder *encoder) 4797edc0e09cSVille Syrjälä { 4798edc0e09cSVille Syrjälä struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); 4799c7e8a3d6SVille Syrjälä u32 bit = dev_priv->hotplug.hpd[encoder->hpd_pin]; 4800edc0e09cSVille Syrjälä 4801edc0e09cSVille Syrjälä return intel_de_read(dev_priv, GEN8_DE_PORT_ISR) & bit; 4802edc0e09cSVille Syrjälä } 4803edc0e09cSVille Syrjälä 4804379bc100SJani Nikula static struct intel_connector * 48057801f3b7SLucas De Marchi intel_ddi_init_hdmi_connector(struct intel_digital_port *dig_port) 4806379bc100SJani Nikula { 4807379bc100SJani Nikula struct intel_connector *connector; 48087801f3b7SLucas De Marchi enum port port = dig_port->base.port; 4809379bc100SJani Nikula 4810379bc100SJani Nikula connector = intel_connector_alloc(); 4811379bc100SJani Nikula if (!connector) 4812379bc100SJani Nikula return NULL; 4813379bc100SJani Nikula 48147801f3b7SLucas De Marchi dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port); 48157801f3b7SLucas De Marchi intel_hdmi_init_connector(dig_port, connector); 4816379bc100SJani Nikula 4817379bc100SJani Nikula return connector; 4818379bc100SJani Nikula } 4819379bc100SJani Nikula 48207801f3b7SLucas De Marchi static bool intel_ddi_a_force_4_lanes(struct intel_digital_port *dig_port) 4821379bc100SJani Nikula { 48227801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 4823379bc100SJani Nikula 48247801f3b7SLucas De Marchi if (dig_port->base.port != PORT_A) 4825379bc100SJani Nikula return false; 4826379bc100SJani Nikula 48277801f3b7SLucas De Marchi if (dig_port->saved_port_bits & DDI_A_4_LANES) 4828379bc100SJani Nikula return false; 4829379bc100SJani Nikula 4830379bc100SJani Nikula /* Broxton/Geminilake: Bspec says that DDI_A_4_LANES is the only 4831379bc100SJani Nikula * supported configuration 4832379bc100SJani Nikula */ 4833379bc100SJani Nikula if (IS_GEN9_LP(dev_priv)) 4834379bc100SJani Nikula return true; 4835379bc100SJani Nikula 4836379bc100SJani Nikula /* Cannonlake: Most of SKUs don't support DDI_E, and the only 4837379bc100SJani Nikula * one who does also have a full A/E split called 4838379bc100SJani Nikula * DDI_F what makes DDI_E useless. However for this 4839379bc100SJani Nikula * case let's trust VBT info. 4840379bc100SJani Nikula */ 4841379bc100SJani Nikula if (IS_CANNONLAKE(dev_priv) && 4842379bc100SJani Nikula !intel_bios_is_port_present(dev_priv, PORT_E)) 4843379bc100SJani Nikula return true; 4844379bc100SJani Nikula 4845379bc100SJani Nikula return false; 4846379bc100SJani Nikula } 4847379bc100SJani Nikula 4848379bc100SJani Nikula static int 48497801f3b7SLucas De Marchi intel_ddi_max_lanes(struct intel_digital_port *dig_port) 4850379bc100SJani Nikula { 48517801f3b7SLucas De Marchi struct drm_i915_private *dev_priv = to_i915(dig_port->base.base.dev); 48527801f3b7SLucas De Marchi enum port port = dig_port->base.port; 4853379bc100SJani Nikula int max_lanes = 4; 4854379bc100SJani Nikula 4855379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 4856379bc100SJani Nikula return max_lanes; 4857379bc100SJani Nikula 4858379bc100SJani Nikula if (port == PORT_A || port == PORT_E) { 4859f7960e7fSJani Nikula if (intel_de_read(dev_priv, DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) 4860379bc100SJani Nikula max_lanes = port == PORT_A ? 4 : 0; 4861379bc100SJani Nikula else 4862379bc100SJani Nikula /* Both A and E share 2 lanes */ 4863379bc100SJani Nikula max_lanes = 2; 4864379bc100SJani Nikula } 4865379bc100SJani Nikula 4866379bc100SJani Nikula /* 4867379bc100SJani Nikula * Some BIOS might fail to set this bit on port A if eDP 4868379bc100SJani Nikula * wasn't lit up at boot. Force this bit set when needed 4869379bc100SJani Nikula * so we use the proper lane count for our calculations. 4870379bc100SJani Nikula */ 48717801f3b7SLucas De Marchi if (intel_ddi_a_force_4_lanes(dig_port)) { 487247bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 487347bdb1caSJani Nikula "Forcing DDI_A_4_LANES for port A\n"); 48747801f3b7SLucas De Marchi dig_port->saved_port_bits |= DDI_A_4_LANES; 4875379bc100SJani Nikula max_lanes = 4; 4876379bc100SJani Nikula } 4877379bc100SJani Nikula 4878379bc100SJani Nikula return max_lanes; 4879379bc100SJani Nikula } 4880379bc100SJani Nikula 4881379bc100SJani Nikula void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port) 4882379bc100SJani Nikula { 48837801f3b7SLucas De Marchi struct intel_digital_port *dig_port; 488470dfbc29SLucas De Marchi struct intel_encoder *encoder; 4885379bc100SJani Nikula bool init_hdmi, init_dp, init_lspcon = false; 4886d8fe2ab6SMatt Roper enum phy phy = intel_port_to_phy(dev_priv, port); 4887379bc100SJani Nikula 4888c5faae5aSJani Nikula init_hdmi = intel_bios_port_supports_dvi(dev_priv, port) || 4889c5faae5aSJani Nikula intel_bios_port_supports_hdmi(dev_priv, port); 4890c5faae5aSJani Nikula init_dp = intel_bios_port_supports_dp(dev_priv, port); 4891379bc100SJani Nikula 4892379bc100SJani Nikula if (intel_bios_is_lspcon_present(dev_priv, port)) { 4893379bc100SJani Nikula /* 4894379bc100SJani Nikula * Lspcon device needs to be driven with DP connector 4895379bc100SJani Nikula * with special detection sequence. So make sure DP 4896379bc100SJani Nikula * is initialized before lspcon. 4897379bc100SJani Nikula */ 4898379bc100SJani Nikula init_dp = true; 4899379bc100SJani Nikula init_lspcon = true; 4900379bc100SJani Nikula init_hdmi = false; 490147bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, "VBT says port %c has lspcon\n", 490247bdb1caSJani Nikula port_name(port)); 4903379bc100SJani Nikula } 4904379bc100SJani Nikula 4905379bc100SJani Nikula if (!init_dp && !init_hdmi) { 490647bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 490747bdb1caSJani Nikula "VBT says port %c is not DVI/HDMI/DP compatible, respect it\n", 4908379bc100SJani Nikula port_name(port)); 4909379bc100SJani Nikula return; 4910379bc100SJani Nikula } 4911379bc100SJani Nikula 49127801f3b7SLucas De Marchi dig_port = kzalloc(sizeof(*dig_port), GFP_KERNEL); 49137801f3b7SLucas De Marchi if (!dig_port) 4914379bc100SJani Nikula return; 4915379bc100SJani Nikula 49167801f3b7SLucas De Marchi encoder = &dig_port->base; 4917379bc100SJani Nikula 491870dfbc29SLucas De Marchi drm_encoder_init(&dev_priv->drm, &encoder->base, &intel_ddi_funcs, 4919379bc100SJani Nikula DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port)); 4920379bc100SJani Nikula 492170dfbc29SLucas De Marchi encoder->hotplug = intel_ddi_hotplug; 492270dfbc29SLucas De Marchi encoder->compute_output_type = intel_ddi_compute_output_type; 492370dfbc29SLucas De Marchi encoder->compute_config = intel_ddi_compute_config; 4924b50a1aa6SManasi Navare encoder->compute_config_late = intel_ddi_compute_config_late; 492570dfbc29SLucas De Marchi encoder->enable = intel_enable_ddi; 492670dfbc29SLucas De Marchi encoder->pre_pll_enable = intel_ddi_pre_pll_enable; 492770dfbc29SLucas De Marchi encoder->pre_enable = intel_ddi_pre_enable; 492870dfbc29SLucas De Marchi encoder->disable = intel_disable_ddi; 492970dfbc29SLucas De Marchi encoder->post_disable = intel_ddi_post_disable; 493070dfbc29SLucas De Marchi encoder->update_pipe = intel_ddi_update_pipe; 493170dfbc29SLucas De Marchi encoder->get_hw_state = intel_ddi_get_hw_state; 493270dfbc29SLucas De Marchi encoder->get_config = intel_ddi_get_config; 493370dfbc29SLucas De Marchi encoder->suspend = intel_dp_encoder_suspend; 493470dfbc29SLucas De Marchi encoder->get_power_domains = intel_ddi_get_power_domains; 493570dfbc29SLucas De Marchi 493670dfbc29SLucas De Marchi encoder->type = INTEL_OUTPUT_DDI; 493770dfbc29SLucas De Marchi encoder->power_domain = intel_port_to_power_domain(port); 493870dfbc29SLucas De Marchi encoder->port = port; 493970dfbc29SLucas De Marchi encoder->cloneable = 0; 494070dfbc29SLucas De Marchi encoder->pipe_mask = ~0; 4941379bc100SJani Nikula 4942379bc100SJani Nikula if (INTEL_GEN(dev_priv) >= 11) 49437801f3b7SLucas De Marchi dig_port->saved_port_bits = 49447801f3b7SLucas De Marchi intel_de_read(dev_priv, DDI_BUF_CTL(port)) 49457801f3b7SLucas De Marchi & DDI_BUF_PORT_REVERSAL; 4946379bc100SJani Nikula else 49477801f3b7SLucas De Marchi dig_port->saved_port_bits = 49487801f3b7SLucas De Marchi intel_de_read(dev_priv, DDI_BUF_CTL(port)) 49497801f3b7SLucas De Marchi & (DDI_BUF_PORT_REVERSAL | DDI_A_4_LANES); 495070dfbc29SLucas De Marchi 49517801f3b7SLucas De Marchi dig_port->dp.output_reg = INVALID_MMIO_REG; 49527801f3b7SLucas De Marchi dig_port->max_lanes = intel_ddi_max_lanes(dig_port); 49537801f3b7SLucas De Marchi dig_port->aux_ch = intel_bios_port_aux_ch(dev_priv, port); 4954379bc100SJani Nikula 4955d8fe2ab6SMatt Roper if (intel_phy_is_tc(dev_priv, phy)) { 4956c5faae5aSJani Nikula bool is_legacy = 4957c5faae5aSJani Nikula !intel_bios_port_supports_typec_usb(dev_priv, port) && 4958c5faae5aSJani Nikula !intel_bios_port_supports_tbt(dev_priv, port); 4959379bc100SJani Nikula 49607801f3b7SLucas De Marchi intel_tc_port_init(dig_port, is_legacy); 496124a7bfe0SImre Deak 496270dfbc29SLucas De Marchi encoder->update_prepare = intel_ddi_update_prepare; 496370dfbc29SLucas De Marchi encoder->update_complete = intel_ddi_update_complete; 4964ab7bc4e1SImre Deak } 4965ab7bc4e1SImre Deak 49661de143ccSPankaj Bharadiya drm_WARN_ON(&dev_priv->drm, port > PORT_I); 49677801f3b7SLucas De Marchi dig_port->ddi_io_power_domain = POWER_DOMAIN_PORT_DDI_A_IO + 4968327f8d8cSLucas De Marchi port - PORT_A; 4969379bc100SJani Nikula 4970379bc100SJani Nikula if (init_dp) { 49717801f3b7SLucas De Marchi if (!intel_ddi_init_dp_connector(dig_port)) 4972379bc100SJani Nikula goto err; 4973379bc100SJani Nikula 49747801f3b7SLucas De Marchi dig_port->hpd_pulse = intel_dp_hpd_pulse; 4975379bc100SJani Nikula } 4976379bc100SJani Nikula 4977379bc100SJani Nikula /* In theory we don't need the encoder->type check, but leave it just in 4978379bc100SJani Nikula * case we have some really bad VBTs... */ 497970dfbc29SLucas De Marchi if (encoder->type != INTEL_OUTPUT_EDP && init_hdmi) { 49807801f3b7SLucas De Marchi if (!intel_ddi_init_hdmi_connector(dig_port)) 4981379bc100SJani Nikula goto err; 4982379bc100SJani Nikula } 4983379bc100SJani Nikula 4984379bc100SJani Nikula if (init_lspcon) { 49857801f3b7SLucas De Marchi if (lspcon_init(dig_port)) 4986379bc100SJani Nikula /* TODO: handle hdmi info frame part */ 498747bdb1caSJani Nikula drm_dbg_kms(&dev_priv->drm, 498847bdb1caSJani Nikula "LSPCON init success on port %c\n", 4989379bc100SJani Nikula port_name(port)); 4990379bc100SJani Nikula else 4991379bc100SJani Nikula /* 4992379bc100SJani Nikula * LSPCON init faied, but DP init was success, so 4993379bc100SJani Nikula * lets try to drive as DP++ port. 4994379bc100SJani Nikula */ 499547bdb1caSJani Nikula drm_err(&dev_priv->drm, 499647bdb1caSJani Nikula "LSPCON init failed on port %c\n", 4997379bc100SJani Nikula port_name(port)); 4998379bc100SJani Nikula } 4999379bc100SJani Nikula 5000edc0e09cSVille Syrjälä if (INTEL_GEN(dev_priv) >= 11) { 5001edc0e09cSVille Syrjälä if (intel_phy_is_tc(dev_priv, phy)) 50027801f3b7SLucas De Marchi dig_port->connected = intel_tc_port_connected; 5003edc0e09cSVille Syrjälä else 50047801f3b7SLucas De Marchi dig_port->connected = lpt_digital_port_connected; 5005c7e8a3d6SVille Syrjälä } else if (INTEL_GEN(dev_priv) >= 8) { 5006c7e8a3d6SVille Syrjälä if (port == PORT_A || IS_GEN9_LP(dev_priv)) 50077801f3b7SLucas De Marchi dig_port->connected = bdw_digital_port_connected; 5008edc0e09cSVille Syrjälä else 50097801f3b7SLucas De Marchi dig_port->connected = lpt_digital_port_connected; 5010edc0e09cSVille Syrjälä } else { 5011c7e8a3d6SVille Syrjälä if (port == PORT_A) 50127801f3b7SLucas De Marchi dig_port->connected = hsw_digital_port_connected; 5013edc0e09cSVille Syrjälä else 50147801f3b7SLucas De Marchi dig_port->connected = lpt_digital_port_connected; 5015edc0e09cSVille Syrjälä } 5016edc0e09cSVille Syrjälä 50177801f3b7SLucas De Marchi intel_infoframe_init(dig_port); 5018379bc100SJani Nikula 5019379bc100SJani Nikula return; 5020379bc100SJani Nikula 5021379bc100SJani Nikula err: 502270dfbc29SLucas De Marchi drm_encoder_cleanup(&encoder->base); 50237801f3b7SLucas De Marchi kfree(dig_port); 5024379bc100SJani Nikula } 5025