From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=92.121.34.13; helo=inva020.nxp.com; envelope-from=meenakshi.aggarwal@nxp.com; receiver=edk2-devel@lists.01.org Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5952121CB74A4 for ; Wed, 28 Nov 2018 01:16:30 -0800 (PST) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 1ED3A1A0309; Wed, 28 Nov 2018 10:16:29 +0100 (CET) Received: from inv0113.in-blr01.nxp.com (inv0113.in-blr01.nxp.com [165.114.116.118]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id BD6C41A02ED; Wed, 28 Nov 2018 10:16:28 +0100 (CET) Received: from uefi-OptiPlex-790.ap.freescale.net (uefi-OptiPlex-790.ap.freescale.net [10.232.132.78]) by inv0113.in-blr01.nxp.com (Postfix) with ESMTP id 2437B35F; Wed, 28 Nov 2018 14:46:28 +0530 (IST) From: Meenakshi Aggarwal To: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, michael.d.kinney@intel.com, edk2-devel@lists.01.org Date: Wed, 28 Nov 2018 20:31:45 +0530 Message-Id: <1543417315-5763-32-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1543417315-5763-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1518771035-6733-1-git-send-email-meenakshi.aggarwal@nxp.com> <1543417315-5763-1-git-send-email-meenakshi.aggarwal@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [PATCH edk2-platforms 31/41] Platform/NXP: LS2088 RDB Board FPGA library X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Nov 2018 09:16:30 -0000 From: Wasim Khan Library to provide functions for accessing FPGA on LS2088ARDB board. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wasim Khan --- .../NXP/LS2088aRdbPkg/Include/Library/FpgaLib.h | 166 +++++++++++++++++++++ .../NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.c | 115 ++++++++++++++ .../NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.inf | 31 ++++ 3 files changed, 312 insertions(+) create mode 100644 Platform/NXP/LS2088aRdbPkg/Include/Library/FpgaLib.h create mode 100644 Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.c create mode 100644 Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.inf diff --git a/Platform/NXP/LS2088aRdbPkg/Include/Library/FpgaLib.h b/Platform/NXP/LS2088aRdbPkg/Include/Library/FpgaLib.h new file mode 100644 index 0000000..84d1f02 --- /dev/null +++ b/Platform/NXP/LS2088aRdbPkg/Include/Library/FpgaLib.h @@ -0,0 +1,166 @@ +/** FpgaLib.h +* Header defining the LS2088a Fpga specific constants (Base addresses, sizes, flags) +* +* Copyright 2017-2018 NXP +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef __LS2088A_FPGA_H__ +#define __LS2088A_FPGA_H__ + +typedef enum { + CLK_66, + CLK_83, + CLK_100, + CLK_125, + CLK_133 +} SYSTEM_CLOCK; + +/* + * FPGA register set of LS2088ARDB board-specific. + */ +typedef struct { + UINT8 Id; // ID value uniquely identifying each QorIQ board type + UINT8 Arch; // Board Version + UINT8 Ver; // FPGA Version + UINT8 Model; // Programming Model + UINT8 Minor; // Minor Revision Number + UINT8 CtlSys; + UINT8 Aux; + UINT8 ClkSpd; + UINT8 StatDut; + UINT8 StatSys; + UINT8 StatAlrm; + UINT8 Present; + UINT8 Present2; + UINT8 RcwCtl; + UINT8 CtlLed; + UINT8 I2cBlk; + UINT8 RcfgCtl; + UINT8 RcfgSt; + UINT8 DcmAd; + UINT8 DcmDa; + UINT8 Dcmd; + UINT8 Dmsg; + UINT8 Gdc; + UINT8 Gdd; + UINT8 Dmack; + UINT8 Res1[6]; + UINT8 Watch; + UINT8 PwrCtl[2]; + UINT8 Res2[2]; + UINT8 PwrStat[4]; + UINT8 Res3[8]; + UINT8 ClkSpd2[2]; + UINT8 Res4[2]; + UINT8 Sclk[3]; + UINT8 Res5; + UINT8 Dclk[3]; + UINT8 Res6; + UINT8 ClkDspd[3]; + UINT8 Res7; + UINT8 RstCtl; + UINT8 RstStat; + UINT8 RstRsn; + UINT8 RstFrc[2]; + UINT8 Res8[11]; + UINT8 BrdCfg[16]; + UINT8 DutCfg[16]; + UINT8 RcwAd[2]; + UINT8 RcwData; + UINT8 Res9[5]; + UINT8 PostCtl; + UINT8 PostStat; + UINT8 PostDat[2]; + UINT8 Pid[4]; + UINT8 GpioIo[4]; + UINT8 GpioDir[4]; + UINT8 Res10[20]; + UINT8 RjtagCtl; + UINT8 RjtagDat; + UINT8 Res11[2]; + UINT8 TrigSrc[4]; + UINT8 TrigDst[4]; + UINT8 TrigStat; + UINT8 Res12[3]; + UINT8 TrigCtr[4]; + UINT8 Res13[16]; + UINT8 ClkFreq[6]; + UINT8 ResC6[8]; + UINT8 ClkBase[2]; + UINT8 ResD0[8]; + UINT8 Cms[2]; + UINT8 ResC0[6]; + UINT8 Aux2[4]; + UINT8 Res14[10]; + UINT8 AuxAd; + UINT8 AuxDa; + UINT8 Res15[16]; +} FPGA_REG_SET; + +/** + Function to read FPGA register. +**/ +UINT8 +FpgaRead ( + UINTN Reg + ); + +/** + Function to write FPGA register. +**/ +VOID +FpgaWrite ( + UINTN Reg, + UINT8 Value + ); + +/** + Function to initialize FPGA timings. +**/ +VOID +FpgaInit ( + VOID + ); + +/** + Function to get system clock frequency. +**/ +UINTN +GetBoardSysClk ( + VOID + ); + +/** + Function to print board personality. +**/ +VOID +PrintBoardPersonality ( + VOID + ); + +#define FPGA_BASE_PHYS 0x520000000 + +//SYSCLK +#define FPGA_CLK_MASK 0x0F // FPGA Clock Mask +#define SYSCLK_66_MHZ 66000000 +#define SYSCLK_83_MHZ 83000000 +#define SYSCLK_100_MHZ 100000000 +#define SYSCLK_125_MHZ 125000000 +#define SYSCLK_133_MHZ 133000000 + +#define FPGA_VBANK_MASK 0x07 +#define FPGA_CS_MASK 0x08 + +#define FPGA_READ(Reg) FpgaRead (OFFSET_OF (FPGA_REG_SET, Reg)) +#define FPGA_WRITE(Reg, Value) FpgaWrite (OFFSET_OF (FPGA_REG_SET, Reg), Value) + +#endif // __LS2088A_FPGA_H__ diff --git a/Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.c b/Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.c new file mode 100644 index 0000000..8948c21 --- /dev/null +++ b/Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.c @@ -0,0 +1,115 @@ +/** @FpgaLib.c + Fpga Library for LS2088A-RDB board, containing functions to + program and read the Fpga registers. + + FPGA is connected to IFC Controller and so MMIO APIs are used + to read/write FPGA registers + + Copyright 2017-2018 NXP + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include + +/** + Function to read FPGA register. + + @param Reg Register offset of FPGA to read. + +**/ +UINT8 +FpgaRead ( + IN UINTN Reg + ) +{ + VOID *Base; + + Base = (VOID *)FPGA_BASE_PHYS; + + return MmioRead8 ((UINTN)(Base + Reg)); +} + +/** + Function to write FPGA register. + + @param Reg Register offset of FPGA to write. + @param Value Value to be written. + +**/ +VOID +FpgaWrite ( + IN UINTN Reg, + IN UINT8 Value + ) +{ + VOID *Base; + + Base = (VOID *)FPGA_BASE_PHYS; + + MmioWrite8 ((UINTN)(Base + Reg), Value); +} + +/** + Function to get board system clock frequency. + +**/ +UINTN +GetBoardSysClk ( + VOID + ) +{ + UINT8 SysclkConf; + SysclkConf = FPGA_READ (BrdCfg[1]); + switch (SysclkConf & FPGA_CLK_MASK) { + case CLK_66: + return SYSCLK_66_MHZ; + case CLK_83: + return SYSCLK_83_MHZ; + case CLK_100: + return SYSCLK_100_MHZ; + case CLK_125: + return SYSCLK_125_MHZ; + case CLK_133: + return SYSCLK_133_MHZ; + } + return SYSCLK_100_MHZ; +} + +/** + Function to print board personality. + +**/ +VOID +PrintBoardPersonality ( + VOID + ) +{ + UINT8 SwitchConf; + SwitchConf = FPGA_READ (Arch); + + DEBUG ((DEBUG_INFO, "Board Arch: V%d, ", SwitchConf >> 4)); + DEBUG ((DEBUG_INFO, "Board version: %c, boot from ", + (SwitchConf & 0xf) + 'A')); + + SwitchConf = FPGA_READ (BrdCfg[0]); + + if (SwitchConf & FPGA_CS_MASK) + DEBUG ((DEBUG_INFO, "NAND\n")); + else + DEBUG ((DEBUG_INFO, "vBank: %d\n", (SwitchConf & FPGA_VBANK_MASK))); + + DEBUG ((DEBUG_INFO, "FPGA: v%d.%d\n", FPGA_READ (Ver), + FPGA_READ (Minor))); +} diff --git a/Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.inf b/Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.inf new file mode 100644 index 0000000..e70723a --- /dev/null +++ b/Platform/NXP/LS2088aRdbPkg/Library/FpgaLib/FpgaLib.inf @@ -0,0 +1,31 @@ +# @FpgaLib.inf +# +# Copyright 2017-2018 NXP +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +[Defines] + INF_VERSION = 0x0001000A + BASE_NAME = FpgaLib + FILE_GUID = dd2ce2f3-f219-4b57-82fd-f1ff8ae8bf5a + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = FpgaLib + +[Sources.common] + FpgaLib.c + +[Packages] + MdePkg/MdePkg.dec + Platform/NXP/LS2088aRdbPkg/LS2088aRdbPkg.dec + Silicon/NXP/NxpQoriqLs.dec + +[LibraryClasses] + BaseLib + IoLib -- 1.9.1