blob: 1432568289be87b8bcc015ad29653f1e54913d7f [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
2-- Copyright (C) 2016 secunet Security Networks AG
3--
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;
17
18package body HW.GFX.GMA.Port_Detect
19is
20
21 PCH_ADPA_CRT_HPD_CHANNEL_MASK : constant := 3 * 2 ** 24;
22 PCH_ADPA_CRT_HPD_ENABLE : constant := 1 * 2 ** 23;
23
24 DP_PORT_DETECTED : constant := 1 * 2 ** 2;
25 PCH_DIGI_PORT_DETECTED : constant := 1 * 2 ** 2;
26 PCH_LVDS_PORT_DETECTED : constant := 1 * 2 ** 1;
27
28 SHOTPLUG_CTL_DETECT_MASK : constant := 16#0003_0303#;
29
30 type PCH_Digital_Port_Value is array (PCH_HDMI_Port) of Word32;
31 SHOTPLUG_CTL_HPD_INPUT_ENABLE : constant PCH_Digital_Port_Value :=
32 (PCH_HDMI_B => 1 * 2 ** 4,
33 PCH_HDMI_C => 1 * 2 ** 12,
34 PCH_HDMI_D => 1 * 2 ** 20);
35 SHOTPLUG_CTL_SHORT_PULSE_MASK : constant PCH_Digital_Port_Value :=
36 (PCH_HDMI_B => 3 * 2 ** 2,
37 PCH_HDMI_C => 3 * 2 ** 10,
38 PCH_HDMI_D => 3 * 2 ** 18);
39 SHOTPLUG_CTL_HPD_STATUS : constant PCH_Digital_Port_Value :=
40 (PCH_HDMI_B => 3 * 2 ** 0,
41 PCH_HDMI_C => 3 * 2 ** 8,
42 PCH_HDMI_D => 3 * 2 ** 16);
43 SHOTPLUG_CTL_LONG_DETECT : constant PCH_Digital_Port_Value :=
44 (PCH_HDMI_B => 1 * 2 ** 1,
45 PCH_HDMI_C => 1 * 2 ** 9,
46 PCH_HDMI_D => 1 * 2 ** 17);
47
48 type PCH_Digital_Regs is array (PCH_HDMI_Port) of Registers.Registers_Index;
49 PCH_HDMI : constant PCH_Digital_Regs :=
50 (PCH_HDMI_B => Registers.PCH_HDMIB,
51 PCH_HDMI_C => Registers.PCH_HDMIC,
52 PCH_HDMI_D => Registers.PCH_HDMID);
53 PCH_DP : constant PCH_Digital_Regs :=
54 (PCH_HDMI_B => Registers.PCH_DP_B,
55 PCH_HDMI_C => Registers.PCH_DP_C,
56 PCH_HDMI_D => Registers.PCH_DP_D);
57
58 procedure Initialize
59 is
60 Internal_Detected,
61 HDMI_Detected,
62 DP_Detected : Boolean;
63
64 type PCH_Port_To_GMA_Port is array (PCH_HDMI_Port) of Port_Type;
65 To_Digital_Port : constant PCH_Port_To_GMA_Port :=
66 (PCH_HDMI_B => Digital1,
67 PCH_HDMI_C => Digital2,
68 PCH_HDMI_D => Digital3);
69 To_DP_Port : constant PCH_Port_To_GMA_Port :=
70 (PCH_HDMI_B => DP1,
71 PCH_HDMI_C => DP2,
72 PCH_HDMI_D => DP3);
73 begin
74 -- PCH_DAC (_A)
75 Registers.Set_Mask
76 (Register => Registers.PCH_ADPA,
77 Mask => PCH_ADPA_CRT_HPD_CHANNEL_MASK or -- clear status
78 PCH_ADPA_CRT_HPD_ENABLE);
79
80 case Config.Internal_Display is
81 when LVDS =>
82 -- PCH_LVDS
83 Registers.Is_Set_Mask
84 (Register => Registers.PCH_LVDS,
85 Mask => PCH_LVDS_PORT_DETECTED,
86 Result => Internal_Detected);
87 when DP =>
88 -- eDP
89 Registers.Is_Set_Mask
90 (Register => Registers.DP_CTL_A,
91 Mask => DP_PORT_DETECTED,
92 Result => Internal_Detected);
93 when None =>
94 Internal_Detected := False;
95 end case;
96 Config.Valid_Port (Internal) := Internal_Detected;
97
98 -- PCH_HDMI_[BCD], PCH_DP_[BCD] share hotplug registers
99 for PCH_Port in PCH_HDMI_Port loop
100 Registers.Is_Set_Mask
101 (Register => PCH_HDMI (PCH_Port),
102 Mask => PCH_DIGI_PORT_DETECTED,
103 Result => HDMI_Detected);
104 Config.Valid_Port (To_Digital_Port (PCH_Port)) := HDMI_Detected;
105
106 Registers.Is_Set_Mask
107 (Register => PCH_DP (PCH_Port),
108 Mask => PCH_DIGI_PORT_DETECTED,
109 Result => DP_Detected);
110 Config.Valid_Port (To_DP_Port (PCH_Port)) := DP_Detected;
111
112 if HDMI_Detected or DP_Detected then
113 Registers.Unset_And_Set_Mask
114 (Register => Registers.SHOTPLUG_CTL,
115 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK or
116 SHOTPLUG_CTL_SHORT_PULSE_MASK (PCH_Port),
117 Mask_Set => SHOTPLUG_CTL_HPD_INPUT_ENABLE (PCH_Port) or
118 SHOTPLUG_CTL_HPD_STATUS (PCH_Port)); -- clear
119 else
120 Registers.Unset_Mask
121 (Register => Registers.SHOTPLUG_CTL,
122 Mask => SHOTPLUG_CTL_DETECT_MASK or
123 SHOTPLUG_CTL_HPD_INPUT_ENABLE (PCH_Port));
124 end if;
125 end loop;
126 end Initialize;
127
128 procedure Hotplug_Detect (Port_Cfg : in Port_Config; Detected : out Boolean)
129 is
130 Ctl32 : Word32;
131 PCH_Port : constant GMA.PCH_Port :=
132 (case Port_Cfg.PCH_Port is
133 when PCH_DP_B => PCH_HDMI_B,
134 when PCH_DP_C => PCH_HDMI_C,
135 when PCH_DP_D => PCH_HDMI_D,
136 when others => Port_Cfg.PCH_Port);
137 begin
138 case PCH_Port is
139 when PCH_DAC =>
140 Registers.Read (Registers.PCH_ADPA, Ctl32, Verbose => False);
141 Ctl32 := Ctl32 and PCH_ADPA_CRT_HPD_CHANNEL_MASK;
142 Detected := Ctl32 = PCH_ADPA_CRT_HPD_CHANNEL_MASK;
143 if Ctl32 /= 0 then
144 Registers.Set_Mask (Registers.PCH_ADPA, Ctl32);
145 end if;
146 when PCH_HDMI_B .. PCH_HDMI_D =>
147 Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
148 Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (PCH_Port)) /= 0;
149
150 if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (PCH_Port)) /= 0 then
151 Registers.Unset_And_Set_Mask
152 (Register => Registers.SHOTPLUG_CTL,
153 Mask_Unset => SHOTPLUG_CTL_DETECT_MASK,
154 Mask_Set => SHOTPLUG_CTL_HPD_STATUS (PCH_Port));
155 end if;
156 when others =>
157 Detected := False;
158 end case;
159 end Hotplug_Detect;
160
161end HW.GFX.GMA.Port_Detect;