diff mbox

[Linaro-uefi,22/28] D03/FdtUpdateLib: Update refclk in DT

Message ID 1479122995-50330-23-git-send-email-heyi.guo@linaro.org
State Superseded
Headers show

Commit Message

gary guo Nov. 14, 2016, 11:29 a.m. UTC
Read reference clock from ARCH timer frequency and set it into DT.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
---
 .../D03/Library/FdtUpdateLib/FdtUpdateLib.c        | 60 ++++++++++++++++++++++
 .../D03/Library/FdtUpdateLib/FdtUpdateLib.inf      |  2 +
 2 files changed, 62 insertions(+)

Comments

Leif Lindholm Nov. 15, 2016, 8:45 p.m. UTC | #1
On Mon, Nov 14, 2016 at 07:29:49PM +0800, Heyi Guo wrote:
> Read reference clock from ARCH timer frequency and set it into DT.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
> ---
>  .../D03/Library/FdtUpdateLib/FdtUpdateLib.c        | 60 ++++++++++++++++++++++
>  .../D03/Library/FdtUpdateLib/FdtUpdateLib.inf      |  2 +
>  2 files changed, 62 insertions(+)
> 
> diff --git a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c
> index b8b9503..d00cb9b 100755
> --- a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c
> +++ b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c
> @@ -14,6 +14,7 @@
>  **/
>  
>  #include <Uefi.h>
> +#include <Library/ArmArchTimer.h>
>  #include <Library/BaseLib.h>
>  #include <libfdt.h>
>  #include <Library/IoLib.h>
> @@ -183,6 +184,61 @@ DelPhyhandleUpdateMacAddress(IN VOID* Fdt)
>      return Status;
>  }
>  
> +STATIC
> +EFI_STATUS
> +UpdateRefClk (IN VOID* Fdt)
> +{
> +  INTN                node;
> +  INTN                Error;
> +  struct              fdt_property *m_prop;
> +  int                 m_oldlen;
> +  UINTN               ArchTimerFreq = 0;
> +  UINT32              Data;
> +  CONST CHAR8         *Property = "clock-frequency";
> +
> +  ArmArchTimerReadReg (CntFrq, &ArchTimerFreq);
> +  if (!ArchTimerFreq) {
> +    DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Get timer frequency failed!\n", __FUNCTION__, __LINE__));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  node = fdt_subnode_offset(Fdt, 0, "soc");
> +  if (node < 0) {
> +    DEBUG ((DEBUG_ERROR, "can not find soc node\n"));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  node = fdt_subnode_offset(Fdt, node, "refclk");
> +  if (node < 0) {
> +    DEBUG ((DEBUG_ERROR, "can not find refclk node\n"));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  m_prop = fdt_get_property_w(Fdt, node, Property, &m_oldlen);
> +  if(!m_prop) {
> +    DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Can't find property %a\n", __FUNCTION__, __LINE__, Property));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  Error = fdt_delprop(Fdt, node, Property);
> +  if (Error) {
> +    DEBUG ((DEBUG_ERROR, "ERROR: fdt_delprop() %a: %a\n", Property, fdt_strerror (Error)));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  // UINT32 is enough for refclk data length
> +  Data = (UINT32) ArchTimerFreq;
> +  Data = cpu_to_fdt32 (Data);
> +  Error = fdt_setprop(Fdt, node, Property, &Data, sizeof(Data));
> +  if (Error) {
> +    DEBUG ((DEBUG_ERROR, "ERROR:fdt_setprop() %a: %a\n", Property, fdt_strerror (Error)));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  DEBUG ((DEBUG_INFO, "Update refclk successfully.\n"));
> +  return EFI_SUCCESS;
> +}
> +
>  INTN
>  GetMemoryNode(VOID* Fdt)
>  {
> @@ -401,6 +457,10 @@ EFI_STATUS EFIFdtUpdate(UINTN FdtFileAddr)
>          Status = EFI_SUCCESS;
>      }
>  
> +    Status =  UpdateRefClk (Fdt);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "UpdateiRefClk fail.\n"));
> +    }
>  
>      Status = UpdateMemoryNode(Fdt);
>      if (EFI_ERROR (Status))
> diff --git a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf
> index b885eae..6a38d28 100755
> --- a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf
> +++ b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf
> @@ -27,6 +27,7 @@
>  
>  
>  [Packages]
> +  ArmPkg/ArmPkg.dec
>    MdePkg/MdePkg.dec
>    MdeModulePkg/MdeModulePkg.dec
>    EmbeddedPkg/EmbeddedPkg.dec
> @@ -36,6 +37,7 @@
>   FdtLib
>   PlatformSysCtrlLib
>   OemMiscLib
> +  ArmLib

Add this sorted?

>  
>  [Protocols]
>   gHisiBoardNicProtocolGuid
> -- 
> 1.9.1
>
diff mbox

Patch

diff --git a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c
index b8b9503..d00cb9b 100755
--- a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c
+++ b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c
@@ -14,6 +14,7 @@ 
 **/
 
 #include <Uefi.h>
+#include <Library/ArmArchTimer.h>
 #include <Library/BaseLib.h>
 #include <libfdt.h>
 #include <Library/IoLib.h>
@@ -183,6 +184,61 @@  DelPhyhandleUpdateMacAddress(IN VOID* Fdt)
     return Status;
 }
 
+STATIC
+EFI_STATUS
+UpdateRefClk (IN VOID* Fdt)
+{
+  INTN                node;
+  INTN                Error;
+  struct              fdt_property *m_prop;
+  int                 m_oldlen;
+  UINTN               ArchTimerFreq = 0;
+  UINT32              Data;
+  CONST CHAR8         *Property = "clock-frequency";
+
+  ArmArchTimerReadReg (CntFrq, &ArchTimerFreq);
+  if (!ArchTimerFreq) {
+    DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Get timer frequency failed!\n", __FUNCTION__, __LINE__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  node = fdt_subnode_offset(Fdt, 0, "soc");
+  if (node < 0) {
+    DEBUG ((DEBUG_ERROR, "can not find soc node\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  node = fdt_subnode_offset(Fdt, node, "refclk");
+  if (node < 0) {
+    DEBUG ((DEBUG_ERROR, "can not find refclk node\n"));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  m_prop = fdt_get_property_w(Fdt, node, Property, &m_oldlen);
+  if(!m_prop) {
+    DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Can't find property %a\n", __FUNCTION__, __LINE__, Property));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Error = fdt_delprop(Fdt, node, Property);
+  if (Error) {
+    DEBUG ((DEBUG_ERROR, "ERROR: fdt_delprop() %a: %a\n", Property, fdt_strerror (Error)));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  // UINT32 is enough for refclk data length
+  Data = (UINT32) ArchTimerFreq;
+  Data = cpu_to_fdt32 (Data);
+  Error = fdt_setprop(Fdt, node, Property, &Data, sizeof(Data));
+  if (Error) {
+    DEBUG ((DEBUG_ERROR, "ERROR:fdt_setprop() %a: %a\n", Property, fdt_strerror (Error)));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  DEBUG ((DEBUG_INFO, "Update refclk successfully.\n"));
+  return EFI_SUCCESS;
+}
+
 INTN
 GetMemoryNode(VOID* Fdt)
 {
@@ -401,6 +457,10 @@  EFI_STATUS EFIFdtUpdate(UINTN FdtFileAddr)
         Status = EFI_SUCCESS;
     }
 
+    Status =  UpdateRefClk (Fdt);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "UpdateiRefClk fail.\n"));
+    }
 
     Status = UpdateMemoryNode(Fdt);
     if (EFI_ERROR (Status))
diff --git a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf
index b885eae..6a38d28 100755
--- a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf
+++ b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf
@@ -27,6 +27,7 @@ 
 
 
 [Packages]
+  ArmPkg/ArmPkg.dec
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec
   EmbeddedPkg/EmbeddedPkg.dec
@@ -36,6 +37,7 @@ 
  FdtLib
  PlatformSysCtrlLib
  OemMiscLib
+  ArmLib
 
 [Protocols]
  gHisiBoardNicProtocolGuid