Moving OMAP 3530 code out of BeagleBoard package into its own package
[mirror_edk2.git] / Omap35xxPkg / MMCHSDxe / MMCHS.h
1 /** @file
2
3 Copyright (c) 2008-2009 Apple Inc. All rights reserved.<BR>
4
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _MMCHS_H_
16 #define _MMCHS_H_
17
18 #include <Library/BaseLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/IoLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24
25 #include <Protocol/EmbeddedExternalDevice.h>
26 #include <Protocol/BlockIo.h>
27 #include <Protocol/Cpu.h>
28 #include <Protocol/DevicePath.h>
29
30 #include <Omap3530/Omap3530.h>
31 #include <TPS65950.h>
32
33 #define MAX_RETRY_COUNT 100
34
35 #define HCS (0x1UL << 30) //Host capacity support/1 = Supporting high capacity
36 #define CCS (0x1UL << 30) //Card capacity status/1 = High capacity card
37 typedef struct {
38 UINT32 Reserved0: 7; // 0
39 UINT32 V170_V195: 1; // 1.70V - 1.95V
40 UINT32 V200_V260: 7; // 2.00V - 2.60V
41 UINT32 V270_V360: 9; // 2.70V - 3.60V
42 UINT32 RESERVED_1: 5; // Reserved
43 UINT32 AccessMode: 2; // 00b (byte mode), 10b (sector mode)
44 UINT32 Busy: 1; // This bit is set to LOW if the card has not finished the power up routine
45 }OCR;
46
47 typedef struct {
48 UINT32 NOT_USED; // 1 [0:0]
49 UINT32 CRC; // CRC7 checksum [7:1]
50 UINT32 MDT; // Manufacturing date [19:8]
51 UINT32 RESERVED_1; // Reserved [23:20]
52 UINT32 PSN; // Product serial number [55:24]
53 UINT8 PRV; // Product revision [63:56]
54 UINT8 PNM[5]; // Product name [64:103]
55 UINT16 OID; // OEM/Application ID [119:104]
56 UINT8 MID; // Manufacturer ID [127:120]
57 }CID;
58
59 typedef struct {
60 UINT8 NOT_USED: 1; // Not used, always 1 [0:0]
61 UINT8 CRC: 7; // CRC [7:1]
62 UINT8 RESERVED_1: 2; // Reserved [9:8]
63 UINT8 FILE_FORMAT: 2; // File format [11:10]
64 UINT8 TMP_WRITE_PROTECT: 1; // Temporary write protection [12:12]
65 UINT8 PERM_WRITE_PROTECT: 1; // Permanent write protection [13:13]
66 UINT8 COPY: 1; // Copy flag (OTP) [14:14]
67 UINT8 FILE_FORMAT_GRP: 1; // File format group [15:15]
68 UINT16 RESERVED_2: 5; // Reserved [20:16]
69 UINT16 WRITE_BL_PARTIAL: 1; // Partial blocks for write allowed [21:21]
70 UINT16 WRITE_BL_LEN: 4; // Max. write data block length [25:22]
71 UINT16 R2W_FACTOR: 3; // Write speed factor [28:26]
72 UINT16 RESERVED_3: 2; // Reserved [30:29]
73 UINT16 WP_GRP_ENABLE: 1; // Write protect group enable [31:31]
74 UINT32 WP_GRP_SIZE: 7; // Write protect group size [38:32]
75 UINT32 SECTOR_SIZE: 7; // Erase sector size [45:39]
76 UINT32 ERASE_BLK_EN: 1; // Erase single block enable [46:46]
77 UINT32 C_SIZE_MULT: 3; // Device size multiplier [49:47]
78 UINT32 VDD_W_CURR_MAX: 3; // Max. write current @ VDD max [52:50]
79 UINT32 VDD_W_CURR_MIN: 3; // Max. write current @ VDD min [55:53]
80 UINT32 VDD_R_CURR_MAX: 3; // Max. read current @ VDD max [58:56]
81 UINT32 VDD_R_CURR_MIN: 3; // Max. read current @ VDD min [61:59]
82 UINT32 C_SIZELow2: 2; // Device size [73:62]
83 UINT32 C_SIZEHigh10: 10;// Device size [73:62]
84 UINT32 RESERVED_4: 2; // Reserved [75:74]
85 UINT32 DSR_IMP: 1; // DSR implemented [76:76]
86 UINT32 READ_BLK_MISALIGN: 1; // Read block misalignment [77:77]
87 UINT32 WRITE_BLK_MISALIGN: 1; // Write block misalignment [78:78]
88 UINT32 READ_BL_PARTIAL: 1; // Partial blocks for read allowed [79:79]
89 UINT32 READ_BL_LEN: 4; // Max. read data block length [83:80]
90 UINT32 CCC: 12;// Card command classes [95:84]
91 UINT8 TRAN_SPEED ; // Max. bus clock frequency [103:96]
92 UINT8 NSAC ; // Data read access-time 2 in CLK cycles (NSAC*100) [111:104]
93 UINT8 TAAC ; // Data read access-time 1 [119:112]
94 UINT8 RESERVED_5: 6; // Reserved [125:120]
95 UINT8 CSD_STRUCTURE: 2; // CSD structure [127:126]
96 }CSD;
97
98 typedef struct {
99 UINT8 NOT_USED: 1; // Not used, always 1 [0:0]
100 UINT8 CRC: 7; // CRC [7:1]
101 UINT8 RESERVED_1: 2; // Reserved [9:8]
102 UINT8 FILE_FORMAT: 2; // File format [11:10]
103 UINT8 TMP_WRITE_PROTECT: 1; // Temporary write protection [12:12]
104 UINT8 PERM_WRITE_PROTECT: 1; // Permanent write protection [13:13]
105 UINT8 COPY: 1; // Copy flag (OTP) [14:14]
106 UINT8 FILE_FORMAT_GRP: 1; // File format group [15:15]
107 UINT16 RESERVED_2: 5; // Reserved [20:16]
108 UINT16 WRITE_BL_PARTIAL: 1; // Partial blocks for write allowed [21:21]
109 UINT16 WRITE_BL_LEN: 4; // Max. write data block length [25:22]
110 UINT16 R2W_FACTOR: 3; // Write speed factor [28:26]
111 UINT16 RESERVED_3: 2; // Reserved [30:29]
112 UINT16 WP_GRP_ENABLE: 1; // Write protect group enable [31:31]
113 UINT16 WP_GRP_SIZE: 7; // Write protect group size [38:32]
114 UINT16 SECTOR_SIZE: 7; // Erase sector size [45:39]
115 UINT16 ERASE_BLK_EN: 1; // Erase single block enable [46:46]
116 UINT16 RESERVED_4: 1; // Reserved [47:47]
117 UINT32 C_SIZELow16: 16;// Device size [69:48]
118 UINT32 C_SIZEHigh6: 6; // Device size [69:48]
119 UINT32 RESERVED_5: 6; // Reserved [75:70]
120 UINT32 DSR_IMP: 1; // DSR implemented [76:76]
121 UINT32 READ_BLK_MISALIGN: 1; // Read block misalignment [77:77]
122 UINT32 WRITE_BLK_MISALIGN: 1; // Write block misalignment [78:78]
123 UINT32 READ_BL_PARTIAL: 1; // Partial blocks for read allowed [79:79]
124 UINT16 READ_BL_LEN: 4; // Max. read data block length [83:80]
125 UINT16 CCC: 12;// Card command classes [95:84]
126 UINT8 TRAN_SPEED ; // Max. bus clock frequency [103:96]
127 UINT8 NSAC ; // Data read access-time 2 in CLK cycles (NSAC*100) [111:104]
128 UINT8 TAAC ; // Data read access-time 1 [119:112]
129 UINT8 RESERVED_6: 6; // 0 [125:120]
130 UINT8 CSD_STRUCTURE: 2; // CSD structure [127:126]
131 }CSD_SDV2;
132
133 typedef enum {
134 UNKNOWN_CARD,
135 MMC_CARD, //MMC card
136 SD_CARD, //SD 1.1 card
137 SD_CARD_2, //SD 2.0 or above standard card
138 SD_CARD_2_HIGH //SD 2.0 or above high capacity card
139 } CARD_TYPE;
140
141 typedef enum {
142 READ,
143 WRITE
144 } OPERATION_TYPE;
145
146 typedef struct
147 {
148 UINT16 RCA;
149 UINTN BlockSize;
150 UINTN NumBlocks;
151 UINTN ClockFrequencySelect;
152 CARD_TYPE CardType;
153 OCR OCRData;
154 CID CIDData;
155 CSD CSDData;
156 } CARD_INFO;
157
158 #endif