mmcsd_card.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) 2006-2018, 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 __MMCSD_CARD_H__
  11. #define __MMCSD_CARD_H__
  12. #include <drivers/mmcsd_host.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #define SD_SCR_BUS_WIDTH_1 (1 << 0)
  17. #define SD_SCR_BUS_WIDTH_4 (1 << 2)
  18. struct rt_mmcsd_cid {
  19. rt_uint8_t mid; /* ManufacturerID */
  20. rt_uint8_t prv; /* Product Revision */
  21. rt_uint16_t oid; /* OEM/Application ID */
  22. rt_uint32_t psn; /* Product Serial Number */
  23. rt_uint8_t pnm[5]; /* Product Name */
  24. rt_uint8_t reserved1;/* reserved */
  25. rt_uint16_t mdt; /* Manufacturing Date */
  26. rt_uint8_t crc; /* CID CRC */
  27. rt_uint8_t reserved2;/* not used, always 1 */
  28. };
  29. struct rt_mmcsd_csd {
  30. rt_uint8_t csd_structure; /* CSD register version */
  31. rt_uint8_t taac;
  32. rt_uint8_t nsac;
  33. rt_uint8_t tran_speed; /* max data transfer rate */
  34. rt_uint16_t card_cmd_class; /* card command classes */
  35. rt_uint8_t rd_blk_len; /* max read data block length */
  36. rt_uint8_t rd_blk_part;
  37. rt_uint8_t wr_blk_misalign;
  38. rt_uint8_t rd_blk_misalign;
  39. rt_uint8_t dsr_imp; /* DSR implemented */
  40. rt_uint8_t c_size_mult; /* CSD 1.0 , device size multiplier */
  41. rt_uint32_t c_size; /* device size */
  42. rt_uint8_t r2w_factor;
  43. rt_uint8_t wr_blk_len; /* max wtire data block length */
  44. rt_uint8_t wr_blk_partial;
  45. rt_uint8_t csd_crc;
  46. };
  47. struct rt_sd_scr {
  48. rt_uint8_t sd_version;
  49. rt_uint8_t sd_bus_widths;
  50. };
  51. struct rt_sdio_cccr {
  52. rt_uint8_t sdio_version;
  53. rt_uint8_t sd_version;
  54. rt_uint8_t direct_cmd:1, /* Card Supports Direct Commands during data transfer
  55. only SD mode, not used for SPI mode */
  56. multi_block:1, /* Card Supports Multi-Block */
  57. read_wait:1, /* Card Supports Read Wait
  58. only SD mode, not used for SPI mode */
  59. suspend_resume:1, /* Card supports Suspend/Resume
  60. only SD mode, not used for SPI mode */
  61. s4mi:1, /* generate interrupts during a 4-bit
  62. multi-block data transfer */
  63. e4mi:1, /* Enable the multi-block IRQ during
  64. 4-bit transfer for the SDIO card */
  65. low_speed:1, /* Card is a Low-Speed card */
  66. low_speed_4:1; /* 4-bit support for Low-Speed cards */
  67. rt_uint8_t bus_width:1, /* Support SDIO bus width, 1:4bit, 0:1bit */
  68. cd_disable:1, /* Connect[0]/Disconnect[1] the 10K-90K ohm pull-up
  69. resistor on CD/DAT[3] (pin 1) of the card */
  70. power_ctrl:1, /* Support Master Power Control */
  71. high_speed:1; /* Support High-Speed */
  72. };
  73. struct rt_sdio_cis {
  74. rt_uint16_t manufacturer;
  75. rt_uint16_t product;
  76. rt_uint16_t func0_blk_size;
  77. rt_uint32_t max_tran_speed;
  78. };
  79. /*
  80. * SDIO function CIS tuple (unknown to the core)
  81. */
  82. struct rt_sdio_function_tuple {
  83. struct rt_sdio_function_tuple *next;
  84. rt_uint8_t code;
  85. rt_uint8_t size;
  86. rt_uint8_t *data;
  87. };
  88. struct rt_sdio_function;
  89. typedef void (rt_sdio_irq_handler_t)(struct rt_sdio_function *);
  90. /*
  91. * SDIO function devices
  92. */
  93. struct rt_sdio_function {
  94. struct rt_mmcsd_card *card; /* the card this device belongs to */
  95. rt_sdio_irq_handler_t *irq_handler; /* IRQ callback */
  96. rt_uint8_t num; /* function number */
  97. rt_uint8_t func_code; /* Standard SDIO Function interface code */
  98. rt_uint16_t manufacturer; /* manufacturer id */
  99. rt_uint16_t product; /* product id */
  100. rt_uint32_t max_blk_size; /* maximum block size */
  101. rt_uint32_t cur_blk_size; /* current block size */
  102. rt_uint32_t enable_timeout_val; /* max enable timeout in msec */
  103. struct rt_sdio_function_tuple *tuples;
  104. void *priv;
  105. };
  106. #define SDIO_MAX_FUNCTIONS 7
  107. struct rt_mmcsd_card {
  108. struct rt_mmcsd_host *host;
  109. rt_uint32_t rca; /* card addr */
  110. rt_uint32_t resp_cid[4]; /* card CID register */
  111. rt_uint32_t resp_csd[4]; /* card CSD register */
  112. rt_uint32_t resp_scr[2]; /* card SCR register */
  113. rt_uint16_t tacc_clks; /* data access time by ns */
  114. rt_uint32_t tacc_ns; /* data access time by clk cycles */
  115. rt_uint32_t max_data_rate; /* max data transfer rate */
  116. rt_uint32_t card_capacity; /* card capacity, unit:KB */
  117. rt_uint32_t card_blksize; /* card block size */
  118. rt_uint32_t erase_size; /* erase size in sectors */
  119. rt_uint16_t card_type;
  120. #define CARD_TYPE_MMC 0 /* MMC card */
  121. #define CARD_TYPE_SD 1 /* SD card */
  122. #define CARD_TYPE_SDIO 2 /* SDIO card */
  123. #define CARD_TYPE_SDIO_COMBO 3 /* SD combo (IO+mem) card */
  124. rt_uint16_t flags;
  125. #define CARD_FLAG_HIGHSPEED (1 << 0) /* SDIO bus speed 50MHz */
  126. #define CARD_FLAG_SDHC (1 << 1) /* SDHC card */
  127. #define CARD_FLAG_SDXC (1 << 2) /* SDXC card */
  128. struct rt_sd_scr scr;
  129. struct rt_mmcsd_csd csd;
  130. rt_uint32_t hs_max_data_rate; /* max data transfer rate in high speed mode */
  131. rt_uint8_t sdio_function_num; /* totol number of SDIO functions */
  132. struct rt_sdio_cccr cccr; /* common card info */
  133. struct rt_sdio_cis cis; /* common tuple info */
  134. struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */
  135. };
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif