mmcsd_card.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * File : mmcsd_card.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2011-07-25 weety first version
  23. */
  24. #ifndef __MMCSD_CARD_H__
  25. #define __MMCSD_CARD_H__
  26. #include <drivers/mmcsd_host.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #define SD_SCR_BUS_WIDTH_1 (1 << 0)
  31. #define SD_SCR_BUS_WIDTH_4 (1 << 2)
  32. struct rt_mmcsd_cid {
  33. rt_uint8_t mid; /* ManufacturerID */
  34. rt_uint8_t prv; /* Product Revision */
  35. rt_uint16_t oid; /* OEM/Application ID */
  36. rt_uint32_t psn; /* Product Serial Number */
  37. rt_uint8_t pnm[5]; /* Product Name */
  38. rt_uint8_t reserved1;/* reserved */
  39. rt_uint16_t mdt; /* Manufacturing Date */
  40. rt_uint8_t crc; /* CID CRC */
  41. rt_uint8_t reserved2;/* not used, always 1 */
  42. };
  43. struct rt_mmcsd_csd {
  44. rt_uint8_t csd_structure; /* CSD register version */
  45. rt_uint8_t taac;
  46. rt_uint8_t nsac;
  47. rt_uint8_t tran_speed; /* max data transfer rate */
  48. rt_uint16_t card_cmd_class; /* card command classes */
  49. rt_uint8_t rd_blk_len; /* max read data block length */
  50. rt_uint8_t rd_blk_part;
  51. rt_uint8_t wr_blk_misalign;
  52. rt_uint8_t rd_blk_misalign;
  53. rt_uint8_t dsr_imp; /* DSR implemented */
  54. rt_uint8_t c_size_mult; /* CSD 1.0 , device size multiplier */
  55. rt_uint32_t c_size; /* device size */
  56. rt_uint8_t r2w_factor;
  57. rt_uint8_t wr_blk_len; /* max wtire data block length */
  58. rt_uint8_t wr_blk_partial;
  59. rt_uint8_t csd_crc;
  60. };
  61. struct rt_sd_scr {
  62. rt_uint8_t sd_version;
  63. rt_uint8_t sd_bus_widths;
  64. };
  65. struct rt_sdio_cccr {
  66. rt_uint8_t sdio_version;
  67. rt_uint8_t sd_version;
  68. rt_uint8_t direct_cmd:1, /* Card Supports Direct Commands during data transfer
  69. only SD mode, not used for SPI mode */
  70. multi_block:1, /* Card Supports Multi-Block */
  71. read_wait:1, /* Card Supports Read Wait
  72. only SD mode, not used for SPI mode */
  73. suspend_resume:1, /* Card supports Suspend/Resume
  74. only SD mode, not used for SPI mode */
  75. s4mi:1, /* generate interrupts during a 4-bit
  76. multi-block data transfer */
  77. e4mi:1, /* Enable the multi-block IRQ during
  78. 4-bit transfer for the SDIO card */
  79. low_speed:1, /* Card is a Low-Speed card */
  80. low_speed_4:1; /* 4-bit support for Low-Speed cards */
  81. rt_uint8_t bus_width:1, /* Support SDIO bus width, 1:4bit, 0:1bit */
  82. cd_disable:1, /* Connect[0]/Disconnect[1] the 10K-90K ohm pull-up
  83. resistor on CD/DAT[3] (pin 1) of the card */
  84. power_ctrl:1, /* Support Master Power Control */
  85. high_speed:1; /* Support High-Speed */
  86. };
  87. struct rt_sdio_cis {
  88. rt_uint16_t manufacturer;
  89. rt_uint16_t product;
  90. rt_uint16_t func0_blk_size;
  91. rt_uint32_t max_tran_speed;
  92. };
  93. /*
  94. * SDIO function CIS tuple (unknown to the core)
  95. */
  96. struct rt_sdio_function_tuple {
  97. struct rt_sdio_function_tuple *next;
  98. rt_uint8_t code;
  99. rt_uint8_t size;
  100. rt_uint8_t *data;
  101. };
  102. struct rt_sdio_function;
  103. typedef void (rt_sdio_irq_handler_t)(struct rt_sdio_function *);
  104. /*
  105. * SDIO function devices
  106. */
  107. struct rt_sdio_function {
  108. struct rt_mmcsd_card *card; /* the card this device belongs to */
  109. rt_sdio_irq_handler_t *irq_handler; /* IRQ callback */
  110. rt_uint8_t num; /* function number */
  111. rt_uint8_t func_code; /* Standard SDIO Function interface code */
  112. rt_uint16_t manufacturer; /* manufacturer id */
  113. rt_uint16_t product; /* product id */
  114. rt_uint32_t max_blk_size; /* maximum block size */
  115. rt_uint32_t cur_blk_size; /* current block size */
  116. rt_uint32_t enable_timeout_val; /* max enable timeout in msec */
  117. struct rt_sdio_function_tuple *tuples;
  118. void *priv;
  119. };
  120. #define SDIO_MAX_FUNCTIONS 7
  121. struct rt_mmcsd_card {
  122. struct rt_mmcsd_host *host;
  123. rt_uint32_t rca; /* card addr */
  124. rt_uint32_t resp_cid[4]; /* card CID register */
  125. rt_uint32_t resp_csd[4]; /* card CSD register */
  126. rt_uint32_t resp_scr[2]; /* card SCR register */
  127. rt_uint16_t tacc_clks; /* data access time by ns */
  128. rt_uint32_t tacc_ns; /* data access time by clk cycles */
  129. rt_uint32_t max_data_rate; /* max data transfer rate */
  130. rt_uint32_t card_capacity; /* card capacity, unit:KB */
  131. rt_uint32_t card_blksize; /* card block size */
  132. rt_uint32_t erase_size; /* erase size in sectors */
  133. rt_uint16_t card_type;
  134. #define CARD_TYPE_MMC 0 /* MMC card */
  135. #define CARD_TYPE_SD 1 /* SD card */
  136. #define CARD_TYPE_SDIO 2 /* SDIO card */
  137. #define CARD_TYPE_SDIO_COMBO 3 /* SD combo (IO+mem) card */
  138. rt_uint16_t flags;
  139. #define CARD_FLAG_HIGHSPEED (1 << 0) /* SDIO bus speed 50MHz */
  140. #define CARD_FLAG_SDHC (1 << 1) /* SDHC card */
  141. #define CARD_FLAG_SDXC (1 << 2) /* SDXC card */
  142. struct rt_sd_scr scr;
  143. struct rt_mmcsd_csd csd;
  144. rt_uint32_t hs_max_data_rate; /* max data transfer rate in high speed mode */
  145. rt_uint8_t sdio_function_num; /* totol number of SDIO functions */
  146. struct rt_sdio_cccr cccr; /* common card info */
  147. struct rt_sdio_cis cis; /* common tuple info */
  148. struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */
  149. };
  150. #ifdef __cplusplus
  151. }
  152. #endif
  153. #endif