1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef _FSL_SDMMC_H_
10 #define _FSL_SDMMC_H_
11 
12 #include "fsl_card.h"
13 
14 /*******************************************************************************
15  * Definitions
16  ******************************************************************************/
17 /*! @brief Reverse byte sequence in uint32_t */
18 #define SWAP_WORD_BYTE_SEQUENCE(x) (__REV(x))
19 /*! @brief Reverse byte sequence for each half word in uint32_t */
20 #define SWAP_HALF_WROD_BYTE_SEQUENCE(x) (__REV16(x))
21 
22 /*! @brief Maximum loop count to check the card operation voltage range */
23 #define FSL_SDMMC_MAX_VOLTAGE_RETRIES (1000U)
24 /*! @brief Maximum loop count to send the cmd */
25 #define FSL_SDMMC_MAX_CMD_RETRIES (10U)
26 /*************************************************************************************************
27  * API
28  ************************************************************************************************/
29 #if defined(__cplusplus)
30 extern "C" {
31 #endif
32 
33 /*!
34  * @brief Selects the card to put it into transfer state.
35  *
36  * @param base HOST peripheral base address.
37  * @param transfer HOST transfer function.
38  * @param relativeAddress Relative address.
39  * @param isSelected True to put card into transfer state.
40  * @retval kStatus_SDMMC_TransferFailed Transfer failed.
41  * @retval kStatus_Success Operate successfully.
42  */
43 status_t SDMMC_SelectCard(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t relativeAddress, bool isSelected);
44 
45 /*!
46  * @brief Sends an application command.
47  *
48  * @param base HOST peripheral base address.
49  * @param transfer HOST transfer function.
50  * @param relativeAddress Card relative address.
51  * @retval kStatus_SDMMC_TransferFailed Transfer failed.
52  * @retval kStatus_SDMMC_CardNotSupport Card doesn't support.
53  * @retval kStatus_Success Operate successfully.
54  */
55 status_t SDMMC_SendApplicationCommand(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t relativeAddress);
56 
57 /*!
58  * @brief Sets the block count.
59  *
60  * @param base HOST peripheral base address.
61  * @param transfer HOST transfer function.
62  * @param blockCount Block count.
63  * @retval kStatus_SDMMC_TransferFailed Transfer failed.
64  * @retval kStatus_Success Operate successfully.
65  */
66 status_t SDMMC_SetBlockCount(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t blockCount);
67 
68 /*!
69  * @brief Sets the card to be idle state.
70  *
71  * @param base HOST peripheral base address.
72  * @param transfer HOST transfer function.
73  * @retval kStatus_SDMMC_TransferFailed Transfer failed.
74  * @retval kStatus_Success Operate successfully.
75  */
76 status_t SDMMC_GoIdle(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer);
77 
78 /*!
79  * @brief Sets data block size.
80  *
81  * @param base HOST peripheral base address.
82  * @param transfer HOST transfer function.
83  * @param blockSize Block size.
84  * @retval kStatus_SDMMC_TransferFailed Transfer failed.
85  * @retval kStatus_Success Operate successfully.
86  */
87 status_t SDMMC_SetBlockSize(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t blockSize);
88 
89 /*!
90  * @brief Sets card to inactive status
91  *
92  * @param base HOST peripheral base address.
93  * @param transfer HOST transfer function.
94  * @retval kStatus_SDMMC_TransferFailed Transfer failed.
95  * @retval kStatus_Success Operate successfully.
96  */
97 status_t SDMMC_SetCardInactive(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer);
98 
99 /*!
100  * @brief provide a simple delay function for sdmmc
101  *
102  * @param num Delay num*10000.
103  */
104 void SDMMC_Delay(uint32_t num);
105 
106 /*!
107  * @brief provide a voltage switch function for SD/SDIO card
108  *
109  * @param base HOST peripheral base address.
110  * @param transfer HOST transfer function.
111  */
112 status_t SDMMC_SwitchVoltage(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer);
113 
114 /*!
115  * @brief excute tuning
116  *
117  * @param base HOST peripheral base address.
118  * @param transfer Host transfer function
119  * @param tuningCmd Tuning cmd
120  * @param blockSize Tuning block size
121  */
122 status_t SDMMC_ExecuteTuning(HOST_TYPE *base, HOST_TRANSFER_FUNCTION transfer, uint32_t tuningCmd, uint32_t blockSize);
123 
124 #if defined(__cplusplus)
125 }
126 #endif
127 
128 #endif /* _FSL_SDMMC_H_ */
129