]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/PcatRealTimeClockRuntimeDxe/PcRtc.h
Code Scrub for ConPlatform.
[mirror_edk2.git] / MdeModulePkg / Universal / PcatRealTimeClockRuntimeDxe / PcRtc.h
CommitLineData
fb0b259e 1/** @file\r
2 Header file for real time clock driver.\r
8cd4d17c 3\r
fb0b259e 4Copyright (c) 2006 - 2007, Intel Corporation\r
3cfb790c 5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
8cd4d17c 12\r
fb0b259e 13**/\r
8cd4d17c 14\r
8cd4d17c 15\r
16#ifndef _RTC_H_\r
17#define _RTC_H_\r
18\r
ed7748fe 19\r
60c93673 20#include <Uefi.h>\r
ed7748fe 21\r
8cd4d17c 22#include <Protocol/RealTimeClock.h>\r
ec35e997 23#include <Guid/GenericPlatformVariable.h>\r
ed7748fe 24\r
8cd4d17c 25#include <Library/BaseLib.h>\r
26#include <Library/DebugLib.h>\r
27#include <Library/UefiLib.h>\r
28#include <Library/BaseMemoryLib.h>\r
29#include <Library/IoLib.h>\r
30#include <Library/TimerLib.h>\r
31#include <Library/UefiDriverEntryPoint.h>\r
32#include <Library/UefiBootServicesTableLib.h>\r
33#include <Library/UefiRuntimeLib.h>\r
34#include <Library/UefiRuntimeServicesTableLib.h>\r
835e5a5f 35#include <Library/PcdLib.h>\r
8cd4d17c 36\r
37\r
38typedef struct {\r
39 EFI_LOCK RtcLock;\r
ec35e997 40 INT16 SavedTimeZone;\r
8cd4d17c 41 UINT8 Daylight;\r
42} PC_RTC_MODULE_GLOBALS;\r
43\r
44#define PCAT_RTC_ADDRESS_REGISTER 0x70\r
45#define PCAT_RTC_DATA_REGISTER 0x71\r
46\r
47//\r
48// Dallas DS12C887 Real Time Clock\r
49//\r
50#define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59\r
51#define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59\r
52#define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59\r
53#define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59\r
54#define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
55#define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
56#define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7\r
57#define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31\r
58#define RTC_ADDRESS_MONTH 8 // R/W Range 1..12\r
59#define RTC_ADDRESS_YEAR 9 // R/W Range 0..99\r
60#define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7]\r
61#define RTC_ADDRESS_REGISTER_B 11 // R/W\r
62#define RTC_ADDRESS_REGISTER_C 12 // RO\r
63#define RTC_ADDRESS_REGISTER_D 13 // RO\r
64#define RTC_ADDRESS_CENTURY 50 // R/W Range 19..20 Bit 8 is R/W\r
65//\r
66// Date and time initial values.\r
67// They are used if the RTC values are invalid during driver initialization\r
68//\r
69#define RTC_INIT_SECOND 0\r
70#define RTC_INIT_MINUTE 0\r
71#define RTC_INIT_HOUR 0\r
72#define RTC_INIT_DAY 1\r
73#define RTC_INIT_MONTH 1\r
74#define RTC_INIT_YEAR 2001\r
75\r
76//\r
77// Register initial values\r
78//\r
79#define RTC_INIT_REGISTER_A 0x26\r
80#define RTC_INIT_REGISTER_B 0x02\r
81#define RTC_INIT_REGISTER_D 0x0\r
82\r
83#pragma pack(1)\r
84//\r
85// Register A\r
86//\r
87typedef struct {\r
88 UINT8 RS : 4; // Rate Selection Bits\r
89 UINT8 DV : 3; // Divisor\r
90 UINT8 UIP : 1; // Update in progress\r
91} RTC_REGISTER_A_BITS;\r
92\r
93typedef union {\r
94 RTC_REGISTER_A_BITS Bits;\r
95 UINT8 Data;\r
96} RTC_REGISTER_A;\r
97\r
98//\r
99// Register B\r
100//\r
101typedef struct {\r
102 UINT8 DSE : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled\r
103 UINT8 MIL : 1; // 0 - 12 hour mode 1 - 24 hour mode\r
104 UINT8 DM : 1; // 0 - BCD Format 1 - Binary Format\r
105 UINT8 SQWE : 1; // 0 - Disable SQWE output 1 - Enable SQWE output\r
106 UINT8 UIE : 1; // 0 - Update INT disabled 1 - Update INT enabled\r
107 UINT8 AIE : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled\r
108 UINT8 PIE : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled\r
109 UINT8 SET : 1; // 0 - Normal operation. 1 - Updates inhibited\r
110} RTC_REGISTER_B_BITS;\r
111\r
112typedef union {\r
113 RTC_REGISTER_B_BITS Bits;\r
114 UINT8 Data;\r
115} RTC_REGISTER_B;\r
116\r
117//\r
118// Register C\r
119//\r
120typedef struct {\r
121 UINT8 Reserved : 4; // Read as zero. Can not be written.\r
122 UINT8 UF : 1; // Update End Interrupt Flag\r
123 UINT8 AF : 1; // Alarm Interrupt Flag\r
124 UINT8 PF : 1; // Periodic Interrupt Flag\r
125 UINT8 IRQF : 1; // Iterrupt Request Flag = PF & PIE | AF & AIE | UF & UIE\r
126} RTC_REGISTER_C_BITS;\r
127\r
128typedef union {\r
129 RTC_REGISTER_C_BITS Bits;\r
130 UINT8 Data;\r
131} RTC_REGISTER_C;\r
132\r
133//\r
134// Register D\r
135//\r
136typedef struct {\r
137 UINT8 Reserved : 7; // Read as zero. Can not be written.\r
138 UINT8 VRT : 1; // Valid RAM and Time\r
139} RTC_REGISTER_D_BITS;\r
140\r
141typedef union {\r
142 RTC_REGISTER_D_BITS Bits;\r
143 UINT8 Data;\r
144} RTC_REGISTER_D;\r
145\r
146#pragma pack()\r
147\r
148EFI_STATUS\r
149PcRtcInit (\r
150 IN PC_RTC_MODULE_GLOBALS *Global\r
151 )\r
152/*++\r
153\r
154Routine Description:\r
155\r
156 GC_TODO: Add function description\r
157\r
158Arguments:\r
159\r
160 Global - GC_TODO: add argument description\r
161\r
162Returns:\r
163\r
164 GC_TODO: add return values\r
165\r
166--*/\r
167;\r
168\r
169EFI_STATUS\r
170PcRtcSetTime (\r
171 IN EFI_TIME *Time,\r
172 IN PC_RTC_MODULE_GLOBALS *Global\r
173 )\r
174/*++\r
175\r
176Routine Description:\r
177\r
178 GC_TODO: Add function description\r
179\r
180Arguments:\r
181\r
182 Time - GC_TODO: add argument description\r
183 Global - GC_TODO: add argument description\r
184\r
185Returns:\r
186\r
187 GC_TODO: add return values\r
188\r
189--*/\r
190;\r
191\r
192EFI_STATUS\r
193PcRtcGetTime (\r
194 OUT EFI_TIME *Time,\r
195 IN EFI_TIME_CAPABILITIES *Capabilities,\r
196 IN PC_RTC_MODULE_GLOBALS *Global\r
197 )\r
198/*++\r
199\r
200Routine Description:\r
201\r
202 GC_TODO: Add function description\r
203\r
204Arguments:\r
205\r
206 Time - GC_TODO: add argument description\r
207 Capabilities - GC_TODO: add argument description\r
208 Global - GC_TODO: add argument description\r
209\r
210Returns:\r
211\r
212 GC_TODO: add return values\r
213\r
214--*/\r
215;\r
216\r
217EFI_STATUS\r
218PcRtcSetWakeupTime (\r
219 IN BOOLEAN Enable,\r
220 OUT EFI_TIME *Time,\r
221 IN PC_RTC_MODULE_GLOBALS *Global\r
222 )\r
223/*++\r
224\r
225Routine Description:\r
226\r
227 GC_TODO: Add function description\r
228\r
229Arguments:\r
230\r
231 Enable - GC_TODO: add argument description\r
232 Time - GC_TODO: add argument description\r
233 Global - GC_TODO: add argument description\r
234\r
235Returns:\r
236\r
237 GC_TODO: add return values\r
238\r
239--*/\r
240;\r
241\r
242EFI_STATUS\r
243PcRtcGetWakeupTime (\r
244 OUT BOOLEAN *Enabled,\r
245 OUT BOOLEAN *Pending,\r
246 OUT EFI_TIME *Time,\r
247 IN PC_RTC_MODULE_GLOBALS *Global\r
248 )\r
249/*++\r
250\r
251Routine Description:\r
252\r
253 GC_TODO: Add function description\r
254\r
255Arguments:\r
256\r
257 Enabled - GC_TODO: add argument description\r
258 Pending - GC_TODO: add argument description\r
259 Time - GC_TODO: add argument description\r
260 Global - GC_TODO: add argument description\r
261\r
262Returns:\r
263\r
264 GC_TODO: add return values\r
265\r
266--*/\r
267;\r
268\r
269EFI_STATUS\r
270EFIAPI\r
271InitializePcRtc (\r
272 IN EFI_HANDLE ImageHandle,\r
273 IN EFI_SYSTEM_TABLE *SystemTable\r
274 )\r
275/*++\r
276\r
277Routine Description:\r
278\r
279 GC_TODO: Add function description\r
280\r
281Arguments:\r
282\r
283 ImageHandle - GC_TODO: add argument description\r
284 SystemTable - GC_TODO: add argument description\r
285\r
286Returns:\r
287\r
288 GC_TODO: add return values\r
289\r
290--*/\r
291;\r
292\r
293UINT8\r
294BcdToDecimal (\r
295 IN UINT8 BcdValue\r
296 )\r
297/*++\r
298\r
299Routine Description:\r
300\r
301 GC_TODO: Add function description\r
302\r
303Arguments:\r
304\r
305 BcdValue - GC_TODO: add argument description\r
306\r
307Returns:\r
308\r
309 GC_TODO: add return values\r
310\r
311--*/\r
312;\r
313\r
314EFI_STATUS\r
315RtcTimeFieldsValid (\r
316 IN EFI_TIME *Time\r
317 )\r
318/*++\r
319\r
320Routine Description:\r
321\r
322 GC_TODO: Add function description\r
323\r
324Arguments:\r
325\r
326 Time - GC_TODO: add argument description\r
327\r
328Returns:\r
329\r
330 GC_TODO: add return values\r
331\r
332--*/\r
333;\r
334\r
335UINT8\r
336DecimaltoBcd (\r
337 IN UINT8 DecValue\r
338 )\r
339/*++\r
340\r
341Routine Description:\r
342\r
343 GC_TODO: Add function description\r
344\r
345Arguments:\r
346\r
347 DecValue - GC_TODO: add argument description\r
348\r
349Returns:\r
350\r
351 GC_TODO: add return values\r
352\r
353--*/\r
354;\r
355\r
356VOID\r
357ConvertEfiTimeToRtcTime (\r
358 IN EFI_TIME *Time,\r
359 IN RTC_REGISTER_B RegisterB,\r
360 IN UINT8 *Century\r
361 )\r
362/*++\r
363\r
364Routine Description:\r
365\r
366 GC_TODO: Add function description\r
367\r
368Arguments:\r
369\r
370 Time - GC_TODO: add argument description\r
371 RegisterB - GC_TODO: add argument description\r
372 Century - GC_TODO: add argument description\r
373\r
374Returns:\r
375\r
376 GC_TODO: add return values\r
377\r
378--*/\r
379;\r
380\r
381EFI_STATUS\r
382RtcTestCenturyRegister (\r
383 VOID\r
384 )\r
385/*++\r
386\r
387Routine Description:\r
388\r
389 GC_TODO: Add function description\r
390\r
391Arguments:\r
392\r
393 None\r
394\r
395Returns:\r
396\r
397 GC_TODO: add return values\r
398\r
399--*/\r
400;\r
401\r
254ba247 402/**\r
403 Converts time read from RTC to EFI_TIME format defined by UEFI spec.\r
8cd4d17c 404\r
254ba247 405 This function converts raw time data read from RTC to the EFI_TIME format\r
406 defined by UEFI spec.\r
407 If data mode of RTC is BCD, then converts it to decimal,\r
408 If RTC is in 12-hour format, then converts it to 24-hour format.\r
8cd4d17c 409\r
254ba247 410 @param Time On input, the time data read from RTC to convert\r
411 On output, the time converted to UEFI format\r
412 @param Century Value of century read from RTC.\r
413 @param RegisterB Value of Register B of RTC, indicating data mode\r
414 and hour format.\r
8cd4d17c 415\r
254ba247 416**/\r
417EFI_STATUS\r
418ConvertRtcTimeToEfiTime (\r
419 IN OUT EFI_TIME *Time,\r
420 IN UINT8 Century,\r
421 IN RTC_REGISTER_B RegisterB\r
ed66e1bc 422 );\r
8cd4d17c 423\r
424EFI_STATUS\r
425RtcWaitToUpdate (\r
426 UINTN Timeout\r
427 )\r
428/*++\r
429\r
430Routine Description:\r
431\r
432 GC_TODO: Add function description\r
433\r
434Arguments:\r
435\r
436 Timeout - GC_TODO: add argument description\r
437\r
438Returns:\r
439\r
440 GC_TODO: add return values\r
441\r
442--*/\r
443;\r
444\r
445UINT8\r
446RtcSaveContext (\r
447 IN PC_RTC_MODULE_GLOBALS *Global\r
448 )\r
449/*++\r
450\r
451Routine Description:\r
452\r
453 GC_TODO: Add function description\r
454\r
455Arguments:\r
456\r
457 Global - GC_TODO: add argument description\r
458\r
459Returns:\r
460\r
461 GC_TODO: add return values\r
462\r
463--*/\r
464;\r
465\r
466VOID\r
467RtcRestoreContext (\r
468 IN UINT8 SavedAddressRegister,\r
469 IN PC_RTC_MODULE_GLOBALS *Global\r
470 )\r
471/*++\r
472\r
473Routine Description:\r
474\r
475 GC_TODO: Add function description\r
476\r
477Arguments:\r
478\r
479 SavedAddressRegister - GC_TODO: add argument description\r
480 Global - GC_TODO: add argument description\r
481\r
482Returns:\r
483\r
484 GC_TODO: add return values\r
485\r
486--*/\r
487;\r
488\r
489BOOLEAN\r
490DayValid (\r
491 IN EFI_TIME *Time\r
492 );\r
493\r
494BOOLEAN\r
495IsLeapYear (\r
496 IN EFI_TIME *Time\r
497 );\r
498\r
499#endif\r