blob: 9a89a588ff633b95ba926e60a9ac0ac15668ced5 [file] [log] [blame]
Angel Pons450c24c2020-05-13 00:49:52 +02001--
2-- Copyright (C) 2020 Angel Pons <th3fanbus@gmail.com>
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.PCH.Sideband;
18
19with HW.Debug;
20with GNAT.Source_Info;
21
22package body HW.GFX.GMA.PCH.Lynxpoint is
23
24 FDI_MPHY_IOSFSB_RESET_CTL : constant := 1 * 2 ** 12;
25 FDI_MPHY_IOSFSB_RESET_STATUS : constant := 1 * 2 ** 13;
26
27 procedure Reset_FDI_mPHY is
28 begin
29 Registers.Set_Mask
30 (Register => Registers.QUIRK_C2004,
31 Mask => FDI_MPHY_IOSFSB_RESET_CTL);
32
33 Registers.Wait_Set_Mask
34 (Register => Registers.QUIRK_C2004,
35 Mask => FDI_MPHY_IOSFSB_RESET_STATUS,
36 TOut_MS => 1); -- 100 us
37
38 Registers.Unset_Mask
39 (Register => Registers.QUIRK_C2004,
40 Mask => FDI_MPHY_IOSFSB_RESET_CTL);
41
42 Registers.Wait_Unset_Mask
43 (Register => Registers.QUIRK_C2004,
44 Mask => FDI_MPHY_IOSFSB_RESET_STATUS,
45 TOut_MS => 1); -- 100 us
46 end Reset_FDI_mPHY;
47
48 -- WaMPhyProgramming:hsw
49 procedure Program_FDI_mPHY
50 is
51 use Sideband;
52 subtype Bit_Index is Natural range 0 .. Word32'Size - 1;
53
54 procedure mPHY_Update_Field
55 (High_Bit : in Bit_Index;
56 Low_Bit : in Bit_Index;
57 Value : in Word32;
58 Register : in Register_Type)
59 with
60 Pre => High_Bit >= Low_Bit
61 is
62 begin
63 Unset_And_Set_Mask
64 (Dest => SBI_MPHY,
65 Register => Register,
66 Mask_Unset => 2 ** (High_Bit + 1) - 2 ** Low_Bit,
67 Mask_Set => Value * 2 ** Low_Bit);
68 end mPHY_Update_Field;
69
70 procedure mPHY_Update_Lanes
71 (High_Bit : in Bit_Index;
72 Low_Bit : in Bit_Index;
73 Value : in Word32;
74 Reg_Lane_0 : in Register_Type;
75 Reg_Lane_1 : in Register_Type)
76 with
77 Pre => High_Bit >= Low_Bit
78 is
79 begin
80 mPHY_Update_Field (High_Bit, Low_Bit, Value, Reg_Lane_0);
81 mPHY_Update_Field (High_Bit, Low_Bit, Value, Reg_Lane_1);
82 end mPHY_Update_Lanes;
83 begin
84 mPHY_Update_Field (31, 24, 16#12#, SBI_MPHY_8008);
85 mPHY_Update_Lanes (11, 11, 1, SBI_MPHY_2008, SBI_MPHY_2108);
86 mPHY_Update_Lanes (24, 24, 1, SBI_MPHY_206C, SBI_MPHY_216C);
87 mPHY_Update_Lanes (21, 21, 1, SBI_MPHY_206C, SBI_MPHY_216C);
88 mPHY_Update_Lanes (18, 18, 1, SBI_MPHY_206C, SBI_MPHY_216C);
89 mPHY_Update_Lanes (15, 13, 16#05#, SBI_MPHY_2080, SBI_MPHY_2180);
90 mPHY_Update_Lanes ( 7, 0, 16#1c#, SBI_MPHY_208C, SBI_MPHY_218C);
91 mPHY_Update_Lanes (23, 16, 16#1c#, SBI_MPHY_2098, SBI_MPHY_2198);
92 mPHY_Update_Lanes (27, 27, 1, SBI_MPHY_20C4, SBI_MPHY_21C4);
93 mPHY_Update_Lanes (31, 28, 16#04#, SBI_MPHY_20EC, SBI_MPHY_21EC);
94 end Program_FDI_mPHY;
95
96 ----------------------------------------------------------------------------
97
98 SBI_SSCCTL_DISABLE : constant := 1 * 2 ** 0;
99 SBI_SSCCTL_PATHALT : constant := 1 * 2 ** 3;
100 SBI_GEN0_CFG_BUFFENABLE_DISABLE : constant := 1 * 2 ** 0;
101
102 procedure Enable_Clkout_DP_And_FDI_mPHY is
103 begin
104 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
105
106 Sideband.Unset_And_Set_Mask
107 (Dest => Sideband.SBI_ICLK,
108 Register => Sideband.SBI_SSCCTL,
109 Mask_Unset => SBI_SSCCTL_DISABLE,
110 Mask_Set => SBI_SSCCTL_PATHALT);
111
112 Time.U_Delay (24);
113
114 Sideband.Unset_Mask
115 (Dest => Sideband.SBI_ICLK,
116 Register => Sideband.SBI_SSCCTL,
117 Mask => SBI_SSCCTL_PATHALT);
118
119 Reset_FDI_mPHY;
120 Program_FDI_mPHY;
121
122 Sideband.Set_Mask
123 (Dest => Sideband.SBI_ICLK,
124 Register => (if Config.Is_LP then Sideband.SBI_GEN0 else Sideband.SBI_DBUFF0),
125 Mask => SBI_GEN0_CFG_BUFFENABLE_DISABLE);
126 end Enable_Clkout_DP_And_FDI_mPHY;
127
128 procedure Disable_Clkout_DP
129 is
130 function Is_Mask_Set (Value, Mask : Word32) return Boolean is
131 ((Value and Mask) = Mask);
132 SSC_Ctl : Word32;
133 begin
134 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
135
136 Sideband.Unset_Mask
137 (Dest => Sideband.SBI_ICLK,
138 Register => (if Config.Is_LP then Sideband.SBI_GEN0 else Sideband.SBI_DBUFF0),
139 Mask => SBI_GEN0_CFG_BUFFENABLE_DISABLE);
140
141 Sideband.Read
142 (Dest => Sideband.SBI_ICLK,
143 Register => Sideband.SBI_SSCCTL,
144 Value => SSC_Ctl);
145
146 if not Is_Mask_Set (SSC_Ctl, SBI_SSCCTL_DISABLE) then
147 if not Is_Mask_Set (SSC_Ctl, SBI_SSCCTL_PATHALT) then
148 Sideband.Set_Mask
149 (Dest => Sideband.SBI_ICLK,
150 Register => Sideband.SBI_SSCCTL,
151 Mask => SBI_SSCCTL_PATHALT);
152 Time.U_Delay (32);
153 end if;
154 Sideband.Set_Mask
155 (Dest => Sideband.SBI_ICLK,
156 Register => Sideband.SBI_SSCCTL,
157 Mask => SBI_SSCCTL_DISABLE);
158 end if;
159 end Disable_Clkout_DP;
160
161 procedure Unbend_Clkout_DP is
162 begin
163 pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
164
165 Sideband.Write
166 (Dest => Sideband.SBI_ICLK,
167 Register => Sideband.SBI_SSCDITHPHASE,
168 Value => 0);
169
170 Sideband.Unset_And_Set_Mask
171 (Dest => Sideband.SBI_ICLK,
172 Register => Sideband.SBI_SSCDIVINTPHASE,
173 Mask_Unset => 16#ffff#,
174 Mask_Set => 16#0025#);
175 end Unbend_Clkout_DP;
176
177end HW.GFX.GMA.PCH.Lynxpoint;