mmcsd_card.h 5.5 KB

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