mmc: bcm2835-sdhost: Support underclocking
authorPhil Elwell <phil@raspberrypi.org>
Mon, 22 Jan 2018 12:17:27 +0000 (12:17 +0000)
committerRaspbian kernel package updater <root@raspbian.org>
Sat, 31 Mar 2018 14:57:29 +0000 (15:57 +0100)
Support underclocking of the SD bus in two ways:
1. using the max-frequency DT property (which currently has no DT
   parameter), and
2. using the exiting sd_overclock parameter.

The two methods differ slightly - in the former the MMC subsystem is
aware of the underclocking, while in the latter it isn't - but the
end results should be the same.

See: https://github.com/raspberrypi/linux/issues/2350

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
drivers/mmc/host/bcm2835-sdhost.c

index a9bc79bfdbb71807819dfe2d8f1651445997f92a..5b1aa59b84af2ba31b9b62c73be9846efa9cb085 100644 (file)
@@ -1515,8 +1515,7 @@ void bcm2835_sdhost_set_clock(struct bcm2835_host *host, unsigned int clock)
        if (host->debug)
                pr_info("%s: set_clock(%d)\n", mmc_hostname(host->mmc), clock);
 
-       if ((host->overclock_50 > 50) &&
-           (clock == 50*MHZ))
+       if (host->overclock_50 && (clock == 50*MHZ))
                clock = host->overclock_50 * MHZ + (MHZ - 1);
 
        /* The SDCDIV register has 11 bits, and holds (div - 2).
@@ -1890,7 +1889,8 @@ int bcm2835_sdhost_add_host(struct bcm2835_host *host)
 
        mmc = host->mmc;
 
-       mmc->f_max = host->max_clk;
+       if (!mmc->f_max || mmc->f_max > host->max_clk)
+               mmc->f_max = host->max_clk;
        mmc->f_min = host->max_clk / SDCDIV_MAX_CDIV;
 
        mmc->max_busy_timeout =  (~(unsigned int)0)/(mmc->f_max/1000);