blob: 15d3720e437b9de006c482c3e45a1f221f9f66d7 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
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 Huber125a29e2016-10-18 00:23:54 +02006-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02008--
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
15with HW.GFX.DP_Training;
16with HW.GFX.GMA.DP_Aux_Ch;
17with HW.GFX.GMA.DP_Info;
18with HW.GFX.GMA.Registers;
19
20with HW.Debug;
21with GNAT.Source_Info;
22
23package 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;
37 DP_CTL_PORT_REVERSAL : constant := 1 * 2 ** 15;
38 DP_CTL_LINK_TRAIN_MASK : constant := 7 * 2 ** 8;
39 DP_CTL_LINK_TRAIN_PAT1 : constant := 0 * 2 ** 8;
40 DP_CTL_LINK_TRAIN_PAT2 : constant := 1 * 2 ** 8;
41 DP_CTL_LINK_TRAIN_IDLE : constant := 2 * 2 ** 8;
42 DP_CTL_LINK_TRAIN_NORMAL : constant := 3 * 2 ** 8;
43 DP_CTL_AUDIO_OUTPUT_ENABLE : constant := 1 * 2 ** 6;
44 DP_CTL_PORT_DETECT : constant := 1 * 2 ** 2;
45
46 function DP_CTL_VSWING_LEVEL_SET
47 (VS : DP_Info.DP_Voltage_Swing)
48 return Word32
49 is
50 begin
51 return Shift_Left
52 (Word32 (DP_Info.DP_Voltage_Swing'Pos (VS)),
53 DP_CTL_VSWING_LEVEL_SET_SHIFT);
54 end DP_CTL_VSWING_LEVEL_SET;
55
56 function DP_CTL_PREEMPH_LEVEL_SET (PE : DP_Info.DP_Pre_Emph) return Word32
57 is
58 begin
59 return Shift_Left
60 (Word32 (DP_Info.DP_Pre_Emph'Pos (PE)), DP_CTL_PREEMPH_LEVEL_SET_SHIFT);
61 end DP_CTL_PREEMPH_LEVEL_SET;
62
63 function DP_CTL_PORT_WIDTH (Lane_Count : DP_Lane_Count) return Word32
64 is
65 begin
66 return Shift_Left
67 (Word32 (Lane_Count_As_Integer (Lane_Count)) - 1,
68 DP_CTL_PORT_WIDTH_SHIFT);
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 => DP_CTL_LINK_TRAIN_PAT1,
74 DP_Info.TP_2 => DP_CTL_LINK_TRAIN_PAT2,
75 DP_Info.TP_3 => DP_CTL_LINK_TRAIN_PAT2,
76 DP_Info.TP_Idle => DP_CTL_LINK_TRAIN_IDLE,
77 DP_Info.TP_None => DP_CTL_LINK_TRAIN_NORMAL);
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 : PCH_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 : PCH_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 : PCH_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 : PCH_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 : PCH_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 Success : out Boolean)
157 is
158 function To_DP (Port : PCH_DP_Port) return DP_Port
159 is
160 begin
161 return
162 (case Port is
163 when PCH_DP_B => DP_B,
164 when PCH_DP_C => DP_C,
165 when PCH_DP_D => DP_D);
166 end To_DP;
167 package Training is new DP_Training
168 (TPS3_Supported => False,
169 T => PCH_DP_Port,
170 Aux_T => DP_Port,
171 Aux_Ch => DP_Aux_Ch,
172 DP_Info => DP_Info,
173 To_Aux => To_DP,
174 Max_V_Swing => Max_V_Swing,
175 Max_Pre_Emph => Max_Pre_Emph,
176 Set_Pattern => Set_Training_Pattern,
177 Set_Signal_Levels => Set_Signal_Levels,
178 Off => Off);
179 begin
180 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
181
182 Registers.Write
183 (Register => DP_CTL (Port_Cfg.PCH_Port),
184 Value => DP_CTL_DISPLAY_PORT_ENABLE or
185 DP_CTL_PORT_WIDTH (Port_Cfg.DP.Lane_Count) or
186 DP_CTL_LINK_TRAIN_PAT1);
187
188 Training.Train_DP
189 (Port => Port_Cfg.PCH_Port,
190 Link => Port_Cfg.DP,
191 Success => Success);
192 end On;
193
194 ----------------------------------------------------------------------------
195
196 procedure All_Off
197 is
198 begin
199 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
200
201 for Port in PCH_DP_Port loop
202 Off (Port);
203 end loop;
204 end All_Off;
205
206end HW.GFX.GMA.PCH.DP;