summaryrefslogtreecommitdiffstats
path: root/drivers/mci/mci_spi.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-11-13 21:07:21 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-11-14 21:09:41 +0100
commit6d0d1392f4db942390d0fe18ca9c98f7c53f3c4e (patch)
treef5af840ac15660f0e80014570310702b48aeb96a /drivers/mci/mci_spi.c
parent0738b3c6fe2425e03f3c858b3809dd584b826c8f (diff)
downloadbarebox-6d0d1392f4db942390d0fe18ca9c98f7c53f3c4e.tar.gz
barebox-6d0d1392f4db942390d0fe18ca9c98f7c53f3c4e.tar.xz
mci_spi: add clock frequency change support
setup the spi master correctly provide f_min and f_max Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mci/mci_spi.c')
-rw-r--r--drivers/mci/mci_spi.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c
index 08939bea58..679a0e1e02 100644
--- a/drivers/mci/mci_spi.c
+++ b/drivers/mci/mci_spi.c
@@ -318,7 +318,15 @@ static void mmc_spi_set_ios(struct mci_host *mci, struct mci_ios *ios)
{
struct mmc_spi_host *host = to_spi_host(mci);
- spi_setup(host->spi);
+ if (host->spi->max_speed_hz != ios->clock && ios->clock != 0) {
+ int status;
+
+ host->spi->max_speed_hz = ios->clock;
+ status = spi_setup(host->spi);
+ dev_dbg(&host->spi->dev,
+ "mmc_spi: clock to %d Hz, %d\n",
+ host->spi->max_speed_hz, status);
+ }
}
static int mmc_spi_init(struct mci_host *mci, struct device_d *mci_dev)
@@ -384,6 +392,25 @@ static int spi_mci_probe(struct device_d *dev)
spi->mode = SPI_MODE_0;
spi->bits_per_word = 8;
+ status = spi_setup(spi);
+ if (status < 0) {
+ dev_dbg(&spi->dev, "needs SPI mode %02x, %d KHz; %d\n",
+ spi->mode, spi->max_speed_hz / 1000,
+ status);
+ return status;
+ }
+
+ /* SPI doesn't need the lowspeed device identification thing for
+ * MMC or SD cards, since it never comes up in open drain mode.
+ * That's good; some SPI masters can't handle very low speeds!
+ *
+ * However, low speed SDIO cards need not handle over 400 KHz;
+ * that's the only reason not to use a few MHz for f_min (until
+ * the upper layer reads the target frequency from the CSD).
+ */
+ host->mci.f_min = 400000;
+ host->mci.f_max = spi->max_speed_hz;
+
host->dev = dev;
host->spi = spi;
dev->priv = host;