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