]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Platform/Generic/RuntimeDxe/StatusCode/Lib/RtLedStatusCode/RtLedStatusCode.c
Update the copyright notice format
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Platform / Generic / RuntimeDxe / StatusCode / Lib / RtLedStatusCode / RtLedStatusCode.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 RtLedStatusCode.c
15
16 Abstract:
17
18 Lib to provide LED status code reporting Routines.
19
20 In general you should use PPI's, but some times a monolithic driver
21 is better. The best justification for monolithic code is debug.
22
23 --*/
24
25 #include "RtLedStatusCode.h"
26
27 //
28 // Prepare the data to initialize LPC chipset for Server Io Configuration
29 // This is hardcoded init value and would vary from platform to platform.
30 //
31 static SIO_INIT_DATA mSioInitData[] = {
32 //
33 // Program magic values in ServerI/O configuration registers
34 //
35 {
36 REG_SERVERIO_CNF1,
37 0x19
38 },
39 {
40 REG_SERVERIO_CNF2,
41 0x22
42 },
43 {
44 REG_SERVERIO_CNF3,
45 0x76
46 },
47 {
48 REG_SERVERIO_CNF4,
49 0x26
50 },
51 //
52 // Force the parallel port to be disabled, override reg 30 setting
53 //
54 {
55 REG_SERVERIO_CNF6,
56 0x02
57 },
58 //
59 // Select GPIO device and setup GPIO base address
60 //
61 {
62 REG_LOGICAL_DEVICE,
63 SIO_GPIO
64 },
65 {
66 ACTIVATE,
67 LOGICAL_DEVICE_OFF
68 },
69 {
70 BASE_ADDRESS_HIGH,
71 SIO_GPIO_HIGH
72 },
73 {
74 BASE_ADDRESS_LOW,
75 SIO_GPIO_LOW
76 },
77 {
78 ACTIVATE,
79 LOGICAL_DEVICE_ON
80 },
81 //
82 // Select DLED STB, post code LED, ZZ_POST_CLK_LED_L
83 //
84 {
85 GPIO_GPSEL,
86 0x43
87 },
88 //
89 // Push pull output enable
90 //
91 {
92 GPIO_GPCFG1,
93 PUSH_PULL | OUTPUT_BUFFER_EN
94 },
95 //
96 // Disable Event IRQ routing
97 //
98 {
99 GPIO_GPEVR,
100 GPIO_EVENT_OFF
101 },
102 //
103 // Select DLED STB, ZZ_POST_DATA_LED_L
104 //
105 {
106 GPIO_GPSEL,
107 0x54
108 },
109 //
110 // Push pull output enable
111 //
112 {
113 GPIO_GPCFG1,
114 PUSH_PULL | OUTPUT_BUFFER_EN
115 },
116 //
117 // Disable Event IRQ routing
118 //
119 {
120 GPIO_GPEVR,
121 GPIO_EVENT_OFF
122 },
123 //
124 // Select Select ACPI_MODE_IND_L
125 //
126 {
127 GPIO_GPSEL,
128 0x63
129 },
130 //
131 // Push pull output enable
132 //
133 {
134 GPIO_GPCFG1,
135 PUSH_PULL | OUTPUT_BUFFER_EN
136 },
137
138 {
139 0xff,
140 0xff
141 }
142 };
143
144 VOID
145 RtLedInitializeStatusCode (
146 IN EFI_HANDLE ImageHandle,
147 IN EFI_SYSTEM_TABLE *SystemTable
148 )
149 /*++
150
151 Routine Description:
152
153 Initialization routine. Initializes LPC47817 to configure GPIO for LED
154
155 Arguments:
156
157 None
158
159 Returns:
160
161 None
162
163 --*/
164 {
165 UINT8 OutputData;
166 UINT16 ConfigPort;
167 UINT16 DataPort;
168 UINT32 Index;
169
170 //
171 // hard code for sio init
172 //
173 ConfigPort = CONFIG_PORT0;
174 DataPort = DATA_PORT0;
175
176 //
177 // Initialize Sio from table to enable SererIoCfg and GPIO
178 //
179 Index = 0;
180 while ((mSioInitData[Index]).RegAddress != 0xff) {
181 OutputData = (UINT8) mSioInitData[Index].RegAddress;
182
183 IoWrite8 (ConfigPort, OutputData);
184
185 OutputData = (UINT8) mSioInitData[Index].RegValue;
186 IoWrite8 (DataPort, OutputData);
187
188 Index++;
189 }
190
191 return ;
192 }
193
194 BOOLEAN
195 CodeTypeToProgressCode (
196 IN EFI_STATUS_CODE_TYPE CodeType,
197 IN EFI_STATUS_CODE_VALUE Value,
198 OUT UINT8 *PostCode
199 )
200 {
201 //
202 // Convert Value to an 8 bit post code
203 //
204 if (((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE)) {
205 *PostCode = (UINT8) (((Value & EFI_STATUS_CODE_CLASS_MASK) >> 24) << 5);
206 *PostCode = (UINT8) (*PostCode | (UINT8) (((Value & EFI_STATUS_CODE_SUBCLASS_MASK) >> 16) & 0x1f));
207 return TRUE;
208 }
209
210 return FALSE;
211 }
212
213 VOID
214 SendDataToPort (
215 IN UINT8 Data,
216 IN UINT16 DataOffset
217 )
218 /*++
219
220 Routine Description:
221
222 Writes the data to control LED output at desired port
223
224 Arguments:
225
226 Data - Data in bit0 is the relevant data
227 DataOffset - Port address to access GPIO54
228
229 Returns:
230
231 None
232
233 --*/
234 {
235 UINT8 PinData;
236
237 //
238 // Read current Pin State of GPIO54
239 //
240 PinData = IoRead8 (DataOffset);
241
242 //
243 // Set GPIO54 pin to zero
244 //
245 PinData &= 0xEF;
246
247 if (Data & 0x01) {
248 //
249 // Set GPIO54 pin to 1 if data is 1
250 // otherwise it will be set to 0
251 //
252 PinData |= LED_MASK_BIT;
253 }
254
255 IoWrite8 (DataOffset, PinData);
256 }
257
258 VOID
259 StrobeData (
260 IN UINT16 StrobeOffset
261 )
262 /*++
263
264 Routine Description:
265
266 Controls the strobe to move the value from LSB to MSB in steps.
267
268 Arguments:
269
270 StrobeOffset - Port address to access GPIO43. This pin controls the shifting
271 of bit value from LSB to MSB
272
273 Returns:
274
275 None
276
277 --*/
278 {
279 UINT8 StrobeData;
280
281 StrobeData = IoRead8 (StrobeOffset);
282
283 //
284 // Make bit 3 of data to be zero
285 //
286 StrobeData &= 0xF7;
287
288 IoWrite8 (StrobeOffset, StrobeData);
289
290 //
291 // Make bit 3 as 1 to perform the strobe to shift the data in 74HCT164
292 //
293 StrobeData |= STROBE_MASK_BIT;
294
295 IoWrite8 (StrobeOffset, StrobeData);
296 }
297
298 VOID
299 SendDataToLed (
300 UINT8 Data
301 )
302 {
303 UINT16 GpioBase;
304 UINT16 DataOffset;
305 UINT16 StrobeOffset;
306 UINTN Index;
307 UINTN DataBitPosition;
308 UINT8 TempData;
309
310 GpioBase = GPIO_BASE (SIO_GPIO_HIGH, SIO_GPIO_LOW);
311
312 DataOffset = (UINT16) (GpioBase + LED_DATA_OFFSET);
313
314 StrobeOffset = (UINT16) (GpioBase + LED_STROBE_OFFSET);
315
316 DataBitPosition = 7;
317
318 Data = (UINT8) (~Data);
319
320 TempData = Data;
321
322 for (Index = 0; Index < 8; Index++) {
323 SendDataToPort ((UINT8) (TempData >> DataBitPosition), DataOffset);
324 StrobeData (StrobeOffset);
325 DataBitPosition--;
326 }
327 //
328 // To fix 5 Volt leakage problem
329 //
330 SendDataToPort (0, DataOffset);
331
332 }
333
334 EFI_STATUS
335 RtLedReportStatusCode (
336 IN EFI_STATUS_CODE_TYPE CodeType,
337 IN EFI_STATUS_CODE_VALUE Value,
338 IN UINT32 Instance,
339 IN EFI_GUID * CallerId,
340 IN EFI_STATUS_CODE_DATA * Data OPTIONAL
341 )
342 /*++
343
344 Routine Description:
345
346 Provide a LED status code
347
348 Arguments:
349
350 Same as ReportStatusCode PPI
351
352 Returns:
353
354 Status - EFI_SUCCESS if the interface could be successfully
355 installed
356
357 --*/
358 {
359 UINT8 ProgressCode;
360
361 if (CodeTypeToProgressCode (CodeType, Value, &ProgressCode)) {
362 SendDataToLed (ProgressCode);
363 }
364
365 return EFI_SUCCESS;
366 }