sdio.h 9.6 KB

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