Skip to content

Commit

Permalink
[MMC] Cleanup 385e322
Browse files Browse the repository at this point in the history
Rather than having two places which independently calculate the
timeout for data transfers, make it a library function instead.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Acked-by: Pierre Ossman <drzeus@drzeus.cx>
  • Loading branch information
Russell King authored and Russell King committed Sep 7, 2006
1 parent 148f93d commit d773d72
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 48 deletions.
64 changes: 50 additions & 14 deletions drivers/mmc/mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,55 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, unsigned int rca,

EXPORT_SYMBOL(mmc_wait_for_app_cmd);

/**
* mmc_set_data_timeout - set the timeout for a data command
* @data: data phase for command
* @card: the MMC card associated with the data transfer
* @write: flag to differentiate reads from writes
*/
void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
int write)
{
unsigned int mult;

/*
* SD cards use a 100 multiplier rather than 10
*/
mult = mmc_card_sd(card) ? 100 : 10;

/*
* Scale up the multiplier (and therefore the timeout) by
* the r2w factor for writes.
*/
if (write)
mult <<= card->csd.r2w_factor;

data->timeout_ns = card->csd.tacc_ns * mult;
data->timeout_clks = card->csd.tacc_clks * mult;

/*
* SD cards also have an upper limit on the timeout.
*/
if (mmc_card_sd(card)) {
unsigned int timeout_us, limit_us;

timeout_us = data->timeout_ns / 1000;
timeout_us += data->timeout_clks * 1000 /
(card->host->ios.clock / 1000);

if (write)
limit_us = 250000;
else
limit_us = 100000;

if (timeout_us > limit_us) {
data->timeout_ns = limit_us * 1000;
data->timeout_clks = 0;
}
}
}
EXPORT_SYMBOL(mmc_set_data_timeout);

static int mmc_select_card(struct mmc_host *host, struct mmc_card *card);

/**
Expand Down Expand Up @@ -908,12 +957,9 @@ static void mmc_read_scrs(struct mmc_host *host)
{
int err;
struct mmc_card *card;

struct mmc_request mrq;
struct mmc_command cmd;
struct mmc_data data;
unsigned int timeout_us;

struct scatterlist sg;

list_for_each_entry(card, &host->cards, node) {
Expand Down Expand Up @@ -948,17 +994,7 @@ static void mmc_read_scrs(struct mmc_host *host)

memset(&data, 0, sizeof(struct mmc_data));

data.timeout_ns = card->csd.tacc_ns * 100;
data.timeout_clks = card->csd.tacc_clks * 100;

timeout_us = data.timeout_ns / 1000;
timeout_us += data.timeout_clks * 1000 /
(host->ios.clock / 1000);

if (timeout_us > 100000) {
data.timeout_ns = 100000000;
data.timeout_clks = 0;
}
mmc_set_data_timeout(&data, card, 0);

data.blksz_bits = 3;
data.blksz = 1 << 3;
Expand Down
35 changes: 1 addition & 34 deletions drivers/mmc/mmc_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,40 +179,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
brq.stop.arg = 0;
brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC;

brq.data.timeout_ns = card->csd.tacc_ns * 10;
brq.data.timeout_clks = card->csd.tacc_clks * 10;

/*
* Scale up the timeout by the r2w factor
*/
if (rq_data_dir(req) == WRITE) {
brq.data.timeout_ns <<= card->csd.r2w_factor;
brq.data.timeout_clks <<= card->csd.r2w_factor;
}

/*
* SD cards use a 100 multiplier and has a upper limit
*/
if (mmc_card_sd(card)) {
unsigned int limit_us, timeout_us;

brq.data.timeout_ns *= 10;
brq.data.timeout_clks *= 10;

if (rq_data_dir(req) == READ)
limit_us = 100000;
else
limit_us = 250000;

timeout_us = brq.data.timeout_ns / 1000;
timeout_us += brq.data.timeout_clks * 1000 /
(card->host->ios.clock / 1000);

if (timeout_us > limit_us) {
brq.data.timeout_ns = limit_us * 1000;
brq.data.timeout_clks = 0;
}
}
mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);

if (rq_data_dir(req) == READ) {
brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK;
Expand Down
2 changes: 2 additions & 0 deletions include/linux/mmc/mmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
extern int mmc_wait_for_app_cmd(struct mmc_host *, unsigned int,
struct mmc_command *, int);

extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *, int);

extern int __mmc_claim_host(struct mmc_host *host, struct mmc_card *card);

static inline void mmc_claim_host(struct mmc_host *host)
Expand Down

0 comments on commit d773d72

Please sign in to comment.