drv_sdio.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (c) 2020-2021, Bluetrum Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-11-30 greedyhao first version
  9. */
  10. #ifndef DEV_SDIO_H__
  11. #define DEV_SDIO_H__
  12. #include "drv_common.h"
  13. #include "board.h"
  14. #include "drivers/dev_mmcsd_core.h"
  15. #include "drivers/dev_sdio.h"
  16. #define SDIO_BUFF_SIZE 1024
  17. #define SDIO_ALIGN_LEN 32
  18. #ifndef SDIO_BASE_ADDRESS
  19. #define SDIO_BASE_ADDRESS (0x40012800U)
  20. #endif
  21. #ifndef SDIO_CLOCK_FREQ
  22. #define SDIO_CLOCK_FREQ (48U * 1000 * 1000)
  23. #endif
  24. #ifndef SDIO_BUFF_SIZE
  25. #define SDIO_BUFF_SIZE (4096)
  26. #endif
  27. #ifndef SDIO_ALIGN_LEN
  28. #define SDIO_ALIGN_LEN (32)
  29. #endif
  30. #ifndef SDIO_MAX_FREQ
  31. #define SDIO_MAX_FREQ (24 * 1000 * 1000)
  32. #endif
  33. #define HW_SDIO_CON_
  34. #define HW_SDIO_CON_CFLAG (0x01u << 12) /*!< 0:send command or received response not finish \
  35. 1:send command or received response finish */
  36. #define HW_SDIO_CON_DFLAG (0x01u << 13) /*!< 0:send or received data not finish \
  37. 1:send or received data finish */
  38. #define HW_SDIO_CON_CCRCE (0x01u << 14) /*!< 0:command crc no error \
  39. 1:command crc error detected */
  40. #define HW_SDIO_CON_NRPS (0x01u << 15) /*!< 0:response received 1:no response received */
  41. #define HW_SDIO_CON_DCRCE (0x01u << 16) /*!< 0:read data crc no error \
  42. 1:read data crc error detected */
  43. #define HW_SDIO_CON_CRCS (0x07u << 17) /*!< 101:error transmission \
  44. 010:non-erroneous transmission \
  45. 111:flash error */
  46. #define HW_SDIO_CON_BUSY (0x01u << 20) /*!< 0:device busy 1:device not busy */
  47. #define HW_SDIO_ERRORS \
  48. (0)
  49. #define HW_SDIO_POWER_OFF (0x00U)
  50. #define HW_SDIO_POWER_UP (0x02U)
  51. #define HW_SDIO_POWER_ON (0x03U)
  52. #define HW_SDIO_FLOW_ENABLE (0x01U << 14)
  53. #define HW_SDIO_BUSWIDE_1B (0x00U << 11)
  54. #define HW_SDIO_BUSWIDE_4B (0x01U << 11)
  55. #define HW_SDIO_BUSWIDE_8B (0x02U << 11)
  56. #define HW_SDIO_BYPASS_ENABLE (0x01U << 10)
  57. #define HW_SDIO_IDLE_ENABLE (0x01U << 9)
  58. #define HW_SDIO_CLK_ENABLE (0x01U << 8)
  59. #define HW_SDIO_SUSPEND_CMD (0x01U << 11)
  60. #define HW_SDIO_CPSM_ENABLE (0x01U << 10)
  61. #define HW_SDIO_WAIT_END (0x01U << 9)
  62. #define HW_SDIO_WAIT_INT (0x01U << 8)
  63. #define HW_SDIO_RESPONSE_NO (0x00U << 6)
  64. #define HW_SDIO_RESPONSE_SHORT (0x01U << 6)
  65. #define HW_SDIO_RESPONSE_LONG (0x03U << 6)
  66. #define HW_SDIO_DATA_LEN_MASK (0x01FFFFFFU)
  67. #define HW_SDIO_IO_ENABLE (0x01U << 11)
  68. #define HW_SDIO_RWMOD_CK (0x01U << 10)
  69. #define HW_SDIO_RWSTOP_ENABLE (0x01U << 9)
  70. #define HW_SDIO_RWSTART_ENABLE (0x01U << 8)
  71. #define HW_SDIO_DBLOCKSIZE_1 (0x00U << 4)
  72. #define HW_SDIO_DBLOCKSIZE_2 (0x01U << 4)
  73. #define HW_SDIO_DBLOCKSIZE_4 (0x02U << 4)
  74. #define HW_SDIO_DBLOCKSIZE_8 (0x03U << 4)
  75. #define HW_SDIO_DBLOCKSIZE_16 (0x04U << 4)
  76. #define HW_SDIO_DBLOCKSIZE_32 (0x05U << 4)
  77. #define HW_SDIO_DBLOCKSIZE_64 (0x06U << 4)
  78. #define HW_SDIO_DBLOCKSIZE_128 (0x07U << 4)
  79. #define HW_SDIO_DBLOCKSIZE_256 (0x08U << 4)
  80. #define HW_SDIO_DBLOCKSIZE_512 (0x09U << 4)
  81. #define HW_SDIO_DBLOCKSIZE_1024 (0x0AU << 4)
  82. #define HW_SDIO_DBLOCKSIZE_2048 (0x0BU << 4)
  83. #define HW_SDIO_DBLOCKSIZE_4096 (0x0CU << 4)
  84. #define HW_SDIO_DBLOCKSIZE_8192 (0x0DU << 4)
  85. #define HW_SDIO_DBLOCKSIZE_16384 (0x0EU << 4)
  86. #define HW_SDIO_DMA_ENABLE (0x01U << 3)
  87. #define HW_SDIO_STREAM_ENABLE (0x01U << 2)
  88. #define HW_SDIO_TO_HOST (0x01U << 1)
  89. #define HW_SDIO_DPSM_ENABLE (0x01U << 0)
  90. #define HW_SDIO_DATATIMEOUT (0xF0000000U)
  91. // struct ab32_sdio
  92. // {};
  93. typedef rt_err_t (*dma_txconfig)(rt_uint32_t *src, int size);
  94. typedef rt_err_t (*dma_rxconfig)(rt_uint32_t *dst, int size);
  95. typedef rt_uint32_t (*sdio_clk_get)(hal_sfr_t hw_sdio);
  96. struct ab32_sdio_des
  97. {
  98. hal_sfr_t hw_sdio;
  99. dma_txconfig txconfig;
  100. dma_rxconfig rxconfig;
  101. sdio_clk_get clk_get;
  102. };
  103. struct ab32_sdio_config
  104. {
  105. hal_sfr_t instance;
  106. // struct dma_config dma_rx, dma_tx;
  107. };
  108. struct ab32_sdio_class
  109. {
  110. const struct ab32_sdio_config *cfg;
  111. struct rt_mmcsd_host host;
  112. };
  113. #endif