summaryrefslogtreecommitdiff
path: root/PcAtChipsetPkg
diff options
context:
space:
mode:
authorElvin Li <elvin.li@intel.com>2014-11-25 03:38:20 +0000
committerli-elvin <li-elvin@Edk2>2014-11-25 03:38:20 +0000
commitd431bf6e56bac6e8b457a6531932dec13f03933a (patch)
treee775fefe0bae6b6d8a387d0dd988041e62c497ce /PcAtChipsetPkg
parent0db3fade2cc1e8e24e676d900664f6aac9bbda6c (diff)
downloadedk2-d431bf6e56bac6e8b457a6531932dec13f03933a.tar.gz
Initialize alarm register in PcRtc module entrypoint to make UEFI SCT GetWakeupTime pass.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Elvin Li <elvin.li@intel.com> Reviewed-by: Feng Tian <feng.tian@intel.com> Reviewed-by: Eric Jin <eric.jin@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16425 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'PcAtChipsetPkg')
-rw-r--r--PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c91
1 files changed, 89 insertions, 2 deletions
diff --git a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
index a77009a21..eb1a6567e 100644
--- a/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
+++ b/PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcRtc.c
@@ -104,6 +104,8 @@ PcRtcInit (
EFI_TIME Time;
UINTN DataSize;
UINT32 TimerVar;
+ BOOLEAN Enabled;
+ BOOLEAN Pending;
//
// Acquire RTC Lock to make access to RTC atomic
@@ -226,11 +228,96 @@ PcRtcInit (
// Reset time value according to new RTC configuration
//
Status = PcRtcSetTime (&Time, Global);
- if(!EFI_ERROR (Status)) {
+ if (EFI_ERROR (Status)) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Reset wakeup time value to valid state when wakeup alarm is disabled and wakeup time is invalid.
+ // Global variable has already had valid SavedTimeZone and Daylight,
+ // so we can use them to get and set wakeup time.
+ //
+ Status = PcRtcGetWakeupTime (&Enabled, &Pending, &Time, Global);
+ if ((Enabled) || (!EFI_ERROR (Status))) {
return EFI_SUCCESS;
- } else {
+ }
+
+ //
+ // When wakeup time is disabled and invalid, reset wakeup time register to valid state
+ // but keep wakeup alarm disabled.
+ //
+ Time.Second = RTC_INIT_SECOND;
+ Time.Minute = RTC_INIT_MINUTE;
+ Time.Hour = RTC_INIT_HOUR;
+ Time.Day = RTC_INIT_DAY;
+ Time.Month = RTC_INIT_MONTH;
+ Time.Year = RTC_INIT_YEAR;
+ Time.Nanosecond = 0;
+ Time.TimeZone = Global->SavedTimeZone;
+ Time.Daylight = Global->Daylight;;
+
+ //
+ // Acquire RTC Lock to make access to RTC atomic
+ //
+ if (!EfiAtRuntime ()) {
+ EfiAcquireLock (&Global->RtcLock);
+ }
+ //
+ // Wait for up to 0.1 seconds for the RTC to be updated
+ //
+ Status = RtcWaitToUpdate (PcdGet32 (PcdRealTimeClockUpdateTimeout));
+ if (EFI_ERROR (Status)) {
+ if (!EfiAtRuntime ()) {
+ EfiReleaseLock (&Global->RtcLock);
+ }
return EFI_DEVICE_ERROR;
}
+
+ ConvertEfiTimeToRtcTime (&Time, RegisterB, &Century);
+
+ //
+ // Set the Y/M/D info to variable as it has no corresponding hw registers.
+ //
+ Status = EfiSetVariable (
+ L"RTCALARM",
+ &gEfiCallerIdGuid,
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+ sizeof (Time),
+ &Time
+ );
+ if (EFI_ERROR (Status)) {
+ if (!EfiAtRuntime ()) {
+ EfiReleaseLock (&Global->RtcLock);
+ }
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Inhibit updates of the RTC
+ //
+ RegisterB.Bits.Set = 1;
+ RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
+
+ //
+ // Set RTC alarm time registers
+ //
+ RtcWrite (RTC_ADDRESS_SECONDS_ALARM, Time.Second);
+ RtcWrite (RTC_ADDRESS_MINUTES_ALARM, Time.Minute);
+ RtcWrite (RTC_ADDRESS_HOURS_ALARM, Time.Hour);
+
+ //
+ // Allow updates of the RTC registers
+ //
+ RegisterB.Bits.Set = 0;
+ RtcWrite (RTC_ADDRESS_REGISTER_B, RegisterB.Data);
+
+ //
+ // Release RTC Lock.
+ //
+ if (!EfiAtRuntime ()) {
+ EfiReleaseLock (&Global->RtcLock);
+ }
+ return EFI_SUCCESS;
}
/**