TianoCore EDK2 master
Loading...
Searching...
No Matches
SpiBus.h File Reference

Go to the source code of this file.

Data Structures

struct  SPI_IO_CHIP
 

Macros

#define SPI_IO_SIGNATURE   SIGNATURE_32 ('s', 'i', 'o', 'c')
 
#define SPI_IO_CHIP_FROM_THIS(a)
 

Functions

BOOLEAN EFIAPI DevicePathsAreEqual (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath1, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath2)
 
EFI_STATUS EFIAPI Transaction (IN CONST EFI_SPI_IO_PROTOCOL *This, IN EFI_SPI_TRANSACTION_TYPE TransactionType, IN BOOLEAN DebugTransaction, IN UINT32 ClockHz OPTIONAL, IN UINT32 BusWidth, IN UINT32 FrameSize, IN UINT32 WriteBytes, IN UINT8 *WriteBuffer, IN UINT32 ReadBytes, OUT UINT8 *ReadBuffer)
 
EFI_STATUS EFIAPI UpdateSpiPeripheral (IN CONST EFI_SPI_IO_PROTOCOL *This, IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral)
 

Detailed Description

SPI bus driver

Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file SpiBus.h.

Macro Definition Documentation

◆ SPI_IO_CHIP_FROM_THIS

#define SPI_IO_CHIP_FROM_THIS (   a)
Value:
CR (a, SPI_IO_CHIP, Protocol, \
SPI_IO_SIGNATURE)
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:659

Definition at line 34 of file SpiBus.h.

◆ SPI_IO_SIGNATURE

#define SPI_IO_SIGNATURE   SIGNATURE_32 ('s', 'i', 'o', 'c')

Definition at line 22 of file SpiBus.h.

Function Documentation

◆ DevicePathsAreEqual()

BOOLEAN EFIAPI DevicePathsAreEqual ( IN CONST EFI_DEVICE_PATH_PROTOCOL DevicePath1,
IN CONST EFI_DEVICE_PATH_PROTOCOL DevicePath2 
)

Checks if two device paths are the same

Parameters
[in]DevicePath1First device path to compare
[in]DevicePath2Second device path to compare
Return values
TRUEThe device paths share the same nodes and values
FALSEThe device paths differ

Checks if two device paths are the same.

Parameters
[in]DevicePath1First device path to compare
[in]DevicePath2Second device path to compare
Return values
TRUEThe device paths share the same nodes and values
FALSEThe device paths differ

Definition at line 28 of file SpiBus.c.

◆ Transaction()

EFI_STATUS EFIAPI Transaction ( IN CONST EFI_SPI_IO_PROTOCOL This,
IN EFI_SPI_TRANSACTION_TYPE  TransactionType,
IN BOOLEAN  DebugTransaction,
IN UINT32 ClockHz  OPTIONAL,
IN UINT32  BusWidth,
IN UINT32  FrameSize,
IN UINT32  WriteBytes,
IN UINT8 *  WriteBuffer,
IN UINT32  ReadBytes,
OUT UINT8 *  ReadBuffer 
)

Initiate a SPI transaction between the host and a SPI peripheral.

This routine must be called at or below TPL_NOTIFY. This routine works with the SPI bus layer to pass the SPI transaction to the SPI controller for execution on the SPI bus. There are four types of supported transactions supported by this routine: Full Duplex: WriteBuffer and ReadBuffer are the same size. Write Only: WriteBuffer contains data for SPI peripheral, ReadBytes = 0 Read Only: ReadBuffer to receive data from SPI peripheral, WriteBytes = 0 Write Then Read: WriteBuffer contains control data to write to SPI peripheral before data is placed into the ReadBuffer. Both WriteBytes and ReadBytes must be non-zero.

Parameters
[in]ThisPointer to an EFI_SPI_IO_PROTOCOL structure.
[in]TransactionTypeType of SPI transaction.
[in]DebugTransactionSet TRUE only when debugging is desired. Debugging may be turned on for a single SPI transaction. Only this transaction will display debugging messages. All other transactions with this value set to FALSE will not display any debugging messages.
[in]ClockHzSpecify the ClockHz value as zero (0) to use the maximum clock frequency supported by the SPI controller and part. Specify a non-zero value only when a specific SPI transaction requires a reduced clock rate.
[in]BusWidthWidth of the SPI bus in bits: 1, 2, 4
[in]FrameSizeFrame size in bits, range: 1 - 32
[in]WriteBytesThe length of the WriteBuffer in bytes. Specify zero for read-only operations.
[in]WriteBufferThe buffer containing data to be sent from the host to the SPI chip. Specify NULL for read only operations. Frame sizes 1-8 bits: UINT8 (one byte) per frame Frame sizes 7-16 bits: UINT16 (two bytes) per frame Frame sizes 17-32 bits: UINT32 (four bytes) per frame The transmit frame is in the least significant N bits.
[in]ReadBytesThe length of the ReadBuffer in bytes. Specify zero for write-only operations.
[out]ReadBufferThe buffer to receeive data from the SPI chip during the transaction. Specify NULL for write only operations. Frame sizes 1-8 bits: UINT8 (one byte) per frame Frame sizes 7-16 bits: UINT16 (two bytes) per frame Frame sizes 17-32 bits: UINT32 (four bytes) per frame The received frame is in the least significant N bits.
Return values
EFI_SUCCESSThe SPI transaction completed successfully
EFI_BAD_BUFFER_SIZEThe writeBytes value was invalid
EFI_BAD_BUFFER_SIZEThe ReadBytes value was invalid
EFI_INVALID_PARAMETERTransactionType is not valid, or BusWidth not supported by SPI peripheral or SPI host controller, or WriteBytes non-zero and WriteBuffer is NULL, or ReadBytes non-zero and ReadBuffer is NULL, or ReadBuffer != WriteBuffer for full-duplex type, or WriteBuffer was NULL, or TPL is too high
EFI_OUT_OF_RESOURCESInsufficient memory for SPI transaction
EFI_UNSUPPORTEDThe FrameSize is not supported by the SPI bus layer or the SPI host controller
EFI_UNSUPPORTEDThe SPI controller was not able to support

