2019-05-27 09:55:01 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-05-21 22:23:20 +04:00
|
|
|
/*
|
|
|
|
* linux/drivers/mmc/sdio_ops.c
|
|
|
|
*
|
|
|
|
* Copyright 2006-2007 Pierre Ossman
|
|
|
|
*/
|
|
|
|
|
2007-07-06 15:35:01 +04:00
|
|
|
#include <linux/scatterlist.h>
|
|
|
|
|
2007-05-21 22:23:20 +04:00
|
|
|
#include <linux/mmc/host.h>
|
2007-05-22 22:25:21 +04:00
|
|
|
#include <linux/mmc/card.h>
|
2007-05-21 22:23:20 +04:00
|
|
|
#include <linux/mmc/mmc.h>
|
|
|
|
#include <linux/mmc/sdio.h>
|
|
|
|
|
|
|
|
#include "core.h"
|
2008-04-13 22:15:52 +04:00
|
|
|
#include "sdio_ops.h"
|
2007-05-21 22:23:20 +04:00
|
|
|
|
|
|
|
int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
|
|
|
|
{
|
2016-12-19 14:51:18 +03:00
|
|
|
struct mmc_command cmd = {};
|
2007-05-21 22:23:20 +04:00
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
cmd.opcode = SD_IO_SEND_OP_COND;
|
|
|
|
cmd.arg = ocr;
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
cmd.flags = MMC_RSP_SPI_R4 | MMC_RSP_R4 | MMC_CMD_BCR;
|
2007-05-21 22:23:20 +04:00
|
|
|
|
|
|
|
for (i = 100; i; i--) {
|
|
|
|
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
/* if we're just probing, do a single pass */
|
|
|
|
if (ocr == 0)
|
2007-05-21 22:23:20 +04:00
|
|
|
break;
|
|
|
|
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
/* otherwise wait until reset completes */
|
|
|
|
if (mmc_host_is_spi(host)) {
|
|
|
|
/*
|
|
|
|
* Both R1_SPI_IDLE and MMC_CARD_BUSY indicate
|
|
|
|
* an initialized card under SPI, but some cards
|
|
|
|
* (Marvell's) only behave when looking at this
|
|
|
|
* one.
|
|
|
|
*/
|
|
|
|
if (cmd.resp[1] & MMC_CARD_BUSY)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (cmd.resp[0] & MMC_CARD_BUSY)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-05-21 22:23:20 +04:00
|
|
|
err = -ETIMEDOUT;
|
|
|
|
|
|
|
|
mmc_delay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rocr)
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
*rocr = cmd.resp[mmc_host_is_spi(host) ? 1 : 0];
|
2007-05-21 22:23:20 +04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:37 +03:00
|
|
|
static int mmc_io_rw_direct_host(struct mmc_host *host, int write, unsigned fn,
|
|
|
|
unsigned addr, u8 in, u8 *out)
|
2007-05-22 22:25:21 +04:00
|
|
|
{
|
2016-12-19 14:51:18 +03:00
|
|
|
struct mmc_command cmd = {};
|
2007-05-22 22:25:21 +04:00
|
|
|
int err;
|
|
|
|
|
2016-08-26 03:49:56 +03:00
|
|
|
if (fn > 7)
|
|
|
|
return -EINVAL;
|
2007-05-22 22:25:21 +04:00
|
|
|
|
2009-03-05 21:40:27 +03:00
|
|
|
/* sanity check */
|
|
|
|
if (addr & ~0x1FFFF)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-05-22 22:25:21 +04:00
|
|
|
cmd.opcode = SD_IO_RW_DIRECT;
|
|
|
|
cmd.arg = write ? 0x80000000 : 0x00000000;
|
|
|
|
cmd.arg |= fn << 28;
|
|
|
|
cmd.arg |= (write && out) ? 0x08000000 : 0x00000000;
|
|
|
|
cmd.arg |= addr << 9;
|
|
|
|
cmd.arg |= in;
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
|
2007-05-22 22:25:21 +04:00
|
|
|
|
2010-03-11 02:20:37 +03:00
|
|
|
err = mmc_wait_for_cmd(host, &cmd, 0);
|
2007-05-22 22:25:21 +04:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2010-03-11 02:20:37 +03:00
|
|
|
if (mmc_host_is_spi(host)) {
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
/* host driver already reported errors */
|
|
|
|
} else {
|
|
|
|
if (cmd.resp[0] & R5_ERROR)
|
|
|
|
return -EIO;
|
|
|
|
if (cmd.resp[0] & R5_FUNCTION_NUMBER)
|
|
|
|
return -EINVAL;
|
|
|
|
if (cmd.resp[0] & R5_OUT_OF_RANGE)
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
2007-05-22 22:25:21 +04:00
|
|
|
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
if (out) {
|
2010-03-11 02:20:37 +03:00
|
|
|
if (mmc_host_is_spi(host))
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
*out = (cmd.resp[0] >> 8) & 0xFF;
|
|
|
|
else
|
|
|
|
*out = cmd.resp[0] & 0xFF;
|
|
|
|
}
|
2007-05-22 22:25:21 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:37 +03:00
|
|
|
int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
|
|
|
|
unsigned addr, u8 in, u8 *out)
|
|
|
|
{
|
|
|
|
return mmc_io_rw_direct_host(card->host, write, fn, addr, in, out);
|
|
|
|
}
|
|
|
|
|
2007-07-06 15:35:01 +04:00
|
|
|
int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
|
2007-08-08 17:24:21 +04:00
|
|
|
unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz)
|
2007-07-06 15:35:01 +04:00
|
|
|
{
|
2016-12-19 14:51:18 +03:00
|
|
|
struct mmc_request mrq = {};
|
|
|
|
struct mmc_command cmd = {};
|
|
|
|
struct mmc_data data = {};
|
2012-10-22 15:01:00 +04:00
|
|
|
struct scatterlist sg, *sg_ptr;
|
|
|
|
struct sg_table sgtable;
|
|
|
|
unsigned int nents, left_size, i;
|
|
|
|
unsigned int seg_size = card->host->max_seg_size;
|
2007-07-06 15:35:01 +04:00
|
|
|
|
2007-08-08 17:24:21 +04:00
|
|
|
WARN_ON(blksz == 0);
|
2007-07-06 15:35:01 +04:00
|
|
|
|
2009-03-05 21:40:27 +03:00
|
|
|
/* sanity check */
|
|
|
|
if (addr & ~0x1FFFF)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2007-07-06 15:35:01 +04:00
|
|
|
mrq.cmd = &cmd;
|
|
|
|
mrq.data = &data;
|
|
|
|
|
|
|
|
cmd.opcode = SD_IO_RW_EXTENDED;
|
|
|
|
cmd.arg = write ? 0x80000000 : 0x00000000;
|
|
|
|
cmd.arg |= fn << 28;
|
2007-08-08 17:24:21 +04:00
|
|
|
cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
|
2007-07-06 15:35:01 +04:00
|
|
|
cmd.arg |= addr << 9;
|
2011-10-26 12:52:17 +04:00
|
|
|
if (blocks == 0)
|
|
|
|
cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */
|
2007-08-08 17:24:21 +04:00
|
|
|
else
|
|
|
|
cmd.arg |= 0x08000000 | blocks; /* block mode */
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
|
2007-07-06 15:35:01 +04:00
|
|
|
|
2007-08-08 17:24:21 +04:00
|
|
|
data.blksz = blksz;
|
2011-10-26 12:52:17 +04:00
|
|
|
/* Code in host drivers/fwk assumes that "blocks" always is >=1 */
|
|
|
|
data.blocks = blocks ? blocks : 1;
|
2007-07-06 15:35:01 +04:00
|
|
|
data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
|
|
|
|
|
2012-10-22 15:01:00 +04:00
|
|
|
left_size = data.blksz * data.blocks;
|
2017-03-22 23:59:29 +03:00
|
|
|
nents = DIV_ROUND_UP(left_size, seg_size);
|
2012-10-22 15:01:00 +04:00
|
|
|
if (nents > 1) {
|
|
|
|
if (sg_alloc_table(&sgtable, nents, GFP_KERNEL))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
data.sg = sgtable.sgl;
|
|
|
|
data.sg_len = nents;
|
|
|
|
|
|
|
|
for_each_sg(data.sg, sg_ptr, data.sg_len, i) {
|
2017-03-22 23:59:29 +03:00
|
|
|
sg_set_buf(sg_ptr, buf + i * seg_size,
|
|
|
|
min(seg_size, left_size));
|
|
|
|
left_size -= seg_size;
|
2012-10-22 15:01:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data.sg = &sg;
|
|
|
|
data.sg_len = 1;
|
|
|
|
|
|
|
|
sg_init_one(&sg, buf, left_size);
|
|
|
|
}
|
2007-07-06 15:35:01 +04:00
|
|
|
|
|
|
|
mmc_set_data_timeout(&data, card);
|
|
|
|
|
|
|
|
mmc_wait_for_req(card->host, &mrq);
|
|
|
|
|
2012-10-22 15:01:00 +04:00
|
|
|
if (nents > 1)
|
|
|
|
sg_free_table(&sgtable);
|
|
|
|
|
2007-07-06 15:35:01 +04:00
|
|
|
if (cmd.error)
|
|
|
|
return cmd.error;
|
|
|
|
if (data.error)
|
|
|
|
return data.error;
|
|
|
|
|
MMC core learns about SPI
Teach the MMC/SD/SDIO core about using SPI mode.
- Use mmc_host_is_spi() so enumeration works through SPI signaling
and protocols, not just the native versions.
- Provide the SPI response type flags with each request issued,
including requests from the new lock/unlock code.
- Understand that cmd->resp[0] and mmc_get_status() results for SPI
return different values than for "native" MMC/SD protocol; this
affects resetting, checking card lock status, and some others.
- Understand that some commands act a bit differently ... notably:
* OP_COND command doesn't return the OCR
* APP_CMD status doesn't have an R1_APP_CMD analogue
Those changes required some new and updated primitives:
- Provide utilities to access two SPI-only requests, and one
request that wasn't previously needed:
* mmc_spi_read_ocr() ... SPI only
* mmc_spi_set_crc() ... SPI only (override by module parm)
* mmc_send_cid() ... for use without broadcast mode
- Updated internal routines:
* Previous mmc_send_csd() modified into mmc_send_cxd_native();
it uses native "R2" responses, which include 16 bytes of data.
* Previous mmc_send_ext_csd() becomes new mmc_send_cxd_data()
helper for command-and-data access
* Bugfix to that mmc_send_cxd_data() code: dma-to-stack is
unsafe/nonportable, so kmalloc a bounce buffer instead.
- Modified mmc_send_ext_csd() now uses mmc_send_cxd_data() helper
- Modified mmc_send_csd(), and new mmc_spi_send_cid(), routines use
those helper routines based on whether they're native or SPI
The newest categories of cards supported by the MMC stack aren't expected
to work yet with SPI: MMC or SD cards with over 4GB data, and SDIO.
All those cards support SPI mode, so eventually they should work too.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>
2007-08-08 20:11:32 +04:00
|
|
|
if (mmc_host_is_spi(card->host)) {
|
|
|
|
/* host driver already reported errors */
|
|
|
|
} else {
|
|
|
|
if (cmd.resp[0] & R5_ERROR)
|
|
|
|
return -EIO;
|
|
|
|
if (cmd.resp[0] & R5_FUNCTION_NUMBER)
|
|
|
|
return -EINVAL;
|
|
|
|
if (cmd.resp[0] & R5_OUT_OF_RANGE)
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
2007-07-06 15:35:01 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-11 02:20:37 +03:00
|
|
|
int sdio_reset(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 abort;
|
|
|
|
|
|
|
|
/* SDIO Simplified Specification V2.0, 4.4 Reset for SDIO */
|
|
|
|
|
|
|
|
ret = mmc_io_rw_direct_host(host, 0, 0, SDIO_CCCR_ABORT, 0, &abort);
|
|
|
|
if (ret)
|
|
|
|
abort = 0x08;
|
|
|
|
else
|
|
|
|
abort |= 0x08;
|
|
|
|
|
2016-01-08 05:15:25 +03:00
|
|
|
return mmc_io_rw_direct_host(host, 1, 0, SDIO_CCCR_ABORT, abort, NULL);
|
2010-03-11 02:20:37 +03:00
|
|
|
}
|
|
|
|
|