| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 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 | |
| 15 | with HW.Debug; |
| 16 | with GNAT.Source_Info; |
| 17 | |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 18 | with HW.GFX.GMA.Config; |
| 19 | with HW.GFX.GMA.Registers; |
| Nico Huber | afadcac | 2017-02-08 13:41:38 +0100 | [diff] [blame] | 20 | with HW.GFX.GMA.DDI_Phy; |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 21 | |
| 22 | use HW.GFX.GMA.Registers; |
| 23 | |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 24 | package body HW.GFX.GMA.PLLs |
| 25 | with |
| 26 | Refined_State => (State => null) |
| 27 | is |
| 28 | |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 29 | -- DPLL clock equation: |
| 30 | -- 5 * Target_Dotclock = Ref_Clk * M1 * (M2 / 2^22) / N / (P1 * P2) |
| 31 | -- |
| 32 | -- Where |
| 33 | -- M1 = 2, |
| 34 | -- Ref_Clk = 100MHz, |
| 35 | -- VCO = Ref_Clk * 2 * (M2 / 2^22), |
| 36 | -- N = 1 and |
| 37 | -- P = P1 * P2. |
| 38 | |
| 39 | Ref_Clk : constant := 100_000_000; |
| 40 | M1 : constant := 2; |
| 41 | N : constant := 1; |
| 42 | |
| 43 | -- i915 has a fixme for the M2 range. But the VCO range is very |
| 44 | -- limited, giving us a narrow range for M2: 24 .. 33.5 |
| 45 | subtype VCO_Range is Pos64 range 4_800_000_000 .. 6_700_000_000; |
| 46 | subtype M2_Range is Pos64 range |
| 47 | N * VCO_Range'First * 2 ** 22 / Ref_Clk / M1 .. |
| 48 | N * VCO_Range'Last * 2 ** 22 / Ref_Clk / M1; |
| 49 | |
| 50 | subtype N_Range is Pos64 range 1 .. 1; |
| 51 | |
| 52 | subtype P1_Range is Pos64 range 2 .. 4; |
| 53 | subtype P2_Range is Pos64 range 1 .. 20; |
| 54 | |
| 55 | subtype Clock_Range is Frequency_Type range |
| 56 | Frequency_Type'First .. 540_000_000; |
| 57 | subtype HDMI_Clock_Range is Clock_Range range |
| 58 | 25_000_000 .. Config.HDMI_Max_Clock_24bpp; |
| 59 | subtype Clock_Gap is Clock_Range range 223_333_333 + 1 .. 240_000_000 - 1; |
| 60 | |
| 61 | type Clock_Type is record |
| 62 | M2 : M2_Range; |
| 63 | P1 : P1_Range; |
| 64 | P2 : P2_Range; |
| 65 | VCO : VCO_Range; |
| 66 | Dotclock : Clock_Range; |
| 67 | end record; |
| 68 | |
| 69 | Invalid_Clock : constant Clock_Type := |
| 70 | (M2 => M2_Range'Last, |
| 71 | P1 => P1_Range'Last, |
| 72 | P2 => P2_Range'Last, |
| 73 | VCO => VCO_Range'Last, |
| 74 | Dotclock => Clock_Range'Last); |
| 75 | |
| 76 | procedure Calculate_Clock_Parameters |
| 77 | (Target_Dotclock : in HDMI_Clock_Range; |
| 78 | Best_Clock : out Clock_Type; |
| 79 | Valid : out Boolean) |
| 80 | with |
| 81 | Pre => True |
| 82 | is |
| 83 | Target_Clock : constant Pos64 := 5 * Target_Dotclock; |
| 84 | |
| 85 | M2, VCO, Current_Clock : Pos64; |
| 86 | P2 : P2_Range; |
| 87 | |
| 88 | Valid_Clk : Boolean; |
| 89 | begin |
| 90 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 91 | |
| 92 | Valid := False; |
| 93 | Best_Clock := Invalid_Clock; |
| 94 | |
| 95 | -- reverse loops as hardware prefers higher values |
| 96 | for P1 in reverse P1_Range loop |
| 97 | -- find the highest P2 that results in valid clock |
| 98 | P2 := P2_Range'Last; |
| 99 | loop |
| 100 | M2 := Div_Round_Closest |
| 101 | (Target_Clock * P2 * P1 * N * 2 ** 22, Ref_Clk * M1); |
| 102 | VCO := Div_Round_Closest (Ref_Clk * M1 * M2, 2 ** 22 * N); |
| 103 | Current_Clock := Div_Round_Closest (VCO, P1 * P2); |
| 104 | |
| 105 | Valid_Clk := M2 in M2_Range and then |
| 106 | Div_Round_Closest (Current_Clock, 5) in Clock_Range; |
| 107 | if Valid_Clk then |
| 108 | -- the error is always below 2^-22, higher P takes precedence |
| 109 | if not Valid or P1 * P2 > Best_Clock.P1 * Best_Clock.P2 then |
| 110 | Best_Clock := Clock_Type' |
| 111 | (M2 => M2, |
| 112 | P1 => P1, |
| 113 | P2 => P2, |
| 114 | VCO => VCO, |
| 115 | Dotclock => Div_Round_Closest (Current_Clock, 5)); |
| 116 | Valid := True; |
| 117 | end if; |
| 118 | end if; |
| 119 | |
| 120 | -- Prefer higher P2 over marginal lower error. This is |
| 121 | -- just an optimization, since lower P2 values would get |
| 122 | -- filtered above anyway. |
| 123 | exit when Valid_Clk; |
| 124 | |
| 125 | -- If M2 got too low, it won't get any better. Another |
| 126 | -- optimization. |
| 127 | exit when M2 < M2_Range'First; |
| 128 | |
| 129 | exit when P2 = P2_Range'First; |
| 130 | |
| 131 | if P2 > 10 then |
| 132 | P2 := P2 - 2; |
| 133 | else |
| 134 | P2 := P2 - 1; |
| 135 | end if; |
| 136 | end loop; |
| 137 | end loop; |
| 138 | |
| 139 | pragma Debug (Valid, Debug.Put_Line ("Valid clock found.")); |
| 140 | pragma Debug (Valid, Debug.Put ("M2 / P1 / P2: ")); |
| 141 | pragma Debug (Valid, Debug.Put_Word32 (Word32 (Best_Clock.M2))); |
| 142 | pragma Debug (Valid, Debug.Put (" / ")); |
| 143 | pragma Debug (Valid, Debug.Put_Int8 (Pos8 (Best_Clock.P1))); |
| 144 | pragma Debug (Valid, Debug.Put (" / ")); |
| 145 | pragma Debug (Valid, Debug.Put_Int8 (Pos8 (Best_Clock.P2))); |
| 146 | pragma Debug (Valid, Debug.New_Line); |
| 147 | pragma Debug (Valid, Debug.Put ("Best / Target: ")); |
| 148 | pragma Debug (Valid, Debug.Put_Int64 (Best_Clock.Dotclock)); |
| 149 | pragma Debug (Valid, Debug.Put (" / ")); |
| 150 | pragma Debug (Valid, Debug.Put_Int64 (Target_Dotclock)); |
| 151 | pragma Debug (Valid, Debug.New_Line); |
| 152 | pragma Debug (not Valid, Debug.Put_Line ("No valid clock found.")); |
| 153 | end Calculate_Clock_Parameters; |
| 154 | |
| 155 | ---------------------------------------------------------------------------- |
| 156 | |
| 157 | subtype Valid_PLLs is T range DPLL_A .. DPLL_C; |
| 158 | |
| 159 | type Port_PLL_Regs is record |
| 160 | PLL_ENABLE : Registers_Index; |
| 161 | PLL_EBB_0 : Registers_Index; |
| 162 | PLL_EBB_4 : Registers_Index; |
| 163 | PLL_0 : Registers_Index; |
| 164 | PLL_1 : Registers_Index; |
| 165 | PLL_2 : Registers_Index; |
| 166 | PLL_3 : Registers_Index; |
| 167 | PLL_6 : Registers_Index; |
| 168 | PLL_8 : Registers_Index; |
| 169 | PLL_9 : Registers_Index; |
| 170 | PLL_10 : Registers_Index; |
| 171 | PCS_DW12_LN01 : Registers_Index; |
| 172 | PCS_DW12_GRP : Registers_Index; |
| 173 | end record; |
| 174 | type Port_PLL_Array is array (Valid_PLLs) of Port_PLL_Regs; |
| 175 | |
| 176 | PORT : constant Port_PLL_Array := |
| 177 | (DPLL_A => |
| 178 | (PLL_ENABLE => BXT_PORT_PLL_ENABLE_A, |
| 179 | PLL_EBB_0 => BXT_PORT_PLL_EBB_0_A, |
| 180 | PLL_EBB_4 => BXT_PORT_PLL_EBB_4_A, |
| 181 | PLL_0 => BXT_PORT_PLL_0_A, |
| 182 | PLL_1 => BXT_PORT_PLL_1_A, |
| 183 | PLL_2 => BXT_PORT_PLL_2_A, |
| 184 | PLL_3 => BXT_PORT_PLL_3_A, |
| 185 | PLL_6 => BXT_PORT_PLL_6_A, |
| 186 | PLL_8 => BXT_PORT_PLL_8_A, |
| 187 | PLL_9 => BXT_PORT_PLL_9_A, |
| 188 | PLL_10 => BXT_PORT_PLL_10_A, |
| 189 | PCS_DW12_LN01 => BXT_PORT_PCS_DW12_01_A, |
| 190 | PCS_DW12_GRP => BXT_PORT_PCS_DW12_GRP_A), |
| 191 | DPLL_B => |
| 192 | (PLL_ENABLE => BXT_PORT_PLL_ENABLE_B, |
| 193 | PLL_EBB_0 => BXT_PORT_PLL_EBB_0_B, |
| 194 | PLL_EBB_4 => BXT_PORT_PLL_EBB_4_B, |
| 195 | PLL_0 => BXT_PORT_PLL_0_B, |
| 196 | PLL_1 => BXT_PORT_PLL_1_B, |
| 197 | PLL_2 => BXT_PORT_PLL_2_B, |
| 198 | PLL_3 => BXT_PORT_PLL_3_B, |
| 199 | PLL_6 => BXT_PORT_PLL_6_B, |
| 200 | PLL_8 => BXT_PORT_PLL_8_B, |
| 201 | PLL_9 => BXT_PORT_PLL_9_B, |
| 202 | PLL_10 => BXT_PORT_PLL_10_B, |
| 203 | PCS_DW12_LN01 => BXT_PORT_PCS_DW12_01_B, |
| 204 | PCS_DW12_GRP => BXT_PORT_PCS_DW12_GRP_B), |
| 205 | DPLL_C => |
| 206 | (PLL_ENABLE => BXT_PORT_PLL_ENABLE_C, |
| 207 | PLL_EBB_0 => BXT_PORT_PLL_EBB_0_C, |
| 208 | PLL_EBB_4 => BXT_PORT_PLL_EBB_4_C, |
| 209 | PLL_0 => BXT_PORT_PLL_0_C, |
| 210 | PLL_1 => BXT_PORT_PLL_1_C, |
| 211 | PLL_2 => BXT_PORT_PLL_2_C, |
| 212 | PLL_3 => BXT_PORT_PLL_3_C, |
| 213 | PLL_6 => BXT_PORT_PLL_6_C, |
| 214 | PLL_8 => BXT_PORT_PLL_8_C, |
| 215 | PLL_9 => BXT_PORT_PLL_9_C, |
| 216 | PLL_10 => BXT_PORT_PLL_10_C, |
| 217 | PCS_DW12_LN01 => BXT_PORT_PCS_DW12_01_C, |
| 218 | PCS_DW12_GRP => BXT_PORT_PCS_DW12_GRP_C)); |
| 219 | |
| 220 | PORT_PLL_ENABLE : constant := 1 * 2 ** 31; |
| 221 | PORT_PLL_ENABLE_LOCK : constant := 1 * 2 ** 30; |
| 222 | PORT_PLL_ENABLE_REF_SEL : constant := 1 * 2 ** 27; |
| 223 | |
| 224 | PORT_PLL_EBB0_P1_SHIFT : constant := 13; |
| 225 | PORT_PLL_EBB0_P1_MASK : constant := 16#07# * 2 ** 13; |
| 226 | PORT_PLL_EBB0_P2_SHIFT : constant := 8; |
| 227 | PORT_PLL_EBB0_P2_MASK : constant := 16#1f# * 2 ** 8; |
| 228 | function PORT_PLL_EBB0_P1 (P1 : P1_Range) return Word32 is |
| 229 | begin |
| 230 | return Shift_Left (Word32 (P1), PORT_PLL_EBB0_P1_SHIFT); |
| 231 | end PORT_PLL_EBB0_P1; |
| 232 | function PORT_PLL_EBB0_P2 (P2 : P2_Range) return Word32 is |
| 233 | begin |
| 234 | return Shift_Left (Word32 (P2), PORT_PLL_EBB0_P2_SHIFT); |
| 235 | end PORT_PLL_EBB0_P2; |
| 236 | |
| 237 | PORT_PLL_EBB4_RECALIBRATE : constant := 1 * 2 ** 14; |
| 238 | PORT_PLL_EBB4_10BIT_CLK_ENABLE : constant := 1 * 2 ** 13; |
| 239 | |
| 240 | PORT_PLL_0_M2_INT_MASK : constant := 16#ff# * 2 ** 0; |
| 241 | function PORT_PLL_0_M2_INT (M2 : M2_Range) return Word32 is |
| 242 | begin |
| 243 | return Shift_Right (Word32 (M2), 22); |
| 244 | end PORT_PLL_0_M2_INT; |
| 245 | |
| 246 | PORT_PLL_1_N_SHIFT : constant := 8; |
| 247 | PORT_PLL_1_N_MASK : constant := 16#0f# * 2 ** 8; |
| 248 | function PORT_PLL_1_N (N : N_Range) return Word32 is |
| 249 | begin |
| 250 | return Shift_Left (Word32 (N), PORT_PLL_1_N_SHIFT); |
| 251 | end PORT_PLL_1_N; |
| 252 | |
| 253 | PORT_PLL_2_M2_FRAC_MASK : constant := 16#3f_ffff#; |
| 254 | function PORT_PLL_2_M2_FRAC (M2 : M2_Range) return Word32 is |
| 255 | begin |
| 256 | return Word32 (M2) and PORT_PLL_2_M2_FRAC_MASK; |
| 257 | end PORT_PLL_2_M2_FRAC; |
| 258 | |
| 259 | PORT_PLL_3_M2_FRAC_EN_MASK : constant := 1 * 2 ** 16; |
| 260 | function PORT_PLL_3_M2_FRAC_EN (M2 : M2_Range) return Word32 is |
| 261 | begin |
| 262 | return |
| 263 | (if (Word32 (M2) and PORT_PLL_2_M2_FRAC_MASK) /= 0 then |
| 264 | PORT_PLL_3_M2_FRAC_EN_MASK else 0); |
| 265 | end PORT_PLL_3_M2_FRAC_EN; |
| 266 | |
| 267 | PORT_PLL_6_GAIN_CTL_SHIFT : constant := 16; |
| 268 | PORT_PLL_6_GAIN_CTL_MASK : constant := 16#07# * 2 ** 16; |
| 269 | PORT_PLL_6_INT_COEFF_SHIFT : constant := 8; |
| 270 | PORT_PLL_6_INT_COEFF_MASK : constant := 16#1f# * 2 ** 8; |
| 271 | PORT_PLL_6_PROP_COEFF_MASK : constant := 16#0f# * 2 ** 0; |
| 272 | function PORT_PLL_6_GAIN_COEFF (VCO : VCO_Range) return Word32 is |
| 273 | begin |
| 274 | return |
| 275 | (if VCO >= 6_200_000_000 then |
| 276 | Shift_Left (Word32'(3), PORT_PLL_6_GAIN_CTL_SHIFT) or |
| 277 | Shift_Left (Word32'(9), PORT_PLL_6_INT_COEFF_SHIFT) or |
| 278 | Word32'(4) |
| 279 | elsif VCO /= 5_400_000_000 then |
| 280 | Shift_Left (Word32'(3), PORT_PLL_6_GAIN_CTL_SHIFT) or |
| 281 | Shift_Left (Word32'(11), PORT_PLL_6_INT_COEFF_SHIFT) or |
| 282 | Word32'(5) |
| 283 | else |
| 284 | Shift_Left (Word32'(1), PORT_PLL_6_GAIN_CTL_SHIFT) or |
| 285 | Shift_Left (Word32'(8), PORT_PLL_6_INT_COEFF_SHIFT) or |
| 286 | Word32'(3)); |
| 287 | end PORT_PLL_6_GAIN_COEFF; |
| 288 | |
| 289 | PORT_PLL_8_TARGET_CNT_MASK : constant := 16#3ff#; |
| 290 | function PORT_PLL_8_TARGET_CNT (VCO : VCO_Range) return Word32 is |
| 291 | begin |
| 292 | return (if VCO >= 6_200_000_000 then 8 else 9); |
| 293 | end PORT_PLL_8_TARGET_CNT; |
| 294 | |
| 295 | PORT_PLL_9_LOCK_THRESHOLD_SHIFT : constant := 1; |
| 296 | PORT_PLL_9_LOCK_THRESHOLD_MASK : constant := 16#07# * 2 ** 1; |
| 297 | function PORT_PLL_9_LOCK_THRESHOLD (Threshold : Natural) return Word32 is |
| 298 | begin |
| 299 | return |
| 300 | Shift_Left (Word32 (Threshold), PORT_PLL_9_LOCK_THRESHOLD_SHIFT) and |
| 301 | PORT_PLL_9_LOCK_THRESHOLD_MASK; |
| 302 | end PORT_PLL_9_LOCK_THRESHOLD; |
| 303 | |
| 304 | PORT_PLL_10_DCO_AMP_OVR_EN_H : constant := 2 ** 27; |
| 305 | PORT_PLL_10_DCO_AMP_SHIFT : constant := 10; |
| 306 | PORT_PLL_10_DCO_AMP_MASK : constant := 16#0f# * 2 ** 10; |
| 307 | function PORT_PLL_10_DCO_AMP (Amp : Natural) return Word32 is |
| 308 | begin |
| 309 | return |
| 310 | Shift_Left (Word32 (Amp), PORT_PLL_10_DCO_AMP_SHIFT) and |
| 311 | PORT_PLL_10_DCO_AMP_MASK; |
| 312 | end PORT_PLL_10_DCO_AMP; |
| 313 | |
| 314 | PORT_PCS_LANE_STAGGER_STRAP_OVRD : constant := 2 ** 6; |
| 315 | PORT_PCS_LANE_STAGGER_MASK : constant := 16#1f# * 2 ** 0; |
| 316 | function PORT_PCS_LANE_STAGGER (Dotclock : Clock_Range) return Word32 is |
| 317 | begin |
| 318 | return Word32'(PORT_PCS_LANE_STAGGER_STRAP_OVRD) or |
| 319 | (if Dotclock > 270_000_000 then |
| 320 | 16#18# |
| 321 | elsif Dotclock > 135_000_000 then |
| 322 | 16#0d# |
| 323 | elsif Dotclock > 67_000_000 then |
| 324 | 16#07# |
| 325 | elsif Dotclock > 33_000_000 then |
| 326 | 16#04# |
| 327 | else |
| 328 | 16#02#); |
| 329 | end PORT_PCS_LANE_STAGGER; |
| 330 | |
| 331 | ---------------------------------------------------------------------------- |
| 332 | |
| Nico Huber | 565f33b | 2018-06-04 14:42:13 +0200 | [diff] [blame] | 333 | procedure Program_DPLL (P : Valid_PLLs; Clock : Clock_Type) |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 334 | is |
| 335 | PCS : Word32; |
| 336 | begin |
| 337 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 338 | |
| 339 | Set_Mask (PORT (P).PLL_ENABLE, PORT_PLL_ENABLE_REF_SEL); -- non-SSC ref |
| 340 | Unset_Mask (PORT (P).PLL_EBB_4, PORT_PLL_EBB4_10BIT_CLK_ENABLE); |
| 341 | |
| 342 | Unset_And_Set_Mask |
| 343 | (Register => PORT (P).PLL_EBB_0, |
| 344 | Mask_Unset => PORT_PLL_EBB0_P1_MASK or |
| 345 | PORT_PLL_EBB0_P2_MASK, |
| 346 | Mask_Set => PORT_PLL_EBB0_P1 (Clock.P1) or |
| 347 | PORT_PLL_EBB0_P2 (Clock.P2)); |
| 348 | Unset_And_Set_Mask |
| 349 | (Register => PORT (P).PLL_0, |
| 350 | Mask_Unset => PORT_PLL_0_M2_INT_MASK, |
| 351 | Mask_Set => PORT_PLL_0_M2_INT (Clock.M2)); |
| 352 | Unset_And_Set_Mask |
| 353 | (Register => PORT (P).PLL_1, |
| 354 | Mask_Unset => PORT_PLL_1_N_MASK, |
| 355 | Mask_Set => PORT_PLL_1_N (N)); |
| 356 | Unset_And_Set_Mask |
| 357 | (Register => PORT (P).PLL_2, |
| 358 | Mask_Unset => PORT_PLL_2_M2_FRAC_MASK, |
| 359 | Mask_Set => PORT_PLL_2_M2_FRAC (Clock.M2)); |
| 360 | Unset_And_Set_Mask |
| 361 | (Register => PORT (P).PLL_3, |
| 362 | Mask_Unset => PORT_PLL_3_M2_FRAC_EN_MASK, |
| 363 | Mask_Set => PORT_PLL_3_M2_FRAC_EN (Clock.M2)); |
| 364 | Unset_And_Set_Mask |
| 365 | (Register => PORT (P).PLL_6, |
| 366 | Mask_Unset => PORT_PLL_6_GAIN_CTL_MASK or |
| 367 | PORT_PLL_6_INT_COEFF_MASK or |
| 368 | PORT_PLL_6_PROP_COEFF_MASK, |
| 369 | Mask_Set => PORT_PLL_6_GAIN_COEFF (Clock.VCO)); |
| 370 | Unset_And_Set_Mask |
| 371 | (Register => PORT (P).PLL_8, |
| 372 | Mask_Unset => PORT_PLL_8_TARGET_CNT_MASK, |
| 373 | Mask_Set => PORT_PLL_8_TARGET_CNT (Clock.VCO)); |
| 374 | Unset_And_Set_Mask |
| 375 | (Register => PORT (P).PLL_9, |
| 376 | Mask_Unset => PORT_PLL_9_LOCK_THRESHOLD_MASK, |
| 377 | Mask_Set => PORT_PLL_9_LOCK_THRESHOLD (5)); |
| 378 | Unset_And_Set_Mask |
| 379 | (Register => PORT (P).PLL_10, |
| 380 | Mask_Unset => PORT_PLL_10_DCO_AMP_MASK, |
| 381 | Mask_Set => PORT_PLL_10_DCO_AMP_OVR_EN_H or |
| 382 | PORT_PLL_10_DCO_AMP (15)); |
| 383 | |
| 384 | Set_Mask (PORT (P).PLL_EBB_4, PORT_PLL_EBB4_RECALIBRATE); |
| 385 | Set_Mask (PORT (P).PLL_EBB_4, PORT_PLL_EBB4_10BIT_CLK_ENABLE); |
| 386 | |
| 387 | Set_Mask (PORT (P).PLL_ENABLE, PORT_PLL_ENABLE); |
| 388 | Wait_Set_Mask |
| 389 | (Register => PORT (P).PLL_ENABLE, |
| 390 | Mask => PORT_PLL_ENABLE_LOCK, |
| 391 | TOut_MS => 1); -- 100us |
| 392 | |
| 393 | Read (PORT (P).PCS_DW12_LN01, PCS); |
| 394 | PCS := PCS and not PORT_PCS_LANE_STAGGER_MASK; |
| 395 | PCS := PCS or PORT_PCS_LANE_STAGGER (Clock.Dotclock); |
| 396 | Write (PORT (P).PCS_DW12_GRP, PCS); |
| 397 | end Program_DPLL; |
| 398 | |
| 399 | ---------------------------------------------------------------------------- |
| 400 | |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 401 | procedure Alloc |
| 402 | (Port_Cfg : in Port_Config; |
| 403 | PLL : out T; |
| 404 | Success : out Boolean) |
| 405 | is |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 406 | Clock : Clock_Type := Invalid_Clock; |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 407 | begin |
| 408 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 409 | |
| 410 | case Port_Cfg.Port is |
| 411 | when DIGI_A => PLL := DPLL_A; |
| 412 | when DIGI_B => PLL := DPLL_B; |
| 413 | when DIGI_C => PLL := DPLL_C; |
| 414 | when others => PLL := Invalid_PLL; |
| 415 | end case; |
| 416 | |
| 417 | Success := PLL /= Invalid_PLL; |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 418 | |
| 419 | if Success then |
| 420 | case Port_Cfg.Display is |
| 421 | when DP => |
| 422 | Success := True; |
| 423 | -- we use static values for DP |
| 424 | case Port_Cfg.DP.Bandwidth is |
| 425 | when DP_Bandwidth_1_62 => |
| 426 | Clock.M2 := 32 * 2 ** 22 + 1677722; |
| 427 | Clock.P1 := 4; |
| 428 | Clock.P2 := 2; |
| 429 | Clock.VCO := 6_480_000_019; |
| 430 | Clock.Dotclock := 162_000_000; |
| 431 | when DP_Bandwidth_2_7 => |
| 432 | Clock.M2 := 27 * 2 ** 22; |
| 433 | Clock.P1 := 4; |
| 434 | Clock.P2 := 1; |
| 435 | Clock.VCO := 5_400_000_000; |
| 436 | Clock.Dotclock := 270_000_000; |
| 437 | when DP_Bandwidth_5_4 => |
| 438 | Clock.M2 := 27 * 2 ** 22; |
| 439 | Clock.P1 := 2; |
| 440 | Clock.P2 := 1; |
| 441 | Clock.VCO := 5_400_000_000; |
| 442 | Clock.Dotclock := 540_000_000; |
| 443 | end case; |
| 444 | when HDMI => |
| 445 | if Port_Cfg.Mode.Dotclock in HDMI_Clock_Range and |
| 446 | (Port_Cfg.Mode.Dotclock * 99 / 100 < Clock_Gap'First or |
| 447 | Port_Cfg.Mode.Dotclock * 101 / 100 > Clock_Gap'Last) |
| 448 | then |
| 449 | Calculate_Clock_Parameters |
| 450 | (Target_Dotclock => Port_Cfg.Mode.Dotclock, |
| 451 | Best_Clock => Clock, |
| 452 | Valid => Success); |
| 453 | else |
| 454 | Success := False; |
| 455 | pragma Debug (Debug.Put_Line |
| 456 | ("Mode's dotclock is out of range.")); |
| 457 | end if; |
| 458 | when others => |
| 459 | Success := False; |
| 460 | pragma Debug (Debug.Put_Line ("Invalid display type!")); |
| 461 | end case; |
| 462 | end if; |
| 463 | |
| 464 | if Success then |
| Nico Huber | afadcac | 2017-02-08 13:41:38 +0100 | [diff] [blame] | 465 | DDI_Phy.Pre_PLL (Port_Cfg); |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 466 | Program_DPLL (PLL, Clock); |
| 467 | end if; |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 468 | end Alloc; |
| 469 | |
| 470 | procedure Free (PLL : T) is |
| 471 | begin |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 472 | if PLL in Valid_PLLs then |
| 473 | Unset_Mask (PORT (PLL).PLL_ENABLE, PORT_PLL_ENABLE); |
| 474 | end if; |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 475 | end Free; |
| 476 | |
| 477 | procedure All_Off is |
| 478 | begin |
| 479 | pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity)); |
| 480 | |
| Nico Huber | 4b0239f | 2017-02-07 18:26:51 +0100 | [diff] [blame] | 481 | for PLL in Valid_PLLs loop |
| 482 | Free (PLL); |
| 483 | end loop; |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 484 | end All_Off; |
| 485 | |
| Nico Huber | 21da574 | 2017-01-20 14:00:53 +0100 | [diff] [blame] | 486 | end HW.GFX.GMA.PLLs; |