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