Commit 92fa2a56 authored by Wolfram Sang's avatar Wolfram Sang Committed by Ulf Hansson

mmc: renesas_sdhi: refactor calculation of best TAP

To select the best TAP, we need to find the longest stream of set bits
in a bit field. There is now a helper function for bitmaps which
iterates over all region of set bits. Using it makes the code much more
concise and easier to understand. Double so, because we need to handle
two bitmaps in the near future. Remove a superfluous comment while here.
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: default avatarYoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Link: https://lore.kernel.org/r/20200408094638.10375-2-wsa+renesas@sang-engineering.comSigned-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent a8e809ec
...@@ -427,15 +427,10 @@ static int renesas_sdhi_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_io ...@@ -427,15 +427,10 @@ static int renesas_sdhi_prepare_hs400_tuning(struct mmc_host *mmc, struct mmc_io
static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host) static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host)
{ {
struct renesas_sdhi *priv = host_to_priv(host); struct renesas_sdhi *priv = host_to_priv(host);
unsigned long tap_cnt; /* counter of tuning success */ unsigned int tap_start = 0, tap_end = 0, tap_cnt = 0, rs, re, i;
unsigned long tap_start;/* start position of tuning success */ unsigned int taps_size = priv->tap_num * 2;
unsigned long tap_end; /* end position of tuning success */
unsigned long ntap; /* temporary counter of tuning success */
unsigned long i;
priv->doing_tune = false; priv->doing_tune = false;
/* Clear SCC_RVSREQ */
sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0); sd_scc_write32(host, priv, SH_MOBILE_SDHI_SCC_RVSREQ, 0);
/* /*
...@@ -443,7 +438,7 @@ static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host) ...@@ -443,7 +438,7 @@ static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host)
* result requiring the tap to be good in both runs before * result requiring the tap to be good in both runs before
* considering it for tuning selection. * considering it for tuning selection.
*/ */
for (i = 0; i < priv->tap_num * 2; i++) { for (i = 0; i < taps_size; i++) {
int offset = priv->tap_num * (i < priv->tap_num ? 1 : -1); int offset = priv->tap_num * (i < priv->tap_num ? 1 : -1);
if (!test_bit(i, priv->taps)) if (!test_bit(i, priv->taps))
...@@ -455,29 +450,14 @@ static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host) ...@@ -455,29 +450,14 @@ static int renesas_sdhi_select_tuning(struct tmio_mmc_host *host)
* is more than SH_MOBILE_SDHI_MAX_TAP probes long then use the * is more than SH_MOBILE_SDHI_MAX_TAP probes long then use the
* center index as the tap. * center index as the tap.
*/ */
tap_cnt = 0; bitmap_for_each_set_region(priv->taps, rs, re, 0, taps_size) {
ntap = 0; if (re - rs > tap_cnt) {
tap_start = 0; tap_end = re;
tap_end = 0; tap_start = rs;
for (i = 0; i < priv->tap_num * 2; i++) { tap_cnt = tap_end - tap_start;
if (test_bit(i, priv->taps)) {
ntap++;
} else {
if (ntap > tap_cnt) {
tap_start = i - ntap;
tap_end = i - 1;
tap_cnt = ntap;
}
ntap = 0;
} }
} }
if (ntap > tap_cnt) {
tap_start = i - ntap;
tap_end = i - 1;
tap_cnt = ntap;
}
if (tap_cnt >= SH_MOBILE_SDHI_MAX_TAP) if (tap_cnt >= SH_MOBILE_SDHI_MAX_TAP)
priv->tap_set = (tap_start + tap_end) / 2 % priv->tap_num; priv->tap_set = (tap_start + tap_end) / 2 % priv->tap_num;
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment