2007-05-21 22:23:20 +04:00
|
|
|
/*
|
|
|
|
* linux/drivers/mmc/sdio_ops.c
|
|
|
|
*
|
|
|
|
* Copyright 2006-2007 Pierre Ossman
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2007-07-06 15:35:01 +04:00
|
|
|
#include <asm/scatterlist.h>
|
|
|
|
#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"
|
|
|
|
|
|
|
|
int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
|
|
|
|
{
|
|
|
|
struct mmc_command cmd;
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
BUG_ON(!host);
|
|
|
|
|
|
|
|
memset(&cmd, 0, sizeof(struct mmc_command));
|
|
|
|
|
|
|
|
cmd.opcode = SD_IO_SEND_OP_COND;
|
|
|
|
cmd.arg = ocr;
|
|
|
|
cmd.flags = MMC_RSP_R4 | MMC_CMD_BCR;
|
|
|
|
|
|
|
|
for (i = 100; i; i--) {
|
|
|
|
err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
|
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
err = -ETIMEDOUT;
|
|
|
|
|
|
|
|
mmc_delay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rocr)
|
|
|
|
*rocr = cmd.resp[0];
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-05-22 22:25:21 +04:00
|
|
|
int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
|
|
|
|
unsigned addr, u8 in, u8* out)
|
|
|
|
{
|
|
|
|
struct mmc_command cmd;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
BUG_ON(!card);
|
|
|
|
BUG_ON(fn > 7);
|
|
|
|
|
|
|
|
memset(&cmd, 0, sizeof(struct mmc_command));
|
|
|
|
|
|
|
|
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;
|
|
|
|
cmd.flags = MMC_RSP_R5 | MMC_CMD_AC;
|
|
|
|
|
|
|
|
err = mmc_wait_for_cmd(card->host, &cmd, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (out)
|
|
|
|
*out = cmd.resp[0] & 0xFF;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct mmc_request mrq;
|
|
|
|
struct mmc_command cmd;
|
|
|
|
struct mmc_data data;
|
|
|
|
struct scatterlist sg;
|
|
|
|
|
|
|
|
BUG_ON(!card);
|
|
|
|
BUG_ON(fn > 7);
|
2007-08-08 17:24:21 +04:00
|
|
|
BUG_ON(blocks == 1 && blksz > 512);
|
|
|
|
WARN_ON(blocks == 0);
|
|
|
|
WARN_ON(blksz == 0);
|
2007-07-06 15:35:01 +04:00
|
|
|
|
|
|
|
memset(&mrq, 0, sizeof(struct mmc_request));
|
|
|
|
memset(&cmd, 0, sizeof(struct mmc_command));
|
|
|
|
memset(&data, 0, sizeof(struct mmc_data));
|
|
|
|
|
|
|
|
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;
|
2007-08-08 17:24:21 +04:00
|
|
|
if (blocks == 1 && blksz <= 512)
|
|
|
|
cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */
|
|
|
|
else
|
|
|
|
cmd.arg |= 0x08000000 | blocks; /* block mode */
|
2007-07-06 15:35:01 +04:00
|
|
|
cmd.flags = MMC_RSP_R5 | MMC_CMD_ADTC;
|
|
|
|
|
2007-08-08 17:24:21 +04:00
|
|
|
data.blksz = blksz;
|
|
|
|
data.blocks = blocks;
|
2007-07-06 15:35:01 +04:00
|
|
|
data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
|
|
|
|
data.sg = &sg;
|
|
|
|
data.sg_len = 1;
|
|
|
|
|
2007-08-08 17:24:21 +04:00
|
|
|
sg_init_one(&sg, buf, blksz * blocks);
|
2007-07-06 15:35:01 +04:00
|
|
|
|
|
|
|
mmc_set_data_timeout(&data, card);
|
|
|
|
|
|
|
|
mmc_wait_for_req(card->host, &mrq);
|
|
|
|
|
|
|
|
if (cmd.error)
|
|
|
|
return cmd.error;
|
|
|
|
if (data.error)
|
|
|
|
return data.error;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|