-
Notifications
You must be signed in to change notification settings - Fork 23
/
mv_ddr4_training_leveling.c
533 lines (477 loc) · 20.3 KB
/
mv_ddr4_training_leveling.c
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*******************************************************************************
Copyright (C) 2016 Marvell International Ltd.
This software file (the "File") is owned and distributed by Marvell
International Ltd. and/or its affiliates ("Marvell") under the following
alternative licensing terms. Once you have made an election to distribute the
File under one of the following license alternatives, please (i) delete this
introductory statement regarding license alternatives, (ii) delete the three
license alternatives that you have not elected to use and (iii) preserve the
Marvell copyright notice above.
********************************************************************************
Marvell Commercial License Option
If you received this File from Marvell and you have entered into a commercial
license agreement (a "Commercial License") with Marvell, the File is licensed
to you under the terms of the applicable Commercial License.
********************************************************************************
Marvell GPL License Option
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, either version 2 of the License, or any later version.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
********************************************************************************
Marvell GNU General Public License FreeRTOS Exception
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File in accordance with the terms and conditions of the Lesser
General Public License Version 2.1 plus the following FreeRTOS exception.
An independent module is a module which is not derived from or based on
FreeRTOS.
Clause 1:
Linking FreeRTOS statically or dynamically with other modules is making a
combined work based on FreeRTOS. Thus, the terms and conditions of the GNU
General Public License cover the whole combination.
As a special exception, the copyright holder of FreeRTOS gives you permission
to link FreeRTOS with independent modules that communicate with FreeRTOS solely
through the FreeRTOS API interface, regardless of the license terms of these
independent modules, and to copy and distribute the resulting combined work
under terms of your choice, provided that:
1. Every copy of the combined work is accompanied by a written statement that
details to the recipient the version of FreeRTOS used and an offer by yourself
to provide the FreeRTOS source code (including any modifications you may have
made) should the recipient request it.
2. The combined work is not itself an RTOS, scheduler, kernel or related
product.
3. The independent modules add significant and primary functionality to
FreeRTOS and do not merely extend the existing functionality already present in
FreeRTOS.
Clause 2:
FreeRTOS may not be used for any competitive or comparative purpose, including
the publication of any form of run time or compile time metric, without the
express permission of Real Time Engineers Ltd. (this is the norm within the
industry and is intended to ensure information accuracy).
********************************************************************************
Marvell BSD License Option
If you received this File from Marvell, you may opt to use, redistribute and/or
modify this File under the following licensing terms.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Marvell nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#if defined(CONFIG_DDR4)
#include "ddr3_init.h"
#include "mv_ddr_regs.h"
static int mv_ddr4_dynamic_pb_wl_supp(u32 dev_num, enum mv_wl_supp_mode ecc_mode);
/* compare test for ddr4 write leveling supplementary */
#define MV_DDR4_COMP_TEST_NO_RESULT 0
#define MV_DDR4_COMP_TEST_RESULT_0 1
#define MV_DDR4_XSB_COMP_PATTERNS_NUM 8
static u8 mv_ddr4_xsb_comp_test(u32 dev_num, u32 subphy_num, u32 if_id,
enum mv_wl_supp_mode ecc_mode)
{
u32 wl_invert;
u8 pb_key, bit, bit_max, word;
struct pattern_info *pattern_table = ddr3_tip_get_pattern_table();
struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
u32 subphy_max = ddr3_tip_dev_attr_get(0, MV_ATTR_OCTET_PER_INTERFACE);
uint64_t read_pattern_64[MV_DDR4_XSB_COMP_PATTERNS_NUM] = {0};
/*
* FIXME: the pattern below is used for writing to the memory
* by the cpu. it was changed to be written through the odpg.
* for a workaround
* uint64_t pattern_test_table_64[MV_DDR4_XSB_COMP_PATTERNS_NUM] = {
* 0xffffffffffffffff,
* 0xffffffffffffffff,
* 0x0000000000000000,
* 0x0000000000000000,
* 0x0000000000000000,
* 0x0000000000000000,
* 0xffffffffffffffff,
* 0xffffffffffffffff};
*/
u32 read_pattern[MV_DDR4_XSB_COMP_PATTERNS_NUM];
/*u32 pattern_test_table[MV_DDR4_XSB_COMP_PATTERNS_NUM] = {
0xffffffff,
0xffffffff,
0x00000000,
0x00000000,
0x00000000,
0x00000000,
0xffffffff,
0xffffffff}; TODO: use pattern_table_get_word */
int i, status;
uint64_t data64;
uintptr_t addr64;
int ecc_running = 0;
u32 ecc_read_subphy_num = 0; /* FIXME: change ecc read subphy num to be configurable */
u8 bit_counter = 0;
int edge = 0;
/* write and read data */
if (MV_DDR_IS_64BIT_DRAM_MODE(tm->bus_act_mask)) {
status = ddr3_tip_if_write(0, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, ODPG_DATA_CTRL_REG,
effective_cs << ODPG_DATA_CS_OFFS,
ODPG_DATA_CS_MASK << ODPG_DATA_CS_OFFS);
if (status != MV_OK)
return status;
addr64 = (uintptr_t)pattern_table[PATTERN_TEST].start_addr;
/*
* FIXME: changed the load pattern to memory through the odpg
* this change is needed to be validate
* this change is done due to un calibrated dm at this stage
* the below code is the code for loading the pattern directly
* to the memory
*
* for (i = 0; i < MV_DDR4_XSB_COMP_PATTERNS_NUM; i++) {
* data64 = pattern_test_table_64[i];
* writeq(addr64, data64);
* addr64 += sizeof(uint64_t);
*}
* FIXME: the below code loads the pattern to the memory through the odpg
* it loads it twice to due supplementary failure, need to check it
*/
int j;
for (j = 0; j < 2; j++)
ddr3_tip_load_pattern_to_mem(dev_num, PATTERN_TEST);
} else if (MV_DDR_IS_32BIT_IN_64BIT_DRAM_MODE(tm->bus_act_mask, subphy_max)) {
status = ddr3_tip_if_write(0, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, ODPG_DATA_CTRL_REG,
effective_cs << ODPG_DATA_CS_OFFS,
ODPG_DATA_CS_MASK << ODPG_DATA_CS_OFFS);
if (status != MV_OK)
return status;
/*
* FIXME: changed the load pattern to memory through the odpg
* this change is needed to be validate
* this change is done due to un calibrated dm at this stage
* the below code is the code for loading the pattern directly
* to the memory
*/
int j;
for (j = 0; j < 2; j++)
ddr3_tip_load_pattern_to_mem(dev_num, PATTERN_TEST);
} else {
/*
* FIXME: changed the load pattern to memory through the odpg
* this change is needed to be validate
* this change is done due to un calibrated dm at this stage
* the below code is the code for loading the pattern directly
* to the memory
*/
int j;
for (j = 0; j < 2; j++)
ddr3_tip_load_pattern_to_mem(dev_num, PATTERN_TEST);
}
if ((ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP4) ||
(ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP3 ||
ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP8)) {
/* disable ecc write mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x0, 0x100);
if (status != MV_OK)
return status;
/* enable read data ecc mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x3, 0x3);
if (status != MV_OK)
return status;
/* unset training start bit */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_REG, 0x80000000, 0x80000000);
if (status != MV_OK)
return status;
ecc_running = 1;
ecc_read_subphy_num = ECC_READ_BUS_0;
}
if (MV_DDR_IS_64BIT_DRAM_MODE(tm->bus_act_mask)) {
status = ddr3_tip_if_write(0, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, ODPG_DATA_CTRL_REG,
effective_cs << ODPG_DATA_CS_OFFS,
ODPG_DATA_CS_MASK << ODPG_DATA_CS_OFFS);
if (status != MV_OK)
return status;
/*
* in case of reading the pattern read it from the address x 8
* the odpg multiply by 8 the addres to read from
*/
addr64 = ((uintptr_t)pattern_table[PATTERN_TEST].start_addr) << 3;
for (i = 0; i < MV_DDR4_XSB_COMP_PATTERNS_NUM; i++) {
data64 = readq(addr64);
addr64 += sizeof(uint64_t);
read_pattern_64[i] = data64;
}
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("xsb comp: if %d bus id %d\n", 0, subphy_num));
for (edge = 0; edge < 8; edge++)
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("0x%16llx\n", (unsigned long long)read_pattern_64[edge]));
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("\n"));
} else if (MV_DDR_IS_32BIT_IN_64BIT_DRAM_MODE(tm->bus_act_mask, subphy_max)) {
status = ddr3_tip_if_write(0, ACCESS_TYPE_MULTICAST, PARAM_NOT_CARE, ODPG_DATA_CTRL_REG,
effective_cs << ODPG_DATA_CS_OFFS,
ODPG_DATA_CS_MASK << ODPG_DATA_CS_OFFS);
if (status != MV_OK)
return status;
status = ddr3_tip_ext_read(dev_num, if_id, pattern_table[PATTERN_TEST].start_addr << 3,
1, read_pattern);
if (status != MV_OK)
return status;
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("xsb comp: if %d bus id %d\n", 0, subphy_num));
for (edge = 0; edge < 8; edge++)
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("0x%16x\n", read_pattern[edge]));
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("\n"));
} else {
status = ddr3_tip_ext_read(dev_num, if_id, ((pattern_table[PATTERN_TEST].start_addr << 3) +
((SDRAM_CS_SIZE + 1) * effective_cs)), 1, read_pattern);
if (status != MV_OK)
return status;
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("xsb comp: if %d bus id %d\n", 0, subphy_num));
for (edge = 0; edge < 8; edge++)
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("0x%16x\n", read_pattern[edge]));
DEBUG_LEVELING(DEBUG_LEVEL_INFO, ("\n"));
}
/* read centralization result to decide on half phase by inverse bit */
status = ddr3_tip_bus_read(dev_num, if_id, ACCESS_TYPE_UNICAST, subphy_num, DDR_PHY_DATA,
CTX_PHY_REG(0), &wl_invert);
if (status != MV_OK)
return status;
if ((wl_invert & 0x20) != 0)
wl_invert = 1;
else
wl_invert = 0;
/* for ecc, read from the "read" subphy (usualy subphy 0) */
if (ecc_running)
subphy_num = ecc_read_subphy_num;
/* per bit loop*/
bit_max = subphy_num * BUS_WIDTH_IN_BITS + BUS_WIDTH_IN_BITS;
for (bit = subphy_num * BUS_WIDTH_IN_BITS; bit < bit_max; bit++) {
/* get per bit pattern key (value of the same bit in the pattern) */
pb_key = 0;
for (word = 0; word < MV_DDR4_XSB_COMP_PATTERNS_NUM; word++) {
if (MV_DDR_IS_64BIT_DRAM_MODE(tm->bus_act_mask)) {
if ((read_pattern_64[word] & ((uint64_t)1 << bit)) != 0)
pb_key |= (1 << word);
} else {
if ((read_pattern[word] & (1 << bit)) != 0)
pb_key |= (1 << word);
}
}
/* find the key value and make decision */
switch (pb_key) {
/* case(s) for 0 */
case 0b11000011: /* nominal */
case 0b10000011: /* sample at start of UI sample at the dqvref TH */
case 0b10000111: /* sample at start of UI sample at the dqvref TH */
case 0b11000001: /* sample at start of UI sample at the dqvref TH */
case 0b11100001: /* sample at start of UI sample at the dqvref TH */
case 0b11100011: /* sample at start of UI sample at the dqvref TH */
case 0b11000111: /* sample at start of UI sample at the dqvref TH */
bit_counter++;
break;
} /* end of switch */
} /* end of per bit loop */
/* check all bits in the current subphy has met the switch condition above */
if (bit_counter == BUS_WIDTH_IN_BITS)
return MV_DDR4_COMP_TEST_RESULT_0;
else {
DEBUG_LEVELING(
DEBUG_LEVEL_INFO,
("different supplementary results (%d -> %d)\n",
MV_DDR4_COMP_TEST_NO_RESULT, MV_DDR4_COMP_TEST_RESULT_0));
return MV_DDR4_COMP_TEST_NO_RESULT;
}
}
int mv_ddr4_dynamic_wl_supp(u32 dev_num)
{
int status = MV_OK;
struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
if (DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask) ||
DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask) ||
DDR3_IS_ECC_PUP8_MODE(tm->bus_act_mask)) {
if (DDR3_IS_ECC_PUP4_MODE(tm->bus_act_mask))
status = mv_ddr4_dynamic_pb_wl_supp(dev_num, WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP4);
else if (DDR3_IS_ECC_PUP3_MODE(tm->bus_act_mask))
status = mv_ddr4_dynamic_pb_wl_supp(dev_num, WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP3);
else /* WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP8 */
status = mv_ddr4_dynamic_pb_wl_supp(dev_num, WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP8);
if (status != MV_OK)
return status;
status = mv_ddr4_dynamic_pb_wl_supp(dev_num, WRITE_LEVELING_SUPP_ECC_MODE_DATA_PUPS);
} else { /* regular supplementary for data subphys in non-ecc mode */
status = mv_ddr4_dynamic_pb_wl_supp(dev_num, WRITE_LEVELING_SUPP_REG_MODE);
}
return status;
}
/* dynamic per bit write leveling supplementary */
static int mv_ddr4_dynamic_pb_wl_supp(u32 dev_num, enum mv_wl_supp_mode ecc_mode)
{
u32 if_id;
u32 subphy_start, subphy_end;
u32 subphy_num = ddr3_tip_dev_attr_get(dev_num, MV_ATTR_OCTET_PER_INTERFACE);
u8 compare_result = 0;
u32 orig_phase;
u32 rd_data, wr_data = 0;
u32 flag, step;
struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
u32 ecc_phy_access_id;
int status;
if (ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP4 ||
ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP3 ||
ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP8) {
/* enable ecc write mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x100, 0x100);
if (status != MV_OK)
return status;
/* disable read data ecc mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x0, 0x3);
if (status != MV_OK)
return status;
/* unset training start bit */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_REG, 0x0, 0x80000000);
if (status != MV_OK)
return status;
if (ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP3)
ecc_phy_access_id = ECC_PHY_ACCESS_3;
else if (ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP4)
ecc_phy_access_id = ECC_PHY_ACCESS_4;
else /* ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP8 */
ecc_phy_access_id = ECC_PHY_ACCESS_8;
subphy_start = ecc_phy_access_id;
subphy_end = subphy_start + 1;
} else if (ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_DATA_PUPS) {
/* disable ecc write mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x0, 0x100);
if (status != MV_OK)
return status;
/* disable ecc mode*/
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
SDRAM_CFG_REG, 0, 0x40000);
if (status != MV_OK)
return status;
subphy_start = 0;
if (MV_DDR_IS_HALF_BUS_DRAM_MODE(tm->bus_act_mask, subphy_num))
subphy_end = (subphy_num - 1) / 2;
else
subphy_end = subphy_num - 1;
} else { /* ecc_mode == WRITE_LEVELING_SUPP_REG_MODE */
subphy_start = 0;
/* remove ecc subphy prior to algorithm's start */
subphy_end = subphy_num - 1; /* TODO: check it */
}
for (if_id = 0; if_id < MAX_INTERFACE_NUM; if_id++) {
VALIDATE_IF_ACTIVE(tm->if_act_mask, if_id);
for (subphy_num = subphy_start; subphy_num < subphy_end; subphy_num++) {
VALIDATE_BUS_ACTIVE(tm->bus_act_mask, subphy_num);
flag = 1;
step = 0;
status = ddr3_tip_bus_read(dev_num, if_id, ACCESS_TYPE_UNICAST, subphy_num, DDR_PHY_DATA,
WL_PHY_REG(effective_cs), &rd_data);
if (status != MV_OK)
return status;
orig_phase = (rd_data >> 6) & 0x7;
while (flag != 0) {
/* get decision for subphy */
compare_result = mv_ddr4_xsb_comp_test(dev_num, subphy_num, if_id, ecc_mode);
if (compare_result == MV_DDR4_COMP_TEST_RESULT_0) {
flag = 0;
} else { /* shift phase to -1 */
step++;
if (step == 1) { /* set phase (0x0[6-8]) to -2 */
if (orig_phase > 1)
wr_data = (rd_data & ~0x1c0) | ((orig_phase - 2) << 6);
else if (orig_phase == 1)
wr_data = (rd_data & ~0x1df);
if (orig_phase >= 1)
ddr3_tip_bus_write(dev_num, ACCESS_TYPE_UNICAST, if_id,
ACCESS_TYPE_UNICAST, subphy_num,
DDR_PHY_DATA,
WL_PHY_REG(effective_cs), wr_data);
} else if (step == 2) { /* shift phase to +1 */
if (orig_phase <= 5) {
wr_data = (rd_data & ~0x1c0) | ((orig_phase + 2) << 6);
ddr3_tip_bus_write(dev_num, ACCESS_TYPE_UNICAST, if_id,
ACCESS_TYPE_UNICAST, subphy_num,
DDR_PHY_DATA,
WL_PHY_REG(effective_cs), wr_data);
}
} else if (step == 3) {
if (orig_phase <= 3) {
wr_data = (rd_data & ~0x1c0) | ((orig_phase + 4) << 6);
ddr3_tip_bus_write(dev_num, ACCESS_TYPE_UNICAST, if_id,
ACCESS_TYPE_UNICAST, subphy_num,
DDR_PHY_DATA,
WL_PHY_REG(effective_cs), wr_data);
}
} else { /* error */
flag = 0;
compare_result = MV_DDR4_COMP_TEST_NO_RESULT;
training_result[training_stage][if_id] = TEST_FAILED;
}
}
}
}
if ((training_result[training_stage][if_id] == NO_TEST_DONE) ||
(training_result[training_stage][if_id] == TEST_SUCCESS))
training_result[training_stage][if_id] = TEST_SUCCESS;
}
if (ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_DATA_PUPS) {
/* enable ecc write mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x100, 0x100);
if (status != MV_OK)
return status;
/* enable ecc mode*/
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
SDRAM_CFG_REG, 0x40000, 0x40000);
if (status != MV_OK)
return status;
} else if (ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP4 ||
ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP3 ||
ecc_mode == WRITE_LEVELING_SUPP_ECC_MODE_ECC_PUP8) {
/* enable ecc write mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x100, 0x100);
if (status != MV_OK)
return status;
/* disable read data ecc mux */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_2_REG, 0x0, 0x3);
if (status != MV_OK)
return status;
/* unset training start bit */
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_REG, 0x0, 0x80000000);
if (status != MV_OK)
return status;
status = ddr3_tip_if_write(dev_num, ACCESS_TYPE_UNICAST, PARAM_NOT_CARE,
TRAINING_SW_1_REG, 0x1 << 16, 0x1 << 16);
if (status != MV_OK)
return status;
} else {
/* do nothing for WRITE_LEVELING_SUPP_REG_MODE */;
}
if (training_result[training_stage][0] == TEST_SUCCESS)
return MV_OK;
else
return MV_FAIL;
}
#endif /* CONFIG_DDR4 */