Newer
Older
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
left_edge[i] !=
IO_IO_OUT1_DELAY_MAX + 1)
right_edge[i] = -1;
/*
* If a right edge has not been
* seen yet, then a future
* passing test will mark this
* edge as the left edge.
*/
else if (right_edge[i] ==
IO_IO_OUT1_DELAY_MAX +
1)
left_edge[i] = -(d + 1);
}
}
debug_cond(DLEVEL == 2, "write_center[r,d=%d):", d);
debug_cond(DLEVEL == 2, "bit_chk_test=%d left_edge[%u]: %d",
(int)(bit_chk & 1), i, left_edge[i]);
debug_cond(DLEVEL == 2, "right_edge[%u]: %d\n", i,
right_edge[i]);
bit_chk = bit_chk >> 1;
}
}
}
/* Check that all bits have a window */
for (i = 0; i < RW_MGR_MEM_DQ_PER_WRITE_DQS; i++) {
debug_cond(DLEVEL == 2, "%s:%d write_center: left_edge[%u]: \
%d right_edge[%u]: %d", __func__, __LINE__,
i, left_edge[i], i, right_edge[i]);
if ((left_edge[i] == IO_IO_OUT1_DELAY_MAX + 1) ||
(right_edge[i] == IO_IO_OUT1_DELAY_MAX + 1)) {
set_failing_group_stage(test_bgn + i,
CAL_STAGE_WRITES,
CAL_SUBSTAGE_WRITES_CENTER);
return 0;
}
}
/* Find middle of window for each DQ bit */
mid_min = left_edge[0] - right_edge[0];
min_index = 0;
for (i = 1; i < RW_MGR_MEM_DQ_PER_WRITE_DQS; i++) {
mid = left_edge[i] - right_edge[i];
if (mid < mid_min) {
mid_min = mid;
min_index = i;
}
}
/*
* -mid_min/2 represents the amount that we need to move DQS.
* If mid_min is odd and positive we'll need to add one to
* make sure the rounding in further calculations is correct
* (always bias to the right), so just add 1 for all positive values.
*/
if (mid_min > 0)
mid_min++;
mid_min = mid_min / 2;
debug_cond(DLEVEL == 1, "%s:%d write_center: mid_min=%d\n", __func__,
__LINE__, mid_min);
/* Determine the amount we can change DQS (which is -mid_min) */
orig_mid_min = mid_min;
new_dqs = start_dqs;
mid_min = 0;
debug_cond(DLEVEL == 1, "%s:%d write_center: start_dqs=%d new_dqs=%d \
mid_min=%d\n", __func__, __LINE__, start_dqs, new_dqs, mid_min);
/* Initialize data for export structures */
dqs_margin = IO_IO_OUT1_DELAY_MAX + 1;
dq_margin = IO_IO_OUT1_DELAY_MAX + 1;
/* add delay to bring centre of all DQ windows to the same "level" */
addr = SDR_PHYGRP_SCCGRP_ADDRESS | SCC_MGR_IO_OUT1_DELAY_OFFSET;
for (i = 0, p = test_bgn; i < RW_MGR_MEM_DQ_PER_WRITE_DQS; i++, p++) {
/* Use values before divide by 2 to reduce round off error */
shift_dq = (left_edge[i] - right_edge[i] -
(left_edge[min_index] - right_edge[min_index]))/2 +
(orig_mid_min - mid_min);
debug_cond(DLEVEL == 2, "%s:%d write_center: before: shift_dq \
[%u]=%d\n", __func__, __LINE__, i, shift_dq);
temp_dq_out1_delay = readl(addr + (i << 2));
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
if (shift_dq + (int32_t)temp_dq_out1_delay >
(int32_t)IO_IO_OUT1_DELAY_MAX) {
shift_dq = (int32_t)IO_IO_OUT1_DELAY_MAX - temp_dq_out1_delay;
} else if (shift_dq + (int32_t)temp_dq_out1_delay < 0) {
shift_dq = -(int32_t)temp_dq_out1_delay;
}
debug_cond(DLEVEL == 2, "write_center: after: shift_dq[%u]=%d\n",
i, shift_dq);
scc_mgr_set_dq_out1_delay(write_group, i, temp_dq_out1_delay +
shift_dq);
scc_mgr_load_dq(i);
debug_cond(DLEVEL == 2, "write_center: margin[%u]=[%d,%d]\n", i,
left_edge[i] - shift_dq + (-mid_min),
right_edge[i] + shift_dq - (-mid_min));
/* To determine values for export structures */
if (left_edge[i] - shift_dq + (-mid_min) < dq_margin)
dq_margin = left_edge[i] - shift_dq + (-mid_min);
if (right_edge[i] + shift_dq - (-mid_min) < dqs_margin)
dqs_margin = right_edge[i] + shift_dq - (-mid_min);
}
/* Move DQS */
scc_mgr_apply_group_dqs_io_and_oct_out1(write_group, new_dqs);
addr = (u32)&sdr_scc_mgr->update;
writel(0, addr);
/* Centre DM */
debug_cond(DLEVEL == 2, "%s:%d write_center: DM\n", __func__, __LINE__);
/*
* set the left and right edge of each bit to an illegal value,
* use (IO_IO_OUT1_DELAY_MAX + 1) as an illegal value,
*/
left_edge[0] = IO_IO_OUT1_DELAY_MAX + 1;
right_edge[0] = IO_IO_OUT1_DELAY_MAX + 1;
int32_t bgn_curr = IO_IO_OUT1_DELAY_MAX + 1;
int32_t end_curr = IO_IO_OUT1_DELAY_MAX + 1;
int32_t bgn_best = IO_IO_OUT1_DELAY_MAX + 1;
int32_t end_best = IO_IO_OUT1_DELAY_MAX + 1;
int32_t win_best = 0;
/* Search for the/part of the window with DM shift */
addr = (u32)&sdr_scc_mgr->update;
for (d = IO_IO_OUT1_DELAY_MAX; d >= 0; d -= DELTA_D) {
scc_mgr_apply_group_dm_out1_delay(write_group, d);
writel(0, addr);
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
if (rw_mgr_mem_calibrate_write_test(rank_bgn, write_group, 1,
PASS_ALL_BITS, &bit_chk,
0)) {
/* USE Set current end of the window */
end_curr = -d;
/*
* If a starting edge of our window has not been seen
* this is our current start of the DM window.
*/
if (bgn_curr == IO_IO_OUT1_DELAY_MAX + 1)
bgn_curr = -d;
/*
* If current window is bigger than best seen.
* Set best seen to be current window.
*/
if ((end_curr-bgn_curr+1) > win_best) {
win_best = end_curr-bgn_curr+1;
bgn_best = bgn_curr;
end_best = end_curr;
}
} else {
/* We just saw a failing test. Reset temp edge */
bgn_curr = IO_IO_OUT1_DELAY_MAX + 1;
end_curr = IO_IO_OUT1_DELAY_MAX + 1;
}
}
/* Reset DM delay chains to 0 */
scc_mgr_apply_group_dm_out1_delay(write_group, 0);
/*
* Check to see if the current window nudges up aganist 0 delay.
* If so we need to continue the search by shifting DQS otherwise DQS
* search begins as a new search. */
if (end_curr != 0) {
bgn_curr = IO_IO_OUT1_DELAY_MAX + 1;
end_curr = IO_IO_OUT1_DELAY_MAX + 1;
}
/* Search for the/part of the window with DQS shifts */
addr = (u32)&sdr_scc_mgr->update;
for (d = 0; d <= IO_IO_OUT1_DELAY_MAX - new_dqs; d += DELTA_D) {
/*
* Note: This only shifts DQS, so are we limiting ourselve to
* width of DQ unnecessarily.
*/
scc_mgr_apply_group_dqs_io_and_oct_out1(write_group,
d + new_dqs);
writel(0, addr);
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
if (rw_mgr_mem_calibrate_write_test(rank_bgn, write_group, 1,
PASS_ALL_BITS, &bit_chk,
0)) {
/* USE Set current end of the window */
end_curr = d;
/*
* If a beginning edge of our window has not been seen
* this is our current begin of the DM window.
*/
if (bgn_curr == IO_IO_OUT1_DELAY_MAX + 1)
bgn_curr = d;
/*
* If current window is bigger than best seen. Set best
* seen to be current window.
*/
if ((end_curr-bgn_curr+1) > win_best) {
win_best = end_curr-bgn_curr+1;
bgn_best = bgn_curr;
end_best = end_curr;
}
} else {
/* We just saw a failing test. Reset temp edge */
bgn_curr = IO_IO_OUT1_DELAY_MAX + 1;
end_curr = IO_IO_OUT1_DELAY_MAX + 1;
/* Early exit optimization: if ther remaining delay
chain space is less than already seen largest window
we can exit */
if ((win_best-1) >
(IO_IO_OUT1_DELAY_MAX - new_dqs - d)) {
break;
}
}
}
/* assign left and right edge for cal and reporting; */
left_edge[0] = -1*bgn_best;
right_edge[0] = end_best;
debug_cond(DLEVEL == 2, "%s:%d dm_calib: left=%d right=%d\n", __func__,
__LINE__, left_edge[0], right_edge[0]);
/* Move DQS (back to orig) */
scc_mgr_apply_group_dqs_io_and_oct_out1(write_group, new_dqs);
/* Move DM */
/* Find middle of window for the DM bit */
mid = (left_edge[0] - right_edge[0]) / 2;
/* only move right, since we are not moving DQS/DQ */
if (mid < 0)
mid = 0;
/* dm_marign should fail if we never find a window */
if (win_best == 0)
dm_margin = -1;
else
dm_margin = left_edge[0] - mid;
scc_mgr_apply_group_dm_out1_delay(write_group, mid);
addr = (u32)&sdr_scc_mgr->update;
writel(0, addr);
debug_cond(DLEVEL == 2, "%s:%d dm_calib: left=%d right=%d mid=%d \
dm_margin=%d\n", __func__, __LINE__, left_edge[0],
right_edge[0], mid, dm_margin);
/* Export values */
gbl->fom_out += dq_margin + dqs_margin;
debug_cond(DLEVEL == 2, "%s:%d write_center: dq_margin=%d \
dqs_margin=%d dm_margin=%d\n", __func__, __LINE__,
dq_margin, dqs_margin, dm_margin);
/*
* Do not remove this line as it makes sure all of our
* decisions have been applied.
*/
addr = (u32)&sdr_scc_mgr->update;
writel(0, addr);
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
return (dq_margin >= 0) && (dqs_margin >= 0) && (dm_margin >= 0);
}
/* calibrate the write operations */
static uint32_t rw_mgr_mem_calibrate_writes(uint32_t rank_bgn, uint32_t g,
uint32_t test_bgn)
{
/* update info for sims */
debug("%s:%d %u %u\n", __func__, __LINE__, g, test_bgn);
reg_file_set_stage(CAL_STAGE_WRITES);
reg_file_set_sub_stage(CAL_SUBSTAGE_WRITES_CENTER);
reg_file_set_group(g);
if (!rw_mgr_mem_calibrate_writes_center(rank_bgn, g, test_bgn)) {
set_failing_group_stage(g, CAL_STAGE_WRITES,
CAL_SUBSTAGE_WRITES_CENTER);
return 0;
}
return 1;
}
/* precharge all banks and activate row 0 in bank "000..." and bank "111..." */
static void mem_precharge_and_activate(void)
{
uint32_t r;
uint32_t addr;
for (r = 0; r < RW_MGR_MEM_NUMBER_OF_RANKS; r++) {
if (param->skip_ranks[r]) {
/* request to skip the rank */
continue;
}
/* set rank */
set_rank_and_odt_mask(r, RW_MGR_ODT_MODE_OFF);
/* precharge all banks ... */
addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_RUN_SINGLE_GROUP_OFFSET;
writel(RW_MGR_PRECHARGE_ALL, addr);
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr0;
writel(0x0F, addr);
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add0;
writel(RW_MGR_ACTIVATE_0_AND_1_WAIT1, addr);
addr = (u32)&sdr_rw_load_mgr_regs->load_cntr1;
writel(0x0F, addr);
addr = (u32)&sdr_rw_load_jump_mgr_regs->load_jump_add1;
writel(RW_MGR_ACTIVATE_0_AND_1_WAIT2, addr);
/* activate rows */
addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_RUN_SINGLE_GROUP_OFFSET;
writel(RW_MGR_ACTIVATE_0_AND_1, addr);
}
}
/* Configure various memory related parameters. */
static void mem_config(void)
{
uint32_t rlat, wlat;
uint32_t rw_wl_nop_cycles;
uint32_t max_latency;
uint32_t addr;
debug("%s:%d\n", __func__, __LINE__);
/* read in write and read latency */
addr = (u32)&data_mgr->t_wl_add;
wlat = readl(addr);
addr = (u32)&data_mgr->mem_t_add;
wlat += readl(addr);
/* WL for hard phy does not include additive latency */
/*
* add addtional write latency to offset the address/command extra
* clock cycle. We change the AC mux setting causing AC to be delayed
* by one mem clock cycle. Only do this for DDR3
*/
wlat = wlat + 1;
addr = (u32)&data_mgr->t_rl_add;
rlat = readl(addr);
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
rw_wl_nop_cycles = wlat - 2;
gbl->rw_wl_nop_cycles = rw_wl_nop_cycles;
/*
* For AV/CV, lfifo is hardened and always runs at full rate so
* max latency in AFI clocks, used here, is correspondingly smaller.
*/
max_latency = (1<<MAX_LATENCY_COUNT_WIDTH)/1 - 1;
/* configure for a burst length of 8 */
/* write latency */
/* Adjust Write Latency for Hard PHY */
wlat = wlat + 1;
/* set a pretty high read latency initially */
gbl->curr_read_lat = rlat + 16;
if (gbl->curr_read_lat > max_latency)
gbl->curr_read_lat = max_latency;
addr = (u32)&phy_mgr_cfg->phy_rlat;
writel(gbl->curr_read_lat, addr);
/* advertise write latency */
gbl->curr_write_lat = wlat;
addr = (u32)&phy_mgr_cfg->afi_wlat;
writel(wlat - 2, addr);
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
/* initialize bit slips */
mem_precharge_and_activate();
}
/* Set VFIFO and LFIFO to instant-on settings in skip calibration mode */
static void mem_skip_calibrate(void)
{
uint32_t vfifo_offset;
uint32_t i, j, r;
uint32_t addr;
debug("%s:%d\n", __func__, __LINE__);
/* Need to update every shadow register set used by the interface */
for (r = 0; r < RW_MGR_MEM_NUMBER_OF_RANKS;
r += NUM_RANKS_PER_SHADOW_REG) {
/*
* Set output phase alignment settings appropriate for
* skip calibration.
*/
for (i = 0; i < RW_MGR_MEM_IF_READ_DQS_WIDTH; i++) {
scc_mgr_set_dqs_en_phase(i, 0);
#if IO_DLL_CHAIN_LENGTH == 6
scc_mgr_set_dqdqs_output_phase(i, 6);
#else
scc_mgr_set_dqdqs_output_phase(i, 7);
#endif
/*
* Case:33398
*
* Write data arrives to the I/O two cycles before write
* latency is reached (720 deg).
* -> due to bit-slip in a/c bus
* -> to allow board skew where dqs is longer than ck
* -> how often can this happen!?
* -> can claim back some ptaps for high freq
* support if we can relax this, but i digress...
*
* The write_clk leads mem_ck by 90 deg
* The minimum ptap of the OPA is 180 deg
* Each ptap has (360 / IO_DLL_CHAIN_LENGH) deg of delay
* The write_clk is always delayed by 2 ptaps
*
* Hence, to make DQS aligned to CK, we need to delay
* DQS by:
* (720 - 90 - 180 - 2 * (360 / IO_DLL_CHAIN_LENGTH))
*
* Dividing the above by (360 / IO_DLL_CHAIN_LENGTH)
* gives us the number of ptaps, which simplies to:
*
* (1.25 * IO_DLL_CHAIN_LENGTH - 2)
*/
scc_mgr_set_dqdqs_output_phase(i, (1.25 *
IO_DLL_CHAIN_LENGTH - 2));
}
addr = (u32)&sdr_scc_mgr->dqs_ena;
writel(0xff, addr);
addr = (u32)&sdr_scc_mgr->dqs_io_ena;
writel(0xff, addr);
addr = SDR_PHYGRP_SCCGRP_ADDRESS | SCC_MGR_GROUP_COUNTER_OFFSET;
for (i = 0; i < RW_MGR_MEM_IF_WRITE_DQS_WIDTH; i++) {
writel(i, addr);
addr = (u32)&sdr_scc_mgr->dq_ena;
writel(0xff, addr);
addr = (u32)&sdr_scc_mgr->dm_ena;
writel(0xff, addr);
addr = (u32)&sdr_scc_mgr->update;
writel(0, addr);
}
/* Compensate for simulation model behaviour */
for (i = 0; i < RW_MGR_MEM_IF_READ_DQS_WIDTH; i++) {
scc_mgr_set_dqs_bus_in_delay(i, 10);
scc_mgr_load_dqs(i);
}
addr = (u32)&sdr_scc_mgr->update;
writel(0, addr);
/*
* ArriaV has hard FIFOs that can only be initialized by incrementing
* in sequencer.
*/
vfifo_offset = CALIB_VFIFO_OFFSET;
addr = (u32)&phy_mgr_cmd->inc_vfifo_hard_phy;
for (j = 0; j < vfifo_offset; j++) {
writel(0xff, addr);
addr = (u32)&phy_mgr_cmd->fifo_reset;
writel(0, addr);
/*
* For ACV with hard lfifo, we get the skip-cal setting from
* generation-time constant.
*/
gbl->curr_read_lat = CALIB_LFIFO_OFFSET;
addr = (u32)&phy_mgr_cfg->phy_rlat;
writel(gbl->curr_read_lat, addr);
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
}
/* Memory calibration entry point */
static uint32_t mem_calibrate(void)
{
uint32_t i;
uint32_t rank_bgn, sr;
uint32_t write_group, write_test_bgn;
uint32_t read_group, read_test_bgn;
uint32_t run_groups, current_run;
uint32_t failing_groups = 0;
uint32_t group_failed = 0;
uint32_t sr_failed = 0;
uint32_t addr;
debug("%s:%d\n", __func__, __LINE__);
/* Initialize the data settings */
gbl->error_substage = CAL_SUBSTAGE_NIL;
gbl->error_stage = CAL_STAGE_NIL;
gbl->error_group = 0xff;
gbl->fom_in = 0;
gbl->fom_out = 0;
mem_config();
uint32_t bypass_mode = 0x1;
addr = SDR_PHYGRP_SCCGRP_ADDRESS | SCC_MGR_GROUP_COUNTER_OFFSET;
for (i = 0; i < RW_MGR_MEM_IF_READ_DQS_WIDTH; i++) {
writel(i, addr);
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
scc_set_bypass_mode(i, bypass_mode);
}
if ((dyn_calib_steps & CALIB_SKIP_ALL) == CALIB_SKIP_ALL) {
/*
* Set VFIFO and LFIFO to instant-on settings in skip
* calibration mode.
*/
mem_skip_calibrate();
} else {
for (i = 0; i < NUM_CALIB_REPEAT; i++) {
/*
* Zero all delay chain/phase settings for all
* groups and all shadow register sets.
*/
scc_mgr_zero_all();
run_groups = ~param->skip_groups;
for (write_group = 0, write_test_bgn = 0; write_group
< RW_MGR_MEM_IF_WRITE_DQS_WIDTH; write_group++,
write_test_bgn += RW_MGR_MEM_DQ_PER_WRITE_DQS) {
/* Initialized the group failure */
group_failed = 0;
current_run = run_groups & ((1 <<
RW_MGR_NUM_DQS_PER_WRITE_GROUP) - 1);
run_groups = run_groups >>
RW_MGR_NUM_DQS_PER_WRITE_GROUP;
if (current_run == 0)
continue;
addr = SDR_PHYGRP_SCCGRP_ADDRESS | SCC_MGR_GROUP_COUNTER_OFFSET;
writel(write_group, addr);
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
scc_mgr_zero_group(write_group, write_test_bgn,
0);
for (read_group = write_group *
RW_MGR_MEM_IF_READ_DQS_WIDTH /
RW_MGR_MEM_IF_WRITE_DQS_WIDTH,
read_test_bgn = 0;
read_group < (write_group + 1) *
RW_MGR_MEM_IF_READ_DQS_WIDTH /
RW_MGR_MEM_IF_WRITE_DQS_WIDTH &&
group_failed == 0;
read_group++, read_test_bgn +=
RW_MGR_MEM_DQ_PER_READ_DQS) {
/* Calibrate the VFIFO */
if (!((STATIC_CALIB_STEPS) &
CALIB_SKIP_VFIFO)) {
if (!rw_mgr_mem_calibrate_vfifo
(read_group,
read_test_bgn)) {
group_failed = 1;
if (!(gbl->
phy_debug_mode_flags &
PHY_DEBUG_SWEEP_ALL_GROUPS)) {
return 0;
}
}
}
}
/* Calibrate the output side */
if (group_failed == 0) {
for (rank_bgn = 0, sr = 0; rank_bgn
< RW_MGR_MEM_NUMBER_OF_RANKS;
rank_bgn +=
NUM_RANKS_PER_SHADOW_REG,
++sr) {
sr_failed = 0;
if (!((STATIC_CALIB_STEPS) &
CALIB_SKIP_WRITES)) {
if ((STATIC_CALIB_STEPS)
& CALIB_SKIP_DELAY_SWEEPS) {
/* not needed in quick mode! */
} else {
/*
* Determine if this set of
* ranks should be skipped
* entirely.
*/
if (!param->skip_shadow_regs[sr]) {
if (!rw_mgr_mem_calibrate_writes
(rank_bgn, write_group,
write_test_bgn)) {
sr_failed = 1;
if (!(gbl->
phy_debug_mode_flags &
PHY_DEBUG_SWEEP_ALL_GROUPS)) {
return 0;
}
}
}
}
}
if (sr_failed != 0)
group_failed = 1;
}
}
if (group_failed == 0) {
for (read_group = write_group *
RW_MGR_MEM_IF_READ_DQS_WIDTH /
RW_MGR_MEM_IF_WRITE_DQS_WIDTH,
read_test_bgn = 0;
read_group < (write_group + 1)
* RW_MGR_MEM_IF_READ_DQS_WIDTH
/ RW_MGR_MEM_IF_WRITE_DQS_WIDTH &&
group_failed == 0;
read_group++, read_test_bgn +=
RW_MGR_MEM_DQ_PER_READ_DQS) {
if (!((STATIC_CALIB_STEPS) &
CALIB_SKIP_WRITES)) {
if (!rw_mgr_mem_calibrate_vfifo_end
(read_group, read_test_bgn)) {
group_failed = 1;
if (!(gbl->phy_debug_mode_flags
& PHY_DEBUG_SWEEP_ALL_GROUPS)) {
return 0;
}
}
}
}
}
if (group_failed != 0)
failing_groups++;
}
/*
* USER If there are any failing groups then report
* the failure.
*/
if (failing_groups != 0)
return 0;
/* Calibrate the LFIFO */
if (!((STATIC_CALIB_STEPS) & CALIB_SKIP_LFIFO)) {
/*
* If we're skipping groups as part of debug,
* don't calibrate LFIFO.
*/
if (param->skip_groups == 0) {
if (!rw_mgr_mem_calibrate_lfifo())
return 0;
}
}
}
}
/*
* Do not remove this line as it makes sure all of our decisions
* have been applied.
*/
addr = (u32)&sdr_scc_mgr->update;
writel(0, addr);
return 1;
}
static uint32_t run_mem_calibrate(void)
{
uint32_t pass;
uint32_t debug_info;
uint32_t addr;
debug("%s:%d\n", __func__, __LINE__);
/* Reset pass/fail status shown on afi_cal_success/fail */
addr = (u32)&phy_mgr_cfg->cal_status;
writel(PHY_MGR_CAL_RESET, addr);
/* stop tracking manger */
uint32_t ctrlcfg = readl(&sdr_ctrl->ctrl_cfg);
writel(ctrlcfg & 0xFFBFFFFF, &sdr_ctrl->ctrl_cfg);
initialize();
rw_mgr_mem_initialize();
pass = mem_calibrate();
mem_precharge_and_activate();
addr = (u32)&phy_mgr_cmd->fifo_reset;
writel(0, addr);
/*
* Handoff:
* Don't return control of the PHY back to AFI when in debug mode.
*/
if ((gbl->phy_debug_mode_flags & PHY_DEBUG_IN_DEBUG_MODE) == 0) {
rw_mgr_mem_handoff();
/*
* In Hard PHY this is a 2-bit control:
* 0: AFI Mux Select
* 1: DDIO Mux Select
*/
addr = (u32)&phy_mgr_cfg->mux_sel;
writel(0x2, addr);
writel(ctrlcfg, &sdr_ctrl->ctrl_cfg);
if (pass) {
printf("%s: CALIBRATION PASSED\n", __FILE__);
gbl->fom_in /= 2;
gbl->fom_out /= 2;
if (gbl->fom_in > 0xff)
gbl->fom_in = 0xff;
if (gbl->fom_out > 0xff)
gbl->fom_out = 0xff;
/* Update the FOM in the register file */
debug_info = gbl->fom_in;
debug_info |= gbl->fom_out << 8;
addr = (u32)&sdr_reg_file->fom;
writel(debug_info, addr);
addr = (u32)&phy_mgr_cfg->cal_debug_info;
writel(debug_info, addr);
addr = (u32)&phy_mgr_cfg->cal_status;
writel(PHY_MGR_CAL_SUCCESS, addr);
} else {
printf("%s: CALIBRATION FAILED\n", __FILE__);
debug_info = gbl->error_stage;
debug_info |= gbl->error_substage << 8;
debug_info |= gbl->error_group << 16;
addr = (u32)&sdr_reg_file->failing_stage;
writel(debug_info, addr);
addr = (u32)&phy_mgr_cfg->cal_debug_info;
writel(debug_info, addr);
addr = (u32)&phy_mgr_cfg->cal_status;
writel(PHY_MGR_CAL_FAIL, addr);
/* Update the failing group/stage in the register file */
debug_info = gbl->error_stage;
debug_info |= gbl->error_substage << 8;
debug_info |= gbl->error_group << 16;
addr = (u32)&sdr_reg_file->failing_stage;
writel(debug_info, addr);
}
return pass;
}
static void hc_initialize_rom_data(void)
{
uint32_t i;
uint32_t addr;
addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_INST_ROM_WRITE_OFFSET;
for (i = 0; i < ARRAY_SIZE(inst_rom_init); i++) {
uint32_t data = inst_rom_init[i];
writel(data, addr + (i << 2));
addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_AC_ROM_WRITE_OFFSET;
for (i = 0; i < ARRAY_SIZE(ac_rom_init); i++) {
uint32_t data = ac_rom_init[i];
writel(data, addr + (i << 2));
}
}
static void initialize_reg_file(void)
{
uint32_t addr;
/* Initialize the register file with the correct data */
addr = (u32)&sdr_reg_file->signature;
writel(REG_FILE_INIT_SEQ_SIGNATURE, addr);
addr = (u32)&sdr_reg_file->debug_data_addr;
writel(0, addr);
addr = (u32)&sdr_reg_file->cur_stage;
writel(0, addr);
addr = (u32)&sdr_reg_file->fom;
writel(0, addr);
addr = (u32)&sdr_reg_file->failing_stage;
writel(0, addr);
addr = (u32)&sdr_reg_file->debug1;
writel(0, addr);
addr = (u32)&sdr_reg_file->debug2;
writel(0, addr);
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
}
static void initialize_hps_phy(void)
{
uint32_t reg;
/*
* Tracking also gets configured here because it's in the
* same register.
*/
uint32_t trk_sample_count = 7500;
uint32_t trk_long_idle_sample_count = (10 << 16) | 100;
/*
* Format is number of outer loops in the 16 MSB, sample
* count in 16 LSB.
*/
reg = 0;
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ACDELAYEN_SET(2);
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQDELAYEN_SET(1);
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSDELAYEN_SET(1);
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSLOGICDELAYEN_SET(1);
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_RESETDELAYEN_SET(0);
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_LPDDRDIS_SET(1);
/*
* This field selects the intrinsic latency to RDATA_EN/FULL path.
* 00-bypass, 01- add 5 cycles, 10- add 10 cycles, 11- add 15 cycles.
*/
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ADDLATSEL_SET(0);
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_SET(
trk_sample_count);
writel(reg, &sdr_ctrl->phy_ctrl0);
reg = 0;
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_SAMPLECOUNT_31_20_SET(
trk_sample_count >>
SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_WIDTH);
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_SET(
trk_long_idle_sample_count);
writel(reg, &sdr_ctrl->phy_ctrl1);
reg = 0;
reg |= SDR_CTRLGRP_PHYCTRL_PHYCTRL_2_LONGIDLESAMPLECOUNT_31_20_SET(
trk_long_idle_sample_count >>
SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_WIDTH);
writel(reg, &sdr_ctrl->phy_ctrl2);
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
}
static void initialize_tracking(void)
{
uint32_t concatenated_longidle = 0x0;
uint32_t concatenated_delays = 0x0;
uint32_t concatenated_rw_addr = 0x0;
uint32_t concatenated_refresh = 0x0;
uint32_t trk_sample_count = 7500;
uint32_t dtaps_per_ptap;
uint32_t tmp_delay;
uint32_t addr;
/*
* compute usable version of value in case we skip full
* computation later
*/
dtaps_per_ptap = 0;
tmp_delay = 0;
while (tmp_delay < IO_DELAY_PER_OPA_TAP) {
dtaps_per_ptap++;
tmp_delay += IO_DELAY_PER_DCHAIN_TAP;
}
dtaps_per_ptap--;
concatenated_longidle = concatenated_longidle ^ 10;
/*longidle outer loop */
concatenated_longidle = concatenated_longidle << 16;
concatenated_longidle = concatenated_longidle ^ 100;
/*longidle sample count */
concatenated_delays = concatenated_delays ^ 243;
/* trfc, worst case of 933Mhz 4Gb */
concatenated_delays = concatenated_delays << 8;
concatenated_delays = concatenated_delays ^ 14;
/* trcd, worst case */
concatenated_delays = concatenated_delays << 8;
concatenated_delays = concatenated_delays ^ 10;
/* vfifo wait */
concatenated_delays = concatenated_delays << 8;
concatenated_delays = concatenated_delays ^ 4;
/* mux delay */
concatenated_rw_addr = concatenated_rw_addr ^ RW_MGR_IDLE;
concatenated_rw_addr = concatenated_rw_addr << 8;
concatenated_rw_addr = concatenated_rw_addr ^ RW_MGR_ACTIVATE_1;
concatenated_rw_addr = concatenated_rw_addr << 8;
concatenated_rw_addr = concatenated_rw_addr ^ RW_MGR_SGLE_READ;
concatenated_rw_addr = concatenated_rw_addr << 8;
concatenated_rw_addr = concatenated_rw_addr ^ RW_MGR_PRECHARGE_ALL;
concatenated_refresh = concatenated_refresh ^ RW_MGR_REFRESH_ALL;
concatenated_refresh = concatenated_refresh << 24;
concatenated_refresh = concatenated_refresh ^ 1000; /* trefi */
/* Initialize the register file with the correct data */
addr = (u32)&sdr_reg_file->dtaps_per_ptap;
writel(dtaps_per_ptap, addr);
addr = (u32)&sdr_reg_file->trk_sample_count;
writel(trk_sample_count, addr);
addr = (u32)&sdr_reg_file->trk_longidle;
writel(concatenated_longidle, addr);
addr = (u32)&sdr_reg_file->delays;
writel(concatenated_delays, addr);
addr = (u32)&sdr_reg_file->trk_rw_mgr_addr;
writel(concatenated_rw_addr, addr);
addr = (u32)&sdr_reg_file->trk_read_dqs_width;
writel(RW_MGR_MEM_IF_READ_DQS_WIDTH, addr);
addr = (u32)&sdr_reg_file->trk_rfsh;
writel(concatenated_refresh, addr);
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
}
int sdram_calibration_full(void)
{
struct param_type my_param;
struct gbl_type my_gbl;
uint32_t pass;
uint32_t i;
param = &my_param;
gbl = &my_gbl;
/* Initialize the debug mode flags */
gbl->phy_debug_mode_flags = 0;
/* Set the calibration enabled by default */
gbl->phy_debug_mode_flags |= PHY_DEBUG_ENABLE_CAL_RPT;
/*
* Only sweep all groups (regardless of fail state) by default
* Set enabled read test by default.
*/
#if DISABLE_GUARANTEED_READ
gbl->phy_debug_mode_flags |= PHY_DEBUG_DISABLE_GUARANTEED_READ;
#endif
/* Initialize the register file */
initialize_reg_file();
/* Initialize any PHY CSR */
initialize_hps_phy();
scc_mgr_initialize();
initialize_tracking();
/* USER Enable all ranks, groups */
for (i = 0; i < RW_MGR_MEM_NUMBER_OF_RANKS; i++)
param->skip_ranks[i] = 0;
for (i = 0; i < NUM_SHADOW_REGS; ++i)
param->skip_shadow_regs[i] = 0;
param->skip_groups = 0;
printf("%s: Preparing to start memory calibration\n", __FILE__);
debug("%s:%d\n", __func__, __LINE__);
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
debug_cond(DLEVEL == 1,
"DDR3 FULL_RATE ranks=%u cs/dimm=%u dq/dqs=%u,%u vg/dqs=%u,%u ",
RW_MGR_MEM_NUMBER_OF_RANKS, RW_MGR_MEM_NUMBER_OF_CS_PER_DIMM,
RW_MGR_MEM_DQ_PER_READ_DQS, RW_MGR_MEM_DQ_PER_WRITE_DQS,
RW_MGR_MEM_VIRTUAL_GROUPS_PER_READ_DQS,
RW_MGR_MEM_VIRTUAL_GROUPS_PER_WRITE_DQS);
debug_cond(DLEVEL == 1,
"dqs=%u,%u dq=%u dm=%u ptap_delay=%u dtap_delay=%u ",
RW_MGR_MEM_IF_READ_DQS_WIDTH, RW_MGR_MEM_IF_WRITE_DQS_WIDTH,
RW_MGR_MEM_DATA_WIDTH, RW_MGR_MEM_DATA_MASK_WIDTH,
IO_DELAY_PER_OPA_TAP, IO_DELAY_PER_DCHAIN_TAP);
debug_cond(DLEVEL == 1, "dtap_dqsen_delay=%u, dll=%u",
IO_DELAY_PER_DQS_EN_DCHAIN_TAP, IO_DLL_CHAIN_LENGTH);
debug_cond(DLEVEL == 1, "max values: en_p=%u dqdqs_p=%u en_d=%u dqs_in_d=%u ",
IO_DQS_EN_PHASE_MAX, IO_DQDQS_OUT_PHASE_MAX,
IO_DQS_EN_DELAY_MAX, IO_DQS_IN_DELAY_MAX);
debug_cond(DLEVEL == 1, "io_in_d=%u io_out1_d=%u io_out2_d=%u ",
IO_IO_IN_DELAY_MAX, IO_IO_OUT1_DELAY_MAX,
IO_IO_OUT2_DELAY_MAX);
debug_cond(DLEVEL == 1, "dqs_in_reserve=%u dqs_out_reserve=%u\n",
IO_DQS_IN_RESERVE, IO_DQS_OUT_RESERVE);
hc_initialize_rom_data();
/* update info for sims */
reg_file_set_stage(CAL_STAGE_NIL);
reg_file_set_group(0);
/*
* Load global needed for those actions that require
* some dynamic calibration support.
*/
dyn_calib_steps = STATIC_CALIB_STEPS;