1 | /** @file
|
---|
2 | This file defines the SPI Configuration 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_CONFIGURATION_PROTOCOL_H__
|
---|
14 | #define __SPI_CONFIGURATION_PROTOCOL_H__
|
---|
15 |
|
---|
16 | ///
|
---|
17 | /// Global ID for the SPI Configuration Protocol
|
---|
18 | ///
|
---|
19 | #define EFI_SPI_CONFIGURATION_GUID \
|
---|
20 | { 0x85a6d3e6, 0xb65b, 0x4afc, \
|
---|
21 | { 0xb3, 0x8f, 0xc6, 0xd5, 0x4a, 0xf6, 0xdd, 0xc8 }}
|
---|
22 |
|
---|
23 | ///
|
---|
24 | /// Macros to easily specify frequencies in hertz, kilohertz and megahertz.
|
---|
25 | ///
|
---|
26 | #define Hz(Frequency) (Frequency)
|
---|
27 | #define KHz(Frequency) (1000 * Hz (Frequency))
|
---|
28 | #define MHz(Frequency) (1000 * KHz (Frequency))
|
---|
29 |
|
---|
30 | typedef struct _EFI_SPI_PERIPHERAL EFI_SPI_PERIPHERAL;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | Manipulate the chip select for a SPI device.
|
---|
34 |
|
---|
35 | This routine must be called at or below TPL_NOTIFY.
|
---|
36 | Update the value of the chip select line for a SPI peripheral.
|
---|
37 | The SPI bus layer calls this routine either in the board layer or in the SPI
|
---|
38 | controller to manipulate the chip select pin at the start and end of a SPI
|
---|
39 | transaction.
|
---|
40 |
|
---|
41 | @param[in] SpiPeripheral The address of an EFI_SPI_PERIPHERAL data structure
|
---|
42 | describing the SPI peripheral whose chip select pin
|
---|
43 | is to be manipulated. The routine may access the
|
---|
44 | ChipSelectParameter field to gain sufficient
|
---|
45 | context to complete the operation.
|
---|
46 | @param[in] PinValue The value to be applied to the chip select line of
|
---|
47 | the SPI peripheral.
|
---|
48 |
|
---|
49 | @retval EFI_SUCCESS The chip select was set successfully
|
---|
50 | @retval EFI_NOT_READY Support for the chip select is not properly
|
---|
51 | initialized
|
---|
52 | @retval EFI_INVALID_PARAMETER The SpiPeripheral->ChipSelectParameter value
|
---|
53 | is invalid
|
---|
54 |
|
---|
55 | **/
|
---|
56 | typedef
|
---|
57 | EFI_STATUS
|
---|
58 | (EFIAPI *EFI_SPI_CHIP_SELECT)(
|
---|
59 | IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral,
|
---|
60 | IN BOOLEAN PinValue
|
---|
61 | );
|
---|
62 |
|
---|
63 | /**
|
---|
64 | Set up the clock generator to produce the correct clock frequency, phase and
|
---|
65 | polarity for a SPI chip.
|
---|
66 |
|
---|
67 | This routine must be called at or below TPL_NOTIFY.
|
---|
68 | This routine updates the clock generator to generate the correct frequency
|
---|
69 | and polarity for the SPI clock.
|
---|
70 |
|
---|
71 | @param[in] SpiPeripheral Pointer to a EFI_SPI_PERIPHERAL data structure from
|
---|
72 | which the routine can access the ClockParameter,
|
---|
73 | ClockPhase and ClockPolarity fields. The routine
|
---|
74 | also has access to the names for the SPI bus and
|
---|
75 | chip which can be used during debugging.
|
---|
76 | @param[in] ClockHz Pointer to the requested clock frequency. The clock
|
---|
77 | generator will choose a supported clock frequency
|
---|
78 | which is less then or equal to this value.
|
---|
79 | Specify zero to turn the clock generator off.
|
---|
80 | The actual clock frequency supported by the clock
|
---|
81 | generator will be returned.
|
---|
82 |
|
---|
83 | @retval EFI_SUCCESS The clock was set up successfully
|
---|
84 | @retval EFI_UNSUPPORTED The SPI controller was not able to support the
|
---|
85 | frequency requested by CLockHz
|
---|
86 |
|
---|
87 | **/
|
---|
88 | typedef EFI_STATUS
|
---|
89 | (EFIAPI *EFI_SPI_CLOCK)(
|
---|
90 | IN CONST EFI_SPI_PERIPHERAL *SpiPeripheral,
|
---|
91 | IN UINT32 *ClockHz
|
---|
92 | );
|
---|
93 |
|
---|
94 | ///
|
---|
95 | /// The EFI_SPI_PART data structure provides a description of a SPI part which
|
---|
96 | /// is independent of the use on the board. This data is available directly
|
---|
97 | /// from the part's datasheet and may be provided by the vendor.
|
---|
98 | ///
|
---|
99 | typedef struct _EFI_SPI_PART {
|
---|
100 | ///
|
---|
101 | /// A Unicode string specifying the SPI chip vendor.
|
---|
102 | ///
|
---|
103 | CONST CHAR16 *Vendor;
|
---|
104 |
|
---|
105 | ///
|
---|
106 | /// A Unicode string specifying the SPI chip part number.
|
---|
107 | ///
|
---|
108 | CONST CHAR16 *PartNumber;
|
---|
109 |
|
---|
110 | ///
|
---|
111 | /// The minimum SPI bus clock frequency used to access this chip. This value
|
---|
112 | /// may be specified in the chip's datasheet. If not, use the value of zero.
|
---|
113 | ///
|
---|
114 | UINT32 MinClockHz;
|
---|
115 |
|
---|
116 | ///
|
---|
117 | /// The maximum SPI bus clock frequency used to access this chip. This value
|
---|
118 | /// is found in the chip's datasheet.
|
---|
119 | ///
|
---|
120 | UINT32 MaxClockHz;
|
---|
121 |
|
---|
122 | ///
|
---|
123 | /// Specify the polarity of the chip select pin. This value can be found in
|
---|
124 | /// the SPI chip's datasheet. Specify TRUE when a one asserts the chip select
|
---|
125 | /// and FALSE when a zero asserts the chip select.
|
---|
126 | ///
|
---|
127 | BOOLEAN ChipSelectPolarity;
|
---|
128 | } EFI_SPI_PART;
|
---|
129 |
|
---|
130 | ///
|
---|
131 | /// The EFI_SPI_BUS data structure provides the connection details between the
|
---|
132 | /// physical SPI bus and the EFI_SPI_HC_PROTOCOL instance which controls that
|
---|
133 | /// SPI bus. This data structure also describes the details of how the clock is
|
---|
134 | /// generated for that SPI bus. Finally this data structure provides the list
|
---|
135 | /// of physical SPI devices which are attached to the SPI bus.
|
---|
136 | ///
|
---|
137 | typedef struct _EFI_SPI_BUS {
|
---|
138 | ///
|
---|
139 | /// A Unicode string describing the SPI bus
|
---|
140 | ///
|
---|
141 | CONST CHAR16 *FriendlyName;
|
---|
142 |
|
---|
143 | ///
|
---|
144 | /// Address of the first EFI_SPI_PERIPHERAL data structure connected to this
|
---|
145 | /// bus. Specify NULL if there are no SPI peripherals connected to this bus.
|
---|
146 | ///
|
---|
147 | CONST EFI_SPI_PERIPHERAL *Peripherallist;
|
---|
148 |
|
---|
149 | ///
|
---|
150 | /// Address of an EFI_DEVICE_PATH_PROTOCOL data structure which uniquely
|
---|
151 | /// describes the SPI controller.
|
---|
152 | ///
|
---|
153 | CONST EFI_DEVICE_PATH_PROTOCOL *ControllerPath;
|
---|
154 |
|
---|
155 | ///
|
---|
156 | /// Address of the routine which controls the clock used by the SPI bus for
|
---|
157 | /// this SPI peripheral. The SPI host co ntroller's clock routine is called
|
---|
158 | /// when this value is set to NULL.
|
---|
159 | ///
|
---|
160 | EFI_SPI_CLOCK Clock;
|
---|
161 |
|
---|
162 | ///
|
---|
163 | /// Address of a data structure containing the additional values which
|
---|
164 | /// describe the necessary control for the clock. When Clock is NULL,
|
---|
165 | /// the declaration for this data structure is provided by the vendor of the
|
---|
166 | /// host's SPI controller driver. When Clock is not NULL, the declaration for
|
---|
167 | /// this data structure is provided by the board layer.
|
---|
168 | ///
|
---|
169 | VOID *ClockParameter;
|
---|
170 | } EFI_SPI_BUS;
|
---|
171 |
|
---|
172 | ///
|
---|
173 | /// Definitions of SPI Part Attributes.
|
---|
174 | ///
|
---|
175 | #define SPI_PART_SUPPORTS_2_BIT_DATA_BUS_WIDTH BIT0
|
---|
176 | #define SPI_PART_SUPPORTS_4_BIT_DATA_BUS_WIDTH BIT1
|
---|
177 | #define SPI_PART_SUPPORTS_8_BIT_DATA_BUS_WIDTH BIT2
|
---|
178 |
|
---|
179 | ///
|
---|
180 | /// The EFI_SPI_PERIPHERAL data structure describes how a specific block of
|
---|
181 | /// logic which is connected to the SPI bus. This data structure also selects
|
---|
182 | /// which upper level driver is used to manipulate this SPI device.
|
---|
183 | /// The SpiPeripheraLDriverGuid is available from the vendor of the SPI
|
---|
184 | /// peripheral driver.
|
---|
185 | ///
|
---|
186 | struct _EFI_SPI_PERIPHERAL {
|
---|
187 | ///
|
---|
188 | /// Address of the next EFI_SPI_PERIPHERAL data structure. Specify NULL if
|
---|
189 | /// the current data structure is the last one on the SPI bus.
|
---|
190 | ///
|
---|
191 | CONST EFI_SPI_PERIPHERAL *NextSpiPeripheral;
|
---|
192 |
|
---|
193 | ///
|
---|
194 | /// A unicode string describing the function of the SPI part.
|
---|
195 | ///
|
---|
196 | CONST CHAR16 *FriendlyName;
|
---|
197 |
|
---|
198 | ///
|
---|
199 | /// Address of a GUID provided by the vendor of the SPI peripheral driver.
|
---|
200 | /// Instead of using a " EFI_SPI_IO_PROTOCOL" GUID, the SPI bus driver uses
|
---|
201 | /// this GUID to identify an EFI_SPI_IO_PROTOCOL data structure and to
|
---|
202 | /// provide the connection points for the SPI peripheral drivers.
|
---|
203 | /// This reduces the comparison logic in the SPI peripheral driver's
|
---|
204 | /// Supported routine.
|
---|
205 | ///
|
---|
206 | CONST GUID *SpiPeripheralDriverGuid;
|
---|
207 |
|
---|
208 | ///
|
---|
209 | /// The address of an EFI_SPI_PART data structure which describes this chip.
|
---|
210 | ///
|
---|
211 | CONST EFI_SPI_PART *SpiPart;
|
---|
212 |
|
---|
213 | ///
|
---|
214 | /// The maximum clock frequency is specified in the EFI_SPI_P ART. When this
|
---|
215 | /// this value is non-zero and less than the value in the EFI_SPI_PART then
|
---|
216 | /// this value is used for the maximum clock frequency for the SPI part.
|
---|
217 | ///
|
---|
218 | UINT32 MaxClockHz;
|
---|
219 |
|
---|
220 | ///
|
---|
221 | /// Specify the idle value of the clock as found in the datasheet.
|
---|
222 | /// Use zero (0) if the clock'S idle value is low or one (1) if the the
|
---|
223 | /// clock's idle value is high.
|
---|
224 | ///
|
---|
225 | BOOLEAN ClockPolarity;
|
---|
226 |
|
---|
227 | ///
|
---|
228 | /// Specify the clock delay after chip select. Specify zero (0) to delay an
|
---|
229 | /// entire clock cycle or one (1) to delay only half a clock cycle.
|
---|
230 | ///
|
---|
231 | BOOLEAN ClockPhase;
|
---|
232 |
|
---|
233 | ///
|
---|
234 | /// SPI peripheral attributes, select zero or more of:
|
---|
235 | /// * SPI_PART_SUPPORTS_2_B1T_DATA_BUS_W1DTH - The SPI peripheral is wired to
|
---|
236 | /// support a 2-bit data bus
|
---|
237 | /// * SPI_PART_SUPPORTS_4_B1T_DATA_BUS_W1DTH - The SPI peripheral is wired to
|
---|
238 | /// support a 4-bit data bus
|
---|
239 | ///
|
---|
240 | UINT32 Attributes;
|
---|
241 |
|
---|
242 | ///
|
---|
243 | /// Address of a vendor specific data structure containing additional board
|
---|
244 | /// configuration details related to the SPI chip. The SPI peripheral layer
|
---|
245 | /// uses this data structure when configuring the chip.
|
---|
246 | ///
|
---|
247 | CONST VOID *ConfigurationData;
|
---|
248 |
|
---|
249 | ///
|
---|
250 | /// The address of an EFI_SPI_BUS data structure which describes the SPI bus
|
---|
251 | /// to which this chip is connected.
|
---|
252 | ///
|
---|
253 | CONST EFI_SPI_BUS *SpiBus;
|
---|
254 |
|
---|
255 | ///
|
---|
256 | /// Address of the routine which controls the chip select pin for this SPI
|
---|
257 | /// peripheral. Call the SPI host controller's chip select routine when this
|
---|
258 | /// value is set to NULL.
|
---|
259 | ///
|
---|
260 | EFI_SPI_CHIP_SELECT ChipSelect;
|
---|
261 |
|
---|
262 | ///
|
---|
263 | /// Address of a data structure containing the additional values which
|
---|
264 | /// describe the necessary control for the chip select. When ChipSelect is
|
---|
265 | /// NULL, the declaration for this data structure is provided by the vendor
|
---|
266 | /// of the host's SPI controller driver. The vendor's documentation specifies
|
---|
267 | /// the necessary values to use for the chip select pin selection and
|
---|
268 | /// control. When Chipselect is not NULL, the declaration for this data
|
---|
269 | /// structure is provided by the board layer.
|
---|
270 | ///
|
---|
271 | VOID *ChipSelectParameter;
|
---|
272 | };
|
---|
273 |
|
---|
274 | ///
|
---|
275 | /// Describe the details of the board's SPI busses to the SPI driver stack.
|
---|
276 | /// The board layer uses the EFI_SPI_CONFIGURATION_PROTOCOL to expose the data
|
---|
277 | /// tables which describe the board's SPI busses, The SPI bus layer uses these
|
---|
278 | /// tables to configure the clock, chip select and manage the SPI transactions
|
---|
279 | /// on the SPI controllers.
|
---|
280 | ///
|
---|
281 | typedef struct _EFI_SPI_CONFIGURATION_PROTOCOL {
|
---|
282 | ///
|
---|
283 | /// The number of SPI busses on the board.
|
---|
284 | ///
|
---|
285 | UINT32 BusCount;
|
---|
286 |
|
---|
287 | ///
|
---|
288 | /// The address of an array of EFI_SPI_BUS data structure addresses.
|
---|
289 | ///
|
---|
290 | CONST EFI_SPI_BUS *CONST *CONST Buslist;
|
---|
291 | } EFI_SPI_CONFIGURATION_PROTOCOL;
|
---|
292 |
|
---|
293 | extern EFI_GUID gEfiSpiConfigurationProtocolGuid;
|
---|
294 |
|
---|
295 | #endif // __SPI_CONFIGURATION_PROTOCOL_H__
|
---|