1 /** 2 * @file hal_sdhost.h 3 * @author ALLWINNERTECH IOT WLAN Team 4 */ 5 6 /* 7 * Copyright (C) 2017 ALLWINNERTECH TECHNOLOGY CO., LTD. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the 17 * distribution. 18 * 3. Neither the name of ALLWINNERTECH TECHNOLOGY CO., LTD. nor the names of 19 * its contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef _DRIVER_CHIP_SDMMC_HAL_SDHOST_H_ 36 #define _DRIVER_CHIP_SDMMC_HAL_SDHOST_H_ 37 38 //#include "driver/chip/hal_def.h" 39 #include "hal/hal_gpio.h" 40 #include <stddef.h> 41 #include <stdint.h> 42 #include <kconfig.h> 43 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 typedef enum { 50 SDC0 = 0, /*!< SDC0 controller */ 51 SDC1 = 1, /*!< SDC1 controller */ 52 SDC_NUM /*!< only support 2 SD controller. */ 53 } SDC_Port; 54 55 typedef enum { 56 SDCGPIO_BAS = 0, 57 SDCGPIO_DET = 1, 58 } HAL_SDCGPIOType; 59 60 typedef struct { 61 uint8_t data_bits; 62 int8_t has_detect_gpio; 63 GPIO_Port detect_port; 64 GPIO_Pin detect_pin; 65 uint16_t detect_delay; /* delay interval (in ms) to wait power stable */ 66 GPIO_PinState detect_pin_present_val; 67 } HAL_SDCGPIOCfg; 68 69 /** @bried Detect card callback if used CONFIG_DETECT_CARD. */ 70 typedef void (*card_detect_cb)(uint32_t present); 71 72 /** @bried SDC Init Structure definition. */ 73 typedef struct { 74 uint16_t debug_mask; 75 uint8_t low_speed; 76 uint8_t dma_use; 77 uint32_t pwr_mode; 78 #ifdef CONFIG_DETECT_CARD 79 uint32_t cd_mode; 80 /* NOTE: The specification advise that CARD_DETECT_BY_D3 is not a preferred 81 * mechanism for card detection. Moreover it won't work with MMC cards. 82 * And, this won't work with external pull-up resistors on the card interface. 83 * The preferred card detection mechanism is a mechanical switch on the card connector. 84 */ 85 #define CARD_DETECT_BY_GPIO_IRQ (2) /* mmc detected by gpio irq */ 86 #define CARD_ALWAYS_PRESENT (3) /* mmc always present, without detect pin */ 87 #define CARD_DETECT_BY_FS (4) /* mmc insert/remove by fs */ 88 #define CARD_DETECT_BY_D3 (5) /* mmc detected by data3 */ 89 90 card_detect_cb cd_cb; /* NOTE: should delay 500ms before rescan card to wait Voltage stable */ 91 #endif 92 } SDC_InitTypeDef; 93 94 /** 95 * @brief Initializes the SDC peripheral. 96 * @param sdc_id: 97 * @arg sdc_id->SDC ID. 98 * @param param: 99 * @arg param->[in] The configuration information. 100 * @retval SDC handler. 101 */ 102 extern struct mmc_host *hal_sdc_init(struct mmc_host *host); 103 104 /** 105 * @brief DeInitializes the SDC peripheral. 106 * @param sdc_id: 107 * @arg sdc_id-> SDC ID. 108 * @retval None. 109 */ 110 extern int32_t hal_sdc_deinit(uint32_t sdc_id); 111 112 extern struct mmc_host *hal_sdc_create(uint32_t sdc_id, SDC_InitTypeDef *param); 113 extern int32_t hal_sdc_destroy(struct mmc_host *host); 114 115 extern struct mmc_host *hal_sdc_open(uint32_t sdc_id); 116 extern uint32_t hal_sdc_close(uint32_t sdc_id); 117 extern void hal_sdc_set_high_speed(struct mmc_host *host); 118 119 extern int hal_sdc_init_timeout(void); 120 121 #ifdef __cplusplus 122 } 123 #endif 124 125 #endif /* _DRIVER_CHIP_SDMMC_HAL_SDHOST_H_ */ 126