blob: 15d4e9f0fc9ce5ed6c5930cd5a29481cdd96afc3 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
2-- Copyright (C) 2015-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.Registers;
16
17with HW.Debug;
18with GNAT.Source_Info;
19
20package body HW.GFX.GMA.PCH.HDMI
21is
22
23 PCH_HDMI_ENABLE : constant := 1 * 2 ** 31;
24 PCH_HDMI_COLOR_FORMAT_8BPC : constant := 0 * 2 ** 26;
25 PCH_HDMI_COLOR_FORMAT_12BPC : constant := 3 * 2 ** 26;
26 PCH_HDMI_COLOR_FORMAT_MASK : constant := 7 * 2 ** 26;
27 PCH_HDMI_SDVO_ENCODING_SDVO : constant := 0 * 2 ** 10;
28 PCH_HDMI_SDVO_ENCODING_HDMI : constant := 2 * 2 ** 10;
29 PCH_HDMI_SDVO_ENCODING_MASK : constant := 3 * 2 ** 10;
30 PCH_HDMI_VSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 4;
31 PCH_HDMI_HSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 3;
32 PCH_HDMI_PORT_DETECT : constant := 1 * 2 ** 2;
33
Nico Huber63dc9192018-06-09 17:42:19 +020034 function PCH_HDMI_MASK return Word32 is
35 (PCH_TRANSCODER_SELECT_MASK or
Nico Huber83693c82016-10-08 22:17:55 +020036 PCH_HDMI_ENABLE or
37 PCH_HDMI_COLOR_FORMAT_MASK or
38 PCH_HDMI_SDVO_ENCODING_MASK or
39 PCH_HDMI_HSYNC_ACTIVE_HIGH or
Nico Huber63dc9192018-06-09 17:42:19 +020040 PCH_HDMI_VSYNC_ACTIVE_HIGH);
Nico Huber83693c82016-10-08 22:17:55 +020041
42 type PCH_HDMI_Array is array (PCH_HDMI_Port) of Registers.Registers_Index;
43 PCH_HDMI : constant PCH_HDMI_Array := PCH_HDMI_Array'
44 (PCH_HDMI_B => Registers.PCH_HDMIB,
45 PCH_HDMI_C => Registers.PCH_HDMIC,
46 PCH_HDMI_D => Registers.PCH_HDMID);
47
48 ----------------------------------------------------------------------------
49
50 procedure On (Port_Cfg : Port_Config; FDI_Port : FDI_Port_Type)
51 is
52 Polarity : constant Word32 :=
53 (if Port_Cfg.Mode.H_Sync_Active_High then
54 PCH_HDMI_HSYNC_ACTIVE_HIGH else 0) or
55 (if Port_Cfg.Mode.V_Sync_Active_High then
56 PCH_HDMI_VSYNC_ACTIVE_HIGH else 0);
57 begin
58 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
59
60 -- registers are just sufficient for setup with DVI adaptor
61
62 Registers.Unset_And_Set_Mask
63 (Register => PCH_HDMI (Port_Cfg.PCH_Port),
64 Mask_Unset => PCH_HDMI_MASK,
65 Mask_Set => PCH_HDMI_ENABLE or
66 PCH_TRANSCODER_SELECT (FDI_Port) or
67 PCH_HDMI_SDVO_ENCODING_HDMI or
68 Polarity);
Nico Huber04c1d012019-10-03 22:28:21 +020069 Registers.Posting_Read (PCH_HDMI (Port_Cfg.PCH_Port));
70 -- Set enable a second time, hardware may miss the first.
71 Registers.Set_Mask (PCH_HDMI (Port_Cfg.PCH_Port), PCH_HDMI_ENABLE);
72 Registers.Posting_Read (PCH_HDMI (Port_Cfg.PCH_Port));
Nico Huber83693c82016-10-08 22:17:55 +020073 end On;
74
75 ----------------------------------------------------------------------------
76
77 procedure Off (Port : PCH_HDMI_Port)
78 is
Nico Huberf6a2d182019-10-01 10:37:49 +020079 With_Transcoder_B_Enabled : Boolean := False;
Nico Huber83693c82016-10-08 22:17:55 +020080 begin
81 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
82
Nico Huberf6a2d182019-10-01 10:37:49 +020083 if not Config.Has_Trans_DP_Ctl then
84 -- Ensure transcoder select isn't set to B,
85 -- disabled HDMI may block DP otherwise.
86 Registers.Is_Set_Mask
87 (Register => PCH_HDMI (Port),
88 Mask => PCH_HDMI_ENABLE or
89 PCH_TRANSCODER_SELECT (FDI_B),
90 Result => With_Transcoder_B_Enabled);
91 end if;
92
Nico Huber83693c82016-10-08 22:17:55 +020093 Registers.Unset_And_Set_Mask
94 (Register => PCH_HDMI (Port),
95 Mask_Unset => PCH_HDMI_MASK,
96 Mask_Set => PCH_HDMI_HSYNC_ACTIVE_HIGH or
97 PCH_HDMI_VSYNC_ACTIVE_HIGH);
Nico Huberf6a2d182019-10-01 10:37:49 +020098 Registers.Posting_Read (PCH_HDMI (Port));
99
100 if not Config.Has_Trans_DP_Ctl and then With_Transcoder_B_Enabled then
101 -- Reenable with transcoder A selected to switch.
102 Registers.Set_Mask (PCH_HDMI (Port), PCH_HDMI_ENABLE);
103 Registers.Posting_Read (PCH_HDMI (Port));
Nico Huber04c1d012019-10-03 22:28:21 +0200104 -- Set enable a second time, hardware may miss the first.
105 Registers.Set_Mask (PCH_HDMI (Port), PCH_HDMI_ENABLE);
106 Registers.Posting_Read (PCH_HDMI (Port));
Nico Huberf6a2d182019-10-01 10:37:49 +0200107 Registers.Unset_Mask (PCH_HDMI (Port), PCH_HDMI_ENABLE);
108 Registers.Posting_Read (PCH_HDMI (Port));
109 end if;
110
Nico Huber83693c82016-10-08 22:17:55 +0200111 end Off;
112
113 procedure All_Off
114 is
115 begin
116 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
117
118 for Port in PCH_HDMI_Port loop
119 Off (Port);
120 end loop;
121 end All_Off;
122
123end HW.GFX.GMA.PCH.HDMI;