2
0

sd.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #define OCR_CCS_BITN 30
  53. typedef enum {
  54. sd_none = -1,
  55. sd_bc = 0, /* broadcast -- no response */
  56. sd_bcr, /* broadcast with response */
  57. sd_ac, /* addressed -- no data transfer */
  58. sd_adtc, /* addressed with data transfer */
  59. } sd_cmd_type_t;
  60. typedef struct {
  61. uint8_t cmd;
  62. uint32_t arg;
  63. uint8_t crc;
  64. } SDRequest;
  65. typedef struct SDState SDState;
  66. SDState *sd_init(BlockDriverState *bs, bool is_spi);
  67. int sd_do_command(SDState *sd, SDRequest *req,
  68. uint8_t *response);
  69. void sd_write_data(SDState *sd, uint8_t value);
  70. uint8_t sd_read_data(SDState *sd);
  71. void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert);
  72. bool sd_data_ready(SDState *sd);
  73. void sd_enable(SDState *sd, bool enable);
  74. #endif /* __hw_sd_h */