diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig index b1a678e..5c0ca4d 100644 --- a/drivers/mci/Kconfig +++ b/drivers/mci/Kconfig @@ -88,6 +88,7 @@ config MCI_SPI bool "MMC/SD over SPI" + select CRC7 depends on SPI help Some systems access MMC/SD/SDIO cards using a SPI controller @@ -98,7 +99,6 @@ config MMC_SPI_CRC_ON bool "Enable CRC protection for transfers" - select CRC7 select CRC16 depends on MCI_SPI help diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index dc562a5..bf2b0f8 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -222,6 +222,7 @@ int err; unsigned voltages; unsigned busy; + unsigned arg; /* * Most cards do not answer if some reserved bits @@ -240,9 +241,12 @@ return err; } - mci_setup_cmd(&cmd, SD_CMD_APP_SEND_OP_COND, - mmc_host_is_spi(host) ? 0 : (voltages | (mci->version == SD_VERSION_2 ? OCR_HCS : 0)), - MMC_RSP_R3); + arg = mmc_host_is_spi(host) ? 0 : voltages; + + if (mci->version == SD_VERSION_2) + arg |= OCR_HCS; + + mci_setup_cmd(&cmd, SD_CMD_APP_SEND_OP_COND, arg, MMC_RSP_R3); err = mci_send_cmd(mci, &cmd, NULL); if (err) { dev_dbg(mci->mci_dev, "SD operation condition set failed: %d\n", err); diff --git a/drivers/mci/mci_spi.c b/drivers/mci/mci_spi.c index 5894104..679a0e1 100644 --- a/drivers/mci/mci_spi.c +++ b/drivers/mci/mci_spi.c @@ -121,14 +121,6 @@ return status; } -/* - * Note that while the CRC, in general, is ignored in SPI mode, the very first - * command must be followed by a valid CRC, since the card is not yet in SPI mode. - * The CRC byte for a CMD0 command with a zero argument is a constant 0x4A. For - * simplicity, this CRC byte is always sent with every command. - */ -#define MMC_SPI_CMD0_CRC ((0x4a << 1) | 0x1) - static int mmc_spi_command_send(struct mmc_spi_host *host, struct mci_cmd *cmd) { uint8_t r1; @@ -141,11 +133,7 @@ command[3] = cmd->cmdarg >> 16; command[4] = cmd->cmdarg >> 8; command[5] = cmd->cmdarg; -#ifdef CONFIG_MMC_SPI_CRC_ON command[6] = (crc7(0, &command[1], 5) << 1) | 0x01; -#else - command[6] = MMC_SPI_CMD0_CRC; -#endif mmc_spi_writebytes(host, 7, command); @@ -330,7 +318,15 @@ { 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) @@ -378,6 +374,7 @@ struct spi_device *spi = (struct spi_device *)dev->type_data; struct mmc_spi_host *host; void *ones; + int status; host = xzalloc(sizeof(*host)); host->mci.send_cmd = mmc_spi_request; @@ -385,6 +382,35 @@ host->mci.init = mmc_spi_init; host->mci.hw_dev = dev; + /* MMC and SD specs only seem to care that sampling is on the + * rising edge ... meaning SPI modes 0 or 3. So either SPI mode + * should be legit. We'll use mode 0 since the steady state is 0, + * which is appropriate for hotplugging, unless the platform data + * specify mode 3 (if hardware is not compatible to mode 0). + */ + if (spi->mode != SPI_MODE_3) + 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;