mmcsd_host.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * File : mmcsd_host.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 __HOST_H__
  25. #define __HOST_H__
  26. #include <rtthread.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. struct rt_mmcsd_io_cfg {
  31. rt_uint32_t clock; /* clock rate */
  32. rt_uint16_t vdd;
  33. /* vdd stores the bit number of the selected voltage range from below. */
  34. rt_uint8_t bus_mode; /* command output mode */
  35. #define MMCSD_BUSMODE_OPENDRAIN 1
  36. #define MMCSD_BUSMODE_PUSHPULL 2
  37. rt_uint8_t chip_select; /* SPI chip select */
  38. #define MMCSD_CS_IGNORE 0
  39. #define MMCSD_CS_HIGH 1
  40. #define MMCSD_CS_LOW 2
  41. rt_uint8_t power_mode; /* power supply mode */
  42. #define MMCSD_POWER_OFF 0
  43. #define MMCSD_POWER_UP 1
  44. #define MMCSD_POWER_ON 2
  45. rt_uint8_t bus_width; /* data bus width */
  46. #define MMCSD_BUS_WIDTH_1 0
  47. #define MMCSD_BUS_WIDTH_4 2
  48. #define MMCSD_BUS_WIDTH_8 3
  49. };
  50. struct rt_mmcsd_host;
  51. struct rt_mmcsd_req;
  52. struct rt_mmcsd_host_ops {
  53. void (*request)(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req);
  54. void (*set_iocfg)(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg);
  55. rt_int32_t (*get_card_status)(struct rt_mmcsd_host *host);
  56. void (*enable_sdio_irq)(struct rt_mmcsd_host *host, rt_int32_t en);
  57. };
  58. struct rt_mmcsd_host {
  59. struct rt_mmcsd_card *card;
  60. const struct rt_mmcsd_host_ops *ops;
  61. rt_uint32_t freq_min;
  62. rt_uint32_t freq_max;
  63. struct rt_mmcsd_io_cfg io_cfg;
  64. rt_uint32_t valid_ocr; /* current valid OCR */
  65. #define VDD_165_195 (1 << 7) /* VDD voltage 1.65 - 1.95 */
  66. #define VDD_20_21 (1 << 8) /* VDD voltage 2.0 ~ 2.1 */
  67. #define VDD_21_22 (1 << 9) /* VDD voltage 2.1 ~ 2.2 */
  68. #define VDD_22_23 (1 << 10) /* VDD voltage 2.2 ~ 2.3 */
  69. #define VDD_23_24 (1 << 11) /* VDD voltage 2.3 ~ 2.4 */
  70. #define VDD_24_25 (1 << 12) /* VDD voltage 2.4 ~ 2.5 */
  71. #define VDD_25_26 (1 << 13) /* VDD voltage 2.5 ~ 2.6 */
  72. #define VDD_26_27 (1 << 14) /* VDD voltage 2.6 ~ 2.7 */
  73. #define VDD_27_28 (1 << 15) /* VDD voltage 2.7 ~ 2.8 */
  74. #define VDD_28_29 (1 << 16) /* VDD voltage 2.8 ~ 2.9 */
  75. #define VDD_29_30 (1 << 17) /* VDD voltage 2.9 ~ 3.0 */
  76. #define VDD_30_31 (1 << 18) /* VDD voltage 3.0 ~ 3.1 */
  77. #define VDD_31_32 (1 << 19) /* VDD voltage 3.1 ~ 3.2 */
  78. #define VDD_32_33 (1 << 20) /* VDD voltage 3.2 ~ 3.3 */
  79. #define VDD_33_34 (1 << 21) /* VDD voltage 3.3 ~ 3.4 */
  80. #define VDD_34_35 (1 << 22) /* VDD voltage 3.4 ~ 3.5 */
  81. #define VDD_35_36 (1 << 23) /* VDD voltage 3.5 ~ 3.6 */
  82. rt_uint32_t flags; /* define device capabilities */
  83. #define MMCSD_BUSWIDTH_4 (1 << 0)
  84. #define MMCSD_BUSWIDTH_8 (1 << 1)
  85. #define MMCSD_MUTBLKWRITE (1 << 2)
  86. #define MMCSD_HOST_IS_SPI (1 << 3)
  87. #define controller_is_spi(host) (host->flags & MMCSD_HOST_IS_SPI)
  88. #define MMCSD_SUP_SDIO_IRQ (1 << 4) /* support signal pending SDIO IRQs */
  89. #define MMCSD_SUP_HIGHSPEED (1 << 5) /* support high speed */
  90. rt_uint32_t max_seg_size; /* maximum size of one dma segment */
  91. rt_uint32_t max_dma_segs; /* maximum number of dma segments in one request */
  92. rt_uint32_t max_blk_size; /* maximum block size */
  93. rt_uint32_t max_blk_count; /* maximum block count */
  94. rt_uint32_t spi_use_crc;
  95. struct rt_semaphore bus_lock;
  96. struct rt_semaphore sem_ack;
  97. rt_uint32_t sdio_irq_num;
  98. struct rt_semaphore *sdio_irq_sem;
  99. struct rt_thread *sdio_irq_thread;
  100. void *private_data;
  101. };
  102. rt_inline void mmcsd_delay_ms(rt_uint32_t ms)
  103. {
  104. if (ms < 1000 / RT_TICK_PER_SECOND)
  105. {
  106. rt_thread_delay(1);
  107. }
  108. else
  109. {
  110. rt_thread_delay(ms/(1000 / RT_TICK_PER_SECOND));
  111. }
  112. }
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif