1 //*****************************************************************************
2 //
3 //! @file am_hal_card.h
4 //!
5 //! @brief Functions for interfacing with the card host.
6 //!
7 //! @addtogroup card_4p Card Functionality for SD/MMC/eMMC/SDIO
8 //! @ingroup apollo4p_hal
9 //! @{
10 //
11 //*****************************************************************************
12 
13 //*****************************************************************************
14 //
15 // Copyright (c) 2023, Ambiq Micro, Inc.
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are met:
20 //
21 // 1. Redistributions of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
23 //
24 // 2. Redistributions in binary form must reproduce the above copyright
25 // notice, this list of conditions and the following disclaimer in the
26 // documentation and/or other materials provided with the distribution.
27 //
28 // 3. Neither the name of the copyright holder nor the names of its
29 // contributors may be used to endorse or promote products derived from this
30 // software without specific prior written permission.
31 //
32 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
36 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 // POSSIBILITY OF SUCH DAMAGE.
43 //
44 // This is part of revision stable-7da8bae71f of the AmbiqSuite Development Package.
45 //
46 //*****************************************************************************
47 #ifndef AM_HAL_CARD_H
48 #define AM_HAL_CARD_H
49 
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
54 
55 //
56 // SD/MMC(eMMC)/SDIO protocol HAL driver APIs
57 //
58 
59 #define MMC_CMD_GO_IDLE_STATE           0
60 #define MMC_CMD_SEND_OP_COND            1
61 #define MMC_CMD_ALL_SEND_CID            2
62 #define MMC_CMD_SET_RELATIVE_ADDR       3
63 #define MMC_CMD_SET_DSR                 4
64 #define MMC_CMD_SLEEP_AWAKE             5
65 #define MMC_CMD_SWITCH                  6
66 #define MMC_CMD_SELECT_CARD             7
67 #define MMC_CMD_SEND_EXT_CSD            8
68 #define MMC_CMD_SEND_CSD                9
69 #define MMC_CMD_SEND_CID                10
70 #define MMC_CMD_STOP_TRANSMISSION       12
71 #define MMC_CMD_SEND_STATUS             13
72 #define MMC_CMD_READ_TUNING_BLOCK       14
73 #define MMC_CMD_SET_BLOCKLEN            16
74 #define MMC_CMD_READ_SINGLE_BLOCK       17
75 #define MMC_CMD_READ_MULTIPLE_BLOCK     18
76 #define MMC_CMD_SEND_TUNING_BLOCK       19
77 #define MMC_CMD_SEND_TUNING_BLOCK_HS200 21
78 #define MMC_CMD_SET_BLOCK_COUNT         23
79 #define MMC_CMD_WRITE_SINGLE_BLOCK      24
80 #define MMC_CMD_WRITE_MULTIPLE_BLOCK    25
81 #define MMC_CMD_ERASE_GROUP_START       35
82 #define MMC_CMD_ERASE_GROUP_END         36
83 #define MMC_CMD_ERASE                   38
84 #define MMC_CMD_APP_CMD                 55
85 #define MMC_CMD_CMD56                   56
86 #define MMC_CMD_SPI_READ_OCR            58
87 #define MMC_CMD_SPI_CRC_ON_OFF          59
88 #define MMC_CMD_RES_MAN                 62
89 
90 #define SDIO_CMD_IO_SEND_OP_COND        5
91 #define SDIO_CMD_SEND_IF_COND           8
92 #define SDIO_CMD_VOLTAGE_SWITCH         11
93 #define SDIO_CMD_IO_RW_DIRECT           52
94 #define SDIO_CMD_IO_RW_EXTENDED         53
95 
96 #define SD_CMD_ERASE_WR_BLK_START       32
97 #define SD_CMD_ERASE_WR_BLK_END         33
98 #define SD_CMD_SEND_OP_COND             41
99 
100 #define MMC_RSP_PRESENT (1 << 0)
101 #define MMC_RSP_136     (1 << 1) /* 136 bit response */
102 #define MMC_RSP_CRC     (1 << 2) /* expect valid crc */
103 #define MMC_RSP_BUSY    (1 << 3) /* card may send busy */
104 #define MMC_RSP_OPCODE  (1 << 4) /* response contains opcode */
105 
106 #define MMC_RSP_NONE (0)
107 #define MMC_RSP_R1   (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE)
108 #define MMC_RSP_R1b  (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE | MMC_RSP_BUSY)
109 #define MMC_RSP_R2   (MMC_RSP_PRESENT | MMC_RSP_136 | MMC_RSP_CRC)
110 #define MMC_RSP_R3   (MMC_RSP_PRESENT)
111 #define MMC_RSP_R4   (MMC_RSP_PRESENT)
112 #define MMC_RSP_R5   (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE)
113 #define MMC_RSP_R6   (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE)
114 #define MMC_RSP_R7   (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE)
115 
116 //
117 // defines for EXT_CSD register in MMC HIGH SPEED cards
118 //
119 // Valid POWER_OFF_NOTIFICATION values
120 #define MMC_EXT_CSD_NO_POWER_NOTIFICATION   (0x00)
121 #define MMC_EXT_CSD_POWERED_ON              (0x01)
122 #define MMC_EXT_CSD_POWER_OFF_SHORT         (0x02)
123 #define MMC_EXT_CSD_POWER_OFF_LONG          (0x03)
124 #define MMC_EXT_CSD_SLEEP_NOTIFICATION      (0x04)
125 
126 //
127 // Supported Bus Width Types
128 //
129 #define SD_BUS_WIDTH1     0
130 #define SD_BUS_WIDTH4     1
131 #define SD_BUS_WIDTH8     2
132 #define SD_BUS_WIDTH4_DDR 5
133 #define SD_BUS_WIDTH8_DDR 6
134 
135 #define MMC_EXT_MODE_COMMAND_SET (0 << 24)
136 #define MMC_EXT_MODE_SET_BIT     (1 << 24)
137 #define MMC_EXT_MODE_CLEAR_BITS  (2 << 24)
138 #define MMC_EXT_MODE_WRITE_BYTE (3 << 24)
139 
140 // Added for MMC4.3
141 #define eMMC_BGA_TYPE 0x01
142 
143 #define MMC_EXT_REGS_CMD_SET             (191 << 16)
144 #define MMC_EXT_REGS_POWER_CLASS         (187 << 16)
145 #define MMC_EXT_REGS_HIGH_SPEED          (185 << 16)
146 #define MMC_EXT_REGS_BUS_WIDTH           (183 << 16)
147 #define MMC_EXT_REGS_BOOT_CONFIG         (179 << 16)
148 #define MMC_EXT_REGS_BOOT_GONFIGPROT     (178 << 16)
149 #define MMC_EXT_REGS_BOOT_BUSWIDTH       (177 << 16)
150 #define MMC_EXT_REGS_ERASEGRP_DEFN       (175 << 16)
151 #define MMC_EXT_REGS_BOOT_WP             (173 << 16)
152 #define MMC_EXT_REGS_USR_WP              (171 << 16)
153 #define MMC_EXT_REGS_FW_CONFIG           (169 << 16)
154 #define MMC_EXT_REGS_SANITIZE_START      165
155 #define MMC_EXT_REGS_BKOPS_START         164
156 #define MMC_EXT_REGS_BKOPS_ENABLE        163
157 #define MMC_EXT_REGS_RST_FUNC            (162 << 16)
158 #define MMC_EXT_REGS_HPI_MGMT            161
159 #define MMC_EXT_REGS_PART_ATTRB          (156 << 16)
160 #define MMC_EXT_REGS_PART_COMPLETE       (155 << 16)
161 #define MMC_EXT_REGS_GP_SIZE_MULT_4_2    (154 << 16)
162 #define MMC_EXT_REGS_GP_SIZE_MULT_4_1    (153 << 16)
163 #define MMC_EXT_REGS_GP_SIZE_MULT_4_0    (152 << 16)
164 #define MMC_EXT_REGS_GP_SIZE_MULT_3_2    (151 << 16)
165 #define MMC_EXT_REGS_GP_SIZE_MULT_3_1    (150 << 16)
166 #define MMC_EXT_REGS_GP_SIZE_MULT_3_0    (149 << 16)
167 #define MMC_EXT_REGS_GP_SIZE_MULT_2_2    (148 << 16)
168 #define MMC_EXT_REGS_GP_SIZE_MULT_2_1    (147 << 16)
169 #define MMC_EXT_REGS_GP_SIZE_MULT_2_0    (146 << 16)
170 #define MMC_EXT_REGS_GP_SIZE_MULT_1_2    (145 << 16)
171 #define MMC_EXT_REGS_GP_SIZE_MULT_1_1    (144 << 16)
172 #define MMC_EXT_REGS_GP_SIZE_MULT_1_0    (143 << 16)
173 #define MMC_EXT_REGS_ENH_SIZE_MULT2      (142 << 16)
174 #define MMC_EXT_REGS_ENH_SIZE_MULT1      (141 << 16)
175 #define MMC_EXT_REGS_ENH_SIZE_MULT0      (140 << 16)
176 #define MMC_EXT_REGS_ENH_START_ADDR      (136 << 16)
177 #define MMC_EXT_REGS_EXCEPTION_EVTS_CTRL (56 << 16)
178 #define MMC_EXT_REGS_CONTEXT_CONF        37
179 #define MMC_EXT_REGS_PWR_OFF_NOTIFY      34
180 #define MMC_EXT_REGS_CACHE_CTRL          33
181 #define MMC_EXT_REGS_FLUSH_CACHE         32
182 #define MMC_EXT_REGS_HS_TIMING           185
183 #define MMC_EXT_REGS_PARTITON_CONFIG     179
184 #define MMC_EXT_REGS_RPMB_SIZE_MULT      168
185 
186 #define MMC_EXP_PACKED_EVENT_EN  0x8
187 #define MMC_EXP_SYSPOOL_EVENT_EN 0x4
188 #define MMC_EXP_DYN_CAP_EVENT_EN 0x2
189 #define MMC_EXT_SEC_SANITIZE     (0x1 << 6)
190 
191 #define MMC_EXT_SET_BUS_WIDTH1     (SD_BUS_WIDTH1 << 8)
192 #define MMC_EXT_SET_BUS_WIDTH4     (SD_BUS_WIDTH4 << 8)
193 #define MMC_EXT_SET_BUS_WIDTH8     (SD_BUS_WIDTH8 << 8)
194 #define MMC_EXT_SET_BUS_WIDTH4_DDR (SD_BUS_WIDTH4_DDR << 8)
195 #define MMC_EXT_SET_BUS_WIDTH8_DDR (SD_BUS_WIDTH8_DDR << 8)
196 
197 #define MMC_EXT_SET_HIGH_SPEED (1 << 8)
198 #define MMC_EXT_SET_CMD_ATA    (1 << 4)
199 
200 // Added for MMC4.3
201 
202 // CARD TYPE FLAGS
203 #define HS_26MHZ           0x1
204 #define HS_52MHZ           0x2
205 #define HS_DDR_52MHZ_18_3V 0x4
206 #define HS_DDR_52MHZ_12V   0x4
207 #define HS200_200MHZ_18V   0x10
208 #define HS200_200MHZ_12V   0x20
209 #define HS200_TIMING       0x02
210 
211 // BOOT ACK FLAGS
212 #define eMMC_BOOT_ACK_EN 0x01
213 #define eMMC_NO_BOOT_ACK 0x00
214 
215 // BOOT PARTITION ENABLE FLAGS
216 #define eMMC_NO_BOOT_EN    0x00
217 #define eMMC_BOOT_PART1_EN 0x01
218 #define eMMC_BOOT_PART2_EN 0x02
219 #define eMMC_BOOT_USER_EN  0x07
220 
221 // BOOT PARTITION ACCESS FLAGS
222 #define eMMC_NO_BOOT_ACCESS 0x00
223 #define eMMC_BOOT1_ACCESS   0x01
224 #define eMMC_BOOT2_ACCESS   0x02
225 #define eMMC_RPMB_ACCESS    0x03
226 #define eMMC_GPP1_ACCESS    0x04
227 #define eMMC_GPP2_ACCESS    0x05
228 #define eMMC_GPP3_ACCESS    0x06
229 #define eMMC_GPP4_ACCESS    0x07
230 
231 // BOOT BUS WIDTH FLAGS
232 #define eMMC_RESET_BUSWDITH  0x00
233 #define eMMC_RETAIN_BUSWDITH 0x01
234 
235 // BOOT BUS WIDTH MODES
236 #define SDR_BCKWARD_COMP_BOOT_MOD 0x00
237 #define SDR_HS_TIMING_BOOT_MODE   0x01
238 #define DDR_BOOT_MODE             0x02
239 
240 // BOOT BUS WIDTHS
241 #define eMMC_BOOT_BUSWIDTH1 0x00
242 #define eMMC_BOOT_BUSWIDTH4 0x01
243 #define eMMC_BOOT_BUSWIDTH8 0x02
244 
245 // Boot Config Protection Flags
246 #define PERM_BOOT_CONFIG_PROT_EN  0x01
247 #define PERM_BOOT_CONFIG_PROT_DIS 0x00
248 #define PWR_BOOT_CONFIG_PROT_EN   0x01
249 #define PWR_BOOT_CONFIG_PROT_DIS  0x00
250 
251 // Boot Write Protection Flags
252 #define BOOT_PWR_WP_DIS  0x01
253 #define BOOT_PWR_WP_USE  0x00
254 #define BOOT_PERM_WP_DIS 0x01
255 #define BOOT_PERM_WP_USE 0x00
256 #define BOOT_PERM_WP_EN  0x01
257 #define BOOT_PERM_NO_WP  0x00
258 #define BOOT_PWR_WP_EN   0x01
259 #define BOOT_PWR_NO_WP   0x00
260 
261 // User Write Protection Flags
262 #define PERM_PSWD_DIS           0x1
263 #define PERM_PSWD_EN            0x0
264 #define CD_PERM_WP_DIS          0x1
265 #define CD_PERM_WP_EN           0x0
266 #define US_PERM_WP_GRP_DIS      0x1
267 #define US_PERM_WP_GRP_EN       0x0
268 #define US_PWR_WP_GRP_DIS       0x1
269 #define US_PWR_WP_GRP_EN        0x0
270 #define US_PERM_WP_CMD28GRP_EN  0x1
271 #define US_PERM_WP_CMD28GRP_DIS 0x0
272 #define US_PWR_WP_CMD28GRP_EN   0x1
273 #define US_PWR_WP_CMD28GRP_DIS  0x0
274 
275 // FW update Flags
276 #define FW_UPDATE_EN  0x0
277 #define FW_UPDATE_DIS 0x1
278 
279 // Reset Function Enable
280 #define RST_N_TEMP_DIS 0x0
281 #define RST_N_PERM_EN  0x1
282 #define RST_N_PERM_DIS 0x2
283 
284 // Partition Support Flags
285 #define ENH_ATTRIBUTE_EN  0x1
286 #define ENH_ATTRIBUTE_DIS 0x0
287 #define PARTITIONING_EN   0x1
288 #define PARTITIONING_DIS  0x0
289 
290 // Partition Atrribute Features
291 #define SET_ENH_USR            0x1
292 #define SET_ENH_GPP1           0x2
293 #define SET_ENH_GPP2           0x4
294 #define SET_ENH_GPP3           0x8
295 #define SET_ENH_GPP4           0x10
296 #define SET_ALL_PART_ATTRB     0x1F
297 #define SET_ALL_GPP_PART_ATTRB 0x1E
298 
299 // Partition Completion Flags
300 #define PARTITION_COMPLETE 0x1
301 
302 // Ext CSD Read Flags
303 #define HS_BOOT_MODE_SUPPORT  0x1
304 #define DDR_BOOT_MODE_SUPPORT (1 << 1)
305 #define ALT_BOOT_MODE_SUPPORT (1 << 2)
306 #define SEC_ER_EN             0x1
307 #define SEC_GB_CL_EN          0x10
308 
309 // eMMC44 RPMB Flags
310 #define AUTH_KEY_PGM_REQ 0x0001
311 #define WR_CNTR_VAL_REQ  0x0002
312 #define AUTH_DAT_WR_REQ  0x0003
313 #define AUTH_DAT_RD_REQ  0x0004
314 #define RESULT_RD_REQ    0x0005
315 
316 #define AUTH_KEY_PGM_RESP 0x0100
317 #define WR_CNTR_VAL_RESP  0x0200
318 #define AUTH_DAT_WR_RESP  0x0300
319 #define AUTH_DAT_RD_RESP  0x0400
320 
321 #define OPR_OK                    0x00
322 #define WRCNT_EXP_OPR_OK          (0x80)
323 #define GEN_FAILURE               0x01
324 #define WRCNT_EXP_GEN_FAILURE     (0x81)
325 #define AUTH_FAILURE              0x02
326 #define WRCNT_EXP_AUTH_FAILURE    (0x82)
327 #define COUNTER_FAILURE           0x03
328 #define WRCNT_EXP_COUNTER_FAILURE (0x83)
329 #define ADDR_FAILURE              0x04
330 #define WRCNT_EXP_ADDR_FAILURE    (0x84)
331 #define WRITE_FAILURE             0x05
332 #define WRCNT_EXP_WRITE_FAILURE   (0x85)
333 #define READ_FAILURE              0x06
334 #define WRCNT_EXP_READ_FAILURE    (0x86)
335 #define AUTH_KEY_NOT_PGMMED       0x07
336 
337 #define RPMB_MAC_KEY_LENGTH        32
338 #define RPMB_NONCE_LENGTH          16
339 #define RPMB_DATA_LENGTH           256
340 #define RPMB_STUFF_LENGTH          196
341 #define RPMB_COUNTER_LENGTH        4
342 #define RPMB_ADDR_LENGTH           2
343 #define RPMB_BLKCNT_LENGTH         2
344 #define RPMB_RESULT_LENGTH         2
345 #define RPMB_RSPREQ_LENGTH         2
346 #define TOTAL_MAC_LEN_PER_FRAME    284
347 #define MACLEN_EXCL_DATA_PER_FRAME 28
348 #define RPMB_BLKCNT_MAX(x)         ((x)*128*1024/256)
349 
350 // EMMC ERROR CODES
351 #define EMMC_INVALID_BOOT_ACK          -26
352 #define EMMC_INVALID_BOOT_PART         -27
353 #define EMMC_INVALID_BOOT_ACCESS       -28
354 #define EMMC_INVALID_BOOT_BUSWIDTH     -29
355 #define EMMC_INVALID_BOOT_BUSWIDTHFLAG -30
356 #define EMMC_INVALID_BOOT_BUSMODE      -31
357 #define EMMC_INVALID_BOOT_CONFIGPROT   -32
358 #define EMMC_INVALID_BOOT_WPENABLE     -33
359 #define EMMC_INVALID_USR_WPENABLE      -34
360 #define EMMC_INVALID_ERASEGRPDEFN      -35
361 #define EMMC_INVALID_GPP_NO            -36
362 
363 // Added for eMMC4.51
364 #define EMMC_CMD38_ERASE        0x00000000
365 #define EMMC_CMD38_SECURE_ERASE 0x80000000
366 #define EMMC_CMD38_SECURE_TRIM1 0x80000001
367 #define EMMC_CMD38_SECURE_TRIM2 0x80008000
368 #define EMMC_CMD38_TRIM         0x00000001
369 #define EMMC_CMD38_DISCARD      0x00000003
370 
371 // SD Card HCS operation define
372 #define SD_CARD_OCR_MSK_BUSY             0x80000000 // Busy flag
373 #define SD_CARD_OCR_MSK_HC               0x40000000 // High Capacity flag
374 #define SD_CARD_OCR_MSK_VOLTAGE_ALL      0x00FF8000 // All Voltage flag
375 #define SD_CARD_SWITCH_1P8V              0x1000000  // 1 << 24
376 #define SD_CARD_DEFAULT_OCR              (SD_CARD_OCR_MSK_VOLTAGE_ALL | SD_CARD_OCR_MSK_HC | SD_CARD_SWITCH_1P8V)
377 #define SD_CARD_1P8V_MSK                 (1 << 24)
378 
379 // SD Card switch function define
380 #define SD_CARD_CHECK_FUNCTION           (0 << 31)
381 #define SD_CARD_SWITCH_FUNCTION          (1 << 31)
382 #define SD_CARD_SWITCH_ARGUMENT          ((0xF << 4) | (0xFF << 8) | (0xFF << 16))
383 
384 // SD Card function group bit define
385 #define SD_CARD_ACCESS_MODE_GROUP         0
386 #define SD_CARD_COMMAND_GROUP             4
387 #define SD_CARD_DRIVER_STRENGTH_GROUP     8
388 #define SD_CARD_POWER_GROUP               12
389 
390 // SD Card access mode bit define
391 #define SD_CARD_CHECK_ALL_SPEED            0
392 #define SD_CARD_DEFAULT_SPEED             (0 << SD_CARD_ACCESS_MODE_GROUP)
393 #define SD_CARD_HIGH_SPEED                (1 << SD_CARD_ACCESS_MODE_GROUP)
394 #define SD_CARD_SDR12                     (0 << SD_CARD_ACCESS_MODE_GROUP)
395 #define SD_CARD_SDR25                     (1 << SD_CARD_ACCESS_MODE_GROUP)
396 #define SD_CARD_SDR50                     (2 << SD_CARD_ACCESS_MODE_GROUP)
397 #define SD_CARD_SDR104                    (3 << SD_CARD_ACCESS_MODE_GROUP)
398 #define SD_CARD_DDR50                     (4 << SD_CARD_ACCESS_MODE_GROUP)
399 
400 // SD Card max capacity define
401 #define SDSC_MAX_BLK_CNT                  0x400000      // SDSC max capacity is 2GB , so max block is 2*1024*1024*1024/512 = 0x400000
402 #define SDHC_MAX_BLK_CNT                  0x4000000     // SDHC max capacity is 32GB , so max block is 32*1024*1024*1024/512 = 0x4000000
403 #define SDXC_MAX_BLK_CNT                  0x100000000   // SDXC max capacity is 2TB , so max block is 2*1024*1024*1024*1024/512 = 0x100000000
404 
405 // SD Card voltage check operation define
406 #define SD_CARD_CHECK_PATTERN               (0xAA << 0)
407 #define SD_CARD_2P7_3P6_VOLTAGE_SUPPLY      (1 << 8)
408 #define SD_CARD_LOW_VOLTAGE_RESERVE         (2 << 8)
409 
410 #define DEFAULT_CMD6_TIMEOUT_MS  500
411 #define DEFAULT_GET_STATUS_TIMEOUT_MS  20
412 
413 #define MMC_STATUS_MASK         (~0x0206BF7F)
414 #define MMC_STATUS_SWITCH_ERROR (1 << 7)
415 #define MMC_STATUS_RDY_FOR_DATA (1 << 8)
416 #define MMC_STATUS_CURR_STATE   (0xf << 9)
417 #define MMC_STATUS_ERROR        (1 << 19)
418 
419 // Card voltage setting
420 #define MMC_VDD_17_18           0x00000020
421 #define MMC_VDD_18_19           0x00000040
422 #define MMC_VDD_19_20           0x00000080
423 
424 // SDIO CCCR Registers
425 #define SDIO_CCCR_CCCR_REV          0x00
426 #define SDIO_CCCR_SD_REV            0x01
427 #define SDIO_CCCR_IO_ENABLE         0x02
428 #define SDIO_CCCR_IO_RDY            0x03
429 #define SDIO_CCCR_INT_ENABLE        0x04
430 #define SDIO_CCCR_INT_RDY           0x05
431 #define SDIO_CCCR_IO_ABORT          0x06
432 #define SDIO_CCCR_BUS_CNTRL         0x07
433 #define SDIO_CCCR_CARD_CAPAB        0x08
434 #define SDIO_CCCR_CIS_PTR1          0x09
435 #define SDIO_CCCR_CIS_PTR2          0x0A
436 #define SDIO_CCCR_CIS_PTR3          0x0B
437 #define SDIO_CCCR_BUS_SUSPEND       0x0C
438 #define SDIO_CCCR_FN_SELECT         0x0D
439 #define SDIO_CCCR_EXEC_FLAGS        0x0E
440 #define SDIO_CCCR_RDY_FLAGS         0x0F
441 #define SDIO_CCCR_FN_BLK_SIZE1      0x10
442 #define SDIO_CCCR_FN_BLK_SIZE2      0x11
443 #define SDIO_CCCR_PWR_CNTRL         0x12
444 #define SDIO_CCCR_BUS_SPEED_SELECT  0x13
445 #define SDIO_CCCR_UHS_SUPPORT       0x14
446 #define SDIO_CCCR_DRIVER_STRENGTH   0x15
447 
448 // SDIO Card Capability Register Bits
449 #define  SDIO_CCCR_CAP_SDC          0x01    /* can do CMD52 while data transfer */
450 #define  SDIO_CCCR_CAP_SMB          0x02    /* can do multi-block xfers (CMD53) */
451 #define  SDIO_CCCR_CAP_SRW          0x04    /* supports read-wait protocol */
452 #define  SDIO_CCCR_CAP_SBS          0x08    /* supports suspend/resume */
453 #define  SDIO_CCCR_CAP_S4MI         0x10    /* interrupt during 4-bit CMD53 */
454 #define  SDIO_CCCR_CAP_E4MI         0x20    /* enable ints during 4-bit CMD53 */
455 #define  SDIO_CCCR_CAP_LSC          0x40    /* low speed card */
456 #define  SDIO_CCCR_CAP_4BLS         0x80    /* 4 bit low speed card */
457 
458 // SDIO Card Power Control Register Bits
459 #define  SDIO_POWER_SMPC            0x01    /* Supports Master Power Control */
460 #define  SDIO_POWER_EMPC            0x02    /* Enable Master Power Control */
461 
462 // SDIO Card Bus Speed Select Register Bits
463 #define  SDIO_SPEED_SHS             0x01    /* Supports High-Speed mode */
464 
465 // SDIO Card Tuple Definitions
466 #define SDIO_CIS_TPL_NULL           0x00
467 #define SDIO_CIS_TPL_MANFID         0x20
468 #define SDIO_CIS_TPL_FUNID          0x21
469 #define SDIO_CIS_TPL_FUNCE          0x22
470 #define SDIO_CIS_TPL_END            0xFF
471 
472 #define SDIO_CARD_MISMATCH_CNT_MAX  0x02
473 
474 // SDIO Card Speed Setting
475 #define SDIO_HIGHSPEED_SUPPORT      0x1
476 #define SDIO_HIGHSPEED_ENABLED      0x3
477 #define SDIO_FULLSPEED_ENABLED      0x0
478 #define SDIO_CARD_MAX_SPEED_LIMIT   96000000
479 #define SDIO_CARD_FULL_SPEED_LIMIT  25000000
480 
481 // EMMC Speed
482 #define MMC_LEGACY_HS 26000000
483 #define MMC_SDR_HS    52000000
484 #define MMC_DDR_HS    52000000
485 #define MMC_HS200    200000000
486 
487 //
488 // apollo4 SDHC speed limitation settings
489 //
490 #define MMC_HS200_MAX_SPEED_LIMIT   96000000
491 #define MMC_HS_MAX_SPEED_LIMIT      48000000
492 
493 //
494 // Internal macros
495 //
496 #define SDIO_TIMING_SCAN_MIN_ACCEPTANCE_LENGTH  2 // Acceptable length should be determined based on system level test.
497 #define AM_HAL_CARD_DEBUG(fmt, ...) am_util_debug_printf("[CARD] line %04d - "fmt, __LINE__, ##__VA_ARGS__)
498 
499 #define SECTOR_MODE       0x4
500 #define CARD_RDY_BIT      ((uint32_t)0x1 << 31)
501 
502 #define SDIO_SCAN_TXDELAY_MAX    16
503 #define SDIO_SCAN_RXDELAY_MAX    32
504 
505 //
506 // SDHC auto cmd32 enable
507 //
508 #define ENABLE_SDHC_AUTO_CMD23_FEATURE
509 
am_hal_unstuff_bits(uint32_t * resp,uint32_t start,uint32_t size)510 static inline uint32_t am_hal_unstuff_bits(uint32_t *resp, uint32_t start, uint32_t size)
511 {
512     const int __size = size;
513     const uint32_t __mask = (__size < 32 ? 1 << __size : 0) - 1;
514     const int __off = 3 - ((start) / 32);
515     const int __shft = (start)&31;
516     uint32_t __res;
517 
518     __res = resp[__off] >> __shft;
519     if (__size + __shft > 32)
520     {
521         __res |= resp[__off - 1] << ((32 - __shft) % 32);
522     }
523     return __res &__mask;
524 }
525 
am_hal_unstuff_bytes(uint32_t * ext_csd,uint32_t start,uint32_t size)526 static inline uint32_t am_hal_unstuff_bytes(uint32_t *ext_csd, uint32_t start, uint32_t size)
527 {
528     int i;
529     const uint32_t __size = size;
530     uint32_t __res = 0x0;
531     const uint8_t *__p = (const uint8_t *)ext_csd;
532     for (i = 0; i < __size; i++)
533     {
534         __res |= __p[start + i] << 8 * i;
535     }
536     return __res;
537 }
538 
539 
540 typedef enum
541 {
542     AM_HAL_ERASE        =          0x00000000,  // Erase
543     AM_HAL_DISCARD      =          0x00000003,  // Discard
544     AM_HAL_SECURE_ERASE = (int32_t)0x80000000,  // Secure Erase
545     AM_HAL_TRIM         =          0x00000001,  // Trim
546     AM_HAL_SECURE_TRIM1 = (int32_t)0x80000001,  // Secure Trim Step 1
547     AM_HAL_SECURE_TRIM2 = (int32_t)0x80008000,  // Secure Trim Step 2
548 } am_hal_card_erase_type_t;
549 
550 //
551 // SDHC card types
552 //
553 typedef enum
554 {
555     AM_HAL_CARD_TYPE_UNKNOWN,
556     AM_HAL_CARD_TYPE_MMC,
557     AM_HAL_CARD_TYPE_EMMC,
558     AM_HAL_CARD_TYPE_SDSC,
559     AM_HAL_CARD_TYPE_SDHC,
560     AM_HAL_CARD_TYPE_SDXC,
561     AM_HAL_CARD_TYPE_SDIO,
562     AM_HAL_CARD_TYPE_COMBO,
563 } am_hal_card_type_e;
564 
565 typedef enum
566 {
567     AM_HAL_CARD_STATE_NOT_PRESENT,
568     AM_HAL_CARD_STATE_PRESENT,
569     AM_HAL_CARD_STATE_IDLE,
570     AM_HAL_CARD_STATE_READY,
571     AM_HAL_CARD_STATE_IDENT,
572     AM_HAL_CARD_STATE_STDY,
573     AM_HAL_CARD_STATE_TRANS,
574     AM_HAL_CARD_STATE_DATA,
575     AM_HAL_CARD_STATE_RCV,
576     AM_HAL_CARD_STATE_PRG,
577     AM_HAL_CARD_STATE_DIS,
578     AM_HAL_CARD_STATE_BTST,
579     AM_HAL_CARD_STATE_SLP,
580     AM_HAL_CARD_STATE_ERROR,
581     AM_HAL_CARD_STATE_PWROFF,
582     AM_HAL_CARD_STATE_PWRON,
583 } am_hal_card_state_e;
584 
585 typedef struct
586 {
587     am_hal_card_type_e  eType;        // Card type
588     uint16_t ui16CmdClass;            // Card command classes
589     uint32_t ui32RCA;                 // Relative card address
590     uint32_t ui32MaxBlks;             // Card capacity in blocks
591     uint32_t ui32BlkSize;             // Block size in bytes
592     uint32_t ui32LogiMaxBlks;         // Card logical capacity in blocks
593     uint32_t ui32LogiBlkSize;         // Logical block size in bytes
594 } am_hal_card_info_t;
595 
596 typedef enum
597 {
598     AM_HAL_CARD_PWR_ON,
599     AM_HAL_CARD_PWR_OFF,
600     AM_HAL_CARD_PWR_CYCLE,
601     AM_HAL_CARD_PWR_SWITCH,
602 } am_hal_card_pwr_e;
603 
604 typedef enum
605 {
606     AM_HAL_SD_CARD_3_3_V,
607     AM_HAL_SD_CARD_1_8_V,
608 } am_hal_sd_card_voltage_e;
609 
610 typedef uint32_t (*am_hal_card_pwr_ctrl_func)(am_hal_card_pwr_e eCardPwr);
611 
612 typedef enum
613 {
614     AM_HAL_CARD_PWR_CTRL_NONE,
615     AM_HAL_CARD_PWR_CTRL_SDHC_OFF,
616     AM_HAL_CARD_PWR_CTRL_SDHC_OFF_AND_CARD_SLEEP,
617     AM_HAL_CARD_PWR_CTRL_SDHC_AND_CARD_OFF,
618 } am_hal_card_pwr_ctrl_policy_e;
619 
620 typedef struct
621 {
622     uint8_t ui8CccrRev;
623     uint8_t ui8SdRev;
624     uint8_t bMultiBlock:1,
625             bFullSpeed:1,
626             bWideBus:1,
627             bHighPower:1,
628             bHighSpeed:1;
629 }am_hal_sdio_card_cccr_t;
630 
631 typedef struct
632 {
633     uint32_t  ui32Vendor;
634     uint32_t  ui32Device;
635     uint32_t  ui32BlkSize;
636     uint32_t  ui32MaxSpeed;
637 }am_hal_sdio_card_cis_t;
638 
639 typedef struct
640 {
641     bool        bHighSpeed;
642     bool        bWrProtect;
643     bool        bSupportLowVolt;
644     bool        bSupportDefaultSpeed;
645     bool        bSupportHighSpeed;
646     bool        bSupportSDR12;
647     bool        bSupportSDR25;
648     bool        bSupportSDR50;
649     bool        bSupportSDR104;
650     bool        bSupportDDR50;
651     uint32_t    ui32CsdVersion;
652     uint32_t    ui32CSize;
653     uint32_t    ui32CSizeMult;
654     uint32_t    ui32RdBlockLen;
655     uint32_t    ui32CurrentVolt;
656 }am_hal_sd_card_info_t;
657 
658 //
659 // SDHC card
660 //
661 typedef struct
662 {
663     am_hal_card_type_e  eType;
664     am_hal_card_state_e eState;
665     uint32_t bCidValid:1;
666     uint32_t bCsdValid:1;
667     uint32_t bExtCsdValid:1;
668     uint32_t ui32OCR;
669     uint32_t ui32RCA;
670     uint32_t ui32FuncNum;
671     uint32_t ui32CID[4];
672     uint32_t ui32CSD[4];
673     uint32_t ui32ExtCSD[128];
674     uint8_t  ui8SpecVer;
675     uint8_t  ui8ExtCSDRev;
676     uint8_t  ui8PowerOffNotification;
677     bool     bHighCapcity;
678     uint32_t ui32CacheSize;
679     uint32_t ui32SleepNotificationTimeout;
680     uint32_t ui32PowerOffNotificationLongTimeout;
681     uint32_t ui32GenericCmd6Timeout;
682     uint32_t ui32MaxBlks;
683     uint32_t ui32Capacity;
684     uint8_t  ui8SecureErase;
685     uint8_t  ui8DeviceType;
686     uint32_t ui32BlkNum;
687     bool     bUseBlkEmulation;
688     uint32_t ui32NativeBlkSize;
689     uint32_t ui32BlkSize;
690     uint32_t ui32RpmbSizeMult;
691     uint16_t ui16CmdClass;
692     am_hal_card_pwr_ctrl_func pCardPwrCtrlFunc;
693     am_hal_card_pwr_ctrl_policy_e eCardPwrCtrlPolicy;
694     am_hal_card_cfg_t cfg;
695     am_hal_card_host_t *pHost;
696     am_hal_sdio_card_cccr_t cccr;
697     am_hal_sdio_card_cis_t cis;
698     am_hal_sd_card_info_t sdcard;
699 }  am_hal_card_t;
700 
701 //
702 // SD/MMC/eMMC/SDIO protocl driver APIs
703 //
704 
705 //*****************************************************************************
706 //
707 //! @brief Power off the SDHC or eMMC CARD
708 //!
709 //! @param pCard        - pointer to the card instance.
710 //!
711 //! This function is used to power off the SDHC host controller or eMMC card according
712 //! to the power policy setting in pCard->eCardPwrCtrlPolicy
713 //!
714 //! @return status      - generic or interface specific status.
715 //
716 //*****************************************************************************
717 extern uint32_t am_hal_card_pwrctrl_sleep(am_hal_card_t *pCard);
718 
719 //*****************************************************************************
720 //
721 //! @brief Power on the SDHC or eMMC CARD
722 //!
723 //! @param pCard        - pointer to the card instance.
724 //!
725 //! This function is used to power on the SDHC host controller or eMMC card according
726 //! to the power policy setting in pCard->eCardPwrCtrlPolicy
727 //!
728 //! @return status      - generic or interface specific status.
729 //
730 //*****************************************************************************
731 extern uint32_t am_hal_card_pwrctrl_wakeup(am_hal_card_t *pCard);
732 
733 //*****************************************************************************
734 //
735 //! @brief Get the card instance function
736 //!
737 //! @param pHost        - pointer to the card host instance.
738 //!
739 //! @param pCard        - pointer to the card instance.
740 //!
741 //! This function finds a card and trying to initialize it. if
742 //! card's initialization succeeds, the card will be 'Trans' state and can do
743 //! block read, write and erase operations.
744 //! @return status      - generic or interface specific status..
745 //
746 //*****************************************************************************
747 extern uint32_t am_hal_card_host_find_card(am_hal_card_host_t *pHost, am_hal_card_t *pCard);
748 
749 //*****************************************************************************
750 //
751 //! @brief Set the card operation configurations
752 //!
753 //! @param pCard        - pointer to the card instance.
754 //!
755 //! @param eType        - card type like eMMC, MMC, SDIO, .etc
756 //!
757 //! @param eBusWidth    - card bus width like 1, 4, 8 bit bus width
758 //!
759 //! @param ui32Clock    - card bus clock speed
760 //!
761 //! @param eIoVoltage   - card bus operation voltage
762 //!
763 //! @param eUHSMode     - card UHS mode
764 //!
765 //! This function sets the card's type, bus width, clock speed, bus operation voltage and UHS mode
766 //! but these settings will take effect immediately.
767 //!
768 //! @return status      - generic or interface specific status..
769 //
770 //*****************************************************************************
771 extern uint32_t am_hal_card_cfg_set(am_hal_card_t *pCard, am_hal_card_type_e eType,
772     am_hal_host_bus_width_e eBusWidth, uint32_t ui32Clock, am_hal_host_bus_voltage_e eIoVoltage,
773     am_hal_host_uhs_mode_e eUHSMode);
774 
775 //*****************************************************************************
776 //
777 //! @brief Initialize the card instance function
778 //!
779 //! @param pCard              - pointer to the card instance.
780 //! @param pCardPwrCtrlFunc   - pointer to the User defined Card Pwr Ctrl Func
781 //! @param eCardPwrCtrlPolicy - Power Control Policy can be:
782 //!     AM_HAL_CARD_PWR_CTRL_NONE
783 //!     AM_HAL_CARD_PWR_CTRL_SDHC_OFF
784 //!     AM_HAL_CARD_PWR_CTRL_SDHC_OFF_AND_CARD_SLEEP
785 //!     AM_HAL_CARD_PWR_CTRL_SDHC_AND_CARD_OFF
786 //!
787 //! This function sends a sequence of commands to initalize the card and let the card
788 //! enter into the 'Trans' state.
789 //!
790 //! @return status      - generic or interface specific status..
791 //
792 //*****************************************************************************
793 extern uint32_t am_hal_card_init(am_hal_card_t *pCard, am_hal_card_pwr_ctrl_func pCardPwrCtrlFunc,
794     am_hal_card_pwr_ctrl_policy_e eCardPwrCtrlPolicy);
795 
796 //*****************************************************************************
797 //
798 //! @brief De-Initialize the card instance function
799 //!
800 //! @param pCard        - pointer to the card instance.
801 //!
802 //! This function resets the card and cleans the card related setting and information.
803 //!
804 //! @return status      - generic or interface specific status..
805 //
806 //*****************************************************************************
807 extern uint32_t am_hal_card_deinit(am_hal_card_t *pCard);
808 
809 //*****************************************************************************
810 //
811 //! @brief synchronous block-oriented read function
812 //!
813 //! @param pCard        - pointer to the card instance.
814 //!
815 //! @param ui32Blk      - start block number
816 //!
817 //! @param ui32BlkCnt   - read block count
818 //!
819 //! @param pui8Buf      - read buffer
820 //!
821 //! This function reads the 'ui32BlkCnt' blocks starting from 'ui32Blk' block and
822 //! saves the data in the 'pui8Buf' read buffer. The caller will be blocked until all
823 //! data has been received or failed.
824 //!
825 //! @return status      - generic or interface specific status..
826 //
827 //*****************************************************************************
828 extern uint32_t am_hal_card_block_read_sync(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
829 
830 //*****************************************************************************
831 //
832 //! @brief synchronous block-oriented write function
833 //!
834 //! @param pCard        - pointer to the card instance.
835 //!
836 //! @param ui32Blk      - start block number
837 //!
838 //! @param ui32BlkCnt   - write block count
839 //!
840 //! @param pui8Buf      - write buffer
841 //!
842 //! This function writes 'ui32BlkCnt' blocks in the 'pui8Buf' write buffer to the card blocks
843 //! starting from 'ui32Blk' block. The caller will be blocked until all data has been sent
844 //! out or failed.
845 //!
846 //! @return status      - generic or interface specific status..
847 //
848 //*****************************************************************************
849 extern uint32_t am_hal_card_block_write_sync(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
850 
851 //*****************************************************************************
852 //
853 //! @brief asynchronous block-oriented read function
854 //!
855 //! @param pCard        - pointer to the card instance.
856 //!
857 //! @param ui32Blk      - start block number
858 //!
859 //! @param ui32BlkCnt   - read block count
860 //!
861 //! @param pui8Buf      - read buffer
862 //!
863 //! This function reads the 'ui32BlkCnt' blocks starting from 'ui32Blk' block and
864 //! saves the data in the 'pui8Buf' read buffer. The caller will not be blocked,
865 //! Data is ready in the buffer will be notified by the register callback function.
866 //!
867 //! @return status      - generic or interface specific status..
868 //
869 //*****************************************************************************
870 extern uint32_t am_hal_card_block_read_async(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
871 
872 //*****************************************************************************
873 //
874 //! @brief asynchronous block-oriented write function
875 //!
876 //! @param pCard        - pointer to the card instance.
877 //!
878 //! @param ui32Blk      - start block number
879 //!
880 //! @param ui32BlkCnt   - write block count
881 //!
882 //! @param pui8Buf      - write buffer
883 //!
884 //! This function writes 'ui32BlkCnt' blocks in the 'pui8Buf' write buffer to the card blocks
885 //! starting from 'ui32Blk' block. The caller will not be blocked, Completion of data transfer
886 //! will be notified by the register callback function.
887 //!
888 //! @return status      - generic or interface specific status..
889 //
890 //*****************************************************************************
891 extern uint32_t am_hal_card_block_write_async(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
892 
893 //*****************************************************************************
894 //
895 //! @brief emmc scatter write synchronous function
896 //!
897 //! @param pCard        - pointer to the card instance.
898 //!
899 //! @param ui32Blk      - start block number
900 //!
901 //! @param pIoVec       - pointer to the write vector.
902 //!
903 //! @param ui8IovCnt    - write vector count
904 //!
905 //! This function writes 'ui8IovCnt' write vector to emmc card and starting from 'ui32Blk'
906 //! block. The caller will be blocked until all data has been sent out or failed.
907 //!
908 //! @return status      - generic or interface specific status..
909 //
910 //*****************************************************************************
911 extern uint32_t am_hal_emmc_card_scatter_write_sync(am_hal_card_t *pCard, uint32_t ui32Blk, am_hal_card_iovec_t *pIoVec, uint8_t ui8IovCnt);
912 
913 //*****************************************************************************
914 //
915 //! @brief emmc scatter read synchronous function
916 //!
917 //! @param pCard        - pointer to the card instance.
918 //!
919 //! @param ui32Blk      - start block number
920 //!
921 //! @param pIoVec       - pointer to the read vector.
922 //!
923 //! @param ui8IovCnt    - read vector count
924 //!
925 //! This function reads 'ui8IovCnt' read vector starting from 'ui32Blk', and saves the data in 'pIoVec'.
926 //! The caller will be blocked until all data has been received or failed.
927 //!
928 //! @return status      - generic or interface specific status..
929 //
930 //*****************************************************************************
931 extern uint32_t am_hal_emmc_card_scatter_read_sync(am_hal_card_t *pCard, uint32_t ui32Blk, am_hal_card_iovec_t *pIoVec, uint8_t ui8IovCnt);
932 
933 //*****************************************************************************
934 //
935 //! @brief emmc scatter write asynchronous function
936 //!
937 //! @param pCard        - pointer to the card instance.
938 //!
939 //! @param ui32Blk      - start block number
940 //!
941 //! @param pIoVec       - pointer to the write vector.
942 //!
943 //! @param ui8IovCnt    - write vector count
944 //!
945 //! This function writes 'ui8IovCnt' write vector to emmc card and starting from 'ui32Blk'
946 //! block. The caller will not be blocked, Completion of data transfer will be notified by
947 //! the register callback function.
948 //!
949 //! @return status      - generic or interface specific status..
950 //
951 //*****************************************************************************
952 extern uint32_t am_hal_emmc_card_scatter_write_async(am_hal_card_t *pCard, uint32_t ui32Blk, am_hal_card_iovec_t *pIoVec, uint8_t ui8IovCnt);
953 
954 //*****************************************************************************
955 //
956 //! @brief emmc scatter read asynchronous function
957 //!
958 //! @param pCard        - pointer to the card instance.
959 //!
960 //! @param ui32Blk      - start block number
961 //!
962 //! @param pIoVec       - pointer to the read vector.
963 //!
964 //! @param ui8IovCnt    - read vector count
965 //!
966 //! This function reads 'ui8IovCnt' read vector starting from 'ui32Blk', and saves the data in 'pIoVec'.
967 //! The caller will not be blocked, Completion of data transfer will be notified by
968 //! the register callback function.
969 //!
970 //! @return status      - generic or interface specific status..
971 //
972 //*****************************************************************************
973 extern uint32_t am_hal_emmc_card_scatter_read_async(am_hal_card_t *pCard, uint32_t ui32Blk, am_hal_card_iovec_t *pIoVec, uint8_t ui8IovCnt);
974 
975 //*****************************************************************************
976 //
977 //! @brief block-oriented erase function
978 //!
979 //! @param pCard        - pointer to the card instance.
980 //!
981 //! @param ui32Blk      - start block number
982 //!
983 //! @param ui32BlkCnt   - write block count
984 //!
985 //! @param erasetype   - erase type
986 //!
987 //! @param ui32TimeoutMS - erase timeout value in millisecond
988 //!
989 //! This function erases 'ui32BlkCnt' blocks staring from 'ui32Blk' block. The caller will be blocked
990 //! until the erase is done or failed.
991 //!
992 //! @return status      - generic or interface specific status..
993 //
994 //*****************************************************************************
995 extern uint32_t am_hal_card_block_erase(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, am_hal_card_erase_type_t erasetype, uint32_t ui32TimeoutMS);
996 
997 //*****************************************************************************
998 //
999 //! @brief Get the card status function
1000 //!
1001 //! @param pCard        - pointer to the card instance.
1002 //!
1003 //! @param pui32Status  - the card status
1004 //!
1005 //! This function gets the card status by sending CMD13.
1006 //!
1007 //! @return status      - generic or interface specific status..
1008 //
1009 //*****************************************************************************
1010 extern uint32_t am_hal_card_status(am_hal_card_t *pCard, uint32_t *pui32Status);
1011 
1012 //*****************************************************************************
1013 //
1014 //! @brief Get the card state function
1015 //!
1016 //! @param pCard        - pointer to the card instance.
1017 //!
1018 //! This function gets the card state by sending CMD13.
1019 //!
1020 //! @return status      - emmc card state.
1021 //
1022 //*****************************************************************************
1023 extern am_hal_card_state_e am_hal_card_state(am_hal_card_t *pCard);
1024 
1025 //*****************************************************************************
1026 //
1027 //! @brief register the card event call back function
1028 //!
1029 //! @param pCard        - pointer to the card instance.
1030 //!
1031 //! @param pfunCallback - function pointer to the call back function.
1032 //!
1033 //! This function registers a card event callback function for async block-oriented
1034 //! read and write functions.
1035 //!
1036 //! @return status      - generic or interface specific status..
1037 //
1038 //*****************************************************************************
1039 extern uint32_t am_hal_card_register_evt_callback(am_hal_card_t *pCard, am_hal_host_event_cb_t pfunCallback);
1040 
1041 //*****************************************************************************
1042 //
1043 //! @brief card cid information parse function
1044 //!
1045 //! @param pCard        - pointer to the card instance.
1046 //! @param ui16Offset  - bit start position in the CID data structure.
1047 //! @param ui8Size     - bit length in the CID data structrure.
1048 //!
1049 //! This function parses the specified CID field in the CID data structure and returns
1050 //! as 32bit length integer.
1051 //!
1052 //! @return status      - generic or interface specific status..
1053 //
1054 //*****************************************************************************
1055 extern uint32_t am_hal_card_get_cid_field(am_hal_card_t *pCard, uint16_t ui16Offset, uint8_t ui8Size);
1056 
1057 //*****************************************************************************
1058 //
1059 //! @brief card csd information parse function
1060 //!
1061 //! @param pCard        - pointer to the card instance.
1062 //! @param ui16Offset  - bit start position in the CSD data structure.
1063 //! @param ui8Size     - bit length in the CSD data structrure.
1064 //!
1065 //! This function parses the specified CSD field in the CSD data structure and returns
1066 //! as 32bit length integer.
1067 //!
1068 //! @return status      - generic or interface specific status..
1069 //
1070 //*****************************************************************************
1071 extern uint32_t am_hal_card_get_csd_field(am_hal_card_t *pCard, uint16_t ui16Offset, uint8_t ui8Size);
1072 
1073 //*****************************************************************************
1074 //
1075 //! @brief card ext csd information parse function
1076 //!
1077 //! @param pCard        - pointer to the card instance.
1078 //! @param ui16Offset  - byte start position in the EXT CSD data structure.
1079 //! @param ui8Size     - byte length in the EXT CSD data structrure.
1080 //!
1081 //! This function parses the specified EXT CSD field in the EXT CSD data structure and returns
1082 //! as 32bit length integer.
1083 //!
1084 //! @return status      - generic or interface specific status..
1085 //
1086 //*****************************************************************************
1087 extern uint32_t am_hal_card_get_ext_csd_field(am_hal_card_t *pCard, uint16_t ui16Offset, uint8_t ui8Size);
1088 
1089 //*****************************************************************************
1090 //
1091 //! @brief Get the card information function
1092 //!
1093 //! @param pCard        - pointer to the card instance.
1094 //! @param pCardInfo    - pointer to am_hal_card_info_t structure that contains card info.
1095 //!
1096 //! This function gets the general eMMC card info into am_hal_card_info_t structure.
1097 //!
1098 //! @return status      - generic or interface specific status..
1099 //
1100 //*****************************************************************************
1101 extern uint32_t am_hal_card_get_info(am_hal_card_t *pCard, am_hal_card_info_t *pCardInfo);
1102 
1103 //*****************************************************************************
1104 //
1105 //! @brief Set the card mode function
1106 //!
1107 //! @param pCard        - pointer to the card instance.
1108 //! @param ui32Mode     - the card mode
1109 //! @param ui32Timeout  - mode switch timeout
1110 //!
1111 //! This function sets the card mode by sending CMD6.
1112 //!
1113 //! @return status      - generic or interface specific status..
1114 //
1115 //*****************************************************************************
1116 extern uint32_t am_hal_card_mode_switch(am_hal_card_t *pCard, uint32_t ui32Mode, uint32_t ui32Timeout);
1117 
1118 //*****************************************************************************
1119 //
1120 //! @brief Get the TX/RX delay setting by calibration
1121 //!
1122 //! @param eUHSMode     - card UHS mode
1123 //! @param ui32Clock    - card bus clock speed
1124 //! @param eBusWidth    - SDIO bus width.
1125 //! @param ui8CalibBuf  - data buffer used to do the calibration
1126 //! @param ui32StartBlk - eMMC start block used to do the calibration
1127 //! @param ui32BlkCnt   - eMMC block number used to do the calibration
1128 //! @param ui8TxRxDelays- an averaged the TX/RX delay values
1129 //!
1130 //! This function get the tx rx delay setting by finding all workable TX/RX delay
1131 //! settings, then an average TX/RX values are returned.
1132 //!
1133 //! @return status      - generic or interface specific status..
1134 //
1135 //*****************************************************************************
1136 extern uint32_t am_hal_card_emmc_calibrate(am_hal_host_uhs_mode_e eUHSMode,
1137                                            uint32_t ui32Clock,
1138                                            am_hal_host_bus_width_e eBusWidth,
1139                                            uint8_t *ui8CalibBuf,
1140                                            uint32_t ui32StartBlk,
1141                                            uint32_t ui32BlkCnt,
1142                                            uint8_t ui8TxRxDelays[2]);
1143 
1144 //*****************************************************************************
1145 //
1146 //! @brief Get the TX/RX delay setting by calibration
1147 //!
1148 //! @param eUHSMode     - card UHS mode
1149 //! @param ui32Clock    - card bus clock speed
1150 //! @param eBusWidth    - SDIO bus width.
1151 //! @param ui8CalibBuf  - data buffer used to do the calibration
1152 //! @param ui32StartBlk - sd card start block used to do the calibration
1153 //! @param ui32BlkCnt   - sd card block number used to do the calibration
1154 //! @param ui8TxRxDelays- an averaged the TX/RX delay values
1155 //! @param pCardPwrCtrlFunc - pointer to the User defined Card Pwr Ctrl Func
1156 //!
1157 //! This function get the tx rx delay setting by finding all workable TX/RX delay
1158 //! settings, then an average TX/RX values are returned.
1159 //!
1160 //! @return status      - generic or interface specific status..
1161 //
1162 //*****************************************************************************
1163 extern uint32_t am_hal_sd_card_calibrate(am_hal_host_uhs_mode_e eUHSMode,
1164                                            uint32_t ui32Clock,
1165                                            am_hal_host_bus_width_e eBusWidth,
1166                                            uint8_t *ui8CalibBuf,
1167                                            uint32_t ui32StartBlk,
1168                                            uint32_t ui32BlkCnt,
1169                                            uint8_t ui8TxRxDelays[2],
1170                                            am_hal_card_pwr_ctrl_func pCardPwrCtrlFunc);
1171 
1172 //*****************************************************************************
1173 //
1174 //! @brief Read blocks of data from the card (GEN_CMD) asynchronously
1175 //!
1176 //! @param pCard    - pointer to the card instance.
1177 //! @param ui32Arg  - command arguments
1178 //! @param pui8Buf  - read buffer
1179 //!
1180 //! @return status  - generic or interface specific status..
1181 //
1182 //*****************************************************************************
1183 extern uint32_t am_hal_card_cmd56_read_async(am_hal_card_t *pCard, uint32_t ui32Arg, uint8_t *pui8Buf);
1184 
1185 //*****************************************************************************
1186 //
1187 //! @brief Read blocks of data from the card (GEN_CMD) synchronously
1188 //!
1189 //! @param pCard    - pointer to the card instance.
1190 //! @param ui32Arg - command arguments
1191 //! @param pui8Buf  - read buffer
1192 //!
1193 //! @return status  - generic or interface specific status..
1194 //
1195 //*****************************************************************************
1196 extern uint32_t am_hal_card_cmd56_read_sync(am_hal_card_t *pCard, uint32_t ui32Arg, uint8_t *pui8Buf);
1197 
1198 //*****************************************************************************
1199 //
1200 //! @brief Enable SDIO card function
1201 //!
1202 //! @param pCard    - pointer to the card instance.
1203 //! @param ui32Func - SDIO card function number.
1204 //!
1205 //! @return status  - generic or interface specific status.
1206 //
1207 //*****************************************************************************
1208 extern uint32_t am_hal_sdio_card_func_enable(am_hal_card_t *pCard, uint32_t ui32Func);
1209 
1210 //*****************************************************************************
1211 //
1212 //! @brief Disable SDIO card function
1213 //!
1214 //! @param pCard    - pointer to the card instance.
1215 //! @param ui32Func - SDIO card function number.
1216 //!
1217 //! @return status  - generic or interface specific status.
1218 //
1219 //*****************************************************************************
1220 extern uint32_t am_hal_sdio_card_func_disable(am_hal_card_t *pCard, uint32_t ui32Func);
1221 
1222 //*****************************************************************************
1223 //
1224 //! @brief Enable SDIO card function's interrupt
1225 //!
1226 //! @param pCard    - pointer to the card instance.
1227 //! @param ui32Func - SDIO card function number.
1228 //!
1229 //! @return status  - generic or interface specific status.
1230 //
1231 //*****************************************************************************
1232 extern uint32_t am_hal_sdio_card_func_interrupt_enable(am_hal_card_t *pCard, uint32_t ui32Func);
1233 
1234 //*****************************************************************************
1235 //
1236 //! @brief Disable SDIO card function's interrupt
1237 //!
1238 //! @param pCard    - pointer to the card instance.
1239 //! @param ui32Func - SDIO card function number.
1240 //!
1241 //! @return status  - generic or interface specific status.
1242 //
1243 //*****************************************************************************
1244 extern uint32_t am_hal_sdio_card_func_interrupt_disable(am_hal_card_t *pCard, uint32_t ui32Func);
1245 
1246 //*****************************************************************************
1247 //
1248 //! @brief Get SDIO card function block size
1249 //!
1250 //! @param pCard        - pointer to the card instance.
1251 //! @param ui32Func     - SDIO card function number.
1252 //! @param pui32BlkSize - pointer to SDIO card block size.
1253 //!
1254 //! @return status      - generic or interface specific status.
1255 //
1256 //*****************************************************************************
1257 extern uint32_t am_hal_sdio_card_get_block_size(am_hal_card_t *pCard, uint32_t ui32Func, uint32_t *pui32BlkSize);
1258 
1259 //*****************************************************************************
1260 //
1261 //! @brief Set SDIO card function block size
1262 //!
1263 //! @param pCard        - pointer to the card instance.
1264 //! @param ui32Func     - SDIO card function number.
1265 //! @param ui32BlkSize  - SDIO card block size.
1266 //!
1267 //! @return status      - generic or interface specific status.
1268 //
1269 //*****************************************************************************
1270 extern uint32_t am_hal_sdio_card_set_block_size(am_hal_card_t *pCard, uint32_t ui32Func, uint32_t ui32BlkSize);
1271 
1272 //*****************************************************************************
1273 //
1274 //! @brief Read single byte from SDIO card
1275 //!
1276 //! @param pCard        - pointer to the card instance.
1277 //! @param ui32Func     - SDIO card function number.
1278 //! @param ui32Addr     - read address
1279 //! @param pui8Data     - read data
1280 //!
1281 //! @return status      - generic or interface specific status.
1282 //
1283 //*****************************************************************************
1284 extern uint32_t am_hal_sdio_card_byte_read(am_hal_card_t *pCard, uint32_t ui32Func, uint32_t ui32Addr, uint8_t *pui8Data);
1285 
1286 //*****************************************************************************
1287 //
1288 //! @brief Write single byte to SDIO card
1289 //!
1290 //! @param pCard        - pointer to the card instance.
1291 //! @param ui32Func     - SDIO card function number.
1292 //! @param ui32Addr     - write address
1293 //! @param ui8Data      - write data
1294 //!
1295 //! @return status      - generic or interface specific status.
1296 //
1297 //*****************************************************************************
1298 extern uint32_t am_hal_sdio_card_byte_write(am_hal_card_t *pCard, uint32_t ui32Func, uint32_t ui32Addr, uint8_t ui8Data);
1299 
1300 //*****************************************************************************
1301 //
1302 //! @brief Read multiple bytes/blocks from SDIO card in sync/blocking mode
1303 //!
1304 //! @param pCard        - pointer to the card instance.
1305 //! @param ui32Func     - SDIO card function number.
1306 //! @param ui32Addr     - read address
1307 //! @param pui8Buf      - read buffer
1308 //! @param ui32BlkCnt   - block or byte count
1309 //! @param ui32BlkSize  - block size
1310 //! @param bIncrAddr    - Selection for incrementing/fixed address
1311 //!
1312 //! @return status      - generic or interface specific status.
1313 //
1314 //*****************************************************************************
1315 extern uint32_t am_hal_sdio_card_multi_bytes_read_sync(am_hal_card_t *pCard,
1316                                                             uint32_t ui32Func,
1317                                                             uint32_t ui32Addr,
1318                                                             uint8_t *pui8Buf,
1319                                                             uint32_t ui32BlkCnt,
1320                                                             uint32_t ui32BlkSize,
1321                                                             bool     bIncrAddr);
1322 
1323 //*****************************************************************************
1324 //
1325 //! @brief Write multiple bytes/blocks to SDIO card in sync/blocking mode
1326 //!
1327 //! @param pCard        - pointer to the card instance.
1328 //! @param ui32Func     - SDIO card function number.
1329 //! @param ui32Addr     - write address
1330 //! @param pui8Buf      - write buffer
1331 //! @param ui32BlkCnt   - block or byte count
1332 //! @param ui32BlkSize  - block size
1333 //! @param bIncrAddr    - Selection for incrementing/fixed address
1334 //!
1335 //! @return status      - generic or interface specific status.
1336 //
1337 //*****************************************************************************
1338 extern uint32_t am_hal_sdio_card_multi_bytes_write_sync(am_hal_card_t *pCard,
1339                                                              uint32_t ui32Func,
1340                                                              uint32_t ui32Addr,
1341                                                              uint8_t *pui8Buf,
1342                                                              uint32_t ui32BlkCnt,
1343                                                              uint32_t ui32BlkSize,
1344                                                              bool     bIncrAddr);
1345 
1346 //*****************************************************************************
1347 //
1348 //! @brief Read multiple bytes/blocks from SDIO card in async/non-blocking mode
1349 //!
1350 //! @param pCard        - pointer to the card instance.
1351 //! @param ui32Func     - SDIO card function number.
1352 //! @param ui32Addr     - read address
1353 //! @param pui8Buf      - read buffer
1354 //! @param ui32BlkCnt   - block or byte count
1355 //! @param ui32BlkSize  - block size
1356 //! @param bIncrAddr    - Selection for incrementing/fixed address
1357 //!
1358 //! @return status      - generic or interface specific status.
1359 //
1360 //*****************************************************************************
1361 extern uint32_t am_hal_sdio_card_multi_bytes_read_async(am_hal_card_t *pCard,
1362                                                              uint32_t ui32Func,
1363                                                              uint32_t ui32Addr,
1364                                                              uint8_t *pui8Buf,
1365                                                              uint32_t ui32BlkCnt,
1366                                                              uint32_t ui32BlkSize,
1367                                                              bool     bIncrAddr);
1368 
1369 //*****************************************************************************
1370 //
1371 //! @brief Write multiple bytes/blocks to SDIO card in async/non-blocking mode
1372 //!
1373 //! @param pCard        - pointer to the card instance.
1374 //! @param ui32Func     - SDIO card function number.
1375 //! @param ui32Addr     - write address
1376 //! @param pui8Buf      - write buffer
1377 //! @param ui32BlkCnt   - block or byte count
1378 //! @param ui32BlkSize  - block size
1379 //! @param bIncrAddr    - Selection for incrementing/fixed address
1380 //!
1381 //! @return status      - generic or interface specific status.
1382 //
1383 //*****************************************************************************
1384 extern uint32_t am_hal_sdio_card_multi_bytes_write_async(am_hal_card_t *pCard,
1385                                                               uint32_t ui32Func,
1386                                                               uint32_t ui32Addr,
1387                                                               uint8_t *pui8Buf,
1388                                                               uint32_t ui32BlkCnt,
1389                                                               uint32_t ui32BlkSize,
1390                                                               bool     bIncrAddr);
1391 
1392 //*****************************************************************************
1393 //
1394 //! @brief emmc rpmb read write function
1395 //!
1396 //! @param pCard        - pointer to the card instance.
1397 //!
1398 //! @param pui8Buf      - write/read buffer
1399 //!
1400 //! @param bRead        - eMMC rpmb write/read direction
1401 //!
1402 //! @param bRelWrite    - eMMC rpmb is reliable write type.
1403 //!
1404 //! This function only support for eMMC rpmb operation.
1405 //!
1406 //! @return status      - generic or interface specific status..
1407 //
1408 //*****************************************************************************
1409 extern uint32_t
1410 am_hal_card_block_rpmb_rw(am_hal_card_t *pCard, uint8_t *pui8Buf, bool bRead, bool bRelWrite);
1411 
1412 //*****************************************************************************
1413 //
1414 //! @brief Enable SD Card detect function
1415 //!
1416 //! @param pCard         - pointer to the card instance.
1417 //!
1418 //! @param pfunCallback  - function pointer to the call back function.
1419 //!
1420 //! This function detect the card insert or removal in the slot
1421 //!
1422 //! @return status      - generic or interface specific status..
1423 //
1424 //*****************************************************************************
1425 extern uint32_t am_hal_sd_card_enable_card_detect(am_hal_card_t *pCard, am_hal_host_event_cb_t pfunCallback);
1426 
1427 //*****************************************************************************
1428 //
1429 //! @brief Disable SD Card detect function
1430 //!
1431 //! @param pCard         - pointer to the card instance.
1432 //!
1433 //! This function only support for sd card operation.
1434 //!
1435 //! @return status      - generic or interface specific status..
1436 //
1437 //*****************************************************************************
1438 extern uint32_t am_hal_sd_card_disable_card_detect(am_hal_card_t *pCard);
1439 
1440 //*****************************************************************************
1441 //
1442 //! @brief SD Card write protect detect function
1443 //!
1444 //! @param pCard         - pointer to the card instance.
1445 //!
1446 //! This function detect the card write is protected or enabled in the slot.
1447 //! must config SD card's WP pin in bsp before write protect detection.
1448 //! return 0: write enable, 1:write protect
1449 //!
1450 //! @return status      - generic or interface specific status.
1451 //
1452 //*****************************************************************************
1453 extern uint32_t am_hal_sd_card_write_protect_detect(am_hal_card_t *pCard);
1454 
1455 //*****************************************************************************
1456 //
1457 //! @brief SD Card get block count function
1458 //!
1459 //! @param pCard         - pointer to the card instance.
1460 //!
1461 //! This function get sd card block count.
1462 //!
1463 //! @return ui32MaxBlks      - sd card block count.
1464 //
1465 //*****************************************************************************
1466 extern uint32_t am_hal_sd_card_get_block_count(am_hal_card_t *pCard);
1467 
1468 //*****************************************************************************
1469 //
1470 //! @brief SD card synchronous block-oriented read function
1471 //!
1472 //! @param pCard        - pointer to the card instance.
1473 //!
1474 //! @param ui32Blk      - start block number
1475 //!
1476 //! @param ui32BlkCnt   - read block count
1477 //!
1478 //! @param pui8Buf      - read buffer
1479 //!
1480 //! This function reads the 'ui32BlkCnt' blocks starting from 'ui32Blk' block and
1481 //! saves the data in the 'pui8Buf' read buffer. The caller will be blocked until all
1482 //! data has been received or failed.
1483 //!
1484 //! @return status      - generic or interface specific status..
1485 //
1486 //*****************************************************************************
1487 extern uint32_t am_hal_sd_card_block_read_sync(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
1488 
1489 //*****************************************************************************
1490 //
1491 //! @brief SD card synchronous block-oriented write function
1492 //!
1493 //! @param pCard        - pointer to the card instance.
1494 //!
1495 //! @param ui32Blk      - start block number
1496 //!
1497 //! @param ui32BlkCnt   - write block count
1498 //!
1499 //! @param pui8Buf      - write buffer
1500 //!
1501 //! This function writes 'ui32BlkCnt' blocks in the 'pui8Buf' write buffer to the card blocks
1502 //! starting from 'ui32Blk' block. The caller will be blocked until all data has been sent
1503 //! out or failed.
1504 //!
1505 //! @return status      - generic or interface specific status.
1506 //
1507 //*****************************************************************************
1508 extern uint32_t am_hal_sd_card_block_write_sync(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
1509 
1510 //*****************************************************************************
1511 //
1512 //! @brief SD card asynchronous block-oriented read function
1513 //!
1514 //! @param pCard        - pointer to the card instance.
1515 //!
1516 //! @param ui32Blk      - start block number
1517 //!
1518 //! @param ui32BlkCnt   - read block count
1519 //!
1520 //! @param pui8Buf      - read buffer
1521 //!
1522 //! This function reads the 'ui32BlkCnt' blocks starting from 'ui32Blk' block and
1523 //! saves the data in the 'pui8Buf' read buffer. The caller will not be blocked,
1524 //! Data is ready in the buffer will be notified by the register callback function.
1525 //!
1526 //! @return status      - generic or interface specific status.
1527 //
1528 //*****************************************************************************
1529 extern uint32_t am_hal_sd_card_block_read_async(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
1530 
1531 //*****************************************************************************
1532 //
1533 //! @brief SD card asynchronous block-oriented write function
1534 //!
1535 //! @param pCard        - pointer to the card instance.
1536 //!
1537 //! @param ui32Blk      - start block number
1538 //!
1539 //! @param ui32BlkCnt   - write block count
1540 //!
1541 //! @param pui8Buf      - write buffer
1542 //!
1543 //! This function writes 'ui32BlkCnt' blocks in the 'pui8Buf' write buffer to the card blocks
1544 //! starting from 'ui32Blk' block. The caller will not be blocked, Completion of data transfer
1545 //! will be notified by the register callback function.
1546 //!
1547 //! @return status      - generic or interface specific status.
1548 //
1549 //*****************************************************************************
1550 extern uint32_t am_hal_sd_card_block_write_async(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint8_t *pui8Buf);
1551 
1552 //*****************************************************************************
1553 //
1554 //! @brief SD card block-oriented erase function
1555 //!
1556 //! @param pCard        - pointer to the card instance.
1557 //!
1558 //! @param ui32Blk      - start block number
1559 //!
1560 //! @param ui32BlkCnt   - write block count
1561 //!
1562 //! @param ui32TimeoutMS - erase timeout value in millisecond
1563 //!
1564 //! This function erases 'ui32BlkCnt' blocks staring from 'ui32Blk' block. The caller will be blocked
1565 //! until the erase is done or failed.
1566 //!
1567 //! @return status      - generic or interface specific status.
1568 //
1569 //*****************************************************************************
1570 extern uint32_t am_hal_sd_card_block_erase(am_hal_card_t *pCard, uint32_t ui32Blk, uint32_t ui32BlkCnt, uint32_t ui32TimeoutMS);
1571 
1572 //*****************************************************************************
1573 //
1574 //! @brief Get the TX/RX delay setting by calibration
1575 //!
1576 //! @param eIndex         - index to the underlying card host instance.s
1577 //!
1578 //! @param eUHSMode       - card UHS mode
1579 //!
1580 //! @param ui32Clock      - card bus clock speed
1581 //!
1582 //! @param eBusWidth      - SDIO bus width.
1583 //!
1584 //! @param ui8CalibBuf    - data buffer used to do the calibration
1585 //!
1586 //! @param ui32StartAddr  - SDIO card start address used to do the calibration
1587 //!
1588 //! @param ui32BlockCnt   - SDIO card block number used to do the calibration
1589 //!
1590 //! @param eIoVoltage     - card bus operation voltage
1591 //!
1592 //! @param ui8TxRxDelays  - an averaged the TX/RX delay values
1593 //!
1594 //! @param pSdioCardReset - pointer to the User reset sdio card
1595 //!
1596 //! This function get the tx rx delay setting by finding all workable TX/RX delay
1597 //! settings, then an average TX/RX values are returned.
1598 //!
1599 //! @return status      - generic or interface specific status..
1600 //
1601 //*****************************************************************************
1602 extern uint32_t am_hal_sdio_card_calibrate(am_hal_host_inst_index_e eIndex,
1603                                     am_hal_host_uhs_mode_e eUHSMode,
1604                                     uint32_t ui32Clock,
1605                                     am_hal_host_bus_width_e eBusWidth,
1606                                     uint8_t *ui8CalibBuf,
1607                                     uint32_t ui32StartAddr,
1608                                     uint32_t ui32BlockCnt,
1609                                     am_hal_host_bus_voltage_e eIoVoltage,
1610                                     uint8_t ui8TxRxDelays[2],
1611                                     am_hal_card_pwr_ctrl_func pSdioCardReset);
1612 
1613 #ifdef __cplusplus
1614 }
1615 #endif
1616 
1617 #endif // AM_HAL_CARD_H
1618 
1619 //*****************************************************************************
1620 //
1621 // End Doxygen group.
1622 //! @}
1623 //
1624 //*****************************************************************************
1625 
1626