blob: c8650796959fea362bb15a50fb0fa99b8ac27096 [file] [log] [blame]
Arthur Heymans73ea0322018-03-28 17:17:07 +02001--
2-- Copyright (C) 2016-2017 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
6-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
8--
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;
17with HW.GFX.GMA.Config_Helpers;
18
19package body HW.GFX.GMA.Port_Detect
20is
21
22 PORT_DETECTED : constant := 1 * 2 ** 2;
23
24 PORTB_HOTPLUG_INT_EN : constant := 1 * 2 ** 29;
25 PORTC_HOTPLUG_INT_EN : constant := 1 * 2 ** 28;
26 PORTD_HOTPLUG_INT_EN : constant := 1 * 2 ** 27;
27 SDVOB_HOTPLUG_INT_EN : constant := 1 * 2 ** 26;
28 SDVOC_HOTPLUG_INT_EN : constant := 1 * 2 ** 25;
29 CRT_HOTPLUG_INT_EN : constant := 1 * 2 ** 9;
30 CRT_HOTPLUG_ACTIVATION_PERIOD_64 : constant := 1 * 2 ** 8;
31
32 type HDMI_Port_Value is array (GMCH_HDMI_Port) of Word32;
33 type DP_Port_Value is array (GMCH_DP_Port) of Word32;
34 HDMI_PORT_HOTPLUG_EN : constant HDMI_Port_Value :=
35 (DIGI_B => SDVOB_HOTPLUG_INT_EN,
36 DIGI_C => SDVOC_HOTPLUG_INT_EN);
37 DP_PORT_HOTPLUG_EN : constant DP_Port_Value :=
38 (DIGI_B => PORTB_HOTPLUG_INT_EN,
39 DIGI_C => PORTC_HOTPLUG_INT_EN,
40 DIGI_D => PORTD_HOTPLUG_INT_EN);
41
42 type HDMI_Regs is array (GMCH_HDMI_Port) of Registers.Registers_Index;
43 type DP_Regs is array (GMCH_DP_Port) of Registers.Registers_Index;
44 GMCH_HDMI : constant HDMI_Regs :=
45 (DIGI_B => Registers.GMCH_HDMIB,
46 DIGI_C => Registers.GMCH_HDMIC);
47 GMCH_DP : constant DP_Regs :=
48 (DIGI_B => Registers.GMCH_DP_B,
49 DIGI_C => Registers.GMCH_DP_C,
50 DIGI_D => Registers.GMCH_DP_D);
51
52 HOTPLUG_INT_STATUS : constant array (Active_Port_Type) of word32 :=
53 (DP1 => 3 * 2 ** 17,
54 DP2 => 3 * 2 ** 19,
55 DP3 => 3 * 2 ** 21,
56 HDMI1 => 1 * 2 ** 2,
57 HDMI2 => 1 * 2 ** 3,
58 Analog => 1 * 2 ** 11,
59 others => 0);
60
61 procedure Initialize
62 is
63 Detected : Boolean;
64 hotplug_mask_set : Word32 :=
65 CRT_HOTPLUG_INT_EN or CRT_HOTPLUG_ACTIVATION_PERIOD_64;
66
67 To_HDMI_Port : constant array (GMCH_HDMI_Port) of Port_Type :=
68 (DIGI_B => HDMI1,
69 DIGI_C => HDMI2);
70 To_DP_Port : constant array (GMCH_DP_Port) of Port_Type :=
71 (DIGI_B => DP1,
72 DIGI_C => DP2,
73 DIGI_D => DP3);
74
75 begin
76 for HDMI_Port in GMCH_HDMI_Port loop
77 Registers.Is_Set_Mask
78 (Register => GMCH_HDMI (HDMI_Port),
79 Mask => PORT_DETECTED,
80 Result => Detected);
81 Config.Valid_Port (To_HDMI_Port (HDMI_Port)) := Detected;
82 hotplug_mask_set := hotplug_mask_set or
83 (if Detected then HDMI_PORT_HOTPLUG_EN (HDMI_Port) else 0);
84 end loop;
85 for DP_Port in GMCH_DP_Port loop
86 Registers.Is_Set_Mask
87 (Register => GMCH_DP (DP_Port),
88 Mask => PORT_DETECTED,
89 Result => Detected);
90 Config.Valid_Port (To_DP_Port (DP_Port)) := Detected;
91 hotplug_mask_set := hotplug_mask_set or
92 (if Detected then DP_PORT_HOTPLUG_EN (DP_Port) else 0);
93 end loop;
94 Registers.Write
95 (Register => Registers.PORT_HOTPLUG_EN,
96 Value => hotplug_mask_set);
97 end Initialize;
98
99 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
100 is
101 Ctl32 : Word32;
102 begin
103 Registers.Read (Register => Registers.PORT_HOTPLUG_STAT,
104 Value => Ctl32);
105 Detected := (Ctl32 and HOTPLUG_INT_STATUS (Port)) /= 0;
106
107 if Detected then
108 registers.Set_Mask
109 (Register => Registers.PORT_HOTPLUG_STAT,
110 Mask => HOTPLUG_INT_STATUS (Port));
111 end if;
112 end Hotplug_Detect;
113
114 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
115 is
116 Ignored_HPD : Boolean;
117 begin
118 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
119 Reason => "We want to clear pending events only");
120 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
121 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
122 end Clear_Hotplug_Detect;
123
124end HW.GFX.GMA.Port_Detect;