blob: 3f8382089fabbb08630062739214084422ee8d7b [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
Nico Huberd920d252023-02-09 13:23:27 +000030 SHOTPLUG_CTL_HPD_INVERT_MASK : constant := 16#0808_0808#;
Nico Huber83693c82016-10-08 22:17:55 +020031 SHOTPLUG_CTL_DETECT_MASK : constant := 16#0303_0303#;
32
33 type Digital_Port_Value is array (Digital_Port) of Word32;
34 DDI_PORT_DETECTED : constant Digital_Port_Value :=
35 (DIGI_B => 1 * 2 ** 2,
36 DIGI_C => 1 * 2 ** 1,
37 DIGI_D => 1 * 2 ** 0,
38 DIGI_A => 1 * 2 ** 0,
39 others => 0);
40 SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant Digital_Port_Value :=
41 (DIGI_B => 1 * 2 ** 4,
42 DIGI_C => 1 * 2 ** 12,
43 DIGI_D => 1 * 2 ** 20,
44 DIGI_A => 1 * 2 ** 28,
45 others => 0);
Nico Huberd920d252023-02-09 13:23:27 +000046 SHOTPLUG_CTL_HPD_INVERT : constant Digital_Port_Value :=
47 (DIGI_B => 1 * 2 ** 3,
48 DIGI_C => 1 * 2 ** 11,
49 DIGI_D => 1 * 2 ** 19,
50 DIGI_A => 1 * 2 ** 27,
51 others => 0);
Nico Huber83693c82016-10-08 22:17:55 +020052 SHOTPLUG_CTL_HPD_STATUS : constant Digital_Port_Value :=
53 (DIGI_B => 3 * 2 ** 0,
54 DIGI_C => 3 * 2 ** 8,
55 DIGI_D => 3 * 2 ** 16,
56 DIGI_A => 3 * 2 ** 24,
57 others => 0);
58 SHOTPLUG_CTL_LONG_DETECT : constant Digital_Port_Value :=
59 (DIGI_B => 1 * 2 ** 1,
60 DIGI_C => 1 * 2 ** 9,
61 DIGI_D => 1 * 2 ** 17,
62 DIGI_A => 1 * 2 ** 25,
63 others => 0);
64
65 procedure Initialize
66 is
Nico Huber907e4152017-07-29 21:18:59 +020067 DDI_A_X4,
Nico Huber83693c82016-10-08 22:17:55 +020068 DAC_Disabled,
69 Internal_Detected,
70 DDI_Detected : Boolean;
71
Nico Huber83693c82016-10-08 22:17:55 +020072 subtype Ext_Digital_Port is
73 Digital_Port range DIGI_B .. DIGI_D;
74 type Digital_Port_To_GMA_Port is array (Ext_Digital_Port) of Port_Type;
75 To_HDMI_Port : constant Digital_Port_To_GMA_Port :=
Nico Huber0d454cd2016-11-21 13:33:43 +010076 (DIGI_B => HDMI1,
77 DIGI_C => HDMI2,
78 DIGI_D => HDMI3);
Nico Huber83693c82016-10-08 22:17:55 +020079 To_DP_Port : constant Digital_Port_To_GMA_Port :=
80 (DIGI_B => DP1,
81 DIGI_C => DP2,
82 DIGI_D => DP3);
Nico Huberd920d252023-02-09 13:23:27 +000083
84 Invert_Mask : constant Word32 :=
85 (if Config.Has_Hotplug_Invert then SHOTPLUG_CTL_HPD_INVERT_MASK else 0);
Nico Huber83693c82016-10-08 22:17:55 +020086 begin
Nico Huber907e4152017-07-29 21:18:59 +020087 if Config.Has_DDI_E and Config.Has_PCH_DAC then
Nico Huber83693c82016-10-08 22:17:55 +020088 -- PCH_DAC (_A)
89 Registers.Is_Set_Mask
Nico Huber907e4152017-07-29 21:18:59 +020090 (Register => Registers.DDI_BUF_CTL_A,
91 Mask => DDI_BUF_CTL_A_LANE_CAPABILITY_X4,
92 Result => DDI_A_X4);
93 Registers.Is_Set_Mask
Nico Huber83693c82016-10-08 22:17:55 +020094 (Register => Registers.SFUSE_STRAP,
95 Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE,
96 Result => DAC_Disabled);
Nico Huber907e4152017-07-29 21:18:59 +020097 Config.Valid_Port (Analog) := not (DDI_A_X4 or DAC_Disabled);
Nico Huber83693c82016-10-08 22:17:55 +020098 end if;
99
Nico Huber8beafd72020-01-07 14:59:44 +0100100 -- DDI_A
Matt DeVillier2a3dbba2020-05-14 17:34:13 -0500101 if Config.Has_Presence_Straps and not Config.Ignore_Presence_Straps then
Nico Huber8beafd72020-01-07 14:59:44 +0100102 Registers.Is_Set_Mask
103 (Register => Registers.DDI_BUF_CTL_A,
104 Mask => DDI_PORT_DETECTED (DIGI_A),
105 Result => Internal_Detected);
106 else
107 Internal_Detected := True; -- XXX: Linux' i915 contains a fixme.
108 end if;
109 if Internal_Detected then
110 if Config.Has_HOTPLUG_CTL then
111 Registers.Set_Mask
112 (Register => Registers.HOTPLUG_CTL,
113 Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or
114 HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status
115 if Config.Has_SHOTPLUG_CTL_A then
116 -- Have to enable south hotplug too on SoCs.
Nico Huber83693c82016-10-08 22:17:55 +0200117 Registers.Unset_And_Set_Mask
118 (Register => Registers.SHOTPLUG_CTL,
119 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber8beafd72020-01-07 14:59:44 +0100120 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A));
Nico Huber83693c82016-10-08 22:17:55 +0200121 end if;
Nico Huber8beafd72020-01-07 14:59:44 +0100122 else
123 Registers.Unset_And_Set_Mask
124 (Register => Registers.SHOTPLUG_CTL,
125 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
126 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A) or
Nico Huberd920d252023-02-09 13:23:27 +0000127 (SHOTPLUG_CTL_HPD_INVERT (DIGI_A) and Invert_Mask) or
Nico Huber8beafd72020-01-07 14:59:44 +0100128 SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear
Nico Huber83693c82016-10-08 22:17:55 +0200129 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200130 end if;
Nico Huber8beafd72020-01-07 14:59:44 +0100131 Config.Valid_Port (eDP) := Internal_Detected;
Nico Huber83693c82016-10-08 22:17:55 +0200132
133 -- DDI_[BCD]
Nico Huber208857d2017-07-29 21:30:24 +0200134 for Port in Ext_Digital_Port range
135 DIGI_B .. Ext_Digital_Port'Min (DIGI_D, Config.Last_Digital_Port)
136 loop
Matt DeVillier2a3dbba2020-05-14 17:34:13 -0500137 if Config.Has_Presence_Straps and not Config.Ignore_Presence_Straps then
Nico Huber1c3b9282017-02-09 13:57:04 +0100138 Registers.Is_Set_Mask
139 (Register => Registers.SFUSE_STRAP,
140 Mask => DDI_PORT_DETECTED (Port),
141 Result => DDI_Detected);
142 else
143 DDI_Detected := True;
144 end if;
Nico Huber318bca12018-06-09 19:22:52 +0200145 Config.Valid_Port (To_HDMI_Port (Port)) := DDI_Detected;
146 Config.Valid_Port (To_DP_Port (Port)) := DDI_Detected;
Nico Huber83693c82016-10-08 22:17:55 +0200147
148 if DDI_Detected then
149 Registers.Unset_And_Set_Mask
150 (Register => Registers.SHOTPLUG_CTL,
151 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
152 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or
Nico Huberd920d252023-02-09 13:23:27 +0000153 (SHOTPLUG_CTL_HPD_INVERT (Port) and Invert_Mask) or
Nico Huber83693c82016-10-08 22:17:55 +0200154 SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status
155 else
156 Registers.Unset_Mask
157 (Register => Registers.SHOTPLUG_CTL,
158 Mask => SHOTPLUG_CTL_DETECT_MASK or
159 SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port));
160 end if;
161 end loop;
162 end Initialize;
163
Nico Huber3be61d42017-01-09 13:58:18 +0100164 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
Nico Huber83693c82016-10-08 22:17:55 +0200165 is
166 Ctl32 : Word32;
Nico Huber3be61d42017-01-09 13:58:18 +0100167 GPU_Port : constant GMA.GPU_Port :=
168 Config_Helpers.To_GPU_Port (Primary, Port);
Nico Huber83693c82016-10-08 22:17:55 +0200169 begin
Nico Huber8fb0f312017-01-18 14:35:45 +0100170 if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then
Nico Huber83693c82016-10-08 22:17:55 +0200171 Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
172 Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
173
174 if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then
175 Registers.Set_Mask
176 (Register => Registers.HOTPLUG_CTL,
177 Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS);
178 end if;
Nico Huber3be61d42017-01-09 13:58:18 +0100179 elsif GPU_Port in DIGI_A .. DIGI_D then
Nico Huber83693c82016-10-08 22:17:55 +0200180 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
Nico Huber3be61d42017-01-09 13:58:18 +0100181 Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0;
Nico Huber83693c82016-10-08 22:17:55 +0200182
Nico Huber3be61d42017-01-09 13:58:18 +0100183 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then
Nico Huber83693c82016-10-08 22:17:55 +0200184 Registers.Unset_And_Set_Mask
185 (Register => Registers.SHOTPLUG_CTL,
186 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber3be61d42017-01-09 13:58:18 +0100187 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port));
Nico Huber83693c82016-10-08 22:17:55 +0200188 end if;
189 else
190 Detected := False;
191 end if;
192 end Hotplug_Detect;
193
Nico Huber4798c662017-01-11 12:44:48 +0100194 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
195 is
196 Ignored_HPD : Boolean;
197 begin
198 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
199 Reason => "We want to clear pending events only");
200 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
201 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
202 end Clear_Hotplug_Detect;
203
Nico Huber83693c82016-10-08 22:17:55 +0200204end HW.GFX.GMA.Port_Detect;