blob: 6fdb527a99411046d3e065c697a4b113fec6fe7d [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
Nico Huber318bca12018-06-09 19:22:52 +020076 Config.Valid_Port (Analog) := True;
Arthur Heymans3f37cce2026-03-03 18:52:12 +010077 Config.Valid_Port (LVDS) := Config.GMCH_GM45 or Config.GMCH_GM965;
78 if not Config.GMCH_GM965 then
79 for HDMI_Port in GMCH_HDMI_Port loop
80 Registers.Is_Set_Mask
81 (Register => GMCH_HDMI (HDMI_Port),
82 Mask => PORT_DETECTED,
83 Result => Detected);
84 Config.Valid_Port (To_HDMI_Port (HDMI_Port)) := Detected;
85 hotplug_mask_set := hotplug_mask_set or
86 (if Detected then HDMI_PORT_HOTPLUG_EN (HDMI_Port) else 0);
87 end loop;
88 for DP_Port in GMCH_DP_Port loop
89 Registers.Is_Set_Mask
90 (Register => GMCH_DP (DP_Port),
91 Mask => PORT_DETECTED,
92 Result => Detected);
93 Config.Valid_Port (To_DP_Port (DP_Port)) := Detected;
94 hotplug_mask_set := hotplug_mask_set or
95 (if Detected then DP_PORT_HOTPLUG_EN (DP_Port) else 0);
96 end loop;
97 end if;
Arthur Heymans73ea0322018-03-28 17:17:07 +020098 Registers.Write
99 (Register => Registers.PORT_HOTPLUG_EN,
100 Value => hotplug_mask_set);
101 end Initialize;
102
103 procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
104 is
105 Ctl32 : Word32;
106 begin
107 Registers.Read (Register => Registers.PORT_HOTPLUG_STAT,
108 Value => Ctl32);
109 Detected := (Ctl32 and HOTPLUG_INT_STATUS (Port)) /= 0;
110
111 if Detected then
112 registers.Set_Mask
113 (Register => Registers.PORT_HOTPLUG_STAT,
114 Mask => HOTPLUG_INT_STATUS (Port));
115 end if;
116 end Hotplug_Detect;
117
118 procedure Clear_Hotplug_Detect (Port : Active_Port_Type)
119 is
120 Ignored_HPD : Boolean;
121 begin
122 pragma Warnings (GNATprove, Off, "unused assignment to ""Ignored_HPD""",
123 Reason => "We want to clear pending events only");
124 Port_Detect.Hotplug_Detect (Port, Ignored_HPD);
125 pragma Warnings (GNATprove, On, "unused assignment to ""Ignored_HPD""");
126 end Clear_Hotplug_Detect;
127
128end HW.GFX.GMA.Port_Detect;