aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hansson <ulf.hansson@linaro.org>2014-01-29 05:01:55 -0500
committerChris Ball <chris@printf.net>2014-02-23 10:40:58 -0500
commitc49433fb66935bd01930e37c7f47d38b6f8135fc (patch)
tree61e31de25238df4f3139315920e6592fa9877ffe
parentbcc3e1726d827c2d6f62f0e0e7bbc99eed7ad925 (diff)
mmc: block: Implement card_busy_detect() for busy detection
To complete a data write request we poll for the card's status register by sending CMD13. The are other scenarios when this polling method are needed, which is why we here moves this code to it's own function. No functional change. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Chris Ball <chris@printf.net>
-rw-r--r--drivers/mmc/card/block.c82
1 files changed, 47 insertions, 35 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 156cabfa61c3..fffa83359c67 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -749,6 +749,49 @@ static int get_card_status(struct mmc_card *card, u32 *status, int retries)
749 return err; 749 return err;
750} 750}
751 751
752static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
753 struct request *req, int *gen_err)
754{
755 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
756 int err = 0;
757 u32 status;
758
759 do {
760 err = get_card_status(card, &status, 5);
761 if (err) {
762 pr_err("%s: error %d requesting status\n",
763 req->rq_disk->disk_name, err);
764 return err;
765 }
766
767 if (status & R1_ERROR) {
768 pr_err("%s: %s: error sending status cmd, status %#x\n",
769 req->rq_disk->disk_name, __func__, status);
770 *gen_err = 1;
771 }
772
773 /*
774 * Timeout if the device never becomes ready for data and never
775 * leaves the program state.
776 */
777 if (time_after(jiffies, timeout)) {
778 pr_err("%s: Card stuck in programming state! %s %s\n",
779 mmc_hostname(card->host),
780 req->rq_disk->disk_name, __func__);
781 return -ETIMEDOUT;
782 }
783
784 /*
785 * Some cards mishandle the status bits,
786 * so make sure to check both the busy
787 * indication and the card state.
788 */
789 } while (!(status & R1_READY_FOR_DATA) ||
790 (R1_CURRENT_STATE(status) == R1_STATE_PRG));
791
792 return err;
793}
794
752#define ERR_NOMEDIUM 3 795#define ERR_NOMEDIUM 3
753#define ERR_RETRY 2 796#define ERR_RETRY 2
754#define ERR_ABORT 1 797#define ERR_ABORT 1
@@ -1156,8 +1199,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
1156 * program mode, which we have to wait for it to complete. 1199 * program mode, which we have to wait for it to complete.
1157 */ 1200 */
1158 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { 1201 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
1159 u32 status; 1202 int err;
1160 unsigned long timeout;
1161 1203
1162 /* Check stop command response */ 1204 /* Check stop command response */
1163 if (brq->stop.resp[0] & R1_ERROR) { 1205 if (brq->stop.resp[0] & R1_ERROR) {
@@ -1167,39 +1209,9 @@ static int mmc_blk_err_check(struct mmc_card *card,
1167 gen_err = 1; 1209 gen_err = 1;
1168 } 1210 }
1169 1211
1170 timeout = jiffies + msecs_to_jiffies(MMC_BLK_TIMEOUT_MS); 1212 err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, req, &gen_err);
1171 do { 1213 if (err)
1172 int err = get_card_status(card, &status, 5); 1214 return MMC_BLK_CMD_ERR;
1173 if (err) {
1174 pr_err("%s: error %d requesting status\n",
1175 req->rq_disk->disk_name, err);
1176 return MMC_BLK_CMD_ERR;
1177 }
1178
1179 if (status & R1_ERROR) {
1180 pr_err("%s: %s: general error sending status command, card status %#x\n",
1181 req->rq_disk->disk_name, __func__,
1182 status);
1183 gen_err = 1;
1184 }
1185
1186 /* Timeout if the device never becomes ready for data
1187 * and never leaves the program state.
1188 */
1189 if (time_after(jiffies, timeout)) {
1190 pr_err("%s: Card stuck in programming state!"\
1191 " %s %s\n", mmc_hostname(card->host),
1192 req->rq_disk->disk_name, __func__);
1193
1194 return MMC_BLK_CMD_ERR;
1195 }
1196 /*
1197 * Some cards mishandle the status bits,
1198 * so make sure to check both the busy
1199 * indication and the card state.
1200 */
1201 } while (!(status & R1_READY_FOR_DATA) ||
1202 (R1_CURRENT_STATE(status) == R1_STATE_PRG));
1203 } 1215 }
1204 1216
1205 /* if general error occurs, retry the write operation. */ 1217 /* if general error occurs, retry the write operation. */