Re: [edk2] [PATCH edk2-platforms v4 07/31] Platform/Hisilicon/D06: Add M41T83RealTimeClockLib

2018-08-30 Thread Leif Lindholm
On Fri, Aug 24, 2018 at 12:07:19AM +0800, Ming Huang wrote:
> Add M41T83RealTimeClockLib for RTC.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ming Huang 

Reviewed-by: Leif Lindholm 


> ---
>  Platform/Hisilicon/D06/D06.dsc  
> |   1 +
>  Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf 
> |  46 ++
>  Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h  
> | 158 ++
>  Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c   
> | 559 
>  4 files changed, 764 insertions(+)
> 
> diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc
> index d14fce1159..27358f8c78 100644
> --- a/Platform/Hisilicon/D06/D06.dsc
> +++ b/Platform/Hisilicon/D06/D06.dsc
> @@ -65,6 +65,7 @@
>CpldIoLib|Silicon/Hisilicon/Library/CpldIoLib/CpldIoLib.inf
>  
>TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf
> +  
> RealTimeClockLib|Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
>  
>CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
>
> GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
> diff --git 
> a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf 
> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
> new file mode 100644
> index 00..e0bf6b3f24
> --- /dev/null
> +++ 
> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
> @@ -0,0 +1,46 @@
> +#/** @file
> +#
> +#  Copyright (c) 2018, Hisilicon Limited. All rights reserved.
> +#  Copyright (c) 2018, Linaro Limited. All rights reserved.
> +#
> +#  This program and the accompanying materials
> +#  are licensed and made available under the terms and conditions of the BSD 
> License
> +#  which 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.
> +#
> +#**/
> +
> +[Defines]
> +  INF_VERSION= 0x0001001A
> +  BASE_NAME  = M41T83RealTimeClockLib
> +  FILE_GUID  = 470DFB96-E205-4515-A75E-2E60F853E79D
> +  MODULE_TYPE= BASE
> +  VERSION_STRING = 1.0
> +  LIBRARY_CLASS  = RealTimeClockLib
> +
> +[Sources.common]
> +  M41T83RealTimeClockLib.c
> +
> +[Packages]
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  MdePkg/MdePkg.dec
> +  Platform/Hisilicon/D06/D06.dec
> +  Silicon/Hisilicon/HisiPkg.dec
> +
> +[LibraryClasses]
> +  BaseMemoryLib
> +  CpldIoLib
> +  DebugLib
> +  I2CLib
> +  IoLib
> +  PcdLib
> +  TimeBaseLib
> +  TimerLib
> +  UefiLib
> +  UefiRuntimeLib# Use EFiAtRuntime to check stage
> +
> +[Depex]
> +  gEfiCpuArchProtocolGuid
> diff --git 
> a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h 
> b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
> new file mode 100644
> index 00..d985055d9b
> --- /dev/null
> +++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
> @@ -0,0 +1,158 @@
> +/** @file
> +
> +  Copyright (c) 2018, Hisilicon Limited. All rights reserved.
> +  Copyright (c) 2018, Linaro Limited. All rights reserved.
> +
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD 
> License
> +  which 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.
> +
> +**/
> +
> +#ifndef __M41T83_REAL_TIME_CLOCK_H__
> +#define __M41T83_REAL_TIME_CLOCK_H__
> +
> +// The delay is need for cpld and I2C. This is a empirical value. 
> MemoryFence is no need.
> +#define RTC_DELAY_30_MS3
> +// The delay is need for cpld and I2C. This is a empirical value. 
> MemoryFence is no need.
> +#define RTC_DELAY_1000_MACROSECOND 1000
> +// The delay is need for cpld and I2C. This is a empirical value. 
> MemoryFence is no need.
> +#define RTC_DELAY_2_MACROSECOND2
> +
> +#define M41T83_REGADDR_DOTSECONDS   0x00
> +#define M41T83_REGADDR_SECONDS  0x01
> +#define M41T83_REGADDR_MINUTES  0x02
> +#define M41T83_REGADDR_HOURS0x03
> +#define M41T83_REGADDR_WEEK_DAY 0x04
> +#define M41T83_REGADDR_DAY  0x05
> +#define M41T83_REGADDR_MONTH0x06
> +#define M41T83_REGADDR_YEAR 0x07
> +#define M41T83_REGADDR_ALARM1SEC0x0E
> +#define M41T83_REGADDR_ALARM1MIN0x0D
> +#define 

