sd.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * SD Memory Card emulation. Mostly correct for MMC too.
  3. *
  4. * Copyright (c) 2006 Andrzej Zaborowski <balrog@zabor.org>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
  18. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  20. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  25. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef __hw_sd_h
  30. #define __hw_sd_h 1
  31. #define OUT_OF_RANGE (1 << 31)
  32. #define ADDRESS_ERROR (1 << 30)
  33. #define BLOCK_LEN_ERROR (1 << 29)
  34. #define ERASE_SEQ_ERROR (1 << 28)
  35. #define ERASE_PARAM (1 << 27)
  36. #define WP_VIOLATION (1 << 26)
  37. #define CARD_IS_LOCKED (1 << 25)
  38. #define LOCK_UNLOCK_FAILED (1 << 24)
  39. #define COM_CRC_ERROR (1 << 23)
  40. #define ILLEGAL_COMMAND (1 << 22)
  41. #define CARD_ECC_FAILED (1 << 21)
  42. #define CC_ERROR (1 << 20)
  43. #define SD_ERROR (1 << 19)
  44. #define CID_CSD_OVERWRITE (1 << 16)
  45. #define WP_ERASE_SKIP (1 << 15)
  46. #define CARD_ECC_DISABLED (1 << 14)
  47. #define ERASE_RESET (1 << 13)
  48. #define CURRENT_STATE (7 << 9)
  49. #define READY_FOR_DATA (1 << 8)
  50. #define APP_CMD (1 << 5)
  51. #define AKE_SEQ_ERROR (1 << 3)
  52. typedef enum {
  53. sd_none = -1,
  54. sd_bc = 0, /* broadcast -- no response */
  55. sd_bcr, /* broadcast with response */
  56. sd_ac, /* addressed -- no data transfer */
  57. sd_adtc, /* addressed with data transfer */
  58. } sd_cmd_type_t;
  59. typedef struct {
  60. uint8_t cmd;
  61. uint32_t arg;
  62. uint8_t crc;
  63. } SDRequest;
  64. typedef struct SDState SDState;
  65. SDState *sd_init(BlockDriverState *bs, int is_spi);
  66. int sd_do_command(SDState *sd, SDRequest *req,
  67. uint8_t *response);
  68. void sd_write_data(SDState *sd, uint8_t value);
  69. uint8_t sd_read_data(SDState *sd);
  70. void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert);
  71. int sd_data_ready(SDState *sd);
  72. void sd_enable(SDState *sd, int enable);
  73. #endif /* __hw_sd_h */