sdhci.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * SD Association Host Standard Specification v2.0 controller emulation
  3. *
  4. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  5. * Mitsyanko Igor <i.mitsyanko@samsung.com>
  6. * Peter A.G. Crosthwaite <peter.crosthwaite@petalogix.com>
  7. *
  8. * Based on MMC controller for Samsung S5PC1xx-based board emulation
  9. * by Alexey Merkulov and Vladimir Monakhov.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. * See the GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU _General Public License along
  22. * with this program; if not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef SDHCI_H
  25. #define SDHCI_H
  26. #include "hw/pci/pci_device.h"
  27. #include "hw/sysbus.h"
  28. #include "hw/sd/sd.h"
  29. #include "qom/object.h"
  30. /* SD/MMC host controller state */
  31. struct SDHCIState {
  32. /*< private >*/
  33. union {
  34. PCIDevice pcidev;
  35. SysBusDevice busdev;
  36. };
  37. /*< public >*/
  38. SDBus sdbus;
  39. MemoryRegion iomem;
  40. AddressSpace sysbus_dma_as;
  41. AddressSpace *dma_as;
  42. MemoryRegion *dma_mr;
  43. const MemoryRegionOps *io_ops;
  44. QEMUTimer *insert_timer; /* timer for 'changing' sd card. */
  45. QEMUTimer *transfer_timer;
  46. qemu_irq irq;
  47. /* Registers cleared on reset */
  48. uint32_t sdmasysad; /* SDMA System Address register */
  49. uint16_t blksize; /* Host DMA Buff Boundary and Transfer BlkSize Reg */
  50. uint16_t blkcnt; /* Blocks count for current transfer */
  51. uint32_t argument; /* Command Argument Register */
  52. uint16_t trnmod; /* Transfer Mode Setting Register */
  53. uint16_t cmdreg; /* Command Register */
  54. uint32_t rspreg[4]; /* Response Registers 0-3 */
  55. uint32_t prnsts; /* Present State Register */
  56. uint8_t hostctl1; /* Host Control Register */
  57. uint8_t pwrcon; /* Power control Register */
  58. uint8_t blkgap; /* Block Gap Control Register */
  59. uint8_t wakcon; /* WakeUp Control Register */
  60. uint16_t clkcon; /* Clock control Register */
  61. uint8_t timeoutcon; /* Timeout Control Register */
  62. uint8_t admaerr; /* ADMA Error Status Register */
  63. uint16_t norintsts; /* Normal Interrupt Status Register */
  64. uint16_t errintsts; /* Error Interrupt Status Register */
  65. uint16_t norintstsen; /* Normal Interrupt Status Enable Register */
  66. uint16_t errintstsen; /* Error Interrupt Status Enable Register */
  67. uint16_t norintsigen; /* Normal Interrupt Signal Enable Register */
  68. uint16_t errintsigen; /* Error Interrupt Signal Enable Register */
  69. uint16_t acmd12errsts; /* Auto CMD12 error status register */
  70. uint16_t hostctl2; /* Host Control 2 */
  71. uint64_t admasysaddr; /* ADMA System Address Register */
  72. uint16_t vendor_spec; /* Vendor specific register */
  73. /* Read-only registers */
  74. uint64_t capareg; /* Capabilities Register */
  75. uint64_t maxcurr; /* Maximum Current Capabilities Register */
  76. uint16_t version; /* Host Controller Version Register */
  77. uint8_t *fifo_buffer; /* SD host i/o FIFO buffer */
  78. uint32_t buf_maxsz;
  79. uint16_t data_count; /* current element in FIFO buffer */
  80. uint8_t stopped_state;/* Current SDHC state */
  81. bool pending_insert_state;
  82. /* Buffer Data Port Register - virtual access point to R and W buffers */
  83. /* Software Reset Register - always reads as 0 */
  84. /* Force Event Auto CMD12 Error Interrupt Reg - write only */
  85. /* Force Event Error Interrupt Register- write only */
  86. /* RO Host Controller Version Register always reads as 0x2401 */
  87. /* Configurable properties */
  88. bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */
  89. uint32_t quirks;
  90. uint8_t endianness;
  91. uint8_t sd_spec_version;
  92. uint8_t uhs_mode;
  93. uint8_t vendor; /* For vendor specific functionality */
  94. };
  95. typedef struct SDHCIState SDHCIState;
  96. #define SDHCI_VENDOR_NONE 0
  97. #define SDHCI_VENDOR_IMX 1
  98. /*
  99. * Controller does not provide transfer-complete interrupt when not
  100. * busy.
  101. *
  102. * NOTE: This definition is taken out of Linux kernel and so the
  103. * original bit number is preserved
  104. */
  105. #define SDHCI_QUIRK_NO_BUSY_IRQ BIT(14)
  106. #define TYPE_PCI_SDHCI "sdhci-pci"
  107. DECLARE_INSTANCE_CHECKER(SDHCIState, PCI_SDHCI,
  108. TYPE_PCI_SDHCI)
  109. #define TYPE_SYSBUS_SDHCI "generic-sdhci"
  110. DECLARE_INSTANCE_CHECKER(SDHCIState, SYSBUS_SDHCI,
  111. TYPE_SYSBUS_SDHCI)
  112. #define TYPE_IMX_USDHC "imx-usdhc"
  113. #define TYPE_S3C_SDHCI "s3c-sdhci"
  114. #endif /* SDHCI_H */