From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from azure-sdnproxy-2.icoremail.net (azure-sdnproxy-2.icoremail.net [52.229.168.213]) by mx.groups.io with SMTP id smtpd.web09.5288.1631180987143540074 for ; Thu, 09 Sep 2021 02:49:47 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: phytium.com.cn, ip: 52.229.168.213, mailfrom: jialing@phytium.com.cn) Received: from prodtpl.icoremail.net (unknown [10.12.1.20]) by hzbj-icmmx-2 (Coremail) with SMTP id AQAAfwBnkdHU2Dlh0ehuAg--.42343S2; Thu, 09 Sep 2021 17:50:12 +0800 (CST) Received: from localhost.localdomain (unknown [223.104.131.170]) by mail (Coremail) with SMTP id AQAAfwBXEie32DlhvRIAAA--.679S2; Thu, 09 Sep 2021 17:49:43 +0800 (CST) From: "Ling Jia" To: devel@edk2.groups.io Cc: Leif Lindholm , Ling Jia Subject: [PATCH v5 06/10] Silicon/Phytium: Added Spi driver support to FT2000/4 Date: Thu, 9 Sep 2021 17:49:34 +0800 Message-Id: <20210909094938.5998-1-jialing@phytium.com.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAfwBXEie32DlhvRIAAA--.679S2 X-CM-SenderInfo: xmldzxdqj61x51wl3zoofrzhdfq/ Authentication-Results: hzbj-icmmx-2; spf=neutral smtp.mail=jialing@ph ytium.com.cn; X-Coremail-Antispam: 1Uk129KBjvJXoW3ZFWkGF1fWr4fKF4rGr1xKrg_yoWDKrW8pF 47trsIgr48Gr4aqw4rX340grs5A3s09a4DKrsxWFy5uFs8WFy8Xa1qyry5Ja4qqr1qyFW8 WFsYqw1Uur1qyw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAU7a7-sFnT9fnUUIcSsGvfJ3UbIYCTnIWIevJa73UjIFyTuYvj4RJUUU UUUUU Content-Transfer-Encoding: quoted-printable The SpiDxe is to provide Spi bus read-write interfaces. Signed-off-by: Ling Jia Reviewed-by: Leif Lindholm --- 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 | 59 ++++= ++ Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h | 51 +++++ Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c | 202 ++++= ++++++++++++++++ 7 files changed, 372 insertions(+) diff --git a/Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec b/Silico= n/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec index 48f430c88d..69842b89e0 100644 --- a/Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec +++ b/Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec @@ -38,4 +38,13 @@ gPhytiumPlatformTokenSpaceGuid.PcdPciConfigBase|0x0|UINT64|0x00000002=0D gPhytiumPlatformTokenSpaceGuid.PcdPciConfigSize|0x0|UINT64|0x00000003=0D =0D + #=0D + # SPI Flash Controller Register Base Address and Size=0D + #=0D + gPhytiumPlatformTokenSpaceGuid.PcdSpiFlashBase|0x0|UINT64|0x00000004=0D + gPhytiumPlatformTokenSpaceGuid.PcdSpiFlashSize|0x0|UINT64|0x00000005=0D + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase|0x0|UINT64|0x0000000= 6=0D + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerSize|0x0|UINT64|0x0000000= 7=0D +=0D [Protocols]=0D + gSpiMasterProtocolGuid =3D { 0xdf093560, 0xf955, 0x11ea, { 0x96, 0x42, 0= x43, 0x9d, 0x80, 0xdd, 0x0b, 0x7c}}=0D diff --git a/Platform/Phytium/DurianPkg/DurianPkg.dsc b/Platform/Phytium/Du= rianPkg/DurianPkg.dsc index 3a9bc2289c..68698d613f 100644 --- a/Platform/Phytium/DurianPkg/DurianPkg.dsc +++ b/Platform/Phytium/DurianPkg/DurianPkg.dsc @@ -244,6 +244,11 @@ #=0D ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf=0D =0D + #=0D + # Spi driver=0D + #=0D + Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf=0D +=0D #=0D # Usb Support=0D #=0D diff --git a/Platform/Phytium/DurianPkg/DurianPkg.fdf b/Platform/Phytium/Du= rianPkg/DurianPkg.fdf index a443d0f3a4..1cf1927484 100644 --- a/Platform/Phytium/DurianPkg/DurianPkg.fdf +++ b/Platform/Phytium/DurianPkg/DurianPkg.fdf @@ -95,6 +95,8 @@ READ_LOCK_STATUS =3D TRUE INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf=0D INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf=0D =0D + INF Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf=0D +=0D INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf=0D INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRu= ntimeDxe.inf=0D =0D diff --git a/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf b/Silico= n/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf new file mode 100644 index 0000000000..21d75f268d --- /dev/null +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf @@ -0,0 +1,44 @@ +#/** @file=0D +# Phytium Spi Master Drivers.=0D +#=0D +# Copyright (C) 2020, Phytium Technology Co, Ltd. All rights reserved.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +#**/=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x0001001b=0D + BASE_NAME =3D SpiDxe=0D + FILE_GUID =3D 2ba95e5c-f7f5-11ea-bf18-67fdc5787495= =0D + MODULE_TYPE =3D DXE_RUNTIME_DRIVER=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D SpiMasterDrvEntryPoint=0D +=0D +[Sources.common]=0D + SpiDxe.c=0D + SpiDxe.h=0D +=0D +[Packages]=0D + ArmPkg/ArmPkg.dec=0D + MdePkg/MdePkg.dec=0D + Silicon/Phytium/PhytiumCommonPkg/PhytiumCommonPkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + DebugLib=0D + IoLib=0D + UefiLib=0D + UefiBootServicesTableLib=0D + UefiDriverEntryPoint=0D +=0D +[Guids]=0D +=0D +[Protocols]=0D + gSpiMasterProtocolGuid=0D +=0D +[FixedPcd]=0D + gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase=0D +=0D +[Depex]=0D + TRUE=0D 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 0000000000..8795ea238d --- /dev/null +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h @@ -0,0 +1,59 @@ +/** @file=0D + Phytium Spi Drivers Header=0D +=0D + Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
= =0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef SPI_DXE_H_=0D +#define SPI_DXE_H_=0D +=0D +#include =0D +=0D +#define SPI_MASTER_SIGNATURE SIGNATURE_32 ('M', 'S', 'P', 'I')=0D +#define REG_MODE_REG 0x02C=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterGetConfig (=0D + IN UINT8 CmdId,=0D + OUT UINT32 *Config,=0D + IN UINTN RegAddr=0D + );=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterSetConfig (=0D + IN UINT8 CmdId,=0D + IN UINT32 Config,=0D + IN UINTN RegAddr=0D + );=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterSetMode (=0D + IN UINT32 Config=0D + );=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterInit (=0D + VOID=0D + );=0D +=0D +typedef struct {=0D + EFI_SPI_DRV_PROTOCOL SpiMasterProtocol;=0D + UINTN Signature;=0D + EFI_HANDLE Handle;=0D +} PHYT_SPI_MASTER;=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterDrvEntryPoint (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + );=0D +=0D +#endif // SPI_DXE_H_=0D diff --git a/Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.= h b/Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h new file mode 100644 index 0000000000..3ed64d1a5d --- /dev/null +++ b/Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h @@ -0,0 +1,51 @@ +/** @file=0D + The Header of Protocol For SPI.=0D +=0D + Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
= =0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef SPI_H_=0D +#define SPI_H_=0D +=0D +extern EFI_GUID gSpiMasterProtocolGuid;=0D +typedef struct _EFI_SPI_DRV_PROTOCOL EFI_SPI_DRV_PROTOCOL;=0D +=0D +typedef=0D +EFI_STATUS=0D +(EFIAPI *SPI_DRV_INIT_INTERFACE) (=0D + VOID=0D + );=0D +=0D +typedef=0D +EFI_STATUS=0D +(EFIAPI *SPI_DRV_SET_CONFIG_INTERFACE)(=0D + IN UINT8 CmdId,=0D + IN UINT32 Config,=0D + IN UINTN RegAddr=0D + );=0D +=0D +typedef=0D +EFI_STATUS=0D +(EFIAPI *SPI_DRV_GET_CONFIG_INTERFACE)(=0D + IN UINT8 CmdId,=0D + OUT UINT32 *Config,=0D + IN UINTN RegAddr=0D + );=0D +=0D +typedef=0D +EFI_STATUS=0D +(EFIAPI *SPI_DRV_CONFIG_MODE_INTERFACE)(=0D + IN UINT32 Config=0D + );=0D +=0D +struct _EFI_SPI_DRV_PROTOCOL{=0D + SPI_DRV_INIT_INTERFACE SpiInit;=0D + SPI_DRV_SET_CONFIG_INTERFACE SpiSetConfig;=0D + SPI_DRV_GET_CONFIG_INTERFACE SpiGetConfig;=0D + SPI_DRV_CONFIG_MODE_INTERFACE SpiSetMode;=0D +};=0D +=0D +#endif // SPI_H_=0D 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 0000000000..7602a3e0cd --- /dev/null +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c @@ -0,0 +1,202 @@ +/** @file=0D + Phytium Spi Master Drivers.=0D +=0D + Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.
= =0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include "SpiDxe.h"=0D +=0D +PHYT_SPI_MASTER *pSpiMasterInstance;=0D +static UINTN mSpiControlBase;=0D +=0D +/**=0D + This function inited a spi driver.=0D +=0D + @param None.=0D +=0D + @retval None.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterInit (=0D + VOID=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + This function seted config to spi registers.=0D +=0D + @param[in] CmdId The id of command.=0D +=0D + @param[in] Config The value to be seted.=0D +=0D + @param[in] RegAddr The address of spi registers.=0D +=0D + @retval EFI_SUCCESS SpiMasterSetConfig() is executed successfully.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterSetConfig (=0D + IN UINT8 CmdId,=0D + IN UINT32 Config,=0D + IN UINTN RegAddr=0D + )=0D +{=0D + UINTN SpiAddr;=0D + UINT32 Value;=0D +=0D + SpiAddr =3D 0;=0D + Value =3D 0;=0D +=0D + if (CmdId !=3D 0) {=0D + Value =3D (CmdId << 24) | (Config & 0xffffff);=0D + } else {=0D + Value =3D Config;=0D + }=0D +=0D + SpiAddr =3D mSpiControlBase + RegAddr;=0D + MmioWrite32 (SpiAddr, Value);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + This function geted config from spi registers.=0D +=0D + @param[in] CmdId The id of command.=0D +=0D + @param[out] Config The pointer of the config.=0D +=0D + @param[in] RegAddr The address of spi registers.=0D +=0D + @retval EFI_SUCCESS SpiMasterGetConfig() is executed successfully.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterGetConfig (=0D + IN UINT8 CmdId,=0D + OUT UINT32 *Config,=0D + IN UINTN RegAddr=0D + )=0D +{=0D + UINTN SpiAddr;=0D + UINT32 Value;=0D +=0D + SpiAddr =3D 0;=0D + Value =3D 0;=0D +=0D + SpiAddr =3D mSpiControlBase + RegAddr;=0D + Value =3D MmioRead32 (SpiAddr);=0D +=0D + if (CmdId !=3D 0) {=0D + *Config =3D Value & 0xffffff;=0D + } else {=0D + *Config =3D Value;=0D + }=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + This function seted spi mode.=0D +=0D + @param[in] Config The value to seted.=0D +=0D + @retval EFI_SUCCESS SpiMasterSetMode() is executed successfully.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterSetMode (=0D + IN UINT32 Config=0D + )=0D +{=0D +=0D + SpiMasterSetConfig (0, Config, REG_MODE_REG);=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + This function inited the spi driver protocol.=0D +=0D + @param[in] SpiMasterProtocol A pointer to the master protocol struct.= =0D +=0D + @retval EFI_SUCCESS SpiMasterInitProtocol() is executed succ= essfully.=0D +=0D +**/=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterInitProtocol (=0D + IN EFI_SPI_DRV_PROTOCOL *SpiMasterProtocol=0D + )=0D +{=0D +=0D + SpiMasterProtocol->SpiInit =3D SpiMasterInit;=0D + SpiMasterProtocol->SpiSetConfig =3D SpiMasterSetConfig;=0D + SpiMasterProtocol->SpiGetConfig =3D SpiMasterGetConfig;=0D + SpiMasterProtocol->SpiSetMode =3D SpiMasterSetMode;=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D +=0D +/**=0D + This function is the entrypoint of the spi driver.=0D +=0D + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e.=0D +=0D + @param[in] SystemTable A pointer to the EFI System Table.=0D +=0D + @retval EFI_SUCCESS The entry point is executed successfully.=0D +=0D + @retval other Some error occurs when executing this entry po= int.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SpiMasterDrvEntryPoint (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + pSpiMasterInstance =3D AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER)= );=0D + if (pSpiMasterInstance =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + mSpiControlBase =3D FixedPcdGet64 (PcdSpiControllerBase);=0D +=0D + SpiMasterInitProtocol (&pSpiMasterInstance->SpiMasterProtocol);=0D +=0D + pSpiMasterInstance->Signature =3D SPI_MASTER_SIGNATURE;=0D +=0D + Status =3D gBS->InstallMultipleProtocolInterfaces (=0D + &(pSpiMasterInstance->Handle),=0D + &gSpiMasterProtocolGuid,=0D + &(pSpiMasterInstance->SpiMasterProtocol),=0D + NULL=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + return EFI_SUCCESS;=0D +}=0D --=20 2.25.1