Statistics
| Branch: | Revision:

root / hw / sd.h @ 5fafdf24

History | View | Annotate | Download (2.9 kB)

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

    
32
#include <vl.h>
33

    
34
#define OUT_OF_RANGE                (1 << 31)
35
#define ADDRESS_ERROR                (1 << 30)
36
#define BLOCK_LEN_ERROR                (1 << 29)
37
#define ERASE_SEQ_ERROR                (1 << 28)
38
#define ERASE_PARAM                (1 << 27)
39
#define WP_VIOLATION                (1 << 26)
40
#define CARD_IS_LOCKED                (1 << 25)
41
#define LOCK_UNLOCK_FAILED        (1 << 24)
42
#define COM_CRC_ERROR                (1 << 23)
43
#define ILLEGAL_COMMAND                (1 << 22)
44
#define CARD_ECC_FAILED                (1 << 21)
45
#define CC_ERROR                (1 << 20)
46
#define SD_ERROR                (1 << 19)
47
#define CID_CSD_OVERWRITE        (1 << 16)
48
#define WP_ERASE_SKIP                (1 << 15)
49
#define CARD_ECC_DISABLED        (1 << 14)
50
#define ERASE_RESET                (1 << 13)
51
#define CURRENT_STATE                (7 << 9)
52
#define READY_FOR_DATA                (1 << 8)
53
#define APP_CMD                        (1 << 5)
54
#define AKE_SEQ_ERROR                (1 << 3)
55

    
56
typedef enum {
57
    sd_none = -1,
58
    sd_bc = 0,        /* broadcast -- no response */
59
    sd_bcr,        /* broadcast with response */
60
    sd_ac,        /* addressed -- no data transfer */
61
    sd_adtc,        /* addressed with data transfer */
62
} sd_cmd_type_t;
63

    
64
struct sd_request_s {
65
    uint8_t cmd;
66
    uint32_t arg;
67
    uint8_t crc;
68
};
69

    
70
typedef struct SDState SDState;
71

    
72
SDState *sd_init(BlockDriverState *bs);
73
int sd_do_command(SDState *sd, struct sd_request_s *req,
74
                  uint8_t *response);
75
void sd_write_data(SDState *sd, uint8_t value);
76
uint8_t sd_read_data(SDState *sd);
77
void sd_set_cb(SDState *sd, void *opaque,
78
               void (*readonly_cb)(void *, int),
79
               void (*inserted_cb)(void *, int));
80
int sd_data_ready(SDState *sd);
81

    
82
#endif        /* __hw_sd_h */