aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/sdhci-of.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/drivers/mmc/host/sdhci-of.c b/drivers/mmc/host/sdhci-of.c
index c8dab07e34b8..01ab916c2802 100644
--- a/drivers/mmc/host/sdhci-of.c
+++ b/drivers/mmc/host/sdhci-of.c
@@ -121,8 +121,8 @@ static void esdhc_writeb(struct sdhci_host *host, u8 val, int reg)
121 121
122static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock) 122static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
123{ 123{
124 int div;
125 int pre_div = 2; 124 int pre_div = 2;
125 int div = 1;
126 126
127 clrbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN | 127 clrbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN |
128 ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK); 128 ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK);
@@ -130,17 +130,14 @@ static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock)
130 if (clock == 0) 130 if (clock == 0)
131 goto out; 131 goto out;
132 132
133 if (host->max_clk / 16 > clock) { 133 while (host->max_clk / pre_div / 16 > clock && pre_div < 256)
134 for (; pre_div < 256; pre_div *= 2) { 134 pre_div *= 2;
135 if (host->max_clk / pre_div < clock * 16)
136 break;
137 }
138 }
139 135
140 for (div = 1; div <= 16; div++) { 136 while (host->max_clk / pre_div / div > clock && div < 16)
141 if (host->max_clk / (div * pre_div) <= clock) 137 div++;
142 break; 138
143 } 139 dev_dbg(mmc_dev(host->mmc), "desired SD clock: %d, actual: %d\n",
140 clock, host->max_clk / pre_div / div);
144 141
145 pre_div >>= 1; 142 pre_div >>= 1;
146 div--; 143 div--;