1 /** @file
2   Header file for SD memory card support.
3 
4   This header file contains some definitions defined in SD Physical Layer Simplified
5   Specification Version 4.10 spec.
6 
7   Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
8   This program and the accompanying materials
9   are licensed and made available under the terms and conditions of the BSD License
10   which accompanies this distribution.  The full text of the license may be found at
11   http://opensource.org/licenses/bsd-license.php
12 
13   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 
16 **/
17 
18 #ifndef __SD_H__
19 #define __SD_H__
20 
21 //
22 // SD command index
23 //
24 #define  SD_GO_IDLE_STATE           0
25 #define  SD_ALL_SEND_CID            2
26 #define  SD_SET_RELATIVE_ADDR       3
27 #define  SD_SET_DSR                 4
28 #define  SDIO_SEND_OP_COND          5
29 #define  SD_SWITCH_FUNC             6
30 #define  SD_SELECT_DESELECT_CARD    7
31 #define  SD_SEND_IF_COND            8
32 #define  SD_SEND_CSD                9
33 #define  SD_SEND_CID                10
34 #define  SD_VOLTAGE_SWITCH          11
35 #define  SD_STOP_TRANSMISSION       12
36 #define  SD_SEND_STATUS             13
37 #define  SD_GO_INACTIVE_STATE       15
38 #define  SD_SET_BLOCKLEN            16
39 #define  SD_READ_SINGLE_BLOCK       17
40 #define  SD_READ_MULTIPLE_BLOCK     18
41 #define  SD_SEND_TUNING_BLOCK       19
42 #define  SD_SPEED_CLASS_CONTROL     20
43 #define  SD_SET_BLOCK_COUNT         23
44 #define  SD_WRITE_SINGLE_BLOCK      24
45 #define  SD_WRITE_MULTIPLE_BLOCK    25
46 #define  SD_PROGRAM_CSD             27
47 #define  SD_SET_WRITE_PROT          28
48 #define  SD_CLR_WRITE_PROT          29
49 #define  SD_SEND_WRITE_PROT         30
50 #define  SD_ERASE_WR_BLK_START      32
51 #define  SD_ERASE_WR_BLK_END        33
52 #define  SD_ERASE                   38
53 #define  SD_LOCK_UNLOCK             42
54 #define  SD_READ_EXTR_SINGLE        48
55 #define  SD_WRITE_EXTR_SINGLE       49
56 #define  SDIO_RW_DIRECT             52
57 #define  SDIO_RW_EXTENDED           53
58 #define  SD_APP_CMD                 55
59 #define  SD_GEN_CMD                 56
60 #define  SD_READ_EXTR_MULTI         58
61 #define  SD_WRITE_EXTR_MULTI        59
62 
63 #define  SD_SET_BUS_WIDTH           6           // ACMD6
64 #define  SD_STATUS                  13          // ACMD13
65 #define  SD_SEND_NUM_WR_BLOCKS      22          // ACMD22
66 #define  SD_SET_WR_BLK_ERASE_COUNT  23          // ACMD23
67 #define  SD_SEND_OP_COND            41          // ACMD41
68 #define  SD_SET_CLR_CARD_DETECT     42          // ACMD42
69 #define  SD_SEND_SCR                51          // ACMD51
70 
71 #pragma pack(1)
72 typedef struct {
73   UINT8   NotUsed:1;                            // Not used [0:0]
74   UINT8   Crc:7;                                // CRC [7:1]
75   UINT16  ManufacturingDate:12;                 // Manufacturing date [19:8]
76   UINT16  Reserved:4;                           // Reserved [23:20]
77   UINT8   ProductSerialNumber[4];               // Product serial number [55:24]
78   UINT8   ProductRevision;                      // Product revision [63:56]
79   UINT8   ProductName[5];                       // Product name [103:64]
80   UINT8   OemId[2];                             // OEM/Application ID [119:104]
81   UINT8   ManufacturerId;                       // Manufacturer ID [127:120]
82 } SD_CID;
83 
84 typedef struct {
85   UINT32  NotUsed:1;                            // Not used [0:0]
86   UINT32  Crc:7;                                // CRC [7:1]
87   UINT32  Reserved:2;                           // Reserved [9:8]
88   UINT32  FileFormat:2;                         // File format [11:10]
89   UINT32  TmpWriteProtect:1;                    // Temporary write protection [12:12]
90   UINT32  PermWriteProtect:1;                   // Permanent write protection [13:13]
91   UINT32  Copy:1;                               // Copy flag (OTP) [14:14]
92   UINT32  FileFormatGrp:1;                      // File format group [15:15]
93   UINT32  Reserved1:5;                          // Reserved [20:16]
94   UINT32  WriteBlPartial:1;                     // Partial blocks for write allowed [21:21]
95   UINT32  WriteBlLen:4;                         // Max. write data block length [25:22]
96   UINT32  R2WFactor:3;                          // Write speed factor [28:26]
97   UINT32  Reserved2:2;                          // Manufacturer default ECC [30:29]
98   UINT32  WpGrpEnable:1;                        // Write protect group enable [31:31]
99 
100   UINT32  WpGrpSize:7;                          // Write protect group size [38:32]
101   UINT32  SectorSize:7;                         // Erase sector size [45:39]
102   UINT32  EraseBlkEn:1;                         // Erase single block enable [46:46]
103   UINT32  CSizeMul:3;                           // device size multiplier [49:47]
104   UINT32  VddWCurrMax:3;                        // max. write current @VDD max [52:50]
105   UINT32  VddWCurrMin:3;                        // max. write current @VDD min [55:53]
106   UINT32  VddRCurrMax:3;                        // max. read current @VDD max [58:56]
107   UINT32  VddRCurrMin:3;                        // max. read current @VDD min [61:59]
108   UINT32  CSizeLow:2;                           // Device size low 2 bits [63:62]
109 
110   UINT32  CSizeHigh:10;                         // Device size high 10 bits [73:64]
111   UINT32  Reserved4:2;                          // Reserved [75:74]
112   UINT32  DsrImp:1;                             // DSR implemented [76:76]
113   UINT32  ReadBlkMisalign:1;                    // Read block misalignment [77:77]
114   UINT32  WriteBlkMisalign:1;                   // Write block misalignment [78:78]
115   UINT32  ReadBlPartial:1;                      // Partial blocks for read allowed [79:79]
116   UINT32  ReadBlLen:4;                          // Max. read data block length [83:80]
117   UINT32  Ccc:12;                               // Card command classes [95:84]
118 
119   UINT32  TranSpeed:8;                          // Max. data transfer rate [103:96]
120   UINT32  Nsac:8;                               // Data read access-time in CLK cycles (NSAC*100) [111:104]
121   UINT32  Taac:8;                               // Data read access-time [119:112]
122   UINT32  Reserved5:6;                          // Reserved [125:120]
123   UINT32  CsdStructure:2;                       // CSD structure [127:126]
124 } SD_CSD;
125 
126 typedef struct {
127   UINT32  NotUsed:1;                            // Not used [0:0]
128   UINT32  Crc:7;                                // CRC [7:1]
129   UINT32  Reserved:2;                           // Reserved [9:8]
130   UINT32  FileFormat:2;                         // File format [11:10]
131   UINT32  TmpWriteProtect:1;                    // Temporary write protection [12:12]
132   UINT32  PermWriteProtect:1;                   // Permanent write protection [13:13]
133   UINT32  Copy:1;                               // Copy flag (OTP) [14:14]
134   UINT32  FileFormatGrp:1;                      // File format group [15:15]
135   UINT32  Reserved1:5;                          // Reserved [20:16]
136   UINT32  WriteBlPartial:1;                     // Partial blocks for write allowed [21:21]
137   UINT32  WriteBlLen:4;                         // Max. write data block length [25:22]
138   UINT32  R2WFactor:3;                          // Write speed factor [28:26]
139   UINT32  Reserved2:2;                          // Manufacturer default ECC [30:29]
140   UINT32  WpGrpEnable:1;                        // Write protect group enable [31:31]
141 
142   UINT32  WpGrpSize:7;                          // Write protect group size [38:32]
143   UINT32  SectorSize:7;                         // Erase sector size [45:39]
144   UINT32  EraseBlkEn:1;                         // Erase single block enable [46:46]
145   UINT32  Reserved3:1;                          // Reserved [47:47]
146   UINT32  CSizeLow:16;                          // Device size low 16 bits [63:48]
147 
148   UINT32  CSizeHigh:6;                          // Device size high 6 bits [69:64]
149   UINT32  Reserved4:6;                          // Reserved [75:70]
150   UINT32  DsrImp:1;                             // DSR implemented [76:76]
151   UINT32  ReadBlkMisalign:1;                    // Read block misalignment [77:77]
152   UINT32  WriteBlkMisalign:1;                   // Write block misalignment [78:78]
153   UINT32  ReadBlPartial:1;                      // Partial blocks for read allowed [79:79]
154   UINT32  ReadBlLen:4;                          // Max. read data block length [83:80]
155   UINT32  Ccc:12;                               // Card command classes [95:84]
156 
157   UINT32  TranSpeed:8;                          // Max. data transfer rate [103:96]
158   UINT32  Nsac:8;                               // Data read access-time in CLK cycles (NSAC*100) [111:104]
159   UINT32  Taac:8;                               // Data read access-time [119:112]
160   UINT32  Reserved5:6;                          // Reserved [125:120]
161   UINT32  CsdStructure:2;                       // CSD structure [127:126]
162 } SD_CSD2;
163 
164 typedef struct {
165   UINT32  Reserved;                             // Reserved [31:0]
166 
167   UINT32  CmdSupport:4;                         // Command Support bits [35:32]
168   UINT32  Reserved1:6;                          // Reserved [41:36]
169   UINT32  SdSpec4:1;                            // Spec. Version 4.00 or higher [42:42]
170   UINT32  ExSecurity:4;                         // Extended Security Support [46:43]
171   UINT32  SdSpec3:1;                            // Spec. Version 3.00 or higher [47:47]
172   UINT32  SdBusWidths:4;                        // DAT Bus widths supported [51:48]
173   UINT32  SdSecurity:3;                         // CPRM security support [54:52]
174   UINT32  DataStatAfterErase:1;                 // Data status after erases [55]
175   UINT32  SdSpec:4;                             // SD Memory Card Spec. Version [59:56]
176   UINT32  ScrStructure:4;                       // SCR Structure [63:60]
177 } SD_SCR;
178 
179 #pragma pack()
180 
181 #endif
182