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