Revert "Revert "UPSTREAM: mmc: dw_mmc: correct the calculation for CLKDIV""
authorGrant Grundler <grundler@chromium.org>
Thu, 21 Mar 2013 16:13:41 +0000 (09:13 -0700)
committerChromeBot <chrome-bot@google.com>
Thu, 21 Mar 2013 21:42:55 +0000 (14:42 -0700)
This reverts commit f786fcc8d52e5a7d15a90cf266f2ac1d40f54a5e

Cannot reproduce "won't boot" with "normal" FW versions. See bug for details.

Change-Id: Ibb2730ecef525831883ff26bc04c72a55f47f06d
Reviewed-on: https://gerrit.chromium.org/gerrit/46128
Reviewed-by: Grant Grundler <grundler@chromium.org>
Tested-by: Grant Grundler <grundler@chromium.org>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Commit-Queue: Paul Stewart <pstew@chromium.org>

drivers/mmc/host/dw_mmc.c

index 3ca2e8d..bd63235 100644 (file)
@@ -629,14 +629,15 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
        u32 div;
 
        if (slot->clock != host->current_speed || force_clkinit) {
-               if (host->bus_hz % slot->clock)
+               div = host->bus_hz / slot->clock;
+               if (host->bus_hz % slot->clock && host->bus_hz > slot->clock)
                        /*
                         * move the + 1 after the divide to prevent
                         * over-clocking the card.
                         */
-                       div = ((host->bus_hz / slot->clock) >> 1) + 1;
-               else
-                       div = (host->bus_hz  / slot->clock) >> 1;
+                       div += 1;
+
+               div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0;
 
                dev_info(&slot->mmc->class_dev,
                         "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ"