aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/card
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-04-09 11:39:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-04-09 11:39:39 -0400
commit97e18dc007546fce8e99098480b921a02ebb3037 (patch)
treef38c022d034e0172e83f6972983577f790f24dac /drivers/mmc/card
parent042f7b7cbd1e531278a09c449563165ba1f07673 (diff)
parentc67480173f72e883235dd0ad09d90156c8f87600 (diff)
Merge tag 'mmc-updates-for-3.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
Pull MMC updates from Chris Ball: "MMC highlights for 3.15: Core: - CONFIG_MMC_UNSAFE_RESUME=y is now default behavior - DT bindings for SDHCI UHS, eMMC HS200, high-speed DDR, at 1.8/1.2V - Add GPIO descriptor based slot-gpio card detect API Drivers: - dw_mmc: Refactor SOCFPGA support as a variant inside dw_mmc-pltfm.c - mmci: Support HW busy detection on ux500 - omap: Support MMC_ERASE - omap_hsmmc: Support MMC_PM_KEEP_POWER, MMC_PM_WAKE_SDIO_IRQ, (a)cmd23 - rtsx: Support pre-req/post-req async - sdhci: Add support for Realtek RTS5250 controllers - sdhci-acpi: Add support for 80860F16, fix 80860F14/SDIO card detect - sdhci-msm: Add new driver for Qualcomm SDHCI chipset support - sdhci-pxav3: Add support for Marvell Armada 380 and 385 SoCs" * tag 'mmc-updates-for-3.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (102 commits) mmc: sdhci-acpi: Intel SDIO has broken card detect mmc: sdhci-pxav3: add support for the Armada 38x SDHCI controller mmc: sdhci-msm: Add platform_execute_tuning implementation mmc: sdhci-msm: Initial support for Qualcomm chipsets mmc: sdhci-msm: Qualcomm SDHCI binding documentation sdhci: only reprogram retuning timer when flag is set mmc: rename ARCH_BCM to ARCH_BCM_MOBILE mmc: sdhci: Allow for irq being shared mmc: sdhci-acpi: Add device id 80860F16 mmc: sdhci-acpi: Fix broken card detect for ACPI HID 80860F14 mmc: slot-gpio: Add GPIO descriptor based CD GPIO API mmc: slot-gpio: Split out CD IRQ request into a separate function mmc: slot-gpio: Record GPIO descriptors instead of GPIO numbers Revert "dts: socfpga: Add support for SD/MMC on the SOCFPGA platform" mmc: sdhci-spear: use generic card detection gpio support mmc: sdhci-spear: remove support for power gpio mmc: sdhci-spear: simplify resource handling mmc: sdhci-spear: fix platform_data usage mmc: sdhci-spear: fix error handling paths for DT mmc: sdhci-bcm-kona: fix build errors when built-in ...
Diffstat (limited to 'drivers/mmc/card')
-rw-r--r--drivers/mmc/card/block.c181
1 files changed, 115 insertions, 66 deletions
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 7b5424f398ac..452782bffebc 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -415,8 +415,7 @@ static int ioctl_do_sanitize(struct mmc_card *card)
415{ 415{
416 int err; 416 int err;
417 417
418 if (!(mmc_can_sanitize(card) && 418 if (!mmc_can_sanitize(card)) {
419 (card->host->caps2 & MMC_CAP2_SANITIZE))) {
420 pr_warn("%s: %s - SANITIZE is not supported\n", 419 pr_warn("%s: %s - SANITIZE is not supported\n",
421 mmc_hostname(card->host), __func__); 420 mmc_hostname(card->host), __func__);
422 err = -EOPNOTSUPP; 421 err = -EOPNOTSUPP;
@@ -722,19 +721,6 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
722 return result; 721 return result;
723} 722}
724 723
725static int send_stop(struct mmc_card *card, u32 *status)
726{
727 struct mmc_command cmd = {0};
728 int err;
729
730 cmd.opcode = MMC_STOP_TRANSMISSION;
731 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
732 err = mmc_wait_for_cmd(card->host, &cmd, 5);
733 if (err == 0)
734 *status = cmd.resp[0];
735 return err;
736}
737
738static int get_card_status(struct mmc_card *card, u32 *status, int retries) 724static int get_card_status(struct mmc_card *card, u32 *status, int retries)
739{ 725{
740 struct mmc_command cmd = {0}; 726 struct mmc_command cmd = {0};
@@ -750,6 +736,99 @@ static int get_card_status(struct mmc_card *card, u32 *status, int retries)
750 return err; 736 return err;
751} 737}
752 738
739static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
740 bool hw_busy_detect, struct request *req, int *gen_err)
741{
742 unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
743 int err = 0;
744 u32 status;
745
746 do {
747 err = get_card_status(card, &status, 5);
748 if (err) {
749 pr_err("%s: error %d requesting status\n",
750 req->rq_disk->disk_name, err);
751 return err;
752 }
753
754 if (status & R1_ERROR) {
755 pr_err("%s: %s: error sending status cmd, status %#x\n",
756 req->rq_disk->disk_name, __func__, status);
757 *gen_err = 1;
758 }
759
760 /* We may rely on the host hw to handle busy detection.*/
761 if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) &&
762 hw_busy_detect)
763 break;
764
765 /*
766 * Timeout if the device never becomes ready for data and never
767 * leaves the program state.
768 */
769 if (time_after(jiffies, timeout)) {
770 pr_err("%s: Card stuck in programming state! %s %s\n",
771 mmc_hostname(card->host),
772 req->rq_disk->disk_name, __func__);
773 return -ETIMEDOUT;
774 }
775
776 /*
777 * Some cards mishandle the status bits,
778 * so make sure to check both the busy
779 * indication and the card state.
780 */
781 } while (!(status & R1_READY_FOR_DATA) ||
782 (R1_CURRENT_STATE(status) == R1_STATE_PRG));
783
784 return err;
785}
786
787static int send_stop(struct mmc_card *card, unsigned int timeout_ms,
788 struct request *req, int *gen_err, u32 *stop_status)
789{
790 struct mmc_host *host = card->host;
791 struct mmc_command cmd = {0};
792 int err;
793 bool use_r1b_resp = rq_data_dir(req) == WRITE;
794
795 /*
796 * Normally we use R1B responses for WRITE, but in cases where the host
797 * has specified a max_busy_timeout we need to validate it. A failure
798 * means we need to prevent the host from doing hw busy detection, which
799 * is done by converting to a R1 response instead.
800 */
801 if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout))
802 use_r1b_resp = false;
803
804 cmd.opcode = MMC_STOP_TRANSMISSION;
805 if (use_r1b_resp) {
806 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
807 cmd.busy_timeout = timeout_ms;
808 } else {
809 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
810 }
811
812 err = mmc_wait_for_cmd(host, &cmd, 5);
813 if (err)
814 return err;
815
816 *stop_status = cmd.resp[0];
817
818 /* No need to check card status in case of READ. */
819 if (rq_data_dir(req) == READ)
820 return 0;
821
822 if (!mmc_host_is_spi(host) &&
823 (*stop_status & R1_ERROR)) {
824 pr_err("%s: %s: general error sending stop command, resp %#x\n",
825 req->rq_disk->disk_name, __func__, *stop_status);
826 *gen_err = 1;
827 }
828
829 return card_busy_detect(card, timeout_ms, use_r1b_resp, req, gen_err);
830}
831
753#define ERR_NOMEDIUM 3 832#define ERR_NOMEDIUM 3
754#define ERR_RETRY 2 833#define ERR_RETRY 2
755#define ERR_ABORT 1 834#define ERR_ABORT 1
@@ -866,26 +945,21 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
866 */ 945 */
867 if (R1_CURRENT_STATE(status) == R1_STATE_DATA || 946 if (R1_CURRENT_STATE(status) == R1_STATE_DATA ||
868 R1_CURRENT_STATE(status) == R1_STATE_RCV) { 947 R1_CURRENT_STATE(status) == R1_STATE_RCV) {
869 err = send_stop(card, &stop_status); 948 err = send_stop(card,
870 if (err) 949 DIV_ROUND_UP(brq->data.timeout_ns, 1000000),
950 req, gen_err, &stop_status);
951 if (err) {
871 pr_err("%s: error %d sending stop command\n", 952 pr_err("%s: error %d sending stop command\n",
872 req->rq_disk->disk_name, err); 953 req->rq_disk->disk_name, err);
873 954 /*
874 /* 955 * If the stop cmd also timed out, the card is probably
875 * If the stop cmd also timed out, the card is probably 956 * not present, so abort. Other errors are bad news too.
876 * not present, so abort. Other errors are bad news too. 957 */
877 */
878 if (err)
879 return ERR_ABORT; 958 return ERR_ABORT;
959 }
960
880 if (stop_status & R1_CARD_ECC_FAILED) 961 if (stop_status & R1_CARD_ECC_FAILED)
881 *ecc_err = 1; 962 *ecc_err = 1;
882 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ)
883 if (stop_status & R1_ERROR) {
884 pr_err("%s: %s: general error sending stop command, stop cmd response %#x\n",
885 req->rq_disk->disk_name, __func__,
886 stop_status);
887 *gen_err = 1;
888 }
889 } 963 }
890 964
891 /* Check for set block count errors */ 965 /* Check for set block count errors */
@@ -1157,8 +1231,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
1157 * program mode, which we have to wait for it to complete. 1231 * program mode, which we have to wait for it to complete.
1158 */ 1232 */
1159 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) { 1233 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
1160 u32 status; 1234 int err;
1161 unsigned long timeout;
1162 1235
1163 /* Check stop command response */ 1236 /* Check stop command response */
1164 if (brq->stop.resp[0] & R1_ERROR) { 1237 if (brq->stop.resp[0] & R1_ERROR) {
@@ -1168,39 +1241,10 @@ static int mmc_blk_err_check(struct mmc_card *card,
1168 gen_err = 1; 1241 gen_err = 1;
1169 } 1242 }
1170 1243
1171 timeout = jiffies + msecs_to_jiffies(MMC_BLK_TIMEOUT_MS); 1244 err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, false, req,
1172 do { 1245 &gen_err);
1173 int err = get_card_status(card, &status, 5); 1246 if (err)
1174 if (err) { 1247 return MMC_BLK_CMD_ERR;
1175 pr_err("%s: error %d requesting status\n",
1176 req->rq_disk->disk_name, err);
1177 return MMC_BLK_CMD_ERR;
1178 }
1179
1180 if (status & R1_ERROR) {
1181 pr_err("%s: %s: general error sending status command, card status %#x\n",
1182 req->rq_disk->disk_name, __func__,
1183 status);
1184 gen_err = 1;
1185 }
1186
1187 /* Timeout if the device never becomes ready for data
1188 * and never leaves the program state.
1189 */
1190 if (time_after(jiffies, timeout)) {
1191 pr_err("%s: Card stuck in programming state!"\
1192 " %s %s\n", mmc_hostname(card->host),
1193 req->rq_disk->disk_name, __func__);
1194
1195 return MMC_BLK_CMD_ERR;
1196 }
1197 /*
1198 * Some cards mishandle the status bits,
1199 * so make sure to check both the busy
1200 * indication and the card state.
1201 */
1202 } while (!(status & R1_READY_FOR_DATA) ||
1203 (R1_CURRENT_STATE(status) == R1_STATE_PRG));
1204 } 1248 }
1205 1249
1206 /* if general error occurs, retry the write operation. */ 1250 /* if general error occurs, retry the write operation. */
@@ -1335,7 +1379,6 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1335 brq->data.blksz = 512; 1379 brq->data.blksz = 512;
1336 brq->stop.opcode = MMC_STOP_TRANSMISSION; 1380 brq->stop.opcode = MMC_STOP_TRANSMISSION;
1337 brq->stop.arg = 0; 1381 brq->stop.arg = 0;
1338 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
1339 brq->data.blocks = blk_rq_sectors(req); 1382 brq->data.blocks = blk_rq_sectors(req);
1340 1383
1341 /* 1384 /*
@@ -1378,9 +1421,15 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1378 if (rq_data_dir(req) == READ) { 1421 if (rq_data_dir(req) == READ) {
1379 brq->cmd.opcode = readcmd; 1422 brq->cmd.opcode = readcmd;
1380 brq->data.flags |= MMC_DATA_READ; 1423 brq->data.flags |= MMC_DATA_READ;
1424 if (brq->mrq.stop)
1425 brq->stop.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 |
1426 MMC_CMD_AC;
1381 } else { 1427 } else {
1382 brq->cmd.opcode = writecmd; 1428 brq->cmd.opcode = writecmd;
1383 brq->data.flags |= MMC_DATA_WRITE; 1429 brq->data.flags |= MMC_DATA_WRITE;
1430 if (brq->mrq.stop)
1431 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B |
1432 MMC_CMD_AC;
1384 } 1433 }
1385 1434
1386 if (do_rel_wr) 1435 if (do_rel_wr)