mci-spi fix
cover mci-spi fix
HI,
THis patch series fix multiple issue on mci-issue
- sd version 2.0 support
- clock frequency support
- sanity check
- always compute crc on command
it include a patch from Franck
The following changes since commit d74bef2b04a3ccf7339ba916e56830bb2feae957:
mount: add compatibility to old mount command (2012-11-02 21:26:29 +0100)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git delivery/mci_spi
for you to fetch changes up to 84368c260b7cf78fe3006368d4a5fa06e722eacf:
mci_spi: add clock frequency change support (2012-11-12 08:50:20 +0800)
----------------------------------------------------------------
Franck Jullien (1):
mci_spi: always compute command crc byte
Jean-Christophe PLAGNIOL-VILLARD (3):
mci-core: spi fix op cond support
mci_spi: add sanity check
mci_spi: add clock frequency change support
drivers/mci/Kconfig | 2 +- drivers/mci/mci-core.c | 10 +++++++--- drivers/mci/mci_spi.c | 52 +++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 47 insertions(+), 17 deletions(-)
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/4 mci_spi: always compute command crc byte
From: Franck Jullien <[email protected]>
The spec says: "the CMD8 CRC verification is always enabled. The Host shall set correct CRC in the argument ofCMD8. If CRC error is detected, card returns CRC error in R1 response regardless of command index."
Make it simple, and compute crc on every commands.
--- drivers/mci/Kconfig | 2 +- drivers/mci/mci_spi.c | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-)
drivers/mci/Kconfig +1 -1
@@ -88,6 +88,7 @@ config MCI_ATMEL 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 MCI_SPI config MMC_SPI_CRC_ON bool "Enable CRC protection for transfers" - select CRC7 select CRC16 depends on MCI_SPI help
drivers/mci/mci_spi.c +0 -12
@@ -121,14 +121,6 @@ mmc_spi_writebytes(struct mmc_spi_host *host, unsigned len, void *data)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 @@ static int mmc_spi_command_send(struct mmc_spi_host *host, struct mci_cmd *cmd) 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);
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/4 mci-core: spi fix op cond support
so we can detect sd card version 2.0 on spi
as we need to the OCR_HCS on version 2.0 regardless if it's a SPI or not
--- drivers/mci/mci-core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/mci/mci-core.c +7 -3
@@ -222,6 +222,7 @@ static int sd_send_op_cond(struct mci *mci)int err;unsigned voltages;unsigned busy; +unsigned arg;/* * Most cards do not answer if some reserved bits
@@ -240,9 +241,12 @@ static int sd_send_op_cond(struct mci *mci)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);
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/4 mci_spi: add sanity check
In reply to Jean-Christophe PLAGNIOL-VILLARDas in linux
SD/MMC support only mode 0 or 3 (if 0 not supported by the spi master) so if the mode is not 3 force 0
--- drivers/mci/mci_spi.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/mci/mci_spi.c +11 -0
@@ -366,6 +366,7 @@ static int spi_mci_probe(struct device_d *dev)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;
@@ -373,6 +374,16 @@ static int spi_mci_probe(struct device_d *dev) 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 ; + host->dev = dev; host->spi = spi; dev->priv = host;
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/4 mci_spi: add clock frequency change support
In reply to Jean-Christophe PLAGNIOL-VILLARDsetup the spi master correctly
provide f_min and f_max
--- drivers/mci/mci_spi.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/mci/mci_spi.c +28 -1
@@ -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;
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox