From patchwork Sat Nov 19 08:38:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 83110 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp508941qge; Sat, 19 Nov 2016 01:12:43 -0800 (PST) X-Received: by 10.200.51.87 with SMTP id u23mr2385317qta.139.1479546763070; Sat, 19 Nov 2016 01:12:43 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 63si7688295qke.298.2016.11.19.01.12.42; Sat, 19 Nov 2016 01:12:43 -0800 (PST) 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 B5A476074B; Sat, 19 Nov 2016 09:12:42 +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 4EF516353A; Sat, 19 Nov 2016 08:48:27 +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 E259D60CC3; Sat, 19 Nov 2016 08:47:07 +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 39CE862FA2 for ; Sat, 19 Nov 2016 08:41:01 +0000 (UTC) Received: by mail-pf0-f180.google.com with SMTP id 189so57956907pfz.3 for ; Sat, 19 Nov 2016 00:41:01 -0800 (PST) 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=kllbAyvTTblNaFnZC7ZQkeLhFLqdlmb26UC7nsbPk94=; b=IkAOzcT1RYJWTyEQwaHEcW048zKbTtdpwGR4jT0gllCN2rKZic16f4ySSo6UARD09v VHTWJEs3MXSOugl8YcgBrCgyCmIKszLO/ERyPmaWZb8AtBfoG6Yo7+5oUtGlSZNCPaG/ 8sMBVvQtMJK57lyTnpTQYR/r0eqi/D3WrCnphQ9exaG0F/olxJhysStqN7ddQ6NERHk3 58DYTLJbTVptO073a7Nul4FeFZIrmWW1pd2lM3L1ARmz4Z74w1D6MkyYBPR9FaULfYa0 e4SC8r7jnq5rOXUi1QiNEhg6O666qLoTxZXLCCw48wawFUn6kzztyLhTpUKwcaAMkezc WfZg== X-Gm-Message-State: AKaTC02loOK2huJHwwoJM6ch11kaPoS7zjcLYTH9Y2zqFFu9n47MdggVdfF67bHiBAQ8Ewq7pl0= X-Received: by 10.98.11.198 with SMTP id 67mr4901433pfl.90.1479544860519; Sat, 19 Nov 2016 00:41:00 -0800 (PST) Received: from localhost.localdomain ([119.145.15.121]) by smtp.gmail.com with ESMTPSA id v193sm5106241pgb.37.2016.11.19.00.40.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 19 Nov 2016 00:41:00 -0800 (PST) From: Heyi Guo To: linaro-uefi@lists.linaro.org Date: Sat, 19 Nov 2016 16:38:06 +0800 Message-Id: <1479544691-59575-52-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1479544691-59575-1-git-send-email-heyi.guo@linaro.org> References: <1479544691-59575-1-git-send-email-heyi.guo@linaro.org> Subject: [Linaro-uefi] [Patch v4 51/56] 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. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Heyi Guo Reviewed-by: Leif Lindholm --- .../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 +#include #include #include #include @@ -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..9569b91 100755 --- a/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf +++ b/Platforms/Hisilicon/D03/Library/FdtUpdateLib/FdtUpdateLib.inf @@ -27,12 +27,14 @@ [Packages] + ArmPkg/ArmPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec EmbeddedPkg/EmbeddedPkg.dec OpenPlatformPkg/Chips/Hisilicon/HisiPkg.dec [LibraryClasses] + ArmLib FdtLib PlatformSysCtrlLib OemMiscLib