blob: d813fe4fabe9f3270e6b0bcd605efc4c0cc43b58 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
2-- Copyright (C) 2015-2016 secunet Security Networks AG
3-- Copyright (C) 2016 Nico Huber <nico.h@gmx.de>
4--
5-- This program is free software; you can redistribute it and/or modify
6-- it under the terms of the GNU General Public License as published by
Nico Huber125a29e2016-10-18 00:23:54 +02007-- the Free Software Foundation; either version 2 of the License, or
8-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02009--
10-- This program is distributed in the hope that it will be useful,
11-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-- GNU General Public License for more details.
14--
15
16with HW.GFX.GMA.Config;
Nico Huber005f9ca2024-07-03 16:57:56 +020017with HW.GFX.GMA.DP_Info;
18with HW.GFX.GMA.Registers;
Nico Huber83693c82016-10-08 22:17:55 +020019with HW.GFX.GMA.Panel;
20with HW.GFX.GMA.Connectors.EDP;
21with HW.GFX.GMA.Connectors.FDI;
22with HW.GFX.GMA.PCH.VGA;
23with HW.GFX.GMA.PCH.LVDS;
24with HW.GFX.GMA.PCH.HDMI;
25with HW.GFX.GMA.PCH.DP;
26with HW.GFX.GMA.PCH.Transcoder;
27
28with HW.Debug;
29with GNAT.Source_Info;
30
31package body HW.GFX.GMA.Connectors
32is
33
Nico Huber3a0e2a02017-07-19 14:41:46 +020034 procedure Post_Reset_Off is null;
35 procedure Initialize is null;
Nico Huber0923b792017-06-09 15:28:41 +020036
Nico Hubera8254482024-07-03 12:23:00 +020037 ----------------------------------------------------------------------------
38
39 procedure Prepare
40 (Port : in Active_Port_Type;
41 Port_Cfg : in out Port_Config;
42 Success : out Boolean)
43 is
Nico Huber005f9ca2024-07-03 16:57:56 +020044 -- Override lane count for FDI_B if FDI_C is used
45 procedure Override_FDI_Link
46 with
47 Post => Port_Cfg.Mode = Port_Cfg'Old.Mode
48 is
49 FDI_TX_CTL_FDI_TX_ENABLE : constant := 1 * 2 ** 31;
50 Enabled : Boolean;
51 begin
52 if Config.Has_FDI_C and then Port_Cfg.Port = DIGI_C then
53 -- if DIGI_D enabled: (FDI names are off by one)
54 Registers.Is_Set_Mask
55 (Register => Registers.FDI_TX_CTL_C,
56 Mask => FDI_TX_CTL_FDI_TX_ENABLE,
57 Result => Enabled);
58 if Enabled then
59 Port_Cfg.FDI.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_2;
60 end if;
61 end if;
62
63 DP_Info.Preferred_Link_Setting (Port_Cfg.FDI, Port_Cfg.Mode, Success);
64 end Override_FDI_Link;
Nico Hubera8254482024-07-03 12:23:00 +020065 begin
Nico Huber005f9ca2024-07-03 16:57:56 +020066 if Port_Cfg.Is_FDI then
67 Override_FDI_Link;
68 else
69 Success := True;
70 end if;
Nico Hubera8254482024-07-03 12:23:00 +020071 end Prepare;
72
73 ----------------------------------------------------------------------------
74
Nico Huber83693c82016-10-08 22:17:55 +020075 function Is_Internal (Port_Cfg : Port_Config) return Boolean
76 is
77 begin
78 return
79 Port_Cfg.Port = DIGI_A or
80 (Port_Cfg.Is_FDI and Port_Cfg.PCH_Port = PCH_LVDS);
81 end Is_Internal;
82
83 ----------------------------------------------------------------------------
84
85 procedure Pre_On
Nico Huber6e327c92016-12-21 14:45:45 +010086 (Pipe : in Pipe_Index;
87 Port_Cfg : in Port_Config;
Nico Huber83693c82016-10-08 22:17:55 +020088 PLL_Hint : in Word32;
Nico Huber83693c82016-10-08 22:17:55 +020089 Success : out Boolean)
90 is
91 begin
92 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
93
94 if Port_Cfg.Port = DIGI_A then
Nico Huber6e327c92016-12-21 14:45:45 +010095 EDP.Pre_On (Pipe, Port_Cfg);
Nico Huber83693c82016-10-08 22:17:55 +020096 elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
97 FDI.Pre_On (Port_Cfg);
98 end if;
99 Success := True;
100 end Pre_On;
101
102 procedure Post_On
Arthur Heymans60d0e5f2018-03-28 17:08:27 +0200103 (Pipe : in Pipe_Index;
104 Port_Cfg : in Port_Config;
Nico Huber83693c82016-10-08 22:17:55 +0200105 PLL_Hint : in Word32;
106 Success : out Boolean)
107 is
108 begin
109 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
110
111 if Port_Cfg.Port = DIGI_A then
112 EDP.Pre_Training;
Nico Huber2bbd6e72020-01-07 18:22:59 +0100113 Panel.On (Port_Cfg.Panel, Wait => True);
Nico Huber7892ff62016-11-21 23:26:00 +0100114 EDP.Post_On (Port_Cfg.DP, Success);
Nico Huber83693c82016-10-08 22:17:55 +0200115 elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
116 declare
117 FDI_Port : constant PCH.FDI_Port_Type :=
118 FDI.PCH_FDIs (Port_Cfg.Port);
119 begin
120 FDI.Post_On (Port_Cfg, Success);
121
122 if Success then
123 PCH.Transcoder.On (Port_Cfg, FDI_Port, PLL_Hint);
124 if Port_Cfg.PCH_Port = PCH_DAC then
125 PCH.VGA.On (FDI_Port, Port_Cfg.Mode);
126 elsif Port_Cfg.PCH_Port = PCH_LVDS then
127 PCH.LVDS.On (Port_Cfg, FDI_Port);
Tim Wawrzynczak605660b2022-06-08 12:48:19 -0600128 elsif Port_Cfg.PCH_Port in PCH.HDMI.IRL_PCH_HDMI_Port then
Nico Huber83693c82016-10-08 22:17:55 +0200129 PCH.HDMI.On (Port_Cfg, FDI_Port);
130 elsif Port_Cfg.PCH_Port in PCH_DP_Port then
Nico Huberf6a2d182019-10-01 10:37:49 +0200131 PCH.DP.On (Port_Cfg, FDI_Port, Success);
Nico Huber83693c82016-10-08 22:17:55 +0200132 end if;
133 end if;
134 end;
135 else
136 Success := False;
137 end if;
138
139 if Success and Is_Internal (Port_Cfg) then
Nico Huber2bbd6e72020-01-07 18:22:59 +0100140 Panel.On (Port_Cfg.Panel, Wait => False);
141 Panel.Backlight_On (Port_Cfg.Panel);
Nico Huber83693c82016-10-08 22:17:55 +0200142 end if;
143 end Post_On;
144
145 ----------------------------------------------------------------------------
146
Nico Huberbfea6a32024-03-07 15:22:36 +0000147 procedure Pre_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config)
Nico Huber83693c82016-10-08 22:17:55 +0200148 is
149 begin
150 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
151
152 if Is_Internal (Port_Cfg) then
Nico Huber2bbd6e72020-01-07 18:22:59 +0100153 Panel.Backlight_Off (Port_Cfg.Panel);
154 Panel.Off (Port_Cfg.Panel);
Nico Huber83693c82016-10-08 22:17:55 +0200155 end if;
156 end Pre_Off;
157
Nico Huberbfea6a32024-03-07 15:22:36 +0000158 procedure Post_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config)
Nico Huber83693c82016-10-08 22:17:55 +0200159 is
160 begin
161 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
162
163 if Port_Cfg.Port = DIGI_A then
164 EDP.Off (Port_Cfg.Port);
165 elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
166 declare
167 FDI_Port : constant PCH.FDI_Port_Type :=
168 FDI.PCH_FDIs (Port_Cfg.Port);
169 begin
170 if Port_Cfg.PCH_Port in PCH_DP_Port then
171 PCH.DP.Off (Port_Cfg.PCH_Port);
172 end if;
173
174 FDI.Off (Port_Cfg.Port, FDI.Link_Off);
175
176 if Port_Cfg.PCH_Port = PCH_DAC then
177 PCH.VGA.Off;
178 elsif Port_Cfg.PCH_Port = PCH_LVDS then
179 PCH.LVDS.Off;
Tim Wawrzynczak605660b2022-06-08 12:48:19 -0600180 elsif Port_Cfg.PCH_Port in PCH.HDMI.IRL_PCH_HDMI_Port then
Nico Huber83693c82016-10-08 22:17:55 +0200181 PCH.HDMI.Off (Port_Cfg.PCH_Port);
182 end if;
183 PCH.Transcoder.Off (FDI_Port);
184
185 FDI.Off (Port_Cfg.Port, FDI.Clock_Off);
186 end;
187 end if;
188 end Post_Off;
189
190 ----------------------------------------------------------------------------
191
192 procedure Pre_All_Off
193 is
194 begin
195 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
196
Nico Huber2bbd6e72020-01-07 18:22:59 +0100197 for P in Valid_Panels loop
198 Panel.Backlight_Off (P);
199 Panel.Off (P);
200 end loop;
Nico Huber83693c82016-10-08 22:17:55 +0200201 end Pre_All_Off;
202
203 procedure Post_All_Off
204 is
205 begin
206 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
207
208 EDP.Off (DIGI_A);
209
210 for Port in FDI.GPU_FDI_Port loop
211 FDI.Off (Port, FDI.Link_Off);
212 end loop;
213 PCH.VGA.Off;
214 PCH.LVDS.Off;
215 PCH.HDMI.All_Off;
216 PCH.DP.All_Off;
217 for Port in PCH.FDI_Port_Type loop
218 PCH.Transcoder.Off (Port);
219 end loop;
220 for Port in FDI.GPU_FDI_Port loop
221 FDI.Off (Port, FDI.Clock_Off);
222 end loop;
223 end Post_All_Off;
224
225end HW.GFX.GMA.Connectors;