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