From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) by mx.groups.io with SMTP id smtpd.web08.10586.1612983991876824498 for ; Wed, 10 Feb 2021 11:06:32 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=ytoG3RfZ; spf=pass (domain: nuviainc.com, ip: 209.85.128.50, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f50.google.com with SMTP id a16so4332312wmm.0 for ; Wed, 10 Feb 2021 11:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nwmATD/ihJT2FVUwxO3Ay91GLnUSShKinY87aikLzLg=; b=ytoG3RfZypkeZ3tSPxHm2N3UhTtrAxZqTywfqtcgpGmkE4Zgo9eYyPv5WyzUNHJmuu eZXvCKFH18u9LLxr+EW4ctkeXviwprZFuSuF6/a+JhefJ1r1ppWv7t02DOMo8ITuOvzx JN2WVLE3KVIB85kDJVKTTDbQ8Ds4iyCno5tTMwdp+vOd9v7Cia4ClBrRgTADiLfMyBtU v2rf0G5XmdvawHN2k+WK8w2syPrQYIkaEAA7G2ZMeYpkYQzWovqWKj4d643zhYtnWt7p iD8X9wLNEz9PpKcgc2i+TuqDOsHQmY/WOzMQvNoZQRvRf4V40x2VNdy4GaqPpPLCM7t/ CZkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=nwmATD/ihJT2FVUwxO3Ay91GLnUSShKinY87aikLzLg=; b=Vc6wjW+4/msIOStZ4UjA5UWRQBueYFy3y8QyEMVjAqh4Nrm+AAbm9gRwLemKqK5M0p 7uirdeLNgrCL2laOGTKMfK+LwN/dOm10XVfrOegXbIUO18W5WnAYtiC8nmG1tEj9QboX YEMDVVedObces6tFy9c51zeXSyKQi7OMQSUGaNJTMnzQBBs0NccIXTbDG8itqeycfFuQ 7SkGigUT18gZ7E+AC2EnLohX95UzlfYpM75KJy1zEigQPUAouAGpUNxo46N/tMQN6oBX 5+DznIFIiTNTZP5YbLZvonW5UtDnmcw8McYxnJ9NELo2P0U08fEqfLUTzqpLml8CEZst 2w0w== X-Gm-Message-State: AOAM530pdSVcLtdqMbZ0npXkgelE7c8xJKQfUIPvOflPOZ0J6gpvv5rg JymzubYY8VW3m1Ekudj4p5djyQ== X-Google-Smtp-Source: ABdhPJwTEzJ2QAX3kRSouwly6RcsDSb+FEnX0Z6ek91Ozic5Q876kCKMtJ5dHYx+CzVPDNU7sqCcmw== X-Received: by 2002:a05:600c:2f81:: with SMTP id t1mr399486wmn.186.1612983990253; Wed, 10 Feb 2021 11:06:30 -0800 (PST) Return-Path: Received: from vanye (cpc1-cmbg19-2-0-cust915.5-4.cable.virginm.net. [82.27.183.148]) by smtp.gmail.com with ESMTPSA id o124sm4071593wmb.5.2021.02.10.11.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Feb 2021 11:06:29 -0800 (PST) Date: Wed, 10 Feb 2021 19:06:28 +0000 From: "Leif Lindholm" To: Ling Jia Cc: devel@edk2.groups.io Subject: Re: [PATCH v1 06/10] Silicon/Phytium: Added Spi driver support to FT2000/4 Message-ID: <20210210190628.GR1664@vanye> References: <20210205100630.46848-1-jialing@phytium.com.cn> <20210205100630.46848-18-jialing@phytium.com.cn> MIME-Version: 1.0 In-Reply-To: <20210205100630.46848-18-jialing@phytium.com.cn> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Feb 05, 2021 at 18:06:26 +0800, Ling Jia wrote: > The SpiDxe is to provide Spi bus read-write interface. > > Signed-off-by: Ling Jia > --- > Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec | 9 + > Platform/Phytium/DurianPkg/DurianPkg.dsc | 5 + > Platform/Phytium/DurianPkg/DurianPkg.fdf | 2 + > Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf | 44 +++++ > Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h | 65 +++++++ > Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h | 51 +++++ > Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c | 196 ++++++++++++++++++++ > 7 files changed, 372 insertions(+) > > diff --git a/Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec b/Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec > index 48f430c88de6..69842b89e021 100644 > --- a/Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec > +++ b/Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec > @@ -38,4 +38,13 @@ [PcdsFixedAtBuild.common] > gPhytiumPlatformTokenSpaceGuid.PcdPciConfigBase|0x0|UINT64|0x00000002 > gPhytiumPlatformTokenSpaceGuid.PcdPciConfigSize|0x0|UINT64|0x00000003 > > + # > + # SPI Flash Controller Register Base Address and Size > + # > + gPhytiumPlatformTokenSpaceGuid.PcdSpiFlashBase|0x0|UINT64|0x00000004 > + gPhytiumPlatformTokenSpaceGuid.PcdSpiFlashSize|0x0|UINT64|0x00000005 > + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase|0x0|UINT64|0x00000006 > + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerSize|0x0|UINT64|0x00000007 > + > [Protocols] > + gSpiMasterProtocolGuid = { 0xdf093560, 0xf955, 0x11ea, { 0x96, 0x42, 0x43, 0x9d, 0x80, 0xdd, 0x0b, 0x7c}} > diff --git a/Platform/Phytium/DurianPkg/DurianPkg.dsc b/Platform/Phytium/DurianPkg/DurianPkg.dsc > index 8ca167329d99..68849d16a00c 100644 > --- a/Platform/Phytium/DurianPkg/DurianPkg.dsc > +++ b/Platform/Phytium/DurianPkg/DurianPkg.dsc > @@ -224,6 +224,11 @@ [Components.common] > # > ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf > > + # > + # Spi driver > + # > + Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf > + > # > # Usb Support > # > diff --git a/Platform/Phytium/DurianPkg/DurianPkg.fdf b/Platform/Phytium/DurianPkg/DurianPkg.fdf > index 96736693db83..f4f12a910d5a 100644 > --- a/Platform/Phytium/DurianPkg/DurianPkg.fdf > +++ b/Platform/Phytium/DurianPkg/DurianPkg.fdf > @@ -95,6 +95,8 @@ [FV.FvMain] > INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf > INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf > > + INF Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf > + > INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf > INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf > > diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf > new file mode 100644 > index 000000000000..738596372791 > --- /dev/null > +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf > @@ -0,0 +1,44 @@ > +#/** @file > +# Phytium Spi Master Drivers. > +# > +# Copyright (C) 2020, Phytium Technology Co,Ltd. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#**/ > + > +[Defines] > + INF_VERSION = 0x0001001b > + BASE_NAME = SpiDxe > + FILE_GUID = 2ba95e5c-f7f5-11ea-bf18-67fdc5787495 > + MODULE_TYPE = DXE_RUNTIME_DRIVER > + VERSION_STRING = 1.0 > + ENTRY_POINT = SpiMasterDrvEntryPoint > + > +[Sources.common] > + SpiDxe.c > + SpiDxe.h > + > +[Packages] > + ArmPkg/ArmPkg.dec > + MdePkg/MdePkg.dec > + Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec > + > +[LibraryClasses] > + BaseLib > + DebugLib > + IoLib > + UefiLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + > +[Guids] > + > +[Protocols] > + gSpiMasterProtocolGuid > + > +[FixedPcd] > + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase > + > +[Depex] > + TRUE > diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h > new file mode 100644 > index 000000000000..cdca471412e9 > --- /dev/null > +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h > @@ -0,0 +1,65 @@ > +/** @file > + Phytium Spi Drivers Header > + > + Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef SPI_DXE_H_ > +#define SPI_DXE_H_ > + > +#include > +#include Change order of above two includes. > +#include > +#include > +#include > +#include > + > +#define SPI_MASTER_SIGNATURE SIGNATURE_32 ('M', 'S', 'P', 'I') > + > +#define REG_MODE_REG 0x02C > + > +EFI_STATUS > +EFIAPI > +SpiMasterGetConfig ( > + IN UINT8 CmdId, > + OUT UINT32 *Config, > + IN UINTN RegAddr > + ); > + > +EFI_STATUS > +EFIAPI > +SpiMasterSetConfig ( > + IN UINT8 CmdId, > + IN UINT32 Config, > + IN UINTN RegAddr > + ); > + > +EFI_STATUS > +EFIAPI > +SpiMasterSetMode ( > + IN UINT32 Config > + ); > + > +EFI_STATUS > +EFIAPI > +SpiMasterInit ( > + VOID > + ); > + > +typedef struct { > + EFI_SPI_DRV_PROTOCOL SpiMasterProtocol; > + UINTN Signature; > + EFI_HANDLE Handle; > + } PHYT_SPI_MASTER; > + > +EFI_STATUS > +EFIAPI > +SpiMasterDrvEntryPoint ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ); > + > +#endif // SPI_DXE_H_ > diff --git a/Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h b/Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h > new file mode 100644 > index 000000000000..3ed64d1a5dd7 > --- /dev/null > +++ b/Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h > @@ -0,0 +1,51 @@ > +/** @file > + The Header of Protocol For SPI. > + > + Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef SPI_H_ > +#define SPI_H_ > + > +extern EFI_GUID gSpiMasterProtocolGuid; > +typedef struct _EFI_SPI_DRV_PROTOCOL EFI_SPI_DRV_PROTOCOL; > + > +typedef > +EFI_STATUS > +(EFIAPI *SPI_DRV_INIT_INTERFACE) ( > + VOID > + ); > + > +typedef > +EFI_STATUS > +(EFIAPI *SPI_DRV_SET_CONFIG_INTERFACE)( > + IN UINT8 CmdId, > + IN UINT32 Config, > + IN UINTN RegAddr > + ); > + > +typedef > +EFI_STATUS > +(EFIAPI *SPI_DRV_GET_CONFIG_INTERFACE)( > + IN UINT8 CmdId, > + OUT UINT32 *Config, > + IN UINTN RegAddr > + ); > + > +typedef > +EFI_STATUS > +(EFIAPI *SPI_DRV_CONFIG_MODE_INTERFACE)( > + IN UINT32 Config > + ); > + > +struct _EFI_SPI_DRV_PROTOCOL{ > + SPI_DRV_INIT_INTERFACE SpiInit; > + SPI_DRV_SET_CONFIG_INTERFACE SpiSetConfig; > + SPI_DRV_GET_CONFIG_INTERFACE SpiGetConfig; > + SPI_DRV_CONFIG_MODE_INTERFACE SpiSetMode; > +}; > + > +#endif // SPI_H_ > diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c > new file mode 100644 > index 000000000000..d86e971818f2 > --- /dev/null > +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c > @@ -0,0 +1,196 @@ > +/** @file > + Phytium Spi Master Drivers. > + > + Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include "SpiDxe.h" > + > +PHYT_SPI_MASTER *pSpiMasterInstance; > +static UINTN mSpiControlBase; > + > +/** > + This function inited a spi driver. > + > + @param None. > + > + @retval None. > + > +**/ > +EFI_STATUS > +EFIAPI > +SpiMasterInit ( > + VOID > + ) > +{ > + return EFI_SUCCESS; > +} > + > + > +/** > + This function seted config to spi registers. > + > + @param[in] CmdId The id of command. > + > + @param[in] Config The value to be seted. > + > + @param[in] RegAddr The address of spi registers. > + > + @retval EFI_SUCCESS SpiMasterSetConfig() is executed successfully. > + > +**/ > +EFI_STATUS > +EFIAPI > +SpiMasterSetConfig ( > + IN UINT8 CmdId, > + IN UINT32 Config, > + IN UINTN RegAddr > + ) > +{ > + UINTN SpiAddr; > + UINT32 Value; > + > + SpiAddr = 0; > + Value = 0; > + > + if (CmdId != 0) > + Value = (CmdId << 24) | (Config & 0xffffff); > + else > + Value = Config; Always use braces: if (){ } else { } > + > + SpiAddr = mSpiControlBase + RegAddr; > + MmioWrite32 (SpiAddr, Value); > + > + return EFI_SUCCESS; > +} > + > + > +/** > + This function geted config from spi registers. > + > + @param[in] CmdId The id of command. > + > + @param[out] Config The pointer of the config. > + > + @param[in] RegAddr The address of spi registers. > + > + @retval EFI_SUCCESS SpiMasterGetConfig() is executed successfully. > + > +**/ > +EFI_STATUS > +EFIAPI > +SpiMasterGetConfig ( > + IN UINT8 CmdId, > + OUT UINT32 *Config, > + IN UINTN RegAddr > + ) > +{ > + UINTN SpiAddr; > + UINT32 Value; > + > + SpiAddr = 0; > + Value = 0; > + > + SpiAddr = mSpiControlBase + RegAddr; > + Value = MmioRead32 (SpiAddr); > + > + if (CmdId != 0) > + *Config = Value & 0xffffff; > + else > + *Config = Value; Use braces. / Leif > + > + return EFI_SUCCESS; > +} > + > + > +/** > + This function seted spi mode. > + > + @param[in] Config The value to seted. > + > + @retval EFI_SUCCESS SpiMasterSetMode() is executed successfully. > + > +**/ > +EFI_STATUS > +EFIAPI > +SpiMasterSetMode ( > + IN UINT32 Config > + ) > +{ > + > + SpiMasterSetConfig (0, Config, REG_MODE_REG); > + > + return EFI_SUCCESS; > +} > + > + > +/** > + This function inited the spi driver protocol. > + > + @param[in] SpiMasterProtocol A pointer to the master protocol struct. > + > + @retval EFI_SUCCESS SpiMasterInitProtocol() is executed successfully. > + > +**/ > +STATIC > +EFI_STATUS > +EFIAPI > +SpiMasterInitProtocol ( > + IN EFI_SPI_DRV_PROTOCOL *SpiMasterProtocol > + ) > +{ > + > + SpiMasterProtocol->SpiInit = SpiMasterInit; > + SpiMasterProtocol->SpiSetConfig = SpiMasterSetConfig; > + SpiMasterProtocol->SpiGetConfig = SpiMasterGetConfig; > + SpiMasterProtocol->SpiSetMode = SpiMasterSetMode; > + > + return EFI_SUCCESS; > +} > + > + > +/** > + This function is the entrypoint of the spi driver. > + > + @param[in] ImageHandle The firmware allocated handle for the EFI image. > + > + @param[in] SystemTable A pointer to the EFI System Table. > + > + @retval EFI_SUCCESS The entry point is executed successfully. > + > + @retval other Some error occurs when executing this entry point. > + > +**/ > +EFI_STATUS > +EFIAPI > +SpiMasterDrvEntryPoint ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + > + pSpiMasterInstance = AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER)); > + if (pSpiMasterInstance == NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + > + mSpiControlBase = FixedPcdGet64 (PcdSpiControllerBase); > + > + SpiMasterInitProtocol (&pSpiMasterInstance->SpiMasterProtocol); > + > + pSpiMasterInstance->Signature = SPI_MASTER_SIGNATURE; > + > + Status = gBS->InstallMultipleProtocolInterfaces ( > + &(pSpiMasterInstance->Handle), > + &gSpiMasterProtocolGuid, > + &(pSpiMasterInstance->SpiMasterProtocol), > + NULL > + ); > + ASSERT_EFI_ERROR (Status); > + > + return EFI_SUCCESS; > +} > -- > 2.25.1 >