Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sdhci-of: cleanup eSDHC's set_clock() a little bit

- Get rid of incomprehensible "if { for { if } }" construction for the
exponential divisor calculation. The first if statement isn't correct
at all, since it should check for "host->max_clk / pre_div / 16 >
clock". The error doesn't cause any bugs because the check in the for
loop does the right thing, and so the outer check becomes useless;

- For the linear divisor do the same: a single while statement is more
readable than for + if construction;

- Add dev_dbg() that prints desired and actual clock frequency.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Cc: Pierre Ossman <pierre@ossman.eu>
Cc: Kumar Gala <galak@kernel.crashing.org>
Cc: David Vrabel <david.vrabel@csr.com>
Cc: Ben Dooks <ben@fluff.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Anton Vorontsov and committed by
Linus Torvalds
ad1e597d 8226a219

+8 -11
+8 -11
drivers/mmc/host/sdhci-of.c
··· 121 121 122 122 static void esdhc_set_clock(struct sdhci_host *host, unsigned int clock) 123 123 { 124 - int div; 125 124 int pre_div = 2; 125 + int div = 1; 126 126 127 127 clrbits32(host->ioaddr + ESDHC_SYSTEM_CONTROL, ESDHC_CLOCK_IPGEN | 128 128 ESDHC_CLOCK_HCKEN | ESDHC_CLOCK_PEREN | ESDHC_CLOCK_MASK); ··· 130 130 if (clock == 0) 131 131 goto out; 132 132 133 - if (host->max_clk / 16 > clock) { 134 - for (; pre_div < 256; pre_div *= 2) { 135 - if (host->max_clk / pre_div < clock * 16) 136 - break; 137 - } 138 - } 133 + while (host->max_clk / pre_div / 16 > clock && pre_div < 256) 134 + pre_div *= 2; 139 135 140 - for (div = 1; div <= 16; div++) { 141 - if (host->max_clk / (div * pre_div) <= clock) 142 - break; 143 - } 136 + while (host->max_clk / pre_div / div > clock && div < 16) 137 + div++; 138 + 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 142 pre_div >>= 1; 146 143 div--;