blob: 5765941160ecf9cb628b7d7395c3773220f11b05 [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 Huber907e4152017-07-29 21:18:59 +020022 DDI_BUF_CTL_A_LANE_CAPABILITY_X4 : constant := 1 * 2 ** 4;
23
Nico Huber83693c82016-10-08 22:17:55 +020024 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
Nico Huber907e4152017-07-29 21:18:59 +020060 DDI_A_X4,
Nico Huber83693c82016-10-08 22:17:55 +020061 DAC_Disabled,
62 Internal_Detected,
63 DDI_Detected : Boolean;
64
Nico Huber83693c82016-10-08 22:17:55 +020065 subtype Ext_Digital_Port is
66 Digital_Port range DIGI_B .. DIGI_D;
67 type Digital_Port_To_GMA_Port is array (Ext_Digital_Port) of Port_Type;
68 To_HDMI_Port : constant Digital_Port_To_GMA_Port :=
Nico Huber0d454cd2016-11-21 13:33:43 +010069 (DIGI_B => HDMI1,
70 DIGI_C => HDMI2,
71 DIGI_D => HDMI3);
Nico Huber83693c82016-10-08 22:17:55 +020072 To_DP_Port : constant Digital_Port_To_GMA_Port :=
73 (DIGI_B => DP1,
74 DIGI_C => DP2,
75 DIGI_D => DP3);
76 begin
Nico Huber907e4152017-07-29 21:18:59 +020077 if Config.Has_DDI_E and Config.Has_PCH_DAC then
Nico Huber83693c82016-10-08 22:17:55 +020078 -- PCH_DAC (_A)
79 Registers.Is_Set_Mask
Nico Huber907e4152017-07-29 21:18:59 +020080 (Register => Registers.DDI_BUF_CTL_A,
81 Mask => DDI_BUF_CTL_A_LANE_CAPABILITY_X4,
82 Result => DDI_A_X4);
83 Registers.Is_Set_Mask
Nico Huber83693c82016-10-08 22:17:55 +020084 (Register => Registers.SFUSE_STRAP,
85 Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE,
86 Result => DAC_Disabled);
Nico Huber907e4152017-07-29 21:18:59 +020087 Config.Valid_Port (Analog) := not (DDI_A_X4 or DAC_Disabled);
Nico Huber83693c82016-10-08 22:17:55 +020088 end if;
89
Nico Huber8beafd72020-01-07 14:59:44 +010090 -- DDI_A
Matt DeVillier2a3dbba2020-05-14 17:34:13 -050091 if Config.Has_Presence_Straps and not Config.Ignore_Presence_Straps then
Nico Huber8beafd72020-01-07 14:59:44 +010092 Registers.Is_Set_Mask
93 (Register => Registers.DDI_BUF_CTL_A,
94 Mask => DDI_PORT_DETECTED (DIGI_A),
95 Result => Internal_Detected);
96 else
97 Internal_Detected := True; -- XXX: Linux' i915 contains a fixme.
98 end if;
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.
Nico Huber83693c82016-10-08 22:17:55 +0200107 Registers.Unset_And_Set_Mask
108 (Register => Registers.SHOTPLUG_CTL,
109 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber8beafd72020-01-07 14:59:44 +0100110 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A));
Nico Huber83693c82016-10-08 22:17:55 +0200111 end if;
Nico Huber8beafd72020-01-07 14:59:44 +0100112 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
Nico Huber83693c82016-10-08 22:17:55 +0200118 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200119 end if;
Nico Huber8beafd72020-01-07 14:59:44 +0100120 Config.Valid_Port (eDP) := Internal_Detected;
Nico Huber83693c82016-10-08 22:17:55 +0200121
122 -- DDI_[BCD]
Nico Huber208857d2017-07-29 21:30:24 +0200123 for Port in Ext_Digital_Port range
124 DIGI_B .. Ext_Digital_Port'Min (DIGI_D, Config.Last_Digital_Port)
125 loop
Matt DeVillier2a3dbba2020-05-14 17:34:13 -0500126 if Config.Has_Presence_Straps and not Config.Ignore_Presence_Straps then
Nico Huber1c3b9282017-02-09 13:57:04 +0100127 Registers.Is_Set_Mask
128 (Register => Registers.SFUSE_STRAP,
129 Mask => DDI_PORT_DETECTED (Port),
130 Result => DDI_Detected);
131 else
132 DDI_Detected := True;
133 end if;
Nico Huber318bca12018-06-09 19:22:52 +0200134 Config.Valid_Port (To_HDMI_Port (Port)) := DDI_Detected;
135 Config.Valid_Port (To_DP_Port (Port)) := DDI_Detected;
Nico Huber83693c82016-10-08 22:17:55 +0200136
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
Nico Huber3be61d42017-01-09 13:58:18 +0100152 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
Nico Huber83693c82016-10-08 22:17:55 +0200153 is
154 Ctl32 : Word32;
Nico Huber3be61d42017-01-09 13:58:18 +0100155 GPU_Port : constant GMA.GPU_Port :=
156 Config_Helpers.To_GPU_Port (Primary, Port);
Nico Huber83693c82016-10-08 22:17:55 +0200157 begin
Nico Huber8fb0f312017-01-18 14:35:45 +0100158 if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then
Nico Huber83693c82016-10-08 22:17:55 +0200159 Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
160 Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
161
162 if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then
163 Registers.Set_Mask
164 (Register => Registers.HOTPLUG_CTL,
165 Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS);
166 end if;
Nico Huber3be61d42017-01-09 13:58:18 +0100167 elsif GPU_Port in DIGI_A .. DIGI_D then
Nico Huber83693c82016-10-08 22:17:55 +0200168 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
Nico Huber3be61d42017-01-09 13:58:18 +0100169 Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0;
Nico Huber83693c82016-10-08 22:17:55 +0200170
Nico Huber3be61d42017-01-09 13:58:18 +0100171 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then
Nico Huber83693c82016-10-08 22:17:55 +0200172 Registers.Unset_And_Set_Mask
173 (Register => Registers.SHOTPLUG_CTL,
174 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber3be61d42017-01-09 13:58:18 +0100175 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port));
Nico Huber83693c82016-10-08 22:17:55 +0200176 end if;
177 else
178 Detected := False;
179 end if;
180 end Hotplug_Detect;
181
Nico Huber4798c662017-01-11 12:44:48 +0100182 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
183 is
184 Ignored_HPD : Boolean;
185 begin
186 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
187 Reason => "We want to clear pending events only");
188 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
189 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
190 end Clear_Hotplug_Detect;
191
Nico Huber83693c82016-10-08 22:17:55 +0200192end HW.GFX.GMA.Port_Detect;