+++ /dev/null
-/** @file\r
- Header file for real time clock driver.\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-\r
-#ifndef _RTC_H_\r
-#define _RTC_H_\r
-\r
-\r
-#include <Uefi.h>\r
-\r
-#include <Protocol/RealTimeClock.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/IoLib.h>\r
-#include <Library/TimerLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
-#include <Library/PcdLib.h>\r
-\r
-\r
-typedef struct {\r
- EFI_LOCK RtcLock;\r
- INT16 SavedTimeZone;\r
- UINT8 Daylight;\r
-} PC_RTC_MODULE_GLOBALS;\r
-\r
-#define PCAT_RTC_ADDRESS_REGISTER 0x70\r
-#define PCAT_RTC_DATA_REGISTER 0x71\r
-\r
-//\r
-// Dallas DS12C887 Real Time Clock\r
-//\r
-#define RTC_ADDRESS_SECONDS 0 // R/W Range 0..59\r
-#define RTC_ADDRESS_SECONDS_ALARM 1 // R/W Range 0..59\r
-#define RTC_ADDRESS_MINUTES 2 // R/W Range 0..59\r
-#define RTC_ADDRESS_MINUTES_ALARM 3 // R/W Range 0..59\r
-#define RTC_ADDRESS_HOURS 4 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
-#define RTC_ADDRESS_HOURS_ALARM 5 // R/W Range 1..12 or 0..23 Bit 7 is AM/PM\r
-#define RTC_ADDRESS_DAY_OF_THE_WEEK 6 // R/W Range 1..7\r
-#define RTC_ADDRESS_DAY_OF_THE_MONTH 7 // R/W Range 1..31\r
-#define RTC_ADDRESS_MONTH 8 // R/W Range 1..12\r
-#define RTC_ADDRESS_YEAR 9 // R/W Range 0..99\r
-#define RTC_ADDRESS_REGISTER_A 10 // R/W[0..6] R0[7]\r
-#define RTC_ADDRESS_REGISTER_B 11 // R/W\r
-#define RTC_ADDRESS_REGISTER_C 12 // RO\r
-#define RTC_ADDRESS_REGISTER_D 13 // RO\r
-#define RTC_ADDRESS_CENTURY 50 // R/W Range 19..20 Bit 8 is R/W\r
-//\r
-// Date and time initial values.\r
-// They are used if the RTC values are invalid during driver initialization\r
-//\r
-#define RTC_INIT_SECOND 0\r
-#define RTC_INIT_MINUTE 0\r
-#define RTC_INIT_HOUR 0\r
-#define RTC_INIT_DAY 1\r
-#define RTC_INIT_MONTH 1\r
-#define RTC_INIT_YEAR 2001\r
-\r
-//\r
-// Register initial values\r
-//\r
-#define RTC_INIT_REGISTER_A 0x26\r
-#define RTC_INIT_REGISTER_B 0x02\r
-#define RTC_INIT_REGISTER_D 0x0\r
-\r
-#pragma pack(1)\r
-//\r
-// Register A\r
-//\r
-typedef struct {\r
- UINT8 RS : 4; // Rate Selection Bits\r
- UINT8 DV : 3; // Divisor\r
- UINT8 UIP : 1; // Update in progress\r
-} RTC_REGISTER_A_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_A_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_A;\r
-\r
-//\r
-// Register B\r
-//\r
-typedef struct {\r
- UINT8 DSE : 1; // 0 - Daylight saving disabled 1 - Daylight savings enabled\r
- UINT8 MIL : 1; // 0 - 12 hour mode 1 - 24 hour mode\r
- UINT8 DM : 1; // 0 - BCD Format 1 - Binary Format\r
- UINT8 SQWE : 1; // 0 - Disable SQWE output 1 - Enable SQWE output\r
- UINT8 UIE : 1; // 0 - Update INT disabled 1 - Update INT enabled\r
- UINT8 AIE : 1; // 0 - Alarm INT disabled 1 - Alarm INT Enabled\r
- UINT8 PIE : 1; // 0 - Periodic INT disabled 1 - Periodic INT Enabled\r
- UINT8 SET : 1; // 0 - Normal operation. 1 - Updates inhibited\r
-} RTC_REGISTER_B_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_B_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_B;\r
-\r
-//\r
-// Register C\r
-//\r
-typedef struct {\r
- UINT8 Reserved : 4; // Read as zero. Can not be written.\r
- UINT8 UF : 1; // Update End Interrupt Flag\r
- UINT8 AF : 1; // Alarm Interrupt Flag\r
- UINT8 PF : 1; // Periodic Interrupt Flag\r
- UINT8 IRQF : 1; // Iterrupt Request Flag = PF & PIE | AF & AIE | UF & UIE\r
-} RTC_REGISTER_C_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_C_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_C;\r
-\r
-//\r
-// Register D\r
-//\r
-typedef struct {\r
- UINT8 Reserved : 7; // Read as zero. Can not be written.\r
- UINT8 VRT : 1; // Valid RAM and Time\r
-} RTC_REGISTER_D_BITS;\r
-\r
-typedef union {\r
- RTC_REGISTER_D_BITS Bits;\r
- UINT8 Data;\r
-} RTC_REGISTER_D;\r
-\r
-#pragma pack()\r
-\r
-/**\r
- Initialize RTC.\r
-\r
- @param Global For global use inside this module.\r
-\r
- @retval EFI_DEVICE_ERROR Initialization failed due to device error.\r
- @retval EFI_SUCCESS Initialization successful.\r
-\r
-**/\r
-EFI_STATUS\r
-PcRtcInit (\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- );\r
-\r
-/**\r
- Sets the current local time and date information.\r
-\r
- @param Time A pointer to the current time.\r
- @param Global For global use inside this module.\r
-\r
- @retval EFI_SUCCESS The operation completed successfully.\r
- @retval EFI_INVALID_PARAMETER A time field is out of range.\r
- @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.\r
-\r
-**/\r
-EFI_STATUS\r
-PcRtcSetTime (\r
- IN EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- );\r
-\r
-/**\r
- Returns the current time and date information, and the time-keeping capabilities\r
- of the hardware platform.\r
-\r
- @param Time A pointer to storage to receive a snapshot of the current time.\r
- @param Capabilities An optional pointer to a buffer to receive the real time clock\r
- device's capabilities.\r
- @param Global For global use inside this module.\r
-\r
- @retval EFI_SUCCESS The operation completed successfully.\r
- @retval EFI_INVALID_PARAMETER Time is NULL.\r
- @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.\r
-\r
-**/\r
-EFI_STATUS\r
-PcRtcGetTime (\r
- OUT EFI_TIME *Time,\r
- OUT EFI_TIME_CAPABILITIES *Capabilities, OPTIONAL\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- );\r
-\r
-/**\r
- Sets the system wakeup alarm clock time.\r
-\r
- @param Enabled Enable or disable the wakeup alarm.\r
- @param Time If Enable is TRUE, the time to set the wakeup alarm for.\r
- If Enable is FALSE, then this parameter is optional, and may be NULL.\r
- @param Global For global use inside this module.\r
-\r
- @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled.\r
- If Enable is FALSE, then the wakeup alarm was disabled.\r
- @retval EFI_INVALID_PARAMETER A time field is out of range.\r
- @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.\r
- @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
-\r
-**/\r
-EFI_STATUS\r
-PcRtcSetWakeupTime (\r
- IN BOOLEAN Enable,\r
- IN EFI_TIME *Time, OPTIONAL\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- );\r
-\r
-/**\r
- Returns the current wakeup alarm clock setting.\r
-\r
- @param Enabled Indicates if the alarm is currently enabled or disabled.\r
- @param Pending Indicates if the alarm signal is pending and requires acknowledgement.\r
- @param Time The current alarm setting.\r
- @param Global For global use inside this module.\r
-\r
- @retval EFI_SUCCESS The alarm settings were returned.\r
- @retval EFI_INVALID_PARAMETER Enabled is NULL.\r
- @retval EFI_INVALID_PARAMETER Pending is NULL.\r
- @retval EFI_INVALID_PARAMETER Time is NULL.\r
- @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.\r
- @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.\r
-\r
-**/\r
-EFI_STATUS\r
-PcRtcGetWakeupTime (\r
- OUT BOOLEAN *Enabled,\r
- OUT BOOLEAN *Pending,\r
- OUT EFI_TIME *Time,\r
- IN PC_RTC_MODULE_GLOBALS *Global\r
- );\r
-\r
-/**\r
- The user Entry Point for PcRTC module.\r
-\r
- This is the entrhy point for PcRTC module. It installs the UEFI runtime service\r
- including GetTime(),SetTime(),GetWakeupTime(),and SetWakeupTime().\r
-\r
- @param ImageHandle The firmware allocated handle for the EFI image.\r
- @param SystemTable A pointer to the EFI System Table.\r
-\r
- @retval EFI_SUCCESS The entry point is executed successfully.\r
- @retval Others Some error occurs when executing this entry point.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InitializePcRtc (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- );\r
-\r
-/**\r
- See if all fields of a variable of EFI_TIME type is correct.\r
-\r
- @param Time The time to be checked.\r
-\r
- @retval EFI_INVALID_PARAMETER Some fields of Time are not correct.\r
- @retval EFI_SUCCESS Time is a valid EFI_TIME variable.\r
-\r
-**/\r
-EFI_STATUS\r
-RtcTimeFieldsValid (\r
- IN EFI_TIME *Time\r
- );\r
-\r
-/**\r
- Converts time from EFI_TIME format defined by UEFI spec to RTC's.\r
-\r
- This function converts time from EFI_TIME format defined by UEFI spec to RTC's.\r
- If data mode of RTC is BCD, then converts EFI_TIME to it.\r
- If RTC is in 12-hour format, then converts EFI_TIME to it.\r
-\r
- @param Time On input, the time data read from UEFI to convert\r
- On output, the time converted to RTC format\r
- @param RegisterB Value of Register B of RTC, indicating data mode\r
- @param Century It is set according to EFI_TIME Time.\r
-\r
-**/\r
-VOID\r
-ConvertEfiTimeToRtcTime (\r
- IN OUT EFI_TIME *Time,\r
- IN RTC_REGISTER_B RegisterB,\r
- OUT UINT8 *Century\r
- );\r
-\r
-\r
-/**\r
- Converts time read from RTC to EFI_TIME format defined by UEFI spec.\r
-\r
- This function converts raw time data read from RTC to the EFI_TIME format\r
- defined by UEFI spec.\r
- If data mode of RTC is BCD, then converts it to decimal,\r
- If RTC is in 12-hour format, then converts it to 24-hour format.\r
-\r
- @param Time On input, the time data read from RTC to convert\r
- On output, the time converted to UEFI format\r
- @param Century Value of century read from RTC.\r
- @param RegisterB Value of Register B of RTC, indicating data mode\r
- and hour format.\r
-\r
- @retval EFI_INVALID_PARAMETER Parameters passed in are invalid.\r
- @retval EFI_SUCCESS Convert RTC time to EFI time successfully.\r
-\r
-**/\r
-EFI_STATUS\r
-ConvertRtcTimeToEfiTime (\r
- IN OUT EFI_TIME *Time,\r
- IN UINT8 Century,\r
- IN RTC_REGISTER_B RegisterB\r
- );\r
-\r
-/**\r
- Wait for a period for the RTC to be ready.\r
-\r
- @param Timeout Tell how long it should take to wait.\r
-\r
- @retval EFI_DEVICE_ERROR RTC device error.\r
- @retval EFI_SUCCESS RTC is updated and ready. \r
-**/\r
-EFI_STATUS\r
-RtcWaitToUpdate (\r
- UINTN Timeout\r
- );\r
-\r
-/**\r
- See if field Day of an EFI_TIME is correct.\r
-\r
- @param Time Its Day field is to be checked.\r
-\r
- @retval TRUE Day field of Time is correct.\r
- @retval FALSE Day field of Time is NOT correct.\r
-**/\r
-BOOLEAN\r
-DayValid (\r
- IN EFI_TIME *Time\r
- );\r
-\r
-/**\r
- Check if it is a leapyear.\r
-\r
- @param Time The time to be checked.\r
-\r
- @retval TRUE It is a leapyear.\r
- @retval FALSE It is NOT a leapyear.\r
-**/\r
-BOOLEAN\r
-IsLeapYear (\r
- IN EFI_TIME *Time\r
- );\r
-\r
-#endif\r