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