blob: 50c14cd7aafae9267a582b123ea83d5e463a6509 [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
90 if Config.Internal_Is_EDP then
91 -- DDI_A
Nico Huber1c3b9282017-02-09 13:57:04 +010092 if Config.Has_Presence_Straps then
93 Registers.Is_Set_Mask
94 (Register => Registers.DDI_BUF_CTL_A,
95 Mask => DDI_PORT_DETECTED (DIGI_A),
96 Result => Internal_Detected);
97 else
98 Internal_Detected := True; -- XXX: Linux' i915 contains a fixme.
99 end if;
Nico Huber83693c82016-10-08 22:17:55 +0200100 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]
Nico Huber208857d2017-07-29 21:30:24 +0200127 for Port in Ext_Digital_Port range
128 DIGI_B .. Ext_Digital_Port'Min (DIGI_D, Config.Last_Digital_Port)
129 loop
Nico Huber1c3b9282017-02-09 13:57:04 +0100130 if Config.Has_Presence_Straps then
131 Registers.Is_Set_Mask
132 (Register => Registers.SFUSE_STRAP,
133 Mask => DDI_PORT_DETECTED (Port),
134 Result => DDI_Detected);
135 else
136 DDI_Detected := True;
137 end if;
Nico Huber318bca12018-06-09 19:22:52 +0200138 Config.Valid_Port (To_HDMI_Port (Port)) := DDI_Detected;
139 Config.Valid_Port (To_DP_Port (Port)) := DDI_Detected;
Nico Huber83693c82016-10-08 22:17:55 +0200140
141 if DDI_Detected then
142 Registers.Unset_And_Set_Mask
143 (Register => Registers.SHOTPLUG_CTL,
144 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
145 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or
146 SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status
147 else
148 Registers.Unset_Mask
149 (Register => Registers.SHOTPLUG_CTL,
150 Mask => SHOTPLUG_CTL_DETECT_MASK or
151 SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port));
152 end if;
153 end loop;
154 end Initialize;
155
Nico Huber3be61d42017-01-09 13:58:18 +0100156 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
Nico Huber83693c82016-10-08 22:17:55 +0200157 is
158 Ctl32 : Word32;
Nico Huber3be61d42017-01-09 13:58:18 +0100159 GPU_Port : constant GMA.GPU_Port :=
160 Config_Helpers.To_GPU_Port (Primary, Port);
Nico Huber83693c82016-10-08 22:17:55 +0200161 begin
Nico Huber8fb0f312017-01-18 14:35:45 +0100162 if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then
Nico Huber83693c82016-10-08 22:17:55 +0200163 Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
164 Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
165
166 if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then
167 Registers.Set_Mask
168 (Register => Registers.HOTPLUG_CTL,
169 Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS);
170 end if;
Nico Huber3be61d42017-01-09 13:58:18 +0100171 elsif GPU_Port in DIGI_A .. DIGI_D then
Nico Huber83693c82016-10-08 22:17:55 +0200172 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
Nico Huber3be61d42017-01-09 13:58:18 +0100173 Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0;
Nico Huber83693c82016-10-08 22:17:55 +0200174
Nico Huber3be61d42017-01-09 13:58:18 +0100175 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then
Nico Huber83693c82016-10-08 22:17:55 +0200176 Registers.Unset_And_Set_Mask
177 (Register => Registers.SHOTPLUG_CTL,
178 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber3be61d42017-01-09 13:58:18 +0100179 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port));
Nico Huber83693c82016-10-08 22:17:55 +0200180 end if;
181 else
182 Detected := False;
183 end if;
184 end Hotplug_Detect;
185
Nico Huber4798c662017-01-11 12:44:48 +0100186 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
187 is
188 Ignored_HPD : Boolean;
189 begin
190 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
191 Reason => "We want to clear pending events only");
192 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
193 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
194 end Clear_Hotplug_Detect;
195
Nico Huber83693c82016-10-08 22:17:55 +0200196end HW.GFX.GMA.Port_Detect;