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