Deleted Added
full compact
mmcreg.h (183542) mmcreg.h (183704)
1/*-
2 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * Portions of this software may have been developed with reference to
25 * the SD Simplified Specification. The following disclaimer may apply:
26 *
27 * The following conditions apply to the release of the simplified
28 * specification ("Simplified Specification") by the SD Card Association and
29 * the SD Group. The Simplified Specification is a subset of the complete SD
30 * Specification which is owned by the SD Card Association and the SD
31 * Group. This Simplified Specification is provided on a non-confidential
32 * basis subject to the disclaimers below. Any implementation of the
33 * Simplified Specification may require a license from the SD Card
34 * Association, SD Group, SD-3C LLC or other third parties.
35 *
36 * Disclaimers:
37 *
38 * The information contained in the Simplified Specification is presented only
39 * as a standard specification for SD Cards and SD Host/Ancillary products and
40 * is provided "AS-IS" without any representations or warranties of any
41 * kind. No responsibility is assumed by the SD Group, SD-3C LLC or the SD
42 * Card Association for any damages, any infringements of patents or other
43 * right of the SD Group, SD-3C LLC, the SD Card Association or any third
44 * parties, which may result from its use. No license is granted by
45 * implication, estoppel or otherwise under any patent or other rights of the
46 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
47 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
48 * or the SD Card Association to disclose or distribute any technical
49 * information, know-how or other confidential information to any third party.
50 *
1/*-
2 * Copyright (c) 2006 M. Warner Losh. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * Portions of this software may have been developed with reference to
25 * the SD Simplified Specification. The following disclaimer may apply:
26 *
27 * The following conditions apply to the release of the simplified
28 * specification ("Simplified Specification") by the SD Card Association and
29 * the SD Group. The Simplified Specification is a subset of the complete SD
30 * Specification which is owned by the SD Card Association and the SD
31 * Group. This Simplified Specification is provided on a non-confidential
32 * basis subject to the disclaimers below. Any implementation of the
33 * Simplified Specification may require a license from the SD Card
34 * Association, SD Group, SD-3C LLC or other third parties.
35 *
36 * Disclaimers:
37 *
38 * The information contained in the Simplified Specification is presented only
39 * as a standard specification for SD Cards and SD Host/Ancillary products and
40 * is provided "AS-IS" without any representations or warranties of any
41 * kind. No responsibility is assumed by the SD Group, SD-3C LLC or the SD
42 * Card Association for any damages, any infringements of patents or other
43 * right of the SD Group, SD-3C LLC, the SD Card Association or any third
44 * parties, which may result from its use. No license is granted by
45 * implication, estoppel or otherwise under any patent or other rights of the
46 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
47 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
48 * or the SD Card Association to disclose or distribute any technical
49 * information, know-how or other confidential information to any third party.
50 *
51 * $FreeBSD: head/sys/dev/mmc/mmcreg.h 183542 2008-10-02 07:06:59Z imp $
51 * $FreeBSD: head/sys/dev/mmc/mmcreg.h 183704 2008-10-08 17:35:41Z mav $
52 */
53
54#ifndef DEV_MMC_MMCREG_H
55#define DEV_MMC_MMCREG_H
56
57/*
58 * This file contains the register definitions for the mmc and sd busses.
59 * They are taken from publicly available sources.
60 */
61
62struct mmc_data;
63struct mmc_request;
64
65struct mmc_command {
66 uint32_t opcode;
67 uint32_t arg;
68 uint32_t resp[4];
69 uint32_t flags; /* Expected responses */
70#define MMC_RSP_PRESENT (1ul << 0) /* Response */
71#define MMC_RSP_136 (1ul << 1) /* 136 bit response */
72#define MMC_RSP_CRC (1ul << 2) /* Expect valid crc */
73#define MMC_RSP_BUSY (1ul << 3) /* Card may send busy */
74#define MMC_RSP_OPCODE (1ul << 4) /* Response include opcode */
75#define MMC_RSP_MASK 0x1ful
76#define MMC_CMD_AC (0ul << 5) /* Addressed Command, no data */
77#define MMC_CMD_ADTC (1ul << 5) /* Addressed Data transfer cmd */
78#define MMC_CMD_BC (2ul << 5) /* Broadcast command, no response */
79#define MMC_CMD_BCR (3ul << 5) /* Broadcast command with response */
80#define MMC_CMD_MASK (3ul << 5)
81
82/* Possible response types defined in the standard: */
83#define MMC_RSP_NONE (0)
84#define MMC_RSP_R1 (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE)
85#define MMC_RSP_R1B (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE | MMC_RSP_BUSY)
86#define MMC_RSP_R2 (MMC_RSP_PRESENT | MMC_RSP_136 | MMC_RSP_CRC)
87#define MMC_RSP_R3 (MMC_RSP_PRESENT)
88#define MMC_RSP_R6 (MMC_RSP_PRESENT | MMC_RSP_CRC)
52 */
53
54#ifndef DEV_MMC_MMCREG_H
55#define DEV_MMC_MMCREG_H
56
57/*
58 * This file contains the register definitions for the mmc and sd busses.
59 * They are taken from publicly available sources.
60 */
61
62struct mmc_data;
63struct mmc_request;
64
65struct mmc_command {
66 uint32_t opcode;
67 uint32_t arg;
68 uint32_t resp[4];
69 uint32_t flags; /* Expected responses */
70#define MMC_RSP_PRESENT (1ul << 0) /* Response */
71#define MMC_RSP_136 (1ul << 1) /* 136 bit response */
72#define MMC_RSP_CRC (1ul << 2) /* Expect valid crc */
73#define MMC_RSP_BUSY (1ul << 3) /* Card may send busy */
74#define MMC_RSP_OPCODE (1ul << 4) /* Response include opcode */
75#define MMC_RSP_MASK 0x1ful
76#define MMC_CMD_AC (0ul << 5) /* Addressed Command, no data */
77#define MMC_CMD_ADTC (1ul << 5) /* Addressed Data transfer cmd */
78#define MMC_CMD_BC (2ul << 5) /* Broadcast command, no response */
79#define MMC_CMD_BCR (3ul << 5) /* Broadcast command with response */
80#define MMC_CMD_MASK (3ul << 5)
81
82/* Possible response types defined in the standard: */
83#define MMC_RSP_NONE (0)
84#define MMC_RSP_R1 (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE)
85#define MMC_RSP_R1B (MMC_RSP_PRESENT | MMC_RSP_CRC | MMC_RSP_OPCODE | MMC_RSP_BUSY)
86#define MMC_RSP_R2 (MMC_RSP_PRESENT | MMC_RSP_136 | MMC_RSP_CRC)
87#define MMC_RSP_R3 (MMC_RSP_PRESENT)
88#define MMC_RSP_R6 (MMC_RSP_PRESENT | MMC_RSP_CRC)
89/* R7 -- new in sd 2.0 */
89#define MMC_RSP_R7 (MMC_RSP_PRESENT | MMC_RSP_CRC)
90#define MMC_RSP(x) ((x) & MMC_RSP_MASK)
91 uint32_t retries;
92 uint32_t error;
93#define MMC_ERR_NONE 0
94#define MMC_ERR_TIMEOUT 1
95#define MMC_ERR_BADCRC 2
96#define MMC_ERR_FIFO 3
97#define MMC_ERR_FAILED 4
98#define MMC_ERR_INVALID 5
99#define MMC_ERR_NO_MEMORY 6
100 struct mmc_data *data; /* Data segment with cmd */
101 struct mmc_request *mrq; /* backpointer to request */
102};
103
104/*
105 * R1 responses
106 *
107 * Types (per SD 2.0 standard)
108 * e : error bit
109 * s : status bit
110 * r : detected and set for the actual command response
111 * x : Detected and set during command execution. The host can get
112 * the status by issuing a command with R1 response.
113 *
114 * Clear Condition (per SD 2.0 standard)
115 * a : according to the card current state.
116 * b : always related to the previous command. reception of a valid
117 * command will clear it (with a delay of one command).
118 * c : clear by read
119 */
120#define R1_OUT_OF_RANGE (1u << 31) /* erx, c */
121#define R1_ADDRESS_ERROR (1u << 30) /* erx, c */
122#define R1_BLOCK_LEN_ERROR (1u << 29) /* erx, c */
123#define R1_ERASE_SEQ_ERROR (1u << 28) /* er, c */
124#define R1_ERASE_PARAM (1u << 27) /* erx, c */
125#define R1_WP_VIOLATION (1u << 26) /* erx, c */
126#define R1_CARD_IS_LOCKED (1u << 25) /* sx, a */
127#define R1_LOCK_UNLOCK_FAILED (1u << 24) /* erx, c */
128#define R1_COM_CRC_ERROR (1u << 23) /* er, b */
129#define R1_ILLEGAL_COMMAND (1u << 22) /* er, b */
130#define R1_CARD_ECC_FAILED (1u << 21) /* erx, c */
131#define R1_CC_ERROR (1u << 20) /* erx, c */
132#define R1_ERROR (1u << 19) /* erx, c */
133#define R1_CSD_OVERWRITE (1u << 16) /* erx, c */
134#define R1_WP_ERASE_SKIP (1u << 15) /* erx, c */
135#define R1_CARD_ECC_DISABLED (1u << 14) /* sx, a */
136#define R1_ERASE_RESET (1u << 13) /* sr, c */
137#define R1_CURRENT_STATE_MASK (0xfu << 9) /* sx, b */
138#define R1_READY_FOR_DATA (1u << 8) /* sx, a */
139#define R1_APP_CMD (1u << 5) /* sr, c */
140#define R1_AKE_SEQ_ERROR (1u << 3) /* er, c */
141#define R1_STATUS(x) (x & 0xFFFFE000
142#define R1_CURRENT_STATE(x) ((x) & R1_CURRENT_STATE_MASK) >> 9
143#define R1_STATE_IDLE 0
144#define R1_STATE_READY 1
145#define R1_STATE_IDENT 2
146#define R1_STATE_STBY 3
147#define R1_STATE_TRAN 4
148#define R1_STATE_DATA 5
149#define R1_STATE_RCV 6
150#define R1_STATE_PRG 7
151#define R1_STATE_DIS 8
152
153struct mmc_data {
154 size_t len; /* size of the data */
155 size_t xfer_len;
156 void *data; /* data buffer */
157 uint32_t flags;
158#define MMC_DATA_WRITE (1UL << 0)
159#define MMC_DATA_READ (1UL << 1)
160#define MMC_DATA_STREAM (1UL << 2)
161#define MMC_DATA_MULTI (1UL << 3)
162 struct mmc_request *mrq;
163};
164
165struct mmc_request {
166 struct mmc_command *cmd;
167 struct mmc_command *stop;
168 void (*done)(struct mmc_request *); /* Completion function */
169 void *done_data; /* requestor set data */
170 uint32_t flags;
171#define MMC_REQ_DONE 1
172};
173
174/* Command definitions */
175
176/* Class 0 and 1: Basic commands & read stream commands */
177#define MMC_GO_IDLE_STATE 0
178#define MMC_SEND_OP_COND 1
179#define MMC_ALL_SEND_CID 2
180#define MMC_SET_RELATIVE_ADDR 3
181#define SD_SEND_RELATIVE_ADDR 3
182#define MMC_SET_DSR 4
183 /* reserved: 5 */
90#define MMC_RSP(x) ((x) & MMC_RSP_MASK)
91 uint32_t retries;
92 uint32_t error;
93#define MMC_ERR_NONE 0
94#define MMC_ERR_TIMEOUT 1
95#define MMC_ERR_BADCRC 2
96#define MMC_ERR_FIFO 3
97#define MMC_ERR_FAILED 4
98#define MMC_ERR_INVALID 5
99#define MMC_ERR_NO_MEMORY 6
100 struct mmc_data *data; /* Data segment with cmd */
101 struct mmc_request *mrq; /* backpointer to request */
102};
103
104/*
105 * R1 responses
106 *
107 * Types (per SD 2.0 standard)
108 * e : error bit
109 * s : status bit
110 * r : detected and set for the actual command response
111 * x : Detected and set during command execution. The host can get
112 * the status by issuing a command with R1 response.
113 *
114 * Clear Condition (per SD 2.0 standard)
115 * a : according to the card current state.
116 * b : always related to the previous command. reception of a valid
117 * command will clear it (with a delay of one command).
118 * c : clear by read
119 */
120#define R1_OUT_OF_RANGE (1u << 31) /* erx, c */
121#define R1_ADDRESS_ERROR (1u << 30) /* erx, c */
122#define R1_BLOCK_LEN_ERROR (1u << 29) /* erx, c */
123#define R1_ERASE_SEQ_ERROR (1u << 28) /* er, c */
124#define R1_ERASE_PARAM (1u << 27) /* erx, c */
125#define R1_WP_VIOLATION (1u << 26) /* erx, c */
126#define R1_CARD_IS_LOCKED (1u << 25) /* sx, a */
127#define R1_LOCK_UNLOCK_FAILED (1u << 24) /* erx, c */
128#define R1_COM_CRC_ERROR (1u << 23) /* er, b */
129#define R1_ILLEGAL_COMMAND (1u << 22) /* er, b */
130#define R1_CARD_ECC_FAILED (1u << 21) /* erx, c */
131#define R1_CC_ERROR (1u << 20) /* erx, c */
132#define R1_ERROR (1u << 19) /* erx, c */
133#define R1_CSD_OVERWRITE (1u << 16) /* erx, c */
134#define R1_WP_ERASE_SKIP (1u << 15) /* erx, c */
135#define R1_CARD_ECC_DISABLED (1u << 14) /* sx, a */
136#define R1_ERASE_RESET (1u << 13) /* sr, c */
137#define R1_CURRENT_STATE_MASK (0xfu << 9) /* sx, b */
138#define R1_READY_FOR_DATA (1u << 8) /* sx, a */
139#define R1_APP_CMD (1u << 5) /* sr, c */
140#define R1_AKE_SEQ_ERROR (1u << 3) /* er, c */
141#define R1_STATUS(x) (x & 0xFFFFE000
142#define R1_CURRENT_STATE(x) ((x) & R1_CURRENT_STATE_MASK) >> 9
143#define R1_STATE_IDLE 0
144#define R1_STATE_READY 1
145#define R1_STATE_IDENT 2
146#define R1_STATE_STBY 3
147#define R1_STATE_TRAN 4
148#define R1_STATE_DATA 5
149#define R1_STATE_RCV 6
150#define R1_STATE_PRG 7
151#define R1_STATE_DIS 8
152
153struct mmc_data {
154 size_t len; /* size of the data */
155 size_t xfer_len;
156 void *data; /* data buffer */
157 uint32_t flags;
158#define MMC_DATA_WRITE (1UL << 0)
159#define MMC_DATA_READ (1UL << 1)
160#define MMC_DATA_STREAM (1UL << 2)
161#define MMC_DATA_MULTI (1UL << 3)
162 struct mmc_request *mrq;
163};
164
165struct mmc_request {
166 struct mmc_command *cmd;
167 struct mmc_command *stop;
168 void (*done)(struct mmc_request *); /* Completion function */
169 void *done_data; /* requestor set data */
170 uint32_t flags;
171#define MMC_REQ_DONE 1
172};
173
174/* Command definitions */
175
176/* Class 0 and 1: Basic commands & read stream commands */
177#define MMC_GO_IDLE_STATE 0
178#define MMC_SEND_OP_COND 1
179#define MMC_ALL_SEND_CID 2
180#define MMC_SET_RELATIVE_ADDR 3
181#define SD_SEND_RELATIVE_ADDR 3
182#define MMC_SET_DSR 4
183 /* reserved: 5 */
184#define MMC_SWITCH_FUNC 6
185#define MMC_SWITCH_FUNC_CMDS 0
186#define MMC_SWITCH_FUNC_SET 1
187#define MMC_SWITCH_FUNC_CLR 2
188#define MMC_SWITCH_FUNC_WR 3
184#define MMC_SELECT_CARD 7
185#define MMC_DESELECT_CARD 7
189#define MMC_SELECT_CARD 7
190#define MMC_DESELECT_CARD 7
186#define MMC_SEND_IF_COND 8
191#define MMC_SEND_EXT_CSD 8
192#define SD_SEND_IF_COND 8
187#define MMC_SEND_CSD 9
188#define MMC_SEND_CID 10
189#define MMC_READ_DAT_UNTIL_STOP 11
190#define MMC_STOP_TRANSMISSION 12
191#define MMC_SEND_STATUS 13
193#define MMC_SEND_CSD 9
194#define MMC_SEND_CID 10
195#define MMC_READ_DAT_UNTIL_STOP 11
196#define MMC_STOP_TRANSMISSION 12
197#define MMC_SEND_STATUS 13
192 /* reserved: 14 */
198#define MMC_BUSTEST_R 14
193#define MMC_GO_INACTIVE_STATE 15
199#define MMC_GO_INACTIVE_STATE 15
200#define MMC_BUSTEST_W 19
194
195/* Class 2: Block oriented read commands */
196#define MMC_SET_BLOCKLEN 16
197#define MMC_READ_SINGLE_BLOCK 17
198#define MMC_READ_MULTIPLE_BLOCK 18
199 /* reserved: 19 */
200
201/* Class 3: Stream write commands */
202#define MMC_WRITE_DAT_UNTIL_STOP 20
203 /* reserved: 21 */
204 /* reserved: 22 */
205
206/* Class 4: Block oriented write commands */
207#define MMC_SET_BLOCK_COUNT 23
208#define MMC_WRITE_BLOCK 24
209#define MMC_WRITE_MULTIPLE_BLOCK 25
210#define MMC_PROGARM_CID 26
211#define MMC_PROGRAM_CSD 27
212
213/* Class 6: Block oriented write protection commands */
214#define MMC_SET_WRITE_PROT 28
215#define MMC_CLR_WRITE_PROT 29
216#define MMC_SEND_WRITE_PROT 30
217 /* reserved: 31 */
218
219/* Class 5: Erase commands */
220#define SD_ERASE_WR_BLK_START 32
221#define SD_ERASE_WR_BLK_END 33
222 /* 34 -- reserved old command */
223#define MMC_ERASE_GROUP_START 35
224#define MMC_ERASE_GROUP_END 36
225 /* 37 -- reserved old command */
226#define MMC_ERASE 38
227
228/* Class 9: I/O mode commands */
229#define MMC_FAST_IO 39
230#define MMC_GO_IRQ_STATE 40
231 /* reserved: 41 */
232
233/* Class 7: Lock card */
234#define MMC_LOCK_UNLOCK 42
235 /* reserved: 43 */
236 /* reserved: 44 */
237 /* reserved: 45 */
238 /* reserved: 46 */
239 /* reserved: 47 */
240 /* reserved: 48 */
241 /* reserved: 49 */
242 /* reserved: 50 */
243 /* reserved: 51 */
244 /* reserved: 54 */
245
246/* Class 8: Application specific commands */
247#define MMC_APP_CMD 55
248#define MMC_GEN_CMD 56
249 /* reserved: 57 */
250 /* reserved: 58 */
251 /* reserved: 59 */
252 /* reserved for mfg: 60 */
253 /* reserved for mfg: 61 */
254 /* reserved for mfg: 62 */
255 /* reserved for mfg: 63 */
256
257/* Class 9: I/O cards (sd) */
258#define SD_IO_RW_DIRECT 52
259#define SD_IO_RW_EXTENDED 53
260
261/* Class 10: Switch function commands */
262#define SD_SWITCH_FUNC 6
263 /* reserved: 34 */
264 /* reserved: 35 */
265 /* reserved: 36 */
266 /* reserved: 37 */
267 /* reserved: 50 */
268 /* reserved: 57 */
269
270
271/* Application specific commands for SD */
272#define ACMD_SET_BUS_WIDTH 6
273#define ACMD_SD_STATUS 13
274#define ACMD_SEND_NUM_WR_BLOCKS 22
275#define ACMD_SET_WR_BLK_ERASE_COUNT 23
276#define ACMD_SD_SEND_OP_COND 41
277#define ACMD_SET_CLR_CARD_DETECT 42
278#define ACMD_SEND_SCR 51
279
201
202/* Class 2: Block oriented read commands */
203#define MMC_SET_BLOCKLEN 16
204#define MMC_READ_SINGLE_BLOCK 17
205#define MMC_READ_MULTIPLE_BLOCK 18
206 /* reserved: 19 */
207
208/* Class 3: Stream write commands */
209#define MMC_WRITE_DAT_UNTIL_STOP 20
210 /* reserved: 21 */
211 /* reserved: 22 */
212
213/* Class 4: Block oriented write commands */
214#define MMC_SET_BLOCK_COUNT 23
215#define MMC_WRITE_BLOCK 24
216#define MMC_WRITE_MULTIPLE_BLOCK 25
217#define MMC_PROGARM_CID 26
218#define MMC_PROGRAM_CSD 27
219
220/* Class 6: Block oriented write protection commands */
221#define MMC_SET_WRITE_PROT 28
222#define MMC_CLR_WRITE_PROT 29
223#define MMC_SEND_WRITE_PROT 30
224 /* reserved: 31 */
225
226/* Class 5: Erase commands */
227#define SD_ERASE_WR_BLK_START 32
228#define SD_ERASE_WR_BLK_END 33
229 /* 34 -- reserved old command */
230#define MMC_ERASE_GROUP_START 35
231#define MMC_ERASE_GROUP_END 36
232 /* 37 -- reserved old command */
233#define MMC_ERASE 38
234
235/* Class 9: I/O mode commands */
236#define MMC_FAST_IO 39
237#define MMC_GO_IRQ_STATE 40
238 /* reserved: 41 */
239
240/* Class 7: Lock card */
241#define MMC_LOCK_UNLOCK 42
242 /* reserved: 43 */
243 /* reserved: 44 */
244 /* reserved: 45 */
245 /* reserved: 46 */
246 /* reserved: 47 */
247 /* reserved: 48 */
248 /* reserved: 49 */
249 /* reserved: 50 */
250 /* reserved: 51 */
251 /* reserved: 54 */
252
253/* Class 8: Application specific commands */
254#define MMC_APP_CMD 55
255#define MMC_GEN_CMD 56
256 /* reserved: 57 */
257 /* reserved: 58 */
258 /* reserved: 59 */
259 /* reserved for mfg: 60 */
260 /* reserved for mfg: 61 */
261 /* reserved for mfg: 62 */
262 /* reserved for mfg: 63 */
263
264/* Class 9: I/O cards (sd) */
265#define SD_IO_RW_DIRECT 52
266#define SD_IO_RW_EXTENDED 53
267
268/* Class 10: Switch function commands */
269#define SD_SWITCH_FUNC 6
270 /* reserved: 34 */
271 /* reserved: 35 */
272 /* reserved: 36 */
273 /* reserved: 37 */
274 /* reserved: 50 */
275 /* reserved: 57 */
276
277
278/* Application specific commands for SD */
279#define ACMD_SET_BUS_WIDTH 6
280#define ACMD_SD_STATUS 13
281#define ACMD_SEND_NUM_WR_BLOCKS 22
282#define ACMD_SET_WR_BLK_ERASE_COUNT 23
283#define ACMD_SD_SEND_OP_COND 41
284#define ACMD_SET_CLR_CARD_DETECT 42
285#define ACMD_SEND_SCR 51
286
287/*
288 * EXT_CSD fields
289 */
290
291#define EXT_CSD_BUS_WIDTH 183 /* R/W */
292#define EXT_CSD_HS_TIMING 185 /* R/W */
293#define EXT_CSD_CARD_TYPE 196 /* RO */
294#define EXT_CSD_REV 192 /* RO */
295#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
296
297/*
298 * EXT_CSD field definitions
299 */
300
301#define EXT_CSD_CMD_SET_NORMAL 1
302#define EXT_CSD_CMD_SET_SECURE 2
303#define EXT_CSD_CMD_SET_CPSECURE 4
304
305#define EXT_CSD_CARD_TYPE_26 1
306#define EXT_CSD_CARD_TYPE_52 2
307
308#define EXT_CSD_BUS_WIDTH_1 0
309#define EXT_CSD_BUS_WIDTH_4 1
310#define EXT_CSD_BUS_WIDTH_8 2
311
312/*
313 * SD bus widths
314 */
315#define SD_BUS_WIDTH_1 0
316#define SD_BUS_WIDTH_4 2
317
280/* OCR bits */
281
282/*
283 * in SD 2.0 spec, bits 8-14 are now marked reserved
284 * Low voltage in SD2.0 spec is bit 7, TBD voltage
285 * Low voltage in MC 3.31 spec is bit 7, 1.65-1.95V
286 * Specs prior to MMC 3.31 defined bits 0-7 as voltages down to 1.5V.
287 * 3.31 redefined them to be reserved and also said that cards had to
288 * support the 2.7-3.6V and fixed the OCR to be 0xfff8000 for high voltage
289 * cards. MMC 4.0 says that a dual voltage card responds with 0xfff8080.
290 * Looks like the fine-grained control of the voltage tolerance ranges
291 * was abandoned.
292 *
293 * The MMC_OCR_CCS appears to be valid for only SD cards.
294 */
295#define MMC_OCR_VOLTAGE 0x3fffffffU /* Vdd Voltage mask */
296#define MMC_OCR_LOW_VOLTAGE (1u << 7) /* Low Voltage Range -- tbd */
297#define MMC_OCR_200_210 (1U << 8) /* Vdd voltage 2.00 ~ 2.10 */
298#define MMC_OCR_210_220 (1U << 9) /* Vdd voltage 2.10 ~ 2.20 */
299#define MMC_OCR_220_230 (1U << 10) /* Vdd voltage 2.20 ~ 2.30 */
300#define MMC_OCR_230_240 (1U << 11) /* Vdd voltage 2.30 ~ 2.40 */
301#define MMC_OCR_240_250 (1U << 12) /* Vdd voltage 2.40 ~ 2.50 */
302#define MMC_OCR_250_260 (1U << 13) /* Vdd voltage 2.50 ~ 2.60 */
303#define MMC_OCR_260_270 (1U << 14) /* Vdd voltage 2.60 ~ 2.70 */
304#define MMC_OCR_270_280 (1U << 15) /* Vdd voltage 2.70 ~ 2.80 */
305#define MMC_OCR_280_290 (1U << 16) /* Vdd voltage 2.80 ~ 2.90 */
306#define MMC_OCR_290_300 (1U << 17) /* Vdd voltage 2.90 ~ 3.00 */
307#define MMC_OCR_300_310 (1U << 18) /* Vdd voltage 3.00 ~ 3.10 */
308#define MMC_OCR_310_320 (1U << 19) /* Vdd voltage 3.10 ~ 3.20 */
309#define MMC_OCR_320_330 (1U << 20) /* Vdd voltage 3.20 ~ 3.30 */
310#define MMC_OCR_330_340 (1U << 21) /* Vdd voltage 3.30 ~ 3.40 */
311#define MMC_OCR_340_350 (1U << 22) /* Vdd voltage 3.40 ~ 3.50 */
312#define MMC_OCR_350_360 (1U << 23) /* Vdd voltage 3.50 ~ 3.60 */
313#define MMC_OCR_CCS (1u << 30) /* Card Capacity status (SD vs SDHC) */
314#define MMC_OCR_CARD_BUSY (1U << 31) /* Card Power up status */
315
316/* CSD -- decoded structure */
317struct mmc_cid {
318 uint32_t mid;
319 char pnm[8];
320 uint32_t psn;
321 uint16_t oid;
322 uint16_t mdt_year;
323 uint8_t mdt_month;
324 uint8_t prv;
325 uint8_t fwrev;
326};
327
328struct mmc_csd
329{
330 uint8_t csd_structure;
318/* OCR bits */
319
320/*
321 * in SD 2.0 spec, bits 8-14 are now marked reserved
322 * Low voltage in SD2.0 spec is bit 7, TBD voltage
323 * Low voltage in MC 3.31 spec is bit 7, 1.65-1.95V
324 * Specs prior to MMC 3.31 defined bits 0-7 as voltages down to 1.5V.
325 * 3.31 redefined them to be reserved and also said that cards had to
326 * support the 2.7-3.6V and fixed the OCR to be 0xfff8000 for high voltage
327 * cards. MMC 4.0 says that a dual voltage card responds with 0xfff8080.
328 * Looks like the fine-grained control of the voltage tolerance ranges
329 * was abandoned.
330 *
331 * The MMC_OCR_CCS appears to be valid for only SD cards.
332 */
333#define MMC_OCR_VOLTAGE 0x3fffffffU /* Vdd Voltage mask */
334#define MMC_OCR_LOW_VOLTAGE (1u << 7) /* Low Voltage Range -- tbd */
335#define MMC_OCR_200_210 (1U << 8) /* Vdd voltage 2.00 ~ 2.10 */
336#define MMC_OCR_210_220 (1U << 9) /* Vdd voltage 2.10 ~ 2.20 */
337#define MMC_OCR_220_230 (1U << 10) /* Vdd voltage 2.20 ~ 2.30 */
338#define MMC_OCR_230_240 (1U << 11) /* Vdd voltage 2.30 ~ 2.40 */
339#define MMC_OCR_240_250 (1U << 12) /* Vdd voltage 2.40 ~ 2.50 */
340#define MMC_OCR_250_260 (1U << 13) /* Vdd voltage 2.50 ~ 2.60 */
341#define MMC_OCR_260_270 (1U << 14) /* Vdd voltage 2.60 ~ 2.70 */
342#define MMC_OCR_270_280 (1U << 15) /* Vdd voltage 2.70 ~ 2.80 */
343#define MMC_OCR_280_290 (1U << 16) /* Vdd voltage 2.80 ~ 2.90 */
344#define MMC_OCR_290_300 (1U << 17) /* Vdd voltage 2.90 ~ 3.00 */
345#define MMC_OCR_300_310 (1U << 18) /* Vdd voltage 3.00 ~ 3.10 */
346#define MMC_OCR_310_320 (1U << 19) /* Vdd voltage 3.10 ~ 3.20 */
347#define MMC_OCR_320_330 (1U << 20) /* Vdd voltage 3.20 ~ 3.30 */
348#define MMC_OCR_330_340 (1U << 21) /* Vdd voltage 3.30 ~ 3.40 */
349#define MMC_OCR_340_350 (1U << 22) /* Vdd voltage 3.40 ~ 3.50 */
350#define MMC_OCR_350_360 (1U << 23) /* Vdd voltage 3.50 ~ 3.60 */
351#define MMC_OCR_CCS (1u << 30) /* Card Capacity status (SD vs SDHC) */
352#define MMC_OCR_CARD_BUSY (1U << 31) /* Card Power up status */
353
354/* CSD -- decoded structure */
355struct mmc_cid {
356 uint32_t mid;
357 char pnm[8];
358 uint32_t psn;
359 uint16_t oid;
360 uint16_t mdt_year;
361 uint8_t mdt_month;
362 uint8_t prv;
363 uint8_t fwrev;
364};
365
366struct mmc_csd
367{
368 uint8_t csd_structure;
369 uint8_t spec_vers;
331 uint16_t ccc;
332 uint16_t tacc;
333 uint32_t nsac;
334 uint32_t r2w_factor;
335 uint32_t tran_speed;
336 uint32_t read_bl_len;
337 uint32_t write_bl_len;
338 uint32_t vdd_r_curr_min;
339 uint32_t vdd_r_curr_max;
340 uint32_t vdd_w_curr_min;
341 uint32_t vdd_w_curr_max;
342 uint32_t wp_grp_size;
343 uint32_t sector_size; /* Erase sector size! */
344 uint64_t capacity;
345 unsigned int read_bl_partial:1,
346 read_blk_misalign:1,
347 write_bl_partial:1,
348 write_blk_misalign:1,
349 dsr_imp:1,
350 erase_blk_en:1,
351 wp_grp_enable:1;
352};
353
370 uint16_t ccc;
371 uint16_t tacc;
372 uint32_t nsac;
373 uint32_t r2w_factor;
374 uint32_t tran_speed;
375 uint32_t read_bl_len;
376 uint32_t write_bl_len;
377 uint32_t vdd_r_curr_min;
378 uint32_t vdd_r_curr_max;
379 uint32_t vdd_w_curr_min;
380 uint32_t vdd_w_curr_max;
381 uint32_t wp_grp_size;
382 uint32_t sector_size; /* Erase sector size! */
383 uint64_t capacity;
384 unsigned int read_bl_partial:1,
385 read_blk_misalign:1,
386 write_bl_partial:1,
387 write_blk_misalign:1,
388 dsr_imp:1,
389 erase_blk_en:1,
390 wp_grp_enable:1;
391};
392
393struct mmc_scr
394{
395 unsigned char sda_vsn;
396 unsigned char bus_widths;
397#define SD_SCR_BUS_WIDTH_1 (1<<0)
398#define SD_SCR_BUS_WIDTH_4 (1<<2)
399};
400
354/*
355 * Older versions of the MMC standard had a variable sector size. However,
356 * I've been able to find no old MMC or SD cards that have a non 512
357 * byte sector size anywhere, so we assume that such cards are very rare
358 * and only note their existance in passing here...
359 */
360#define MMC_SECTOR_SIZE 512
361
362#endif /* DEV_MMCREG_H */
401/*
402 * Older versions of the MMC standard had a variable sector size. However,
403 * I've been able to find no old MMC or SD cards that have a non 512
404 * byte sector size anywhere, so we assume that such cards are very rare
405 * and only note their existance in passing here...
406 */
407#define MMC_SECTOR_SIZE 512
408
409#endif /* DEV_MMCREG_H */