3 The definition for SD host controller driver model and HC protocol routines.
5 Copyright (c) 2013-2016 Intel Corporation.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _SD_CONTROLLER_H_
12 #define _SD_CONTROLLER_H_
18 #include <Protocol/PciIo.h>
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>
31 #include "ComponentName.h"
35 extern EFI_DRIVER_BINDING_PROTOCOL gSDControllerDriverBinding
;
36 extern EFI_COMPONENT_NAME_PROTOCOL gSDControllerName
;
37 extern EFI_COMPONENT_NAME2_PROTOCOL gSDControllerName2
;
40 #define SDHOST_DATA_SIGNATURE SIGNATURE_32 ('s', 'd', 'h', 's')
42 #define BLOCK_SIZE 0x200
43 #define TIME_OUT_1S 1000
47 // PCI Class Code structure
60 EFI_SD_HOST_IO_PROTOCOL SDHostIo
;
61 EFI_PCI_IO_PROTOCOL
*PciIo
;
62 BOOLEAN IsAutoStopCmd
;
63 UINT32 BaseClockInMHz
;
64 UINT32 CurrentClockInKHz
;
66 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
69 #define SDHOST_DATA_FROM_THIS(a) \
70 CR(a, SDHOST_DATA, SDHostIo, SDHOST_DATA_SIGNATURE)
73 Test to see if this driver supports ControllerHandle. Any
74 ControllerHandle that has SDHostIoProtocol installed will be supported.
76 @param This Protocol instance pointer.
77 @param Controller Handle of device to test.
78 @param RemainingDevicePath Not used.
80 @return EFI_SUCCESS This driver supports this device.
81 @return EFI_UNSUPPORTED This driver does not support this device.
86 SDControllerSupported (
87 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
88 IN EFI_HANDLE Controller
,
89 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
93 Starting the SD Host Controller Driver.
95 @param This Protocol instance pointer.
96 @param Controller Handle of device to test.
97 @param RemainingDevicePath Not used.
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.
108 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
109 IN EFI_HANDLE Controller
,
110 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
114 Stop this driver on ControllerHandle. Support stopping any child handles
115 created by this driver.
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.
129 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
130 IN EFI_HANDLE Controller
,
131 IN UINTN NumberOfChildren
,
132 IN EFI_HANDLE
*ChildHandleBuffer
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
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.
152 @retval EFI_INVALID_PARAMETER
153 @retval EFI_OUT_OF_RESOURCES
155 @retval EFI_DEVICE_ERROR
161 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
162 IN UINT16 CommandIndex
,
164 IN TRANSFER_TYPE DataType
,
165 IN UINT8
*Buffer
, OPTIONAL
166 IN UINT32 BufferSize
,
167 IN RESPONSE_TYPE ResponseType
,
169 OUT UINT32
*ResponseData OPTIONAL
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.
176 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
177 @param MaxFrequency Max frequency in HZ.
186 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
187 IN UINT32 MaxFrequencyInKHz
191 Set bus width of the host controller
193 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
194 @param BusWidth Bus width in 1, 4, 8 bits.
197 @retval EFI_INVALID_PARAMETER
203 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
209 Set voltage which could supported by the host controller.
210 Support 0(Power off the host), 1.8V, 3.0V, 3.3V
212 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
213 @param Voltage Units in 0.1 V.
216 @retval EFI_INVALID_PARAMETER
222 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
228 Reset the host controller.
230 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
231 @param ResetAll TRUE to reset all.
240 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
241 IN RESET_TYPE ResetType
246 Enable auto stop on the host controller.
248 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
249 @param Enable TRUE to enable, FALSE to disable.
258 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
263 Find whether these is a card inserted into the slot. If so init the host.
264 If not, return EFI_NOT_FOUND.
266 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
269 @retval EFI_NOT_FOUND
274 DetectCardAndInitHost (
275 IN EFI_SD_HOST_IO_PROTOCOL
*This
279 Set the Block length on the host controller.
281 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
282 @param BlockLength card supportes block length.
291 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
292 IN UINT32 BlockLength
296 Enable/Disable High Speed transfer mode
298 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
299 @param Enable TRUE to Enable, FALSE to Disable
306 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
313 IN EFI_SD_HOST_IO_PROTOCOL
*This
,