blob: 9987aca7b9f090eaa96198b1d329b74d090bb323 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
2-- Copyright (C) 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
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.GMA.Config;
16with HW.GFX.GMA.Registers;
17
18package body HW.GFX.GMA.Port_Detect
19is
20
21 PCH_ADPA_CRT_HPD_CHANNEL_MASK : constant := 3 * 2 ** 24;
22 PCH_ADPA_CRT_HPD_ENABLE : constant := 1 * 2 ** 23;
23
24 SFUSE_STRAP_CRT_DAC_CAP_DISABLE : constant := 1 * 2 ** 6;
25
26 HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE : constant := 1 * 2 ** 4;
27 HOTPLUG_CTL_DDI_A_HPD_STATUS : constant := 3 * 2 ** 0;
28 HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT : constant := 1 * 2 ** 1;
29
30 SHOTPLUG_CTL_DETECT_MASK : constant := 16#0303_0303#;
31
32 type Digital_Port_Value is array (Digital_Port) of Word32;
33 DDI_PORT_DETECTED : constant Digital_Port_Value :=
34 (DIGI_B => 1 * 2 ** 2,
35 DIGI_C => 1 * 2 ** 1,
36 DIGI_D => 1 * 2 ** 0,
37 DIGI_A => 1 * 2 ** 0,
38 others => 0);
39 SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant Digital_Port_Value :=
40 (DIGI_B => 1 * 2 ** 4,
41 DIGI_C => 1 * 2 ** 12,
42 DIGI_D => 1 * 2 ** 20,
43 DIGI_A => 1 * 2 ** 28,
44 others => 0);
45 SHOTPLUG_CTL_HPD_STATUS : constant Digital_Port_Value :=
46 (DIGI_B => 3 * 2 ** 0,
47 DIGI_C => 3 * 2 ** 8,
48 DIGI_D => 3 * 2 ** 16,
49 DIGI_A => 3 * 2 ** 24,
50 others => 0);
51 SHOTPLUG_CTL_LONG_DETECT : constant Digital_Port_Value :=
52 (DIGI_B => 1 * 2 ** 1,
53 DIGI_C => 1 * 2 ** 9,
54 DIGI_D => 1 * 2 ** 17,
55 DIGI_A => 1 * 2 ** 25,
56 others => 0);
57
58 procedure Initialize
59 is
60 DAC_Disabled,
61 Internal_Detected,
62 DDI_Detected : Boolean;
63
64 Last_Digital_Port : constant Digital_Port :=
65 (if Config.Has_DDI_D then DIGI_D else DIGI_C);
66
67 subtype Ext_Digital_Port is
68 Digital_Port range DIGI_B .. DIGI_D;
69 type Digital_Port_To_GMA_Port is array (Ext_Digital_Port) of Port_Type;
70 To_HDMI_Port : constant Digital_Port_To_GMA_Port :=
Nico Huber0d454cd2016-11-21 13:33:43 +010071 (DIGI_B => HDMI1,
72 DIGI_C => HDMI2,
73 DIGI_D => HDMI3);
Nico Huber83693c82016-10-08 22:17:55 +020074 To_DP_Port : constant Digital_Port_To_GMA_Port :=
75 (DIGI_B => DP1,
76 DIGI_C => DP2,
77 DIGI_D => DP3);
78 begin
79 if Config.Has_PCH_DAC then
80 -- PCH_DAC (_A)
81 Registers.Is_Set_Mask
82 (Register => Registers.SFUSE_STRAP,
83 Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE,
84 Result => DAC_Disabled);
85 if not DAC_Disabled then
86 Registers.Set_Mask
87 (Register => Registers.PCH_ADPA,
88 Mask => PCH_ADPA_CRT_HPD_CHANNEL_MASK or -- clear status
89 PCH_ADPA_CRT_HPD_ENABLE);
90 end if;
91 Config.Valid_Port (Analog) := not DAC_Disabled;
92 end if;
93
94 if Config.Internal_Is_EDP then
95 -- DDI_A
96 Registers.Is_Set_Mask
97 (Register => Registers.DDI_BUF_CTL_A,
98 Mask => DDI_PORT_DETECTED (DIGI_A),
99 Result => Internal_Detected);
100 if Internal_Detected then
101 if Config.Has_HOTPLUG_CTL then
102 Registers.Set_Mask
103 (Register => Registers.HOTPLUG_CTL,
104 Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or
105 HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status
106 if Config.Has_SHOTPLUG_CTL_A then
107 -- Have to enable south hotplug too on SoCs.
108 Registers.Unset_And_Set_Mask
109 (Register => Registers.SHOTPLUG_CTL,
110 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
111 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A));
112 end if;
113 else
114 Registers.Unset_And_Set_Mask
115 (Register => Registers.SHOTPLUG_CTL,
116 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
117 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A) or
118 SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear
119 end if;
120 end if;
121 else
122 Internal_Detected := False;
123 end if;
124 Config.Valid_Port (Internal) := Internal_Detected;
125
126 -- DDI_[BCD]
127 for Port in Ext_Digital_Port range DIGI_B .. Last_Digital_Port loop
128 Registers.Is_Set_Mask
129 (Register => Registers.SFUSE_STRAP,
130 Mask => DDI_PORT_DETECTED (Port),
131 Result => DDI_Detected);
132 Config.Valid_Port (To_HDMI_Port (Port)) :=
133 Config.Valid_Port (To_HDMI_Port (Port)) and DDI_Detected;
134 Config.Valid_Port (To_DP_Port (Port)) :=
135 Config.Valid_Port (To_DP_Port (Port)) and DDI_Detected;
136
137 if DDI_Detected then
138 Registers.Unset_And_Set_Mask
139 (Register => Registers.SHOTPLUG_CTL,
140 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
141 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or
142 SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status
143 else
144 Registers.Unset_Mask
145 (Register => Registers.SHOTPLUG_CTL,
146 Mask => SHOTPLUG_CTL_DETECT_MASK or
147 SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port));
148 end if;
149 end loop;
150 end Initialize;
151
152 procedure Hotplug_Detect (Port_Cfg : in Port_Config; Detected : out Boolean)
153 is
154 Ctl32 : Word32;
155 begin
156 if Port_Cfg.Display = VGA then
157 Registers.Read (Registers.PCH_ADPA, Ctl32, Verbose => False);
158 Ctl32 := Ctl32 and PCH_ADPA_CRT_HPD_CHANNEL_MASK;
159 Detected := Ctl32 = PCH_ADPA_CRT_HPD_CHANNEL_MASK;
160 if Ctl32 /= 0 then
161 Registers.Set_Mask
162 (Register => Registers.PCH_ADPA,
163 Mask => PCH_ADPA_CRT_HPD_CHANNEL_MASK);
164 end if;
165 elsif Config.Has_HOTPLUG_CTL and then Port_Cfg.Port = DIGI_A then
166 Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
167 Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
168
169 if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then
170 Registers.Set_Mask
171 (Register => Registers.HOTPLUG_CTL,
172 Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS);
173 end if;
174 elsif Port_Cfg.Port in DIGI_A .. DIGI_D then
175 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
176 Detected :=
177 (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (Port_Cfg.Port)) /= 0;
178
179 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (Port_Cfg.Port)) /= 0 then
180 Registers.Unset_And_Set_Mask
181 (Register => Registers.SHOTPLUG_CTL,
182 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
183 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (Port_Cfg.Port));
184 end if;
185 else
186 Detected := False;
187 end if;
188 end Hotplug_Detect;
189
190end HW.GFX.GMA.Port_Detect;