summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2015-07-19 04:04:33 +0200
committerMarek Vasut <marex@denx.de>2015-08-08 14:14:18 +0200
commitcbb0b7e03641bbeea558b7d0497d0267578459a2 (patch)
treefe1dc9785ba0284a662268c23a48b08f050a4528 /drivers
parent28fd242a18f78ea9f3c208e9180ecaed76cfb83d (diff)
ddr: altera: Clean up sdr_find_window_centre() part 2
This function is a treasure trove of ad-hoc iterative implementations of mathematical functions. Replace all of those with their non-iterative counterpart. Signed-off-by: Marek Vasut <marex@denx.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ddr/altera/sequencer.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/drivers/ddr/altera/sequencer.c b/drivers/ddr/altera/sequencer.c
index 4c4b36ce50..eb246cc89d 100644
--- a/drivers/ddr/altera/sequencer.c
+++ b/drivers/ddr/altera/sequencer.c
@@ -1492,28 +1492,27 @@ static int sdr_find_window_centre(const u32 grp, const u32 work_bgn,
debug_cond(DLEVEL == 2, "work_bgn=%d work_end=%d work_mid=%d\n",
work_bgn, work_end, work_mid);
/* Get the middle delay to be less than a VFIFO delay */
- for (p = 0; p <= IO_DQS_EN_PHASE_MAX;
- p++, tmp_delay += IO_DELAY_PER_OPA_TAP)
- ;
+ tmp_delay = (IO_DQS_EN_PHASE_MAX + 1) * IO_DELAY_PER_OPA_TAP;
debug_cond(DLEVEL == 2, "vfifo ptap delay %d\n", tmp_delay);
- while (work_mid > tmp_delay)
- work_mid -= tmp_delay;
+ work_mid %= tmp_delay;
debug_cond(DLEVEL == 2, "new work_mid %d\n", work_mid);
- tmp_delay = 0;
- for (p = 0; p <= IO_DQS_EN_PHASE_MAX && tmp_delay < work_mid;
- p++, tmp_delay += IO_DELAY_PER_OPA_TAP)
- ;
- tmp_delay -= IO_DELAY_PER_OPA_TAP;
- debug_cond(DLEVEL == 2, "new p %d, tmp_delay=%d\n", p - 1, tmp_delay);
+ tmp_delay = rounddown(work_mid, IO_DELAY_PER_OPA_TAP);
+ if (tmp_delay > IO_DQS_EN_PHASE_MAX * IO_DELAY_PER_OPA_TAP)
+ tmp_delay = IO_DQS_EN_PHASE_MAX * IO_DELAY_PER_OPA_TAP;
+ p = tmp_delay / IO_DELAY_PER_OPA_TAP;
+
+ debug_cond(DLEVEL == 2, "new p %d, tmp_delay=%d\n", p, tmp_delay);
+
+ d = DIV_ROUND_UP(work_mid - tmp_delay, IO_DELAY_PER_DQS_EN_DCHAIN_TAP);
+ if (d > IO_DQS_EN_DELAY_MAX)
+ d = IO_DQS_EN_DELAY_MAX;
+ tmp_delay += d * IO_DELAY_PER_DQS_EN_DCHAIN_TAP;
- for (d = 0; d <= IO_DQS_EN_DELAY_MAX && tmp_delay < work_mid;
- d++, tmp_delay += IO_DELAY_PER_DQS_EN_DCHAIN_TAP)
- ;
debug_cond(DLEVEL == 2, "new d %d, tmp_delay=%d\n", d, tmp_delay);
- scc_mgr_set_dqs_en_phase_all_ranks(grp, p - 1);
+ scc_mgr_set_dqs_en_phase_all_ranks(grp, p);
scc_mgr_set_dqs_en_delay_all_ranks(grp, d);
/*
@@ -1540,7 +1539,7 @@ static int sdr_find_window_centre(const u32 grp, const u32 work_bgn,
} else {
debug_cond(DLEVEL == 2,
"%s:%d center: found: vfifo=%u ptap=%u dtap=%u\n",
- __func__, __LINE__, v, p - 1, d);
+ __func__, __LINE__, v, p, d);
return 1;
}
}