3 Provides some data structure definitions used by the SD/MMC host controller driver.
5 Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
6 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
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_MMC_PCI_HCI_H_
18 #define _SD_MMC_PCI_HCI_H_
21 // SD Host Controller SlotInfo Register Offset
23 #define SD_MMC_HC_SLOT_OFFSET 0x40
25 #define SD_MMC_HC_MAX_SLOT 6
28 // SD Host Controller MMIO Register Offset
30 #define SD_MMC_HC_SDMA_ADDR 0x00
31 #define SD_MMC_HC_ARG2 0x00
32 #define SD_MMC_HC_BLK_SIZE 0x04
33 #define SD_MMC_HC_BLK_COUNT 0x06
34 #define SD_MMC_HC_ARG1 0x08
35 #define SD_MMC_HC_TRANS_MOD 0x0C
36 #define SD_MMC_HC_COMMAND 0x0E
37 #define SD_MMC_HC_RESPONSE 0x10
38 #define SD_MMC_HC_BUF_DAT_PORT 0x20
39 #define SD_MMC_HC_PRESENT_STATE 0x24
40 #define SD_MMC_HC_HOST_CTRL1 0x28
41 #define SD_MMC_HC_POWER_CTRL 0x29
42 #define SD_MMC_HC_BLK_GAP_CTRL 0x2A
43 #define SD_MMC_HC_WAKEUP_CTRL 0x2B
44 #define SD_MMC_HC_CLOCK_CTRL 0x2C
45 #define SD_MMC_HC_TIMEOUT_CTRL 0x2E
46 #define SD_MMC_HC_SW_RST 0x2F
47 #define SD_MMC_HC_NOR_INT_STS 0x30
48 #define SD_MMC_HC_ERR_INT_STS 0x32
49 #define SD_MMC_HC_NOR_INT_STS_EN 0x34
50 #define SD_MMC_HC_ERR_INT_STS_EN 0x36
51 #define SD_MMC_HC_NOR_INT_SIG_EN 0x38
52 #define SD_MMC_HC_ERR_INT_SIG_EN 0x3A
53 #define SD_MMC_HC_AUTO_CMD_ERR_STS 0x3C
54 #define SD_MMC_HC_HOST_CTRL2 0x3E
55 #define SD_MMC_HC_CAP 0x40
56 #define SD_MMC_HC_MAX_CURRENT_CAP 0x48
57 #define SD_MMC_HC_FORCE_EVT_AUTO_CMD 0x50
58 #define SD_MMC_HC_FORCE_EVT_ERR_INT 0x52
59 #define SD_MMC_HC_ADMA_ERR_STS 0x54
60 #define SD_MMC_HC_ADMA_SYS_ADDR 0x58
61 #define SD_MMC_HC_PRESET_VAL 0x60
62 #define SD_MMC_HC_SHARED_BUS_CTRL 0xE0
63 #define SD_MMC_HC_SLOT_INT_STS 0xFC
64 #define SD_MMC_HC_CTRL_VER 0xFE
67 // SD Host Controller bits to HOST_CTRL2 register
69 #define SD_MMC_HC_CTRL_UHS_MASK 0x0007
70 #define SD_MMC_HC_CTRL_UHS_SDR12 0x0000
71 #define SD_MMC_HC_CTRL_UHS_SDR25 0x0001
72 #define SD_MMC_HC_CTRL_UHS_SDR50 0x0002
73 #define SD_MMC_HC_CTRL_UHS_SDR104 0x0003
74 #define SD_MMC_HC_CTRL_UHS_DDR50 0x0004
75 #define SD_MMC_HC_CTRL_MMC_LEGACY 0x0000
76 #define SD_MMC_HC_CTRL_MMC_HS_SDR 0x0001
77 #define SD_MMC_HC_CTRL_MMC_HS_DDR 0x0004
78 #define SD_MMC_HC_CTRL_MMC_HS200 0x0003
79 #define SD_MMC_HC_CTRL_MMC_HS400 0x0005
82 // The transfer modes supported by SD Host Controller
83 // Simplified Spec 3.0 Table 1-2
90 } SD_MMC_HC_TRANSFER_MODE
;
93 // The maximum data length of each descriptor line
95 #define ADMA_MAX_DATA_PER_LINE_16B SIZE_64KB
96 #define ADMA_MAX_DATA_PER_LINE_26B SIZE_64MB
99 // ADMA descriptor for 32b addressing.
107 UINT32 UpperLength
:10;
108 UINT32 LowerLength
:16;
110 } SD_MMC_HC_ADMA_32_DESC_LINE
;
113 // ADMA descriptor for 64b addressing.
121 UINT32 UpperLength
:10;
122 UINT32 LowerLength
:16;
126 } SD_MMC_HC_ADMA_64_DESC_LINE
;
128 #define SD_MMC_SDMA_BOUNDARY 512 * 1024
129 #define SD_MMC_SDMA_ROUND_UP(x, n) (((x) + n) & ~(n - 1))
132 UINT8 FirstBar
:3; // bit 0:2
133 UINT8 Reserved
:1; // bit 3
134 UINT8 SlotNum
:3; // bit 4:6
135 UINT8 Reserved1
:1; // bit 7
136 } SD_MMC_HC_SLOT_INFO
;
139 UINT32 TimeoutFreq
:6; // bit 0:5
140 UINT32 Reserved
:1; // bit 6
141 UINT32 TimeoutUnit
:1; // bit 7
142 UINT32 BaseClkFreq
:8; // bit 8:15
143 UINT32 MaxBlkLen
:2; // bit 16:17
144 UINT32 BusWidth8
:1; // bit 18
145 UINT32 Adma2
:1; // bit 19
146 UINT32 Reserved2
:1; // bit 20
147 UINT32 HighSpeed
:1; // bit 21
148 UINT32 Sdma
:1; // bit 22
149 UINT32 SuspRes
:1; // bit 23
150 UINT32 Voltage33
:1; // bit 24
151 UINT32 Voltage30
:1; // bit 25
152 UINT32 Voltage18
:1; // bit 26
153 UINT32 SysBus64V4
:1; // bit 27
154 UINT32 SysBus64V3
:1; // bit 28
155 UINT32 AsyncInt
:1; // bit 29
156 UINT32 SlotType
:2; // bit 30:31
157 UINT32 Sdr50
:1; // bit 32
158 UINT32 Sdr104
:1; // bit 33
159 UINT32 Ddr50
:1; // bit 34
160 UINT32 Reserved3
:1; // bit 35
161 UINT32 DriverTypeA
:1; // bit 36
162 UINT32 DriverTypeC
:1; // bit 37
163 UINT32 DriverTypeD
:1; // bit 38
164 UINT32 DriverType4
:1; // bit 39
165 UINT32 TimerCount
:4; // bit 40:43
166 UINT32 Reserved4
:1; // bit 44
167 UINT32 TuningSDR50
:1; // bit 45
168 UINT32 RetuningMod
:2; // bit 46:47
169 UINT32 ClkMultiplier
:8; // bit 48:55
170 UINT32 Reserved5
:7; // bit 56:62
171 UINT32 Hs400
:1; // bit 63
172 } SD_MMC_HC_SLOT_CAP
;
175 // SD Host controller version
177 #define SD_MMC_HC_CTRL_VER_100 0x00
178 #define SD_MMC_HC_CTRL_VER_200 0x01
179 #define SD_MMC_HC_CTRL_VER_300 0x02
180 #define SD_MMC_HC_CTRL_VER_400 0x03
181 #define SD_MMC_HC_CTRL_VER_410 0x04
182 #define SD_MMC_HC_CTRL_VER_420 0x05
185 // SD Host controller V4 enhancements
187 #define SD_MMC_HC_V4_EN BIT12
188 #define SD_MMC_HC_64_ADDR_EN BIT13
189 #define SD_MMC_HC_26_DATA_LEN_ADMA_EN BIT10
192 Dump the content of SD/MMC host controller's Capability Register.
194 @param[in] Slot The slot number of the SD card to send the command to.
195 @param[in] Capability The buffer to store the capability data.
201 IN SD_MMC_HC_SLOT_CAP
*Capability
205 Read SlotInfo register from SD/MMC host controller pci config space.
207 @param[in] PciIo The PCI IO protocol instance.
208 @param[out] FirstBar The buffer to store the first BAR value.
209 @param[out] SlotNum The buffer to store the supported slot number.
211 @retval EFI_SUCCESS The operation succeeds.
212 @retval Others The operation fails.
218 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
224 Read/Write specified SD/MMC host controller mmio register.
226 @param[in] PciIo The PCI IO protocol instance.
227 @param[in] BarIndex The BAR index of the standard PCI Configuration
228 header to use as the base address for the memory
229 operation to perform.
230 @param[in] Offset The offset within the selected BAR to start the
232 @param[in] Read A boolean to indicate it's read or write operation.
233 @param[in] Count The width of the mmio register in bytes.
234 Must be 1, 2 , 4 or 8 bytes.
235 @param[in, out] Data For read operations, the destination buffer to store
236 the results. For write operations, the source buffer
237 to write data from. The caller is responsible for
238 having ownership of the data buffer and ensuring its
239 size not less than Count bytes.
241 @retval EFI_INVALID_PARAMETER The PciIo or Data is NULL or the Count is not valid.
242 @retval EFI_SUCCESS The read/write operation succeeds.
243 @retval Others The read/write operation fails.
249 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
258 Do OR operation with the value of the specified SD/MMC host controller mmio register.
260 @param[in] PciIo The PCI IO protocol instance.
261 @param[in] BarIndex The BAR index of the standard PCI Configuration
262 header to use as the base address for the memory
263 operation to perform.
264 @param[in] Offset The offset within the selected BAR to start the
266 @param[in] Count The width of the mmio register in bytes.
267 Must be 1, 2 , 4 or 8 bytes.
268 @param[in] OrData The pointer to the data used to do OR operation.
269 The caller is responsible for having ownership of
270 the data buffer and ensuring its size not less than
273 @retval EFI_INVALID_PARAMETER The PciIo or OrData is NULL or the Count is not valid.
274 @retval EFI_SUCCESS The OR operation succeeds.
275 @retval Others The OR operation fails.
281 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
289 Do AND operation with the value of the specified SD/MMC host controller mmio register.
291 @param[in] PciIo The PCI IO protocol instance.
292 @param[in] BarIndex The BAR index of the standard PCI Configuration
293 header to use as the base address for the memory
294 operation to perform.
295 @param[in] Offset The offset within the selected BAR to start the
297 @param[in] Count The width of the mmio register in bytes.
298 Must be 1, 2 , 4 or 8 bytes.
299 @param[in] AndData The pointer to the data used to do AND operation.
300 The caller is responsible for having ownership of
301 the data buffer and ensuring its size not less than
304 @retval EFI_INVALID_PARAMETER The PciIo or AndData is NULL or the Count is not valid.
305 @retval EFI_SUCCESS The AND operation succeeds.
306 @retval Others The AND operation fails.
312 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
320 Wait for the value of the specified MMIO register set to the test value.
322 @param[in] PciIo The PCI IO protocol instance.
323 @param[in] BarIndex The BAR index of the standard PCI Configuration
324 header to use as the base address for the memory
325 operation to perform.
326 @param[in] Offset The offset within the selected BAR to start the
328 @param[in] Count The width of the mmio register in bytes.
329 Must be 1, 2, 4 or 8 bytes.
330 @param[in] MaskValue The mask value of memory.
331 @param[in] TestValue The test value of memory.
332 @param[in] Timeout The time out value for wait memory set, uses 1
333 microsecond as a unit.
335 @retval EFI_TIMEOUT The MMIO register hasn't expected value in timeout
337 @retval EFI_SUCCESS The MMIO register has expected value.
338 @retval Others The MMIO operation fails.
344 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
354 Get the controller version information from the specified slot.
356 @param[in] PciIo The PCI IO protocol instance.
357 @param[in] Slot The slot number of the SD card to send the command to.
358 @param[out] Version The buffer to store the version information.
360 @retval EFI_SUCCESS The operation executes successfully.
361 @retval Others The operation fails.
365 SdMmcHcGetControllerVersion (
366 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
372 Set all interrupt status bits in Normal and Error Interrupt Status Enable
375 @param[in] PciIo The PCI IO protocol instance.
376 @param[in] Slot The slot number of the SD card to send the command to.
378 @retval EFI_SUCCESS The operation executes successfully.
379 @retval Others The operation fails.
383 SdMmcHcEnableInterrupt (
384 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
389 Get the capability data from the specified slot.
391 @param[in] PciIo The PCI IO protocol instance.
392 @param[in] Slot The slot number of the SD card to send the command to.
393 @param[out] Capability The buffer to store the capability data.
395 @retval EFI_SUCCESS The operation executes successfully.
396 @retval Others The operation fails.
400 SdMmcHcGetCapability (
401 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
403 OUT SD_MMC_HC_SLOT_CAP
*Capability
407 Get the maximum current capability data from the specified slot.
409 @param[in] PciIo The PCI IO protocol instance.
410 @param[in] Slot The slot number of the SD card to send the command to.
411 @param[out] MaxCurrent The buffer to store the maximum current capability data.
413 @retval EFI_SUCCESS The operation executes successfully.
414 @retval Others The operation fails.
418 SdMmcHcGetMaxCurrent (
419 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
421 OUT UINT64
*MaxCurrent
425 Detect whether there is a SD/MMC card attached at the specified SD/MMC host controller
428 Refer to SD Host Controller Simplified spec 3.0 Section 3.1 for details.
430 @param[in] PciIo The PCI IO protocol instance.
431 @param[in] Slot The slot number of the SD card to send the command to.
432 @param[out] MediaPresent The pointer to the media present boolean value.
434 @retval EFI_SUCCESS There is no media change happened.
435 @retval EFI_MEDIA_CHANGED There is media change happened.
436 @retval Others The detection fails.
441 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
443 OUT BOOLEAN
*MediaPresent
447 Stop SD/MMC card clock.
449 Refer to SD Host Controller Simplified spec 3.0 Section 3.2.2 for details.
451 @param[in] PciIo The PCI IO protocol instance.
452 @param[in] Slot The slot number of the SD card to send the command to.
454 @retval EFI_SUCCESS Succeed to stop SD/MMC clock.
455 @retval Others Fail to stop SD/MMC clock.
460 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
465 SD/MMC card clock supply.
467 Refer to SD Host Controller Simplified spec 3.0 Section 3.2.1 for details.
469 @param[in] PciIo The PCI IO protocol instance.
470 @param[in] Slot The slot number of the SD card to send the command to.
471 @param[in] ClockFreq The max clock frequency to be set. The unit is KHz.
472 @param[in] BaseClkFreq The base clock frequency of host controller in MHz.
473 @param[in] ControllerVer The version of host controller.
475 @retval EFI_SUCCESS The clock is supplied successfully.
476 @retval Others The clock isn't supplied successfully.
481 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
484 IN UINT32 BaseClkFreq
,
485 IN UINT16 ControllerVer
489 SD/MMC bus power control.
491 Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details.
493 @param[in] PciIo The PCI IO protocol instance.
494 @param[in] Slot The slot number of the SD card to send the command to.
495 @param[in] PowerCtrl The value setting to the power control register.
497 @retval TRUE There is a SD/MMC card attached.
498 @retval FALSE There is no a SD/MMC card attached.
502 SdMmcHcPowerControl (
503 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
509 Set the SD/MMC bus width.
511 Refer to SD Host Controller Simplified spec 3.0 Section 3.4 for details.
513 @param[in] PciIo The PCI IO protocol instance.
514 @param[in] Slot The slot number of the SD card to send the command to.
515 @param[in] BusWidth The bus width used by the SD/MMC device, it must be 1, 4 or 8.
517 @retval EFI_SUCCESS The bus width is set successfully.
518 @retval Others The bus width isn't set successfully.
523 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
529 Supply SD/MMC card with lowest clock frequency at initialization.
531 @param[in] PciIo The PCI IO protocol instance.
532 @param[in] Slot The slot number of the SD card to send the command to.
533 @param[in] BaseClkFreq The base clock frequency of host controller in MHz.
534 @param[in] ControllerVer The version of host controller.
536 @retval EFI_SUCCESS The clock is supplied successfully.
537 @retval Others The clock isn't supplied successfully.
541 SdMmcHcInitClockFreq (
542 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
544 IN UINT32 BaseClkFreq
,
545 IN UINT16 ControllerVer
549 Supply SD/MMC card with maximum voltage at initialization.
551 Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details.
553 @param[in] PciIo The PCI IO protocol instance.
554 @param[in] Slot The slot number of the SD card to send the command to.
555 @param[in] Capability The capability of the slot.
557 @retval EFI_SUCCESS The voltage is supplied successfully.
558 @retval Others The voltage isn't supplied successfully.
562 SdMmcHcInitPowerVoltage (
563 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
565 IN SD_MMC_HC_SLOT_CAP Capability
569 Initialize the Timeout Control register with most conservative value at initialization.
571 Refer to SD Host Controller Simplified spec 3.0 Section 2.2.15 for details.
573 @param[in] PciIo The PCI IO protocol instance.
574 @param[in] Slot The slot number of the SD card to send the command to.
576 @retval EFI_SUCCESS The timeout control register is configured successfully.
577 @retval Others The timeout control register isn't configured successfully.
581 SdMmcHcInitTimeoutCtrl (
582 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
587 Set SD Host Controller control 2 registry according to selected speed.
589 @param[in] ControllerHandle The handle of the controller.
590 @param[in] PciIo The PCI IO protocol instance.
591 @param[in] Slot The slot number of the SD card to send the command to.
592 @param[in] Timing The timing to select.
594 @retval EFI_SUCCESS The timing is set successfully.
595 @retval Others The timing isn't set successfully.
598 SdMmcHcUhsSignaling (
599 IN EFI_HANDLE ControllerHandle
,
600 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
602 IN SD_MMC_BUS_MODE Timing