]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressSysConfigLib/ArmVExpressSysConfig.c
ArmPlatformPkg/ArmPlatformSysConfigLib: Add function 'ArmPlatformSysConfigGetValues'
[mirror_edk2.git] / ArmPlatformPkg / ArmVExpressPkg / Library / ArmVExpressSysConfigLib / ArmVExpressSysConfig.c
CommitLineData
7b80d1a3 1/** @file SysCfgArmVExpress.c\r
2\r
3 Copyright (c) 2011, ARM Ltd. All rights reserved.<BR>\r
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include <PiDxe.h>\r
15#include <Library/IoLib.h>\r
16#include <Library/DebugLib.h>\r
17\r
18#include <Library/ArmPlatformSysConfigLib.h>\r
19#include <ArmPlatform.h>\r
20\r
21//\r
22// SYS_CFGCTRL Bits\r
23//\r
24#define SYS_CFGCTRL_START BIT31\r
25#define SYS_CFGCTRL_READ (0 << 30)\r
26#define SYS_CFGCTRL_WRITE (1 << 30)\r
27#define SYS_CFGCTRL_FUNCTION(fun) (((fun ) & 0x3F) << 20)\r
28#define SYS_CFGCTRL_SITE(site) (((site) & 0x3) << 16)\r
29#define SYS_CFGCTRL_POSITION(pos) (((pos ) & 0xF) << 12)\r
30#define SYS_CFGCTRL_DEVICE(dev) ((dev ) & 0xFFF)\r
31\r
32//\r
33// SYS_CFGSTAT Bits\r
34//\r
35#define SYS_CFGSTAT_ERROR BIT1\r
36#define SYS_CFGSTAT_COMPLETE BIT0\r
37\r
38/****************************************************************************\r
39 *\r
40 * This file makes it easier to access the System Configuration Registers\r
41 * in the ARM Versatile Express motherboard.\r
42 *\r
43 ****************************************************************************/\r
44\r
45EFI_STATUS\r
46ArmPlatformSysConfigInitialize (\r
47 VOID\r
48 )\r
49{\r
50 return EFI_SUCCESS;\r
51}\r
52\r
53/***************************************\r
54 * GENERAL FUNCTION: AccessSysCfgRegister\r
55 * Interacts with\r
56 * SYS_CFGSTAT\r
57 * SYS_CFGDATA\r
58 * SYS_CFGCTRL\r
59 * for setting and for reading out values\r
60 ***************************************/\r
61\r
62EFI_STATUS\r
63AccessSysCfgRegister (\r
64 IN UINT32 ReadWrite,\r
65 IN UINT32 Function,\r
66 IN UINT32 Site,\r
67 IN UINT32 Position,\r
68 IN UINT32 Device,\r
69 IN OUT UINT32* Data\r
70 )\r
71{\r
72 UINT32 SysCfgCtrl;\r
73\r
74 // Clear the COMPLETE bit\r
75 MmioAnd32(ARM_VE_SYS_CFGSTAT_REG, ~SYS_CFGSTAT_COMPLETE);\r
76\r
77 // If writing, then set the data value\r
78 if(ReadWrite == SYS_CFGCTRL_WRITE) {\r
79 MmioWrite32(ARM_VE_SYS_CFGDATA_REG, *Data);\r
80 }\r
81\r
82 // Set the control value\r
83 SysCfgCtrl = SYS_CFGCTRL_START | ReadWrite | SYS_CFGCTRL_FUNCTION(Function) | SYS_CFGCTRL_SITE(Site) |\r
84 SYS_CFGCTRL_POSITION(Position) | SYS_CFGCTRL_DEVICE(Device);\r
85 MmioWrite32(ARM_VE_SYS_CFGCTRL_REG, SysCfgCtrl);\r
86\r
87 // Wait until the COMPLETE bit is set\r
88 while ((MmioRead32(ARM_VE_SYS_CFGSTAT_REG) & SYS_CFGSTAT_COMPLETE) == 0);\r
89\r
90 // Check for errors\r
91 if(MmioRead32(ARM_VE_SYS_CFGSTAT_REG) & SYS_CFGSTAT_ERROR) {\r
92 return EFI_DEVICE_ERROR;\r
93 }\r
94\r
95 // If reading then get the data value\r
96 if(ReadWrite == SYS_CFGCTRL_READ) {\r
97 *Data = MmioRead32(ARM_VE_SYS_CFGDATA_REG);\r
98 }\r
99\r
100 return EFI_SUCCESS;\r
101}\r
102\r
103EFI_STATUS\r
104ArmPlatformSysConfigGet (\r
105 IN SYS_CONFIG_FUNCTION Function,\r
106 OUT UINT32* Value\r
107 )\r
108{\r
109 UINT32 Site;\r
110 UINT32 Position;\r
111 UINT32 Device;\r
112\r
113 Position = 0;\r
114 Device = 0;\r
115\r
116 // Intercept some functions\r
117 switch(Function) {\r
118\r
119 case SYS_CFG_OSC_SITE1:\r
120 Function = SYS_CFG_OSC;\r
121 Site = ARM_VE_DAUGHTERBOARD_1_SITE;\r
122 break;\r
123\r
124 case SYS_CFG_OSC_SITE2:\r
125 Function = SYS_CFG_OSC;\r
126 Site = ARM_VE_DAUGHTERBOARD_2_SITE;\r
127 break;\r
128\r
129 case SYS_CFG_MUXFPGA:\r
130 Site = *Value;\r
131 break;\r
132\r
133 case SYS_CFG_OSC:\r
134 case SYS_CFG_VOLT:\r
135 case SYS_CFG_AMP:\r
136 case SYS_CFG_TEMP:\r
137 case SYS_CFG_RESET:\r
138 case SYS_CFG_SCC:\r
139 case SYS_CFG_DVIMODE:\r
140 case SYS_CFG_POWER:\r
141 Site = ARM_VE_MOTHERBOARD_SITE;\r
142 break;\r
143\r
144 case SYS_CFG_SHUTDOWN:\r
145 case SYS_CFG_REBOOT:\r
146 case SYS_CFG_RTC:\r
147 default:\r
148 return EFI_UNSUPPORTED;\r
149 }\r
150\r
151 return AccessSysCfgRegister (SYS_CFGCTRL_READ, Function, Site, Position, Device, Value);\r
152}\r
153\r
911da886 154EFI_STATUS\r
155ArmPlatformSysConfigGetValues (\r
156 IN SYS_CONFIG_FUNCTION Function,\r
157 IN UINTN Size,\r
158 OUT UINT32* Values\r
159 )\r
160{\r
161 return EFI_UNSUPPORTED;\r
162}\r
163\r
7b80d1a3 164EFI_STATUS\r
165ArmPlatformSysConfigSet (\r
166 IN SYS_CONFIG_FUNCTION Function,\r
167 IN UINT32 Value\r
168 )\r
169{\r
170 UINT32 Site;\r
171 UINT32 Position;\r
172 UINT32 Device;\r
173\r
174 Position = 0;\r
175 Device = 0;\r
176\r
177 // Intercept some functions\r
178 switch(Function) {\r
179\r
180 case SYS_CFG_OSC_SITE1:\r
181 Function = SYS_CFG_OSC;\r
182 Site = ARM_VE_DAUGHTERBOARD_1_SITE;\r
183 break;\r
184\r
185 case SYS_CFG_OSC_SITE2:\r
186 Function = SYS_CFG_OSC;\r
187 Site = ARM_VE_DAUGHTERBOARD_2_SITE;\r
188 break;\r
189\r
190 case SYS_CFG_MUXFPGA:\r
191 Site = Value;\r
192 break;\r
193\r
194 case SYS_CFG_RESET:\r
195 case SYS_CFG_SCC:\r
196 case SYS_CFG_SHUTDOWN:\r
197 case SYS_CFG_REBOOT:\r
198 case SYS_CFG_DVIMODE:\r
199 case SYS_CFG_POWER:\r
200 Site = ARM_VE_MOTHERBOARD_SITE;\r
201 break;\r
202\r
203 case SYS_CFG_OSC:\r
204 case SYS_CFG_VOLT:\r
205 case SYS_CFG_AMP:\r
206 case SYS_CFG_TEMP:\r
207 case SYS_CFG_RTC:\r
208 default:\r
209 return(EFI_UNSUPPORTED);\r
210 }\r
211\r
212 return AccessSysCfgRegister (SYS_CFGCTRL_WRITE, Function, Site, Position, Device, &Value);\r
213}\r
214\r
215EFI_STATUS\r
216ArmPlatformSysConfigSetDevice (\r
217 IN SYS_CONFIG_FUNCTION Function,\r
218 IN UINT32 Device,\r
219 IN UINT32 Value\r
220 )\r
221{\r
222 UINT32 Site;\r
223 UINT32 Position;\r
224\r
225 Position = 0;\r
226\r
227 // Intercept some functions\r
228 switch(Function) {\r
4463f706 229 case SYS_CFG_SCC:\r
a79803d7 230#ifdef ARM_VE_SCC_BASE\r
4463f706 231 MmioWrite32 ((ARM_VE_SCC_BASE + (Device * 4)),Value);\r
232 return EFI_SUCCESS;\r
a79803d7 233#else\r
234 // There is no System Configuration Controller on the Model\r
235 return EFI_UNSUPPORTED;\r
236#endif\r
7b80d1a3 237\r
238 case SYS_CFG_OSC_SITE1:\r
239 Function = SYS_CFG_OSC;\r
240 Site = ARM_VE_DAUGHTERBOARD_1_SITE;\r
241 break;\r
242\r
243 case SYS_CFG_OSC_SITE2:\r
244 Function = SYS_CFG_OSC;\r
245 Site = ARM_VE_DAUGHTERBOARD_2_SITE;\r
246 break;\r
247\r
248 case SYS_CFG_MUXFPGA:\r
249 Site = Value;\r
250 break;\r
251\r
252 case SYS_CFG_RTC:\r
253 return(EFI_UNSUPPORTED);\r
254 //break;\r
255\r
256 case SYS_CFG_OSC:\r
257 case SYS_CFG_VOLT:\r
258 case SYS_CFG_AMP:\r
259 case SYS_CFG_TEMP:\r
260 case SYS_CFG_RESET:\r
7b80d1a3 261 case SYS_CFG_SHUTDOWN:\r
262 case SYS_CFG_REBOOT:\r
263 case SYS_CFG_DVIMODE:\r
264 case SYS_CFG_POWER:\r
265 Site = ARM_VE_MOTHERBOARD_SITE;\r
266 break;\r
267 default:\r
268 return EFI_UNSUPPORTED;\r
269 }\r
270\r
271 return AccessSysCfgRegister (SYS_CFGCTRL_WRITE, Function, Site, Position, Device, &Value);\r
272}\r