VoodooSDHCI

VoodooSDHCI Svn Source Tree

Root/trunk/SD_Commands.h

  • Property svn:executable set to *
1#ifndef SD_H
2#define SD_H
3
4#include "License.h"
5#include "SD_Misc.h"
6
7/* SD commands type argument response */
8 /* class 0 */
9/* This is basically the same command as for MMC with some quirks. */
10#define SD_SEND_RELATIVE_ADDR 3 /* bcr R6 */
11#define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7 */
12
13 /* class 10 */
14#define SD_SWITCH 6 /* adtc [31:0] See below R1 */
15
16 /* Application commands */
17#define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */
18#define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */
19#define SD_APP_SET_WR_BLK_ERASE_COUNT 23/* R1 */
20#define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */
21#define SD_APP_SEND_SCR 51 /* adtc R1 */
22
23/* Standard MMC commands (4.1) type argument response */
24 /* class 1 */
25#define SD_GO_IDLE_STATE 0 /* bc */
26#define SD_SEND_OP_COND 1 /* bcr [31:0] OCR R3 */
27#define SD_ALL_SEND_CID 2 /* bcr R2 */
28#define SD_SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */
29#define SD_SET_DSR 4 /* bc [31:16] RCA */
30#define SD_SWITCH 6 /* ac [31:0] See below R1b */
31#define SD_SELECT_CARD 7 /* ac [31:16] RCA R1 */
32#define SD_SEND_EXT_CSD 8 /* adtc R1 */
33#define SD_SEND_CSD 9 /* ac [31:16] RCA R2 */
34#define SD_SEND_CID 10 /* ac [31:16] RCA R2 */
35#define SD_READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */
36#define SD_STOP_TRANSMISSION 12 /* ac R1b */
37#define SD_SEND_STATUS 13 /* ac [31:16] RCA R1 */
38#define SD_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */
39#define SD_SPI_READ_OCR 58 /* spi spi_R3 */
40#define SD_SPI_CRC_ON_OFF 59 /* spi [0:0] flag spi_R1 */
41
42 /* class 2 */
43#define SD_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */
44#define SD_READ_SINGLE_BLOCK 17 /* adtc [31:0] data addr R1 */
45#define SD_READ_MULTIPLE_BLOCK 18 /* adtc [31:0] data addr R1 */
46
47 /* class 3 */
48#define SD_WRITE_DAT_UNTIL_STOP 20 /* adtc [31:0] data addr R1 */
49
50 /* class 4 */
51#define SD_SET_BLOCK_COUNT 23 /* adtc [31:0] data addr R1 */
52#define SD_WRITE_BLOCK 24 /* adtc [31:0] data addr R1 */
53#define SD_WRITE_MULTIPLE_BLOCK 25 /* adtc R1 */
54#define SD_PROGRAM_CID 26 /* adtc R1 */
55#define SD_PROGRAM_CSD 27 /* adtc R1 */
56
57 /* class 6 */
58#define SD_SET_WRITE_PROT 28 /* ac [31:0] data addr R1b */
59#define SD_CLR_WRITE_PROT 29 /* ac [31:0] data addr R1b */
60#define SD_SEND_WRITE_PROT 30 /* adtc [31:0] wpdata addr R1 */
61
62 /* class 5 */
63#define SD_ERASE_GROUP_START 35 /* ac [31:0] data addr R1 */
64#define SD_ERASE_GROUP_END 36 /* ac [31:0] data addr R1 */
65#define SD_ERASE 38 /* ac R1b */
66
67 /* class 9 */
68#define SD_FAST_IO 39 /* ac <Complex> R4 */
69#define SD_GO_IRQ_STATE 40 /* bcr R5 */
70
71 /* class 7 */
72#define SD_LOCK_UNLOCK 42 /* adtc R1b */
73
74 /* class 8 */
75#define SD_APP_CMD 55 /* ac [31:16] RCA R1 */
76#define SD_GEN_CMD 56 /* adtc [0] RD/WR R1 */
77
78/*
79 * MMC_SWITCH argument format:
80 *
81 *[31:26] Always 0
82 *[25:24] Access Mode
83 *[23:16] Location of target Byte in EXT_CSD
84 *[15:08] Value Byte
85 *[07:03] Always 0
86 *[02:00] Command Set
87 */
88
89/*
90 MMC status in R1, for native mode (SPI bits are different)
91 Type
92e : error bit
93s : status bit
94r : detected and set for the actual command response
95x : detected and set during command execution. the host must poll
96 the card by sending status command in order to read these bits.
97 Clear condition
98a : according to the card state
99b : always related to the previous command. Reception of
100 a valid command will clear it (with a delay of one command)
101c : clear by read
102 */
103
104#define R1_OUT_OF_RANGE(1 << 31)/* er, c */
105#define R1_ADDRESS_ERROR(1 << 30)/* erx, c */
106#define R1_BLOCK_LEN_ERROR(1 << 29)/* er, c */
107#define R1_ERASE_SEQ_ERROR (1 << 28)/* er, c */
108#define R1_ERASE_PARAM(1 << 27)/* ex, c */
109#define R1_WP_VIOLATION(1 << 26)/* erx, c */
110#define R1_CARD_IS_LOCKED(1 << 25)/* sx, a */
111#define R1_LOCK_UNLOCK_FAILED(1 << 24)/* erx, c */
112#define R1_COM_CRC_ERROR(1 << 23)/* er, b */
113#define R1_ILLEGAL_COMMAND(1 << 22)/* er, b */
114#define R1_CARD_ECC_FAILED(1 << 21)/* ex, c */
115#define R1_CC_ERROR(1 << 20)/* erx, c */
116#define R1_ERROR(1 << 19)/* erx, c */
117#define R1_UNDERRUN(1 << 18)/* ex, c */
118#define R1_OVERRUN(1 << 17)/* ex, c */
119#define R1_CID_CSD_OVERWRITE(1 << 16)/* erx, c, CID/CSD overwrite */
120#define R1_WP_ERASE_SKIP(1 << 15)/* sx, c */
121#define R1_CARD_ECC_DISABLED(1 << 14)/* sx, a */
122#define R1_ERASE_RESET(1 << 13)/* sr, c */
123#define R1_STATUS(x) (x & 0xFFFFE000)
124#define R1_CURRENT_STATE(x)((x & 0x00001E00) >> 9)/* sx, b (4 bits) */
125#define R1_READY_FOR_DATA(1 << 8)/* sx, a */
126#define R1_APP_CMD(1 << 5)/* sr, c */
127
128/*
129 * MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
130 * R1 is the low order byte; R2 is the next highest byte, when present.
131 */
132#define R1_SPI_IDLE(1 << 0)
133#define R1_SPI_ERASE_RESET(1 << 1)
134#define R1_SPI_ILLEGAL_COMMAND(1 << 2)
135#define R1_SPI_COM_CRC(1 << 3)
136#define R1_SPI_ERASE_SEQ(1 << 4)
137#define R1_SPI_ADDRESS(1 << 5)
138#define R1_SPI_PARAMETER(1 << 6)
139/* R1 bit 7 is always zero */
140#define R2_SPI_CARD_LOCKED(1 << 8)
141#define R2_SPI_WP_ERASE_SKIP(1 << 9)/* or lock/unlock fail */
142#define R2_SPI_LOCK_UNLOCK_FAILR2_SPI_WP_ERASE_SKIP
143#define R2_SPI_ERROR(1 << 10)
144#define R2_SPI_CC_ERROR(1 << 11)
145#define R2_SPI_CARD_ECC_ERROR(1 << 12)
146#define R2_SPI_WP_VIOLATION(1 << 13)
147#define R2_SPI_ERASE_PARAM(1 << 14)
148#define R2_SPI_OUT_OF_RANGE(1 << 15)/* or CSD overwrite */
149#define R2_SPI_CSD_OVERWRITER2_SPI_OUT_OF_RANGE
150
151/* These are unpacked versions of the actual responses */
152
153struct _mmc_csd {
154UInt8 csd_structure;
155UInt8 spec_vers;
156UInt8 taac;
157UInt8 nsac;
158UInt8 tran_speed;
159UInt16 ccc;
160UInt8 read_bl_len;
161UInt8 read_bl_partial;
162UInt8 write_blk_misalign;
163UInt8 read_blk_misalign;
164UInt8 dsr_imp;
165UInt16 c_size;
166UInt8 vdd_r_curr_min;
167UInt8 vdd_r_curr_max;
168UInt8 vdd_w_curr_min;
169UInt8 vdd_w_curr_max;
170UInt8 c_size_mult;
171union {
172struct { /* MMC system specification version 3.1 */
173UInt8 erase_grp_size;
174UInt8 erase_grp_mult;
175} v31;
176struct { /* MMC system specification version 2.2 */
177UInt8 sector_size;
178UInt8 erase_grp_size;
179} v22;
180} erase;
181UInt8 wp_grp_size;
182UInt8 wp_grp_enable;
183UInt8 default_ecc;
184UInt8 r2w_factor;
185UInt8 write_bl_len;
186UInt8 write_bl_partial;
187UInt8 file_format_grp;
188UInt8 copy;
189UInt8 perm_write_protect;
190UInt8 tmp_write_protect;
191UInt8 file_format;
192UInt8 ecc;
193};
194
195/*
196 * OCR bits are mostly in host.h
197 */
198#define MMC_CARD_BUSY0x80000000/* Card Power up status bit */
199
200/*
201 * Card Command Classes (CCC)
202 */
203#define CCC_BASIC(1<<0)/* (0) Basic protocol functions */
204/* (CMD0,1,2,3,4,7,9,10,12,13,15) */
205/* (and for SPI, CMD58,59) */
206#define CCC_STREAM_READ(1<<1)/* (1) Stream read commands */
207/* (CMD11) */
208#define CCC_BLOCK_READ(1<<2)/* (2) Block read commands */
209/* (CMD16,17,18) */
210#define CCC_STREAM_WRITE(1<<3)/* (3) Stream write commands */
211/* (CMD20) */
212#define CCC_BLOCK_WRITE(1<<4)/* (4) Block write commands */
213/* (CMD16,24,25,26,27) */
214#define CCC_ERASE(1<<5)/* (5) Ability to erase blocks */
215/* (CMD32,33,34,35,36,37,38,39) */
216#define CCC_WRITE_PROT(1<<6)/* (6) Able to write protect blocks */
217/* (CMD28,29,30) */
218#define CCC_LOCK_CARD(1<<7)/* (7) Able to lock down card */
219/* (CMD16,CMD42) */
220#define CCC_APP_SPEC(1<<8)/* (8) Application specific */
221/* (CMD55,56,57,ACMD*) */
222#define CCC_IO_MODE(1<<9)/* (9) I/O mode */
223/* (CMD5,39,40,52,53) */
224#define CCC_SWITCH(1<<10)/* (10) High speed switch */
225/* (CMD6,34,35,36,37,50) */
226/* (11) Reserved */
227/* (CMD?) */
228
229/*
230 * CSD field definitions
231 */
232
233#define CSD_STRUCT_VER_1_0 0 /* Valid for system specification 1.0 - 1.2 */
234#define CSD_STRUCT_VER_1_1 1 /* Valid for system specification 1.4 - 2.2 */
235#define CSD_STRUCT_VER_1_2 2 /* Valid for system specification 3.1 - 3.2 - 3.31 - 4.0 - 4.1 */
236#define CSD_STRUCT_EXT_CSD 3 /* Version is coded in CSD_STRUCTURE in EXT_CSD */
237
238#define CSD_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.2 */
239#define CSD_SPEC_VER_1 1 /* Implements system specification 1.4 */
240#define CSD_SPEC_VER_2 2 /* Implements system specification 2.0 - 2.2 */
241#define CSD_SPEC_VER_3 3 /* Implements system specification 3.1 - 3.2 - 3.31 */
242#define CSD_SPEC_VER_4 4 /* Implements system specification 4.0 - 4.1 */
243
244/*
245 * EXT_CSD fields
246 */
247
248#define EXT_CSD_BUS_WIDTH183/* R/W */
249#define EXT_CSD_HS_TIMING185/* R/W */
250#define EXT_CSD_CARD_TYPE196/* RO */
251#define EXT_CSD_REV192/* RO */
252#define EXT_CSD_SEC_CNT212/* RO, 4 bytes */
253
254/*
255 * EXT_CSD field definitions
256 */
257
258#define EXT_CSD_CMD_SET_NORMAL(1<<0)
259#define EXT_CSD_CMD_SET_SECURE(1<<1)
260#define EXT_CSD_CMD_SET_CPSECURE(1<<2)
261
262#define EXT_CSD_CARD_TYPE_26(1<<0)/* Card can run at 26MHz */
263#define EXT_CSD_CARD_TYPE_52(1<<1)/* Card can run at 52MHz */
264
265#define EXT_CSD_BUS_WIDTH_10/* Card is in 1 bit mode */
266#define EXT_CSD_BUS_WIDTH_41/* Card is in 4 bit mode */
267#define EXT_CSD_BUS_WIDTH_82/* Card is in 8 bit mode */
268
269/*
270 * MMC_SWITCH access modes
271 */
272
273#define MMC_SWITCH_MODE_CMD_SET0x00/* Change the command set */
274#define MMC_SWITCH_MODE_SET_BITS0x01/* Set bits which are 1 in value */
275#define MMC_SWITCH_MODE_CLEAR_BITS0x02/* Clear bits which are 1 in value */
276#define MMC_SWITCH_MODE_WRITE_BYTE0x03/* Set target to value */
277
278/*
279 * SD_SWITCH argument format:
280 *
281 * [31] Check (0) or switch (1)
282 * [30:24] Reserved (0)
283 * [23:20] Function group 6
284 * [19:16] Function group 5
285 * [15:12] Function group 4
286 * [11:8] Function group 3
287 * [7:4] Function group 2
288 * [3:0] Function group 1
289 */
290
291/*
292 * SD_SEND_IF_COND argument format:
293 *
294 *[31:12] Reserved (0)
295 *[11:8] Host Voltage Supply Flags
296 *[7:0] Check Pattern (0xAA)
297 */
298
299/*
300 * SCR field definitions
301 */
302
303#define SCR_SPEC_VER_00/* Implements system specification 1.0 - 1.01 */
304#define SCR_SPEC_VER_11/* Implements system specification 1.10 */
305#define SCR_SPEC_VER_22/* Implements system specification 2.00 */
306
307/*
308 * SD bus widths
309 */
310#define SD_BUS_WIDTH_10
311#define SD_BUS_WIDTH_42
312
313/*
314 * SD_SWITCH mode
315 */
316#define SD_SWITCH_CHECK0
317#define SD_SWITCH_SET1
318
319/*
320 * SD_SWITCH function groups
321 */
322#define SD_SWITCH_GRP_ACCESS0
323
324/*
325 * SD_SWITCH access modes
326 */
327#define SD_SWITCH_ACCESS_DEF0
328#define SD_SWITCH_ACCESS_HS1
329
330/**********************************/
331/* From original SDHCI OSX driver */
332/**********************************/
333#define R00
334#define R11
335#define R1b2
336#define R23
337#define R34
338#define R45
339#define R56
340#define R5b 7
341#define R68
342#define R79
343
344#define SDCR0R0
345#define SDCR1R0
346#define SDCR2R2
347#define SDCR3R6
348#define SDCR4R0
349#define SDCR5R0
350#define SDCR6R1
351#define SDCR7R1b
352#define SDCR8R7
353#define SDCR9R2
354#define SDCR10R2
355#define SDCR11R0
356#define SDCR12R1b
357#define SDCR13R1
358#define SDCR14R0
359#define SDCR15R0
360#define SDCR16R1
361#define SDCR17R1
362#define SDCR18R1
363#define SDCR19R0
364#define SDCR20R0
365#define SDCR21R0
366#define SDCR22R0
367#define SDCR23R0
368#define SDCR24R1
369#define SDCR25R1
370#define SDCR26R0
371#define SDCR27R1
372#define SDCR28R1b
373#define SDCR29R1b
374#define SDCR30R1
375#define SDCR31R0
376#define SDCR32R1
377#define SDCR33R1
378#define SDCR34R0
379#define SDCR35R0
380#define SDCR36R0
381#define SDCR37R0
382#define SDCR38R1b
383#define SDCR39R0
384#define SDCR40R0
385#define SDCR41R0
386#define SDCR42R1
387#define SDCR43R0
388#define SDCR44R0
389#define SDCR45R0
390#define SDCR46R0
391#define SDCR47R0
392#define SDCR48R0
393#define SDCR49R0
394#define SDCR50R0
395#define SDCR51R0
396#define SDCR52R0
397#define SDCR53R0
398#define SDCR54R0
399#define SDCR55R1
400#define SDCR56R1
401#define SDCR57R0
402#define SDCR58R0
403#define SDCR59R0
404#define SDCR60R0
405#define SDCR61R0
406#define SDCR62R0
407#define SDCR63R0
408
409#define SDACR0R0
410#define SDACR1R0
411#define SDACR2R0
412#define SDACR3R0
413#define SDACR4R0
414#define SDACR5R0
415#define SDACR6R1
416#define SDACR7R0
417#define SDACR8R0
418#define SDACR9R0
419#define SDACR10R0
420#define SDACR11R0
421#define SDACR12R0
422#define SDACR13R1
423#define SDACR14R0
424#define SDACR15R0
425#define SDACR16R0
426#define SDACR17R0
427#define SDACR18R0
428#define SDACR19R0
429#define SDACR20R0
430#define SDACR21R1
431#define SDACR22R1
432#define SDACR23R0
433#define SDACR24R0
434#define SDACR25R0
435#define SDACR26R0
436#define SDACR27R0
437#define SDACR28R0
438#define SDACR29R0
439#define SDACR30R0
440#define SDACR31R0
441#define SDACR32R0
442#define SDACR33R0
443#define SDACR34R0
444#define SDACR35R0
445#define SDACR36R0
446#define SDACR37R0
447#define SDACR38R0
448#define SDACR39R0
449#define SDACR40R0
450#define SDACR41R3
451#define SDACR42R1
452#define SDACR43R0
453#define SDACR44R0
454#define SDACR45R0
455#define SDACR46R0
456#define SDACR47R0
457#define SDACR48R0
458#define SDACR49R0
459#define SDACR50R0
460#define SDACR51R1
461#define SDACR52R0
462#define SDACR53R0
463#define SDACR54R0
464#define SDACR55R0
465#define SDACR56R0
466#define SDACR57R0
467#define SDACR58R0
468#define SDACR59R0
469#define SDACR60R0
470#define SDACR61R0
471#define SDACR62R0
472#define SDACR63R0
473
474#endif /* SD_H */
475

Archive Download this file

Revision: HEAD