| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 1 | -- |
| 2 | -- Copyright (C) 2015 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 Huber | 125a29e | 2016-10-18 00:23:54 +0200 | [diff] [blame] | 6 | -- the Free Software Foundation; either version 2 of the License, or |
| 7 | -- (at your option) any later version. |
| Nico Huber | 83693c8 | 2016-10-08 22:17:55 +0200 | [diff] [blame] | 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.GFX.GMA.Registers; |
| 16 | |
| 17 | package body HW.GFX.GMA.PCH.Sideband is |
| 18 | |
| 19 | SBI_CTL_DEST_ICLK : constant := 0 * 2 ** 16; |
| 20 | SBI_CTL_DEST_MPHY : constant := 1 * 2 ** 16; |
| 21 | SBI_CTL_OP_IORD : constant := 2 * 2 ** 8; |
| 22 | SBI_CTL_OP_IOWR : constant := 3 * 2 ** 8; |
| 23 | SBI_CTL_OP_CRRD : constant := 6 * 2 ** 8; |
| 24 | SBI_CTL_OP_CRWR : constant := 7 * 2 ** 8; |
| 25 | |
| 26 | SBI_RESPONSE_FAIL : constant := 1 * 2 ** 1; |
| 27 | SBI_BUSY : constant := 1 * 2 ** 0; |
| 28 | |
| 29 | type Register_Array is array (Register_Type) of Word32; |
| 30 | Register_Addr : constant Register_Array := Register_Array' |
| 31 | (SBI_SSCDIVINTPHASE6 => 16#0600_0000#, |
| 32 | SBI_SSCCTL6 => 16#060c_0000#, |
| 33 | SBI_SSCAUXDIV => 16#0610_0000#); |
| 34 | |
| 35 | ---------------------------------------------------------------------------- |
| 36 | |
| 37 | procedure Read |
| 38 | (Dest : in Destination_Type; |
| 39 | Register : in Register_Type; |
| 40 | Value : out Word32) |
| 41 | is |
| 42 | begin |
| 43 | Registers.Wait_Unset_Mask |
| 44 | (Register => Registers.SBI_CTL_STAT, |
| 45 | Mask => SBI_BUSY); |
| 46 | |
| 47 | Registers.Write |
| 48 | (Register => Registers.SBI_ADDR, |
| 49 | Value => Register_Addr (Register)); |
| 50 | |
| 51 | if Dest = SBI_ICLK then |
| 52 | Registers.Write |
| 53 | (Register => Registers.SBI_CTL_STAT, |
| 54 | Value => SBI_CTL_DEST_ICLK or SBI_CTL_OP_CRRD or SBI_BUSY); |
| 55 | else |
| 56 | Registers.Write |
| 57 | (Register => Registers.SBI_CTL_STAT, |
| 58 | Value => SBI_CTL_DEST_MPHY or SBI_CTL_OP_IORD or SBI_BUSY); |
| 59 | end if; |
| 60 | |
| 61 | Registers.Wait_Unset_Mask |
| 62 | (Register => Registers.SBI_CTL_STAT, |
| 63 | Mask => SBI_BUSY); |
| 64 | |
| 65 | Registers.Read |
| 66 | (Register => Registers.SBI_DATA, |
| 67 | Value => Value); |
| 68 | end Read; |
| 69 | |
| 70 | procedure Write |
| 71 | (Dest : in Destination_Type; |
| 72 | Register : in Register_Type; |
| 73 | Value : in Word32) |
| 74 | is |
| 75 | begin |
| 76 | Registers.Wait_Unset_Mask |
| 77 | (Register => Registers.SBI_CTL_STAT, |
| 78 | Mask => SBI_BUSY); |
| 79 | |
| 80 | Registers.Write |
| 81 | (Register => Registers.SBI_ADDR, |
| 82 | Value => Register_Addr (Register)); |
| 83 | Registers.Write |
| 84 | (Register => Registers.SBI_DATA, |
| 85 | Value => Value); |
| 86 | |
| 87 | if Dest = SBI_ICLK then |
| 88 | Registers.Write |
| 89 | (Register => Registers.SBI_CTL_STAT, |
| 90 | Value => SBI_CTL_DEST_ICLK or SBI_CTL_OP_CRWR or SBI_BUSY); |
| 91 | else |
| 92 | Registers.Write |
| 93 | (Register => Registers.SBI_CTL_STAT, |
| 94 | Value => SBI_CTL_DEST_MPHY or SBI_CTL_OP_IOWR or SBI_BUSY); |
| 95 | end if; |
| 96 | |
| 97 | Registers.Wait_Unset_Mask |
| 98 | (Register => Registers.SBI_CTL_STAT, |
| 99 | Mask => SBI_BUSY); |
| 100 | end Write; |
| 101 | |
| 102 | ---------------------------------------------------------------------------- |
| 103 | |
| 104 | procedure Unset_Mask |
| 105 | (Dest : in Destination_Type; |
| 106 | Register : in Register_Type; |
| 107 | Mask : in Word32) |
| 108 | is |
| 109 | Value : Word32; |
| 110 | begin |
| 111 | Read (Dest, Register, Value); |
| 112 | Write (Dest, Register, Value and not Mask); |
| 113 | end Unset_Mask; |
| 114 | |
| 115 | procedure Set_Mask |
| 116 | (Dest : in Destination_Type; |
| 117 | Register : in Register_Type; |
| 118 | Mask : in Word32) |
| 119 | is |
| 120 | Value : Word32; |
| 121 | begin |
| 122 | Read (Dest, Register, Value); |
| 123 | Write (Dest, Register, Value or Mask); |
| 124 | end Set_Mask; |
| 125 | |
| 126 | procedure Unset_And_Set_Mask |
| 127 | (Dest : in Destination_Type; |
| 128 | Register : in Register_Type; |
| 129 | Mask_Unset : in Word32; |
| 130 | Mask_Set : in Word32) |
| 131 | is |
| 132 | Value : Word32; |
| 133 | begin |
| 134 | Read (Dest, Register, Value); |
| 135 | Write (Dest, Register, (Value and not Mask_Unset) or Mask_Set); |
| 136 | end Unset_And_Set_Mask; |
| 137 | |
| 138 | end HW.GFX.GMA.PCH.Sideband; |