1
2
3
4
5#ifndef LINUX_MMC_CORE_H
6#define LINUX_MMC_CORE_H
7
8#include <linux/completion.h>
9#include <linux/types.h>
10
11struct mmc_data;
12struct mmc_request;
13
14enum mmc_blk_status {
15 MMC_BLK_SUCCESS = 0,
16 MMC_BLK_PARTIAL,
17 MMC_BLK_CMD_ERR,
18 MMC_BLK_RETRY,
19 MMC_BLK_ABORT,
20 MMC_BLK_DATA_ERR,
21 MMC_BLK_ECC_ERR,
22 MMC_BLK_NOMEDIUM,
23 MMC_BLK_NEW_REQUEST,
24};
25
26struct mmc_command {
27 u32 opcode;
28 u32 arg;
29#define MMC_CMD23_ARG_REL_WR (1 << 31)
30#define MMC_CMD23_ARG_PACKED ((0 << 31) | (1 << 30))
31#define MMC_CMD23_ARG_TAG_REQ (1 << 29)
32 u32 resp[4];
33 unsigned int flags;
34#define MMC_RSP_PRESENT (1 << 0)
35#define MMC_RSP_136 (1 << 1)
36#define MMC_RSP_CRC (1 << 2)
37#define MMC_RSP_BUSY (1 << 3)
38#define MMC_RSP_OPCODE (1 << 4)
39
40#define MMC_CMD_MASK (3 << 5)
41#define MMC_CMD_AC (0 << 5)
42#define MMC_CMD_ADTC (1 << 5)
43#define MMC_CMD_BC (2 << 5)
44#define MMC_CMD_BCR (3 << 5)
45
46#define MMC_RSP_SPI_S1 (1 << 7)
47#define MMC_RSP_SPI_S2 (1 << 8)
48#define MMC_RSP_SPI_B4 (1 << 9)
49#define MMC_RSP_SPI_BUSY (1 << 10)
50
51
52
53
54
55
56#define MMC_RSP_NONE (0)
57#define MMC_RSP_R1 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
58#define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
59#define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
60#define MMC_RSP_R3 (MMC_RSP_PRESENT)
61#define MMC_RSP_R4 (MMC_RSP_PRESENT)
62#define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
63#define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
64#define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
65
66
67#define MMC_RSP_R1_NO_CRC (MMC_RSP_PRESENT|MMC_RSP_OPCODE)
68
69#define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
70
71
72
73
74
75
76#define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)
77#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
78#define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
79#define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
80#define MMC_RSP_SPI_R4 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
81#define MMC_RSP_SPI_R5 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
82#define MMC_RSP_SPI_R7 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
83
84#define mmc_spi_resp_type(cmd) ((cmd)->flags & \
85 (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
86
87
88
89
90#define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK)
91
92 unsigned int retries;
93 int error;
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 unsigned int busy_timeout;
110
111 bool sanitize_busy;
112
113 struct mmc_data *data;
114 struct mmc_request *mrq;
115};
116
117struct mmc_data {
118 unsigned int timeout_ns;
119 unsigned int timeout_clks;
120 unsigned int blksz;
121 unsigned int blocks;
122 unsigned int blk_addr;
123 int error;
124 unsigned int flags;
125
126#define MMC_DATA_WRITE BIT(8)
127#define MMC_DATA_READ BIT(9)
128
129#define MMC_DATA_QBR BIT(10)
130#define MMC_DATA_PRIO BIT(11)
131#define MMC_DATA_REL_WR BIT(12)
132#define MMC_DATA_DAT_TAG BIT(13)
133#define MMC_DATA_FORCED_PRG BIT(14)
134
135 unsigned int bytes_xfered;
136
137 struct mmc_command *stop;
138 struct mmc_request *mrq;
139
140 unsigned int sg_len;
141 int sg_count;
142 struct scatterlist *sg;
143 s32 host_cookie;
144};
145
146struct mmc_host;
147struct mmc_request {
148 struct mmc_command *sbc;
149 struct mmc_command *cmd;
150 struct mmc_data *data;
151 struct mmc_command *stop;
152
153 struct completion completion;
154 struct completion cmd_completion;
155 void (*done)(struct mmc_request *);
156
157
158
159
160
161 void (*recovery_notifier)(struct mmc_request *);
162 struct mmc_host *host;
163
164
165 bool cap_cmd_during_tfr;
166
167 int tag;
168};
169
170struct mmc_card;
171
172void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq);
173int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd,
174 int retries);
175
176int mmc_hw_reset(struct mmc_host *host);
177int mmc_sw_reset(struct mmc_host *host);
178void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card);
179
180#endif
181