From: Ling Jia <jialing@phytium.com.cn>
To: devel@edk2.groups.io
Cc: Leif Lindholm <leif@nuviainc.com>, Ling <jialing@phytium.com.cn>,
Peng Xie <xiepeng@phytium.com.cn>,
Yiqi Shu <shuyiqi@phytium.com.cn>
Subject: [PATCH v1 07/10] Silicon/Phytium: Added Spi driver support to Phytium2000-4
Date: Fri, 15 Jan 2021 08:47:59 +0000 [thread overview]
Message-ID: <20210115084802.62196-8-jialing@phytium.com.cn> (raw)
In-Reply-To: <20210115084802.62196-1-jialing@phytium.com.cn>
From: Ling <jialing@phytium.com.cn>
The PhytiumSpiDxe is to provide Spi bus read-write interface.
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Ling Jia <jialing@phytium.com.cn>
Signed-off-by: Peng Xie <xiepeng@phytium.com.cn>
Reviewed-by: Yiqi Shu <shuyiqi@phytium.com.cn>
---
Platform/Phytium/Durian/DurianPkg.dsc | 5 +
Platform/Phytium/Durian/DurianPkg.fdf | 5 +
Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.inf | 52 ++++++
Silicon/Phytium/Include/Protocol/PhytiumSpi.h | 51 ++++++
Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.h | 73 ++++++++
Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.c | 189 ++++++++++++++++++++
6 files changed, 375 insertions(+)
diff --git a/Platform/Phytium/Durian/DurianPkg.dsc b/Platform/Phytium/Durian/DurianPkg.dsc
index 5c40d9fb5dce..a23c1d52cece 100644
--- a/Platform/Phytium/Durian/DurianPkg.dsc
+++ b/Platform/Phytium/Durian/DurianPkg.dsc
@@ -256,6 +256,11 @@ [Components.common]
#
ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf
+ #
+ # Spi driver
+ #
+ Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.inf
+
#
# Usb Support
#
diff --git a/Platform/Phytium/Durian/DurianPkg.fdf b/Platform/Phytium/Durian/DurianPkg.fdf
index d39d1a660102..ad0406b3133b 100644
--- a/Platform/Phytium/Durian/DurianPkg.fdf
+++ b/Platform/Phytium/Durian/DurianPkg.fdf
@@ -105,6 +105,11 @@ [FV.FvMain]
INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
INF ArmPkg/Drivers/GenericWatchdogDxe/GenericWatchdogDxe.inf
+ #
+ # Spi driver
+ #
+ INF Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.inf
+
# Variable services
INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
diff --git a/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.inf b/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.inf
new file mode 100644
index 000000000000..522a633a23e6
--- /dev/null
+++ b/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.inf
@@ -0,0 +1,52 @@
+#/** @file
+# Phytium Spi Master Drivers.
+#
+# Copyright (C) 2020, Phytium Technology Co,Ltd. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010019
+ BASE_NAME = PhytiumSpiDxe
+ FILE_GUID = 2ba95e5c-f7f5-11ea-bf18-67fdc5787495
+ MODULE_TYPE = DXE_RUNTIME_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = SpiMasterDrvEntryPoint
+
+[Sources.common]
+ PhytiumSpiDxe.c
+ PhytiumSpiDxe.h
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ArmPkg/ArmPkg.dec
+ ArmPlatformPkg/ArmPlatformPkg.dec
+ Silicon/Phytium/Phytium.dec
+
+[LibraryClasses]
+ BaseLib
+ DebugLib
+ PcdLib
+ IoLib
+ UefiBootServicesTableLib
+ DxeServicesTableLib
+ UefiRuntimeLib
+ UefiLib
+ UefiDriverEntryPoint
+
+[Guids]
+ gEfiEventVirtualAddressChangeGuid
+
+[Protocols]
+ gPhytiumSpiMasterProtocolGuid
+
+[FixedPcd]
+ gPhytiumPlatformTokenSpaceGuid.PcdSpiFlashBase
+ gPhytiumPlatformTokenSpaceGuid.PcdSpiFlashSize
+ gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerBase
+ gPhytiumPlatformTokenSpaceGuid.PcdSpiControllerSize
+
+[Depex]
+ TRUE
diff --git a/Silicon/Phytium/Include/Protocol/PhytiumSpi.h b/Silicon/Phytium/Include/Protocol/PhytiumSpi.h
new file mode 100644
index 000000000000..43a258924662
--- /dev/null
+++ b/Silicon/Phytium/Include/Protocol/PhytiumSpi.h
@@ -0,0 +1,51 @@
+/** @file
+ The Header of Protocol For SPI.
+
+ Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __PHYTIUM_SPI_H__
+#define __PHYTIUM_SPI_H__
+
+extern EFI_GUID gPhytiumSpiMasterProtocolGuid;
+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 /* __PHYTIUM_SPI_H__ */
diff --git a/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.h b/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.h
new file mode 100644
index 000000000000..1a5cbb6b5a33
--- /dev/null
+++ b/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.h
@@ -0,0 +1,73 @@
+/** @file
+ Phytium Spi Drivers Header
+
+ Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __PHYTIUM_SPI_DXE_H__
+#define __PHYTIUM_SPI_DXE_H__
+
+#include <PiDxe.h>
+#include <Library/IoLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+#include <Uefi/UefiBaseType.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Guid/GlobalVariable.h>
+#include <Guid/EventGroup.h>
+#include <Protocol/PhytiumSpi.h>
+
+#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 /* __PHYTIUM_SPI_DXE_H__ */
diff --git a/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.c b/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.c
new file mode 100644
index 000000000000..ade1a2351d9f
--- /dev/null
+++ b/Silicon/Phytium/Phytium2000-4/Drivers/PhytiumSpiDxe/PhytiumSpiDxe.c
@@ -0,0 +1,189 @@
+/** @file
+ Phytium Spi Master Drivers.
+
+ Copyright (C) 2020, Phytium Technology Co Ltd. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "PhytiumSpiDxe.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 = 0;
+ UINT32 Value = 0;
+
+ if(CmdId != 0)
+ Value =(CmdId << 24) | (Config & 0xffffff);
+ else
+ Value = Config;
+
+ 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 = 0;
+ UINT32 Value = 0;
+
+ SpiAddr = mSpiControlBase + RegAddr;
+ Value = MmioRead32 (SpiAddr);
+ if(CmdId != 0)
+ *Config = Value & 0xffffff;
+ else
+ *Config = 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 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),
+ &gPhytiumSpiMasterProtocolGuid,
+ &(pSpiMasterInstance->SpiMasterProtocol),
+ NULL
+ );
+ ASSERT_EFI_ERROR(Status);
+
+ return EFI_SUCCESS;
+}
--
2.25.1
next prev parent reply other threads:[~2021-01-15 8:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-15 8:47 added support for DurianPkg Ling Jia
2021-01-15 8:47 ` [PATCH v1 01/10] Silicon/Phytium/: added PhytiumPlatformLib to Phytium2000-4 Ling Jia
2021-01-22 13:13 ` Leif Lindholm
2021-01-25 8:56 ` 贾玲
2021-01-15 8:47 ` [PATCH v1 02/10] Silicon/Phytium: Added Acpi support " Ling Jia
2021-01-15 8:47 ` [PATCH v1 03/10] Silicon/Phytium: Added SMBIOS " Ling Jia
2021-01-15 8:47 ` [PATCH v1 04/10] Silicon/Phytium/Phytium2000-4/Library: Added PciSegmentLib " Ling Jia
2021-01-15 8:47 ` [PATCH v1 05/10] Silicon/Phytium: Added PciHostBridgeLib " Ling Jia
2021-01-15 8:47 ` [PATCH v1 06/10] Silicon/Phytium: Added Logo support to Phytium Silicon Ling Jia
2021-01-15 8:47 ` Ling Jia [this message]
2021-01-15 8:48 ` [PATCH v1 08/10] Silicon/Phytium: Added flash driver " Ling Jia
2021-01-15 8:48 ` [PATCH v1 09/10] Silicon/Phytium: Added fvb driver for norflash Ling Jia
2021-01-15 8:48 ` [PATCH v1 10/10] Silicon/Phytium: Added Rtc driver to Phytium2000-4 Ling Jia
2021-01-22 12:04 ` added support for DurianPkg Leif Lindholm
2021-03-12 20:50 ` [edk2-devel] " Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210115084802.62196-8-jialing@phytium.com.cn \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox