--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation. All rights reserved. \r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+ \r
+ PcRtc.h\r
+\r
+Abstract:\r
+\r
+ Include for real time clock driver\r
+\r
+Revision History\r
+\r
+\r
+--*/\r
+\r
+#ifndef _RTC_H_\r
+#define _RTC_H_\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/RealTimeClock.h>\r
+//\r
+// The Library classes this module consumes\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
+\r
+\r
+typedef struct {\r
+ EFI_LOCK RtcLock;\r
+ UINT16 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
+EFI_STATUS\r
+PcRtcInit (\r
+ IN PC_RTC_MODULE_GLOBALS *Global\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Global - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PcRtcSetTime (\r
+ IN EFI_TIME *Time,\r
+ IN PC_RTC_MODULE_GLOBALS *Global\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - GC_TODO: add argument description\r
+ Global - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PcRtcGetTime (\r
+ OUT EFI_TIME *Time,\r
+ IN EFI_TIME_CAPABILITIES *Capabilities,\r
+ IN PC_RTC_MODULE_GLOBALS *Global\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - GC_TODO: add argument description\r
+ Capabilities - GC_TODO: add argument description\r
+ Global - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+PcRtcSetWakeupTime (\r
+ IN BOOLEAN Enable,\r
+ OUT EFI_TIME *Time,\r
+ IN PC_RTC_MODULE_GLOBALS *Global\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Enable - GC_TODO: add argument description\r
+ Time - GC_TODO: add argument description\r
+ Global - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\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
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Enabled - GC_TODO: add argument description\r
+ Pending - GC_TODO: add argument description\r
+ Time - GC_TODO: add argument description\r
+ Global - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializePcRtc (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ ImageHandle - GC_TODO: add argument description\r
+ SystemTable - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINT8\r
+BcdToDecimal (\r
+ IN UINT8 BcdValue\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ BcdValue - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINT8\r
+DecimaltoBcd (\r
+ IN UINT8 DecValue\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ DecValue - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+ConvertEfiTimeToRtcTime (\r
+ IN EFI_TIME *Time,\r
+ IN RTC_REGISTER_B RegisterB,\r
+ IN UINT8 *Century\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - GC_TODO: add argument description\r
+ RegisterB - GC_TODO: add argument description\r
+ Century - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+RtcTestCenturyRegister (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+ConvertRtcTimeToEfiTime (\r
+ IN EFI_TIME *Time,\r
+ IN RTC_REGISTER_B RegisterB\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Time - GC_TODO: add argument description\r
+ RegisterB - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+RtcWaitToUpdate (\r
+ UINTN Timeout\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Timeout - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINT8\r
+RtcSaveContext (\r
+ IN PC_RTC_MODULE_GLOBALS *Global\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Global - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+RtcRestoreContext (\r
+ IN UINT8 SavedAddressRegister,\r
+ IN PC_RTC_MODULE_GLOBALS *Global\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ SavedAddressRegister - GC_TODO: add argument description\r
+ Global - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+DayValid (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+ IN EFI_TIME *Time\r
+ );\r
+\r
+#endif\r