From patchwork Tue Dec 6 10:56:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: gary guo X-Patchwork-Id: 86770 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1960092qgi; Tue, 6 Dec 2016 03:16:19 -0800 (PST) X-Received: by 10.55.187.65 with SMTP id l62mr59484300qkf.270.1481022979656; Tue, 06 Dec 2016 03:16:19 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c123si11420710qkb.20.2016.12.06.03.16.19; Tue, 06 Dec 2016 03:16:19 -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 317D860A4A; Tue, 6 Dec 2016 11:16:19 +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_H3, RCVD_IN_MSPIKE_WL 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 81ED9609AA; Tue, 6 Dec 2016 11:04:25 +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 86C16609E6; Tue, 6 Dec 2016 11:04:10 +0000 (UTC) Received: from mail-pg0-f49.google.com (mail-pg0-f49.google.com [74.125.83.49]) by lists.linaro.org (Postfix) with ESMTPS id 92C1D60BEE for ; Tue, 6 Dec 2016 10:59:52 +0000 (UTC) Received: by mail-pg0-f49.google.com with SMTP id x23so148344053pgx.1 for ; Tue, 06 Dec 2016 02:59:52 -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=kYoDiTOHSNUPGWWQnrftsn5vZnxYP4fEaGiSBYHtAvw=; b=cpx8c7RHh+PSJ8BXsQR3tZBeooEHIrfpcoh71aM5Y2T7DG4IlR146MF7m7S26yFq5/ Ib3e5RF4fLbX5XymCLWg9tnnuo9EOVI/kBOw/K0asdqA8I7I+C/awpyY5AtbI8Nm/in4 oEvDKAYMq9KEPxuMUQfUA84+Bt7ksVj5fKMOgz4+mzu7RSNKyuvtczMrTeuF0UmqykXt EIA3xG0Uud6SJb/2p3HA3jV2EptnPniIcg6UkAso4x2wRCW+kHeYzlkjjFA263fGDPqB Et/ChUVT3eFPTjVPG79ilor5KENg5ov/PEW7M4rUFoUscn5pvQLRImJBF5s94pFELSL5 auFQ== X-Gm-Message-State: AKaTC03blAYrUQZEe6hWAD4vTTjuCMFM88dMsrbMdiX68b4qEfqp0T/H5C4Y10YeYzJAgOHddpk= X-Received: by 10.84.129.34 with SMTP id 31mr136739372plb.104.1481021991775; Tue, 06 Dec 2016 02:59:51 -0800 (PST) Received: from localhost.localdomain ([119.145.15.121]) by smtp.gmail.com with ESMTPSA id x26sm6980952pge.24.2016.12.06.02.59.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Dec 2016 02:59:51 -0800 (PST) From: Heyi Guo To: linaro-uefi@lists.linaro.org Date: Tue, 6 Dec 2016 18:56:56 +0800 Message-Id: <1481021828-59826-26-git-send-email-heyi.guo@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481021828-59826-1-git-send-email-heyi.guo@linaro.org> References: <1481021828-59826-1-git-send-email-heyi.guo@linaro.org> Cc: sunchenhui@huawei.com, wanghuiqiang@huawei.com Subject: [Linaro-uefi] [linaro-uefi v6 25/37] 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