1 /** @file
2 *
3 * Copyright (c) 2011-2013, ARM Limited. All rights reserved.
4 *
5 * 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 #include "Mmc.h"
16
17 #if !defined(MDEPKG_NDEBUG)
18 CONST CHAR8* mStrUnit[] = { "100kbit/s", "1Mbit/s", "10Mbit/s", "100MBit/s",
19 "Unknown", "Unknown", "Unknown", "Unknown" };
20 CONST CHAR8* mStrValue[] = { "1.0", "1.2", "1.3", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0",
21 "Unknown", "Unknown", "Unknown", "Unknown" };
22 #endif
23
24 VOID
PrintCID(IN UINT32 * Cid)25 PrintCID (
26 IN UINT32* Cid
27 )
28 {
29 DEBUG ((EFI_D_ERROR, "- PrintCID\n"));
30 DEBUG ((EFI_D_ERROR, "\t- Manufacturing date: %d/%d\n", (Cid[0] >> 8) & 0xF, (Cid[0] >> 12) & 0xFF));
31 DEBUG ((EFI_D_ERROR, "\t- Product serial number: 0x%X%X\n", Cid[1] & 0xFFFFFF, (Cid[0] >> 24) & 0xFF));
32 DEBUG ((EFI_D_ERROR, "\t- Product revision: %d\n", Cid[1] >> 24));
33 //DEBUG ((EFI_D_ERROR, "\t- Product name: %s\n", (char*)(Cid + 2)));
34 DEBUG ((EFI_D_ERROR, "\t- OEM ID: %c%c\n", (Cid[3] >> 8) & 0xFF, (Cid[3] >> 16) & 0xFF));
35 }
36
37
38 VOID
PrintCSD(IN UINT32 * Csd)39 PrintCSD (
40 IN UINT32* Csd
41 )
42 {
43 UINTN Value;
44
45 if (((Csd[2] >> 30) & 0x3) == 0) {
46 DEBUG ((EFI_D_ERROR, "- PrintCSD Version 1.01-1.10/Version 2.00/Standard Capacity\n"));
47 } else if (((Csd[2] >> 30) & 0x3) == 1) {
48 DEBUG ((EFI_D_ERROR, "- PrintCSD Version 2.00/High Capacity\n"));
49 } else {
50 DEBUG ((EFI_D_ERROR, "- PrintCSD Version Higher than v3.3\n"));
51 }
52
53 DEBUG ((EFI_D_ERROR, "\t- Supported card command class: 0x%X\n", MMC_CSD_GET_CCC (Csd)));
54 DEBUG ((EFI_D_ERROR, "\t- Speed: %a %a\n",mStrValue[(MMC_CSD_GET_TRANSPEED (Csd) >> 3) & 0xF],mStrUnit[MMC_CSD_GET_TRANSPEED (Csd) & 7]));
55 DEBUG ((EFI_D_ERROR, "\t- Maximum Read Data Block: %d\n",2 << (MMC_CSD_GET_READBLLEN (Csd)-1)));
56 DEBUG ((EFI_D_ERROR, "\t- Maximum Write Data Block: %d\n",2 << (MMC_CSD_GET_WRITEBLLEN (Csd)-1)));
57
58 if (!MMC_CSD_GET_FILEFORMATGRP (Csd)) {
59 Value = MMC_CSD_GET_FILEFORMAT (Csd);
60 if (Value == 0) {
61 DEBUG ((EFI_D_ERROR, "\t- Format (0): Hard disk-like file system with partition table\n"));
62 } else if (Value == 1) {
63 DEBUG ((EFI_D_ERROR, "\t- Format (1): DOS FAT (floppy-like) with boot sector only (no partition table)\n"));
64 } else if (Value == 2) {
65 DEBUG ((EFI_D_ERROR, "\t- Format (2): Universal File Format\n"));
66 } else {
67 DEBUG ((EFI_D_ERROR, "\t- Format (3): Others/Unknown\n"));
68 }
69 } else {
70 DEBUG ((EFI_D_ERROR, "\t- Format: Reserved\n"));
71 }
72 }
73
74 VOID
PrintRCA(IN UINT32 Rca)75 PrintRCA (
76 IN UINT32 Rca
77 )
78 {
79 DEBUG ((EFI_D_ERROR, "- PrintRCA: 0x%X\n", Rca));
80 DEBUG ((EFI_D_ERROR, "\t- Status: 0x%X\n", Rca & 0xFFFF));
81 DEBUG ((EFI_D_ERROR, "\t- RCA: 0x%X\n", (Rca >> 16) & 0xFFFF));
82 }
83
84 VOID
PrintOCR(IN UINT32 Ocr)85 PrintOCR (
86 IN UINT32 Ocr
87 )
88 {
89 UINTN MinV;
90 UINTN MaxV;
91 UINTN Volts;
92 UINTN Loop;
93
94 MinV = 36; // 3.6
95 MaxV = 20; // 2.0
96 Volts = 20; // 2.0
97
98 // The MMC register bits [23:8] indicate the working range of the card
99 for (Loop = 8; Loop < 24; Loop++) {
100 if (Ocr & (1 << Loop)) {
101 if (MinV > Volts) {
102 MinV = Volts;
103 }
104 if (MaxV < Volts) {
105 MaxV = Volts + 1;
106 }
107 }
108 Volts++;
109 }
110
111 DEBUG ((EFI_D_ERROR, "- PrintOCR Ocr (0x%X)\n",Ocr));
112 DEBUG ((EFI_D_ERROR, "\t- Card operating voltage: %d.%d to %d.%d\n", MinV/10, MinV % 10, MaxV/10, MaxV % 10));
113 if (((Ocr >> 29) & 3) == 0) {
114 DEBUG ((EFI_D_ERROR, "\t- AccessMode: Byte Mode\n"));
115 } else {
116 DEBUG ((EFI_D_ERROR, "\t- AccessMode: Block Mode (0x%X)\n", ((Ocr >> 29) & 3)));
117 }
118
119 if (Ocr & MMC_OCR_POWERUP) {
120 DEBUG ((EFI_D_ERROR, "\t- PowerUp\n"));
121 } else {
122 DEBUG ((EFI_D_ERROR, "\t- Voltage Not Supported\n"));
123 }
124 }
125
126 VOID
PrintResponseR1(IN UINT32 Response)127 PrintResponseR1 (
128 IN UINT32 Response
129 )
130 {
131 DEBUG ((EFI_D_INFO, "Response: 0x%X\n", Response));
132 if (Response & MMC_R0_READY_FOR_DATA) {
133 DEBUG ((EFI_D_INFO, "\t- READY_FOR_DATA\n"));
134 }
135
136 switch ((Response >> 9) & 0xF) {
137 case 0:
138 DEBUG ((EFI_D_INFO, "\t- State: Idle\n"));
139 break;
140 case 1:
141 DEBUG ((EFI_D_INFO, "\t- State: Ready\n"));
142 break;
143 case 2:
144 DEBUG ((EFI_D_INFO, "\t- State: Ident\n"));
145 break;
146 case 3:
147 DEBUG ((EFI_D_INFO, "\t- State: StandBy\n"));
148 break;
149 case 4:
150 DEBUG ((EFI_D_INFO, "\t- State: Tran\n"));
151 break;
152 case 5:
153 DEBUG ((EFI_D_INFO, "\t- State: Data\n"));
154 break;
155 case 6:
156 DEBUG ((EFI_D_INFO, "\t- State: Rcv\n"));
157 break;
158 case 7:
159 DEBUG ((EFI_D_INFO, "\t- State: Prg\n"));
160 break;
161 case 8:
162 DEBUG ((EFI_D_INFO, "\t- State: Dis\n"));
163 break;
164 default:
165 DEBUG ((EFI_D_INFO, "\t- State: Reserved\n"));
166 break;
167 }
168 }
169