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
|
/*
* This file is part of the coreboot project.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <stdint.h>
#include <delay.h>
#include <console/console.h>
#include "gm45.h"
static const int ddr3_lookup_schedule[6][2] = {
{ 0, 1 }, { 2, 3 }, { 4, 5 }, { 4, 5 }, { 6, 7 }, { 6, 7 }
};
/* Look-up table:
* a1step X idx X (group || pull-up/-down)
*/
static const u8 ddr3_lut[2][64][8] = {
{ /* Stepping B3 and below. */
{ 8, 8, 3, 3, 3, 3, 5, 7 },
{ 8, 8, 3, 3, 3, 3, 5, 7 },
{ 8, 8, 3, 3, 3, 3, 5, 7 },
{ 8, 8, 3, 3, 3, 3, 5, 7 },
{ 8, 8, 3, 3, 3, 3, 5, 7 },
{ 8, 8, 3, 3, 3, 3,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, 15 },
{ 43, 43, 7, 7, 7, 7, 15, 15 },
{ 43, 43, 7, 7, 7, 7, 15, 15 },
{ 43, 43, 8, 7, 8, 7, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
{ 43, 43, 8, 8, 8, 8, 15, 15 },
}
};
static void lookup_and_write(const int a1step,
const int row, const int col,
unsigned int mchbar)
{
int i;
/* Write 4 32-bit registers, 4 values each. */
for (i = row; i < row + 16; i += 4) {
MCHBAR32(mchbar) =
((ddr3_lut[a1step][i + 0][col] & 0x3f) << 0) |
((ddr3_lut[a1step][i + 1][col] & 0x3f) << 8) |
((ddr3_lut[a1step][i + 2][col] & 0x3f) << 16) |
((ddr3_lut[a1step][i + 3][col] & 0x3f) << 24);
mchbar += 4;
}
}
void raminit_rcomp_calibration(const stepping_t stepping) {
const int a1step = stepping >= STEPPING_CONVERSION_A1;
int i;
enum {
PULL_UP = 0,
PULL_DOWN = 1,
};
/* channel X group X pull-up/-down */
char lut_idx[2][6][2];
for (i = 0; i < 2 * 6 * 2; ++i)
((char *)lut_idx)[i] = -1;
MCHBAR32(0x400) |= (1 << 2);
MCHBAR32(0x418) |= (1 << 17);
MCHBAR32(0x40c) &= ~(1 << 23);
MCHBAR32(0x41c) &= ~((1 << 7) | (1 << 3));
MCHBAR32(0x400) |= 1;
/* Read lookup indices. */
for (i = 0; i < 12; ++i) {
do {
MCHBAR32(0x400) |= (1 << 3);
udelay(10);
MCHBAR32(0x400) &= ~(1 << 3);
} while ((MCHBAR32(0x530) & 0x7) != 0x4);
u32 reg = MCHBAR32(0x400);
const unsigned int group = (reg >> 13) & 0x7;
const unsigned int channel = (reg >> 12) & 0x1;
if (group > 5)
break;
reg = MCHBAR32(0x518);
lut_idx[channel][group][PULL_UP] = (reg >> 24) & 0x7f;
lut_idx[channel][group][PULL_DOWN] = (reg >> 16) & 0x7f;
}
/* Cleanup? */
MCHBAR32(0x400) |= (1 << 3);
udelay(10);
MCHBAR32(0x400) &= ~(1 << 3);
MCHBAR32(0x400) &= ~(1 << 2);
/* Check for consistency. */
for (i = 0; i < 2 * 6 * 2; ++i) {
const char idx = ((char *)lut_idx)[i];
if ((idx < 7) || (idx > 55))
die("Bad RCOMP calibration lookup index.\n");
}
/* Lookup values and fill registers. */
int channel, group, pu_pd;
unsigned int mchbar = 0x0680;
for (channel = 0; channel < 2; ++channel) {
for (group = 0; group < 6; ++group) {
for (pu_pd = PULL_DOWN; pu_pd >= PULL_UP; --pu_pd) {
lookup_and_write(
a1step,
lut_idx[channel][group][pu_pd] - 7,
ddr3_lookup_schedule[group][pu_pd],
mchbar);
mchbar += 0x0018;
}
mchbar += 0x0010;
/* Channel B knows only the first two groups. */
if ((1 == channel) && (1 == group))
break;
}
mchbar += 0x0040;
}
}
|