Lines Matching +full:no +full:- +full:mmc
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Access SD/MMC cards through SPI master controllers
7 * (C) Copyright 2006-2007, David Brownell
9 * Hans-Peter Nilsson (hp@axis.com)
18 #include <linux/dma-direction.h>
20 #include <linux/crc-itu-t.h>
23 #include <linux/mmc/host.h>
24 #include <linux/mmc/mmc.h> /* for R1_SPI_* bit values */
25 #include <linux/mmc/slot-gpio.h>
35 * - For now, we won't try to interoperate with a real mmc/sd/sdio
37 * SPI protocol. The main reason for such configs would be mmc-ish
40 * We don't have a "DataFlash/MMC/SD/SDIO card slot" abstraction to
44 * - MMC depends on a different chipselect management policy than the
52 * - We tell the controller to keep the chipselect active from the
54 * of SPI controller drivers that mis-handle the cs_change flag!
98 /* "scratch" is per-{command,block} data exchanged with the card */
106 struct mmc_host *mmc; member
126 * has no need to read its input data; and many cards won't care.
136 * MMC-over-SPI protocol glue, used by the MMC stack interface
142 return spi_setup(host->spi); in mmc_cs_off()
147 if (len > sizeof(*host->data)) { in mmc_spi_readbytes()
149 return -EIO; in mmc_spi_readbytes()
152 host->status.len = len; in mmc_spi_readbytes()
154 return spi_sync_locked(host->spi, &host->readback); in mmc_spi_readbytes()
160 u8 *cp = host->data->status; in mmc_spi_skip()
179 return -ETIMEDOUT; in mmc_spi_skip()
185 return mmc_spi_skip(host, timeout, sizeof(host->data->status), 0); in mmc_spi_wait_unbusy()
195 * Note that for SPI, cmd->resp[0] is not the same data as "native" protocol
199 * cmd->resp[1] holds any four-byte response, for R3 (READ_OCR) and on
214 /* return zero, else negative errno after setting cmd->error */
219 u8 *cp = host->data->status; in mmc_spi_response_get()
220 u8 *end = cp + host->t.len; in mmc_spi_response_get()
229 cmd->opcode, maptype(cmd)); in mmc_spi_response_get()
243 cp = host->data->status; in mmc_spi_response_get()
246 /* Card sends N(CR) (== 1..8) bytes of all-ones then one in mmc_spi_response_get()
249 * REVISIT block read paths use nasty byte-at-a-time I/O in mmc_spi_response_get()
264 value = -ETIMEDOUT; in mmc_spi_response_get()
271 /* Houston, we have an ugly card with a bit-shifted response */ in mmc_spi_response_get()
278 cp = host->data->status; in mmc_spi_response_get()
286 cmd->resp[0] = rotator >> 8; in mmc_spi_response_get()
289 cmd->resp[0] = *cp++; in mmc_spi_response_get()
291 cmd->error = 0; in mmc_spi_response_get()
293 /* Status byte: the entire seven-bit R1 response. */ in mmc_spi_response_get()
294 if (cmd->resp[0] != 0) { in mmc_spi_response_get()
296 & cmd->resp[0]) in mmc_spi_response_get()
297 value = -EFAULT; /* Bad address */ in mmc_spi_response_get()
298 else if (R1_SPI_ILLEGAL_COMMAND & cmd->resp[0]) in mmc_spi_response_get()
299 value = -ENOSYS; /* Function not implemented */ in mmc_spi_response_get()
300 else if (R1_SPI_COM_CRC & cmd->resp[0]) in mmc_spi_response_get()
301 value = -EILSEQ; /* Illegal byte sequence */ in mmc_spi_response_get()
303 & cmd->resp[0]) in mmc_spi_response_get()
304 value = -EIO; /* I/O error */ in mmc_spi_response_get()
311 * and less-common stuff like various erase operations. in mmc_spi_response_get()
318 timeout_ms = cmd->busy_timeout ? cmd->busy_timeout : in mmc_spi_response_get()
333 cp = host->data->status; in mmc_spi_response_get()
339 cmd->resp[0] |= (rotator & 0xFF00); in mmc_spi_response_get()
341 cmd->resp[0] |= *cp << 8; in mmc_spi_response_get()
348 cmd->resp[1] = 0; in mmc_spi_response_get()
350 cmd->resp[1] <<= 8; in mmc_spi_response_get()
356 cp = host->data->status; in mmc_spi_response_get()
361 cmd->resp[1] |= (rotator >> 8); in mmc_spi_response_get()
364 cmd->resp[1] |= *cp++; in mmc_spi_response_get()
374 dev_dbg(&host->spi->dev, "bad response type %04x\n", in mmc_spi_response_get()
377 value = -EINVAL; in mmc_spi_response_get()
382 dev_dbg(&host->spi->dev, "%s: resp %04x %08x\n", in mmc_spi_response_get()
383 tag, cmd->resp[0], cmd->resp[1]); in mmc_spi_response_get()
390 cmd->error = value; in mmc_spi_response_get()
398 * On error, caller must cope with mmc core retry mechanism. That
399 * means immediate low-level resubmit, which affects the bus lock...
406 struct scratch *data = host->data; in mmc_spi_command_send()
407 u8 *cp = data->status; in mmc_spi_command_send()
416 * - an all-ones byte to ensure the card is ready in mmc_spi_command_send()
417 * - opcode byte (plus start and transmission bits) in mmc_spi_command_send()
418 * - four bytes of big-endian argument in mmc_spi_command_send()
419 * - crc7 (plus end bit) ... always computed, it's cheap in mmc_spi_command_send()
421 * We init the whole buffer to all-ones, which is what we need in mmc_spi_command_send()
424 memset(cp, 0xff, sizeof(data->status)); in mmc_spi_command_send()
426 cp[1] = 0x40 | cmd->opcode; in mmc_spi_command_send()
427 put_unaligned_be32(cmd->arg, cp + 2); in mmc_spi_command_send()
431 /* Then, read up to 13 bytes (while writing all-ones): in mmc_spi_command_send()
432 * - N(CR) (== 1..8) bytes of all-ones in mmc_spi_command_send()
433 * - status byte (for all response types) in mmc_spi_command_send()
434 * - the rest of the response, either: in mmc_spi_command_send()
441 * - N(EC) (== 0..N) bytes of all-ones, before deselect/finish in mmc_spi_command_send()
442 * - N(RC) (== 1..N) bytes of all-ones, before next command in mmc_spi_command_send()
443 * - N(WR) (== 1..N) bytes of all-ones, before data write in mmc_spi_command_send()
453 * - R1B responses need at least N(EC) bytes of all-zeroes. in mmc_spi_command_send()
458 * - Data block reads are more troublesome, since a variable in mmc_spi_command_send()
460 * + N(CX) (== 0..8) bytes of all-ones, before CSD or CID in mmc_spi_command_send()
461 * + N(AC) (== 1..many) bytes of all-ones in mmc_spi_command_send()
466 if (cs_on && (mrq->data->flags & MMC_DATA_READ)) { in mmc_spi_command_send()
471 if (cmd->flags & MMC_RSP_SPI_S2) /* R2/R5 */ in mmc_spi_command_send()
473 else if (cmd->flags & MMC_RSP_SPI_B4) /* R3/R4/R7 */ in mmc_spi_command_send()
475 else if (cmd->flags & MMC_RSP_BUSY) /* R1B */ in mmc_spi_command_send()
476 cp = data->status + sizeof(data->status); in mmc_spi_command_send()
480 dev_dbg(&host->spi->dev, " CMD%d, resp %s\n", in mmc_spi_command_send()
481 cmd->opcode, maptype(cmd)); in mmc_spi_command_send()
484 spi_message_init(&host->m); in mmc_spi_command_send()
486 t = &host->t; in mmc_spi_command_send()
488 t->tx_buf = t->rx_buf = data->status; in mmc_spi_command_send()
489 t->len = cp - data->status; in mmc_spi_command_send()
490 t->cs_change = 1; in mmc_spi_command_send()
491 spi_message_add_tail(t, &host->m); in mmc_spi_command_send()
493 status = spi_sync_locked(host->spi, &host->m); in mmc_spi_command_send()
495 dev_dbg(&host->spi->dev, " ... write returned %d\n", status); in mmc_spi_command_send()
496 cmd->error = status; in mmc_spi_command_send()
500 /* after no-data commands and STOP_TRANSMISSION, chipselect off */ in mmc_spi_command_send()
508 * We always provide TX data for data and CRC. The MMC/SD protocol
519 struct scratch *scratch = host->data; in mmc_spi_setup_data_message()
521 spi_message_init(&host->m); in mmc_spi_setup_data_message()
527 t = &host->token; in mmc_spi_setup_data_message()
529 t->len = 1; in mmc_spi_setup_data_message()
531 scratch->data_token = SPI_TOKEN_MULTI_WRITE; in mmc_spi_setup_data_message()
533 scratch->data_token = SPI_TOKEN_SINGLE; in mmc_spi_setup_data_message()
534 t->tx_buf = &scratch->data_token; in mmc_spi_setup_data_message()
535 spi_message_add_tail(t, &host->m); in mmc_spi_setup_data_message()
539 * either TX-only, or RX with TX-ones. in mmc_spi_setup_data_message()
541 t = &host->t; in mmc_spi_setup_data_message()
543 t->tx_buf = host->ones; in mmc_spi_setup_data_message()
545 spi_message_add_tail(t, &host->m); in mmc_spi_setup_data_message()
547 t = &host->crc; in mmc_spi_setup_data_message()
549 t->len = 2; in mmc_spi_setup_data_message()
552 t->tx_buf = &scratch->crc_val; in mmc_spi_setup_data_message()
554 t->tx_buf = host->ones; in mmc_spi_setup_data_message()
555 t->rx_buf = &scratch->crc_val; in mmc_spi_setup_data_message()
557 spi_message_add_tail(t, &host->m); in mmc_spi_setup_data_message()
560 * A single block read is followed by N(EC) [0+] all-ones bytes in mmc_spi_setup_data_message()
563 * Multiblock reads are followed by N(AC) [1+] all-ones bytes before in mmc_spi_setup_data_message()
567 * For a write, the one-byte data response follows immediately, then in mmc_spi_setup_data_message()
568 * come zero or more busy bytes, then N(WR) [1+] all-ones bytes. in mmc_spi_setup_data_message()
571 * minimize I/O ops by using a single read to collect end-of-busy. in mmc_spi_setup_data_message()
574 t = &host->early_status; in mmc_spi_setup_data_message()
576 t->len = (direction == DMA_TO_DEVICE) ? sizeof(scratch->status) : 1; in mmc_spi_setup_data_message()
577 t->tx_buf = host->ones; in mmc_spi_setup_data_message()
578 t->rx_buf = scratch->status; in mmc_spi_setup_data_message()
579 t->cs_change = 1; in mmc_spi_setup_data_message()
580 spi_message_add_tail(t, &host->m); in mmc_spi_setup_data_message()
586 * - caller handled preceding N(WR) [1+] all-ones bytes
587 * - data block
591 * - an all-ones byte ... card writes a data-response byte
592 * - followed by N(EC) [0+] all-ones bytes, card writes zero/'busy'
600 struct spi_device *spi = host->spi; in mmc_spi_writeblock()
602 struct scratch *scratch = host->data; in mmc_spi_writeblock()
605 if (host->mmc->use_spi_crc) in mmc_spi_writeblock()
606 scratch->crc_val = cpu_to_be16(crc_itu_t(0, t->tx_buf, t->len)); in mmc_spi_writeblock()
608 status = spi_sync_locked(spi, &host->m); in mmc_spi_writeblock()
610 dev_dbg(&spi->dev, "write error (%d)\n", status); in mmc_spi_writeblock()
615 * Get the transmission data-response reply. It must follow in mmc_spi_writeblock()
621 * In practice, there are (even modern SDHC-)cards which are late in mmc_spi_writeblock()
624 * bit-by-bit. Arggh!!! in mmc_spi_writeblock()
626 pattern = get_unaligned_be32(scratch->status); in mmc_spi_writeblock()
631 /* left-adjust to leading 0 bit */ in mmc_spi_writeblock()
634 /* right-adjust for pattern matching. Code is in bit 4..0 now. */ in mmc_spi_writeblock()
643 status = -EILSEQ; in mmc_spi_writeblock()
649 status = -EIO; in mmc_spi_writeblock()
652 status = -EPROTO; in mmc_spi_writeblock()
656 dev_dbg(&spi->dev, "write error %02x (%d)\n", in mmc_spi_writeblock()
657 scratch->status[0], status); in mmc_spi_writeblock()
661 t->tx_buf += t->len; in mmc_spi_writeblock()
666 for (i = 4; i < sizeof(scratch->status); i++) { in mmc_spi_writeblock()
667 /* card is non-busy if the most recent bit is 1 */ in mmc_spi_writeblock()
668 if (scratch->status[i] & 0x01) in mmc_spi_writeblock()
676 * - skip leading all-ones bytes ... either
679 * - data block
680 * + token ... if error token, no data or crc
684 * After single block reads, we're done; N(EC) [0+] all-ones bytes follow
694 struct spi_device *spi = host->spi; in mmc_spi_readblock()
696 struct scratch *scratch = host->data; in mmc_spi_readblock()
700 /* At least one SD card sends an all-zeroes byte when N(CX) in mmc_spi_readblock()
701 * applies, before the all-ones bytes ... just cope with that. in mmc_spi_readblock()
706 status = scratch->status[0]; in mmc_spi_readblock()
711 dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status); in mmc_spi_readblock()
715 /* The token may be bit-shifted... in mmc_spi_readblock()
716 * the first 0-bit precedes the data stream. in mmc_spi_readblock()
721 bitshift--; in mmc_spi_readblock()
725 status = spi_sync_locked(spi, &host->m); in mmc_spi_readblock()
727 dev_dbg(&spi->dev, "read error %d\n", status); in mmc_spi_readblock()
733 * all the magic to get byte-aligned data. in mmc_spi_readblock()
735 u8 *cp = t->rx_buf; in mmc_spi_readblock()
737 unsigned int bitright = 8 - bitshift; in mmc_spi_readblock()
739 for (len = t->len; len; len--) { in mmc_spi_readblock()
744 cp = (u8 *) &scratch->crc_val; in mmc_spi_readblock()
752 if (host->mmc->use_spi_crc) { in mmc_spi_readblock()
753 u16 crc = crc_itu_t(0, t->rx_buf, t->len); in mmc_spi_readblock()
755 be16_to_cpus(&scratch->crc_val); in mmc_spi_readblock()
756 if (scratch->crc_val != crc) { in mmc_spi_readblock()
757 dev_dbg(&spi->dev, in mmc_spi_readblock()
758 "read - crc error: crc_val=0x%04x, computed=0x%04x len=%d\n", in mmc_spi_readblock()
759 scratch->crc_val, crc, t->len); in mmc_spi_readblock()
760 return -EILSEQ; in mmc_spi_readblock()
764 t->rx_buf += t->len; in mmc_spi_readblock()
770 * An MMC/SD data stage includes one or more blocks, optional CRCs,
778 struct spi_device *spi = host->spi; in mmc_spi_data_do()
783 bool multiple = (data->blocks > 1); in mmc_spi_data_do()
789 t = &host->t; in mmc_spi_data_do()
791 if (t->speed_hz) in mmc_spi_data_do()
792 clock_rate = t->speed_hz; in mmc_spi_data_do()
794 clock_rate = spi->max_speed_hz; in mmc_spi_data_do()
796 timeout = data->timeout_ns / 1000 + in mmc_spi_data_do()
797 data->timeout_clks * 1000000 / clock_rate; in mmc_spi_data_do()
801 * each 512-byte block in mmc_spi_data_do()
803 for_each_sg(data->sg, sg, data->sg_len, n_sg) { in mmc_spi_data_do()
806 unsigned length = sg->length; in mmc_spi_data_do()
811 t->tx_buf = kmap_addr + sg->offset; in mmc_spi_data_do()
813 t->rx_buf = kmap_addr + sg->offset; in mmc_spi_data_do()
817 t->len = min(length, blk_size); in mmc_spi_data_do()
819 dev_dbg(&spi->dev, " %s block, %d bytes\n", write_or_read, t->len); in mmc_spi_data_do()
828 data->bytes_xfered += t->len; in mmc_spi_data_do()
829 length -= t->len; in mmc_spi_data_do()
841 data->error = status; in mmc_spi_data_do()
842 dev_dbg(&spi->dev, "%s status %d\n", write_or_read, status); in mmc_spi_data_do()
847 /* NOTE some docs describe an MMC-only SET_BLOCK_COUNT (CMD23) that in mmc_spi_data_do()
851 * MMC specs should sort that out before Linux starts using CMD23. in mmc_spi_data_do()
854 struct scratch *scratch = host->data; in mmc_spi_data_do()
856 const unsigned statlen = sizeof(scratch->status); in mmc_spi_data_do()
858 dev_dbg(&spi->dev, " STOP_TRAN\n"); in mmc_spi_data_do()
860 /* Tweak the per-block message we set up earlier by morphing in mmc_spi_data_do()
862 * all-ones bytes ... skip N(BR) (0..1), scan the rest for in mmc_spi_data_do()
865 INIT_LIST_HEAD(&host->m.transfers); in mmc_spi_data_do()
866 list_add(&host->early_status.transfer_list, in mmc_spi_data_do()
867 &host->m.transfers); in mmc_spi_data_do()
869 memset(scratch->status, 0xff, statlen); in mmc_spi_data_do()
870 scratch->status[0] = SPI_TOKEN_STOP_TRAN; in mmc_spi_data_do()
872 host->early_status.tx_buf = host->early_status.rx_buf; in mmc_spi_data_do()
873 host->early_status.len = statlen; in mmc_spi_data_do()
875 tmp = spi_sync_locked(spi, &host->m); in mmc_spi_data_do()
877 if (!data->error) in mmc_spi_data_do()
878 data->error = tmp; in mmc_spi_data_do()
883 * avoiding wasteful byte-at-a-time scanning... but more in mmc_spi_data_do()
887 if (scratch->status[tmp] != 0) in mmc_spi_data_do()
891 if (tmp < 0 && !data->error) in mmc_spi_data_do()
892 data->error = tmp; in mmc_spi_data_do()
899 * MMC driver implementation -- the interface to the MMC stack
902 static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq) in mmc_spi_request() argument
904 struct mmc_spi_host *host = mmc_priv(mmc); in mmc_spi_request()
905 int status = -EINVAL; in mmc_spi_request()
910 /* MMC core and layered drivers *MUST* issue SPI-aware commands */ in mmc_spi_request()
915 cmd = mrq->cmd; in mmc_spi_request()
917 dev_dbg(&host->spi->dev, "bogus command\n"); in mmc_spi_request()
918 cmd->error = -EINVAL; in mmc_spi_request()
922 cmd = mrq->stop; in mmc_spi_request()
924 dev_dbg(&host->spi->dev, "bogus STOP command\n"); in mmc_spi_request()
925 cmd->error = -EINVAL; in mmc_spi_request()
931 mmc_request_done(host->mmc, mrq); in mmc_spi_request()
938 spi_bus_lock(host->spi->master); in mmc_spi_request()
942 status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL); in mmc_spi_request()
943 if (status == 0 && mrq->data) { in mmc_spi_request()
944 mmc_spi_data_do(host, mrq->cmd, mrq->data, mrq->data->blksz); in mmc_spi_request()
953 if (mrq->data->error == -EILSEQ && crc_retry) { in mmc_spi_request()
958 crc_retry--; in mmc_spi_request()
959 mrq->data->error = 0; in mmc_spi_request()
963 if (mrq->stop) in mmc_spi_request()
964 status = mmc_spi_command_send(host, mrq, mrq->stop, 0); in mmc_spi_request()
970 spi_bus_unlock(host->spi->master); in mmc_spi_request()
972 mmc_request_done(host->mmc, mrq); in mmc_spi_request()
978 * not all MMC/SD sockets support power switching.
986 * wait till not-busy, skip debris from any old commands. in mmc_spi_initsequence()
992 * Do a burst with chipselect active-high. We need to do this to in mmc_spi_initsequence()
1000 * Note that this is one of the places MMC/SD plays games with the in mmc_spi_initsequence()
1010 host->spi->mode ^= SPI_CS_HIGH; in mmc_spi_initsequence()
1011 if (spi_setup(host->spi) != 0) { in mmc_spi_initsequence()
1013 dev_warn(&host->spi->dev, in mmc_spi_initsequence()
1014 "can't change chip-select polarity\n"); in mmc_spi_initsequence()
1015 host->spi->mode ^= SPI_CS_HIGH; in mmc_spi_initsequence()
1019 host->spi->mode ^= SPI_CS_HIGH; in mmc_spi_initsequence()
1020 if (spi_setup(host->spi) != 0) { in mmc_spi_initsequence()
1022 dev_err(&host->spi->dev, in mmc_spi_initsequence()
1023 "can't restore chip-select polarity\n"); in mmc_spi_initsequence()
1038 static void mmc_spi_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) in mmc_spi_set_ios() argument
1040 struct mmc_spi_host *host = mmc_priv(mmc); in mmc_spi_set_ios()
1042 if (host->power_mode != ios->power_mode) { in mmc_spi_set_ios()
1045 canpower = host->pdata && host->pdata->setpower; in mmc_spi_set_ios()
1047 dev_dbg(&host->spi->dev, "power %s (%d)%s\n", in mmc_spi_set_ios()
1048 mmc_powerstring(ios->power_mode), in mmc_spi_set_ios()
1049 ios->vdd, in mmc_spi_set_ios()
1056 switch (ios->power_mode) { in mmc_spi_set_ios()
1059 host->pdata->setpower(&host->spi->dev, in mmc_spi_set_ios()
1060 ios->vdd); in mmc_spi_set_ios()
1061 if (ios->power_mode == MMC_POWER_UP) in mmc_spi_set_ios()
1062 msleep(host->powerup_msecs); in mmc_spi_set_ios()
1067 if (ios->power_mode == MMC_POWER_ON) in mmc_spi_set_ios()
1075 * - Clock low means CPOL 0, e.g. mode 0 in mmc_spi_set_ios()
1076 * - MOSI low comes from writing zero in mmc_spi_set_ios()
1077 * - Chipselect is usually active low... in mmc_spi_set_ios()
1079 if (canpower && ios->power_mode == MMC_POWER_OFF) { in mmc_spi_set_ios()
1083 host->spi->mode &= ~(SPI_CPOL|SPI_CPHA); in mmc_spi_set_ios()
1084 mres = spi_setup(host->spi); in mmc_spi_set_ios()
1086 dev_dbg(&host->spi->dev, in mmc_spi_set_ios()
1089 if (spi_write(host->spi, &nullbyte, 1) < 0) in mmc_spi_set_ios()
1090 dev_dbg(&host->spi->dev, in mmc_spi_set_ios()
1097 * power supply is off, so now MMC is off too! in mmc_spi_set_ios()
1099 * FIXME no, chipselect can be high since the in mmc_spi_set_ios()
1104 host->spi->mode |= (SPI_CPOL|SPI_CPHA); in mmc_spi_set_ios()
1105 mres = spi_setup(host->spi); in mmc_spi_set_ios()
1107 dev_dbg(&host->spi->dev, in mmc_spi_set_ios()
1112 host->power_mode = ios->power_mode; in mmc_spi_set_ios()
1115 if (host->spi->max_speed_hz != ios->clock && ios->clock != 0) { in mmc_spi_set_ios()
1118 host->spi->max_speed_hz = ios->clock; in mmc_spi_set_ios()
1119 status = spi_setup(host->spi); in mmc_spi_set_ios()
1120 dev_dbg(&host->spi->dev, " clock to %d Hz, %d\n", in mmc_spi_set_ios()
1121 host->spi->max_speed_hz, status); in mmc_spi_set_ios()
1140 mmc_spi_detect_irq(int irq, void *mmc) in mmc_spi_detect_irq() argument
1142 struct mmc_spi_host *host = mmc_priv(mmc); in mmc_spi_detect_irq()
1143 u16 delay_msec = max(host->pdata->detect_delay, (u16)100); in mmc_spi_detect_irq()
1145 mmc_detect_change(mmc, msecs_to_jiffies(delay_msec)); in mmc_spi_detect_irq()
1152 struct mmc_host *mmc; in mmc_spi_probe() local
1158 * per-transfer overheads (by making fewer transfers). in mmc_spi_probe()
1160 if (spi->master->flags & SPI_CONTROLLER_HALF_DUPLEX) in mmc_spi_probe()
1161 return -EINVAL; in mmc_spi_probe()
1163 /* MMC and SD specs only seem to care that sampling is on the in mmc_spi_probe()
1169 if (spi->mode != SPI_MODE_3) in mmc_spi_probe()
1170 spi->mode = SPI_MODE_0; in mmc_spi_probe()
1171 spi->bits_per_word = 8; in mmc_spi_probe()
1175 dev_dbg(&spi->dev, "needs SPI mode %02x, %d KHz; %d\n", in mmc_spi_probe()
1176 spi->mode, spi->max_speed_hz / 1000, in mmc_spi_probe()
1184 * NOTE if many systems use more than one MMC-over-SPI connector in mmc_spi_probe()
1187 status = -ENOMEM; in mmc_spi_probe()
1193 mmc = mmc_alloc_host(sizeof(*host), &spi->dev); in mmc_spi_probe()
1194 if (!mmc) in mmc_spi_probe()
1197 mmc->ops = &mmc_spi_ops; in mmc_spi_probe()
1198 mmc->max_blk_size = MMC_SPI_BLOCKSIZE; in mmc_spi_probe()
1199 mmc->max_segs = MMC_SPI_BLOCKSATONCE; in mmc_spi_probe()
1200 mmc->max_req_size = MMC_SPI_BLOCKSATONCE * MMC_SPI_BLOCKSIZE; in mmc_spi_probe()
1201 mmc->max_blk_count = MMC_SPI_BLOCKSATONCE; in mmc_spi_probe()
1203 mmc->caps = MMC_CAP_SPI; in mmc_spi_probe()
1206 * MMC or SD cards, since it never comes up in open drain mode. in mmc_spi_probe()
1213 mmc->f_min = 400000; in mmc_spi_probe()
1214 mmc->f_max = spi->max_speed_hz; in mmc_spi_probe()
1216 host = mmc_priv(mmc); in mmc_spi_probe()
1217 host->mmc = mmc; in mmc_spi_probe()
1218 host->spi = spi; in mmc_spi_probe()
1220 host->ones = ones; in mmc_spi_probe()
1222 dev_set_drvdata(&spi->dev, mmc); in mmc_spi_probe()
1227 host->pdata = mmc_spi_get_pdata(spi); in mmc_spi_probe()
1228 if (host->pdata) in mmc_spi_probe()
1229 mmc->ocr_avail = host->pdata->ocr_mask; in mmc_spi_probe()
1230 if (!mmc->ocr_avail) { in mmc_spi_probe()
1231 dev_warn(&spi->dev, "ASSUMING 3.2-3.4 V slot power\n"); in mmc_spi_probe()
1232 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; in mmc_spi_probe()
1234 if (host->pdata && host->pdata->setpower) { in mmc_spi_probe()
1235 host->powerup_msecs = host->pdata->powerup_msecs; in mmc_spi_probe()
1236 if (!host->powerup_msecs || host->powerup_msecs > 250) in mmc_spi_probe()
1237 host->powerup_msecs = 250; in mmc_spi_probe()
1241 host->data = kmalloc(sizeof(*host->data), GFP_KERNEL); in mmc_spi_probe()
1242 if (!host->data) in mmc_spi_probe()
1246 spi_message_init(&host->readback); in mmc_spi_probe()
1248 spi_message_add_tail(&host->status, &host->readback); in mmc_spi_probe()
1249 host->status.tx_buf = host->ones; in mmc_spi_probe()
1250 host->status.rx_buf = &host->data->status; in mmc_spi_probe()
1251 host->status.cs_change = 1; in mmc_spi_probe()
1254 if (host->pdata && host->pdata->init) { in mmc_spi_probe()
1255 status = host->pdata->init(&spi->dev, mmc_spi_detect_irq, mmc); in mmc_spi_probe()
1261 if (host->pdata) { in mmc_spi_probe()
1262 mmc->caps |= host->pdata->caps; in mmc_spi_probe()
1263 mmc->caps2 |= host->pdata->caps2; in mmc_spi_probe()
1266 status = mmc_add_host(mmc); in mmc_spi_probe()
1274 status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1000); in mmc_spi_probe()
1275 if (status == -EPROBE_DEFER) in mmc_spi_probe()
1283 mmc->caps &= ~MMC_CAP_NEEDS_POLL; in mmc_spi_probe()
1284 mmc_gpiod_request_cd_irq(mmc); in mmc_spi_probe()
1286 mmc_detect_change(mmc, 0); in mmc_spi_probe()
1289 status = mmc_gpiod_request_ro(mmc, NULL, 1, 0); in mmc_spi_probe()
1290 if (status == -EPROBE_DEFER) in mmc_spi_probe()
1295 dev_info(&spi->dev, "SD/MMC host %s%s%s%s\n", in mmc_spi_probe()
1296 dev_name(&mmc->class_dev), in mmc_spi_probe()
1297 has_ro ? "" : ", no WP", in mmc_spi_probe()
1298 (host->pdata && host->pdata->setpower) in mmc_spi_probe()
1299 ? "" : ", no poweroff", in mmc_spi_probe()
1300 (mmc->caps & MMC_CAP_NEEDS_POLL) in mmc_spi_probe()
1305 mmc_remove_host(mmc); in mmc_spi_probe()
1307 kfree(host->data); in mmc_spi_probe()
1310 mmc_free_host(mmc); in mmc_spi_probe()
1319 struct mmc_host *mmc = dev_get_drvdata(&spi->dev); in mmc_spi_remove() local
1320 struct mmc_spi_host *host = mmc_priv(mmc); in mmc_spi_remove()
1323 if (host->pdata && host->pdata->exit) in mmc_spi_remove()
1324 host->pdata->exit(&spi->dev, mmc); in mmc_spi_remove()
1326 mmc_remove_host(mmc); in mmc_spi_remove()
1328 kfree(host->data); in mmc_spi_remove()
1329 kfree(host->ones); in mmc_spi_remove()
1331 spi->max_speed_hz = mmc->f_max; in mmc_spi_remove()
1333 mmc_free_host(mmc); in mmc_spi_remove()
1337 { "mmc-spi-slot"},
1343 { .compatible = "mmc-spi-slot", },
1360 MODULE_AUTHOR("Mike Lavender, David Brownell, Hans-Peter Nilsson, Jan Nikitenko");
1361 MODULE_DESCRIPTION("SPI SD/MMC host driver");