sdio.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #ifndef _SDIO_H
  2. #define _SDIO_H
  3. #include "FreeRTOS.h"
  4. #include "mmcsd_host.h"
  5. #include "mmcsd_card.h"
  6. #include "sdio_func_ids.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*
  11. * Card Common Control Registers (CCCR)
  12. */
  13. #define SDIO_REG_CCCR_CCCR_REV 0x00
  14. #define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */
  15. #define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */
  16. #define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */
  17. #define SDIO_CCCR_REV_3_00 3 /* CCCR/FBR Version 2.00 */
  18. #define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */
  19. #define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */
  20. #define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */
  21. #define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */
  22. #define SDIO_REG_CCCR_SD_REV 0x01
  23. #define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */
  24. #define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */
  25. #define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */
  26. #define SDIO_REG_CCCR_IO_EN 0x02
  27. #define SDIO_REG_CCCR_IO_RDY 0x03
  28. #define SDIO_REG_CCCR_INT_EN 0x04 /* Function/Master Interrupt Enable */
  29. #define SDIO_REG_CCCR_INT_PEND 0x05 /* Function Interrupt Pending */
  30. #define SDIO_REG_CCCR_IO_ABORT 0x06 /* function abort/card reset */
  31. #define SDIO_REG_CCCR_BUS_IF 0x07 /* bus interface controls */
  32. #define SDIO_BUS_WIDTH_1BIT 0x00
  33. #define SDIO_BUS_WIDTH_4BIT 0x02
  34. #define SDIO_BUS_ECSI 0x20 /* Enable continuous SPI interrupt */
  35. #define SDIO_BUS_SCSI 0x40 /* Support continuous SPI interrupt */
  36. #define SDIO_BUS_ASYNC_INT 0x20
  37. #define SDIO_BUS_CD_DISABLE 0x80 /* disable pull-up on DAT3 (pin 1) */
  38. #define SDIO_REG_CCCR_CARD_CAPS 0x08
  39. #define SDIO_CCCR_CAP_SDC 0x01 /* can do CMD52 while data transfer */
  40. #define SDIO_CCCR_CAP_SMB 0x02 /* can do multi-block xfers (CMD53) */
  41. #define SDIO_CCCR_CAP_SRW 0x04 /* supports read-wait protocol */
  42. #define SDIO_CCCR_CAP_SBS 0x08 /* supports suspend/resume */
  43. #define SDIO_CCCR_CAP_S4MI 0x10 /* interrupt during 4-bit CMD53 */
  44. #define SDIO_CCCR_CAP_E4MI 0x20 /* enable ints during 4-bit CMD53 */
  45. #define SDIO_CCCR_CAP_LSC 0x40 /* low speed card */
  46. #define SDIO_CCCR_CAP_4BLS 0x80 /* 4 bit low speed card */
  47. #define SDIO_REG_CCCR_CIS_PTR 0x09 /* common CIS pointer (3 bytes) */
  48. /* Following 4 regs are valid only if SBS is set */
  49. #define SDIO_REG_CCCR_BUS_SUSPEND 0x0c
  50. #define SDIO_REG_CCCR_FUNC_SEL 0x0d
  51. #define SDIO_REG_CCCR_EXEC_FLAG 0x0e
  52. #define SDIO_REG_CCCR_READY_FLAG 0x0f
  53. #define SDIO_REG_CCCR_FN0_BLKSIZE 0x10 /* 2bytes, 0x10~0x11 */
  54. #define SDIO_REG_CCCR_POWER_CTRL 0x12
  55. #define SDIO_POWER_SMPC 0x01 /* Supports Master Power Control */
  56. #define SDIO_POWER_EMPC 0x02 /* Enable Master Power Control */
  57. #define SDIO_REG_CCCR_SPEED 0x13
  58. #define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */
  59. #define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */
  60. /*
  61. * Function Basic Registers (FBR)
  62. */
  63. #define SDIO_REG_FBR_BASE(f) ((f) * 0x100) /* base of function f's FBRs */
  64. #define SDIO_REG_FBR_STD_FUNC_IF 0x00
  65. #define SDIO_FBR_SUPPORTS_CSA 0x40 /* supports Code Storage Area */
  66. #define SDIO_FBR_ENABLE_CSA 0x80 /* enable Code Storage Area */
  67. #define SDIO_REG_FBR_STD_IF_EXT 0x01
  68. #define SDIO_REG_FBR_POWER 0x02
  69. #define SDIO_FBR_POWER_SPS 0x01 /* Supports Power Selection */
  70. #define SDIO_FBR_POWER_EPS 0x02 /* Enable (low) Power Selection */
  71. #define SDIO_REG_FBR_CIS 0x09 /* CIS pointer (3 bytes) */
  72. #define SDIO_REG_FBR_CSA 0x0C /* CSA pointer (3 bytes) */
  73. #define SDIO_REG_FBR_CSA_DATA 0x0F
  74. #define SDIO_REG_FBR_BLKSIZE 0x10 /* block size (2 bytes) */
  75. /* SDIO CIS Tuple code */
  76. #define CISTPL_NULL 0x00
  77. #define CISTPL_CHECKSUM 0x10
  78. #define CISTPL_VERS_1 0x15
  79. #define CISTPL_ALTSTR 0x16
  80. #define CISTPL_MANFID 0x20
  81. #define CISTPL_FUNCID 0x21
  82. #define CISTPL_FUNCE 0x22
  83. #define CISTPL_SDIO_STD 0x91
  84. #define CISTPL_SDIO_EXT 0x92
  85. #define CISTPL_END 0xff
  86. /* SDIO device id */
  87. #define SDIO_ANY_FUNC_ID 0xff
  88. #define SDIO_ANY_MAN_ID 0xffff
  89. #define SDIO_ANY_PROD_ID 0xffff
  90. struct sdio_device_id
  91. {
  92. uint8_t func_code;
  93. uint16_t manufacturer;
  94. uint16_t product;
  95. };
  96. struct sdio_driver_t
  97. {
  98. char *name;
  99. int32_t (*probe)(struct mmcsd_card *card);
  100. int32_t (*remove)(struct mmcsd_card *card);
  101. struct sdio_device_id *id;
  102. };
  103. int32_t sdio_io_send_op_cond(struct mmcsd_host *host,
  104. uint32_t ocr,
  105. uint32_t *cmd5_resp);
  106. int32_t sdio_io_rw_direct(struct mmcsd_card *card,
  107. int32_t rw,
  108. uint32_t fn,
  109. uint32_t reg_addr,
  110. uint8_t *pdata,
  111. uint8_t raw);
  112. int32_t sdio_io_rw_extended(struct mmcsd_card *card,
  113. int32_t rw,
  114. uint32_t fn,
  115. uint32_t addr,
  116. int32_t op_code,
  117. uint8_t *buf,
  118. uint32_t blocks,
  119. uint32_t blksize);
  120. int32_t sdio_io_rw_extended_block(struct sdio_function *func,
  121. int32_t rw,
  122. uint32_t addr,
  123. int32_t op_code,
  124. uint8_t *buf,
  125. uint32_t len);
  126. uint8_t sdio_io_readb(struct sdio_function *func,
  127. uint32_t reg,
  128. int32_t *err);
  129. int32_t sdio_io_writeb(struct sdio_function *func,
  130. uint32_t reg,
  131. uint8_t data);
  132. uint16_t sdio_io_readw(struct sdio_function *func,
  133. uint32_t addr,
  134. int32_t *err);
  135. int32_t sdio_io_writew(struct sdio_function *func,
  136. uint16_t data,
  137. uint32_t addr);
  138. uint32_t sdio_io_readl(struct sdio_function *func,
  139. uint32_t addr,
  140. int32_t *err);
  141. int32_t sdio_io_writel(struct sdio_function *func,
  142. uint32_t data,
  143. uint32_t addr);
  144. int32_t sdio_io_read_multi_fifo_b(struct sdio_function *func,
  145. uint32_t addr,
  146. uint8_t *buf,
  147. uint32_t len);
  148. int32_t sdio_io_write_multi_fifo_b(struct sdio_function *func,
  149. uint32_t addr,
  150. uint8_t *buf,
  151. uint32_t len);
  152. int32_t sdio_io_read_multi_incr_b(struct sdio_function *func,
  153. uint32_t addr,
  154. uint8_t *buf,
  155. uint32_t len);
  156. int32_t sdio_io_write_multi_incr_b(struct sdio_function *func,
  157. uint32_t addr,
  158. uint8_t *buf,
  159. uint32_t len);
  160. int32_t init_sdio(struct mmcsd_host *host, uint32_t ocr);
  161. int32_t sdio_attach_irq(struct sdio_function *func,
  162. sdio_irq_handler_t *handler);
  163. int32_t sdio_detach_irq(struct sdio_function *func);
  164. void sdio_irq_wakeup(struct mmcsd_host *host);
  165. void sdio_irq_wakeup_isr(struct mmcsd_host *host);
  166. int32_t sdio_enable_func(struct sdio_function *func);
  167. int32_t sdio_disable_func(struct sdio_function *func);
  168. void sdio_set_drvdata(struct sdio_function *func, void *data);
  169. void* sdio_get_drvdata(struct sdio_function *func);
  170. int32_t sdio_set_block_size(struct sdio_function *func,
  171. uint32_t blksize);
  172. int32_t sdio_register_driver(struct sdio_driver_t *driver);
  173. int32_t sdio_unregister_driver(struct sdio_driver_t *driver);
  174. void sdio_init(void);
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif