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