1 | /** @file
|
---|
2 | This file defines the SPI I/O Protocol.
|
---|
3 |
|
---|
4 | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
---|
5 | Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | @par Revision Reference:
|
---|
9 | This Protocol was introduced in UEFI PI Specification 1.8 A.
|
---|
10 |
|
---|
11 | **/
|
---|
12 |
|
---|
13 | #ifndef __SPI_IO_PROTOCOL_H__
|
---|
14 | #define __SPI_IO_PROTOCOL_H__
|
---|
15 |
|
---|
16 | #include <Protocol/LegacySpiController.h>
|
---|
17 | #include <Protocol/SpiConfiguration.h>
|
---|
18 |
|
---|
19 | typedef struct _EFI_SPI_IO_PROTOCOL EFI_SPI_IO_PROTOCOL;
|
---|
20 |
|
---|
21 | ///
|
---|
22 | /// Note: The UEFI PI 1.6 specification does not specify values for the
|
---|
23 | /// members below. The order matches the specification.
|
---|
24 | ///
|
---|
25 | typedef enum {
|
---|
26 | ///
|
---|
27 | /// Data flowing in both direction between the host and
|
---|
28 | /// SPI peripheral.ReadBytes must equal WriteBytes and both ReadBuffer and
|
---|
29 | /// WriteBuffer must be provided.
|
---|
30 | ///
|
---|
31 | SPI_TRANSACTION_FULL_DUPLEX,
|
---|
32 |
|
---|
33 | ///
|
---|
34 | /// Data flowing from the host to the SPI peripheral.ReadBytes must be
|
---|
35 | /// zero.WriteBytes must be non - zero and WriteBuffer must be provided.
|
---|
36 | ///
|
---|
37 | SPI_TRANSACTION_WRITE_ONLY,
|
---|
38 |
|
---|
39 | ///
|
---|
40 | /// Data flowing from the SPI peripheral to the host.WriteBytes must be
|
---|
41 | /// zero.ReadBytes must be non - zero and ReadBuffer must be provided.
|
---|
42 | ///
|
---|
43 | SPI_TRANSACTION_READ_ONLY,
|
---|
44 |
|
---|
45 | ///
|
---|
46 | /// Data first flowing from the host to the SPI peripheral and then data
|
---|
47 | /// flows from the SPI peripheral to the host.These types of operations get
|
---|
48 | /// used for SPI flash devices when control data (opcode, address) must be
|
---|
49 | /// passed to the SPI peripheral to specify the data to be read.
|
---|
50 | ///
|
---|
51 | SPI_TRANSACTION_WRITE_THEN_READ
|
---|
52 | } EFI_SPI_TRANSACTION_TYPE;
|
---|
53 |
|
---|
54 | /**
|
---|
55 | Initiate a SPI transaction between the host and a SPI peripheral.
|
---|
56 |
|
---|
57 | This routine must be called at or below TPL_NOTIFY.
|
---|
58 | This routine works with the SPI bus layer to pass the SPI transaction to the
|
---|
59 | SPI controller for execution on the SPI bus. There are four types of
|
---|
60 | supported transactions supported by this routine:
|
---|
61 | * Full Duplex: WriteBuffer and ReadBuffer are the same size.
|
---|
62 | * Write Only: WriteBuffer contains data for SPI peripheral, ReadBytes = 0
|
---|
63 | * Read Only: ReadBuffer to receive data from SPI peripheral, WriteBytes = 0
|
---|
64 | * Write Then Read: WriteBuffer contains control data to write to SPI
|
---|
65 | peripheral before data is placed into the ReadBuffer.
|
---|
66 | Both WriteBytes and ReadBytes must be non-zero.
|
---|
67 |
|
---|
68 | @param[in] This Pointer to an EFI_SPI_IO_PROTOCOL structure.
|
---|
69 | @param[in] TransactionType Type of SPI transaction.
|
---|
70 | @param[in] DebugTransaction Set TRUE only when debugging is desired.
|
---|
71 | Debugging may be turned on for a single SPI
|
---|
72 | transaction. Only this transaction will display
|
---|
73 | debugging messages. All other transactions with
|
---|
74 | this value set to FALSE will not display any
|
---|
75 | debugging messages.
|
---|
76 | @param[in] ClockHz Specify the ClockHz value as zero (0) to use
|
---|
77 | the maximum clock frequency supported by the
|
---|
78 | SPI controller and part. Specify a non-zero
|
---|
79 | value only when a specific SPI transaction
|
---|
80 | requires a reduced clock rate.
|
---|
81 | @param[in] BusWidth Width of the SPI bus in bits: 1, 2, 4
|
---|
82 | @param[in] FrameSize Frame size in bits, range: 1 - 32
|
---|
83 | @param[in] WriteBytes The length of the WriteBuffer in bytes.
|
---|
84 | Specify zero for read-only operations.
|
---|
85 | @param[in] WriteBuffer The buffer containing data to be sent from the
|
---|
86 | host to the SPI chip. Specify NULL for read
|
---|
87 | only operations.
|
---|
88 | * Frame sizes 1-8 bits: UINT8 (one byte) per
|
---|
89 | frame
|
---|
90 | * Frame sizes 7-16 bits: UINT16 (two bytes) per
|
---|
91 | frame
|
---|
92 | * Frame sizes 17-32 bits: UINT32 (four bytes)
|
---|
93 | per frame The transmit frame is in the least
|
---|
94 | significant N bits.
|
---|
95 | @param[in] ReadBytes The length of the ReadBuffer in bytes.
|
---|
96 | Specify zero for write-only operations.
|
---|
97 | @param[out] ReadBuffer The buffer to receeive data from the SPI chip
|
---|
98 | during the transaction. Specify NULL for write
|
---|
99 | only operations.
|
---|
100 | * Frame sizes 1-8 bits: UINT8 (one byte) per
|
---|
101 | frame
|
---|
102 | * Frame sizes 7-16 bits: UINT16 (two bytes) per
|
---|
103 | frame
|
---|
104 | * Frame sizes 17-32 bits: UINT32 (four bytes)
|
---|
105 | per frame The received frame is in the least
|
---|
106 | significant N bits.
|
---|
107 |
|
---|
108 | @retval EFI_SUCCESS The SPI transaction completed successfully
|
---|
109 | @retval EFI_BAD_BUFFER_SIZE The writeBytes value was invalid
|
---|
110 | @retval EFI_BAD_BUFFER_SIZE The ReadBytes value was invalid
|
---|
111 | @retval EFI_INVALID_PARAMETER TransactionType is not valid,
|
---|
112 | or BusWidth not supported by SPI peripheral or
|
---|
113 | SPI host controller,
|
---|
114 | or WriteBytes non-zero and WriteBuffer is
|
---|
115 | NULL,
|
---|
116 | or ReadBytes non-zero and ReadBuffer is NULL,
|
---|
117 | or ReadBuffer != WriteBuffer for full-duplex
|
---|
118 | type,
|
---|
119 | or WriteBuffer was NULL,
|
---|
120 | or TPL is too high
|
---|
121 | @retval EFI_OUT_OF_RESOURCES Insufficient memory for SPI transaction
|
---|
122 | @retval EFI_UNSUPPORTED The FrameSize is not supported by the SPI bus
|
---|
123 | layer or the SPI host controller
|
---|
124 | @retval EFI_UNSUPPORTED The SPI controller was not able to support
|
---|
125 |
|
---|
126 | **/
|
---|
127 | typedef
|
---|
128 | EFI_STATUS
|
---|
129 | (EFIAPI *EFI_SPI_IO_PROTOCOL_TRANSACTION)(
|
---|
130 | IN CONST EFI_SPI_IO_PROTOCOL *This,
|
---|
131 | IN EFI_SPI_TRANSACTION_TYPE TransactionType,
|
---|
132 | IN BOOLEAN DebugTransaction,
|
---|
133 | IN UINT32 ClockHz OPTIONAL,
|
---|
134 | IN UINT32 BusWidth,
|
---|
135 | IN UINT32 FrameSize,
|
---|
136 | IN UINT32 WriteBytes,
|
---|
137 | IN UINT8 *WriteBuffer,
|
---|
138 | IN UINT32 ReadBytes,
|
---|
139 | OUT UINT8 *ReadBuffer
|
---|
140 | );
|
---|
141 |
|
---|
142 | /**
|
---|
143 | Update the SPI peripheral associated with this SPI 10 instance.
|
---|
144 |
|
---|
145 | Support socketed SPI parts by allowing the SPI peripheral driver to replace
|
---|
146 | the SPI peripheral after the connection is made. An example use is socketed
|
---|
147 | SPI NOR flash parts, where the size and parameters change depending upon
|
---|
148 | device is in the socket.
|
---|
149 |
|
---|
150 | @param[in] This Pointer to an EFI_SPI_IO_PROTOCOL structure.
|
---|
151 | @param[in] SpiPeripheral Pointer to an EFI_SPI_PERIPHERAL structure.
|
---|
152 |
|
---|
153 | @retval EFI_SUCCESS The SPI peripheral was updated successfully
|
---|
154 | @retval EFI_INVALID_PARAMETER The SpiPeripheral value is NULL,
|
---|
155 | or the SpiPeripheral->SpiBus is NULL,
|
---|
156 | or the SpiP eripheral - >SpiBus pointing at
|
---|
157 | wrong bus,
|
---|
158 | or the SpiP eripheral - >SpiPart is NULL
|
---|
159 |
|
---|
160 | **/
|
---|
161 | typedef EFI_STATUS
|
---|
162 | (EFIAPI *EFI_SPI_IO_PROTOCOL_UPDATE_SPI_PERIPHERAL)(
|
---|
163 | IN CONST EFI_SPI_IO_PROTOCOL *This,
|
---|
164 | IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral
|
---|
165 | );
|
---|
166 |
|
---|
167 | ///
|
---|
168 | /// The EFI_SPI_BUS_ TRANSACTION data structure contains the description of the
|
---|
169 | /// SPI transaction to perform on the host controller.
|
---|
170 | ///
|
---|
171 | typedef struct _EFI_SPI_BUS_TRANSACTION {
|
---|
172 | ///
|
---|
173 | /// Pointer to the SPI peripheral being manipulated.
|
---|
174 | ///
|
---|
175 | CONST EFI_SPI_PERIPHERAL *SpiPeripheral;
|
---|
176 |
|
---|
177 | ///
|
---|
178 | /// Type of transaction specified by one of the EFI_SPI_TRANSACTION_TYPE
|
---|
179 | /// values.
|
---|
180 | ///
|
---|
181 | EFI_SPI_TRANSACTION_TYPE TransactionType;
|
---|
182 |
|
---|
183 | ///
|
---|
184 | /// TRUE if the transaction is being debugged. Debugging may be turned on for
|
---|
185 | /// a single SPI transaction. Only this transaction will display debugging
|
---|
186 | /// messages. All other transactions with this value set to FALSE will not
|
---|
187 | /// display any debugging messages.
|
---|
188 | ///
|
---|
189 | BOOLEAN DebugTransaction;
|
---|
190 |
|
---|
191 | ///
|
---|
192 | /// SPI bus width in bits: 1, 2, 4
|
---|
193 | ///
|
---|
194 | UINT32 BusWidth;
|
---|
195 |
|
---|
196 | ///
|
---|
197 | /// Frame size in bits, range: 1 - 32
|
---|
198 | ///
|
---|
199 | UINT32 FrameSize;
|
---|
200 |
|
---|
201 | ///
|
---|
202 | /// Length of the write buffer in bytes
|
---|
203 | ///
|
---|
204 | UINT32 WriteBytes;
|
---|
205 |
|
---|
206 | ///
|
---|
207 | /// Buffer containing data to send to the SPI peripheral
|
---|
208 | /// Frame sizes 1 - 8 bits: UINT8 (one byte) per frame
|
---|
209 | /// Frame sizes 7 - 16 bits : UINT16 (two bytes) per frame
|
---|
210 | ///
|
---|
211 | UINT8 *WriteBuffer;
|
---|
212 |
|
---|
213 | ///
|
---|
214 | /// Length of the read buffer in bytes
|
---|
215 | ///
|
---|
216 | UINT32 ReadBytes;
|
---|
217 |
|
---|
218 | ///
|
---|
219 | /// Buffer to receive the data from the SPI peripheral
|
---|
220 | /// * Frame sizes 1 - 8 bits: UINT8 (one byte) per frame
|
---|
221 | /// * Frame sizes 7 - 16 bits : UINT16 (two bytes) per frame
|
---|
222 | /// * Frame sizes 17 - 32 bits : UINT32 (four bytes) per frame
|
---|
223 | ///
|
---|
224 | UINT8 *ReadBuffer;
|
---|
225 | } EFI_SPI_BUS_TRANSACTION;
|
---|
226 |
|
---|
227 | ///
|
---|
228 | /// Definitions of SPI I/O Attributes.
|
---|
229 | ///
|
---|
230 | #define SPI_IO_SUPPORTS_2_BIT_DATA_BUS_WIDTH BIT0
|
---|
231 | #define SPI_IO_SUPPORTS_4_BIT_DATA_BUS_WIDTH BIT1
|
---|
232 | #define SPI_IO_SUPPORTS_8_BIT_DATA_BUS_WIDTH BIT2
|
---|
233 | #define SPI_IO_TRANSFER_SIZE_INCLUDES_OPCODE BIT3
|
---|
234 | #define SPI_IO_TRANSFER_SIZE_INCLUDES_ADDRESS BIT4
|
---|
235 |
|
---|
236 | ///
|
---|
237 | /// Support managed SPI data transactions between the SPI controller and a SPI
|
---|
238 | /// chip.
|
---|
239 | ///
|
---|
240 | struct _EFI_SPI_IO_PROTOCOL {
|
---|
241 | ///
|
---|
242 | /// Address of an EFI_SPI_PERIPHERAL data structure associated with this
|
---|
243 | /// protocol instance.
|
---|
244 | ///
|
---|
245 | CONST EFI_SPI_PERIPHERAL *SpiPeripheral;
|
---|
246 |
|
---|
247 | ///
|
---|
248 | /// Address of the original EFI_SPI_PERIPHERAL data structure associated with
|
---|
249 | /// this protocol instance.
|
---|
250 | ///
|
---|
251 | CONST EFI_SPI_PERIPHERAL *OriginalSpiPeripheral;
|
---|
252 |
|
---|
253 | ///
|
---|
254 | /// Mask of frame sizes which the SPI 10 layer supports. Frame size of N-bits
|
---|
255 | /// is supported when bit N-1 is set. The host controller must support a
|
---|
256 | /// frame size of 8-bits. Frame sizes of 16, 24 and 32-bits are converted to
|
---|
257 | /// 8-bit frame sizes by the SPI bus layer if the frame size is not supported
|
---|
258 | /// by the SPI host controller.
|
---|
259 | ///
|
---|
260 | UINT32 FrameSizeSupportMask;
|
---|
261 |
|
---|
262 | ///
|
---|
263 | /// Maximum transfer size in bytes: 1 - Oxffffffff
|
---|
264 | ///
|
---|
265 | UINT32 MaximumTransferBytes;
|
---|
266 |
|
---|
267 | ///
|
---|
268 | /// Transaction attributes: One or more from:
|
---|
269 | /// * SPI_10_SUPPORTS_2_B1T_DATA_BUS_W1DTH
|
---|
270 | /// - The SPI host and peripheral supports a 2-bit data bus
|
---|
271 | /// * SPI_IO_SUPPORTS_4_BIT_DATA_BUS_W1DTH
|
---|
272 | /// - The SPI host and peripheral supports a 4-bit data bus
|
---|
273 | /// * SPI_IO_TRANSFER_SIZE_INCLUDES_OPCODE
|
---|
274 | /// - Transfer size includes the opcode byte
|
---|
275 | /// * SPI_IO_TRANSFER_SIZE_INCLUDES_ADDRESS
|
---|
276 | /// - Transfer size includes the 3 address bytes
|
---|
277 | ///
|
---|
278 | UINT32 Attributes;
|
---|
279 |
|
---|
280 | ///
|
---|
281 | /// Pointer to legacy SPI controller protocol
|
---|
282 | ///
|
---|
283 | CONST EFI_LEGACY_SPI_CONTROLLER_PROTOCOL *LegacySpiProtocol;
|
---|
284 |
|
---|
285 | ///
|
---|
286 | /// Initiate a SPI transaction between the host and a SPI peripheral.
|
---|
287 | ///
|
---|
288 | EFI_SPI_IO_PROTOCOL_TRANSACTION Transaction;
|
---|
289 |
|
---|
290 | ///
|
---|
291 | /// Update the SPI peripheral associated with this SPI 10 instance.
|
---|
292 | ///
|
---|
293 | EFI_SPI_IO_PROTOCOL_UPDATE_SPI_PERIPHERAL UpdateSpiPeripheral;
|
---|
294 | };
|
---|
295 |
|
---|
296 | #endif // __SPI_IO_PROTOCOL_H__
|
---|