| Arthur Heymans | 73ea032 | 2018-03-28 17:17:07 +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 |
| 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| 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.GMCH.DP is |
| 24 | |
| 25 | type DP_Array is array (GMCH_DP_Port) of Registers.Registers_Index; |
| 26 | DP_CTL : constant DP_Array := |
| 27 | (DIGI_B => Registers.GMCH_DP_B, |
| 28 | DIGI_C => Registers.GMCH_DP_C, |
| 29 | DIGI_D => Registers.GMCH_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; |
| 37 | DP_CTL_ENHANCED_FRAMING_ENABLE : constant := 1 * 2 ** 18; |
| 38 | DP_CTL_PORT_REVERSAL : constant := 1 * 2 ** 15; |
| 39 | DP_CTL_LINK_TRAIN_MASK : constant := 3 * 2 ** 28; |
| 40 | DP_CTL_LINK_TRAIN_PAT1 : constant := 0 * 2 ** 28; |
| 41 | DP_CTL_LINK_TRAIN_PAT2 : constant := 1 * 2 ** 28; |
| 42 | DP_CTL_LINK_TRAIN_IDLE : constant := 2 * 2 ** 28; |
| 43 | DP_CTL_LINK_TRAIN_NORMAL : constant := 3 * 2 ** 28; |
| 44 | DP_CTL_AUDIO_OUTPUT_ENABLE : constant := 1 * 2 ** 6; |
| 45 | DP_CTL_PORT_DETECT : constant := 1 * 2 ** 2; |
| 46 | DP_CTL_VSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 4; |
| 47 | DP_CTL_HSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 3; |
| 48 | DP_CTL_COLOR_RANGE_16_235 : constant := 1 * 2 ** 8; |
| 49 | DP_CTL_SCRAMBLE_DISABLE : constant := 1 * 2 ** 7; |
| 50 | |
| 51 | function DP_CTL_VSWING_LEVEL_SET |
| 52 | (VS : DP_Info.DP_Voltage_Swing) |
| 53 | return Word32 |
| 54 | is |
| 55 | begin |
| 56 | return Shift_Left(Word32 (DP_Info.DP_Voltage_Swing'Pos (VS)), 25); |
| 57 | end DP_CTL_VSWING_LEVEL_SET; |
| 58 | |
| 59 | function DP_CTL_PREEMPH_LEVEL_SET (PE : DP_Info.DP_Pre_Emph) return Word32 |
| 60 | is |
| 61 | begin |
| 62 | return Shift_Left(Word32 (DP_Info.DP_Pre_Emph'Pos (PE)), 22); |
| 63 | end DP_CTL_PREEMPH_LEVEL_SET; |
| 64 | |
| 65 | function DP_CTL_PORT_WIDTH (Lane_Count : DP_Lane_Count) return Word32 |
| 66 | is |
| 67 | begin |
| 68 | return Shift_Left(Word32 (Lane_Count_As_Integer (Lane_Count)) - 1, 19); |
| 69 | end DP_CTL_PORT_WIDTH; |
| 70 | |
| 71 | type DP_CTL_LINK_TRAIN_Array is array (DP_Info.Training_Pattern) of Word32; |
| 72 | DP_CTL_LINK_TRAIN : constant DP_CTL_LINK_TRAIN_Array := |
| 73 | (DP_Info.TP_1 => 0 * 2 ** 28, |
| 74 | DP_Info.TP_2 => 1 * 2 ** 28, |
| 75 | DP_Info.TP_3 => 1 * 2 ** 28, |
| 76 | DP_Info.TP_Idle => 2 * 2 ** 28, |
| 77 | DP_Info.TP_None => 3 * 2 ** 28); |
| 78 | |
| 79 | ---------------------------------------------------------------------------- |
| 80 | |
| 81 | pragma Warnings (GNATprove, Off, "unused variable ""Port""", |
| 82 | Reason => "Needed for a common interface"); |
| 83 | function Max_V_Swing |
| 84 | (Port : GMCH_DP_Port) |
| 85 | return DP_Info.DP_Voltage_Swing |
| 86 | is |
| 87 | begin |
| 88 | return DP_Info.VS_Level_3; |
| 89 | end Max_V_Swing; |
| 90 | |
| 91 | function Max_Pre_Emph |
| 92 | (Port : GMCH_DP_Port; |
| 93 | Train_Set : DP_Info.Train_Set) |
| 94 | return DP_Info.DP_Pre_Emph |
| 95 | is |
| 96 | begin |
| 97 | return |
| 98 | (case Train_Set.Voltage_Swing is |
| 99 | when DP_Info.VS_Level_0 => DP_Info.Emph_Level_3, |
| 100 | when DP_Info.VS_Level_1 => DP_Info.Emph_Level_2, |
| 101 | when DP_Info.VS_Level_2 => DP_Info.Emph_Level_1, |
| 102 | when DP_Info.VS_Level_3 => DP_Info.Emph_Level_0); |
| 103 | end Max_Pre_Emph; |
| 104 | |
| 105 | ---------------------------------------------------------------------------- |
| 106 | |
| 107 | pragma Warnings (GNATprove, Off, "unused variable ""Link""", |
| 108 | Reason => "Needed for a common interface"); |
| 109 | procedure Set_Training_Pattern |
| 110 | (Port : GMCH_DP_Port; |
| 111 | Link : DP_Link; |
| 112 | Pattern : DP_Info.Training_Pattern) |
| 113 | is |
| 114 | begin |
| 115 | Registers.Unset_And_Set_Mask |
| 116 | (Register => DP_CTL (Port), |
| 117 | Mask_Unset => DP_CTL_LINK_TRAIN_MASK, |
| 118 | Mask_Set => DP_CTL_LINK_TRAIN (Pattern)); |
| 119 | end Set_Training_Pattern; |
| 120 | |
| 121 | procedure Set_Signal_Levels |
| 122 | (Port : GMCH_DP_Port; |
| 123 | Link : DP_Link; |
| 124 | Train_Set : DP_Info.Train_Set) |
| 125 | is |
| 126 | begin |
| 127 | Registers.Unset_And_Set_Mask |
| 128 | (Register => DP_CTL (Port), |
| 129 | Mask_Unset => DP_CTL_VSWING_LEVEL_SET_MASK or |
| 130 | DP_CTL_PREEMPH_LEVEL_SET_MASK, |
| 131 | Mask_Set => DP_CTL_VSWING_LEVEL_SET (Train_Set.Voltage_Swing) or |
| 132 | DP_CTL_PREEMPH_LEVEL_SET (Train_Set.Pre_Emph)); |
| 133 | end Set_Signal_Levels; |
| 134 | |
| 135 | procedure Off (Port : GMCH_DP_Port) |
| 136 | is |
| 137 | begin |
| 138 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 139 | |
| 140 | Registers.Unset_And_Set_Mask |
| 141 | (Register => DP_CTL (Port), |
| 142 | Mask_Unset => DP_CTL_LINK_TRAIN_MASK, |
| 143 | Mask_Set => DP_CTL_LINK_TRAIN_IDLE); |
| 144 | Registers.Posting_Read (DP_CTL (Port)); |
| 145 | |
| 146 | Registers.Write (DP_CTL (Port), 0); |
| 147 | Registers.Posting_Read (DP_CTL (Port)); |
| 148 | end Off; |
| 149 | pragma Warnings (GNATprove, On, "unused variable ""Port"""); |
| 150 | pragma Warnings (GNATprove, On, "unused variable ""Link"""); |
| 151 | |
| 152 | ---------------------------------------------------------------------------- |
| 153 | |
| 154 | procedure On |
| 155 | (Port_Cfg : in Port_Config; |
| 156 | Pipe : in Pipe_Index; |
| 157 | Success : out Boolean) |
| 158 | is |
| 159 | function To_DP (Port : GMCH_DP_Port) return DP_Port |
| 160 | is |
| 161 | begin |
| 162 | return |
| 163 | (case Port is |
| 164 | when DIGI_B => DP_B, |
| 165 | when DIGI_C => DP_C, |
| 166 | when DIGI_D => DP_D); |
| 167 | end To_DP; |
| 168 | package Training is new DP_Training |
| 169 | (TPS3_Supported => False, |
| 170 | T => GMCH_DP_Port, |
| 171 | Aux_T => DP_Port, |
| 172 | Aux_Ch => DP_Aux_Ch, |
| 173 | DP_Info => DP_Info, |
| 174 | To_Aux => To_DP, |
| 175 | Max_V_Swing => Max_V_Swing, |
| 176 | Max_Pre_Emph => Max_Pre_Emph, |
| 177 | Set_Pattern => Set_Training_Pattern, |
| 178 | Set_Signal_Levels => Set_Signal_Levels, |
| 179 | Off => Off); |
| 180 | |
| 181 | Sync_Polarity : constant Word32 := |
| 182 | (if Port_Cfg.Mode.H_Sync_Active_High then DP_CTL_HSYNC_ACTIVE_HIGH else 0) or |
| 183 | (if Port_Cfg.Mode.V_Sync_Active_High then DP_CTL_VSYNC_ACTIVE_HIGH else 0); |
| 184 | |
| 185 | begin |
| 186 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 187 | |
| 188 | Registers.Write |
| 189 | (Register => DP_CTL (Port_Cfg.Port), |
| 190 | Value => DP_CTL_DISPLAY_PORT_ENABLE or |
| 191 | DP_CTL_PORT_WIDTH (Port_Cfg.DP.Lane_Count) or |
| 192 | DP_CTL_LINK_TRAIN_PAT1 or |
| 193 | (if Port_Cfg.DP.Enhanced_Framing |
| 194 | then DP_CTL_ENHANCED_FRAMING_ENABLE else 0) or |
| 195 | GMCH_PORT_PIPE_SELECT(Pipe) or |
| 196 | Sync_Polarity or |
| 197 | DP_CTL_COLOR_RANGE_16_235); |
| 198 | Training.Train_DP |
| 199 | (Port => Port_Cfg.Port, |
| 200 | Link => Port_Cfg.DP, |
| 201 | Success => Success); |
| 202 | end On; |
| 203 | |
| 204 | ---------------------------------------------------------------------------- |
| 205 | |
| 206 | procedure All_Off |
| 207 | is |
| 208 | begin |
| 209 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 210 | |
| 211 | for Port in GMCH_DP_Port loop |
| 212 | Off (Port); |
| 213 | end loop; |
| 214 | end All_Off; |
| 215 | |
| 216 | end HW.GFX.GMA.GMCH.DP; |