From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (EUR05-VI1-obe.outbound.protection.outlook.com [40.107.21.89]) by mx.groups.io with SMTP id smtpd.web10.2055.1588225901177372222 for ; Wed, 29 Apr 2020 22:51:41 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp1.onmicrosoft.com header.s=selector2-nxp1-onmicrosoft-com header.b=VD5zVhkg; spf=pass (domain: oss.nxp.com, ip: 40.107.21.89, mailfrom: pankaj.bansal@oss.nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZStS9spTvKq+PbTsaQghJV6cLNLizm+btLmYO0XtF9pQU+dfml4ozGccODKUHoODm2uUOPc41rjuyKdAHspwik5hdkJDIwFDc4Ce22eAgRutUHWlnC0DeaTFRg4P9xsCQufcPffBI9UrFzhiYrMhyJdhzACQBweMM6mmi56wjxjdbSq5L1gXUfza1ExzuTOk2Q2RiQHEoqmVMIhCGSCK1JIaXEjRjPIG5PTL4tl02e15yHCa27zvNcUNTfPsOzd9gB9Kdcl0/H3BDFqNEhuslkN/B0Eb8pGAQvgdFaBrXQehCWOsIahy6xLxwfZN75lsYgS/G0OnZcOMV3cDswxmLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jhX65a9vgFP8u1l8cXGCktVdzHOz+/a9ENx7g8Pi6tk=; b=F0KS0gEiYj9uka+SackB4/HcZj8WeLSmLUoRJAAqzjQOLNMhceAFdst52bx+U1lYP/sY90pr7aTsjNu322hFwE+oEHBLqk2efeH0ZeZKaS+MWCER9l6SFZOMa4mixfyEcGq8x7jmP0qPkhnyzrtrq/gSkIsRxUuBTGOtmli8zzXzdcu+9L8julRLJMcVgI2t+t8nx4+a45Dv9Y1pGz25PurI4aVhZM1ZDCKQrQF/Y0VkCRJsmMfSmB0lh5dDwq1f9+3VEN7bhrp8IFOaGXxSCpBG3FPQc8jhlnZyquu+IWnY9HE9vuYjGfu6ixehUjG6lYrn1MkfSc/rD3kb5m5Vyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jhX65a9vgFP8u1l8cXGCktVdzHOz+/a9ENx7g8Pi6tk=; b=VD5zVhkgalt7/KJurDWYJb/fTIhHppZi7u6hYLE6D3IfZNfvDAjq7DyTH0p0ga2oYejn0sAOnOBm33ama3yMMD8HfK1vWJLnteuppB+H5TY2smsWmR5mxCX4P/RIVQL6lk6CHo3tcNFRAX6HnFWtvaX/6PxuO0KQtNNwxc0yXQk= Authentication-Results: nuviainc.com; dkim=none (message not signed) header.d=none;nuviainc.com; dmarc=none action=none header.from=oss.nxp.com; Received: from VI1PR04MB5933.eurprd04.prod.outlook.com (2603:10a6:803:ec::16) by VI1PR04MB4429.eurprd04.prod.outlook.com (2603:10a6:803:6e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13; Thu, 30 Apr 2020 05:51:39 +0000 Received: from VI1PR04MB5933.eurprd04.prod.outlook.com ([fe80::45c4:8846:5327:9513]) by VI1PR04MB5933.eurprd04.prod.outlook.com ([fe80::45c4:8846:5327:9513%7]) with mapi id 15.20.2958.020; Thu, 30 Apr 2020 05:51:38 +0000 From: "Pankaj Bansal" To: Leif Lindholm , Meenakshi Aggarwal , Michael D Kinney , devel@edk2.groups.io, Varun Sethi , Samer El-Haj-Mahmoud , Jon Nettleton , Ard Biesheuvel Subject: [PATCH edk2-platforms v4 13/24] Platform/NXP/LS1043aRdbPkg: Add Clock retrieval APIs Date: Fri, 1 May 2020 11:19:44 +0530 Message-ID: <20200501054955.13025-14-pankaj.bansal@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200501054955.13025-1-pankaj.bansal@oss.nxp.com> References: <20200501054955.13025-1-pankaj.bansal@oss.nxp.com> X-ClientProxiedBy: SG2PR03CA0131.apcprd03.prod.outlook.com (2603:1096:4:91::35) To VI1PR04MB5933.eurprd04.prod.outlook.com (2603:10a6:803:ec::16) Return-Path: pankaj.bansal@oss.nxp.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from uefi-workstation.ap.freescale.net (92.120.0.69) by SG2PR03CA0131.apcprd03.prod.outlook.com (2603:1096:4:91::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.14 via Frontend Transport; Thu, 30 Apr 2020 05:51:36 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [92.120.0.69] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f4e2ff1f-21ce-44a9-51ad-08d7ecca8ccd X-MS-TrafficTypeDiagnostic: VI1PR04MB4429:|VI1PR04MB4429: X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0389EDA07F X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5933.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(136003)(376002)(39860400002)(346002)(366004)(396003)(6512007)(26005)(16526019)(5660300002)(6666004)(478600001)(186003)(2906002)(110136005)(52116002)(6486002)(316002)(8676002)(6506007)(66476007)(19627235002)(86362001)(2616005)(66946007)(44832011)(956004)(66556008)(1076003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bgc6Xfy5v1qF7cPuRcjsxMUJ3+E+CEkb03PREjyllwBT7fioCqjAzhq2QNym4rzbqoOTxLLHZsHlMHv067Fh43MUF9uDyrIexZ3oIs6FGiiiKtwUUe27Gn0+GJt7M7d8DQ7PjIXw0U7Mb7GR62kikQM35XnErEsAaJnosXLBnzCUseWkS9ckG/zK5oFjrx0275wx6q+ddCflCDndbBvBS86mZXJZuuqiEHRil2c1BDHN9E7LpkKRMZs94N/3GnfNQ5BNxgy49c/SeaEvxpuaqeMKs/sLj0o/Aln1q+dxAqntjLaz1Yi+eyNGrM+BGIBoDdbZHYoVhy8infcJKrnMJmUDZa5/a0T/xCeIqbRaBpaz/ZK7KLXBRHZTNsSYajchllCEtJ2RUtFjzr6BBlBTgPiIsp2cw35Yuwjmb7H2G8aGG9oA3vCAiOSsA9V+bE3C X-MS-Exchange-AntiSpam-MessageData: GJwkO+K0j7hfd48jeRRY9zi8lQ8YaxCaIuZerntX1BoaohJAseGKCq6a80XSR5uS7PsMYUV4/98DllYc+TgflQXyZrfpk9aTrO8qWLg81UXzJMPOo8p0T5Ko1jttVm6Sp0qAPs35EIznH566tJ453acWXXuIfuuF/BquUuV4PcoN4/F043CpjLCZ3X3ZZJ7LXLacNuYiYgXnEc6fRFYfdWaeLSXr/OxB0wfMFlgC+sVkFe3Y3DWxxJgXxcyYntMUx1/Kq70U4/ItTZJTqqNufLGpA6FL5SyVkS4+eI9VtquxL2fnUNiu83Nd6hFTm4q41rI/frCCcZ9DCx/nMzAmFyyUBPL53OlLucyp/fGyfnGFP86XOReOy/fKk3eWafDrnjx1YZ6yIfGVX5PBdqXO+2trJbO5A6peV8P2jUmMF7Nx4ANrYu4PWWSFmgOAKsapXObWehAnV4PbuZWyLzjmg+A8DiqpuO4rCBGhgCd5ctalaJh/4wTtnhMrrwmz9xgnBoVwX2RRzGeCI2s8fabM9ezy5SKiAzJ7R3/J8CmLkFNesIZf997QmkL0HVy4S5cz/x0KA0WFRNs31yLKzEGLBagc1bTgyIpqIJA34WUfU8i9BdIKyJIh1SfxRzC1NjO9nN06TA4nFHXBWgosh2oQIGrBu0Dwp/pLqDxa08MrtymBV0MizKxADcXrbEvfthaL3bjuMsl2+O+T+QoojgRSKKopNuFwgpomoOGBSfadiE0sysm//PLfV42dugIQ1iX4b3aRDTGqfHAlRBpFuFvn1YXfJm3TkEJ8vqBpdzzMEOE= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4e2ff1f-21ce-44a9-51ad-08d7ecca8ccd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2020 05:51:38.8757 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tmtpqlWOLyFBx1ScjweFj1wU7IzLOOrFVewwD6alxoItDoRAsqSaoqr/4uTB/m3L8iE4ehhfIshqyKUlLk6HIg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4429 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Pankaj Bansal The SOC takes primary clocking input from the external signal (a clock generator on board). The input (frequency) is multiplied using multiple phase locked loops (PLL) to create a variety of frequencies which can then be passed to a variety of internal logic, including cores and peripheral IP modules. Therefore, move the clock retrieval APIs to Platform Lib. The Input clock is retrieved from board components in Platform Lib, and passed on to SOC Lib APIs to get the correct clock for an IP (after PLL multiplication). Signed-off-by: Pankaj Bansal Reviewed-by: Leif Lindholm --- Notes: V4: - fixed line adds whitespace error in NxpPlatformGetClock.h =20 V3: - sorted NXP_IP_CLOCK enum alphabetically Silicon/NXP/Library/SocLib/LS1043aSocLib.inf | 1 + Silicon/NXP/Include/Library/SocLib.h | 44 ++= +++++++++++++++ Silicon/NXP/Include/Ppi/NxpPlatformGetClock.h | 52 ++= ++++++++++++++++++ Silicon/NXP/LS1043A/Include/Soc.h | 11 ++= +++ Platform/NXP/LS1043aRdbPkg/Library/ArmPlatformLib/ArmPlatformLib.c | 51 ++= +++++++++++++++++ Silicon/NXP/Library/SocLib/Chassis2/Soc.c | 52 ++= ++++++++++++++++++ 6 files changed, 211 insertions(+) diff --git a/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf b/Silicon/NXP/Lib= rary/SocLib/LS1043aSocLib.inf index 99d89498e0e2..3d38a7e58b91 100644 --- a/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf +++ b/Silicon/NXP/Library/SocLib/LS1043aSocLib.inf @@ -17,6 +17,7 @@ ArmPkg/ArmPkg.dec MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec + Silicon/NXP/LS1043A/LS1043A.dec Silicon/NXP/NxpQoriqLs.dec =20 [LibraryClasses] diff --git a/Silicon/NXP/Include/Library/SocLib.h b/Silicon/NXP/Include/Lib= rary/SocLib.h new file mode 100644 index 000000000000..fc4d786c710b --- /dev/null +++ b/Silicon/NXP/Include/Library/SocLib.h @@ -0,0 +1,44 @@ +/** @file + + Copyright 2020 NXP + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SOC_LIB_H__ +#define SOC_LIB_H__ + +#include +#include + +/** + Return the input clock frequency to an IP Module. + This function reads the RCW bits and calculates the PLL multiplier/divi= der + values to be applied to various IP modules. + If a module is disabled or doesn't exist on platform, then return zero. + + @param[in] BaseClock Base clock to which PLL multiplier/divider values= is + to be applied. + @param[in] ClockType Variable of Type NXP_IP_CLOCK. Indicates which IP= clock + is to be retrieved. + @param[in] Args Variable argument list which is parsed based on + ClockType. e.g. if the ClockType is NXP_I2C_CLOCK= , then + the second argument will be interpreted as contro= ller + number. e.g. if there are four i2c controllers in= SOC, + then this value can be 0, 1, 2, 3 + e.g. if ClockType is NXP_CORE_CLOCK, then second + argument is interpreted as cluster number and thi= rd + argument is interpreted as core number (within th= e + cluster) + + @return Actual Clock Frequency. Return value 0 should be + interpreted as clock not being provided to IP. +**/ +UINT64 +SocGetClock ( + IN UINT64 BaseClock, + IN NXP_IP_CLOCK ClockType, + IN VA_LIST Args + ); + +#endif // SOC_LIB_H__ diff --git a/Silicon/NXP/Include/Ppi/NxpPlatformGetClock.h b/Silicon/NXP/In= clude/Ppi/NxpPlatformGetClock.h new file mode 100644 index 000000000000..8431148acb9f --- /dev/null +++ b/Silicon/NXP/Include/Ppi/NxpPlatformGetClock.h @@ -0,0 +1,52 @@ +/** @file +* +* Copyright 2020 NXP +* +* SPDX-License-Identifier: BSD-2-Clause-Patent +* +**/ + +#ifndef NXP_PLATFORM_PPI_H__ +#define NXP_PLATFORM_PPI_H__ + +#include + +typedef enum _NXP_IP_CLOCK { + NXP_CORE_CLOCK, + NXP_I2C_CLOCK, + NXP_SYSTEM_CLOCK, + NXP_UART_CLOCK +} NXP_IP_CLOCK; + +/** + Get the clocks supplied by Platform(Board) to NXP Layerscape SOC IPs + + @param[in] ClockType Variable of Type NXP_IP_CLOCK. Indicates which IP= clock + is to be retrieved. + @param[in] ... Variable argument list which is parsed based on + ClockType. e.g. if the ClockType is NXP_I2C_CLOCK= , then + the second argument will be interpreted as contro= ller + number. e.g. if there are four i2c controllers in= SOC, + then this value can be 0, 1, 2, 3 + e.g. if ClockType is NXP_CORE_CLOCK, then second + argument is interpreted as cluster number and thi= rd + argument is interpreted as core number (within th= e + cluster) + + @return Actual Clock Frequency. Return value 0 should be + interpreted as clock not being provided to IP. +**/ +typedef +UINT64 +(EFIAPI * NXP_PLATFORM_GET_CLOCK)( + IN NXP_IP_CLOCK ClockType, + ... + ); + +typedef struct { + NXP_PLATFORM_GET_CLOCK PlatformGetClock; +} NXP_PLATFORM_GET_CLOCK_PPI; + +extern NXP_PLATFORM_GET_CLOCK_PPI gPlatformGetClockPpi; + +#endif // NXP_PLATFORM_PPI_H__ diff --git a/Silicon/NXP/LS1043A/Include/Soc.h b/Silicon/NXP/LS1043A/Includ= e/Soc.h index 441871757d67..e62de570da8a 100644 --- a/Silicon/NXP/LS1043A/Include/Soc.h +++ b/Silicon/NXP/LS1043A/Include/Soc.h @@ -8,6 +8,8 @@ #ifndef SOC_H__ #define SOC_H__ =20 +#include + /** Soc Memory Map **/ @@ -41,4 +43,13 @@ #define LS1043A_I2C_SIZE 0x10000 #define LS1043A_I2C_NUM_CONTROLLERS 4 =20 +#define LS1043A_DCFG_ADDRESS CHASSIS2_DCFG_ADDRESS + +/** + Reset Control Word (RCW) Bits +**/ +#define SYS_PLL_RAT(x) (((x) & 0x7c) >> 2) // Bits 2-6 + +typedef CCSR_GUR LS1043A_DEVICE_CONFIG; + #endif // SOC_H__ diff --git a/Platform/NXP/LS1043aRdbPkg/Library/ArmPlatformLib/ArmPlatformL= ib.c b/Platform/NXP/LS1043aRdbPkg/Library/ArmPlatformLib/ArmPlatformLib.c index 718c71bf02eb..7f5872a78cfc 100644 --- a/Platform/NXP/LS1043aRdbPkg/Library/ArmPlatformLib/ArmPlatformLib.c +++ b/Platform/NXP/LS1043aRdbPkg/Library/ArmPlatformLib/ArmPlatformLib.c @@ -12,10 +12,60 @@ **/ =20 #include +#include #include +#include =20 extern VOID SocInit (VOID); =20 +/** + Get the clocks supplied by Platform(Board) to NXP Layerscape SOC IPs + + @param[in] ClockType Variable of Type NXP_IP_CLOCK. Indicates which IP= clock + is to be retrieved. + @param[in] ... Variable argument list which is parsed based on + ClockType. e.g. if the ClockType is NXP_I2C_CLOCK= , then + the second argument will be interpreted as contro= ller + number. + if ClockType is NXP_CORE_CLOCK, then second argum= ent + is interpreted as cluster number and third argume= nt is + interpreted as core number (within the cluster) + + @return Actual Clock Frequency. Return value 0 should be + interpreted as clock not being provided to IP. +**/ +UINT64 +EFIAPI +NxpPlatformGetClock( + IN UINT32 ClockType, + ... + ) +{ + UINT64 Clock; + VA_LIST Args; + + Clock =3D 0; + + VA_START (Args, ClockType); + + switch (ClockType) { + case NXP_SYSTEM_CLOCK: + Clock =3D 100 * 1000 * 1000; // 100 MHz + break; + case NXP_I2C_CLOCK: + case NXP_UART_CLOCK: + Clock =3D NxpPlatformGetClock (NXP_SYSTEM_CLOCK); + Clock =3D SocGetClock (Clock, ClockType, Args); + break; + default: + break; + } + + VA_END (Args); + + return Clock; +} + /** Return the current Boot Mode =20 @@ -69,6 +119,7 @@ PrePeiCoreGetMpCoreInfo ( } =20 ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi =3D { PrePeiCoreGetMpCoreInfo }; +NXP_PLATFORM_GET_CLOCK_PPI gPlatformGetClockPpi =3D { NxpPlatformGetClock = }; =20 EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] =3D { { diff --git a/Silicon/NXP/Library/SocLib/Chassis2/Soc.c b/Silicon/NXP/Librar= y/SocLib/Chassis2/Soc.c index 98ca2e162f7b..973ae630440b 100644 --- a/Silicon/NXP/Library/SocLib/Chassis2/Soc.c +++ b/Silicon/NXP/Library/SocLib/Chassis2/Soc.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include =20 /** Calculate the frequency of various controllers and @@ -50,6 +52,56 @@ GetSysInfo ( CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK; } =20 +/** + Return the input clock frequency to an IP Module. + This function reads the RCW bits and calculates the PLL multiplier/divi= der + values to be applied to various IP modules. + If a module is disabled or doesn't exist on platform, then return zero. + + @param[in] BaseClock Base clock to which PLL multiplier/divider values= is + to be applied. + @param[in] ClockType Variable of Type NXP_IP_CLOCK. Indicates which IP= clock + is to be retrieved. + @param[in] Args Variable argument list which is parsed based on + ClockType. e.g. if the ClockType is NXP_I2C_CLOCK= , then + the second argument will be interpreted as contro= ller + number. e.g. if there are four i2c controllers in= SOC, + then this value can be 0, 1, 2, 3 + e.g. if ClockType is NXP_CORE_CLOCK, then second + argument is interpreted as cluster number and thi= rd + argument is interpreted as core number (within th= e + cluster) + + @return Actual Clock Frequency. Return value 0 should be + interpreted as clock not being provided to IP. +**/ +UINT64 +SocGetClock ( + IN UINT64 BaseClock, + IN NXP_IP_CLOCK ClockType, + IN VA_LIST Args + ) +{ + LS1043A_DEVICE_CONFIG *Dcfg; + UINT32 RcwSr; + UINT64 ReturnValue; + + ReturnValue =3D 0; + Dcfg =3D (LS1043A_DEVICE_CONFIG *)LS1043A_DCFG_ADDRESS; + + switch (ClockType) { + case NXP_UART_CLOCK: + case NXP_I2C_CLOCK: + RcwSr =3D GurRead ((UINTN)&Dcfg->RcwSr[0]); + ReturnValue =3D BaseClock * SYS_PLL_RAT (RcwSr); + break; + default: + break; + } + + return ReturnValue; +} + /** Function to initialize SoC specific constructs **/ --=20 2.17.1