drv_sdio.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-23 liuduanfei first version
  9. * 2020-08-25 wanghaijing add sdmmmc2
  10. */
  11. #ifndef __DRV_SDIO_H__
  12. #define __DRV_SDIO_H__
  13. #include <rtthread.h>
  14. #include "rtdevice.h"
  15. #include <rthw.h>
  16. #include <drv_common.h>
  17. #include <string.h>
  18. #include <drivers/mmcsd_core.h>
  19. #include <drivers/sdio.h>
  20. #define SDIO_BUFF_SIZE 4096
  21. #define SDIO_ALIGN_LEN 32
  22. #ifndef SDIO1_BASE_ADDRESS
  23. #define SDIO1_BASE_ADDRESS (0x52007000)
  24. #endif
  25. #ifndef SDIO2_BASE_ADDRESS
  26. #define SDIO2_BASE_ADDRESS (0x48022400)
  27. #endif
  28. #ifndef SDIO_CLOCK_FREQ
  29. #define SDIO_CLOCK_FREQ (200U * 1000 * 1000)
  30. #endif
  31. #ifndef SDIO_BUFF_SIZE
  32. #define SDIO_BUFF_SIZE (4096)
  33. #endif
  34. #ifndef SDIO_ALIGN_LEN
  35. #define SDIO_ALIGN_LEN (32)
  36. #endif
  37. #ifndef SDIO_MAX_FREQ
  38. #define SDIO_MAX_FREQ (25 * 1000 * 1000)
  39. #endif
  40. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  41. #define SDIO_ERRORS \
  42. (SDMMC_STA_IDMATE | SDMMC_STA_ACKTIMEOUT | \
  43. SDMMC_STA_RXOVERR | SDMMC_STA_TXUNDERR | \
  44. SDMMC_STA_DTIMEOUT | SDMMC_STA_CTIMEOUT | \
  45. SDMMC_STA_DCRCFAIL | SDMMC_STA_CCRCFAIL)
  46. #define SDIO_MASKR_ALL \
  47. (SDMMC_MASK_CCRCFAILIE | SDMMC_MASK_DCRCFAILIE | SDMMC_MASK_CTIMEOUTIE | \
  48. SDMMC_MASK_TXUNDERRIE | SDMMC_MASK_RXOVERRIE | SDMMC_MASK_CMDRENDIE | \
  49. SDMMC_MASK_CMDSENTIE | SDMMC_MASK_DATAENDIE | SDMMC_MASK_ACKTIMEOUTIE)
  50. #define HW_SDIO_DATATIMEOUT (0xFFFFFFFFU)
  51. struct stm32_sdio
  52. {
  53. volatile rt_uint32_t power; /* offset 0x00 */
  54. volatile rt_uint32_t clkcr; /* offset 0x04 */
  55. volatile rt_uint32_t arg; /* offset 0x08 */
  56. volatile rt_uint32_t cmd; /* offset 0x0C */
  57. volatile rt_uint32_t respcmd; /* offset 0x10 */
  58. volatile rt_uint32_t resp1; /* offset 0x14 */
  59. volatile rt_uint32_t resp2; /* offset 0x18 */
  60. volatile rt_uint32_t resp3; /* offset 0x1C */
  61. volatile rt_uint32_t resp4; /* offset 0x20 */
  62. volatile rt_uint32_t dtimer; /* offset 0x24 */
  63. volatile rt_uint32_t dlen; /* offset 0x28 */
  64. volatile rt_uint32_t dctrl; /* offset 0x2C */
  65. volatile rt_uint32_t dcount; /* offset 0x30 */
  66. volatile rt_uint32_t sta; /* offset 0x34 */
  67. volatile rt_uint32_t icr; /* offset 0x38 */
  68. volatile rt_uint32_t mask; /* offset 0x3C */
  69. volatile rt_uint32_t acktimer; /* offset 0x40 */
  70. volatile rt_uint32_t reserved0[3]; /* offset 0x44 ~ 0x4C */
  71. volatile rt_uint32_t idmatrlr; /* offset 0x50 */
  72. volatile rt_uint32_t idmabsizer; /* offset 0x54 */
  73. volatile rt_uint32_t idmabase0r; /* offset 0x58 */
  74. volatile rt_uint32_t idmabase1r; /* offset 0x5C */
  75. volatile rt_uint32_t reserved1[8]; /* offset 0x60 ~ 7C */
  76. volatile rt_uint32_t fifo; /* offset 0x80 */
  77. };
  78. typedef rt_uint32_t (*sdio_clk_get)(struct stm32_sdio *hw_sdio);
  79. struct stm32_sdio_des
  80. {
  81. struct stm32_sdio *hw_sdio;
  82. sdio_clk_get clk_get;
  83. SD_HandleTypeDef hsd;
  84. };
  85. /* stm32 sdio dirver class */
  86. struct stm32_sdio_class
  87. {
  88. struct stm32_sdio_des *des;
  89. const struct stm32_sdio_config *cfg;
  90. struct rt_mmcsd_host host;
  91. };
  92. extern void sdcard_change(void);
  93. #endif /* __DRV_SDIO_H__ */