hal_sdhost.h 4.4 KB

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