[edk2] [PATCH edk2-platforms v4 07/31] Platform/Hisilicon/D06: Add M41T83RealTimeClockLib

2018-08-23 Thread Ming Huang
Add M41T83RealTimeClockLib for RTC.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ming Huang 
---
 Platform/Hisilicon/D06/D06.dsc  |  
 1 +
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf |  
46 ++
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h  | 
158 ++
 Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.c   | 
559 
 4 files changed, 764 insertions(+)

diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc
index d14fce1159..27358f8c78 100644
--- a/Platform/Hisilicon/D06/D06.dsc
+++ b/Platform/Hisilicon/D06/D06.dsc
@@ -65,6 +65,7 @@
   CpldIoLib|Silicon/Hisilicon/Library/CpldIoLib/CpldIoLib.inf
 
   TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf
+  
RealTimeClockLib|Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
 
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
   GenericBdsLib|IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
new file mode 100644
index 00..e0bf6b3f24
--- /dev/null
+++ 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClockLib.inf
@@ -0,0 +1,46 @@
+#/** @file
+#
+#  Copyright (c) 2018, Hisilicon Limited. All rights reserved.
+#  Copyright (c) 2018, Linaro Limited. All rights reserved.
+#
+#  This program and the accompanying materials
+#  are licensed and made available under the terms and conditions of the BSD 
License
+#  which 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.
+#
+#**/
+
+[Defines]
+  INF_VERSION= 0x0001001A
+  BASE_NAME  = M41T83RealTimeClockLib
+  FILE_GUID  = 470DFB96-E205-4515-A75E-2E60F853E79D
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = RealTimeClockLib
+
+[Sources.common]
+  M41T83RealTimeClockLib.c
+
+[Packages]
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdePkg/MdePkg.dec
+  Platform/Hisilicon/D06/D06.dec
+  Silicon/Hisilicon/HisiPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  CpldIoLib
+  DebugLib
+  I2CLib
+  IoLib
+  PcdLib
+  TimeBaseLib
+  TimerLib
+  UefiLib
+  UefiRuntimeLib# Use EFiAtRuntime to check stage
+
+[Depex]
+  gEfiCpuArchProtocolGuid
diff --git 
a/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h 
b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
new file mode 100644
index 00..d985055d9b
--- /dev/null
+++ b/Silicon/Hisilicon/Library/M41T83RealTimeClockLib/M41T83RealTimeClock.h
@@ -0,0 +1,158 @@
+/** @file
+
+  Copyright (c) 2018, Hisilicon Limited. All rights reserved.
+  Copyright (c) 2018, Linaro Limited. All rights reserved.
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD 
License
+  which 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.
+
+**/
+
+#ifndef __M41T83_REAL_TIME_CLOCK_H__
+#define __M41T83_REAL_TIME_CLOCK_H__
+
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_30_MS3
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_1000_MACROSECOND 1000
+// The delay is need for cpld and I2C. This is a empirical value. MemoryFence 
is no need.
+#define RTC_DELAY_2_MACROSECOND2
+
+#define M41T83_REGADDR_DOTSECONDS   0x00
+#define M41T83_REGADDR_SECONDS  0x01
+#define M41T83_REGADDR_MINUTES  0x02
+#define M41T83_REGADDR_HOURS0x03
+#define M41T83_REGADDR_WEEK_DAY 0x04
+#define M41T83_REGADDR_DAY  0x05
+#define M41T83_REGADDR_MONTH0x06
+#define M41T83_REGADDR_YEAR 0x07
+#define M41T83_REGADDR_ALARM1SEC0x0E
+#define M41T83_REGADDR_ALARM1MIN0x0D
+#define M41T83_REGADDR_ALARM1HOUR   0x0C
+#define M41T83_REGADDR_ALARM1DATE   0x0B
+#define M41T83_REGADDR_ALARM1MONTH  0x0A
+
+#define M41T83_REGADDR_TIMERCONTROL 0x11
+
+#define M41T83_REGADDR_ALARM2SEC0x18
+#define M41T83_REGADDR_ALARM2MIN0x17
+#define M41T83_REGADDR_ALARM2HOUR   0x16
+#define M41T83_REGADDR_ALARM2DATE   0x15
+#define