blob: f0902462c814625b6cefb74ebcea6e0acd207e30 [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.Config;
16with HW.GFX.GMA.Registers;
17with HW.GFX.GMA.PCH.Sideband;
18
19with HW.Debug;
20with GNAT.Source_Info;
21
22use type HW.Word64;
23
24package body HW.GFX.GMA.PCH.VGA is
25
26 PCH_ADPA_DAC_ENABLE : constant := 1 * 2 ** 31;
27 PCH_ADPA_VSYNC_DISABLE : constant := 1 * 2 ** 11;
28 PCH_ADPA_HSYNC_DISABLE : constant := 1 * 2 ** 10;
29 PCH_ADPA_VSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 4;
30 PCH_ADPA_HSYNC_ACTIVE_HIGH : constant := 1 * 2 ** 3;
31
32 PCH_ADPA_MASK : constant Word32 :=
33 PCH_TRANSCODER_SELECT_MASK or
34 PCH_ADPA_DAC_ENABLE or
35 PCH_ADPA_VSYNC_DISABLE or
36 PCH_ADPA_HSYNC_DISABLE or
37 PCH_ADPA_VSYNC_ACTIVE_HIGH or
38 PCH_ADPA_HSYNC_ACTIVE_HIGH;
39
40 ----------------------------------------------------------------------------
41
42 procedure On
43 (Port : FDI_Port_Type;
44 Mode : Mode_Type)
45 is
46 Polarity : Word32 := 0;
47 begin
48 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
49
50 if Mode.H_Sync_Active_High then
51 Polarity := Polarity or PCH_ADPA_HSYNC_ACTIVE_HIGH;
52 end if;
53 if Mode.V_Sync_Active_High then
54 Polarity := Polarity or PCH_ADPA_VSYNC_ACTIVE_HIGH;
55 end if;
56
57 Registers.Unset_And_Set_Mask
58 (Register => Registers.PCH_ADPA,
59 Mask_Unset => PCH_ADPA_MASK,
60 Mask_Set => PCH_ADPA_DAC_ENABLE or
61 PCH_TRANSCODER_SELECT (Port) or
62 Polarity);
63 end On;
64
65 ----------------------------------------------------------------------------
66
67 procedure Off
68 is
69 Sync_Disable : Word32 := 0;
70 begin
71 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
72
73 if Config.VGA_Has_Sync_Disable then
74 Sync_Disable := PCH_ADPA_HSYNC_DISABLE or PCH_ADPA_VSYNC_DISABLE;
75 end if;
76
77 Registers.Unset_And_Set_Mask
78 (Register => Registers.PCH_ADPA,
79 Mask_Unset => PCH_ADPA_DAC_ENABLE,
80 Mask_Set => Sync_Disable);
81 end Off;
82
83 ----------------------------------------------------------------------------
84
85 PCH_PIXCLK_GATE_GATE : constant := 0 * 2 ** 0;
86 PCH_PIXCLK_GATE_UNGATE : constant := 1 * 2 ** 0;
87
88 SBI_SSCCTL_DISABLE : constant := 1 * 2 ** 0;
89 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT : constant := 1;
90 SBI_SSCDIVINTPHASE_DIVSEL_MASK : constant := 16#7f# * 2 ** 1;
91 SBI_SSCDIVINTPHASE_INCVAL_SHIFT : constant := 8;
92 SBI_SSCDIVINTPHASE_INCVAL_MASK : constant := 16#7f# * 2 ** 8;
93 SBI_SSCDIVINTPHASE_DIR_SHIFT : constant := 15;
94 SBI_SSCDIVINTPHASE_DIR_MASK : constant := 16#01# * 2 ** 15;
95 SBI_SSCDIVINTPHASE_PROPAGATE : constant := 1 * 2 ** 0;
96 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT : constant := 4;
97 SBI_SSCAUXDIV_FINALDIV2SEL_MASK : constant := 16#01# * 2 ** 4;
98
99 function SBI_SSCDIVINTPHASE_DIVSEL (Val : Word32) return Word32 is
100 begin
101 return Shift_Left (Val, SBI_SSCDIVINTPHASE_DIVSEL_SHIFT);
102 end SBI_SSCDIVINTPHASE_DIVSEL;
103
104 function SBI_SSCDIVINTPHASE_INCVAL (Val : Word32) return Word32 is
105 begin
106 return Shift_Left (Val, SBI_SSCDIVINTPHASE_INCVAL_SHIFT);
107 end SBI_SSCDIVINTPHASE_INCVAL;
108
109 function SBI_SSCDIVINTPHASE_DIR (Val : Word32) return Word32 is
110 begin
111 return Shift_Left (Val, SBI_SSCDIVINTPHASE_DIR_SHIFT);
112 end SBI_SSCDIVINTPHASE_DIR;
113
114 function SBI_SSCAUXDIV_FINALDIV2SEL (Val : Word32) return Word32 is
115 begin
116 return Shift_Left (Val, SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT);
117 end SBI_SSCAUXDIV_FINALDIV2SEL;
118
119 procedure Clock_On (Mode : Mode_Type)
120 is
121 Refclock : constant := 2_700_000_000;
122
123 Aux_Div,
124 Div_Sel,
125 Phase_Inc,
126 Phase_Dir : Word32;
127 begin
128 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
129
130 Registers.Write (Registers.PCH_PIXCLK_GATE, PCH_PIXCLK_GATE_GATE);
131
132 Sideband.Set_Mask
133 (Dest => Sideband.SBI_ICLK,
134 Register => Sideband.SBI_SSCCTL6,
135 Mask => SBI_SSCCTL_DISABLE);
136
137 Aux_Div := 16#0000_0000#;
138 Div_Sel := Word32 (Refclock / Mode.Dotclock - 2);
139 Phase_Inc := Word32 ((Refclock * 64) / Mode.Dotclock) and 16#0000_003f#;
140 Phase_Dir := 16#0000_0000#;
141
142 pragma Debug (Debug.Put_Reg32 ("Aux_Div ", Aux_Div));
143 pragma Debug (Debug.Put_Reg32 ("Div_Sel ", Div_Sel));
144 pragma Debug (Debug.Put_Reg32 ("Phase_Inc", Phase_Inc));
145 pragma Debug (Debug.Put_Reg32 ("Phase_Dir", Phase_Dir));
146
147 Sideband.Unset_And_Set_Mask
148 (Dest => Sideband.SBI_ICLK,
149 Register => Sideband.SBI_SSCDIVINTPHASE6,
150 Mask_Unset => SBI_SSCDIVINTPHASE_DIVSEL_MASK or
151 SBI_SSCDIVINTPHASE_INCVAL_MASK or
152 SBI_SSCDIVINTPHASE_DIR_MASK,
153 Mask_Set => SBI_SSCDIVINTPHASE_DIVSEL (Div_Sel) or
154 SBI_SSCDIVINTPHASE_INCVAL (Phase_Inc) or
155 SBI_SSCDIVINTPHASE_DIR (Phase_Dir) or
156 SBI_SSCDIVINTPHASE_PROPAGATE);
157
158 Sideband.Unset_And_Set_Mask
159 (Dest => Sideband.SBI_ICLK,
160 Register => Sideband.SBI_SSCAUXDIV,
161 Mask_Unset => SBI_SSCAUXDIV_FINALDIV2SEL_MASK,
162 Mask_Set => SBI_SSCAUXDIV_FINALDIV2SEL (Aux_Div));
163
164 Sideband.Unset_Mask
165 (Dest => Sideband.SBI_ICLK,
166 Register => Sideband.SBI_SSCCTL6,
167 Mask => SBI_SSCCTL_DISABLE);
168
169 Registers.Write (Registers.PCH_PIXCLK_GATE, PCH_PIXCLK_GATE_UNGATE);
170 end Clock_On;
171
172end HW.GFX.GMA.PCH.VGA;