blob: 41126bfc9408250396e884cd007292ea3119956d [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
Nico Huber125a29e2016-10-18 00:23:54 +02006-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02008--
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.Registers;
16
17package 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'
Angel Pons450c24c2020-05-13 00:49:52 +020031 (SBI_SSCDIVINTPHASE => 16#0200_0000#,
32 SBI_SSCDITHPHASE => 16#0204_0000#,
33 SBI_SSCCTL => 16#020c_0000#,
34 SBI_SSCDIVINTPHASE6 => 16#0600_0000#,
Nico Huber83693c82016-10-08 22:17:55 +020035 SBI_SSCCTL6 => 16#060c_0000#,
Angel Pons450c24c2020-05-13 00:49:52 +020036 SBI_SSCAUXDIV => 16#0610_0000#,
37 SBI_GEN0 => 16#1f00_0000#,
38 SBI_DBUFF0 => 16#2a00_0000#,
39
40 SBI_MPHY_2008 => 16#2008_0000#,
41 SBI_MPHY_206C => 16#206c_0000#,
42 SBI_MPHY_2080 => 16#2080_0000#,
43 SBI_MPHY_208C => 16#208c_0000#,
44 SBI_MPHY_2098 => 16#2098_0000#,
45 SBI_MPHY_20C4 => 16#20c4_0000#,
46 SBI_MPHY_20EC => 16#20ec_0000#,
47 SBI_MPHY_2108 => 16#2108_0000#,
48 SBI_MPHY_216C => 16#216c_0000#,
49 SBI_MPHY_2180 => 16#2180_0000#,
50 SBI_MPHY_218C => 16#218c_0000#,
51 SBI_MPHY_2198 => 16#2198_0000#,
52 SBI_MPHY_21C4 => 16#21c4_0000#,
53 SBI_MPHY_21EC => 16#21ec_0000#,
54 SBI_MPHY_8008 => 16#8008_0000#);
Nico Huber83693c82016-10-08 22:17:55 +020055
56 ----------------------------------------------------------------------------
57
58 procedure Read
59 (Dest : in Destination_Type;
60 Register : in Register_Type;
61 Value : out Word32)
62 is
63 begin
64 Registers.Wait_Unset_Mask
65 (Register => Registers.SBI_CTL_STAT,
66 Mask => SBI_BUSY);
67
68 Registers.Write
69 (Register => Registers.SBI_ADDR,
70 Value => Register_Addr (Register));
71
72 if Dest = SBI_ICLK then
73 Registers.Write
74 (Register => Registers.SBI_CTL_STAT,
75 Value => SBI_CTL_DEST_ICLK or SBI_CTL_OP_CRRD or SBI_BUSY);
76 else
77 Registers.Write
78 (Register => Registers.SBI_CTL_STAT,
79 Value => SBI_CTL_DEST_MPHY or SBI_CTL_OP_IORD or SBI_BUSY);
80 end if;
81
82 Registers.Wait_Unset_Mask
83 (Register => Registers.SBI_CTL_STAT,
84 Mask => SBI_BUSY);
85
86 Registers.Read
87 (Register => Registers.SBI_DATA,
88 Value => Value);
89 end Read;
90
91 procedure Write
92 (Dest : in Destination_Type;
93 Register : in Register_Type;
94 Value : in Word32)
95 is
96 begin
97 Registers.Wait_Unset_Mask
98 (Register => Registers.SBI_CTL_STAT,
99 Mask => SBI_BUSY);
100
101 Registers.Write
102 (Register => Registers.SBI_ADDR,
103 Value => Register_Addr (Register));
104 Registers.Write
105 (Register => Registers.SBI_DATA,
106 Value => Value);
107
108 if Dest = SBI_ICLK then
109 Registers.Write
110 (Register => Registers.SBI_CTL_STAT,
111 Value => SBI_CTL_DEST_ICLK or SBI_CTL_OP_CRWR or SBI_BUSY);
112 else
113 Registers.Write
114 (Register => Registers.SBI_CTL_STAT,
115 Value => SBI_CTL_DEST_MPHY or SBI_CTL_OP_IOWR or SBI_BUSY);
116 end if;
117
118 Registers.Wait_Unset_Mask
119 (Register => Registers.SBI_CTL_STAT,
120 Mask => SBI_BUSY);
121 end Write;
122
123 ----------------------------------------------------------------------------
124
125 procedure Unset_Mask
126 (Dest : in Destination_Type;
127 Register : in Register_Type;
128 Mask : in Word32)
129 is
130 Value : Word32;
131 begin
132 Read (Dest, Register, Value);
133 Write (Dest, Register, Value and not Mask);
134 end Unset_Mask;
135
136 procedure Set_Mask
137 (Dest : in Destination_Type;
138 Register : in Register_Type;
139 Mask : in Word32)
140 is
141 Value : Word32;
142 begin
143 Read (Dest, Register, Value);
144 Write (Dest, Register, Value or Mask);
145 end Set_Mask;
146
147 procedure Unset_And_Set_Mask
148 (Dest : in Destination_Type;
149 Register : in Register_Type;
150 Mask_Unset : in Word32;
151 Mask_Set : in Word32)
152 is
153 Value : Word32;
154 begin
155 Read (Dest, Register, Value);
156 Write (Dest, Register, (Value and not Mask_Unset) or Mask_Set);
157 end Unset_And_Set_Mask;
158
159end HW.GFX.GMA.PCH.Sideband;