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