2 This file defines the SPI I/O Protocol.
4 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD
7 License which accompanies this distribution. The full text of the license may
8 be found at http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 @par Revision Reference:
14 This Protocol was introduced in UEFI PI Specification 1.6.
18 #ifndef __SPI_IO_PROTOCOL_H__
19 #define __SPI_IO_PROTOCOL_H__
21 #include <Protocol/LegacySpiController.h>
22 #include <Protocol/SpiConfiguration.h>
24 typedef struct _EFI_SPI_IO_PROTOCOL EFI_SPI_IO_PROTOCOL
;
27 /// Note: The UEFI PI 1.6 specification does not specify values for the
28 /// members below. The order matches the specification.
32 /// Data flowing in both direction between the host and
33 /// SPI peripheral.ReadBytes must equal WriteBytes and both ReadBuffer and
34 /// WriteBuffer must be provided.
36 SPI_TRANSACTION_FULL_DUPLEX
,
39 /// Data flowing from the host to the SPI peripheral.ReadBytes must be
40 /// zero.WriteBytes must be non - zero and WriteBuffer must be provided.
42 SPI_TRANSACTION_WRITE_ONLY
,
45 /// Data flowing from the SPI peripheral to the host.WriteBytes must be
46 /// zero.ReadBytes must be non - zero and ReadBuffer must be provided.
48 SPI_TRANSACTION_READ_ONLY
,
51 /// Data first flowing from the host to the SPI peripheral and then data
52 /// flows from the SPI peripheral to the host.These types of operations get
53 /// used for SPI flash devices when control data (opcode, address) must be
54 /// passed to the SPI peripheral to specify the data to be read.
56 SPI_TRANSACTION_WRITE_THEN_READ
57 } EFI_SPI_TRANSACTION_TYPE
;
60 Initiate a SPI transaction between the host and a SPI peripheral.
62 This routine must be called at or below TPL_NOTIFY.
63 This routine works with the SPI bus layer to pass the SPI transaction to the
64 SPI controller for execution on the SPI bus. There are four types of
65 supported transactions supported by this routine:
66 * Full Duplex: WriteBuffer and ReadBuffer are the same size.
67 * Write Only: WriteBuffer contains data for SPI peripheral, ReadBytes = 0
68 * Read Only: ReadBuffer to receive data from SPI peripheral, WriteBytes = 0
69 * Write Then Read: WriteBuffer contains control data to write to SPI
70 peripheral before data is placed into the ReadBuffer.
71 Both WriteBytes and ReadBytes must be non-zero.
73 @param[in] This Pointer to an EFI_SPI_IO_PROTOCOL structure.
74 @param[in] TransactionType Type of SPI transaction.
75 @param[in] DebugTransaction Set TRUE only when debugging is desired.
76 Debugging may be turned on for a single SPI
77 transaction. Only this transaction will display
78 debugging messages. All other transactions with
79 this value set to FALSE will not display any
81 @param[in] ClockHz Specify the ClockHz value as zero (0) to use
82 the maximum clock frequency supported by the
83 SPI controller and part. Specify a non-zero
84 value only when a specific SPI transaction
85 requires a reduced clock rate.
86 @param[in] BusWidth Width of the SPI bus in bits: 1, 2, 4
87 @param[in] FrameSize Frame size in bits, range: 1 - 32
88 @param[in] WriteBytes The length of the WriteBuffer in bytes.
89 Specify zero for read-only operations.
90 @param[in] WriteBuffer The buffer containing data to be sent from the
91 host to the SPI chip. Specify NULL for read
93 * Frame sizes 1-8 bits: UINT8 (one byte) per
95 * Frame sizes 7-16 bits: UINT16 (two bytes) per
97 * Frame sizes 17-32 bits: UINT32 (four bytes)
98 per frame The transmit frame is in the least
100 @param[in] ReadBytes The length of the ReadBuffer in bytes.
101 Specify zero for write-only operations.
102 @param[out] ReadBuffer The buffer to receeive data from the SPI chip
103 during the transaction. Specify NULL for write
105 * Frame sizes 1-8 bits: UINT8 (one byte) per
107 * Frame sizes 7-16 bits: UINT16 (two bytes) per
109 * Frame sizes 17-32 bits: UINT32 (four bytes)
110 per frame The received frame is in the least
113 @retval EFI_SUCCESS The SPI transaction completed successfully
114 @retval EFI_BAD_BUFFER_SIZE The writeBytes value was invalid
115 @retval EFI_BAD_BUFFER_SIZE The ReadBytes value was invalid
116 @retval EFI_INVALID_PARAMETER TransactionType is not valid,
117 or BusWidth not supported by SPI peripheral or
119 or WriteBytes non-zero and WriteBuffer is
121 or ReadBytes non-zero and ReadBuffer is NULL,
122 or ReadBuffer != WriteBuffer for full-duplex
124 or WriteBuffer was NULL,
126 @retval EFI_OUT_OF_RESOURCES Insufficient memory for SPI transaction
127 @retval EFI_UNSUPPORTED The FrameSize is not supported by the SPI bus
128 layer or the SPI host controller
129 @retval EFI_UNSUPPORTED The SPI controller was not able to support
134 (EFIAPI
*EFI_SPI_IO_PROTOCOL_TRANSACTION
) (
135 IN CONST EFI_SPI_IO_PROTOCOL
*This
,
136 IN EFI_SPI_TRANSACTION_TYPE TransactionType
,
137 IN BOOLEAN DebugTransaction
,
138 IN UINT32 ClockHz OPTIONAL
,
141 IN UINT32 WriteBytes
,
142 IN UINT8
*WriteBuffer
,
144 OUT UINT8
*ReadBuffer
148 Update the SPI peripheral associated with this SPI 10 instance.
150 Support socketed SPI parts by allowing the SPI peripheral driver to replace
151 the SPI peripheral after the connection is made. An example use is socketed
152 SPI NOR flash parts, where the size and parameters change depending upon
153 device is in the socket.
155 @param[in] This Pointer to an EFI_SPI_IO_PROTOCOL structure.
156 @param[in] SpiPeripheral Pointer to an EFI_SPI_PERIPHERAL structure.
158 @retval EFI_SUCCESS The SPI peripheral was updated successfully
159 @retval EFI_INVALID_PARAMETER The SpiPeripheral value is NULL,
160 or the SpiPeripheral->SpiBus is NULL,
161 or the SpiP eripheral - >SpiBus pointing at
163 or the SpiP eripheral - >SpiPart is NULL
167 (EFIAPI
*EFI_SPI_IO_PROTOCOL_UPDATE_SPI_PERIPHERAL
) (
168 IN CONST EFI_SPI_IO_PROTOCOL
*This
,
169 IN CONST EFI_SPI_PERIPHERAL
*SpiPeripheral
173 /// The EFI_SPI_BUS_ TRANSACTION data structure contains the description of the
174 /// SPI transaction to perform on the host controller.
176 typedef struct _EFI_SPI_BUS_TRANSACTION
{
178 /// Pointer to the SPI peripheral being manipulated.
180 CONST EFI_SPI_PERIPHERAL
*SpiPeripheral
;
183 /// Type of transaction specified by one of the EFI_SPI_TRANSACTION_TYPE
186 EFI_SPI_TRANSACTION_TYPE TransactionType
;
189 /// TRUE if the transaction is being debugged. Debugging may be turned on for
190 /// a single SPI transaction. Only this transaction will display debugging
191 /// messages. All other transactions with this value set to FALSE will not
192 /// display any debugging messages.
194 BOOLEAN DebugTransaction
;
197 /// SPI bus width in bits: 1, 2, 4
202 /// Frame size in bits, range: 1 - 32
207 /// Length of the write buffer in bytes
212 /// Buffer containing data to send to the SPI peripheral
213 /// Frame sizes 1 - 8 bits: UINT8 (one byte) per frame
214 /// Frame sizes 7 - 16 bits : UINT16 (two bytes) per frame
219 /// Length of the read buffer in bytes
224 /// Buffer to receive the data from the SPI peripheral
225 /// * Frame sizes 1 - 8 bits: UINT8 (one byte) per frame
226 /// * Frame sizes 7 - 16 bits : UINT16 (two bytes) per frame
227 /// * Frame sizes 17 - 32 bits : UINT32 (four bytes) per frame
230 } EFI_SPI_BUS_TRANSACTION
;
233 /// Support managed SPI data transactions between the SPI controller and a SPI
236 struct _EFI_SPI_IO_PROTOCOL
{
238 /// Address of an EFI_SPI_PERIPHERAL data structure associated with this
239 /// protocol instance.
241 CONST EFI_SPI_PERIPHERAL
*SpiPeripheral
;
244 /// Address of the original EFI_SPI_PERIPHERAL data structure associated with
245 /// this protocol instance.
247 CONST EFI_SPI_PERIPHERAL
*OriginalSpiPeripheral
;
250 /// Mask of frame sizes which the SPI 10 layer supports. Frame size of N-bits
251 /// is supported when bit N-1 is set. The host controller must support a
252 /// frame size of 8-bits. Frame sizes of 16, 24 and 32-bits are converted to
253 /// 8-bit frame sizes by the SPI bus layer if the frame size is not supported
254 /// by the SPI host controller.
256 UINT32 FrameSizeSupportMask
;
259 /// Maximum transfer size in bytes: 1 - Oxffffffff
261 UINT32 MaximumTransferBytes
;
264 /// Transaction attributes: One or more from:
265 /// * SPI_10_SUPPORTS_2_B1T_DATA_BUS_W1DTH
266 /// - The SPI host and peripheral supports a 2-bit data bus
267 /// * SPI_IO_SUPPORTS_4_BIT_DATA_BUS_W1DTH
268 /// - The SPI host and peripheral supports a 4-bit data bus
269 /// * SPI_IO_TRANSFER_SIZE_INCLUDES_OPCODE
270 /// - Transfer size includes the opcode byte
271 /// * SPI_IO_TRANSFER_SIZE_INCLUDES_ADDRESS
272 /// - Transfer size includes the 3 address bytes
277 /// Pointer to legacy SPI controller protocol
279 CONST EFI_LEGACY_SPI_CONTROLLER_PROTOCOL
*LegacySpiProtocol
;
282 /// Initiate a SPI transaction between the host and a SPI peripheral.
284 EFI_SPI_IO_PROTOCOL_TRANSACTION Transaction
;
287 /// Update the SPI peripheral associated with this SPI 10 instance.
289 EFI_SPI_IO_PROTOCOL_UPDATE_SPI_PERIPHERAL UpdateSpiPeripheral
;
292 #endif // __SPI_IO_PROTOCOL_H__