From nobody Mon Feb 9 15:10:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+72979+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+72979+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1616006563; cv=none; d=zohomail.com; s=zohoarc; b=UDmxdOVVQPFFyFSZfuLXuCmcsA2HkyITL84T5LZWylEoF/YawsAd7dCYcB5rP8D0zKvVYC2MpnD6TNv8hFqRMfCA7yqf3qFh7LKEEa5CoEiZTLbJgmBqjnM9QdRT3iTd3GvTCJmGh44J2sS0VMaz//awKuOu2ajszFBWiRaHVsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616006563; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Yz2epH6XJgrNaWldFSH3JB3r7Vi3s6ZShtlsKnaB07A=; b=KW5kzqJrbBqOLBj4aLFh/lylw4Jqu+NJ3f5NIh2SjwmpVY8mNjc/tegs0c60HnqRT81N1Hdj+URZUzP2kpz39h0ZXCMtLKniM/G6UJHF21hUwEFsyIXuXPqZ1NERsixyNhb7urxpNdk1DhVjaQHbGAEufe6Umay8bgbm2ps1I5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+72979+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1616006563914235.09141649674325; Wed, 17 Mar 2021 11:42:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mFDEYY1788612xnRkqLccskm; Wed, 17 Mar 2021 11:42:43 -0700 X-Received: from zg8tmty1ljiyny4xntqumjca.icoremail.net (zg8tmty1ljiyny4xntqumjca.icoremail.net [165.227.154.27]) by mx.groups.io with SMTP id smtpd.web09.3184.1615966022772472974 for ; Wed, 17 Mar 2021 00:27:03 -0700 X-Received: from localhost.localdomain (unknown [223.153.147.73]) by c1app7 (Coremail) with SMTP id BwINCgB3HOE4r1FgGIYZAA--.29335S8; Wed, 17 Mar 2021 15:26:59 +0800 (CST) From: "Ling Jia" To: devel@edk2.groups.io Cc: Leif Lindholm , Ling Jia Subject: [edk2-devel] [PATCH v3 06/10] Silicon/Phytium: Added Spi driver support to FT2000/4 Date: Wed, 17 Mar 2021 15:26:43 +0800 Message-Id: <20210317072647.77340-7-jialing@phytium.com.cn> In-Reply-To: <20210317072647.77340-1-jialing@phytium.com.cn> References: <20210317072647.77340-1-jialing@phytium.com.cn> MIME-Version: 1.0 X-CM-TRANSID: BwINCgB3HOE4r1FgGIYZAA--.29335S8 X-Coremail-Antispam: 1UD129KBjvJXoW3CF15XrW3GrWUJFy5ArWDArb_yoWDKFWkpF 47trsIgr48Gr4avw4rX340grs5A3s09a4DKrsxWFy5ZFs0gFy8Xa1qyry5Ja4qqr4qyFW8 WFsYqw1Uur1qyw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBm14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr 1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE14v_GF4l42 xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWU GwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1Y6r17MIIYrxkI7VAKI4 8JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4U MIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I 8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU1zuWDUUUU X-CM-SenderInfo: xmldzxdqj61x51wl3zoofrzhdfq/ Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jialing@phytium.com.cn X-Gm-Message-State: yakJSfyDp86dOev6IYGqefisx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1616006563; bh=qdr+0ogEKh0tU5J8Y3UipbjfUFByhLT6axjH5f/xCmM=; h=Cc:Date:From:Reply-To:Subject:To; b=co8iAhl1Xif0t+IaSKjNk2IxdIw19tSediruTSOphzrHr2t3J2JR5gWKSwLCDsNgLBW 09IJNZ6XQaMfpE3UeYBSlP63aoMhvBtAqsBaRNQRdZjCJLkoZ6FTw1NWTaXHywSBwSbhL 6rqLxn+YNEo4+K/QBQqpDUZnzo22EKqDpIM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The SpiDxe is to provide Spi bus read-write interfaces. v3: Optimized the codes to conform to specifications. 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 | 64 ++++= +++ Silicon/Phytium/PhytiumCommonPkg/Include/Protocol/SpiProtocol.h | 51 +++++ Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c | 198 ++++= ++++++++++++++++ 7 files changed, 373 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 gPhytiumPlatformTokenSpaceGuid.PcdPciConfigSize|0x0|UINT64|0x00000003 =20 + # + # 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 =3D { 0xdf093560, 0xf955, 0x11ea, { 0x96, 0x42, 0= x43, 0x9d, 0x80, 0xdd, 0x0b, 0x7c}} 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 @@ # ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf =20 + # + # Spi driver + # + Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf + # # Usb Support # 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 INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf =20 + INF Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.inf + INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRu= ntimeDxe.inf =20 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 +# Phytium Spi Master Drivers. +# +# Copyright (C) 2020, Phytium Technology Co, Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION =3D 0x0001001b + BASE_NAME =3D SpiDxe + FILE_GUID =3D 2ba95e5c-f7f5-11ea-bf18-67fdc5787495 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D 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 0000000000..fbadd01921 --- /dev/null +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.h @@ -0,0 +1,64 @@ +/** @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 +#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 0000000000..3ed64d1a5d --- /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 0000000000..885bbd6361 --- /dev/null +++ b/Silicon/Phytium/FT2000-4Pkg/Drivers/SpiDxe/SpiDxe.c @@ -0,0 +1,198 @@ +/** @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 =3D 0; + Value =3D 0; + + if (CmdId !=3D 0) { + Value =3D (CmdId << 24) | (Config & 0xffffff); + } else { + Value =3D Config; + } + + SpiAddr =3D 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 =3D 0; + Value =3D 0; + + SpiAddr =3D mSpiControlBase + RegAddr; + Value =3D MmioRead32 (SpiAddr); + + if (CmdId !=3D 0) { + *Config =3D Value & 0xffffff; + } else { + *Config =3D Value; + } + + 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 succ= essfully. + +**/ +STATIC +EFI_STATUS +EFIAPI +SpiMasterInitProtocol ( + IN EFI_SPI_DRV_PROTOCOL *SpiMasterProtocol + ) +{ + + SpiMasterProtocol->SpiInit =3D SpiMasterInit; + SpiMasterProtocol->SpiSetConfig =3D SpiMasterSetConfig; + SpiMasterProtocol->SpiGetConfig =3D SpiMasterGetConfig; + SpiMasterProtocol->SpiSetMode =3D SpiMasterSetMode; + + return EFI_SUCCESS; +} + + +/** + This function is the entrypoint of the spi driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + + @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 po= int. + +**/ +EFI_STATUS +EFIAPI +SpiMasterDrvEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + pSpiMasterInstance =3D AllocateRuntimeZeroPool (sizeof (PHYT_SPI_MASTER)= ); + if (pSpiMasterInstance =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + mSpiControlBase =3D FixedPcdGet64 (PcdSpiControllerBase); + + SpiMasterInitProtocol (&pSpiMasterInstance->SpiMasterProtocol); + + pSpiMasterInstance->Signature =3D SPI_MASTER_SIGNATURE; + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &(pSpiMasterInstance->Handle), + &gSpiMasterProtocolGuid, + &(pSpiMasterInstance->SpiMasterProtocol), + NULL + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#72979): https://edk2.groups.io/g/devel/message/72979 Mute This Topic: https://groups.io/mt/81410911/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-