| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2016 Nico Huber <nico.h@gmx.de> |
| 3 | -- |
| 4 | -- This program is free software; you can redistribute it and/or modify |
| 5 | -- it under the terms of the GNU General Public License as published by |
| Nico Huber | 125a29e | 2016-10-18 00:23:54 +0200 | [diff] [blame] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 8 | -- |
| 9 | -- This program is distributed in the hope that it will be useful, |
| 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | -- GNU General Public License for more details. |
| 13 | -- |
| 14 | |
| 15 | with HW.GFX.DP_Training; |
| 16 | with HW.GFX.GMA.DP_Aux_Ch; |
| 17 | with HW.GFX.GMA.DP_Info; |
| 18 | with HW.GFX.GMA.Registers; |
| 19 | |
| 20 | with HW.Debug; |
| 21 | with GNAT.Source_Info; |
| 22 | |
| 23 | package body HW.GFX.GMA.PCH.DP is |
| 24 | |
| 25 | type DP_Array is array (PCH_DP_Port) of Registers.Registers_Index; |
| 26 | DP_CTL : constant DP_Array := |
| 27 | (PCH_DP_B => Registers.PCH_DP_B, |
| 28 | PCH_DP_C => Registers.PCH_DP_C, |
| 29 | PCH_DP_D => Registers.PCH_DP_D); |
| 30 | |
| 31 | DP_CTL_DISPLAY_PORT_ENABLE : constant := 1 * 2 ** 31; |
| 32 | DP_CTL_VSWING_LEVEL_SET_SHIFT : constant := 25; |
| 33 | DP_CTL_VSWING_LEVEL_SET_MASK : constant := 7 * 2 ** 25; |
| 34 | DP_CTL_PREEMPH_LEVEL_SET_SHIFT : constant := 22; |
| 35 | DP_CTL_PREEMPH_LEVEL_SET_MASK : constant := 7 * 2 ** 22; |
| 36 | DP_CTL_PORT_WIDTH_SHIFT : constant := 19; |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 37 | DP_CTL_ENHANCED_FRAMING_ENABLE : constant := 1 * 2 ** 18; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 38 | DP_CTL_PORT_REVERSAL : constant := 1 * 2 ** 15; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 39 | DP_CTL_AUDIO_OUTPUT_ENABLE : constant := 1 * 2 ** 6; |
| 40 | DP_CTL_PORT_DETECT : constant := 1 * 2 ** 2; |
| 41 | |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 42 | function DP_CTL_LINK_TRAIN_SHIFT return Natural is |
| 43 | (if Config.Has_Trans_DP_Ctl then 8 else 28); |
| 44 | |
| 45 | function DP_CTL_LINK_TRAIN_MASK return Word32 is |
| 46 | (if Config.Has_Trans_DP_Ctl then 7 * 2 ** 8 else 3 * 2 ** 28); |
| 47 | |
| 48 | function DP_CTL_LINK_TRAIN (Pat : DP_Info.Training_Pattern) return Word32 is |
| 49 | (case Pat is |
| 50 | when DP_Info.TP_1 => Shift_Left (0, DP_CTL_LINK_TRAIN_SHIFT), |
| 51 | when DP_Info.TP_2 => Shift_Left (1, DP_CTL_LINK_TRAIN_SHIFT), |
| 52 | when DP_Info.TP_3 => Shift_Left (1, DP_CTL_LINK_TRAIN_SHIFT), |
| 53 | when DP_Info.TP_Idle => Shift_Left (2, DP_CTL_LINK_TRAIN_SHIFT), |
| 54 | when DP_Info.TP_None => Shift_Left (3, DP_CTL_LINK_TRAIN_SHIFT)); |
| 55 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 56 | function DP_CTL_VSWING_LEVEL_SET |
| 57 | (VS : DP_Info.DP_Voltage_Swing) |
| 58 | return Word32 |
| 59 | is |
| 60 | begin |
| 61 | return Shift_Left |
| 62 | (Word32 (DP_Info.DP_Voltage_Swing'Pos (VS)), |
| 63 | DP_CTL_VSWING_LEVEL_SET_SHIFT); |
| 64 | end DP_CTL_VSWING_LEVEL_SET; |
| 65 | |
| 66 | function DP_CTL_PREEMPH_LEVEL_SET (PE : DP_Info.DP_Pre_Emph) return Word32 |
| 67 | is |
| 68 | begin |
| 69 | return Shift_Left |
| 70 | (Word32 (DP_Info.DP_Pre_Emph'Pos (PE)), DP_CTL_PREEMPH_LEVEL_SET_SHIFT); |
| 71 | end DP_CTL_PREEMPH_LEVEL_SET; |
| 72 | |
| 73 | function DP_CTL_PORT_WIDTH (Lane_Count : DP_Lane_Count) return Word32 |
| 74 | is |
| 75 | begin |
| 76 | return Shift_Left |
| 77 | (Word32 (Lane_Count_As_Integer (Lane_Count)) - 1, |
| 78 | DP_CTL_PORT_WIDTH_SHIFT); |
| 79 | end DP_CTL_PORT_WIDTH; |
| 80 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 81 | ---------------------------------------------------------------------------- |
| 82 | |
| 83 | pragma Warnings (GNATprove, Off, "unused variable ""Port""", |
| 84 | Reason => "Needed for a common interface"); |
| 85 | function Max_V_Swing |
| 86 | (Port : PCH_DP_Port) |
| 87 | return DP_Info.DP_Voltage_Swing |
| 88 | is |
| 89 | begin |
| 90 | return DP_Info.VS_Level_3; |
| 91 | end Max_V_Swing; |
| 92 | |
| 93 | function Max_Pre_Emph |
| 94 | (Port : PCH_DP_Port; |
| 95 | Train_Set : DP_Info.Train_Set) |
| 96 | return DP_Info.DP_Pre_Emph |
| 97 | is |
| 98 | begin |
| 99 | return |
| 100 | (case Train_Set.Voltage_Swing is |
| 101 | when DP_Info.VS_Level_0 => DP_Info.Emph_Level_3, |
| 102 | when DP_Info.VS_Level_1 => DP_Info.Emph_Level_2, |
| 103 | when DP_Info.VS_Level_2 => DP_Info.Emph_Level_1, |
| 104 | when DP_Info.VS_Level_3 => DP_Info.Emph_Level_0); |
| 105 | end Max_Pre_Emph; |
| 106 | |
| 107 | ---------------------------------------------------------------------------- |
| 108 | |
| 109 | pragma Warnings (GNATprove, Off, "unused variable ""Link""", |
| 110 | Reason => "Needed for a common interface"); |
| 111 | procedure Set_Training_Pattern |
| 112 | (Port : PCH_DP_Port; |
| 113 | Link : DP_Link; |
| 114 | Pattern : DP_Info.Training_Pattern) |
| 115 | is |
| 116 | begin |
| 117 | Registers.Unset_And_Set_Mask |
| 118 | (Register => DP_CTL (Port), |
| 119 | Mask_Unset => DP_CTL_LINK_TRAIN_MASK, |
| 120 | Mask_Set => DP_CTL_LINK_TRAIN (Pattern)); |
| 121 | end Set_Training_Pattern; |
| 122 | |
| 123 | procedure Set_Signal_Levels |
| 124 | (Port : PCH_DP_Port; |
| 125 | Link : DP_Link; |
| 126 | Train_Set : DP_Info.Train_Set) |
| 127 | is |
| 128 | begin |
| 129 | Registers.Unset_And_Set_Mask |
| 130 | (Register => DP_CTL (Port), |
| 131 | Mask_Unset => DP_CTL_VSWING_LEVEL_SET_MASK or |
| 132 | DP_CTL_PREEMPH_LEVEL_SET_MASK, |
| 133 | Mask_Set => DP_CTL_VSWING_LEVEL_SET (Train_Set.Voltage_Swing) or |
| 134 | DP_CTL_PREEMPH_LEVEL_SET (Train_Set.Pre_Emph)); |
| 135 | end Set_Signal_Levels; |
| 136 | |
| 137 | procedure Off (Port : PCH_DP_Port) |
| 138 | is |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 139 | With_Transcoder_B_Enabled : Boolean := False; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 140 | begin |
| 141 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 142 | |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 143 | if not Config.Has_Trans_DP_Ctl then |
| 144 | -- Ensure transcoder select isn't set to B, |
| 145 | -- disabled DP may block HDMI otherwise. |
| 146 | Registers.Is_Set_Mask |
| 147 | (Register => DP_CTL (Port), |
| 148 | Mask => DP_CTL_DISPLAY_PORT_ENABLE or |
| 149 | PCH_TRANSCODER_SELECT (FDI_B), |
| 150 | Result => With_Transcoder_B_Enabled); |
| 151 | end if; |
| 152 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 153 | Registers.Unset_And_Set_Mask |
| 154 | (Register => DP_CTL (Port), |
| 155 | Mask_Unset => DP_CTL_LINK_TRAIN_MASK, |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 156 | Mask_Set => DP_CTL_LINK_TRAIN (DP_Info.TP_Idle)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 157 | Registers.Posting_Read (DP_CTL (Port)); |
| 158 | |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 159 | Registers.Unset_Mask (DP_CTL (Port), DP_CTL_DISPLAY_PORT_ENABLE); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 160 | Registers.Posting_Read (DP_CTL (Port)); |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 161 | |
| 162 | if not Config.Has_Trans_DP_Ctl and then With_Transcoder_B_Enabled then |
| 163 | -- Reenable with transcoder A selected to switch. |
| 164 | Registers.Unset_And_Set_Mask |
| 165 | (Register => DP_CTL (Port), |
| 166 | Mask_Unset => PCH_TRANSCODER_SELECT_MASK or |
| 167 | DP_CTL_LINK_TRAIN_MASK, |
| 168 | Mask_Set => DP_CTL_DISPLAY_PORT_ENABLE or |
| 169 | PCH_TRANSCODER_SELECT (FDI_A) or |
| 170 | DP_CTL_LINK_TRAIN (DP_Info.TP_1)); |
| 171 | Registers.Posting_Read (DP_CTL (Port)); |
| 172 | Registers.Unset_Mask (DP_CTL (Port), DP_CTL_DISPLAY_PORT_ENABLE); |
| 173 | Registers.Posting_Read (DP_CTL (Port)); |
| 174 | end if; |
| 175 | |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 176 | end Off; |
| 177 | pragma Warnings (GNATprove, On, "unused variable ""Port"""); |
| 178 | pragma Warnings (GNATprove, On, "unused variable ""Link"""); |
| 179 | |
| 180 | ---------------------------------------------------------------------------- |
| 181 | |
| 182 | procedure On |
| 183 | (Port_Cfg : in Port_Config; |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 184 | FDI_Port : in FDI_Port_Type; |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 185 | Success : out Boolean) |
| 186 | is |
| 187 | function To_DP (Port : PCH_DP_Port) return DP_Port |
| 188 | is |
| 189 | begin |
| 190 | return |
| 191 | (case Port is |
| 192 | when PCH_DP_B => DP_B, |
| 193 | when PCH_DP_C => DP_C, |
| 194 | when PCH_DP_D => DP_D); |
| 195 | end To_DP; |
| 196 | package Training is new DP_Training |
| 197 | (TPS3_Supported => False, |
| 198 | T => PCH_DP_Port, |
| 199 | Aux_T => DP_Port, |
| 200 | Aux_Ch => DP_Aux_Ch, |
| 201 | DP_Info => DP_Info, |
| 202 | To_Aux => To_DP, |
| 203 | Max_V_Swing => Max_V_Swing, |
| 204 | Max_Pre_Emph => Max_Pre_Emph, |
| 205 | Set_Pattern => Set_Training_Pattern, |
| 206 | Set_Signal_Levels => Set_Signal_Levels, |
| 207 | Off => Off); |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 208 | |
| 209 | DP_CTL_Transcoder_Select : constant Word32 := |
| 210 | (if Config.Has_Trans_DP_Ctl |
| 211 | then 0 else PCH_TRANSCODER_SELECT (FDI_Port)); |
| 212 | DP_CTL_Enhanced_Framing : constant Word32 := |
| 213 | (if Config.Has_Trans_DP_Ctl |
| 214 | then 0 else DP_CTL_ENHANCED_FRAMING_ENABLE); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 215 | begin |
| 216 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 217 | |
| 218 | Registers.Write |
| 219 | (Register => DP_CTL (Port_Cfg.PCH_Port), |
| 220 | Value => DP_CTL_DISPLAY_PORT_ENABLE or |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 221 | DP_CTL_Transcoder_Select or |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 222 | DP_CTL_PORT_WIDTH (Port_Cfg.DP.Lane_Count) or |
| Nico Huber | f6a2d18 | 2019-10-01 10:37:49 +0200 | [diff] [blame] | 223 | DP_CTL_Enhanced_Framing or |
| 224 | DP_CTL_LINK_TRAIN (DP_Info.TP_1)); |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 225 | |
| 226 | Training.Train_DP |
| 227 | (Port => Port_Cfg.PCH_Port, |
| 228 | Link => Port_Cfg.DP, |
| 229 | Success => Success); |
| 230 | end On; |
| 231 | |
| 232 | ---------------------------------------------------------------------------- |
| 233 | |
| 234 | procedure All_Off |
| 235 | is |
| 236 | begin |
| 237 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 238 | |
| 239 | for Port in PCH_DP_Port loop |
| 240 | Off (Port); |
| 241 | end loop; |
| 242 | end All_Off; |
| 243 | |
| 244 | end HW.GFX.GMA.PCH.DP; |