1 /******************************************************************************
3 * Copyright (C) 2013 - 2015 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
36 * @addtogroup sdps_v2_5
39 * This header file contains the identifiers and basic HW access driver
40 * functions (or macros) that can be used to access the device. Other driver
41 * functions are defined in xsdps.h.
44 * MODIFICATION HISTORY:
46 * Ver Who Date Changes
47 * ----- --- -------- -----------------------------------------------
48 * 1.00a hk/sg 10/17/13 Initial release
49 * 2.5 sg 07/09/15 Added SD 3.0 features
50 * kvn 07/15/15 Modified the code according to MISRAC-2012.
51 * 2.7 sk 12/10/15 Added support for MMC cards.
52 * sk 03/02/16 Configured the Tap Delay values for eMMC HS200 mode.
55 ******************************************************************************/
64 /***************************** Include Files *********************************/
66 #include "xil_types.h"
67 #include "xil_assert.h"
69 #include "xparameters.h"
71 /************************** Constant Definitions *****************************/
73 /** @name Register Map
75 * Register offsets from the base address of an SD device.
79 #define XSDPS_SDMA_SYS_ADDR_OFFSET 0x00U /**< SDMA System Address
81 #define XSDPS_SDMA_SYS_ADDR_LO_OFFSET XSDPS_SDMA_SYS_ADDR_OFFSET
82 /**< SDMA System Address
84 #define XSDPS_ARGMT2_LO_OFFSET 0x00U /**< Argument2 Low Register */
85 #define XSDPS_SDMA_SYS_ADDR_HI_OFFSET 0x02U /**< SDMA System Address
87 #define XSDPS_ARGMT2_HI_OFFSET 0x02U /**< Argument2 High Register */
89 #define XSDPS_BLK_SIZE_OFFSET 0x04U /**< Block Size Register */
90 #define XSDPS_BLK_CNT_OFFSET 0x06U /**< Block Count Register */
91 #define XSDPS_ARGMT_OFFSET 0x08U /**< Argument Register */
92 #define XSDPS_ARGMT1_LO_OFFSET XSDPS_ARGMT_OFFSET
93 /**< Argument1 Register */
94 #define XSDPS_ARGMT1_HI_OFFSET 0x0AU /**< Argument1 Register */
96 #define XSDPS_XFER_MODE_OFFSET 0x0CU /**< Transfer Mode Register */
97 #define XSDPS_CMD_OFFSET 0x0EU /**< Command Register */
98 #define XSDPS_RESP0_OFFSET 0x10U /**< Response0 Register */
99 #define XSDPS_RESP1_OFFSET 0x14U /**< Response1 Register */
100 #define XSDPS_RESP2_OFFSET 0x18U /**< Response2 Register */
101 #define XSDPS_RESP3_OFFSET 0x1CU /**< Response3 Register */
102 #define XSDPS_BUF_DAT_PORT_OFFSET 0x20U /**< Buffer Data Port */
103 #define XSDPS_PRES_STATE_OFFSET 0x24U /**< Present State */
104 #define XSDPS_HOST_CTRL1_OFFSET 0x28U /**< Host Control 1 */
105 #define XSDPS_POWER_CTRL_OFFSET 0x29U /**< Power Control */
106 #define XSDPS_BLK_GAP_CTRL_OFFSET 0x2AU /**< Block Gap Control */
107 #define XSDPS_WAKE_UP_CTRL_OFFSET 0x2BU /**< Wake Up Control */
108 #define XSDPS_CLK_CTRL_OFFSET 0x2CU /**< Clock Control */
109 #define XSDPS_TIMEOUT_CTRL_OFFSET 0x2EU /**< Timeout Control */
110 #define XSDPS_SW_RST_OFFSET 0x2FU /**< Software Reset */
111 #define XSDPS_NORM_INTR_STS_OFFSET 0x30U /**< Normal Interrupt
113 #define XSDPS_ERR_INTR_STS_OFFSET 0x32U /**< Error Interrupt
115 #define XSDPS_NORM_INTR_STS_EN_OFFSET 0x34U /**< Normal Interrupt
116 Status Enable Register */
117 #define XSDPS_ERR_INTR_STS_EN_OFFSET 0x36U /**< Error Interrupt
118 Status Enable Register */
119 #define XSDPS_NORM_INTR_SIG_EN_OFFSET 0x38U /**< Normal Interrupt
120 Signal Enable Register */
121 #define XSDPS_ERR_INTR_SIG_EN_OFFSET 0x3AU /**< Error Interrupt
122 Signal Enable Register */
124 #define XSDPS_AUTO_CMD12_ERR_STS_OFFSET 0x3CU /**< Auto CMD12 Error Status
126 #define XSDPS_HOST_CTRL2_OFFSET 0x3EU /**< Host Control2 Register */
127 #define XSDPS_CAPS_OFFSET 0x40U /**< Capabilities Register */
128 #define XSDPS_CAPS_EXT_OFFSET 0x44U /**< Capabilities Extended */
129 #define XSDPS_MAX_CURR_CAPS_OFFSET 0x48U /**< Maximum Current
130 Capabilities Register */
131 #define XSDPS_MAX_CURR_CAPS_EXT_OFFSET 0x4CU /**< Maximum Current
132 Capabilities Ext Register */
133 #define XSDPS_FE_ERR_INT_STS_OFFSET 0x52U /**< Force Event for
134 Error Interrupt Status */
135 #define XSDPS_FE_AUTO_CMD12_EIS_OFFSET 0x50U /**< Auto CM12 Error Interrupt
137 #define XSDPS_ADMA_ERR_STS_OFFSET 0x54U /**< ADMA Error Status
139 #define XSDPS_ADMA_SAR_OFFSET 0x58U /**< ADMA System Address
141 #define XSDPS_ADMA_SAR_EXT_OFFSET 0x5CU /**< ADMA System Address
143 #define XSDPS_PRE_VAL_1_OFFSET 0x60U /**< Preset Value Register */
144 #define XSDPS_PRE_VAL_2_OFFSET 0x64U /**< Preset Value Register */
145 #define XSDPS_PRE_VAL_3_OFFSET 0x68U /**< Preset Value Register */
146 #define XSDPS_PRE_VAL_4_OFFSET 0x6CU /**< Preset Value Register */
147 #define XSDPS_BOOT_TOUT_CTRL_OFFSET 0x70U /**< Boot timeout control
150 #define XSDPS_SHARED_BUS_CTRL_OFFSET 0xE0U /**< Shared Bus Control
152 #define XSDPS_SLOT_INTR_STS_OFFSET 0xFCU /**< Slot Interrupt Status
154 #define XSDPS_HOST_CTRL_VER_OFFSET 0xFEU /**< Host Controller Version
159 /** @name Control Register - Host control, Power control,
160 * Block Gap control and Wakeup control
162 * This register contains bits for various configuration options of
163 * the SD host controller. Read/Write apart from the reserved bits.
167 #define XSDPS_HC_LED_MASK 0x00000001U /**< LED Control */
168 #define XSDPS_HC_WIDTH_MASK 0x00000002U /**< Bus width */
169 #define XSDPS_HC_BUS_WIDTH_4 0x00000002U
170 #define XSDPS_HC_SPEED_MASK 0x00000004U /**< High Speed */
171 #define XSDPS_HC_DMA_MASK 0x00000018U /**< DMA Mode Select */
172 #define XSDPS_HC_DMA_SDMA_MASK 0x00000000U /**< SDMA Mode */
173 #define XSDPS_HC_DMA_ADMA1_MASK 0x00000008U /**< ADMA1 Mode */
174 #define XSDPS_HC_DMA_ADMA2_32_MASK 0x00000010U /**< ADMA2 Mode - 32 bit */
175 #define XSDPS_HC_DMA_ADMA2_64_MASK 0x00000018U /**< ADMA2 Mode - 64 bit */
176 #define XSDPS_HC_EXT_BUS_WIDTH 0x00000020U /**< Bus width - 8 bit */
177 #define XSDPS_HC_CARD_DET_TL_MASK 0x00000040U /**< Card Detect Tst Lvl */
178 #define XSDPS_HC_CARD_DET_SD_MASK 0x00000080U /**< Card Detect Sig Det */
180 #define XSDPS_PC_BUS_PWR_MASK 0x00000001U /**< Bus Power Control */
181 #define XSDPS_PC_BUS_VSEL_MASK 0x0000000EU /**< Bus Voltage Select */
182 #define XSDPS_PC_BUS_VSEL_3V3_MASK 0x0000000EU /**< Bus Voltage 3.3V */
183 #define XSDPS_PC_BUS_VSEL_3V0_MASK 0x0000000CU /**< Bus Voltage 3.0V */
184 #define XSDPS_PC_BUS_VSEL_1V8_MASK 0x0000000AU /**< Bus Voltage 1.8V */
185 #define XSDPS_PC_EMMC_HW_RST_MASK 0x00000010U /**< HW reset for eMMC */
187 #define XSDPS_BGC_STP_REQ_MASK 0x00000001U /**< Block Gap Stop Req */
188 #define XSDPS_BGC_CNT_REQ_MASK 0x00000002U /**< Block Gap Cont Req */
189 #define XSDPS_BGC_RWC_MASK 0x00000004U /**< Block Gap Rd Wait */
190 #define XSDPS_BGC_INTR_MASK 0x00000008U /**< Block Gap Intr */
191 #define XSDPS_BGC_SPI_MODE_MASK 0x00000010U /**< Block Gap SPI Mode */
192 #define XSDPS_BGC_BOOT_EN_MASK 0x00000020U /**< Block Gap Boot Enb */
193 #define XSDPS_BGC_ALT_BOOT_EN_MASK 0x00000040U /**< Block Gap Alt BootEn */
194 #define XSDPS_BGC_BOOT_ACK_MASK 0x00000080U /**< Block Gap Boot Ack */
196 #define XSDPS_WC_WUP_ON_INTR_MASK 0x00000001U /**< Wakeup Card Intr */
197 #define XSDPS_WC_WUP_ON_INSRT_MASK 0x00000002U /**< Wakeup Card Insert */
198 #define XSDPS_WC_WUP_ON_REM_MASK 0x00000004U /**< Wakeup Card Removal */
202 /** @name Control Register - Clock control, Timeout control & Software reset
204 * This register contains bits for configuration options of clock, timeout and
206 * Read/Write except for Inter_Clock_Stable bit (read only) and reserved bits.
210 #define XSDPS_CC_INT_CLK_EN_MASK 0x00000001U
211 #define XSDPS_CC_INT_CLK_STABLE_MASK 0x00000002U
212 #define XSDPS_CC_SD_CLK_EN_MASK 0x00000004U
213 #define XSDPS_CC_SD_CLK_GEN_SEL_MASK 0x00000020U
214 #define XSDPS_CC_SDCLK_FREQ_SEL_EXT_MASK 0x000000C0U
215 #define XSDPS_CC_SDCLK_FREQ_SEL_MASK 0x0000FF00U
216 #define XSDPS_CC_SDCLK_FREQ_D256_MASK 0x00008000U
217 #define XSDPS_CC_SDCLK_FREQ_D128_MASK 0x00004000U
218 #define XSDPS_CC_SDCLK_FREQ_D64_MASK 0x00002000U
219 #define XSDPS_CC_SDCLK_FREQ_D32_MASK 0x00001000U
220 #define XSDPS_CC_SDCLK_FREQ_D16_MASK 0x00000800U
221 #define XSDPS_CC_SDCLK_FREQ_D8_MASK 0x00000400U
222 #define XSDPS_CC_SDCLK_FREQ_D4_MASK 0x00000200U
223 #define XSDPS_CC_SDCLK_FREQ_D2_MASK 0x00000100U
224 #define XSDPS_CC_SDCLK_FREQ_BASE_MASK 0x00000000U
225 #define XSDPS_CC_MAX_DIV_CNT 256U
226 #define XSDPS_CC_EXT_MAX_DIV_CNT 2046U
227 #define XSDPS_CC_EXT_DIV_SHIFT 6U
229 #define XSDPS_TC_CNTR_VAL_MASK 0x0000000FU
231 #define XSDPS_SWRST_ALL_MASK 0x00000001U
232 #define XSDPS_SWRST_CMD_LINE_MASK 0x00000002U
233 #define XSDPS_SWRST_DAT_LINE_MASK 0x00000004U
235 #define XSDPS_CC_MAX_NUM_OF_DIV 9U
236 #define XSDPS_CC_DIV_SHIFT 8U
240 /** @name SD Interrupt Registers
242 * <b> Normal and Error Interrupt Status Register </b>
243 * This register shows the normal and error interrupt status.
244 * Status enable register affects reads of this register.
245 * If Signal enable register is set and the corresponding status bit is set,
246 * interrupt is generated.
247 * Write to clear except
248 * Error_interrupt and Card_Interrupt bits - Read only
250 * <b> Normal and Error Interrupt Status Enable Register </b>
251 * Setting this register bits enables Interrupt status.
252 * Read/Write except Fixed_to_0 bit (Read only)
254 * <b> Normal and Error Interrupt Signal Enable Register </b>
255 * This register is used to select which interrupt status is
256 * indicated to the Host System as the interrupt.
257 * Read/Write except Fixed_to_0 bit (Read only)
259 * All three registers have same bit definitions
263 #define XSDPS_INTR_CC_MASK 0x00000001U /**< Command Complete */
264 #define XSDPS_INTR_TC_MASK 0x00000002U /**< Transfer Complete */
265 #define XSDPS_INTR_BGE_MASK 0x00000004U /**< Block Gap Event */
266 #define XSDPS_INTR_DMA_MASK 0x00000008U /**< DMA Interrupt */
267 #define XSDPS_INTR_BWR_MASK 0x00000010U /**< Buffer Write Ready */
268 #define XSDPS_INTR_BRR_MASK 0x00000020U /**< Buffer Read Ready */
269 #define XSDPS_INTR_CARD_INSRT_MASK 0x00000040U /**< Card Insert */
270 #define XSDPS_INTR_CARD_REM_MASK 0x00000080U /**< Card Remove */
271 #define XSDPS_INTR_CARD_MASK 0x00000100U /**< Card Interrupt */
272 #define XSDPS_INTR_INT_A_MASK 0x00000200U /**< INT A Interrupt */
273 #define XSDPS_INTR_INT_B_MASK 0x00000400U /**< INT B Interrupt */
274 #define XSDPS_INTR_INT_C_MASK 0x00000800U /**< INT C Interrupt */
275 #define XSDPS_INTR_RE_TUNING_MASK 0x00001000U /**< Re-Tuning Interrupt */
276 #define XSDPS_INTR_BOOT_ACK_RECV_MASK 0x00002000U /**< Boot Ack Recv
278 #define XSDPS_INTR_BOOT_TERM_MASK 0x00004000U /**< Boot Terminate
280 #define XSDPS_INTR_ERR_MASK 0x00008000U /**< Error Interrupt */
281 #define XSDPS_NORM_INTR_ALL_MASK 0x0000FFFFU
283 #define XSDPS_INTR_ERR_CT_MASK 0x00000001U /**< Command Timeout
285 #define XSDPS_INTR_ERR_CCRC_MASK 0x00000002U /**< Command CRC Error */
286 #define XSDPS_INTR_ERR_CEB_MASK 0x00000004U /**< Command End Bit
288 #define XSDPS_INTR_ERR_CI_MASK 0x00000008U /**< Command Index Error */
289 #define XSDPS_INTR_ERR_DT_MASK 0x00000010U /**< Data Timeout Error */
290 #define XSDPS_INTR_ERR_DCRC_MASK 0x00000020U /**< Data CRC Error */
291 #define XSDPS_INTR_ERR_DEB_MASK 0x00000040U /**< Data End Bit Error */
292 #define XSDPS_INTR_ERR_CUR_LMT_MASK 0x00000080U /**< Current Limit Error */
293 #define XSDPS_INTR_ERR_AUTO_CMD12_MASK 0x00000100U /**< Auto CMD12 Error */
294 #define XSDPS_INTR_ERR_ADMA_MASK 0x00000200U /**< ADMA Error */
295 #define XSDPS_INTR_ERR_TR_MASK 0x00001000U /**< Tuning Error */
296 #define XSDPS_INTR_VEND_SPF_ERR_MASK 0x0000E000U /**< Vendor Specific
298 #define XSDPS_ERROR_INTR_ALL_MASK 0x0000F3FFU /**< Mask for error bits */
301 /** @name Block Size and Block Count Register
303 * This register contains the block count for current transfer,
304 * block size and SDMA buffer size.
305 * Read/Write except for reserved bits.
309 #define XSDPS_BLK_SIZE_MASK 0x00000FFFU /**< Transfer Block Size */
310 #define XSDPS_SDMA_BUFF_SIZE_MASK 0x00007000U /**< Host SDMA Buffer Size */
311 #define XSDPS_BLK_SIZE_1024 0x400U
312 #define XSDPS_BLK_SIZE_2048 0x800U
313 #define XSDPS_BLK_CNT_MASK 0x0000FFFFU /**< Block Count for
318 /** @name Transfer Mode and Command Register
320 * The Transfer Mode register is used to control the data transfers and
321 * Command register is used for command generation
322 * Read/Write except for reserved bits.
326 #define XSDPS_TM_DMA_EN_MASK 0x00000001U /**< DMA Enable */
327 #define XSDPS_TM_BLK_CNT_EN_MASK 0x00000002U /**< Block Count Enable */
328 #define XSDPS_TM_AUTO_CMD12_EN_MASK 0x00000004U /**< Auto CMD12 Enable */
329 #define XSDPS_TM_DAT_DIR_SEL_MASK 0x00000010U /**< Data Transfer
331 #define XSDPS_TM_MUL_SIN_BLK_SEL_MASK 0x00000020U /**< Multi/Single
334 #define XSDPS_CMD_RESP_SEL_MASK 0x00000003U /**< Response Type
336 #define XSDPS_CMD_RESP_NONE_MASK 0x00000000U /**< No Response */
337 #define XSDPS_CMD_RESP_L136_MASK 0x00000001U /**< Response length 138 */
338 #define XSDPS_CMD_RESP_L48_MASK 0x00000002U /**< Response length 48 */
339 #define XSDPS_CMD_RESP_L48_BSY_CHK_MASK 0x00000003U /**< Response length 48 &
342 #define XSDPS_CMD_CRC_CHK_EN_MASK 0x00000008U /**< Command CRC Check
344 #define XSDPS_CMD_INX_CHK_EN_MASK 0x00000010U /**< Command Index Check
346 #define XSDPS_DAT_PRESENT_SEL_MASK 0x00000020U /**< Data Present Select */
347 #define XSDPS_CMD_TYPE_MASK 0x000000C0U /**< Command Type */
348 #define XSDPS_CMD_TYPE_NORM_MASK 0x00000000U /**< CMD Type - Normal */
349 #define XSDPS_CMD_TYPE_SUSPEND_MASK 0x00000040U /**< CMD Type - Suspend */
350 #define XSDPS_CMD_TYPE_RESUME_MASK 0x00000080U /**< CMD Type - Resume */
351 #define XSDPS_CMD_TYPE_ABORT_MASK 0x000000C0U /**< CMD Type - Abort */
352 #define XSDPS_CMD_MASK 0x00003F00U /**< Command Index Mask -
358 /** @name Auto CMD Error Status Register
360 * This register is read only register which contains
361 * information about the error status of Auto CMD 12 and 23.
365 #define XSDPS_AUTO_CMD12_NT_EX_MASK 0x0001U /**< Auto CMD12 Not
367 #define XSDPS_AUTO_CMD_TOUT_MASK 0x0002U /**< Auto CMD Timeout
369 #define XSDPS_AUTO_CMD_CRC_MASK 0x0004U /**< Auto CMD CRC Error */
370 #define XSDPS_AUTO_CMD_EB_MASK 0x0008U /**< Auto CMD End Bit
372 #define XSDPS_AUTO_CMD_IND_MASK 0x0010U /**< Auto CMD Index Error */
373 #define XSDPS_AUTO_CMD_CNI_ERR_MASK 0x0080U /**< Command not issued by
377 /** @name Host Control2 Register
379 * This register contains extended configuration bits.
383 #define XSDPS_HC2_UHS_MODE_MASK 0x0007U /**< UHS Mode select bits */
384 #define XSDPS_HC2_UHS_MODE_SDR12_MASK 0x0000U /**< SDR12 UHS Mode */
385 #define XSDPS_HC2_UHS_MODE_SDR25_MASK 0x0001U /**< SDR25 UHS Mode */
386 #define XSDPS_HC2_UHS_MODE_SDR50_MASK 0x0002U /**< SDR50 UHS Mode */
387 #define XSDPS_HC2_UHS_MODE_SDR104_MASK 0x0003U /**< SDR104 UHS Mode */
388 #define XSDPS_HC2_UHS_MODE_DDR50_MASK 0x0004U /**< DDR50 UHS Mode */
389 #define XSDPS_HC2_1V8_EN_MASK 0x0008U /**< 1.8V Signal Enable */
390 #define XSDPS_HC2_DRV_STR_SEL_MASK 0x0030U /**< Driver Strength
392 #define XSDPS_HC2_DRV_STR_B_MASK 0x0000U /**< Driver Strength B */
393 #define XSDPS_HC2_DRV_STR_A_MASK 0x0010U /**< Driver Strength A */
394 #define XSDPS_HC2_DRV_STR_C_MASK 0x0020U /**< Driver Strength C */
395 #define XSDPS_HC2_DRV_STR_D_MASK 0x0030U /**< Driver Strength D */
396 #define XSDPS_HC2_EXEC_TNG_MASK 0x0040U /**< Execute Tuning */
397 #define XSDPS_HC2_SAMP_CLK_SEL_MASK 0x0080U /**< Sampling Clock
399 #define XSDPS_HC2_ASYNC_INTR_EN_MASK 0x4000U /**< Asynchronous Interrupt
401 #define XSDPS_HC2_PRE_VAL_EN_MASK 0x8000U /**< Preset Value Enable */
405 /** @name Capabilities Register
407 * Capabilities register is a read only register which contains
408 * information about the host controller.
409 * Sufficient if read once after power on.
413 #define XSDPS_CAP_TOUT_CLK_FREQ_MASK 0x0000003FU /**< Timeout clock freq
415 #define XSDPS_CAP_TOUT_CLK_UNIT_MASK 0x00000080U /**< Timeout clock unit -
417 #define XSDPS_CAP_MAX_BLK_LEN_MASK 0x00030000U /**< Max block length */
418 #define XSDPS_CAP_MAX_BLK_LEN_512B_MASK 0x00000000U /**< Max block 512 bytes */
419 #define XSDPS_CAP_MAX_BL_LN_1024_MASK 0x00010000U /**< Max block 1024 bytes */
420 #define XSDPS_CAP_MAX_BL_LN_2048_MASK 0x00020000U /**< Max block 2048 bytes */
421 #define XSDPS_CAP_MAX_BL_LN_4096_MASK 0x00030000U /**< Max block 4096 bytes */
423 #define XSDPS_CAP_EXT_MEDIA_BUS_MASK 0x00040000U /**< Extended media bus */
424 #define XSDPS_CAP_ADMA2_MASK 0x00080000U /**< ADMA2 support */
425 #define XSDPS_CAP_HIGH_SPEED_MASK 0x00200000U /**< High speed support */
426 #define XSDPS_CAP_SDMA_MASK 0x00400000U /**< SDMA support */
427 #define XSDPS_CAP_SUSP_RESUME_MASK 0x00800000U /**< Suspend/Resume
429 #define XSDPS_CAP_VOLT_3V3_MASK 0x01000000U /**< 3.3V support */
430 #define XSDPS_CAP_VOLT_3V0_MASK 0x02000000U /**< 3.0V support */
431 #define XSDPS_CAP_VOLT_1V8_MASK 0x04000000U /**< 1.8V support */
433 #define XSDPS_CAP_SYS_BUS_64_MASK 0x10000000U /**< 64 bit system bus
436 #define XSDPS_CAP_INTR_MODE_MASK 0x08000000U /**< Interrupt mode
438 #define XSDPS_CAP_SPI_MODE_MASK 0x20000000U /**< SPI mode */
439 #define XSDPS_CAP_SPI_BLOCK_MODE_MASK 0x40000000U /**< SPI block mode */
443 #define XSDPS_CAPS_ASYNC_INTR_MASK 0x20000000U /**< Async Interrupt
445 #define XSDPS_CAPS_SLOT_TYPE_MASK 0xC0000000U /**< Slot Type */
446 #define XSDPS_CAPS_REM_CARD 0x00000000U /**< Removable Slot */
447 #define XSDPS_CAPS_EMB_SLOT 0x40000000U /**< Embedded Slot */
448 #define XSDPS_CAPS_SHR_BUS 0x80000000U /**< Shared Bus Slot */
450 #define XSDPS_ECAPS_SDR50_MASK 0x00000001U /**< SDR50 Mode support */
451 #define XSDPS_ECAPS_SDR104_MASK 0x00000002U /**< SDR104 Mode support */
452 #define XSDPS_ECAPS_DDR50_MASK 0x00000004U /**< DDR50 Mode support */
453 #define XSDPS_ECAPS_DRV_TYPE_A_MASK 0x00000010U /**< DriverType A support */
454 #define XSDPS_ECAPS_DRV_TYPE_C_MASK 0x00000020U /**< DriverType C support */
455 #define XSDPS_ECAPS_DRV_TYPE_D_MASK 0x00000040U /**< DriverType D support */
456 #define XSDPS_ECAPS_TMR_CNT_MASK 0x00000F00U /**< Timer Count for
458 #define XSDPS_ECAPS_USE_TNG_SDR50_MASK 0x00002000U /**< SDR50 Mode needs
460 #define XSDPS_ECAPS_RE_TNG_MODES_MASK 0x0000C000U /**< Re-tuning modes
462 #define XSDPS_ECAPS_RE_TNG_MODE1_MASK 0x00000000U /**< Re-tuning mode 1 */
463 #define XSDPS_ECAPS_RE_TNG_MODE2_MASK 0x00004000U /**< Re-tuning mode 2 */
464 #define XSDPS_ECAPS_RE_TNG_MODE3_MASK 0x00008000U /**< Re-tuning mode 3 */
465 #define XSDPS_ECAPS_CLK_MULT_MASK 0x00FF0000U /**< Clock Multiplier value
466 for Programmable clock
468 #define XSDPS_ECAPS_SPI_MODE_MASK 0x01000000U /**< SPI mode */
469 #define XSDPS_ECAPS_SPI_BLK_MODE_MASK 0x02000000U /**< SPI block mode */
473 /** @name Present State Register
475 * Gives the current status of the host controller
480 #define XSDPS_PSR_INHIBIT_CMD_MASK 0x00000001U /**< Command inhibit - CMD */
481 #define XSDPS_PSR_INHIBIT_DAT_MASK 0x00000002U /**< Command Inhibit - DAT */
482 #define XSDPS_PSR_DAT_ACTIVE_MASK 0x00000004U /**< DAT line active */
483 #define XSDPS_PSR_RE_TUNING_REQ_MASK 0x00000008U /**< Re-tuning request */
484 #define XSDPS_PSR_WR_ACTIVE_MASK 0x00000100U /**< Write transfer active */
485 #define XSDPS_PSR_RD_ACTIVE_MASK 0x00000200U /**< Read transfer active */
486 #define XSDPS_PSR_BUFF_WR_EN_MASK 0x00000400U /**< Buffer write enable */
487 #define XSDPS_PSR_BUFF_RD_EN_MASK 0x00000800U /**< Buffer read enable */
488 #define XSDPS_PSR_CARD_INSRT_MASK 0x00010000U /**< Card inserted */
489 #define XSDPS_PSR_CARD_STABLE_MASK 0x00020000U /**< Card state stable */
490 #define XSDPS_PSR_CARD_DPL_MASK 0x00040000U /**< Card detect pin level */
491 #define XSDPS_PSR_WPS_PL_MASK 0x00080000U /**< Write protect switch
493 #define XSDPS_PSR_DAT30_SG_LVL_MASK 0x00F00000U /**< Data 3:0 signal lvl */
494 #define XSDPS_PSR_CMD_SG_LVL_MASK 0x01000000U /**< Cmd Line signal lvl */
495 #define XSDPS_PSR_DAT74_SG_LVL_MASK 0x1E000000U /**< Data 7:4 signal lvl */
499 /** @name Maximum Current Capablities Register
501 * This register is read only register which contains
502 * information about current capabilities at each voltage levels.
506 #define XSDPS_MAX_CUR_CAPS_1V8_MASK 0x00000F00U /**< Maximum Current
507 Capability at 1.8V */
508 #define XSDPS_MAX_CUR_CAPS_3V0_MASK 0x000000F0U /**< Maximum Current
509 Capability at 3.0V */
510 #define XSDPS_MAX_CUR_CAPS_3V3_MASK 0x0000000FU /**< Maximum Current
511 Capability at 3.3V */
515 /** @name Force Event for Auto CMD Error Status Register
517 * This register is write only register which contains
518 * control bits to generate events for Auto CMD error status.
522 #define XSDPS_FE_AUTO_CMD12_NT_EX_MASK 0x0001U /**< Auto CMD12 Not
524 #define XSDPS_FE_AUTO_CMD_TOUT_MASK 0x0002U /**< Auto CMD Timeout
526 #define XSDPS_FE_AUTO_CMD_CRC_MASK 0x0004U /**< Auto CMD CRC Error */
527 #define XSDPS_FE_AUTO_CMD_EB_MASK 0x0008U /**< Auto CMD End Bit
529 #define XSDPS_FE_AUTO_CMD_IND_MASK 0x0010U /**< Auto CMD Index Error */
530 #define XSDPS_FE_AUTO_CMD_CNI_ERR_MASK 0x0080U /**< Command not issued by
536 /** @name Force Event for Error Interrupt Status Register
538 * This register is write only register which contains
539 * control bits to generate events of error interrupt status register.
543 #define XSDPS_FE_INTR_ERR_CT_MASK 0x0001U /**< Command Timeout
545 #define XSDPS_FE_INTR_ERR_CCRC_MASK 0x0002U /**< Command CRC Error */
546 #define XSDPS_FE_INTR_ERR_CEB_MASK 0x0004U /**< Command End Bit
548 #define XSDPS_FE_INTR_ERR_CI_MASK 0x0008U /**< Command Index Error */
549 #define XSDPS_FE_INTR_ERR_DT_MASK 0x0010U /**< Data Timeout Error */
550 #define XSDPS_FE_INTR_ERR_DCRC_MASK 0x0020U /**< Data CRC Error */
551 #define XSDPS_FE_INTR_ERR_DEB_MASK 0x0040U /**< Data End Bit Error */
552 #define XSDPS_FE_INTR_ERR_CUR_LMT_MASK 0x0080U /**< Current Limit Error */
553 #define XSDPS_FE_INTR_ERR_AUTO_CMD_MASK 0x0100U /**< Auto CMD Error */
554 #define XSDPS_FE_INTR_ERR_ADMA_MASK 0x0200U /**< ADMA Error */
555 #define XSDPS_FE_INTR_ERR_TR_MASK 0x1000U /**< Target Reponse */
556 #define XSDPS_FE_INTR_VEND_SPF_ERR_MASK 0xE000U /**< Vendor Specific
561 /** @name ADMA Error Status Register
563 * This register is read only register which contains
564 * status information about ADMA errors.
568 #define XSDPS_ADMA_ERR_MM_LEN_MASK 0x04U /**< ADMA Length Mismatch
570 #define XSDPS_ADMA_ERR_STATE_MASK 0x03U /**< ADMA Error State */
571 #define XSDPS_ADMA_ERR_STATE_STOP_MASK 0x00U /**< ADMA Error State
573 #define XSDPS_ADMA_ERR_STATE_FDS_MASK 0x01U /**< ADMA Error State
575 #define XSDPS_ADMA_ERR_STATE_TFR_MASK 0x03U /**< ADMA Error State
579 /** @name Preset Values Register
581 * This register is read only register which contains
582 * preset values for each of speed modes.
586 #define XSDPS_PRE_VAL_SDCLK_FSEL_MASK 0x03FFU /**< SDCLK Frequency
588 #define XSDPS_PRE_VAL_CLK_GEN_SEL_MASK 0x0400U /**< Clock Generator
590 #define XSDPS_PRE_VAL_DRV_STR_SEL_MASK 0xC000U /**< Driver Strength
595 /** @name Slot Interrupt Status Register
597 * This register is read only register which contains
598 * interrupt slot signal for each slot.
602 #define XSDPS_SLOT_INTR_STS_INT_MASK 0x0007U /**< Interrupt Signal
607 /** @name Host Controller Version Register
609 * This register is read only register which contains
610 * Host Controller and Vendor Specific version.
614 #define XSDPS_HC_VENDOR_VER 0xFF00U /**< Vendor
617 #define XSDPS_HC_SPEC_VER_MASK 0x00FFU /**< Host
620 #define XSDPS_HC_SPEC_V3 0x0002U
621 #define XSDPS_HC_SPEC_V2 0x0001U
622 #define XSDPS_HC_SPEC_V1 0x0000U
624 /** @name Block size mask for 512 bytes
626 * Block size mask for 512 bytes - This is the default block size.
630 #define XSDPS_BLK_SIZE_512_MASK 0x200U
636 * Constant definitions for commands and response related to SD
640 #define XSDPS_APP_CMD_PREFIX 0x8000U
648 #define ACMD6 (XSDPS_APP_CMD_PREFIX + 0x0600U)
652 #define CMD10 0x0A00U
653 #define CMD11 0x0B00U
654 #define CMD12 0x0C00U
655 #define ACMD13 (XSDPS_APP_CMD_PREFIX + 0x0D00U)
656 #define CMD16 0x1000U
657 #define CMD17 0x1100U
658 #define CMD18 0x1200U
659 #define CMD19 0x1300U
660 #define CMD21 0x1500U
661 #define CMD23 0x1700U
662 #define ACMD23 (XSDPS_APP_CMD_PREFIX + 0x1700U)
663 #define CMD24 0x1800U
664 #define CMD25 0x1900U
665 #define CMD41 0x2900U
666 #define ACMD41 (XSDPS_APP_CMD_PREFIX + 0x2900U)
667 #define ACMD42 (XSDPS_APP_CMD_PREFIX + 0x2A00U)
668 #define ACMD51 (XSDPS_APP_CMD_PREFIX + 0x3300U)
669 #define CMD52 0x3400U
670 #define CMD55 0x3700U
671 #define CMD58 0x3A00U
673 #define RESP_NONE (u32)XSDPS_CMD_RESP_NONE_MASK
674 #define RESP_R1 (u32)XSDPS_CMD_RESP_L48_MASK | (u32)XSDPS_CMD_CRC_CHK_EN_MASK | \
675 (u32)XSDPS_CMD_INX_CHK_EN_MASK
677 #define RESP_R1B (u32)XSDPS_CMD_RESP_L48_BSY_CHK_MASK | \
678 (u32)XSDPS_CMD_CRC_CHK_EN_MASK | (u32)XSDPS_CMD_INX_CHK_EN_MASK
680 #define RESP_R2 (u32)XSDPS_CMD_RESP_L136_MASK | (u32)XSDPS_CMD_CRC_CHK_EN_MASK
681 #define RESP_R3 (u32)XSDPS_CMD_RESP_L48_MASK
683 #define RESP_R6 (u32)XSDPS_CMD_RESP_L48_BSY_CHK_MASK | \
684 (u32)XSDPS_CMD_CRC_CHK_EN_MASK | (u32)XSDPS_CMD_INX_CHK_EN_MASK
688 /* Card Interface Conditions Definitions */
689 #define XSDPS_CIC_CHK_PATTERN 0xAAU
690 #define XSDPS_CIC_VOLT_MASK (0xFU<<8)
691 #define XSDPS_CIC_VOLT_2V7_3V6 (1U<<8)
692 #define XSDPS_CIC_VOLT_LOW (1U<<9)
694 /* Operation Conditions Register Definitions */
695 #define XSDPS_OCR_PWRUP_STS (1U<<31)
696 #define XSDPS_OCR_CC_STS (1U<<30)
697 #define XSDPS_OCR_S18 (1U<<24)
698 #define XSDPS_OCR_3V5_3V6 (1U<<23)
699 #define XSDPS_OCR_3V4_3V5 (1U<<22)
700 #define XSDPS_OCR_3V3_3V4 (1U<<21)
701 #define XSDPS_OCR_3V2_3V3 (1U<<20)
702 #define XSDPS_OCR_3V1_3V2 (1U<<19)
703 #define XSDPS_OCR_3V0_3V1 (1U<<18)
704 #define XSDPS_OCR_2V9_3V0 (1U<<17)
705 #define XSDPS_OCR_2V8_2V9 (1U<<16)
706 #define XSDPS_OCR_2V7_2V8 (1U<<15)
707 #define XSDPS_OCR_1V7_1V95 (1U<<7)
708 #define XSDPS_OCR_HIGH_VOL 0x00FF8000U
709 #define XSDPS_OCR_LOW_VOL 0x00000080U
711 /* SD Card Configuration Register Definitions */
712 #define XSDPS_SCR_REG_LEN 8U
713 #define XSDPS_SCR_STRUCT_MASK (0xFU<<28)
714 #define XSDPS_SCR_SPEC_MASK (0xFU<<24)
715 #define XSDPS_SCR_SPEC_1V0 0U
716 #define XSDPS_SCR_SPEC_1V1 (1U<<24)
717 #define XSDPS_SCR_SPEC_2V0_3V0 (2U<<24)
718 #define XSDPS_SCR_MEM_VAL_AF_ERASE (1U<<23)
719 #define XSDPS_SCR_SEC_SUPP_MASK (7U<<20)
720 #define XSDPS_SCR_SEC_SUPP_NONE 0U
721 #define XSDPS_SCR_SEC_SUPP_1V1 (2U<<20)
722 #define XSDPS_SCR_SEC_SUPP_2V0 (3U<<20)
723 #define XSDPS_SCR_SEC_SUPP_3V0 (4U<<20)
724 #define XSDPS_SCR_BUS_WIDTH_MASK (0xFU<<16)
725 #define XSDPS_SCR_BUS_WIDTH_1 (1U<<16)
726 #define XSDPS_SCR_BUS_WIDTH_4 (4U<<16)
727 #define XSDPS_SCR_SPEC3_MASK (1U<<12)
728 #define XSDPS_SCR_SPEC3_2V0 0U
729 #define XSDPS_SCR_SPEC3_3V0 (1U<<12)
730 #define XSDPS_SCR_CMD_SUPP_MASK 0x3U
731 #define XSDPS_SCR_CMD23_SUPP (1U<<1)
732 #define XSDPS_SCR_CMD20_SUPP (1U<<0)
734 /* Card Status Register Definitions */
735 #define XSDPS_CD_STS_OUT_OF_RANGE (1U<<31)
736 #define XSDPS_CD_STS_ADDR_ERR (1U<<30)
737 #define XSDPS_CD_STS_BLK_LEN_ERR (1U<<29)
738 #define XSDPS_CD_STS_ER_SEQ_ERR (1U<<28)
739 #define XSDPS_CD_STS_ER_PRM_ERR (1U<<27)
740 #define XSDPS_CD_STS_WP_VIO (1U<<26)
741 #define XSDPS_CD_STS_IS_LOCKED (1U<<25)
742 #define XSDPS_CD_STS_LOCK_UNLOCK_FAIL (1U<<24)
743 #define XSDPS_CD_STS_CMD_CRC_ERR (1U<<23)
744 #define XSDPS_CD_STS_ILGL_CMD (1U<<22)
745 #define XSDPS_CD_STS_CARD_ECC_FAIL (1U<<21)
746 #define XSDPS_CD_STS_CC_ERR (1U<<20)
747 #define XSDPS_CD_STS_ERR (1U<<19)
748 #define XSDPS_CD_STS_CSD_OVRWR (1U<<16)
749 #define XSDPS_CD_STS_WP_ER_SKIP (1U<<15)
750 #define XSDPS_CD_STS_CARD_ECC_DIS (1U<<14)
751 #define XSDPS_CD_STS_ER_RST (1U<<13)
752 #define XSDPS_CD_STS_CUR_STATE (0xFU<<9)
753 #define XSDPS_CD_STS_RDY_FOR_DATA (1U<<8)
754 #define XSDPS_CD_STS_APP_CMD (1U<<5)
755 #define XSDPS_CD_STS_AKE_SEQ_ERR (1U<<2)
757 /* Switch Function Definitions CMD6 */
758 #define XSDPS_SWITCH_SD_RESP_LEN 64U
760 #define XSDPS_SWITCH_FUNC_SWITCH (1U<<31)
761 #define XSDPS_SWITCH_FUNC_CHECK 0U
763 #define XSDPS_MODE_FUNC_GRP1 1U
764 #define XSDPS_MODE_FUNC_GRP2 2U
765 #define XSDPS_MODE_FUNC_GRP3 3U
766 #define XSDPS_MODE_FUNC_GRP4 4U
767 #define XSDPS_MODE_FUNC_GRP5 5U
768 #define XSDPS_MODE_FUNC_GRP6 6U
770 #define XSDPS_FUNC_GRP_DEF_VAL 0xFU
771 #define XSDPS_FUNC_ALL_GRP_DEF_VAL 0xFFFFFFU
773 #define XSDPS_ACC_MODE_DEF_SDR12 0U
774 #define XSDPS_ACC_MODE_HS_SDR25 1U
775 #define XSDPS_ACC_MODE_SDR50 2U
776 #define XSDPS_ACC_MODE_SDR104 3U
777 #define XSDPS_ACC_MODE_DDR50 4U
779 #define XSDPS_CMD_SYS_ARG_SHIFT 4U
780 #define XSDPS_CMD_SYS_DEF 0U
781 #define XSDPS_CMD_SYS_eC 1U
782 #define XSDPS_CMD_SYS_OTP 3U
783 #define XSDPS_CMD_SYS_ASSD 4U
784 #define XSDPS_CMD_SYS_VEND 5U
786 #define XSDPS_DRV_TYPE_ARG_SHIFT 8U
787 #define XSDPS_DRV_TYPE_B 0U
788 #define XSDPS_DRV_TYPE_A 1U
789 #define XSDPS_DRV_TYPE_C 2U
790 #define XSDPS_DRV_TYPE_D 3U
792 #define XSDPS_CUR_LIM_ARG_SHIFT 12U
793 #define XSDPS_CUR_LIM_200 0U
794 #define XSDPS_CUR_LIM_400 1U
795 #define XSDPS_CUR_LIM_600 2U
796 #define XSDPS_CUR_LIM_800 3U
798 #define CSD_SPEC_VER_MASK 0x3C0000U
800 /* EXT_CSD field definitions */
801 #define XSDPS_EXT_CSD_SIZE 512U
803 #define EXT_CSD_WR_REL_PARAM_EN (1U<<2)
805 #define EXT_CSD_BOOT_WP_B_PWR_WP_DIS (0x40U)
806 #define EXT_CSD_BOOT_WP_B_PERM_WP_DIS (0x10U)
807 #define EXT_CSD_BOOT_WP_B_PERM_WP_EN (0x04U)
808 #define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01U)
810 #define EXT_CSD_PART_CONFIG_ACC_MASK (0x7U)
811 #define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1U)
812 #define EXT_CSD_PART_CONFIG_ACC_RPMB (0x3U)
813 #define EXT_CSD_PART_CONFIG_ACC_GP0 (0x4U)
815 #define EXT_CSD_PART_SUPPORT_PART_EN (0x1U)
817 #define EXT_CSD_CMD_SET_NORMAL (1U<<0)
818 #define EXT_CSD_CMD_SET_SECURE (1U<<1)
819 #define EXT_CSD_CMD_SET_CPSECURE (1U<<2)
821 #define EXT_CSD_CARD_TYPE_26 (1U<<0) /* Card can run at 26MHz */
822 #define EXT_CSD_CARD_TYPE_52 (1U<<1) /* Card can run at 52MHz */
823 #define EXT_CSD_CARD_TYPE_MASK 0x3FU /* Mask out reserved bits */
824 #define EXT_CSD_CARD_TYPE_DDR_1_8V (1U<<2) /* Card can run at 52MHz */
825 /* DDR mode @1.8V or 3V I/O */
826 #define EXT_CSD_CARD_TYPE_DDR_1_2V (1U<<3) /* Card can run at 52MHz */
827 /* DDR mode @1.2V I/O */
828 #define EXT_CSD_CARD_TYPE_DDR_52 (EXT_CSD_CARD_TYPE_DDR_1_8V \
829 | EXT_CSD_CARD_TYPE_DDR_1_2V)
830 #define EXT_CSD_CARD_TYPE_SDR_1_8V (1U<<4) /* Card can run at 200MHz */
831 #define EXT_CSD_CARD_TYPE_SDR_1_2V (1U<<5) /* Card can run at 200MHz */
832 /* SDR mode @1.2V I/O */
833 #define EXT_CSD_BUS_WIDTH_BYTE 183U
834 #define EXT_CSD_BUS_WIDTH_1_BIT 0U /* Card is in 1 bit mode */
835 #define EXT_CSD_BUS_WIDTH_4_BIT 1U /* Card is in 4 bit mode */
836 #define EXT_CSD_BUS_WIDTH_8_BIT 2U /* Card is in 8 bit mode */
837 #define EXT_CSD_BUS_WIDTH_DDR_4_BIT 5U /* Card is in 4 bit DDR mode */
838 #define EXT_CSD_BUS_WIDTH_DDR_8_BIT 6U /* Card is in 8 bit DDR mode */
840 #define EXT_CSD_HS_TIMING_BYTE 185U
841 #define EXT_CSD_HS_TIMING_DEF 0U
842 #define EXT_CSD_HS_TIMING_HIGH 1U /* Card is in high speed mode */
843 #define EXT_CSD_HS_TIMING_HS200 2U /* Card is in HS200 mode */
846 #define XSDPS_EXT_CSD_CMD_SET 0U
847 #define XSDPS_EXT_CSD_SET_BITS 1U
848 #define XSDPS_EXT_CSD_CLR_BITS 2U
849 #define XSDPS_EXT_CSD_WRITE_BYTE 3U
851 #define XSDPS_MMC_DEF_SPEED_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
852 | ((u32)EXT_CSD_HS_TIMING_BYTE << 16) \
853 | ((u32)EXT_CSD_HS_TIMING_DEF << 8))
855 #define XSDPS_MMC_HIGH_SPEED_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
856 | ((u32)EXT_CSD_HS_TIMING_BYTE << 16) \
857 | ((u32)EXT_CSD_HS_TIMING_HIGH << 8))
859 #define XSDPS_MMC_HS200_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
860 | ((u32)EXT_CSD_HS_TIMING_BYTE << 16) \
861 | ((u32)EXT_CSD_HS_TIMING_HS200 << 8))
863 #define XSDPS_MMC_1_BIT_BUS_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
864 | ((u32)EXT_CSD_BUS_WIDTH_BYTE << 16) \
865 | ((u32)EXT_CSD_BUS_WITH_1_BIT << 8))
867 #define XSDPS_MMC_4_BIT_BUS_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
868 | ((u32)EXT_CSD_BUS_WIDTH_BYTE << 16) \
869 | ((u32)EXT_CSD_BUS_WIDTH_4_BIT << 8))
871 #define XSDPS_MMC_8_BIT_BUS_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
872 | ((u32)EXT_CSD_BUS_WIDTH_BYTE << 16) \
873 | ((u32)EXT_CSD_BUS_WIDTH_8_BIT << 8))
875 #define XSDPS_MMC_DDR_4_BIT_BUS_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
876 | ((u32)EXT_CSD_BUS_WIDTH_BYTE << 16) \
877 | ((u32)EXT_CSD_BUS_WIDTH_DDR_4_BIT << 8))
879 #define XSDPS_MMC_DDR_8_BIT_BUS_ARG (((u32)XSDPS_EXT_CSD_WRITE_BYTE << 24) \
880 | ((u32)EXT_CSD_BUS_WIDTH_BYTE << 16) \
881 | ((u32)EXT_CSD_BUS_WIDTH_DDR_8_BIT << 8))
883 #define XSDPS_MMC_DELAY_FOR_SWITCH 1000U
887 /* @400KHz, in usec */
888 #define XSDPS_74CLK_DELAY 2960U
889 #define XSDPS_100CLK_DELAY 4000U
890 #define XSDPS_INIT_DELAY 10000U
892 #define XSDPS_DEF_VOLT_LVL XSDPS_PC_BUS_VSEL_3V0_MASK
893 #define XSDPS_CARD_DEF_ADDR 0x1234U
895 #define XSDPS_CARD_SD 1U
896 #define XSDPS_CARD_MMC 2U
897 #define XSDPS_CARD_SDIO 3U
898 #define XSDPS_CARD_SDCOMBO 4U
899 #define XSDPS_CHIP_EMMC 5U
902 /** @name ADMA2 Descriptor related definitions
904 * ADMA2 Descriptor related definitions
908 #define XSDPS_DESC_MAX_LENGTH 65536U
910 #define XSDPS_DESC_VALID (0x1U << 0)
911 #define XSDPS_DESC_END (0x1U << 1)
912 #define XSDPS_DESC_INT (0x1U << 2)
913 #define XSDPS_DESC_TRAN (0x2U << 4)
917 /* For changing clock frequencies */
918 #define XSDPS_CLK_400_KHZ 400000U /**< 400 KHZ */
919 #define XSDPS_CLK_50_MHZ 50000000U /**< 50 MHZ */
920 #define XSDPS_CLK_52_MHZ 52000000U /**< 52 MHZ */
921 #define XSDPS_SD_VER_1_0 0x1U /**< SD ver 1 */
922 #define XSDPS_SD_VER_2_0 0x2U /**< SD ver 2 */
923 #define XSDPS_SCR_BLKCNT 1U
924 #define XSDPS_SCR_BLKSIZE 8U
925 #define XSDPS_1_BIT_WIDTH 0x1U
926 #define XSDPS_4_BIT_WIDTH 0x2U
927 #define XSDPS_8_BIT_WIDTH 0x3U
928 #define XSDPS_UHS_SPEED_MODE_SDR12 0x0U
929 #define XSDPS_UHS_SPEED_MODE_SDR25 0x1U
930 #define XSDPS_UHS_SPEED_MODE_SDR50 0x2U
931 #define XSDPS_UHS_SPEED_MODE_SDR104 0x3U
932 #define XSDPS_UHS_SPEED_MODE_DDR50 0x4U
933 #define XSDPS_SWITCH_CMD_BLKCNT 1U
934 #define XSDPS_SWITCH_CMD_BLKSIZE 64U
935 #define XSDPS_SWITCH_CMD_HS_GET 0x00FFFFF0U
936 #define XSDPS_SWITCH_CMD_HS_SET 0x80FFFFF1U
937 #define XSDPS_SWITCH_CMD_SDR12_SET 0x80FFFFF0U
938 #define XSDPS_SWITCH_CMD_SDR25_SET 0x80FFFFF1U
939 #define XSDPS_SWITCH_CMD_SDR50_SET 0x80FFFFF2U
940 #define XSDPS_SWITCH_CMD_SDR104_SET 0x80FFFFF3U
941 #define XSDPS_SWITCH_CMD_DDR50_SET 0x80FFFFF4U
942 #define XSDPS_EXT_CSD_CMD_BLKCNT 1U
943 #define XSDPS_EXT_CSD_CMD_BLKSIZE 512U
944 #define XSDPS_TUNING_CMD_BLKCNT 1U
945 #define XSDPS_TUNING_CMD_BLKSIZE 64U
947 #define XSDPS_HIGH_SPEED_MAX_CLK 50000000U
948 #define XSDPS_UHS_SDR104_MAX_CLK 208000000U
949 #define XSDPS_UHS_SDR50_MAX_CLK 100000000U
950 #define XSDPS_UHS_DDR50_MAX_CLK 50000000U
951 #define XSDPS_UHS_SDR25_MAX_CLK 50000000U
952 #define XSDPS_UHS_SDR12_MAX_CLK 25000000U
954 #define SD_DRIVER_TYPE_B 0x01U
955 #define SD_DRIVER_TYPE_A 0x02U
956 #define SD_DRIVER_TYPE_C 0x04U
957 #define SD_DRIVER_TYPE_D 0x08U
958 #define SD_SET_CURRENT_LIMIT_200 0U
959 #define SD_SET_CURRENT_LIMIT_400 1U
960 #define SD_SET_CURRENT_LIMIT_600 2U
961 #define SD_SET_CURRENT_LIMIT_800 3U
963 #define SD_MAX_CURRENT_200 (1U << SD_SET_CURRENT_LIMIT_200)
964 #define SD_MAX_CURRENT_400 (1U << SD_SET_CURRENT_LIMIT_400)
965 #define SD_MAX_CURRENT_600 (1U << SD_SET_CURRENT_LIMIT_600)
966 #define SD_MAX_CURRENT_800 (1U << SD_SET_CURRENT_LIMIT_800)
968 #define XSDPS_SD_SDR12_MAX_CLK 25000000U
969 #define XSDPS_SD_SDR25_MAX_CLK 50000000U
970 #define XSDPS_SD_SDR50_MAX_CLK 100000000U
971 #define XSDPS_SD_DDR50_MAX_CLK 50000000U
972 #define XSDPS_SD_SDR104_MAX_CLK 208000000U
973 #define XSDPS_MMC_HS200_MAX_CLK 200000000U
975 #define XSDPS_CARD_STATE_IDLE 0U
976 #define XSDPS_CARD_STATE_RDY 1U
977 #define XSDPS_CARD_STATE_IDEN 2U
978 #define XSDPS_CARD_STATE_STBY 3U
979 #define XSDPS_CARD_STATE_TRAN 4U
980 #define XSDPS_CARD_STATE_DATA 5U
981 #define XSDPS_CARD_STATE_RCV 6U
982 #define XSDPS_CARD_STATE_PROG 7U
983 #define XSDPS_CARD_STATE_DIS 8U
984 #define XSDPS_CARD_STATE_BTST 9U
985 #define XSDPS_CARD_STATE_SLP 10U
987 #define XSDPS_SLOT_REM 0U
988 #define XSDPS_SLOT_EMB 1U
990 #if defined (__arm__) || defined (__aarch64__)
991 #define SD_DLL_CTRL 0x00000358U
992 #define SD_ITAPDLY 0x00000314U
993 #define SD_OTAPDLYSEL 0x00000318U
994 #define SD0_DLL_RST 0x00000004U
995 #define SD0_ITAPCHGWIN 0x00000200U
996 #define SD0_ITAPDLYENA 0x00000100U
997 #define SD0_OTAPDLYENA 0x00000040U
998 #define SD0_OTAPDLYSEL_HS200 0x00000003U
1001 /**************************** Type Definitions *******************************/
1003 /***************** Macros (Inline Functions) Definitions *********************/
1004 #define XSdPs_In64 Xil_In64
1005 #define XSdPs_Out64 Xil_Out64
1007 #define XSdPs_In32 Xil_In32
1008 #define XSdPs_Out32 Xil_Out32
1010 #define XSdPs_In16 Xil_In16
1011 #define XSdPs_Out16 Xil_Out16
1013 #define XSdPs_In8 Xil_In8
1014 #define XSdPs_Out8 Xil_Out8
1016 /****************************************************************************/
1020 * @param BaseAddress contains the base address of the device.
1021 * @param RegOffset contains the offset from the 1st register of the
1022 * device to the target register.
1024 * @return The value read from the register.
1026 * @note C-Style signature:
1027 * u32 XSdPs_ReadReg(XSdPs *InstancePtr. s32 RegOffset)
1029 ******************************************************************************/
1030 #define XSdPs_ReadReg64(InstancePtr, RegOffset) \
1031 XSdPs_In64((InstancePtr->Config.BaseAddress) + RegOffset)
1033 /***************************************************************************/
1035 * Write to a register.
1037 * @param BaseAddress contains the base address of the device.
1038 * @param RegOffset contains the offset from the 1st register of the
1039 * device to target register.
1040 * @param RegisterValue is the value to be written to the register.
1044 * @note C-Style signature:
1045 * void XSdPs_WriteReg(XSdPs *InstancePtr, s32 RegOffset,
1046 * u64 RegisterValue)
1048 ******************************************************************************/
1049 #define XSdPs_WriteReg64(InstancePtr, RegOffset, RegisterValue) \
1050 XSdPs_Out64((InstancePtr->Config.BaseAddress) + (RegOffset), \
1053 /****************************************************************************/
1057 * @param BaseAddress contains the base address of the device.
1058 * @param RegOffset contains the offset from the 1st register of the
1059 * device to the target register.
1061 * @return The value read from the register.
1063 * @note C-Style signature:
1064 * u32 XSdPs_ReadReg(u32 BaseAddress. int RegOffset)
1066 ******************************************************************************/
1067 #define XSdPs_ReadReg(BaseAddress, RegOffset) \
1068 XSdPs_In32((BaseAddress) + (RegOffset))
1070 /***************************************************************************/
1072 * Write to a register.
1074 * @param BaseAddress contains the base address of the device.
1075 * @param RegOffset contains the offset from the 1st register of the
1076 * device to target register.
1077 * @param RegisterValue is the value to be written to the register.
1081 * @note C-Style signature:
1082 * void XSdPs_WriteReg(u32 BaseAddress, int RegOffset,
1083 * u32 RegisterValue)
1085 ******************************************************************************/
1086 #define XSdPs_WriteReg(BaseAddress, RegOffset, RegisterValue) \
1087 XSdPs_Out32((BaseAddress) + (RegOffset), (RegisterValue))
1089 /****************************************************************************/
1093 * @param BaseAddress contains the base address of the device.
1094 * @param RegOffset contains the offset from the 1st register of the
1095 * device to the target register.
1097 * @return The value read from the register.
1099 * @note C-Style signature:
1100 * u16 XSdPs_ReadReg(u32 BaseAddress. int RegOffset)
1102 ******************************************************************************/
1103 #define XSdPs_ReadReg16(BaseAddress, RegOffset) \
1104 XSdPs_In16((BaseAddress) + (RegOffset))
1106 /***************************************************************************/
1108 * Write to a register.
1110 * @param BaseAddress contains the base address of the device.
1111 * @param RegOffset contains the offset from the 1st register of the
1112 * device to target register.
1113 * @param RegisterValue is the value to be written to the register.
1117 * @note C-Style signature:
1118 * void XSdPs_WriteReg(u32 BaseAddress, int RegOffset,
1119 * u16 RegisterValue)
1121 ******************************************************************************/
1122 #define XSdPs_WriteReg16(BaseAddress, RegOffset, RegisterValue) \
1123 XSdPs_Out16((BaseAddress) + (RegOffset), (RegisterValue))
1125 /****************************************************************************/
1129 * @param BaseAddress contains the base address of the device.
1130 * @param RegOffset contains the offset from the 1st register of the
1131 * device to the target register.
1133 * @return The value read from the register.
1135 * @note C-Style signature:
1136 * u8 XSdPs_ReadReg(u32 BaseAddress. int RegOffset)
1138 ******************************************************************************/
1139 #define XSdPs_ReadReg8(BaseAddress, RegOffset) \
1140 XSdPs_In8((BaseAddress) + (RegOffset))
1142 /***************************************************************************/
1144 * Write to a register.
1146 * @param BaseAddress contains the base address of the device.
1147 * @param RegOffset contains the offset from the 1st register of the
1148 * device to target register.
1149 * @param RegisterValue is the value to be written to the register.
1153 * @note C-Style signature:
1154 * void XSdPs_WriteReg(u32 BaseAddress, int RegOffset,
1157 ******************************************************************************/
1158 #define XSdPs_WriteReg8(BaseAddress, RegOffset, RegisterValue) \
1159 XSdPs_Out8((BaseAddress) + (RegOffset), (RegisterValue))
1161 /***************************************************************************/
1163 * Macro to get present status register
1165 * @param BaseAddress contains the base address of the device.
1169 * @note C-Style signature:
1170 * void XSdPs_WriteReg(u32 BaseAddress, int RegOffset,
1173 ******************************************************************************/
1174 #define XSdPs_GetPresentStatusReg(BaseAddress) \
1175 XSdPs_In32((BaseAddress) + (XSDPS_PRES_STATE_OFFSET))
1177 /************************** Function Prototypes ******************************/
1179 /************************** Variable Definitions *****************************/
1185 #endif /* SD_HW_H_ */