]>
Commit | Line | Data |
---|---|---|
9b6bbcdb MK |
1 | /** @file\r |
2 | \r | |
3 | The definition for SD host controller driver model and HC protocol routines.\r | |
4 | \r | |
74c6a103 | 5 | Copyright (c) 2013-2016 Intel Corporation.\r |
9b6bbcdb | 6 | \r |
c9f231d0 | 7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
9b6bbcdb MK |
8 | \r |
9 | **/\r | |
10 | \r | |
11 | #ifndef _SD_CONTROLLER_H_\r | |
12 | #define _SD_CONTROLLER_H_\r | |
13 | \r | |
14 | \r | |
15 | #include <Uefi.h>\r | |
16 | \r | |
17 | \r | |
18 | #include <Protocol/PciIo.h>\r | |
19 | \r | |
20 | #include <Library/DebugLib.h>\r | |
21 | #include <Library/BaseMemoryLib.h>\r | |
22 | #include <Library/UefiDriverEntryPoint.h>\r | |
23 | #include <Library/UefiBootServicesTableLib.h>\r | |
24 | #include <Library/UefiLib.h>\r | |
25 | #include <Library/BaseLib.h>\r | |
26 | #include <Library/MemoryAllocationLib.h>\r | |
27 | #include <Library/PcdLib.h>\r | |
28 | #include <IndustryStandard/Pci22.h>\r | |
29 | \r | |
30 | \r | |
31 | #include "ComponentName.h"\r | |
32 | #include "SDHostIo.h"\r | |
33 | \r | |
34 | \r | |
35 | extern EFI_DRIVER_BINDING_PROTOCOL gSDControllerDriverBinding;\r | |
36 | extern EFI_COMPONENT_NAME_PROTOCOL gSDControllerName;\r | |
37 | extern EFI_COMPONENT_NAME2_PROTOCOL gSDControllerName2;\r | |
38 | \r | |
39 | \r | |
40 | #define SDHOST_DATA_SIGNATURE SIGNATURE_32 ('s', 'd', 'h', 's')\r | |
41 | \r | |
42 | #define BLOCK_SIZE 0x200\r | |
43 | #define TIME_OUT_1S 1000\r | |
44 | \r | |
45 | #pragma pack(1)\r | |
46 | //\r | |
47 | // PCI Class Code structure\r | |
48 | //\r | |
49 | typedef struct {\r | |
50 | UINT8 PI;\r | |
51 | UINT8 SubClassCode;\r | |
52 | UINT8 BaseCode;\r | |
53 | } PCI_CLASSC;\r | |
54 | \r | |
55 | #pragma pack()\r | |
56 | \r | |
57 | \r | |
58 | typedef struct {\r | |
59 | UINTN Signature;\r | |
60 | EFI_SD_HOST_IO_PROTOCOL SDHostIo;\r | |
61 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
62 | BOOLEAN IsAutoStopCmd;\r | |
63 | UINT32 BaseClockInMHz;\r | |
64 | UINT32 CurrentClockInKHz;\r | |
65 | UINT32 BlockLength;\r | |
66 | EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r | |
67 | }SDHOST_DATA;\r | |
68 | \r | |
69 | #define SDHOST_DATA_FROM_THIS(a) \\r | |
70 | CR(a, SDHOST_DATA, SDHostIo, SDHOST_DATA_SIGNATURE)\r | |
71 | \r | |
72 | /**\r | |
73 | Test to see if this driver supports ControllerHandle. Any\r | |
74 | ControllerHandle that has SDHostIoProtocol installed will be supported.\r | |
75 | \r | |
76 | @param This Protocol instance pointer.\r | |
77 | @param Controller Handle of device to test.\r | |
78 | @param RemainingDevicePath Not used.\r | |
79 | \r | |
80 | @return EFI_SUCCESS This driver supports this device.\r | |
81 | @return EFI_UNSUPPORTED This driver does not support this device.\r | |
82 | \r | |
83 | **/\r | |
84 | EFI_STATUS\r | |
85 | EFIAPI\r | |
86 | SDControllerSupported (\r | |
87 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
88 | IN EFI_HANDLE Controller,\r | |
89 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
90 | );\r | |
91 | \r | |
92 | /**\r | |
93 | Starting the SD Host Controller Driver.\r | |
94 | \r | |
95 | @param This Protocol instance pointer.\r | |
96 | @param Controller Handle of device to test.\r | |
97 | @param RemainingDevicePath Not used.\r | |
98 | \r | |
99 | @retval EFI_SUCCESS This driver supports this device.\r | |
100 | @retval EFI_UNSUPPORTED This driver does not support this device.\r | |
101 | @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.\r | |
102 | EFI_OUT_OF_RESOURCES- Failed due to resource shortage.\r | |
103 | \r | |
104 | **/\r | |
105 | EFI_STATUS\r | |
106 | EFIAPI\r | |
107 | SDControllerStart (\r | |
108 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
109 | IN EFI_HANDLE Controller,\r | |
110 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
111 | );\r | |
112 | \r | |
113 | /**\r | |
74c6a103 | 114 | Stop this driver on ControllerHandle. Support stopping any child handles\r |
9b6bbcdb MK |
115 | created by this driver.\r |
116 | \r | |
117 | @param This Protocol instance pointer.\r | |
118 | @param Controller Handle of device to stop driver on.\r | |
119 | @param NumberOfChildren Number of Children in the ChildHandleBuffer.\r | |
120 | @param ChildHandleBuffer List of handles for the children we need to stop.\r | |
121 | \r | |
122 | @return EFI_SUCCESS\r | |
123 | @return others\r | |
124 | \r | |
125 | **/\r | |
126 | EFI_STATUS\r | |
127 | EFIAPI\r | |
128 | SDControllerStop (\r | |
129 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
130 | IN EFI_HANDLE Controller,\r | |
131 | IN UINTN NumberOfChildren,\r | |
132 | IN EFI_HANDLE *ChildHandleBuffer\r | |
133 | );\r | |
134 | \r | |
135 | /**\r | |
136 | The main function used to send the command to the card inserted into the SD host slot.\r | |
137 | It will assemble the arguments to set the command register and wait for the command\r | |
138 | and transfer completed until timeout. Then it will read the response register to fill\r | |
139 | the ResponseData.\r | |
140 | \r | |
141 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
142 | @param CommandIndex The command index to set the command index field of command register.\r | |
143 | @param Argument Command argument to set the argument field of command register.\r | |
144 | @param DataType TRANSFER_TYPE, indicates no data, data in or data out.\r | |
145 | @param Buffer Contains the data read from / write to the device.\r | |
146 | @param BufferSize The size of the buffer.\r | |
147 | @param ResponseType RESPONSE_TYPE.\r | |
148 | @param TimeOut Time out value in 1 ms unit.\r | |
149 | @param ResponseData Depending on the ResponseType, such as CSD or card status.\r | |
150 | \r | |
151 | @retval EFI_SUCCESS\r | |
152 | @retval EFI_INVALID_PARAMETER\r | |
153 | @retval EFI_OUT_OF_RESOURCES\r | |
154 | @retval EFI_TIMEOUT\r | |
155 | @retval EFI_DEVICE_ERROR\r | |
156 | \r | |
157 | **/\r | |
158 | EFI_STATUS\r | |
159 | EFIAPI\r | |
160 | SendCommand (\r | |
161 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
162 | IN UINT16 CommandIndex,\r | |
163 | IN UINT32 Argument,\r | |
164 | IN TRANSFER_TYPE DataType,\r | |
165 | IN UINT8 *Buffer, OPTIONAL\r | |
166 | IN UINT32 BufferSize,\r | |
167 | IN RESPONSE_TYPE ResponseType,\r | |
168 | IN UINT32 TimeOut,\r | |
169 | OUT UINT32 *ResponseData OPTIONAL\r | |
170 | );\r | |
171 | \r | |
172 | /**\r | |
173 | Set max clock frequency of the host, the actual frequency may not be the same as MaxFrequency.\r | |
174 | It depends on the max frequency the host can support, divider, and host speed mode.\r | |
175 | \r | |
176 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
177 | @param MaxFrequency Max frequency in HZ.\r | |
178 | \r | |
179 | @retval EFI_SUCCESS\r | |
180 | @retval EFI_TIMEOUT\r | |
181 | \r | |
182 | **/\r | |
183 | EFI_STATUS\r | |
184 | EFIAPI\r | |
185 | SetClockFrequency (\r | |
186 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
187 | IN UINT32 MaxFrequencyInKHz\r | |
188 | );\r | |
189 | \r | |
190 | /**\r | |
191 | Set bus width of the host controller\r | |
192 | \r | |
193 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
194 | @param BusWidth Bus width in 1, 4, 8 bits.\r | |
195 | \r | |
196 | @retval EFI_SUCCESS\r | |
197 | @retval EFI_INVALID_PARAMETER\r | |
198 | \r | |
199 | **/\r | |
200 | EFI_STATUS\r | |
201 | EFIAPI\r | |
202 | SetBusWidth (\r | |
203 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
204 | IN UINT32 BusWidth\r | |
205 | );\r | |
206 | \r | |
207 | \r | |
208 | /**\r | |
209 | Set voltage which could supported by the host controller.\r | |
210 | Support 0(Power off the host), 1.8V, 3.0V, 3.3V\r | |
211 | \r | |
212 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
213 | @param Voltage Units in 0.1 V.\r | |
214 | \r | |
215 | @retval EFI_SUCCESS\r | |
216 | @retval EFI_INVALID_PARAMETER\r | |
217 | \r | |
218 | **/\r | |
219 | EFI_STATUS\r | |
220 | EFIAPI\r | |
221 | SetHostVoltage (\r | |
222 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
223 | IN UINT32 Voltage\r | |
224 | );\r | |
225 | \r | |
226 | \r | |
227 | /**\r | |
228 | Reset the host controller.\r | |
229 | \r | |
230 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
231 | @param ResetAll TRUE to reset all.\r | |
232 | \r | |
233 | @retval EFI_SUCCESS\r | |
234 | @retval EFI_TIMEOUT\r | |
235 | \r | |
236 | **/\r | |
237 | EFI_STATUS\r | |
238 | EFIAPI\r | |
239 | ResetSDHost (\r | |
240 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
241 | IN RESET_TYPE ResetType\r | |
242 | );\r | |
243 | \r | |
244 | \r | |
245 | /**\r | |
246 | Enable auto stop on the host controller.\r | |
247 | \r | |
248 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
249 | @param Enable TRUE to enable, FALSE to disable.\r | |
250 | \r | |
251 | @retval EFI_SUCCESS\r | |
252 | @retval EFI_TIMEOUT\r | |
253 | \r | |
254 | **/\r | |
255 | EFI_STATUS\r | |
256 | EFIAPI\r | |
257 | EnableAutoStopCmd (\r | |
258 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
259 | IN BOOLEAN Enable\r | |
260 | );\r | |
261 | \r | |
262 | /**\r | |
263 | Find whether these is a card inserted into the slot. If so init the host.\r | |
264 | If not, return EFI_NOT_FOUND.\r | |
265 | \r | |
266 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
267 | \r | |
268 | @retval EFI_SUCCESS\r | |
269 | @retval EFI_NOT_FOUND\r | |
270 | \r | |
271 | **/\r | |
272 | EFI_STATUS\r | |
273 | EFIAPI\r | |
274 | DetectCardAndInitHost (\r | |
275 | IN EFI_SD_HOST_IO_PROTOCOL *This\r | |
276 | );\r | |
277 | \r | |
278 | /**\r | |
279 | Set the Block length on the host controller.\r | |
280 | \r | |
281 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
282 | @param BlockLength card supportes block length.\r | |
283 | \r | |
284 | @retval EFI_SUCCESS\r | |
285 | @retval EFI_TIMEOUT\r | |
286 | \r | |
287 | **/\r | |
288 | EFI_STATUS\r | |
289 | EFIAPI\r | |
290 | SetBlockLength (\r | |
291 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
292 | IN UINT32 BlockLength\r | |
293 | );\r | |
294 | \r | |
295 | /**\r | |
296 | Enable/Disable High Speed transfer mode\r | |
297 | \r | |
298 | @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.\r | |
299 | @param Enable TRUE to Enable, FALSE to Disable\r | |
300 | \r | |
301 | @return EFI_SUCCESS\r | |
302 | **/\r | |
303 | EFI_STATUS\r | |
304 | EFIAPI\r | |
305 | SetHighSpeedMode (\r | |
306 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
307 | IN BOOLEAN Enable\r | |
308 | );\r | |
309 | \r | |
310 | EFI_STATUS\r | |
311 | EFIAPI\r | |
312 | SetDDRMode (\r | |
313 | IN EFI_SD_HOST_IO_PROTOCOL *This,\r | |
314 | IN BOOLEAN Enable\r | |
315 | );\r | |
316 | #endif\r |