]>
Commit | Line | Data |
---|---|---|
fb0b259e | 1 | /** @file\r |
2 | Header file for real time clock driver.\r | |
8cd4d17c | 3 | \r |
fb0b259e | 4 | Copyright (c) 2006 - 2007, Intel Corporation\r |
3cfb790c | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT 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 | |
38 | typedef 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 | |
87 | typedef 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 | |
93 | typedef 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 | |
101 | typedef 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 | |
112 | typedef 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 | |
120 | typedef 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 | |
128 | typedef 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 | |
136 | typedef 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 | |
141 | typedef 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 | |
8d85dc31 | 148 | /**\r |
149 | Initialize RTC.\r | |
150 | \r | |
151 | @param Global For global use inside this module.\r | |
152 | \r | |
153 | @retval EFI_DEVICE_ERROR Initialization failed due to device error.\r | |
154 | @retval EFI_SUCCESS Initialization successful.\r | |
155 | \r | |
156 | **/\r | |
8cd4d17c | 157 | EFI_STATUS\r |
158 | PcRtcInit (\r | |
159 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
160 | )\r | |
8d85dc31 | 161 | ;\r |
8cd4d17c | 162 | \r |
8d85dc31 | 163 | /**\r |
164 | Sets the current local time and date information.\r | |
8cd4d17c | 165 | \r |
8d85dc31 | 166 | @param Time A pointer to the current time.\r |
167 | @param Global For global use inside this module.\r | |
8cd4d17c | 168 | \r |
8d85dc31 | 169 | @retval EFI_SUCCESS The operation completed successfully.\r |
170 | @retval EFI_INVALID_PARAMETER A time field is out of range.\r | |
171 | @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.\r | |
8cd4d17c | 172 | \r |
8d85dc31 | 173 | **/\r |
8cd4d17c | 174 | EFI_STATUS\r |
175 | PcRtcSetTime (\r | |
176 | IN EFI_TIME *Time,\r | |
177 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
178 | )\r | |
8d85dc31 | 179 | ;\r |
8cd4d17c | 180 | \r |
8d85dc31 | 181 | /**\r |
182 | Returns the current time and date information, and the time-keeping capabilities\r | |
183 | of the hardware platform.\r | |
8cd4d17c | 184 | \r |
8d85dc31 | 185 | @param Time A pointer to storage to receive a snapshot of the current time.\r |
186 | @param Capabilities An optional pointer to a buffer to receive the real time clock\r | |
187 | device's capabilities.\r | |
188 | @param Global For global use inside this module.\r | |
8cd4d17c | 189 | \r |
8d85dc31 | 190 | @retval EFI_SUCCESS The operation completed successfully.\r |
191 | @retval EFI_INVALID_PARAMETER Time is NULL.\r | |
192 | @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.\r | |
8cd4d17c | 193 | \r |
8d85dc31 | 194 | **/\r |
8cd4d17c | 195 | EFI_STATUS\r |
196 | PcRtcGetTime (\r | |
197 | OUT EFI_TIME *Time,\r | |
8d85dc31 | 198 | OUT EFI_TIME_CAPABILITIES *Capabilities, OPTIONAL\r |
8cd4d17c | 199 | IN PC_RTC_MODULE_GLOBALS *Global\r |
200 | )\r | |
8d85dc31 | 201 | ;\r |
8cd4d17c | 202 | \r |
8d85dc31 | 203 | /**\r |
204 | Sets the system wakeup alarm clock time.\r | |
8cd4d17c | 205 | \r |
8d85dc31 | 206 | @param Enabled Enable or disable the wakeup alarm.\r |
207 | @param Time If Enable is TRUE, the time to set the wakeup alarm for.\r | |
208 | If Enable is FALSE, then this parameter is optional, and may be NULL.\r | |
209 | @param Global For global use inside this module.\r | |
8cd4d17c | 210 | \r |
8d85dc31 | 211 | @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.\r |
212 | If Enable is FALSE, then the wakeup alarm was disabled.\r | |
213 | @retval EFI_INVALID_PARAMETER A time field is out of range.\r | |
214 | @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r | |
215 | @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r | |
8cd4d17c | 216 | \r |
8d85dc31 | 217 | **/\r |
8cd4d17c | 218 | EFI_STATUS\r |
219 | PcRtcSetWakeupTime (\r | |
220 | IN BOOLEAN Enable,\r | |
8d85dc31 | 221 | IN EFI_TIME *Time, OPTIONAL\r |
222 | IN PC_RTC_MODULE_GLOBALS *Global\r | |
8cd4d17c | 223 | )\r |
8d85dc31 | 224 | ;\r |
8cd4d17c | 225 | \r |
8d85dc31 | 226 | /**\r |
227 | Returns the current wakeup alarm clock setting.\r | |
8cd4d17c | 228 | \r |
8d85dc31 | 229 | @param Enabled Indicates if the alarm is currently enabled or disabled.\r |
230 | @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r | |
231 | @param Time The current alarm setting.\r | |
232 | @param Global For global use inside this module.\r | |
8cd4d17c | 233 | \r |
8d85dc31 | 234 | @retval EFI_SUCCESS The alarm settings were returned.\r |
235 | @retval EFI_INVALID_PARAMETER Enabled is NULL.\r | |
236 | @retval EFI_INVALID_PARAMETER Pending is NULL.\r | |
237 | @retval EFI_INVALID_PARAMETER Time is NULL.\r | |
238 | @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r | |
239 | @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r | |
8cd4d17c | 240 | \r |
8d85dc31 | 241 | **/\r |
8cd4d17c | 242 | EFI_STATUS\r |
243 | PcRtcGetWakeupTime (\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 | |
8d85dc31 | 249 | ;\r |
8cd4d17c | 250 | \r |
8d85dc31 | 251 | /**\r |
252 | The user Entry Point for PcRTC module.\r | |
8cd4d17c | 253 | \r |
8d85dc31 | 254 | This is the entrhy point for PcRTC module. It installs the UEFI runtime service\r |
255 | including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().\r | |
8cd4d17c | 256 | \r |
8d85dc31 | 257 | @param ImageHandle The firmware allocated handle for the EFI image.\r |
258 | @param SystemTable A pointer to the EFI System Table.\r | |
8cd4d17c | 259 | \r |
8d85dc31 | 260 | @retval EFI_SUCCESS The entry point is executed successfully.\r |
261 | @retval Others Some error occurs when executing this entry point.\r | |
8cd4d17c | 262 | \r |
8d85dc31 | 263 | **/\r |
8cd4d17c | 264 | EFI_STATUS\r |
265 | EFIAPI\r | |
266 | InitializePcRtc (\r | |
267 | IN EFI_HANDLE ImageHandle,\r | |
268 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
269 | )\r | |
8cd4d17c | 270 | ;\r |
271 | \r | |
8d85dc31 | 272 | /**\r |
273 | See if all fields of a variable of EFI_TIME type is correct.\r | |
8cd4d17c | 274 | \r |
8d85dc31 | 275 | @param Time The time to be checked.\r |
8cd4d17c | 276 | \r |
8d85dc31 | 277 | @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.\r |
278 | @retval EFI_SUCCESS Time is a valid EFI_TIME variable.\r | |
8cd4d17c | 279 | \r |
8d85dc31 | 280 | **/\r |
8cd4d17c | 281 | EFI_STATUS\r |
282 | RtcTimeFieldsValid (\r | |
283 | IN EFI_TIME *Time\r | |
284 | )\r | |
8cd4d17c | 285 | ;\r |
286 | \r | |
8d85dc31 | 287 | /**\r |
288 | Converts time from EFI_TIME format defined by UEFI spec to RTC's.\r | |
8cd4d17c | 289 | \r |
8d85dc31 | 290 | This function converts time from EFI_TIME format defined by UEFI spec to RTC's.\r |
291 | If data mode of RTC is BCD, then converts EFI_TIME to it.\r | |
292 | If RTC is in 12-hour format, then converts EFI_TIME to it.\r | |
8cd4d17c | 293 | \r |
8d85dc31 | 294 | @param Time On input, the time data read from UEFI to convert\r |
295 | On output, the time converted to RTC format\r | |
296 | @param RegisterB Value of Register B of RTC, indicating data mode\r | |
297 | @param Century It is set according to EFI_TIME Time.\r | |
8cd4d17c | 298 | \r |
8d85dc31 | 299 | **/\r |
8cd4d17c | 300 | VOID\r |
301 | ConvertEfiTimeToRtcTime (\r | |
8d85dc31 | 302 | IN OUT EFI_TIME *Time,\r |
303 | IN RTC_REGISTER_B RegisterB,\r | |
304 | OUT UINT8 *Century\r | |
8cd4d17c | 305 | )\r |
8cd4d17c | 306 | ;\r |
307 | \r | |
8d85dc31 | 308 | /**\r |
309 | See if centry register of RTC is valid.\r | |
310 | \r | |
311 | @retval EFI_SUCCESS Century register is valid.\r | |
312 | @retval EFI_DEVICE_ERROR Century register is NOT valid.\r | |
313 | **/\r | |
8cd4d17c | 314 | EFI_STATUS\r |
315 | RtcTestCenturyRegister (\r | |
316 | VOID\r | |
317 | )\r | |
8cd4d17c | 318 | ;\r |
319 | \r | |
254ba247 | 320 | /**\r |
321 | Converts time read from RTC to EFI_TIME format defined by UEFI spec.\r | |
8cd4d17c | 322 | \r |
254ba247 | 323 | This function converts raw time data read from RTC to the EFI_TIME format\r |
324 | defined by UEFI spec.\r | |
325 | If data mode of RTC is BCD, then converts it to decimal,\r | |
326 | If RTC is in 12-hour format, then converts it to 24-hour format.\r | |
8cd4d17c | 327 | \r |
254ba247 | 328 | @param Time On input, the time data read from RTC to convert\r |
329 | On output, the time converted to UEFI format\r | |
330 | @param Century Value of century read from RTC.\r | |
331 | @param RegisterB Value of Register B of RTC, indicating data mode\r | |
332 | and hour format.\r | |
8cd4d17c | 333 | \r |
8d85dc31 | 334 | @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.\r |
335 | @retval EFI_SUCCESS Convert RTC time to EFI time successfully.\r | |
336 | \r | |
254ba247 | 337 | **/\r |
338 | EFI_STATUS\r | |
339 | ConvertRtcTimeToEfiTime (\r | |
340 | IN OUT EFI_TIME *Time,\r | |
341 | IN UINT8 Century,\r | |
342 | IN RTC_REGISTER_B RegisterB\r | |
ed66e1bc | 343 | );\r |
8cd4d17c | 344 | \r |
8d85dc31 | 345 | /**\r |
346 | Wait for a period for the RTC to be ready.\r | |
347 | \r | |
348 | @param Timeout Tell how long it should take to wait.\r | |
349 | \r | |
350 | @retval EFI_DEVICE_ERROR RTC device error.\r | |
351 | @retval EFI_SUCCESS RTC is updated and ready. \r | |
352 | **/\r | |
8cd4d17c | 353 | EFI_STATUS\r |
354 | RtcWaitToUpdate (\r | |
355 | UINTN Timeout\r | |
356 | )\r | |
8cd4d17c | 357 | ;\r |
358 | \r | |
8d85dc31 | 359 | /**\r |
360 | See if field Day of an EFI_TIME is correct.\r | |
8cd4d17c | 361 | \r |
8d85dc31 | 362 | @param Time Its Day field is to be checked.\r |
8cd4d17c | 363 | \r |
8d85dc31 | 364 | @retval TRUE Day field of Time is correct.\r |
365 | @retval FALSE Day field of Time is NOT correct.\r | |
366 | **/\r | |
8cd4d17c | 367 | BOOLEAN\r |
368 | DayValid (\r | |
369 | IN EFI_TIME *Time\r | |
370 | );\r | |
371 | \r | |
8d85dc31 | 372 | /**\r |
373 | Check if it is a leapyear.\r | |
374 | \r | |
375 | @param Time The time to be checked.\r | |
376 | \r | |
377 | @retval TRUE It is a leapyear.\r | |
378 | @retval FALSE It is NOT a leapyear.\r | |
379 | **/\r | |
8cd4d17c | 380 | BOOLEAN\r |
381 | IsLeapYear (\r | |
382 | IN EFI_TIME *Time\r | |
383 | );\r | |
384 | \r | |
385 | #endif\r |