blob: d8a1d075bff5c68a58084a61143cb5231e847b3e [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
Nico Huber3be61d42017-01-09 13:58:18 +01002-- Copyright (C) 2016-2017 secunet Security Networks AG
Nico Huber83693c82016-10-08 22:17:55 +02003--
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;
Nico Huber3be61d42017-01-09 13:58:18 +010017with HW.GFX.GMA.Config_Helpers;
Nico Huber83693c82016-10-08 22:17:55 +020018
19package body HW.GFX.GMA.Port_Detect
20is
21
Nico Huber83693c82016-10-08 22:17:55 +020022 SFUSE_STRAP_CRT_DAC_CAP_DISABLE : constant := 1 * 2 ** 6;
23
24 HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE : constant := 1 * 2 ** 4;
25 HOTPLUG_CTL_DDI_A_HPD_STATUS : constant := 3 * 2 ** 0;
26 HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT : constant := 1 * 2 ** 1;
27
28 SHOTPLUG_CTL_DETECT_MASK : constant := 16#0303_0303#;
29
30 type Digital_Port_Value is array (Digital_Port) of Word32;
31 DDI_PORT_DETECTED : constant Digital_Port_Value :=
32 (DIGI_B => 1 * 2 ** 2,
33 DIGI_C => 1 * 2 ** 1,
34 DIGI_D => 1 * 2 ** 0,
35 DIGI_A => 1 * 2 ** 0,
36 others => 0);
37 SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant Digital_Port_Value :=
38 (DIGI_B => 1 * 2 ** 4,
39 DIGI_C => 1 * 2 ** 12,
40 DIGI_D => 1 * 2 ** 20,
41 DIGI_A => 1 * 2 ** 28,
42 others => 0);
43 SHOTPLUG_CTL_HPD_STATUS : constant Digital_Port_Value :=
44 (DIGI_B => 3 * 2 ** 0,
45 DIGI_C => 3 * 2 ** 8,
46 DIGI_D => 3 * 2 ** 16,
47 DIGI_A => 3 * 2 ** 24,
48 others => 0);
49 SHOTPLUG_CTL_LONG_DETECT : constant Digital_Port_Value :=
50 (DIGI_B => 1 * 2 ** 1,
51 DIGI_C => 1 * 2 ** 9,
52 DIGI_D => 1 * 2 ** 17,
53 DIGI_A => 1 * 2 ** 25,
54 others => 0);
55
56 procedure Initialize
57 is
58 DAC_Disabled,
59 Internal_Detected,
60 DDI_Detected : Boolean;
61
Nico Huber83693c82016-10-08 22:17:55 +020062 subtype Ext_Digital_Port is
63 Digital_Port range DIGI_B .. DIGI_D;
64 type Digital_Port_To_GMA_Port is array (Ext_Digital_Port) of Port_Type;
65 To_HDMI_Port : constant Digital_Port_To_GMA_Port :=
Nico Huber0d454cd2016-11-21 13:33:43 +010066 (DIGI_B => HDMI1,
67 DIGI_C => HDMI2,
68 DIGI_D => HDMI3);
Nico Huber83693c82016-10-08 22:17:55 +020069 To_DP_Port : constant Digital_Port_To_GMA_Port :=
70 (DIGI_B => DP1,
71 DIGI_C => DP2,
72 DIGI_D => DP3);
73 begin
74 if Config.Has_PCH_DAC then
75 -- PCH_DAC (_A)
76 Registers.Is_Set_Mask
77 (Register => Registers.SFUSE_STRAP,
78 Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE,
79 Result => DAC_Disabled);
Nico Huber83693c82016-10-08 22:17:55 +020080 Config.Valid_Port (Analog) := not DAC_Disabled;
81 end if;
82
83 if Config.Internal_Is_EDP then
84 -- DDI_A
Nico Huber1c3b9282017-02-09 13:57:04 +010085 if Config.Has_Presence_Straps then
86 Registers.Is_Set_Mask
87 (Register => Registers.DDI_BUF_CTL_A,
88 Mask => DDI_PORT_DETECTED (DIGI_A),
89 Result => Internal_Detected);
90 else
91 Internal_Detected := True; -- XXX: Linux' i915 contains a fixme.
92 end if;
Nico Huber83693c82016-10-08 22:17:55 +020093 if Internal_Detected then
94 if Config.Has_HOTPLUG_CTL then
95 Registers.Set_Mask
96 (Register => Registers.HOTPLUG_CTL,
97 Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or
98 HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status
99 if Config.Has_SHOTPLUG_CTL_A then
100 -- Have to enable south hotplug too on SoCs.
101 Registers.Unset_And_Set_Mask
102 (Register => Registers.SHOTPLUG_CTL,
103 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
104 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A));
105 end if;
106 else
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) or
111 SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear
112 end if;
113 end if;
114 else
115 Internal_Detected := False;
116 end if;
117 Config.Valid_Port (Internal) := Internal_Detected;
118
119 -- DDI_[BCD]
Nico Huberac455ad2017-02-14 14:41:19 +0100120 for Port in Ext_Digital_Port range DIGI_B .. Config.Last_Digital_Port loop
Nico Huber1c3b9282017-02-09 13:57:04 +0100121 if Config.Has_Presence_Straps then
122 Registers.Is_Set_Mask
123 (Register => Registers.SFUSE_STRAP,
124 Mask => DDI_PORT_DETECTED (Port),
125 Result => DDI_Detected);
126 else
127 DDI_Detected := True;
128 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200129 Config.Valid_Port (To_HDMI_Port (Port)) :=
130 Config.Valid_Port (To_HDMI_Port (Port)) and DDI_Detected;
131 Config.Valid_Port (To_DP_Port (Port)) :=
132 Config.Valid_Port (To_DP_Port (Port)) and DDI_Detected;
133
134 if DDI_Detected then
135 Registers.Unset_And_Set_Mask
136 (Register => Registers.SHOTPLUG_CTL,
137 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
138 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or
139 SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status
140 else
141 Registers.Unset_Mask
142 (Register => Registers.SHOTPLUG_CTL,
143 Mask => SHOTPLUG_CTL_DETECT_MASK or
144 SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port));
145 end if;
146 end loop;
147 end Initialize;
148
Nico Huber3be61d42017-01-09 13:58:18 +0100149 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
Nico Huber83693c82016-10-08 22:17:55 +0200150 is
151 Ctl32 : Word32;
Nico Huber3be61d42017-01-09 13:58:18 +0100152 GPU_Port : constant GMA.GPU_Port :=
153 Config_Helpers.To_GPU_Port (Primary, Port);
Nico Huber83693c82016-10-08 22:17:55 +0200154 begin
Nico Huber8fb0f312017-01-18 14:35:45 +0100155 if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then
Nico Huber83693c82016-10-08 22:17:55 +0200156 Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
157 Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
158
159 if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then
160 Registers.Set_Mask
161 (Register => Registers.HOTPLUG_CTL,
162 Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS);
163 end if;
Nico Huber3be61d42017-01-09 13:58:18 +0100164 elsif GPU_Port in DIGI_A .. DIGI_D then
Nico Huber83693c82016-10-08 22:17:55 +0200165 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
Nico Huber3be61d42017-01-09 13:58:18 +0100166 Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0;
Nico Huber83693c82016-10-08 22:17:55 +0200167
Nico Huber3be61d42017-01-09 13:58:18 +0100168 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then
Nico Huber83693c82016-10-08 22:17:55 +0200169 Registers.Unset_And_Set_Mask
170 (Register => Registers.SHOTPLUG_CTL,
171 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber3be61d42017-01-09 13:58:18 +0100172 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port));
Nico Huber83693c82016-10-08 22:17:55 +0200173 end if;
174 else
175 Detected := False;
176 end if;
177 end Hotplug_Detect;
178
Nico Huber4798c662017-01-11 12:44:48 +0100179 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
180 is
181 Ignored_HPD : Boolean;
182 begin
183 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
184 Reason => "We want to clear pending events only");
185 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
186 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
187 end Clear_Hotplug_Detect;
188
Nico Huber83693c82016-10-08 22:17:55 +0200189end HW.GFX.GMA.Port_Detect;