2 Header file for real time clock driver.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2017, AMD Inc. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
18 #include <Guid/Acpi.h>
20 #include <Protocol/RealTimeClock.h>
22 #include <Library/BaseLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/IoLib.h>
27 #include <Library/TimerLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/UefiRuntimeLib.h>
31 #include <Library/UefiRuntimeServicesTableLib.h>
32 #include <Library/PcdLib.h>
33 #include <Library/ReportStatusCodeLib.h>
39 UINT8 CenturyRtcAddress
;
40 } PC_RTC_MODULE_GLOBALS
;
42 extern PC_RTC_MODULE_GLOBALS mModuleGlobal
;
45 // Dallas DS12C887 Real Time Clock
47 #define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59
48 #define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59
49 #define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59
50 #define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59
51 #define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM
52 #define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM
53 #define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7
54 #define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31
55 #define RTC_ADDRESS_MONTH 8 // R/W Range 1..12
56 #define RTC_ADDRESS_YEAR 9 // R/W Range 0..99
57 #define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7]
58 #define RTC_ADDRESS_REGISTER_B 11 // R/W
59 #define RTC_ADDRESS_REGISTER_C 12 // RO
60 #define RTC_ADDRESS_REGISTER_D 13 // RO
62 // Date and time initial values.
63 // They are used if the RTC values are invalid during driver initialization
65 #define RTC_INIT_SECOND 0
66 #define RTC_INIT_MINUTE 0
67 #define RTC_INIT_HOUR 0
68 #define RTC_INIT_DAY 1
69 #define RTC_INIT_MONTH 1
76 UINT8 Rs
: 4; // Rate Selection Bits
77 UINT8 Dv
: 3; // Divisor
78 UINT8 Uip
: 1; // Update in progress
79 } RTC_REGISTER_A_BITS
;
82 RTC_REGISTER_A_BITS Bits
;
90 UINT8 Dse
: 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled
91 UINT8 Mil
: 1; // 0 - 12 hour mode 1 - 24 hour mode
92 UINT8 Dm
: 1; // 0 - BCD Format 1 - Binary Format
93 UINT8 Sqwe
: 1; // 0 - Disable SQWE output 1 - Enable SQWE output
94 UINT8 Uie
: 1; // 0 - Update INT disabled 1 - Update INT enabled
95 UINT8 Aie
: 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled
96 UINT8 Pie
: 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled
97 UINT8 Set
: 1; // 0 - Normal operation. 1 - Updates inhibited
98 } RTC_REGISTER_B_BITS
;
101 RTC_REGISTER_B_BITS Bits
;
109 UINT8 Reserved
: 4; // Read as zero. Can not be written.
110 UINT8 Uf
: 1; // Update End Interrupt Flag
111 UINT8 Af
: 1; // Alarm Interrupt Flag
112 UINT8 Pf
: 1; // Periodic Interrupt Flag
113 UINT8 Irqf
: 1; // Interrupt Request Flag = PF & PIE | AF & AIE | UF & UIE
114 } RTC_REGISTER_C_BITS
;
117 RTC_REGISTER_C_BITS Bits
;
125 UINT8 Reserved
: 7; // Read as zero. Can not be written.
126 UINT8 Vrt
: 1; // Valid RAM and Time
127 } RTC_REGISTER_D_BITS
;
130 RTC_REGISTER_D_BITS Bits
;
139 @param Global For global use inside this module.
141 @retval EFI_DEVICE_ERROR Initialization failed due to device error.
142 @retval EFI_SUCCESS Initialization successful.
147 IN PC_RTC_MODULE_GLOBALS
*Global
151 Sets the current local time and date information.
153 @param Time A pointer to the current time.
154 @param Global For global use inside this module.
156 @retval EFI_SUCCESS The operation completed successfully.
157 @retval EFI_INVALID_PARAMETER A time field is out of range.
158 @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
164 IN PC_RTC_MODULE_GLOBALS
*Global
168 Returns the current time and date information, and the time-keeping capabilities
169 of the hardware platform.
171 @param Time A pointer to storage to receive a snapshot of the current time.
172 @param Capabilities An optional pointer to a buffer to receive the real time clock
173 device's capabilities.
174 @param Global For global use inside this module.
176 @retval EFI_SUCCESS The operation completed successfully.
177 @retval EFI_INVALID_PARAMETER Time is NULL.
178 @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
184 OUT EFI_TIME_CAPABILITIES
*Capabilities
, OPTIONAL
185 IN PC_RTC_MODULE_GLOBALS
*Global
189 Sets the system wakeup alarm clock time.
191 @param Enabled Enable or disable the wakeup alarm.
192 @param Time If Enable is TRUE, the time to set the wakeup alarm for.
193 If Enable is FALSE, then this parameter is optional, and may be NULL.
194 @param Global For global use inside this module.
196 @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.
197 If Enable is FALSE, then the wakeup alarm was disabled.
198 @retval EFI_INVALID_PARAMETER A time field is out of range.
199 @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
200 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
206 IN EFI_TIME
*Time
, OPTIONAL
207 IN PC_RTC_MODULE_GLOBALS
*Global
211 Returns the current wakeup alarm clock setting.
213 @param Enabled Indicates if the alarm is currently enabled or disabled.
214 @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
215 @param Time The current alarm setting.
216 @param Global For global use inside this module.
218 @retval EFI_SUCCESS The alarm settings were returned.
219 @retval EFI_INVALID_PARAMETER Enabled is NULL.
220 @retval EFI_INVALID_PARAMETER Pending is NULL.
221 @retval EFI_INVALID_PARAMETER Time is NULL.
222 @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
223 @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
228 OUT BOOLEAN
*Enabled
,
229 OUT BOOLEAN
*Pending
,
231 IN PC_RTC_MODULE_GLOBALS
*Global
235 The user Entry Point for PcRTC module.
237 This is the entry point for PcRTC module. It installs the UEFI runtime service
238 including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().
240 @param ImageHandle The firmware allocated handle for the EFI image.
241 @param SystemTable A pointer to the EFI System Table.
243 @retval EFI_SUCCESS The entry point is executed successfully.
244 @retval Others Some error occurs when executing this entry point.
250 IN EFI_HANDLE ImageHandle
,
251 IN EFI_SYSTEM_TABLE
*SystemTable
255 See if all fields of a variable of EFI_TIME type is correct.
257 @param Time The time to be checked.
259 @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.
260 @retval EFI_SUCCESS Time is a valid EFI_TIME variable.
269 Converts time from EFI_TIME format defined by UEFI spec to RTC format.
271 This function converts time from EFI_TIME format defined by UEFI spec to RTC format.
272 If data mode of RTC is BCD, then converts EFI_TIME to it.
273 If RTC is in 12-hour format, then converts EFI_TIME to it.
275 @param Time On input, the time data read from UEFI to convert
276 On output, the time converted to RTC format
277 @param RegisterB Value of Register B of RTC, indicating data mode
280 ConvertEfiTimeToRtcTime (
281 IN OUT EFI_TIME
*Time
,
282 IN RTC_REGISTER_B RegisterB
287 Converts time read from RTC to EFI_TIME format defined by UEFI spec.
289 This function converts raw time data read from RTC to the EFI_TIME format
290 defined by UEFI spec.
291 If data mode of RTC is BCD, then converts it to decimal,
292 If RTC is in 12-hour format, then converts it to 24-hour format.
294 @param Time On input, the time data read from RTC to convert
295 On output, the time converted to UEFI format
296 @param RegisterB Value of Register B of RTC, indicating data mode
299 @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.
300 @retval EFI_SUCCESS Convert RTC time to EFI time successfully.
304 ConvertRtcTimeToEfiTime (
305 IN OUT EFI_TIME
*Time
,
306 IN RTC_REGISTER_B RegisterB
310 Wait for a period for the RTC to be ready.
312 @param Timeout Tell how long it should take to wait.
314 @retval EFI_DEVICE_ERROR RTC device error.
315 @retval EFI_SUCCESS RTC is updated and ready.
323 See if field Day of an EFI_TIME is correct.
325 @param Time Its Day field is to be checked.
327 @retval TRUE Day field of Time is correct.
328 @retval FALSE Day field of Time is NOT correct.
336 Check if it is a leapyear.
338 @param Time The time to be checked.
340 @retval TRUE It is a leapyear.
341 @retval FALSE It is NOT a leapyear.
349 Get the century RTC address from the ACPI FADT table.
351 @return The century RTC address or 0 if not found.
354 GetCenturyRtcAddress (
359 Notification function of ACPI Table change.
361 This is a notification function registered on ACPI Table change event.
362 It saves the Century address stored in ACPI FADT table.
364 @param Event Event whose notification function is being invoked.
365 @param Context Pointer to the notification function's context.
370 PcRtcAcpiTableChangeCallback (