3 The definition for SD host controller driver model and HC protocol routines.
5 Copyright (c) 2013-2015 Intel Corporation.
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _SD_CONTROLLER_H_
18 #define _SD_CONTROLLER_H_
24 #include <Protocol/PciIo.h>
26 #include <Library/DebugLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/UefiLib.h>
31 #include <Library/BaseLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/PcdLib.h>
34 #include <IndustryStandard/Pci22.h>
37 #include "ComponentName.h"
41 extern EFI_DRIVER_BINDING_PROTOCOL gSDControllerDriverBinding
;
42 extern EFI_COMPONENT_NAME_PROTOCOL gSDControllerName
;
43 extern EFI_COMPONENT_NAME2_PROTOCOL gSDControllerName2
;
46 #define SDHOST_DATA_SIGNATURE SIGNATURE_32 ('s', 'd', 'h', 's')
48 #define BLOCK_SIZE 0x200
49 #define TIME_OUT_1S 1000
53 // PCI Class Code structure
66 EFI_SD_HOST_IO_PROTOCOL SDHostIo
;
67 EFI_PCI_IO_PROTOCOL
*PciIo
;
68 BOOLEAN IsAutoStopCmd
;
69 UINT32 BaseClockInMHz
;
70 UINT32 CurrentClockInKHz
;
72 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
75 #define SDHOST_DATA_FROM_THIS(a) \
76 CR(a, SDHOST_DATA, SDHostIo, SDHOST_DATA_SIGNATURE)
79 Test to see if this driver supports ControllerHandle. Any
80 ControllerHandle that has SDHostIoProtocol installed will be supported.
82 @param This Protocol instance pointer.
83 @param Controller Handle of device to test.
84 @param RemainingDevicePath Not used.
86 @return EFI_SUCCESS This driver supports this device.
87 @return EFI_UNSUPPORTED This driver does not support this device.
92 SDControllerSupported (
93 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
94 IN EFI_HANDLE Controller
,
95 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
99 Starting the SD Host Controller Driver.
101 @param This Protocol instance pointer.
102 @param Controller Handle of device to test.
103 @param RemainingDevicePath Not used.
105 @retval EFI_SUCCESS This driver supports this device.
106 @retval EFI_UNSUPPORTED This driver does not support this device.
107 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
108 EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
114 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
115 IN EFI_HANDLE Controller
,
116 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
120 Stop this driver on ControllerHandle. Support stoping any child handles
121 created by this driver.
123 @param This Protocol instance pointer.
124 @param Controller Handle of device to stop driver on.
125 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
126 @param ChildHandleBuffer List of handles for the children we need to stop.
135 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
136 IN EFI_HANDLE Controller
,
137 IN UINTN NumberOfChildren
,
138 IN EFI_HANDLE
*ChildHandleBuffer
142 The main function used to send the command to the card inserted into the SD host slot.
143 It will assemble the arguments to set the command register and wait for the command
144 and transfer completed until timeout. Then it will read the response register to fill
147 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
148 @param CommandIndex The command index to set the command index field of command register.
149 @param Argument Command argument to set the argument field of command register.
150 @param DataType TRANSFER_TYPE, indicates no data, data in or data out.
151 @param Buffer Contains the data read from / write to the device.
152 @param BufferSize The size of the buffer.
153 @param ResponseType RESPONSE_TYPE.
154 @param TimeOut Time out value in 1 ms unit.
155 @param ResponseData Depending on the ResponseType, such as CSD or card status.
158 @retval EFI_INVALID_PARAMETER
159 @retval EFI_OUT_OF_RESOURCES
161 @retval EFI_DEVICE_ERROR
167 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
168 IN UINT16 CommandIndex
,
170 IN TRANSFER_TYPE DataType
,
171 IN UINT8
*Buffer
, OPTIONAL
172 IN UINT32 BufferSize
,
173 IN RESPONSE_TYPE ResponseType
,
175 OUT UINT32
*ResponseData OPTIONAL
179 Set max clock frequency of the host, the actual frequency may not be the same as MaxFrequency.
180 It depends on the max frequency the host can support, divider, and host speed mode.
182 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
183 @param MaxFrequency Max frequency in HZ.
192 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
193 IN UINT32 MaxFrequencyInKHz
197 Set bus width of the host controller
199 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
200 @param BusWidth Bus width in 1, 4, 8 bits.
203 @retval EFI_INVALID_PARAMETER
209 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
215 Set voltage which could supported by the host controller.
216 Support 0(Power off the host), 1.8V, 3.0V, 3.3V
218 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
219 @param Voltage Units in 0.1 V.
222 @retval EFI_INVALID_PARAMETER
228 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
234 Reset the host controller.
236 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
237 @param ResetAll TRUE to reset all.
246 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
247 IN RESET_TYPE ResetType
252 Enable auto stop on the host controller.
254 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
255 @param Enable TRUE to enable, FALSE to disable.
264 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
269 Find whether these is a card inserted into the slot. If so init the host.
270 If not, return EFI_NOT_FOUND.
272 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
275 @retval EFI_NOT_FOUND
280 DetectCardAndInitHost (
281 IN EFI_SD_HOST_IO_PROTOCOL
*This
285 Set the Block length on the host controller.
287 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
288 @param BlockLength card supportes block length.
297 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
298 IN UINT32 BlockLength
302 Enable/Disable High Speed transfer mode
304 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance.
305 @param Enable TRUE to Enable, FALSE to Disable
312 IN EFI_SD_HOST_IO_PROTOCOL
*This
,
319 IN EFI_SD_HOST_IO_PROTOCOL
*This
,