mmcsd_host.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-07-25 weety first version
  9. */
  10. #ifndef __HOST_H__
  11. #define __HOST_H__
  12. #include <rtthread.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. struct rt_mmcsd_io_cfg
  17. {
  18. rt_uint32_t clock; /* clock rate */
  19. rt_uint16_t vdd;
  20. /* vdd stores the bit number of the selected voltage range from below. */
  21. rt_uint8_t bus_mode; /* command output mode */
  22. #define MMCSD_BUSMODE_OPENDRAIN 1
  23. #define MMCSD_BUSMODE_PUSHPULL 2
  24. rt_uint8_t chip_select; /* SPI chip select */
  25. #define MMCSD_CS_IGNORE 0
  26. #define MMCSD_CS_HIGH 1
  27. #define MMCSD_CS_LOW 2
  28. rt_uint8_t power_mode; /* power supply mode */
  29. #define MMCSD_POWER_OFF 0
  30. #define MMCSD_POWER_UP 1
  31. #define MMCSD_POWER_ON 2
  32. rt_uint8_t bus_width; /* data bus width */
  33. #define MMCSD_BUS_WIDTH_1 0
  34. #define MMCSD_BUS_WIDTH_4 2
  35. #define MMCSD_BUS_WIDTH_8 3
  36. unsigned char timing; /* timing specification used */
  37. #define MMCSD_TIMING_LEGACY 0
  38. #define MMCSD_TIMING_MMC_HS 1
  39. #define MMCSD_TIMING_SD_HS 2
  40. #define MMCSD_TIMING_UHS_SDR12 3
  41. #define MMCSD_TIMING_UHS_SDR25 4
  42. #define MMCSD_TIMING_UHS_SDR50 5
  43. #define MMCSD_TIMING_UHS_SDR104 6
  44. #define MMCSD_TIMING_UHS_DDR50 7
  45. #define MMCSD_TIMING_MMC_DDR52 8
  46. #define MMCSD_TIMING_MMC_HS200 9
  47. #define MMCSD_TIMING_MMC_HS400 10
  48. unsigned char drv_type; /* driver type (A, B, C, D) */
  49. #define MMCSD_SET_DRIVER_TYPE_B 0
  50. #define MMCSD_SET_DRIVER_TYPE_A 1
  51. #define MMCSD_SET_DRIVER_TYPE_C 2
  52. #define MMCSD_SET_DRIVER_TYPE_D 3
  53. unsigned char signal_voltage;
  54. #define MMCSD_SIGNAL_VOLTAGE_330 0
  55. #define MMCSD_SIGNAL_VOLTAGE_180 1
  56. #define MMCSD_SIGNAL_VOLTAGE_120 2
  57. };
  58. struct rt_mmcsd_host;
  59. struct rt_mmcsd_req;
  60. struct rt_mmcsd_host_ops
  61. {
  62. void (*request)(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req);
  63. void (*set_iocfg)(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg);
  64. rt_int32_t (*get_card_status)(struct rt_mmcsd_host *host);
  65. void (*enable_sdio_irq)(struct rt_mmcsd_host *host, rt_int32_t en);
  66. rt_int32_t (*execute_tuning)(struct rt_mmcsd_host *host, rt_int32_t opcode);
  67. };
  68. struct rt_mmcsd_host
  69. {
  70. char name[RT_NAME_MAX];
  71. struct rt_mmcsd_card *card;
  72. const struct rt_mmcsd_host_ops *ops;
  73. rt_uint32_t freq_min;
  74. rt_uint32_t freq_max;
  75. struct rt_mmcsd_io_cfg io_cfg;
  76. rt_uint32_t valid_ocr; /* current valid OCR */
  77. #define VDD_165_195 (1 << 7) /* VDD voltage 1.65 - 1.95 */
  78. #define VDD_20_21 (1 << 8) /* VDD voltage 2.0 ~ 2.1 */
  79. #define VDD_21_22 (1 << 9) /* VDD voltage 2.1 ~ 2.2 */
  80. #define VDD_22_23 (1 << 10) /* VDD voltage 2.2 ~ 2.3 */
  81. #define VDD_23_24 (1 << 11) /* VDD voltage 2.3 ~ 2.4 */
  82. #define VDD_24_25 (1 << 12) /* VDD voltage 2.4 ~ 2.5 */
  83. #define VDD_25_26 (1 << 13) /* VDD voltage 2.5 ~ 2.6 */
  84. #define VDD_26_27 (1 << 14) /* VDD voltage 2.6 ~ 2.7 */
  85. #define VDD_27_28 (1 << 15) /* VDD voltage 2.7 ~ 2.8 */
  86. #define VDD_28_29 (1 << 16) /* VDD voltage 2.8 ~ 2.9 */
  87. #define VDD_29_30 (1 << 17) /* VDD voltage 2.9 ~ 3.0 */
  88. #define VDD_30_31 (1 << 18) /* VDD voltage 3.0 ~ 3.1 */
  89. #define VDD_31_32 (1 << 19) /* VDD voltage 3.1 ~ 3.2 */
  90. #define VDD_32_33 (1 << 20) /* VDD voltage 3.2 ~ 3.3 */
  91. #define VDD_33_34 (1 << 21) /* VDD voltage 3.3 ~ 3.4 */
  92. #define VDD_34_35 (1 << 22) /* VDD voltage 3.4 ~ 3.5 */
  93. #define VDD_35_36 (1 << 23) /* VDD voltage 3.5 ~ 3.6 */
  94. rt_uint32_t flags; /* define device capabilities */
  95. #define MMCSD_BUSWIDTH_4 (1 << 0)
  96. #define MMCSD_BUSWIDTH_8 (1 << 1)
  97. #define MMCSD_MUTBLKWRITE (1 << 2)
  98. #define MMCSD_HOST_IS_SPI (1 << 3)
  99. #define controller_is_spi(host) (host->flags & MMCSD_HOST_IS_SPI)
  100. #define MMCSD_SUP_SDIO_IRQ (1 << 4) /* support signal pending SDIO IRQs */
  101. #define MMCSD_SUP_HIGHSPEED (1 << 5) /* support high speed SDR*/
  102. #define MMCSD_SUP_DDR_3V3 (1 << 6)
  103. #define MMCSD_SUP_DDR_1V8 (1 << 7)
  104. #define MMCSD_SUP_DDR_1V2 (1 << 8)
  105. #define MMCSD_SUP_HIGHSPEED_DDR (MMCSD_SUP_DDR_3V3 | MMCSD_SUP_DDR_1V8 | MMCSD_SUP_DDR_1V2)/* HIGH SPEED DDR*/
  106. #define MMCSD_SUP_HS200_1V8 (1 << 9)
  107. #define MMCSD_SUP_HS200_1V2 (1 << 10)
  108. #define MMCSD_SUP_HS200 (MMCSD_SUP_HS200_1V2 | MMCSD_SUP_HS200_1V8) /* hs200 sdr */
  109. #define MMCSD_SUP_NONREMOVABLE (1 << 11)
  110. rt_uint32_t max_seg_size; /* maximum size of one dma segment */
  111. rt_uint32_t max_dma_segs; /* maximum number of dma segments in one request */
  112. rt_uint32_t max_blk_size; /* maximum block size */
  113. rt_uint32_t max_blk_count; /* maximum block count */
  114. rt_uint32_t id; /* Assigned host id */
  115. rt_uint32_t spi_use_crc;
  116. struct rt_mutex bus_lock;
  117. struct rt_semaphore sem_ack;
  118. rt_uint32_t sdio_irq_num;
  119. struct rt_semaphore *sdio_irq_sem;
  120. struct rt_thread *sdio_irq_thread;
  121. void *private_data;
  122. };
  123. #ifdef __cplusplus
  124. }
  125. #endif
  126. #endif