Force RTC century to 20 in case core driver has failed to
initialize it.

Contributed-under: TianoCore Contribution Agreement 1.1

Signed-off-by: zwei4 <[email protected]>
---
 .../Common/PlatformSettings/PlatformDxe/Platform.c |  5 +++
 .../PlatformSettings/PlatformDxe/PlatformDxe.h     |  6 +++
 .../PlatformSettings/PlatformDxe/PlatformDxe.inf   |  1 +
 .../Common/PlatformSettings/PlatformDxe/Rtc.c      | 51 ++++++++++++++++++++++
 4 files changed, 63 insertions(+)
 create mode 100644 
Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Rtc.c

diff --git 
a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c 
b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c
index abe635d90..a6d251ded 100644
--- a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c
+++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Platform.c
@@ -390,6 +390,11 @@ ReadyToBootFunction (
     mPciLanInfo = NULL;
   }
 
+  //
+  // Set RTC century in case RTC core driver failed to initialize it.
+  //
+  AdjustRtcCentury ();
+
   return;
 }
 
diff --git 
a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.h 
b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.h
index 1475c4cab..a27277bb7 100644
--- 
a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.h
+++ 
b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.h
@@ -235,6 +235,12 @@ InitSioPlatformPolicy (
   VOID
   );
 
+VOID
+EFIAPI
+AdjustRtcCentury (
+  VOID
+  );
+
 //
 // Global externs
 //
diff --git 
a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf
 
b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf
index 7516a1548..ee8fd5a68 100644
--- 
a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf
+++ 
b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/PlatformDxe.inf
@@ -33,6 +33,7 @@
   PciDevice.c
   IchTcoReset.c
   SensorVar.c
+  Rtc.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git 
a/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Rtc.c 
b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Rtc.c
new file mode 100644
index 000000000..4b6ab285e
--- /dev/null
+++ b/Platform/BroxtonPlatformPkg/Common/PlatformSettings/PlatformDxe/Rtc.c
@@ -0,0 +1,51 @@
+/** @file
+  Adjust Default System Time.
+  
+  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
+                                                                               
    
+  This program and the accompanying materials are licensed and made available 
under
+  the terms and conditions of the BSD License that accompanies this 
distribution.  
+  The full text of the license may be found at                                 
    
+  http://opensource.org/licenses/bsd-license.php.                              
    
+                                                                               
    
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,        
    
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR 
IMPLIED.    
+                                                                               
    
+--*/
+
+#include <PlatformDxe.h>
+
+//
+// Date and time initial values.
+// They are used if the RTC values are invalid during driver initialization
+//
+#define RTC_INIT_SECOND 0
+#define RTC_INIT_MINUTE 0
+#define RTC_INIT_HOUR   0
+
+#define RTC_ADDRESS_CENTURY      50
+
+#define RTC_ADDRESS_REGISTER     0x70
+#define RTC_DATA_REGISTER        0x71
+
+/**
+  Set RTC century to 20 in case RTC core driver failed to initialize it.
+
+**/
+VOID
+EFIAPI
+AdjustRtcCentury (
+  VOID
+  )
+{
+
+  UINT8  Century;
+
+  Century = 20;
+  Century = DecimalToBcd8 (20);
+  IoWrite8 (RTC_ADDRESS_REGISTER, (UINT8) (RTC_ADDRESS_CENTURY | (UINT8) 
(IoRead8 (PCAT_RTC_ADDRESS_REGISTER) & 0x80)));
+  IoWrite8 (RTC_DATA_REGISTER, Century);
+  Century = IoRead8(RTC_DATA_REGISTER);
+
+  return;
+}
-- 
2.14.1.windows.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to