blob: bf9fba57c4952ad415d85f0cdafd3dbff59aaae0 [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
62 Last_Digital_Port : constant Digital_Port :=
63 (if Config.Has_DDI_D then DIGI_D else DIGI_C);
64
65 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
77 if Config.Has_PCH_DAC then
78 -- PCH_DAC (_A)
79 Registers.Is_Set_Mask
80 (Register => Registers.SFUSE_STRAP,
81 Mask => SFUSE_STRAP_CRT_DAC_CAP_DISABLE,
82 Result => DAC_Disabled);
Nico Huber83693c82016-10-08 22:17:55 +020083 Config.Valid_Port (Analog) := not DAC_Disabled;
84 end if;
85
86 if Config.Internal_Is_EDP then
87 -- DDI_A
88 Registers.Is_Set_Mask
89 (Register => Registers.DDI_BUF_CTL_A,
90 Mask => DDI_PORT_DETECTED (DIGI_A),
91 Result => Internal_Detected);
92 if Internal_Detected then
93 if Config.Has_HOTPLUG_CTL then
94 Registers.Set_Mask
95 (Register => Registers.HOTPLUG_CTL,
96 Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or
97 HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status
98 if Config.Has_SHOTPLUG_CTL_A then
99 -- Have to enable south hotplug too on SoCs.
100 Registers.Unset_And_Set_Mask
101 (Register => Registers.SHOTPLUG_CTL,
102 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
103 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A));
104 end if;
105 else
106 Registers.Unset_And_Set_Mask
107 (Register => Registers.SHOTPLUG_CTL,
108 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
109 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A) or
110 SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear
111 end if;
112 end if;
113 else
114 Internal_Detected := False;
115 end if;
116 Config.Valid_Port (Internal) := Internal_Detected;
117
118 -- DDI_[BCD]
119 for Port in Ext_Digital_Port range DIGI_B .. Last_Digital_Port loop
120 Registers.Is_Set_Mask
121 (Register => Registers.SFUSE_STRAP,
122 Mask => DDI_PORT_DETECTED (Port),
123 Result => DDI_Detected);
124 Config.Valid_Port (To_HDMI_Port (Port)) :=
125 Config.Valid_Port (To_HDMI_Port (Port)) and DDI_Detected;
126 Config.Valid_Port (To_DP_Port (Port)) :=
127 Config.Valid_Port (To_DP_Port (Port)) and DDI_Detected;
128
129 if DDI_Detected then
130 Registers.Unset_And_Set_Mask
131 (Register => Registers.SHOTPLUG_CTL,
132 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
133 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or
134 SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status
135 else
136 Registers.Unset_Mask
137 (Register => Registers.SHOTPLUG_CTL,
138 Mask => SHOTPLUG_CTL_DETECT_MASK or
139 SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port));
140 end if;
141 end loop;
142 end Initialize;
143
Nico Huber3be61d42017-01-09 13:58:18 +0100144 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
Nico Huber83693c82016-10-08 22:17:55 +0200145 is
146 Ctl32 : Word32;
Nico Huber3be61d42017-01-09 13:58:18 +0100147 GPU_Port : constant GMA.GPU_Port :=
148 Config_Helpers.To_GPU_Port (Primary, Port);
Nico Huber83693c82016-10-08 22:17:55 +0200149 begin
Nico Huber8fb0f312017-01-18 14:35:45 +0100150 if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then
Nico Huber83693c82016-10-08 22:17:55 +0200151 Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
152 Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
153
154 if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then
155 Registers.Set_Mask
156 (Register => Registers.HOTPLUG_CTL,
157 Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS);
158 end if;
Nico Huber3be61d42017-01-09 13:58:18 +0100159 elsif GPU_Port in DIGI_A .. DIGI_D then
Nico Huber83693c82016-10-08 22:17:55 +0200160 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
Nico Huber3be61d42017-01-09 13:58:18 +0100161 Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0;
Nico Huber83693c82016-10-08 22:17:55 +0200162
Nico Huber3be61d42017-01-09 13:58:18 +0100163 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then
Nico Huber83693c82016-10-08 22:17:55 +0200164 Registers.Unset_And_Set_Mask
165 (Register => Registers.SHOTPLUG_CTL,
166 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber3be61d42017-01-09 13:58:18 +0100167 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port));
Nico Huber83693c82016-10-08 22:17:55 +0200168 end if;
169 else
170 Detected := False;
171 end if;
172 end Hotplug_Detect;
173
Nico Huber4798c662017-01-11 12:44:48 +0100174 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
175 is
176 Ignored_HPD : Boolean;
177 begin
178 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
179 Reason => "We want to clear pending events only");
180 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
181 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
182 end Clear_Hotplug_Detect;
183
Nico Huber83693c82016-10-08 22:17:55 +0200184end HW.GFX.GMA.Port_Detect;