1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __WM_SDIO_HOST_H_ 17 #define __WM_SDIO_HOST_H_ 18 19 #include <core_804.h> 20 #include "wm_regs.h" 21 22 typedef struct { 23 __IOM uint32_t MMC_CTL; 24 __IOM uint32_t MMC_IO; 25 __IOM uint32_t MMC_BYTECNTL; 26 __IM uint32_t MMC_TR_BLOCKCNT; 27 __IOM uint32_t MMC_CRCCTL; /*!< Offset: 0x010 */ 28 __IM uint32_t CMD_CRC; 29 __IM uint32_t DAT_CRCL; 30 __IM uint32_t DAT_CRCH; 31 __IOM uint32_t MMC_PORT; /*!< Offset: 0x020 */ 32 __IOM uint32_t MMC_INT_MASK; 33 __IOM uint32_t MMC_INT_SRC; 34 __IOM uint32_t MMC_CARDSEL; 35 __IM uint32_t MMC_SIG; /*!< Offset: 0x030 */ 36 __IOM uint32_t MMC_IO_MBCTL; 37 __IOM uint32_t MMC_BLOCKCNT; 38 __IOM uint32_t MMC_TIMEOUTCNT; 39 __IOM uint32_t CMD_BUF[16]; /*!< Offset: 0x040 */ 40 __IOM uint32_t BUF_CTL; /*!< Offset: 0x080 */ 41 uint32_t RESERVED3[31U]; 42 __IOM uint32_t DATA_BUF[128]; /*!< Offset: 0x100 */ 43 }SDIO_HOST_Type; 44 45 #define SDIO_HOST ((SDIO_HOST_Type *)HR_SDIO_HOST_BASE_ADDR) 46 47 typedef struct { 48 long long CardCapacity; 49 u32 CardBlockSize; 50 u16 RCA; 51 u8 CardType; 52 } SD_CardInfo_t; 53 extern SD_CardInfo_t SDCardInfo; 54 /** 55 * @defgroup Driver_APIs Driver APIs 56 * @brief Driver APIs 57 */ 58 59 /** 60 * @addtogroup Driver_APIs 61 * @{ 62 */ 63 64 /** 65 * @defgroup SDIOH_Driver_APIs SDIO HOST Driver APIs 66 * @brief SDIO HOST driver APIs 67 */ 68 69 /** 70 * @addtogroup SDIOH_Driver_APIs 71 * @{ 72 */ 73 74 /** 75 * @brief This function is used to initial the sd host module . 76 * 77 * @param[out] rca_ref Pointer to the rca reference 78 * 79 * @retval status 0 if succeed, otherwise fail 80 * 81 * @note None 82 */ 83 int sdh_card_init(uint32_t *rca_ref); 84 85 /** 86 * @brief This function is used to set the width of bus . 87 * 88 * @param[in] rca the rca reference 89 * @param[in] bus_width: 0:1bit; 2:4bits 90 * 91 * @retval status 0 if succeed, otherwise fail 92 * 93 * @note None 94 */ 95 int wm_sd_card_set_bus_width(uint32_t rca, uint8_t bus_width); 96 97 /** 98 * @brief This function is used to read one block data from the sd card with irq mode . 99 * 100 * @param[in] sd_addr address that to be read from 101 * @param[in] buf Pointer to the buffer that the data shall be read into 102 * 103 * @retval status 0 if succeed, otherwise fail 104 * 105 * @note None 106 */ 107 int wm_sd_card_block_read(uint32_t rca, uint32_t sd_addr, char *buf); 108 109 /** 110 * @brief This function is used to write one block data into the sd card with irq mode . 111 * 112 * @param[in] sd_addr address that to be written to 113 * @param[in] buf Pointer to the buffer that holding the data to be written 114 * 115 * @retval status 0 if succeed, otherwise fail 116 * 117 * @note None 118 */ 119 int wm_sd_card_block_write(uint32_t rca, uint32_t sd_addr, char *buf); 120 121 /** 122 * @brief This function is used to read blocks of data from the sd card with dma mode . 123 * 124 * @param[in] sd_addr address that to be read from 125 * @param[in] buf Pointer to the buffer that the data shall be read into 126 * @param[in] buflen buffer size, should be integer multiple of 512 127 * 128 * @retval status 0 if succeed, otherwise fail 129 * 130 * @note None 131 */ 132 int wm_sd_card_blocks_read(uint32_t rca, uint32_t sd_addr, char *buf, uint32_t buflen); 133 134 /** 135 * @brief This function is used to write blocks of data into the sd card with dma mode . 136 * 137 * @param[in] sd_addr address that to be written to 138 * @param[in] buf Pointer to the buffer that holding the data to be written 139 * @param[in] buflen buffer size, should be integer multiple of 512 140 * 141 * @retval status 0 if succeed, otherwise fail 142 * 143 * @note None 144 */ 145 int wm_sd_card_blocks_write(uint32_t rca, uint32_t sd_addr, char *buf, uint32_t buflen); 146 147 /** 148 * @} 149 */ 150 151 /** 152 * @} 153 */ 154 155 #endif // __WM_SDIO_HOST_H_ 156 157