blob: f90b7bab7a5f8aebe42ace043a8c761ae32216db [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
Nico Huberf84bb892026-04-08 10:33:22 +000049 FDI_TX_CTL_FDI_TX_ENABLE : constant := 1 * 2 ** 31;
50 FDI_TX_CTL_PORT_WIDTH_SEL_4 : constant := 3 * 2 ** 19;
Nico Huber005f9ca2024-07-03 16:57:56 +020051 Enabled : Boolean;
52 begin
Nico Huberf84bb892026-04-08 10:33:22 +000053 if Config.Has_FDI_C and then Port_Cfg.Port = DIGI_D then
54 -- if DIGI_C (FDI_B) is enabled w/ 4 lanes, DIGI_D can't be used:
55 Registers.Is_Set_Mask
56 (Register => Registers.FDI_TX_CTL_B,
57 Mask => FDI_TX_CTL_FDI_TX_ENABLE or
58 FDI_TX_CTL_PORT_WIDTH_SEL_4,
59 Result => Enabled);
60 if Enabled then
61 Success := False;
62 return;
63 end if;
64 end if;
65
Nico Huber005f9ca2024-07-03 16:57:56 +020066 if Config.Has_FDI_C and then Port_Cfg.Port = DIGI_C then
67 -- if DIGI_D enabled: (FDI names are off by one)
68 Registers.Is_Set_Mask
69 (Register => Registers.FDI_TX_CTL_C,
70 Mask => FDI_TX_CTL_FDI_TX_ENABLE,
71 Result => Enabled);
72 if Enabled then
73 Port_Cfg.FDI.Receiver_Caps.Max_Lane_Count := DP_Lane_Count_2;
74 end if;
75 end if;
76
77 DP_Info.Preferred_Link_Setting (Port_Cfg.FDI, Port_Cfg.Mode, Success);
78 end Override_FDI_Link;
Nico Hubera8254482024-07-03 12:23:00 +020079 begin
Nico Huber005f9ca2024-07-03 16:57:56 +020080 if Port_Cfg.Is_FDI then
81 Override_FDI_Link;
82 else
83 Success := True;
84 end if;
Nico Hubera8254482024-07-03 12:23:00 +020085 end Prepare;
86
87 ----------------------------------------------------------------------------
88
Nico Huber83693c82016-10-08 22:17:55 +020089 function Is_Internal (Port_Cfg : Port_Config) return Boolean
90 is
91 begin
92 return
93 Port_Cfg.Port = DIGI_A or
94 (Port_Cfg.Is_FDI and Port_Cfg.PCH_Port = PCH_LVDS);
95 end Is_Internal;
96
97 ----------------------------------------------------------------------------
98
99 procedure Pre_On
Nico Huber6e327c92016-12-21 14:45:45 +0100100 (Pipe : in Pipe_Index;
101 Port_Cfg : in Port_Config;
Nico Huber83693c82016-10-08 22:17:55 +0200102 PLL_Hint : in Word32;
Nico Huber83693c82016-10-08 22:17:55 +0200103 Success : out Boolean)
104 is
105 begin
106 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
107
108 if Port_Cfg.Port = DIGI_A then
Nico Huber6e327c92016-12-21 14:45:45 +0100109 EDP.Pre_On (Pipe, Port_Cfg);
Nico Huber83693c82016-10-08 22:17:55 +0200110 elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
111 FDI.Pre_On (Port_Cfg);
112 end if;
113 Success := True;
114 end Pre_On;
115
116 procedure Post_On
Arthur Heymans60d0e5f2018-03-28 17:08:27 +0200117 (Pipe : in Pipe_Index;
118 Port_Cfg : in Port_Config;
Nico Huber83693c82016-10-08 22:17:55 +0200119 PLL_Hint : in Word32;
120 Success : out Boolean)
121 is
122 begin
123 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
124
125 if Port_Cfg.Port = DIGI_A then
126 EDP.Pre_Training;
Nico Huber2bbd6e72020-01-07 18:22:59 +0100127 Panel.On (Port_Cfg.Panel, Wait => True);
Nico Huber7892ff62016-11-21 23:26:00 +0100128 EDP.Post_On (Port_Cfg.DP, Success);
Nico Huber83693c82016-10-08 22:17:55 +0200129 elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
130 declare
131 FDI_Port : constant PCH.FDI_Port_Type :=
132 FDI.PCH_FDIs (Port_Cfg.Port);
133 begin
134 FDI.Post_On (Port_Cfg, Success);
135
136 if Success then
137 PCH.Transcoder.On (Port_Cfg, FDI_Port, PLL_Hint);
138 if Port_Cfg.PCH_Port = PCH_DAC then
139 PCH.VGA.On (FDI_Port, Port_Cfg.Mode);
140 elsif Port_Cfg.PCH_Port = PCH_LVDS then
141 PCH.LVDS.On (Port_Cfg, FDI_Port);
Tim Wawrzynczak605660b2022-06-08 12:48:19 -0600142 elsif Port_Cfg.PCH_Port in PCH.HDMI.IRL_PCH_HDMI_Port then
Nico Huber83693c82016-10-08 22:17:55 +0200143 PCH.HDMI.On (Port_Cfg, FDI_Port);
144 elsif Port_Cfg.PCH_Port in PCH_DP_Port then
Nico Huberf6a2d182019-10-01 10:37:49 +0200145 PCH.DP.On (Port_Cfg, FDI_Port, Success);
Nico Huber83693c82016-10-08 22:17:55 +0200146 end if;
147 end if;
148 end;
149 else
150 Success := False;
151 end if;
152
153 if Success and Is_Internal (Port_Cfg) then
Nico Huber2bbd6e72020-01-07 18:22:59 +0100154 Panel.On (Port_Cfg.Panel, Wait => False);
155 Panel.Backlight_On (Port_Cfg.Panel);
Nico Huber83693c82016-10-08 22:17:55 +0200156 end if;
157 end Post_On;
158
159 ----------------------------------------------------------------------------
160
Nico Huberbfea6a32024-03-07 15:22:36 +0000161 procedure Pre_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config)
Nico Huber83693c82016-10-08 22:17:55 +0200162 is
163 begin
164 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
165
166 if Is_Internal (Port_Cfg) then
Nico Huber2bbd6e72020-01-07 18:22:59 +0100167 Panel.Backlight_Off (Port_Cfg.Panel);
168 Panel.Off (Port_Cfg.Panel);
Nico Huber83693c82016-10-08 22:17:55 +0200169 end if;
170 end Pre_Off;
171
Nico Huberbfea6a32024-03-07 15:22:36 +0000172 procedure Post_Off (Pipe : Pipe_Index; Port_Cfg : Port_Config)
Nico Huber83693c82016-10-08 22:17:55 +0200173 is
174 begin
175 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
176
177 if Port_Cfg.Port = DIGI_A then
178 EDP.Off (Port_Cfg.Port);
179 elsif Port_Cfg.Port in FDI.GPU_FDI_Port then
180 declare
181 FDI_Port : constant PCH.FDI_Port_Type :=
182 FDI.PCH_FDIs (Port_Cfg.Port);
183 begin
184 if Port_Cfg.PCH_Port in PCH_DP_Port then
185 PCH.DP.Off (Port_Cfg.PCH_Port);
186 end if;
187
188 FDI.Off (Port_Cfg.Port, FDI.Link_Off);
189
190 if Port_Cfg.PCH_Port = PCH_DAC then
191 PCH.VGA.Off;
192 elsif Port_Cfg.PCH_Port = PCH_LVDS then
193 PCH.LVDS.Off;
Tim Wawrzynczak605660b2022-06-08 12:48:19 -0600194 elsif Port_Cfg.PCH_Port in PCH.HDMI.IRL_PCH_HDMI_Port then
Nico Huber83693c82016-10-08 22:17:55 +0200195 PCH.HDMI.Off (Port_Cfg.PCH_Port);
196 end if;
197 PCH.Transcoder.Off (FDI_Port);
198
199 FDI.Off (Port_Cfg.Port, FDI.Clock_Off);
200 end;
201 end if;
202 end Post_Off;
203
204 ----------------------------------------------------------------------------
205
206 procedure Pre_All_Off
207 is
208 begin
209 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
210
Nico Huber2bbd6e72020-01-07 18:22:59 +0100211 for P in Valid_Panels loop
212 Panel.Backlight_Off (P);
213 Panel.Off (P);
214 end loop;
Nico Huber83693c82016-10-08 22:17:55 +0200215 end Pre_All_Off;
216
217 procedure Post_All_Off
218 is
219 begin
220 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
221
222 EDP.Off (DIGI_A);
223
224 for Port in FDI.GPU_FDI_Port loop
225 FDI.Off (Port, FDI.Link_Off);
226 end loop;
227 PCH.VGA.Off;
228 PCH.LVDS.Off;
229 PCH.HDMI.All_Off;
230 PCH.DP.All_Off;
231 for Port in PCH.FDI_Port_Type loop
232 PCH.Transcoder.Off (Port);
233 end loop;
234 for Port in FDI.GPU_FDI_Port loop
235 FDI.Off (Port, FDI.Clock_Off);
236 end loop;
237 end Post_All_Off;
238
239end HW.GFX.GMA.Connectors;