From patchwork Thu Oct 27 03:15:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 79592 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp407633qge; Wed, 26 Oct 2016 20:28:29 -0700 (PDT) X-Received: by 10.55.189.4 with SMTP id n4mr4149786qkf.209.1477538909303; Wed, 26 Oct 2016 20:28:29 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l7si3039042qkd.209.2016.10.26.20.28.29; Wed, 26 Oct 2016 20:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linaro-uefi-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=linaro-uefi-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id AC52760974; Thu, 27 Oct 2016 03:28:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2 autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 26A4961CC5; Thu, 27 Oct 2016 03:20:45 +0000 (UTC) X-Original-To: linaro-uefi@lists.linaro.org Delivered-To: linaro-uefi@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2857F61DA5; Thu, 27 Oct 2016 03:20:38 +0000 (UTC) Received: from mail-pf0-f180.google.com (mail-pf0-f180.google.com [209.85.192.180]) by lists.linaro.org (Postfix) with ESMTPS id 87B6960D9D for ; Thu, 27 Oct 2016 03:16:50 +0000 (UTC) Received: by mail-pf0-f180.google.com with SMTP id n85so8218683pfi.1 for ; Wed, 26 Oct 2016 20:16:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H6BS7j92bjrZjpGIdLg1jhTNJL9K0Tnx6Z8uzzzNqxs=; b=Jcs/MeAA7rWPYlZ8nx4lO55LNL+sgilObL0qcVnneVjPHcqUCudG5QCoXan9QRoehp yX9MvRTz8OPKgLDoar5gI3f3qtG5alTHizz4zky98srUOf5urLsFeML+B6L484PLUcDZ F/UtnlNUVxvCjmMIi6V8CFVLBLaFSbkcNcuUwfrZKOII5jQcHiFQ760DBWyeiyDcNPN3 dQ6waF7GLJoh/n55y7ezst9ujQrXwIo75frEMnicoV65c/PO9gIgE7kHiLoUdAMfGO6s Ya+GRXgLJvaR+06tq8jgmk8fmKAnxbL7zfLdpW7XPzaGtdrORxPQMJWowRVM0QouEUU1 XUcg== X-Gm-Message-State: ABUngvc3TdpiS1YZjw6XD2iFYdsH1dOGgg6Z9IwWqrCxKGfgqer9dk/tjzECOdk/rX4GsBHxFBk= X-Received: by 10.98.38.199 with SMTP id m190mr1747888pfm.45.1477538209858; Wed, 26 Oct 2016 20:16:49 -0700 (PDT) Received: from localhost.localdomain ([119.145.15.121]) by smtp.gmail.com with ESMTPSA id h5sm7091734pfg.86.2016.10.26.20.16.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 20:16:49 -0700 (PDT) From: Heyi Guo To: linaro-uefi@lists.linaro.org Date: Thu, 27 Oct 2016 11:15:23 +0800 Message-Id: <1477538129-118465-19-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477538129-118465-1-git-send-email-heyi.guo@linaro.org> References: <1477538129-118465-1-git-send-email-heyi.guo@linaro.org> Cc: Heyi Guo Subject: [Linaro-uefi] [PATCH 20/26] D03/FdtUpdateLib: Update refclk in DT X-BeenThere: linaro-uefi@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-uefi-bounces@lists.linaro.org Sender: "Linaro-uefi" Read reference clock from ARCH timer frequency and set it into DT. Change-Id: I7a305b78512bcbaaab4ed3adc2675800c2462f46 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Heyi Guo --- .../D03/Library/FdtUpdateLib/FdtUpdateLib.c | 64 ++++++++++++++++++++++ .../D03/Library/FdtUpdateLib/FdtUpdateLib.inf | 8 ++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c index b8b9503..f9db938 100755 --- a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c +++ b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -183,6 +184,67 @@ 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 ((EFI_D_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 ((EFI_D_ERROR, "can not find soc root node\n")); + return EFI_INVALID_PARAMETER; + } + + node = fdt_subnode_offset(Fdt, node, "refclk"); + if (node < 0) + { + DEBUG ((EFI_D_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 ((EFI_D_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 ((EFI_D_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 ((EFI_D_ERROR, "ERROR:fdt_setprop() %a: %a\n", Property, fdt_strerror (Error))); + return EFI_INVALID_PARAMETER; + } + + DEBUG ((EFI_D_INFO, "Update refclk successfully.\n")); + return EFI_SUCCESS; +} + INTN GetMemoryNode(VOID* Fdt) { @@ -401,6 +463,8 @@ EFI_STATUS EFIFdtUpdate(UINTN FdtFileAddr) Status = EFI_SUCCESS; } + // Ignore the return status and continue running + (VOID) UpdateRefClk (Fdt); 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..816f6f5 100755 --- a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf +++ b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf @@ -29,13 +29,15 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + ArmPkg/ArmPkg.dec EmbeddedPkg/EmbeddedPkg.dec OpenPlatformPkg/Chips/Hisilicon/HisiPkg.dec [LibraryClasses] - FdtLib - PlatformSysCtrlLib - OemMiscLib + ArmLib + FdtLib + PlatformSysCtrlLib + OemMiscLib [Protocols] gHisiBoardNicProtocolGuid