Initiate a SPI transaction between the host and a SPI peripheral.

This routine must be called at or below TPL_NOTIFY. This routine works with the SPI bus layer to pass the SPI transaction to the SPI controller for execution on the SPI bus. There are four types of supported transactions supported by this routine: Full Duplex: WriteBuffer and ReadBuffer are the same size. Write Only: WriteBuffer contains data for SPI peripheral, ReadBytes = 0 Read Only: ReadBuffer to receive data from SPI peripheral, WriteBytes = 0 Write Then Read: WriteBuffer contains control data to write to SPI peripheral before data is placed into the ReadBuffer. Both WriteBytes and ReadBytes must be non-zero.

Parameters
[in]ThisPointer to an EFI_SPI_IO_PROTOCOL structure.
[in]TransactionTypeType of SPI transaction.
[in]DebugTransactionSet TRUE only when debugging is desired. Debugging may be turned on for a single SPI transaction. Only this transaction will display debugging messages. All other transactions with this value set to FALSE will not display any debugging messages.
[in]ClockHzSpecify the ClockHz value as zero (0) to use the maximum clock frequency supported by the SPI controller and part. Specify a non-zero value only when a specific SPI transaction requires a reduced clock rate.
[in]BusWidthWidth of the SPI bus in bits: 1, 2, 4
[in]FrameSizeFrame size in bits, range: 1 - 32
[in]WriteBytesThe length of the WriteBuffer in bytes. Specify zero for read-only operations.
[in]WriteBufferThe buffer containing data to be sent from the host to the SPI chip. Specify NULL for read only operations. Frame sizes 1-8 bits: UINT8 (one byte) per frame Frame sizes 7-16 bits: UINT16 (two bytes) per frame Frame sizes 17-32 bits: UINT32 (four bytes) per frame The transmit frame is in the least significant N bits.
[in]ReadBytesThe length of the ReadBuffer in bytes. Specify zero for write-only operations.
[out]ReadBufferThe buffer to receeive data from the SPI chip during the transaction. Specify NULL for write only operations. Frame sizes 1-8 bits: UINT8 (one byte) per frame Frame sizes 7-16 bits: UINT16 (two bytes) per frame Frame sizes 17-32 bits: UINT32 (four bytes) per frame The received frame is in the least significant N bits.
Return values
EFI_SUCCESSThe SPI transaction completed successfully
EFI_BAD_BUFFER_SIZEThe WriteBytes value was invalid
EFI_BAD_BUFFER_SIZEThe ReadBytes value was invalid
EFI_INVALID_PARAMETERTransactionType is not valid, or BusWidth not supported by SPI peripheral or SPI host controller, or WriteBytes non-zero and WriteBuffer is NULL, or ReadBytes non-zero and ReadBuffer is NULL, or ReadBuffer != WriteBuffer for full-duplex type, or WriteBuffer was NULL, or TPL is too high
EFI_OUT_OF_RESOURCESInsufficient memory for SPI transaction
EFI_UNSUPPORTEDThe FrameSize is not supported by the SPI bus layer or the SPI host controller
EFI_UNSUPPORTEDThe SPI controller was not able to support

Definition at line 231 of file SpiBus.c.

◆ UpdateSpiPeripheral()

EFI_STATUS EFIAPI UpdateSpiPeripheral ( IN CONST EFI_SPI_IO_PROTOCOL This,
IN CONST EFI_SPI_PERIPHERAL SpiPeripheral 
)

Update the SPI peripheral associated with this SPI 10 instance.

Support socketed SPI parts by allowing the SPI peripheral driver to replace the SPI peripheral after the connection is made. An example use is socketed SPI NOR flash parts, where the size and parameters change depending upon device is in the socket.

Parameters
[in]ThisPointer to an EFI_SPI_IO_PROTOCOL structure.
[in]SpiPeripheralPointer to an EFI_SPI_PERIPHERAL structure.
Return values
EFI_SUCCESSThe SPI peripheral was updated successfully
EFI_INVALID_PARAMETERThe SpiPeripheral value is NULL, or the SpiPeripheral->SpiBus is NULL, or the SpiPeripheral->SpiBus pointing at wrong bus, or the SpiPeripheral->SpiPart is NULL

Update the SPI peripheral associated with this SPI 10 SpiChip.

Support socketed SPI parts by allowing the SPI peripheral driver to replace the SPI peripheral after the connection is made. An example use is socketed SPI NOR flash parts, where the size and parameters change depending upon device is in the socket.

Parameters
[in]ThisPointer to an EFI_SPI_IO_PROTOCOL structure.
[in]SpiPeripheralPointer to an EFI_SPI_PERIPHERAL structure.
Return values
EFI_SUCCESSThe SPI peripheral was updated successfully
EFI_INVALID_PARAMETERThe SpiPeripheral value is NULL, or the SpiPeripheral->SpiBus is NULL, or the SpiPeripheral->SpiBus pointing at wrong bus, or the SpiPeripheral->SpiPart is NULL

Definition at line 399 of file SpiBus.c.