blob: b8ba37dd3304fd72091395667f04d61fcc4014f2 [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
85 Registers.Is_Set_Mask
86 (Register => Registers.DDI_BUF_CTL_A,
87 Mask => DDI_PORT_DETECTED (DIGI_A),
88 Result => Internal_Detected);
89 if Internal_Detected then
90 if Config.Has_HOTPLUG_CTL then
91 Registers.Set_Mask
92 (Register => Registers.HOTPLUG_CTL,
93 Mask => HOTPLUG_CTL_DDI_A_HPD_INPUT_ENABLE or
94 HOTPLUG_CTL_DDI_A_HPD_STATUS); -- clear status
95 if Config.Has_SHOTPLUG_CTL_A then
96 -- Have to enable south hotplug too on SoCs.
97 Registers.Unset_And_Set_Mask
98 (Register => Registers.SHOTPLUG_CTL,
99 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
100 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A));
101 end if;
102 else
103 Registers.Unset_And_Set_Mask
104 (Register => Registers.SHOTPLUG_CTL,
105 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
106 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (DIGI_A) or
107 SHOTPLUG_CTL_HPD_STATUS (DIGI_A)); -- clear
108 end if;
109 end if;
110 else
111 Internal_Detected := False;
112 end if;
113 Config.Valid_Port (Internal) := Internal_Detected;
114
115 -- DDI_[BCD]
Nico Huberac455ad2017-02-14 14:41:19 +0100116 for Port in Ext_Digital_Port range DIGI_B .. Config.Last_Digital_Port loop
Nico Huber83693c82016-10-08 22:17:55 +0200117 Registers.Is_Set_Mask
118 (Register => Registers.SFUSE_STRAP,
119 Mask => DDI_PORT_DETECTED (Port),
120 Result => DDI_Detected);
121 Config.Valid_Port (To_HDMI_Port (Port)) :=
122 Config.Valid_Port (To_HDMI_Port (Port)) and DDI_Detected;
123 Config.Valid_Port (To_DP_Port (Port)) :=
124 Config.Valid_Port (To_DP_Port (Port)) and DDI_Detected;
125
126 if DDI_Detected then
127 Registers.Unset_And_Set_Mask
128 (Register => Registers.SHOTPLUG_CTL,
129 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
130 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port) or
131 SHOTPLUG_CTL_HPD_STATUS (Port)); -- clear status
132 else
133 Registers.Unset_Mask
134 (Register => Registers.SHOTPLUG_CTL,
135 Mask => SHOTPLUG_CTL_DETECT_MASK or
136 SHOTPLUG_CTL_HPD_INPUT_ENABLE (Port));
137 end if;
138 end loop;
139 end Initialize;
140
Nico Huber3be61d42017-01-09 13:58:18 +0100141 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
Nico Huber83693c82016-10-08 22:17:55 +0200142 is
143 Ctl32 : Word32;
Nico Huber3be61d42017-01-09 13:58:18 +0100144 GPU_Port : constant GMA.GPU_Port :=
145 Config_Helpers.To_GPU_Port (Primary, Port);
Nico Huber83693c82016-10-08 22:17:55 +0200146 begin
Nico Huber8fb0f312017-01-18 14:35:45 +0100147 if Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then
Nico Huber83693c82016-10-08 22:17:55 +0200148 Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
149 Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
150
151 if (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_STATUS) /= 0 then
152 Registers.Set_Mask
153 (Register => Registers.HOTPLUG_CTL,
154 Mask => HOTPLUG_CTL_DDI_A_HPD_STATUS);
155 end if;
Nico Huber3be61d42017-01-09 13:58:18 +0100156 elsif GPU_Port in DIGI_A .. DIGI_D then
Nico Huber83693c82016-10-08 22:17:55 +0200157 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
Nico Huber3be61d42017-01-09 13:58:18 +0100158 Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0;
Nico Huber83693c82016-10-08 22:17:55 +0200159
Nico Huber3be61d42017-01-09 13:58:18 +0100160 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then
Nico Huber83693c82016-10-08 22:17:55 +0200161 Registers.Unset_And_Set_Mask
162 (Register => Registers.SHOTPLUG_CTL,
163 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
Nico Huber3be61d42017-01-09 13:58:18 +0100164 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (GPU_Port));
Nico Huber83693c82016-10-08 22:17:55 +0200165 end if;
166 else
167 Detected := False;
168 end if;
169 end Hotplug_Detect;
170
Nico Huber4798c662017-01-11 12:44:48 +0100171 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
172 is
173 Ignored_HPD : Boolean;
174 begin
175 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
176 Reason => "We want to clear pending events only");
177 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
178 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
179 end Clear_Hotplug_Detect;
180
Nico Huber83693c82016-10-08 22:17:55 +0200181end HW.GFX.GMA.Port_Detect;