blob: 1fb3578ef7abcbc218fb3c1e871980bae6c74f70 [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
6-- the Free Software Foundation; version 2 of the License.
7--
8-- This program is distributed in the hope that it will be useful,
9-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11-- GNU General Public License for more details.
12--
13
14with HW.GFX.DP_Training;
15with HW.GFX.GMA.DP_Aux_Ch;
16with HW.GFX.GMA.DP_Info;
17with HW.GFX.GMA.Registers;
18
19with HW.Debug;
20with GNAT.Source_Info;
21
22package body HW.GFX.GMA.PCH.DP is
23
24 type DP_Array is array (PCH_DP_Port) of Registers.Registers_Index;
25 DP_CTL : constant DP_Array :=
26 (PCH_DP_B => Registers.PCH_DP_B,
27 PCH_DP_C => Registers.PCH_DP_C,
28 PCH_DP_D => Registers.PCH_DP_D);
29
30 DP_CTL_DISPLAY_PORT_ENABLE : constant := 1 * 2 ** 31;
31 DP_CTL_VSWING_LEVEL_SET_SHIFT : constant := 25;
32 DP_CTL_VSWING_LEVEL_SET_MASK : constant := 7 * 2 ** 25;
33 DP_CTL_PREEMPH_LEVEL_SET_SHIFT : constant := 22;
34 DP_CTL_PREEMPH_LEVEL_SET_MASK : constant := 7 * 2 ** 22;
35 DP_CTL_PORT_WIDTH_SHIFT : constant := 19;
36 DP_CTL_PORT_REVERSAL : constant := 1 * 2 ** 15;
37 DP_CTL_LINK_TRAIN_MASK : constant := 7 * 2 ** 8;
38 DP_CTL_LINK_TRAIN_PAT1 : constant := 0 * 2 ** 8;
39 DP_CTL_LINK_TRAIN_PAT2 : constant := 1 * 2 ** 8;
40 DP_CTL_LINK_TRAIN_IDLE : constant := 2 * 2 ** 8;
41 DP_CTL_LINK_TRAIN_NORMAL : constant := 3 * 2 ** 8;
42 DP_CTL_AUDIO_OUTPUT_ENABLE : constant := 1 * 2 ** 6;
43 DP_CTL_PORT_DETECT : constant := 1 * 2 ** 2;
44
45 function DP_CTL_VSWING_LEVEL_SET
46 (VS : DP_Info.DP_Voltage_Swing)
47 return Word32
48 is
49 begin
50 return Shift_Left
51 (Word32 (DP_Info.DP_Voltage_Swing'Pos (VS)),
52 DP_CTL_VSWING_LEVEL_SET_SHIFT);
53 end DP_CTL_VSWING_LEVEL_SET;
54
55 function DP_CTL_PREEMPH_LEVEL_SET (PE : DP_Info.DP_Pre_Emph) return Word32
56 is
57 begin
58 return Shift_Left
59 (Word32 (DP_Info.DP_Pre_Emph'Pos (PE)), DP_CTL_PREEMPH_LEVEL_SET_SHIFT);
60 end DP_CTL_PREEMPH_LEVEL_SET;
61
62 function DP_CTL_PORT_WIDTH (Lane_Count : DP_Lane_Count) return Word32
63 is
64 begin
65 return Shift_Left
66 (Word32 (Lane_Count_As_Integer (Lane_Count)) - 1,
67 DP_CTL_PORT_WIDTH_SHIFT);
68 end DP_CTL_PORT_WIDTH;
69
70 type DP_CTL_LINK_TRAIN_Array is array (DP_Info.Training_Pattern) of Word32;
71 DP_CTL_LINK_TRAIN : constant DP_CTL_LINK_TRAIN_Array :=
72 (DP_Info.TP_1 => DP_CTL_LINK_TRAIN_PAT1,
73 DP_Info.TP_2 => DP_CTL_LINK_TRAIN_PAT2,
74 DP_Info.TP_3 => DP_CTL_LINK_TRAIN_PAT2,
75 DP_Info.TP_Idle => DP_CTL_LINK_TRAIN_IDLE,
76 DP_Info.TP_None => DP_CTL_LINK_TRAIN_NORMAL);
77
78 ----------------------------------------------------------------------------
79
80 pragma Warnings (GNATprove, Off, "unused variable ""Port""",
81 Reason => "Needed for a common interface");
82 function Max_V_Swing
83 (Port : PCH_DP_Port)
84 return DP_Info.DP_Voltage_Swing
85 is
86 begin
87 return DP_Info.VS_Level_3;
88 end Max_V_Swing;
89
90 function Max_Pre_Emph
91 (Port : PCH_DP_Port;
92 Train_Set : DP_Info.Train_Set)
93 return DP_Info.DP_Pre_Emph
94 is
95 begin
96 return
97 (case Train_Set.Voltage_Swing is
98 when DP_Info.VS_Level_0 => DP_Info.Emph_Level_3,
99 when DP_Info.VS_Level_1 => DP_Info.Emph_Level_2,
100 when DP_Info.VS_Level_2 => DP_Info.Emph_Level_1,
101 when DP_Info.VS_Level_3 => DP_Info.Emph_Level_0);
102 end Max_Pre_Emph;
103
104 ----------------------------------------------------------------------------
105
106 pragma Warnings (GNATprove, Off, "unused variable ""Link""",
107 Reason => "Needed for a common interface");
108 procedure Set_Training_Pattern
109 (Port : PCH_DP_Port;
110 Link : DP_Link;
111 Pattern : DP_Info.Training_Pattern)
112 is
113 begin
114 Registers.Unset_And_Set_Mask
115 (Register => DP_CTL (Port),
116 Mask_Unset => DP_CTL_LINK_TRAIN_MASK,
117 Mask_Set => DP_CTL_LINK_TRAIN (Pattern));
118 end Set_Training_Pattern;
119
120 procedure Set_Signal_Levels
121 (Port : PCH_DP_Port;
122 Link : DP_Link;
123 Train_Set : DP_Info.Train_Set)
124 is
125 begin
126 Registers.Unset_And_Set_Mask
127 (Register => DP_CTL (Port),
128 Mask_Unset => DP_CTL_VSWING_LEVEL_SET_MASK or
129 DP_CTL_PREEMPH_LEVEL_SET_MASK,
130 Mask_Set => DP_CTL_VSWING_LEVEL_SET (Train_Set.Voltage_Swing) or
131 DP_CTL_PREEMPH_LEVEL_SET (Train_Set.Pre_Emph));
132 end Set_Signal_Levels;
133
134 procedure Off (Port : PCH_DP_Port)
135 is
136 begin
137 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
138
139 Registers.Unset_And_Set_Mask
140 (Register => DP_CTL (Port),
141 Mask_Unset => DP_CTL_LINK_TRAIN_MASK,
142 Mask_Set => DP_CTL_LINK_TRAIN_IDLE);
143 Registers.Posting_Read (DP_CTL (Port));
144
145 Registers.Write (DP_CTL (Port), 0);
146 Registers.Posting_Read (DP_CTL (Port));
147 end Off;
148 pragma Warnings (GNATprove, On, "unused variable ""Port""");
149 pragma Warnings (GNATprove, On, "unused variable ""Link""");
150
151 ----------------------------------------------------------------------------
152
153 procedure On
154 (Port_Cfg : in Port_Config;
155 Success : out Boolean)
156 is
157 function To_DP (Port : PCH_DP_Port) return DP_Port
158 is
159 begin
160 return
161 (case Port is
162 when PCH_DP_B => DP_B,
163 when PCH_DP_C => DP_C,
164 when PCH_DP_D => DP_D);
165 end To_DP;
166 package Training is new DP_Training
167 (TPS3_Supported => False,
168 T => PCH_DP_Port,
169 Aux_T => DP_Port,
170 Aux_Ch => DP_Aux_Ch,
171 DP_Info => DP_Info,
172 To_Aux => To_DP,
173 Max_V_Swing => Max_V_Swing,
174 Max_Pre_Emph => Max_Pre_Emph,
175 Set_Pattern => Set_Training_Pattern,
176 Set_Signal_Levels => Set_Signal_Levels,
177 Off => Off);
178 begin
179 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
180
181 Registers.Write
182 (Register => DP_CTL (Port_Cfg.PCH_Port),
183 Value => DP_CTL_DISPLAY_PORT_ENABLE or
184 DP_CTL_PORT_WIDTH (Port_Cfg.DP.Lane_Count) or
185 DP_CTL_LINK_TRAIN_PAT1);
186
187 Training.Train_DP
188 (Port => Port_Cfg.PCH_Port,
189 Link => Port_Cfg.DP,
190 Success => Success);
191 end On;
192
193 ----------------------------------------------------------------------------
194
195 procedure All_Off
196 is
197 begin
198 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
199
200 for Port in PCH_DP_Port loop
201 Off (Port);
202 end loop;
203 end All_Off;
204
205end HW.GFX.GMA.PCH.DP;