1 /** @file 2 3 Interface definition for EFI_SD_HOST_IO_PROTOCOL. 4 5 Copyright (c) 2013-2015 Intel Corporation. 6 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 11 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. 14 15 **/ 16 17 #ifndef _SD_HOST_IO_H 18 #define _SD_HOST_IO_H 19 20 #include "SDCard.h" 21 #include "CEATA.h" 22 23 24 #define EFI_SD_HOST_IO_PROTOCOL_GUID \ 25 { \ 26 0xb63f8ec7, 0xa9c9, 0x4472, {0xa4, 0xc0, 0x4d, 0x8b, 0xf3, 0x65, 0xcc, 0x51} \ 27 } 28 29 /// 30 /// Forward reference for pure ANSI compatability 31 /// 32 typedef struct _EFI_SD_HOST_IO_PROTOCOL EFI_SD_HOST_IO_PROTOCOL; 33 34 35 36 typedef enum { 37 ResponseNo = 0, 38 ResponseR1, 39 ResponseR1b, 40 ResponseR2, 41 ResponseR3, 42 ResponseR4, 43 ResponseR5, 44 ResponseR5b, 45 ResponseR6, 46 ResponseR7 47 }RESPONSE_TYPE; 48 49 typedef enum { 50 NoData = 0, 51 InData, 52 OutData 53 }TRANSFER_TYPE; 54 55 typedef enum { 56 Reset_Auto = 0, 57 Reset_DAT, 58 Reset_CMD, 59 Reset_DAT_CMD, 60 Reset_All 61 }RESET_TYPE; 62 63 #define PCI_SUBCLASS_SD_HOST_CONTROLLER 0x05 64 #define PCI_IF_STANDARD_HOST_NO_DMA 0x00 65 #define PCI_IF_STANDARD_HOST_SUPPORT_DMA 0x01 66 67 #define SDHCI_SPEC_100 0 68 #define SDHCI_SPEC_200 1 69 #define SDHCI_SPEC_300 2 70 71 // 72 //MMIO Registers definition for MMC/SDIO controller 73 // 74 #define MMIO_DMAADR 0x00 75 #define MMIO_BLKSZ 0x04 76 #define MMIO_BLKCNT 0x06 77 #define MMIO_CMDARG 0x08 78 #define MMIO_XFRMODE 0x0C 79 #define MMIO_SDCMD 0x0E 80 #define MMIO_RESP 0x10 81 #define MMIO_BUFDATA 0x20 82 #define MMIO_PSTATE 0x24 83 #define MMIO_HOSTCTL 0x28 84 #define MMIO_PWRCTL 0x29 85 #define MMIO_BLKGAPCTL 0x2A 86 #define MMIO_WAKECTL 0x2B 87 #define MMIO_CLKCTL 0x2C 88 #define V_MMIO_CLKCTL_MAX_8BIT_FREQ_SEL 0x80 89 #define V_MMIO_CLKCTL_MAX_10BIT_FREQ_SEL 0x3FF 90 #define B_MMIO_CLKCTL_UPR_SDCLK_FREQ_SEL_MASK 0xC0 91 92 #define MMIO_TOCTL 0x2E 93 #define MMIO_SWRST 0x2F 94 #define MMIO_NINTSTS 0x30 95 #define MMIO_ERINTSTS 0x32 96 #define MMIO_NINTEN 0x34 97 #define MMIO_ERINTEN 0x36 98 #define MMIO_NINTSIGEN 0x38 99 #define MMIO_ERINTSIGEN 0x3A 100 #define MMIO_AC12ERRSTS 0x3C 101 #define MMIO_HOSTCTL2 0x3E 102 #define MMIO_CAP 0x40 103 #define MMIO_MCCAP 0x48 104 #define MMIO_SLTINTSTS 0xFC 105 #define MMIO_CTRLRVER 0xFE 106 #define MMIO_SRST 0x1FC 107 108 // 109 // Protocol definitions 110 // 111 112 /** 113 The main function used to send the command to the card inserted into the SD host slot. 114 It will assemble the arguments to set the command register and wait for the command 115 and transfer completed until timeout. Then it will read the response register to fill 116 the ResponseData. 117 118 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 119 @param CommandIndex The command index to set the command index field of command register. 120 @param Argument Command argument to set the argument field of command register. 121 @param DataType TRANSFER_TYPE, indicates no data, data in or data out. 122 @param Buffer Contains the data read from / write to the device. 123 @param BufferSize The size of the buffer. 124 @param ResponseType RESPONSE_TYPE. 125 @param TimeOut Time out value in 1 ms unit. 126 @param ResponseData Depending on the ResponseType, such as CSD or card status. 127 128 @retval EFI_SUCCESS 129 @retval EFI_INVALID_PARAMETER 130 @retval EFI_OUT_OF_RESOURCES 131 @retval EFI_TIMEOUT 132 @retval EFI_DEVICE_ERROR 133 134 **/ 135 136 typedef 137 EFI_STATUS 138 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SEND_COMMAND) ( 139 IN EFI_SD_HOST_IO_PROTOCOL *This, 140 IN UINT16 CommandIndex, 141 IN UINT32 Argument, 142 IN TRANSFER_TYPE DataType, 143 IN UINT8 *Buffer, OPTIONAL 144 IN UINT32 BufferSize, 145 IN RESPONSE_TYPE ResponseType, 146 IN UINT32 TimeOut, 147 OUT UINT32 *ResponseData OPTIONAL 148 ); 149 150 /** 151 Set max clock frequency of the host, the actual frequency may not be the same as MaxFrequency. 152 It depends on the max frequency the host can support, divider, and host speed mode. 153 154 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 155 @param MaxFrequency Max frequency in HZ. 156 157 @retval EFI_SUCCESS 158 @retval EFI_TIMEOUT 159 160 **/ 161 162 typedef 163 EFI_STATUS 164 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_CLOCK_FREQUENCY) ( 165 IN EFI_SD_HOST_IO_PROTOCOL *This, 166 IN UINT32 MaxFrequency 167 ); 168 169 170 /** 171 Set bus width of the host controller 172 173 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 174 @param BusWidth Bus width in 1, 4, 8 bits. 175 176 @retval EFI_SUCCESS 177 @retval EFI_INVALID_PARAMETER 178 179 **/ 180 181 typedef 182 EFI_STATUS 183 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_BUS_WIDTH) ( 184 IN EFI_SD_HOST_IO_PROTOCOL *This, 185 IN UINT32 BusWidth 186 ); 187 188 /** 189 Set voltage which could supported by the host controller. 190 Support 0(Power off the host), 1.8V, 3.0V, 3.3V 191 192 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 193 @param Voltage Units in 0.1 V. 194 195 @retval EFI_SUCCESS 196 @retval EFI_INVALID_PARAMETER 197 198 **/ 199 200 typedef 201 EFI_STATUS 202 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_HOST_VOLTAGE) ( 203 IN EFI_SD_HOST_IO_PROTOCOL *This, 204 IN UINT32 Voltage 205 ); 206 207 /** 208 Reset the host controller. 209 210 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 211 @param ResetAll TRUE to reset all. 212 213 @retval EFI_SUCCESS 214 @retval EFI_TIMEOUT 215 216 **/ 217 218 typedef 219 EFI_STATUS 220 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_RESET_SD_HOST) ( 221 IN EFI_SD_HOST_IO_PROTOCOL *This, 222 IN RESET_TYPE ResetType 223 ); 224 225 /** 226 Enable auto stop on the host controller. 227 228 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 229 @param Enable TRUE to enable, FALSE to disable. 230 231 @retval EFI_SUCCESS 232 @retval EFI_TIMEOUT 233 234 **/ 235 236 typedef 237 EFI_STATUS 238 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_ENABLE_AUTO_STOP_CMD) ( 239 IN EFI_SD_HOST_IO_PROTOCOL *This, 240 IN BOOLEAN Enable 241 ); 242 243 /** 244 Find whether these is a card inserted into the slot. If so init the host. 245 If not, return EFI_NOT_FOUND. 246 247 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 248 249 @retval EFI_SUCCESS 250 @retval EFI_NOT_FOUND 251 252 **/ 253 254 typedef 255 EFI_STATUS 256 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_DETECT_CARD_AND_INIT_HOST) ( 257 IN EFI_SD_HOST_IO_PROTOCOL *This 258 ); 259 260 /** 261 Set the Block length on the host controller. 262 263 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 264 @param BlockLength card supportes block length. 265 266 @retval EFI_SUCCESS 267 @retval EFI_TIMEOUT 268 269 **/ 270 271 typedef 272 EFI_STATUS 273 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_SET_BLOCK_LENGTH) ( 274 IN EFI_SD_HOST_IO_PROTOCOL *This, 275 IN UINT32 BlockLength 276 ); 277 278 /** 279 Enable/Disable High Speed transfer mode 280 281 @param This A pointer to the EFI_SD_HOST_IO_PROTOCOL instance. 282 @param Enable TRUE to Enable, FALSE to Disable 283 284 @return EFI_SUCCESS 285 **/ 286 typedef 287 EFI_STATUS 288 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_HIGH_SPEED_MODE) ( 289 IN EFI_SD_HOST_IO_PROTOCOL *This, 290 IN BOOLEAN Enable 291 ); 292 293 typedef 294 EFI_STATUS 295 (EFIAPI *EFI_SD_HOST_IO_PROTOCOL_DUAL_DATARATE_MODE) ( 296 IN EFI_SD_HOST_IO_PROTOCOL *This, 297 IN BOOLEAN Enable 298 ); 299 300 301 302 #define EFI_SD_HOST_IO_PROTOCOL_REVISION_01 0x02 303 304 305 typedef struct { 306 UINT32 HighSpeedSupport: 1; //High speed supported 307 UINT32 V18Support: 1; //1.8V supported 308 UINT32 V30Support: 1; //3.0V supported 309 UINT32 V33Support: 1; //3.3V supported 310 UINT32 Reserved0: 4; 311 UINT32 HostVersion: 8; 312 UINT32 BusWidth4: 1; // 4 bit width 313 UINT32 BusWidth8: 1; // 8 bit width 314 UINT32 Reserved1: 14; 315 UINT32 BoundarySize; 316 }HOST_CAPABILITY; 317 318 319 // 320 // Interface structure for the SD HOST I/O Protocol 321 // 322 struct _EFI_SD_HOST_IO_PROTOCOL { 323 UINT32 Revision; 324 HOST_CAPABILITY HostCapability; 325 EFI_SD_HOST_IO_PROTOCOL_SEND_COMMAND SendCommand; 326 EFI_SD_HOST_IO_PROTOCOL_SET_CLOCK_FREQUENCY SetClockFrequency; 327 EFI_SD_HOST_IO_PROTOCOL_SET_BUS_WIDTH SetBusWidth; 328 EFI_SD_HOST_IO_PROTOCOL_SET_HOST_VOLTAGE SetHostVoltage; 329 EFI_SD_HOST_IO_PROTOCOL_RESET_SD_HOST ResetSDHost; 330 EFI_SD_HOST_IO_PROTOCOL_ENABLE_AUTO_STOP_CMD EnableAutoStopCmd; 331 EFI_SD_HOST_IO_PROTOCOL_DETECT_CARD_AND_INIT_HOST DetectCardAndInitHost; 332 EFI_SD_HOST_IO_PROTOCOL_SET_BLOCK_LENGTH SetBlockLength; 333 EFI_SD_HOST_IO_PROTOCOL_HIGH_SPEED_MODE SetHighSpeedMode; 334 EFI_SD_HOST_IO_PROTOCOL_DUAL_DATARATE_MODE SetDDRMode; 335 }; 336 337 extern EFI_GUID gEfiSDHostIoProtocolGuid; 338 339 #endif 340