mmc: move shared mmc_test and ffu functions to core.c
PATCH 2/3 mmc: move shared mmc_test and ffu functions to core.c
eMMC5.0 FFU is using some of pre-existing mmc_test.c functionality. In order to prevent code duplication, some code of mmc_test.c was moved to core.c and modified.
Signed-off-by Avi Shchislowski <[email protected]>
Signed-off-by Alex Lemberg <[email protected]>
--- drivers/mmc/card/mmc_test.c | 97 ++++---------------------------- drivers/mmc/core/core.c | 128 +++++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/core.h | 8 +++ 3 files changed, 147 insertions(+), 86 deletions(-)
drivers/mmc/card/mmc_test.c +11 -86
@@ -13,6 +13,7 @@#include <linux/mmc/card.h> #include <linux/mmc/host.h> #include <linux/mmc/mmc.h> +#include <linux/mmc/core.h> #include <linux/slab.h> #include <linux/device.h>
@@ -192,43 +193,8 @@ static void mmc_test_prepare_mrq(struct mmc_test_card *test, struct mmc_request *mrq, struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, unsigned blocks, unsigned blksz, int write) { - BUG_ON(!mrq || !mrq->cmd || !mrq->data || !mrq->stop); - -if (blocks >1 ) { - mrq->cmd->opcode = write ? -MMC_WRITE_MULTIPLE_BLOCK :MMC_READ_MULTIPLE_BLOCK ; - }else { - mrq->cmd->opcode = write ? -MMC_WRITE_BLOCK :MMC_READ_SINGLE_BLOCK ; - } - - mrq->cmd->arg = dev_addr; -if (!mmc_card_blockaddr (test->card)) - mrq->cmd->arg <<=9 ; - - mrq->cmd->flags =MMC_RSP_R1 |MMC_CMD_ADTC ; - -if (blocks ==1 ) - mrq->stop =NULL ; -else { - mrq->stop->opcode =MMC_STOP_TRANSMISSION ; - mrq->stop->arg =0 ; - mrq->stop->flags =MMC_RSP_R1B |MMC_CMD_AC ; - } - - mrq->data->blksz = blksz; - mrq->data->blocks = blocks; - mrq->data->flags = write ?MMC_DATA_WRITE :MMC_DATA_READ ; - mrq->data->sg = sg; - mrq->data->sg_len = sg_len; - -mmc_set_data_timeout (mrq->data, test->card); -} - -static int mmc_test_busy (struct mmc_command *cmd) -{ -return !(cmd->resp[0 ] &R1_READY_FOR_DATA ) || - (R1_CURRENT_STATE (cmd->resp[0 ]) ==R1_STATE_PRG ); + mmc_prepare_mrq(test->card, mrq, sg, sg_len, +dev_addr ,blocks ,blksz ,write ); }/*
@@ -236,30 +202,9 @@ static int mmc_test_busy(struct mmc_command *cmd)*/ static int mmc_test_wait_busy (struct mmc_test_card *test) { -int ret, busy; -struct mmc_command cmd = {0 }; - - busy =0 ; -do { -memset (&cmd,0 ,sizeof (struct mmc_command )); - - cmd.opcode =MMC_SEND_STATUS ; - cmd.arg = test->card->rca <<16 ; - cmd.flags =MMC_RSP_R1 |MMC_CMD_AC ; - - ret =mmc_wait_for_cmd (test->card->host, &cmd,0 ); -if (ret) -break ; - -if (!busy &&mmc_test_busy (&cmd)) { - busy =1 ; -if (test->card->host->caps &MMC_CAP_WAIT_WHILE_BUSY ) -pr_info ("%s: Warning: Host did not " -"wait for busy state to end.\n" , -mmc_hostname (test->card->host)); - } - }while (mmc_test_busy (&cmd)); +int ret; + ret =mmc_wait_busy (test->card);return ret; }
@@ -696,19 +641,9 @@ static int mmc_test_check_result(struct mmc_test_card *test, {int ret; -BUG_ON (!mrq || !mrq->cmd || !mrq->data); - ret =0 ; -if (!ret && mrq->cmd->error) - ret = mrq->cmd->error; -if (!ret && mrq->data->error) - ret = mrq->data->error; -if (!ret && mrq->stop && mrq->stop->error) - ret = mrq->stop->error; -if (!ret && mrq->data->bytes_xfered != - mrq->data->blocks * mrq->data->blksz) - ret =RESULT_FAIL ; + ret =mmc_check_result (mrq);if (ret == -EINVAL ) ret =RESULT_UNSUP_HOST ;
@@ -847,23 +782,13 @@ static int mmc_test_simple_transfer(struct mmc_test_card *test, struct scatterlist *sg, unsigned sg_len, unsigned dev_addr, unsigned blocks, unsigned blksz, int write) { - struct mmc_request mrq = {0}; -struct mmc_command cmd = {0 }; -struct mmc_command stop = {0 }; -struct mmc_data data = {0 }; - - mrq.cmd = &cmd; - mrq.data = &data; - mrq.stop = &stop; + int ret; -mmc_test_prepare_mrq (test, &mrq, sg, sg_len, dev_addr, + ret =mmc_simple_transfer (test->card, sg, sg_len, dev_addr, blocks, blksz, write); - -mmc_wait_for_req (test->card->host, &mrq); - -mmc_test_wait_busy (test); - -return mmc_test_check_result (test, &mrq); +if (ret == -EINVAL ) + ret =RESULT_UNSUP_HOST ; +return ret; }/*
drivers/mmc/core/core.c +128 -0
134 lines not on this page · raw message
include/linux/mmc/core.h +8 -0
@@ -196,6 +196,14 @@ extern void mmc_put_card(struct mmc_card *card);extern int mmc_flush_cache (struct mmc_card *);extern int mmc_detect_card_removed (struct mmc_host *host); +extern void mmc_prepare_mrq (struct mmc_card *card, +struct mmc_request *mrq,struct scatterlist *sg,unsigned sg_len, +unsigned dev_addr,unsigned blocks,unsigned blksz,int write); +extern int mmc_wait_busy (struct mmc_card *card); +extern int mmc_check_result (struct mmc_request *mrq); +extern int mmc_simple_transfer (struct mmc_card *card, +struct scatterlist *sg,unsigned sg_len,unsigned dev_addr, +unsigned blocks,unsigned blksz,int write);/** * mmc_claim_host - exclusively claim a host
Signature · 1 line
1.7.9.5