blob: 5990fcf9e8bc9191a7378fa0024f24078b7dada9 [file] [log] [blame]
Nico Huber7ad2d652016-12-07 15:19:32 +01001--
2-- Copyright (C) 2015-2016 secunet Security Networks AG
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
15with HW.Debug;
16with GNAT.Source_Info;
17
Nico Huber7ad2d652016-12-07 15:19:32 +010018with HW.GFX.GMA.DP_Info;
19
20package body HW.GFX.GMA.Transcoder is
21
22 type Default_Transcoder_Array is array (Pipe_Index) of Transcoder_Index;
23 Default_Transcoder : constant Default_Transcoder_Array :=
24 (Primary => Trans_A,
25 Secondary => Trans_B,
26 Tertiary => Trans_C);
27
28 function Get_Idx (Pipe : Pipe_Index; Port : GPU_Port) return Transcoder_Index
29 is
30 begin
31 return
32 (if Config.Has_EDP_Transcoder and then Port = DIGI_A then
33 Trans_EDP
34 else
35 Default_Transcoder (Pipe));
36 end Get_Idx;
37
38 ----------------------------------------------------------------------------
39
40 TRANS_CLK_SEL_PORT_NONE : constant := 0 * 2 ** 29;
41
42 type TRANS_CLK_SEL_PORT_Array is
43 array (Digital_Port) of Word32;
44 TRANS_CLK_SEL_PORT : constant TRANS_CLK_SEL_PORT_Array :=
45 (DIGI_A => 0 * 2 ** 29, -- DDI A is not selectable
46 DIGI_B => 2 * 2 ** 29,
47 DIGI_C => 3 * 2 ** 29,
48 DIGI_D => 4 * 2 ** 29,
49 DIGI_E => 5 * 2 ** 29);
50
51 TRANS_CONF_ENABLE : constant := 1 * 2 ** 31;
52 TRANS_CONF_ENABLED_STATUS : constant := 1 * 2 ** 30;
53 TRANS_CONF_ENABLE_DITHER : constant := 1 * 2 ** 4;
54
55 type BPC_Array is array (BPC_Type) of Word32;
56 TRANS_CONF_BPC : constant BPC_Array :=
57 (6 => 2 * 2 ** 5,
58 8 => 0 * 2 ** 5,
59 10 => 1 * 2 ** 5,
60 12 => 3 * 2 ** 5,
61 others => 0 * 2 ** 5); -- default to 8 BPC
62
63 function BPC_Conf (BPC : BPC_Type; Dither : Boolean) return Word32 is
64 begin
65 return
66 (if Config.Has_Pipeconf_BPC then TRANS_CONF_BPC (BPC) else 0) or
67 (if Dither then TRANS_CONF_ENABLE_DITHER else 0);
68 end BPC_Conf;
69
70 ----------------------------------------------------------------------------
71
72 DDI_FUNC_CTL_ENABLE : constant := 1 * 2 ** 31;
73 DDI_FUNC_CTL_MODE_SELECT_MASK : constant := 7 * 2 ** 24;
74 DDI_FUNC_CTL_MODE_SELECT_HDMI : constant := 0 * 2 ** 24;
75 DDI_FUNC_CTL_MODE_SELECT_DVI : constant := 1 * 2 ** 24;
76 DDI_FUNC_CTL_MODE_SELECT_DP_SST : constant := 2 * 2 ** 24;
77 DDI_FUNC_CTL_MODE_SELECT_DP_MST : constant := 3 * 2 ** 24;
78 DDI_FUNC_CTL_MODE_SELECT_FDI : constant := 4 * 2 ** 24;
79 DDI_FUNC_CTL_EDP_SELECT_MASK : constant := 7 * 2 ** 12;
80 DDI_FUNC_CTL_EDP_SELECT_ALWAYS_ON : constant := 0 * 2 ** 12;
81 DDI_FUNC_CTL_EDP_SELECT_A : constant := 4 * 2 ** 12;
82 DDI_FUNC_CTL_EDP_SELECT_B : constant := 5 * 2 ** 12;
83 DDI_FUNC_CTL_EDP_SELECT_C : constant := 6 * 2 ** 12;
84
85 type DDI_Select_Array is array (Digital_Port) of Word32;
86 DDI_FUNC_CTL_DDI_SELECT : constant DDI_Select_Array :=
87 (DIGI_A => 0 * 2 ** 28,
88 DIGI_B => 1 * 2 ** 28,
89 DIGI_C => 2 * 2 ** 28,
90 DIGI_D => 3 * 2 ** 28,
91 DIGI_E => 4 * 2 ** 28);
92
93 type DDI_Mode_Array is array (Display_Type) of Word32;
94 DDI_FUNC_CTL_MODE_SELECT : constant DDI_Mode_Array :=
95 (VGA => DDI_FUNC_CTL_MODE_SELECT_FDI,
96 HDMI => DDI_FUNC_CTL_MODE_SELECT_DVI,
97 DP => DDI_FUNC_CTL_MODE_SELECT_DP_SST,
98 others => 0);
99
100 type HV_Sync_Array is array (Boolean) of Word32;
101 DDI_FUNC_CTL_VSYNC : constant HV_Sync_Array :=
102 (False => 0 * 2 ** 17,
103 True => 1 * 2 ** 17);
104 DDI_FUNC_CTL_HSYNC : constant HV_Sync_Array :=
105 (False => 0 * 2 ** 16,
106 True => 1 * 2 ** 16);
107
108 type EDP_Select_Array is array (Pipe_Index) of Word32;
109 DDI_FUNC_CTL_EDP_SELECT : constant EDP_Select_Array :=
110 (Primary => DDI_FUNC_CTL_EDP_SELECT_ALWAYS_ON, -- we never use
111 -- panel fitter
112 Secondary => DDI_FUNC_CTL_EDP_SELECT_B,
113 Tertiary => DDI_FUNC_CTL_EDP_SELECT_C);
114 DDI_FUNC_CTL_EDP_SELECT_ONOFF : constant EDP_Select_Array :=
115 (Primary => DDI_FUNC_CTL_EDP_SELECT_A,
116 Secondary => DDI_FUNC_CTL_EDP_SELECT_B,
117 Tertiary => DDI_FUNC_CTL_EDP_SELECT_C);
118
119 type Port_Width_Array is array (DP_Lane_Count) of Word32;
120 DDI_FUNC_CTL_PORT_WIDTH : constant Port_Width_Array :=
121 (DP_Lane_Count_1 => 0 * 2 ** 1,
122 DP_Lane_Count_2 => 1 * 2 ** 1,
123 DP_Lane_Count_4 => 3 * 2 ** 1);
124
125 DDI_FUNC_CTL_BPC : constant BPC_Array :=
126 (6 => 2 * 2 ** 20,
127 8 => 0 * 2 ** 20,
128 10 => 1 * 2 ** 20,
129 12 => 3 * 2 ** 20,
130 others => 0 * 2 ** 20); -- default to 8 BPC
131
132 ----------------------------------------------------------------------------
133
134 TRANS_MSA_MISC_SYNC_CLK : constant := 1 * 2 ** 0;
135 TRANS_MSA_MISC_BPC : constant BPC_Array :=
136 (6 => 0 * 2 ** 5,
137 8 => 1 * 2 ** 5,
138 10 => 2 * 2 ** 5,
139 12 => 3 * 2 ** 5,
140 16 => 4 * 2 ** 5,
141 others => 1 * 2 ** 5); -- default to 8 BPC
142
143 function TRANS_DATA_M_TU (Transfer_Unit : Positive) return Word32 is
144 begin
145 return Shift_Left (Word32 (Transfer_Unit - 1), 25);
146 end TRANS_DATA_M_TU;
147
148 ----------------------------------------------------------------------------
149
150 function Encode (LSW, MSW : Pos16) return Word32
151 is
Nico Huber31a52172017-03-05 14:17:34 +0100152 pragma Warnings (GNAT, Off, """Integer_16"" is already use-visible *",
153 Reason => "Needed for older compiler versions");
Nico Huber7ad2d652016-12-07 15:19:32 +0100154 use type HW.Pos16;
Nico Huber31a52172017-03-05 14:17:34 +0100155 pragma Warnings (GNAT, On, """Integer_16"" is already use-visible *");
Nico Huber7ad2d652016-12-07 15:19:32 +0100156 begin
157 return Shift_Left (Word32 (MSW - 1), 16) or Word32 (LSW - 1);
158 end Encode;
159
160 ----------------------------------------------------------------------------
161
162 procedure Setup_Link
163 (Trans : Transcoder_Regs;
164 Link : DP_Link;
165 Mode : Mode_Type)
166 with
167 Global => (In_Out => Registers.Register_State),
168 Depends => (Registers.Register_State =>+ (Trans, Link, Mode))
169 is
170 Data_M, Link_M : DP_Info.M_Type;
171 Data_N, Link_N : DP_Info.N_Type;
172 begin
173 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
174
175 DP_Info.Calculate_M_N
176 (Link => Link,
177 Mode => Mode,
178 Data_M => Data_M,
179 Data_N => Data_N,
180 Link_M => Link_M,
181 Link_N => Link_N);
182
183 Registers.Write
184 (Register => Trans.DATA_M1,
185 Value => TRANS_DATA_M_TU (64) or
186 Word32 (Data_M));
187 Registers.Write
188 (Register => Trans.DATA_N1,
189 Value => Word32 (Data_N));
190
191 Registers.Write
192 (Register => Trans.LINK_M1,
193 Value => Word32 (Link_M));
194 Registers.Write
195 (Register => Trans.LINK_N1,
196 Value => Word32 (Link_N));
197
198 if Config.Has_Pipe_MSA_Misc then
199 Registers.Write
200 (Register => Trans.MSA_MISC,
201 Value => TRANS_MSA_MISC_SYNC_CLK or
202 TRANS_MSA_MISC_BPC (Mode.BPC));
203 end if;
204 end Setup_Link;
205
206 ----------------------------------------------------------------------------
207
208 procedure Setup
209 (Pipe : Pipe_Index;
210 Port_Cfg : Port_Config)
211 is
212 use type HW.GFX.GMA.Registers.Registers_Invalid_Index;
213
214 Trans : Transcoder_Regs renames
215 Transcoders (Get_Idx (Pipe, Port_Cfg.Port));
216 M : constant Mode_Type := Port_Cfg.Mode;
217 begin
218 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
219
220 if Config.Has_Trans_Clk_Sel and then
221 Trans.CLK_SEL /= Registers.Invalid_Register
222 then
223 Registers.Write
224 (Register => Trans.CLK_SEL,
225 Value => TRANS_CLK_SEL_PORT (Port_Cfg.Port));
226 end if;
227
228 if Port_Cfg.Is_FDI then
229 Setup_Link (Trans, Port_Cfg.FDI, Port_Cfg.Mode);
230 elsif Port_Cfg.Display = DP then
231 Setup_Link (Trans, Port_Cfg.DP, Port_Cfg.Mode);
232 end if;
233
234 Registers.Write (Trans.HTOTAL, Encode (M.H_Visible, M.H_Total));
235 Registers.Write (Trans.HBLANK, Encode (M.H_Visible, M.H_Total));
236 Registers.Write (Trans.HSYNC, Encode (M.H_Sync_Begin, M.H_Sync_End));
237 Registers.Write (Trans.VTOTAL, Encode (M.V_Visible, M.V_Total));
238 Registers.Write (Trans.VBLANK, Encode (M.V_Visible, M.V_Total));
239 Registers.Write (Trans.VSYNC, Encode (M.V_Sync_Begin, M.V_Sync_End));
240 end Setup;
241
242 ----------------------------------------------------------------------------
243
244 procedure On
245 (Pipe : Pipe_Index;
246 Port_Cfg : Port_Config;
247 Dither : Boolean)
248 is
249 Trans : Transcoder_Regs renames
250 Transcoders (Get_Idx (Pipe, Port_Cfg.Port));
251 begin
252 if Config.Has_Pipe_DDI_Func then
253 Registers.Write
254 (Register => Trans.DDI_FUNC_CTL,
255 Value => DDI_FUNC_CTL_ENABLE or
256 DDI_FUNC_CTL_DDI_SELECT (Port_Cfg.Port) or
257 DDI_FUNC_CTL_MODE_SELECT (Port_Cfg.Display) or
258 DDI_FUNC_CTL_BPC (Port_Cfg.Mode.BPC) or
259 DDI_FUNC_CTL_VSYNC (Port_Cfg.Mode.V_Sync_Active_High) or
260 DDI_FUNC_CTL_HSYNC (Port_Cfg.Mode.H_Sync_Active_High) or
261 DDI_FUNC_CTL_EDP_SELECT (Pipe) or
262 DDI_FUNC_CTL_PORT_WIDTH (Port_Cfg.DP.Lane_Count));
263 end if;
264
265 Registers.Write
266 (Register => Trans.CONF,
267 Value => TRANS_CONF_ENABLE or
268 (if not Config.Has_Pipeconf_Misc then
269 BPC_Conf (Port_Cfg.Mode.BPC, Dither) else 0));
270 Registers.Posting_Read (Trans.CONF);
271 end On;
272
273 ----------------------------------------------------------------------------
274
275 procedure Trans_Off (Trans : Transcoder_Regs)
276 is
277 Enabled : Boolean;
278 begin
279 Registers.Is_Set_Mask (Trans.CONF, TRANS_CONF_ENABLE, Enabled);
280
281 if Enabled then
282 Registers.Unset_Mask (Trans.CONF, TRANS_CONF_ENABLE);
283 end if;
284
285 -- Workaround for Broadwell:
286 -- Status may be wrong if pipe hasn't been enabled since reset.
287 if not Config.Pipe_Enabled_Workaround or else Enabled then
288 -- synchronously wait until pipe is truly off
289 Registers.Wait_Unset_Mask
290 (Register => Trans.CONF,
291 Mask => TRANS_CONF_ENABLED_STATUS,
292 TOut_MS => 40);
293 end if;
294
295 if Config.Has_Pipe_DDI_Func then
296 Registers.Write (Trans.DDI_FUNC_CTL, 0);
297 end if;
298 end Trans_Off;
299
300 procedure Off (Pipe : Pipe_Index)
301 is
302 DDI_Func_Ctl : Word32;
303 begin
304 if Config.Has_EDP_Transcoder then
305 Registers.Read (Registers.PIPE_EDP_DDI_FUNC_CTL, DDI_Func_Ctl);
306 DDI_Func_Ctl := DDI_Func_Ctl and DDI_FUNC_CTL_EDP_SELECT_MASK;
307
308 if (Pipe = Primary and
309 DDI_Func_Ctl = DDI_FUNC_CTL_EDP_SELECT_ALWAYS_ON) or
310 DDI_Func_Ctl = DDI_FUNC_CTL_EDP_SELECT_ONOFF (Pipe)
311 then
312 Trans_Off (Transcoders (Trans_EDP));
313 end if;
314 end if;
315
316 Trans_Off (Transcoders (Default_Transcoder (Pipe)));
317 end Off;
318
319 procedure Clk_Off (Pipe : Pipe_Index)
320 is
321 use type Registers.Registers_Invalid_Index;
322
323 Trans : Transcoder_Regs renames Transcoders (Default_Transcoder (Pipe));
324 begin
325 if Config.Has_Trans_Clk_Sel and then
326 Trans.CLK_SEL /= Registers.Invalid_Register
327 then
328 Registers.Write (Trans.CLK_SEL, TRANS_CLK_SEL_PORT_NONE);
329 end if;
330 end Clk_Off;
331
332end HW.GFX.GMA.Transcoder;