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