1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/** @file
This file does TypeC initialization.
Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "TypeC.h"
static MUX_PROGRAMMING_TABLE mAuroraMuxTable[] = {
// Address Register Data String
//====================================================================================
{A_GENERAL, R_FIRMWARE_VERSION, MUX_TABLE_NULL, "Firmware Version Number"},
{A_STATUS, R_CC_STATUS_1, MUX_TABLE_NULL, "CC_Status_1"},
{A_STATUS, R_CC_STATUS_2, MUX_TABLE_NULL, "CC_Status_2"},
{A_STATUS, R_CC_STATUS_3, MUX_TABLE_NULL, "CC_Status_3"},
{A_STATUS, R_MUX_HPD_ASSERT, MUX_TABLE_NULL, "MUX_In_HPD_Assertion"},
{A_STATUS, R_MUX_STATUS, MUX_TABLE_NULL, "MUX Status"},
{A_STATUS, R_MUX_DP_TRAINING, MUX_TABLE_NULL, "MUX_DP_Training_Disable"},
{A_STATUS, R_MUX_DP_AUX_INTERCEPT, MUX_TABLE_NULL, "MUX_DP_AUX_Interception_Disable"},
{A_STATUS, R_MUX_DP_EQ_CONFIG, MUX_TABLE_NULL, "MUX_DP_EQ_Configuration"},
{A_STATUS, R_MUX_DP_OUTPUT_CONFIG, MUX_TABLE_NULL, "MUX_DP_Output_Configuration"}
};
VOID
PrintChar (
IN UINTN DebugMask,
IN UINTN Count,
IN CHAR16 *Char
)
{
UINTN Index;
for (Index = 0; Index < Count; Index++) {
DEBUG ((DebugMask, "%s", Char));
}
}
#define DIVIDING_LINE "+----------------------------------------------------+------------------+\n"
VOID
DumpParagraph (
IN UINTN DebugMask,
IN VOID *Ptr,
IN UINTN Count
)
{
CHAR8 AsciiBuffer[17];
UINT8 *Data;
UINTN Index;
UINTN Paragraphs;
UINTN PlaceHolder;
UINTN PlaceHolders;
//
// Use a different pointer so that the one passed in doesn't change
//
Data = (UINT8 *) Ptr;
//
// Calcualte the number of paragraphs
//
Paragraphs = Count / 16;
if ((Paragraphs * 16) < Count) {
Paragraphs++;
}
//
// Calculate the number of columns
//
PlaceHolder = Paragraphs;
PlaceHolders = 0;
while (PlaceHolder > 0) {
PlaceHolders++;
PlaceHolder >>= 4;
}
//
// Dump the buffer
//
if (Count > 0 ) {
//
// Print header
//
PrintChar (DebugMask, PlaceHolders + 5, L" ");
DEBUG ((DebugMask, DIVIDING_LINE));
PrintChar (DebugMask, PlaceHolders + 5, L" ");
DEBUG ((DebugMask, "| x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF | String |\n"));
DEBUG ((DebugMask, " +"));
PrintChar (DebugMask, PlaceHolders + 3, L"-");
DEBUG ((DebugMask, DIVIDING_LINE));
//
// Print data
//
for (Index = 0; Index < (Paragraphs * 16); Index++) {
//
// Print divider
//
if (Index % 0x10 == 0x00) {
if ((Index > 0) && ((Index / 0x10) % 0x04 == 0x00) && (Paragraphs > 6)) {
DEBUG ((DebugMask, " +"));
PrintChar (DebugMask, PlaceHolders + 3, L"-");
DEBUG ((DebugMask, DIVIDING_LINE));
}
DEBUG ((DebugMask, " | %0*xx | ", PlaceHolders, (Index / 0x10)));
}
//
// Print the data or a filler
//
if (Index < Count) {
DEBUG ((DebugMask, "%02x ", Data[Index]));
if ((Data[Index] < 32) || (Data[Index] > 126)) {
//
// Not printable
//
AsciiBuffer[(Index % 0x10)] = '.';
} else {
//
// Printable
//
AsciiBuffer[(Index % 0x10)] = Data[Index];
}
} else {
DEBUG ((DebugMask, " "));
AsciiBuffer[(Index % 0x10)] = ' ';
}
//
// Print break or line end if needed
//
if (Index % 0x10 == 0x0F) {
AsciiBuffer[16] = 0x00;
DEBUG ((DebugMask, "| %a |\n", AsciiBuffer));
} else if (Index % 0x04 == 0x03) {
DEBUG ((DebugMask, " "));
}
}
//
// Print footer
//
DEBUG ((DebugMask, " +"));
PrintChar (DebugMask, PlaceHolders + 3, L"-");
DEBUG ((DebugMask, DIVIDING_LINE));
}
}
EFI_STATUS
EFIAPI
ReadMux (
IN UINT8 SlaveAddress,
IN UINT8 Offset,
OUT UINT8 *Data
)
{
UINT8 RetryCount;
EFI_STATUS Status;
RetryCount = MUX_RETRY_COUNT;
do {
*Data = 0x00;
Status = ByteReadI2C (PARADE_MUX_I2C_BUS, SlaveAddress, Offset, 1, Data);
} while ((RetryCount-- > 0) && (EFI_ERROR (Status)));
return Status;
}
EFI_STATUS
EFIAPI
WriteMux (
IN UINT8 SlaveAddress,
IN UINT8 Offset,
OUT UINT8 *Data
)
{
UINT8 RetryCount;
EFI_STATUS Status;
RetryCount = MUX_RETRY_COUNT;
do {
Status = ByteWriteI2C (PARADE_MUX_I2C_BUS, SlaveAddress, Offset, 1, Data);
} while ((RetryCount-- > 0) && (EFI_ERROR (Status)));
return Status;
}
VOID
DumpMux (
VOID
)
{
UINT8 Data[256];
UINT16 Offset;
BXT_CONF_PAD0 padConfg0;
BXT_CONF_PAD1 padConfg1;
UINT8 SlaveAddress;
EFI_STATUS Status;
//
// Loop thru device and dump it all
//
DEBUG ((DEBUG_INFO, "\n%a(#%d) - Dump the PS8750 I2C data\n", __FUNCTION__, __LINE__));
for (SlaveAddress = 0x08; SlaveAddress <= 0x0E; SlaveAddress++) {
for (Offset = 0x00; Offset <= 0xFF; Offset++) {
Status = ReadMux (SlaveAddress, (UINT8) Offset, &Data[Offset]);
if (EFI_ERROR (Status)) Data[Offset] = 0xFF;
}
DEBUG ((DEBUG_INFO, "\nSlaveAddress = 0x%02x\n", (SlaveAddress << 1)));
DumpParagraph (DEBUG_INFO, Data, 256);
}
DEBUG ((DEBUG_INFO, "\n"));
padConfg0.padCnf0 = GpioPadRead (NW_GPIO_199 + BXT_GPIO_PAD_CONF0_OFFSET);
padConfg1.padCnf1 = GpioPadRead (NW_GPIO_199 + BXT_GPIO_PAD_CONF1_OFFSET);
DEBUG ((DEBUG_INFO, "%a(#%d) - GPIO_199 (DDI1 HPD) Rx = %d RxInv = %d\n\n", __FUNCTION__, __LINE__, padConfg0.r.GPIORxState, padConfg0.r.RXINV));
}
EFI_STATUS
EFIAPI
SetupTypecMuxAux (
VOID
)
{
UINT8 Data8;
UINTN index;
MUX_DATA_TABLE MuxData;
BXT_CONF_PAD0 padConfg0;
BXT_CONF_PAD1 padConfg1;
UINT8 *Ptr;
EFI_STATUS Status;
//
// Read/write MUX info
//
Ptr = (UINT8 *) &MuxData;
for (index = 0; index < (sizeof (mAuroraMuxTable) / sizeof (mAuroraMuxTable[0])); index++) {
Status = ReadMux (mAuroraMuxTable[index].Address, mAuroraMuxTable[index].Register, &Data8);
DEBUG ((DEBUG_INFO, "%a(#%d) - %.*a [0x%02x:0x%02x] = 0x%02x (%r)\n", __FUNCTION__, __LINE__, MUX_TABLE_STRING_LENGTH, mAuroraMuxTable[index].String, (mAuroraMuxTable[index].Address << 1), mAuroraMuxTable[index].Register, Data8, Status));
Ptr[index] = Data8;
if ((mAuroraMuxTable[index].Data != MUX_TABLE_NULL) && (!EFI_ERROR (Status))) {
Data8 = (UINT8) (mAuroraMuxTable[index].Data & 0x00FF);
Status = WriteMux (mAuroraMuxTable[index].Address, mAuroraMuxTable[index].Register, &Data8);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a(#%d) - ERROR: ByteWriteI2C returned %r for %a = 0x%02x\n", __FUNCTION__, __LINE__, Status, mAuroraMuxTable[index].String, Data8));
} else {
Status = ReadMux (mAuroraMuxTable[index].Address, mAuroraMuxTable[index].Register, &Data8);
DEBUG ((DEBUG_INFO, "%a(#%d) - %.*a [0x%02x:0x%02x] = 0x%02x (%r)\n", __FUNCTION__, __LINE__, MUX_TABLE_STRING_LENGTH, mAuroraMuxTable[index].String, (mAuroraMuxTable[index].Address << 1), mAuroraMuxTable[index].Register, Data8, Status));
Ptr[index] = Data8;
}
}
}
//
// Display HPD
//
padConfg0.padCnf0 = GpioPadRead (NW_GPIO_199 + BXT_GPIO_PAD_CONF0_OFFSET);
padConfg1.padCnf1 = GpioPadRead (NW_GPIO_199 + BXT_GPIO_PAD_CONF1_OFFSET);
DEBUG ((DEBUG_INFO, "%a(#%d) - GPIO_199 (DDI1 HPD) Rx = %d RxInv = %d\n", __FUNCTION__, __LINE__, padConfg0.r.GPIORxState, padConfg0.r.RXINV));
//
// See if we need to assert the HPD on the MUX
//
if ((MuxData.MuxStatus & BIT7) == BIT7) {
//
// We are in DP mode
//
if ((MuxData.HpdAssert & BIT7) != BIT7) {
//
// We need to assert the MUX HPD
//
Data8 = MuxData.HpdAssert | BIT7;
Status = WriteMux (A_STATUS, R_MUX_HPD_ASSERT, &Data8);
//
// Display HPD
//
padConfg0.padCnf0 = GpioPadRead (NW_GPIO_199 + BXT_GPIO_PAD_CONF0_OFFSET);
padConfg1.padCnf1 = GpioPadRead (NW_GPIO_199 + BXT_GPIO_PAD_CONF1_OFFSET);
DEBUG ((DEBUG_INFO, "%a(#%d) - GPIO_199 (DDI1 HPD) Rx = %d RxInv = %d\n", __FUNCTION__, __LINE__, padConfg0.r.GPIORxState, padConfg0.r.RXINV));
}
}
return EFI_SUCCESS;
}
|