Statistics
| Branch: | Revision:

root / hw / sd.h @ 78895427

History | View | Annotate | Download (2.8 kB)

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