aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-10-09 21:58:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-09 21:58:42 -0400
commit943c2acea53784c45fb291498d04d5188fdea891 (patch)
tree063fac3e584f8f4a5babbc329499f84b3da291d7 /drivers/mmc/core
parent10f39f04b2cb7a06ba5d4ea0f20bd156d0367bee (diff)
parente6c085863f97f0a8f009753e1baaf83e4aac7b42 (diff)
Merge tag 'mmc-merge-for-3.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
Pull MMC updates from Chris Ball: "Core: - Add DT properties for card detection (broken-cd, cd-gpios, non-removable) - Don't poll non-removable devices - Fixup/rework eMMC sleep mode/"power off notify" feature - Support eMMC background operations (BKOPS). To set the one-time programmable fuse that enables bkops on an eMMC that doesn't already have it set, you can use the "mmc bkops enable" command in: git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc-utils.git Drivers: - atmel-mci, dw_mmc, pxa-mci, dove, s3c, spear: Add device tree support - bfin_sdh: Add support for the controller in bf60x - dw_mmc: Support Samsung Exynos SoCs - eSDHC: Add ADMA support - sdhci: Support testing a cd-gpio (from slot-gpio) instead of presence bit - sdhci-pltfm: Support broken-cd DT property - tegra: Convert to only supporting DT (mach-tegra has gone DT-only)" * tag 'mmc-merge-for-3.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (67 commits) mmc: core: Fixup broken suspend and eMMC4.5 power off notify mmc: sdhci-spear: Add clk_{un}prepare() support mmc: sdhci-spear: add device tree bindings mmc: sdhci-s3c: Add clk_(enable/disable) in runtime suspend/resume mmc: core: Replace MMC_CAP2_BROKEN_VOLTAGE with test for fixed regulator mmc: sdhci-pxav3: Use sdhci_get_of_property for parsing DT quirks mmc: dt: Support "broken-cd" property in sdhci-pltfm mmc: sdhci-s3c: fix the wrong number of max bus clocks mmc: sh-mmcif: avoid oops on spurious interrupts mmc: sh-mmcif: properly handle MMC_WRITE_MULTIPLE_BLOCK completion IRQ mmc: sdhci-s3c: Fix crash on module insertion for second time mmc: sdhci-s3c: Enable only required bus clock mmc: Revert "mmc: dw_mmc: Add check for IDMAC configuration" mmc: mxcmmc: fix bug that may block a data transfer forever mmc: omap_hsmmc: Pass on the suspend failure to the PM core mmc: atmel-mci: AP700x PDC is not connected to MCI mmc: atmel-mci: DMA can be used with other controllers mmc: mmci: use clk_prepare_enable and clk_disable_unprepare mmc: sdhci-s3c: Add device tree support mmc: dw_mmc: add support for exynos specific implementation of dw-mshc ...
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r--drivers/mmc/core/core.c240
-rw-r--r--drivers/mmc/core/debugfs.c2
-rw-r--r--drivers/mmc/core/mmc.c57
-rw-r--r--drivers/mmc/core/mmc_ops.c84
-rw-r--r--drivers/mmc/core/sdio_bus.c7
-rw-r--r--drivers/mmc/core/slot-gpio.c8
6 files changed, 287 insertions, 111 deletions
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 8ac5246e2ab2..06c42cfb7c34 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -26,6 +26,7 @@
26#include <linux/suspend.h> 26#include <linux/suspend.h>
27#include <linux/fault-inject.h> 27#include <linux/fault-inject.h>
28#include <linux/random.h> 28#include <linux/random.h>
29#include <linux/slab.h>
29 30
30#include <linux/mmc/card.h> 31#include <linux/mmc/card.h>
31#include <linux/mmc/host.h> 32#include <linux/mmc/host.h>
@@ -41,6 +42,12 @@
41#include "sd_ops.h" 42#include "sd_ops.h"
42#include "sdio_ops.h" 43#include "sdio_ops.h"
43 44
45/*
46 * Background operations can take a long time, depending on the housekeeping
47 * operations the card has to perform.
48 */
49#define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */
50
44static struct workqueue_struct *workqueue; 51static struct workqueue_struct *workqueue;
45static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; 52static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
46 53
@@ -245,6 +252,70 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
245 host->ops->request(host, mrq); 252 host->ops->request(host, mrq);
246} 253}
247 254
255/**
256 * mmc_start_bkops - start BKOPS for supported cards
257 * @card: MMC card to start BKOPS
258 * @form_exception: A flag to indicate if this function was
259 * called due to an exception raised by the card
260 *
261 * Start background operations whenever requested.
262 * When the urgent BKOPS bit is set in a R1 command response
263 * then background operations should be started immediately.
264*/
265void mmc_start_bkops(struct mmc_card *card, bool from_exception)
266{
267 int err;
268 int timeout;
269 bool use_busy_signal;
270
271 BUG_ON(!card);
272
273 if (!card->ext_csd.bkops_en || mmc_card_doing_bkops(card))
274 return;
275
276 err = mmc_read_bkops_status(card);
277 if (err) {
278 pr_err("%s: Failed to read bkops status: %d\n",
279 mmc_hostname(card->host), err);
280 return;
281 }
282
283 if (!card->ext_csd.raw_bkops_status)
284 return;
285
286 if (card->ext_csd.raw_bkops_status < EXT_CSD_BKOPS_LEVEL_2 &&
287 from_exception)
288 return;
289
290 mmc_claim_host(card->host);
291 if (card->ext_csd.raw_bkops_status >= EXT_CSD_BKOPS_LEVEL_2) {
292 timeout = MMC_BKOPS_MAX_TIMEOUT;
293 use_busy_signal = true;
294 } else {
295 timeout = 0;
296 use_busy_signal = false;
297 }
298
299 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
300 EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal);
301 if (err) {
302 pr_warn("%s: Error %d starting bkops\n",
303 mmc_hostname(card->host), err);
304 goto out;
305 }
306
307 /*
308 * For urgent bkops status (LEVEL_2 and more)
309 * bkops executed synchronously, otherwise
310 * the operation is in progress
311 */
312 if (!use_busy_signal)
313 mmc_card_set_doing_bkops(card);
314out:
315 mmc_release_host(card->host);
316}
317EXPORT_SYMBOL(mmc_start_bkops);
318
248static void mmc_wait_done(struct mmc_request *mrq) 319static void mmc_wait_done(struct mmc_request *mrq)
249{ 320{
250 complete(&mrq->completion); 321 complete(&mrq->completion);
@@ -354,6 +425,14 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
354 if (host->areq) { 425 if (host->areq) {
355 mmc_wait_for_req_done(host, host->areq->mrq); 426 mmc_wait_for_req_done(host, host->areq->mrq);
356 err = host->areq->err_check(host->card, host->areq); 427 err = host->areq->err_check(host->card, host->areq);
428 /*
429 * Check BKOPS urgency for each R1 response
430 */
431 if (host->card && mmc_card_mmc(host->card) &&
432 ((mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1) ||
433 (mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1B)) &&
434 (host->areq->mrq->cmd->resp[0] & R1_EXCEPTION_EVENT))
435 mmc_start_bkops(host->card, true);
357 } 436 }
358 437
359 if (!err && areq) 438 if (!err && areq)
@@ -398,7 +477,7 @@ EXPORT_SYMBOL(mmc_wait_for_req);
398 * @card: the MMC card associated with the HPI transfer 477 * @card: the MMC card associated with the HPI transfer
399 * 478 *
400 * Issued High Priority Interrupt, and check for card status 479 * Issued High Priority Interrupt, and check for card status
401 * util out-of prg-state. 480 * until out-of prg-state.
402 */ 481 */
403int mmc_interrupt_hpi(struct mmc_card *card) 482int mmc_interrupt_hpi(struct mmc_card *card)
404{ 483{
@@ -424,8 +503,9 @@ int mmc_interrupt_hpi(struct mmc_card *card)
424 case R1_STATE_IDLE: 503 case R1_STATE_IDLE:
425 case R1_STATE_READY: 504 case R1_STATE_READY:
426 case R1_STATE_STBY: 505 case R1_STATE_STBY:
506 case R1_STATE_TRAN:
427 /* 507 /*
428 * In idle states, HPI is not needed and the caller 508 * In idle and transfer states, HPI is not needed and the caller
429 * can issue the next intended command immediately 509 * can issue the next intended command immediately
430 */ 510 */
431 goto out; 511 goto out;
@@ -489,6 +569,64 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries
489EXPORT_SYMBOL(mmc_wait_for_cmd); 569EXPORT_SYMBOL(mmc_wait_for_cmd);
490 570
491/** 571/**
572 * mmc_stop_bkops - stop ongoing BKOPS
573 * @card: MMC card to check BKOPS
574 *
575 * Send HPI command to stop ongoing background operations to
576 * allow rapid servicing of foreground operations, e.g. read/
577 * writes. Wait until the card comes out of the programming state
578 * to avoid errors in servicing read/write requests.
579 */
580int mmc_stop_bkops(struct mmc_card *card)
581{
582 int err = 0;
583
584 BUG_ON(!card);
585 err = mmc_interrupt_hpi(card);
586
587 /*
588 * If err is EINVAL, we can't issue an HPI.
589 * It should complete the BKOPS.
590 */
591 if (!err || (err == -EINVAL)) {
592 mmc_card_clr_doing_bkops(card);
593 err = 0;
594 }
595
596 return err;
597}
598EXPORT_SYMBOL(mmc_stop_bkops);
599
600int mmc_read_bkops_status(struct mmc_card *card)
601{
602 int err;
603 u8 *ext_csd;
604
605 /*
606 * In future work, we should consider storing the entire ext_csd.
607 */
608 ext_csd = kmalloc(512, GFP_KERNEL);
609 if (!ext_csd) {
610 pr_err("%s: could not allocate buffer to receive the ext_csd.\n",
611 mmc_hostname(card->host));
612 return -ENOMEM;
613 }
614
615 mmc_claim_host(card->host);
616 err = mmc_send_ext_csd(card, ext_csd);
617 mmc_release_host(card->host);
618 if (err)
619 goto out;
620
621 card->ext_csd.raw_bkops_status = ext_csd[EXT_CSD_BKOPS_STATUS];
622 card->ext_csd.raw_exception_status = ext_csd[EXT_CSD_EXP_EVENTS_STATUS];
623out:
624 kfree(ext_csd);
625 return err;
626}
627EXPORT_SYMBOL(mmc_read_bkops_status);
628
629/**
492 * mmc_set_data_timeout - set the timeout for a data command 630 * mmc_set_data_timeout - set the timeout for a data command
493 * @data: data phase for command 631 * @data: data phase for command
494 * @card: the MMC card associated with the data transfer 632 * @card: the MMC card associated with the data transfer
@@ -975,7 +1113,8 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc,
975 int tmp; 1113 int tmp;
976 int voltage; 1114 int voltage;
977 1115
978 /* REVISIT mmc_vddrange_to_ocrmask() may have set some 1116 /*
1117 * REVISIT mmc_vddrange_to_ocrmask() may have set some
979 * bits this regulator doesn't quite support ... don't 1118 * bits this regulator doesn't quite support ... don't
980 * be too picky, most cards and regulators are OK with 1119 * be too picky, most cards and regulators are OK with
981 * a 0.1V range goof (it's a small error percentage). 1120 * a 0.1V range goof (it's a small error percentage).
@@ -989,12 +1128,13 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc,
989 max_uV = min_uV + 100 * 1000; 1128 max_uV = min_uV + 100 * 1000;
990 } 1129 }
991 1130
992 /* avoid needless changes to this voltage; the regulator 1131 /*
993 * might not allow this operation 1132 * If we're using a fixed/static regulator, don't call
1133 * regulator_set_voltage; it would fail.
994 */ 1134 */
995 voltage = regulator_get_voltage(supply); 1135 voltage = regulator_get_voltage(supply);
996 1136
997 if (mmc->caps2 & MMC_CAP2_BROKEN_VOLTAGE) 1137 if (regulator_count_voltages(supply) == 1)
998 min_uV = max_uV = voltage; 1138 min_uV = max_uV = voltage;
999 1139
1000 if (voltage < 0) 1140 if (voltage < 0)
@@ -1133,48 +1273,6 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type)
1133 mmc_host_clk_release(host); 1273 mmc_host_clk_release(host);
1134} 1274}
1135 1275
1136static void mmc_poweroff_notify(struct mmc_host *host)
1137{
1138 struct mmc_card *card;
1139 unsigned int timeout;
1140 unsigned int notify_type = EXT_CSD_NO_POWER_NOTIFICATION;
1141 int err = 0;
1142
1143 card = host->card;
1144 mmc_claim_host(host);
1145
1146 /*
1147 * Send power notify command only if card
1148 * is mmc and notify state is powered ON
1149 */
1150 if (card && mmc_card_mmc(card) &&
1151 (card->poweroff_notify_state == MMC_POWERED_ON)) {
1152
1153 if (host->power_notify_type == MMC_HOST_PW_NOTIFY_SHORT) {
1154 notify_type = EXT_CSD_POWER_OFF_SHORT;
1155 timeout = card->ext_csd.generic_cmd6_time;
1156 card->poweroff_notify_state = MMC_POWEROFF_SHORT;
1157 } else {
1158 notify_type = EXT_CSD_POWER_OFF_LONG;
1159 timeout = card->ext_csd.power_off_longtime;
1160 card->poweroff_notify_state = MMC_POWEROFF_LONG;
1161 }
1162
1163 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1164 EXT_CSD_POWER_OFF_NOTIFICATION,
1165 notify_type, timeout);
1166
1167 if (err && err != -EBADMSG)
1168 pr_err("Device failed to respond within %d poweroff "
1169 "time. Forcefully powering down the device\n",
1170 timeout);
1171
1172 /* Set the card state to no notification after the poweroff */
1173 card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION;
1174 }
1175 mmc_release_host(host);
1176}
1177
1178/* 1276/*
1179 * Apply power to the MMC stack. This is a two-stage process. 1277 * Apply power to the MMC stack. This is a two-stage process.
1180 * First, we enable power to the card without the clock running. 1278 * First, we enable power to the card without the clock running.
@@ -1237,8 +1335,6 @@ static void mmc_power_up(struct mmc_host *host)
1237 1335
1238void mmc_power_off(struct mmc_host *host) 1336void mmc_power_off(struct mmc_host *host)
1239{ 1337{
1240 int err = 0;
1241
1242 if (host->ios.power_mode == MMC_POWER_OFF) 1338 if (host->ios.power_mode == MMC_POWER_OFF)
1243 return; 1339 return;
1244 1340
@@ -1247,22 +1343,6 @@ void mmc_power_off(struct mmc_host *host)
1247 host->ios.clock = 0; 1343 host->ios.clock = 0;
1248 host->ios.vdd = 0; 1344 host->ios.vdd = 0;
1249 1345
1250 /*
1251 * For eMMC 4.5 device send AWAKE command before
1252 * POWER_OFF_NOTIFY command, because in sleep state
1253 * eMMC 4.5 devices respond to only RESET and AWAKE cmd
1254 */
1255 if (host->card && mmc_card_is_sleep(host->card) &&
1256 host->bus_ops->resume) {
1257 err = host->bus_ops->resume(host);
1258
1259 if (!err)
1260 mmc_poweroff_notify(host);
1261 else
1262 pr_warning("%s: error %d during resume "
1263 "(continue with poweroff sequence)\n",
1264 mmc_hostname(host), err);
1265 }
1266 1346
1267 /* 1347 /*
1268 * Reset ocr mask to be the highest possible voltage supported for 1348 * Reset ocr mask to be the highest possible voltage supported for
@@ -2052,6 +2132,11 @@ void mmc_rescan(struct work_struct *work)
2052 if (host->rescan_disable) 2132 if (host->rescan_disable)
2053 return; 2133 return;
2054 2134
2135 /* If there is a non-removable card registered, only scan once */
2136 if ((host->caps & MMC_CAP_NONREMOVABLE) && host->rescan_entered)
2137 return;
2138 host->rescan_entered = 1;
2139
2055 mmc_bus_get(host); 2140 mmc_bus_get(host);
2056 2141
2057 /* 2142 /*
@@ -2327,9 +2412,14 @@ int mmc_suspend_host(struct mmc_host *host)
2327 2412
2328 mmc_bus_get(host); 2413 mmc_bus_get(host);
2329 if (host->bus_ops && !host->bus_dead) { 2414 if (host->bus_ops && !host->bus_dead) {
2330 2415 if (host->bus_ops->suspend) {
2331 if (host->bus_ops->suspend) 2416 if (mmc_card_doing_bkops(host->card)) {
2417 err = mmc_stop_bkops(host->card);
2418 if (err)
2419 goto out;
2420 }
2332 err = host->bus_ops->suspend(host); 2421 err = host->bus_ops->suspend(host);
2422 }
2333 2423
2334 if (err == -ENOSYS || !host->bus_ops->resume) { 2424 if (err == -ENOSYS || !host->bus_ops->resume) {
2335 /* 2425 /*
@@ -2411,15 +2501,24 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2411 struct mmc_host *host = container_of( 2501 struct mmc_host *host = container_of(
2412 notify_block, struct mmc_host, pm_notify); 2502 notify_block, struct mmc_host, pm_notify);
2413 unsigned long flags; 2503 unsigned long flags;
2414 2504 int err = 0;
2415 2505
2416 switch (mode) { 2506 switch (mode) {
2417 case PM_HIBERNATION_PREPARE: 2507 case PM_HIBERNATION_PREPARE:
2418 case PM_SUSPEND_PREPARE: 2508 case PM_SUSPEND_PREPARE:
2509 if (host->card && mmc_card_mmc(host->card) &&
2510 mmc_card_doing_bkops(host->card)) {
2511 err = mmc_stop_bkops(host->card);
2512 if (err) {
2513 pr_err("%s: didn't stop bkops\n",
2514 mmc_hostname(host));
2515 return err;
2516 }
2517 mmc_card_clr_doing_bkops(host->card);
2518 }
2419 2519
2420 spin_lock_irqsave(&host->lock, flags); 2520 spin_lock_irqsave(&host->lock, flags);
2421 host->rescan_disable = 1; 2521 host->rescan_disable = 1;
2422 host->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT;
2423 spin_unlock_irqrestore(&host->lock, flags); 2522 spin_unlock_irqrestore(&host->lock, flags);
2424 cancel_delayed_work_sync(&host->detect); 2523 cancel_delayed_work_sync(&host->detect);
2425 2524
@@ -2443,7 +2542,6 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2443 2542
2444 spin_lock_irqsave(&host->lock, flags); 2543 spin_lock_irqsave(&host->lock, flags);
2445 host->rescan_disable = 0; 2544 host->rescan_disable = 0;
2446 host->power_notify_type = MMC_HOST_PW_NOTIFY_LONG;
2447 spin_unlock_irqrestore(&host->lock, flags); 2545 spin_unlock_irqrestore(&host->lock, flags);
2448 mmc_detect_change(host, 0); 2546 mmc_detect_change(host, 0);
2449 2547
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 9ab5b17d488a..d96c643dde1c 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -281,7 +281,7 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
281 if (err) 281 if (err)
282 goto out_free; 282 goto out_free;
283 283
284 for (i = 511; i >= 0; i--) 284 for (i = 0; i < 512; i++)
285 n += sprintf(buf + n, "%02x", ext_csd[i]); 285 n += sprintf(buf + n, "%02x", ext_csd[i]);
286 n += sprintf(buf + n, "\n"); 286 n += sprintf(buf + n, "\n");
287 BUG_ON(n != EXT_CSD_STR_LEN); 287 BUG_ON(n != EXT_CSD_STR_LEN);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 396b25891bb9..7cc46382fd64 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -463,6 +463,17 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
463 } 463 }
464 464
465 if (card->ext_csd.rev >= 5) { 465 if (card->ext_csd.rev >= 5) {
466 /* check whether the eMMC card supports BKOPS */
467 if (ext_csd[EXT_CSD_BKOPS_SUPPORT] & 0x1) {
468 card->ext_csd.bkops = 1;
469 card->ext_csd.bkops_en = ext_csd[EXT_CSD_BKOPS_EN];
470 card->ext_csd.raw_bkops_status =
471 ext_csd[EXT_CSD_BKOPS_STATUS];
472 if (!card->ext_csd.bkops_en)
473 pr_info("%s: BKOPS_EN bit is not set\n",
474 mmc_hostname(card->host));
475 }
476
466 /* check whether the eMMC card supports HPI */ 477 /* check whether the eMMC card supports HPI */
467 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { 478 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) {
468 card->ext_csd.hpi = 1; 479 card->ext_csd.hpi = 1;
@@ -996,7 +1007,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
996 * so check for success and update the flag 1007 * so check for success and update the flag
997 */ 1008 */
998 if (!err) 1009 if (!err)
999 card->poweroff_notify_state = MMC_POWERED_ON; 1010 card->ext_csd.power_off_notification = EXT_CSD_POWER_ON;
1000 } 1011 }
1001 1012
1002 /* 1013 /*
@@ -1262,6 +1273,35 @@ err:
1262 return err; 1273 return err;
1263} 1274}
1264 1275
1276static int mmc_can_poweroff_notify(const struct mmc_card *card)
1277{
1278 return card &&
1279 mmc_card_mmc(card) &&
1280 (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON);
1281}
1282
1283static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
1284{
1285 unsigned int timeout = card->ext_csd.generic_cmd6_time;
1286 int err;
1287
1288 /* Use EXT_CSD_POWER_OFF_SHORT as default notification type. */
1289 if (notify_type == EXT_CSD_POWER_OFF_LONG)
1290 timeout = card->ext_csd.power_off_longtime;
1291
1292 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1293 EXT_CSD_POWER_OFF_NOTIFICATION,
1294 notify_type, timeout);
1295 if (err)
1296 pr_err("%s: Power Off Notification timed out, %u\n",
1297 mmc_hostname(card->host), timeout);
1298
1299 /* Disable the power off notification after the switch operation. */
1300 card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION;
1301
1302 return err;
1303}
1304
1265/* 1305/*
1266 * Host is being removed. Free up the current card. 1306 * Host is being removed. Free up the current card.
1267 */ 1307 */
@@ -1322,11 +1362,11 @@ static int mmc_suspend(struct mmc_host *host)
1322 BUG_ON(!host->card); 1362 BUG_ON(!host->card);
1323 1363
1324 mmc_claim_host(host); 1364 mmc_claim_host(host);
1325 if (mmc_card_can_sleep(host)) { 1365 if (mmc_can_poweroff_notify(host->card))
1366 err = mmc_poweroff_notify(host->card, EXT_CSD_POWER_OFF_SHORT);
1367 else if (mmc_card_can_sleep(host))
1326 err = mmc_card_sleep(host); 1368 err = mmc_card_sleep(host);
1327 if (!err) 1369 else if (!mmc_host_is_spi(host))
1328 mmc_card_set_sleep(host->card);
1329 } else if (!mmc_host_is_spi(host))
1330 err = mmc_deselect_cards(host); 1370 err = mmc_deselect_cards(host);
1331 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1371 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
1332 mmc_release_host(host); 1372 mmc_release_host(host);
@@ -1348,11 +1388,7 @@ static int mmc_resume(struct mmc_host *host)
1348 BUG_ON(!host->card); 1388 BUG_ON(!host->card);
1349 1389
1350 mmc_claim_host(host); 1390 mmc_claim_host(host);
1351 if (mmc_card_is_sleep(host->card)) { 1391 err = mmc_init_card(host, host->ocr, host->card);
1352 err = mmc_card_awake(host);
1353 mmc_card_clr_sleep(host->card);
1354 } else
1355 err = mmc_init_card(host, host->ocr, host->card);
1356 mmc_release_host(host); 1392 mmc_release_host(host);
1357 1393
1358 return err; 1394 return err;
@@ -1363,7 +1399,6 @@ static int mmc_power_restore(struct mmc_host *host)
1363 int ret; 1399 int ret;
1364 1400
1365 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1401 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
1366 mmc_card_clr_sleep(host->card);
1367 mmc_claim_host(host); 1402 mmc_claim_host(host);
1368 ret = mmc_init_card(host, host->ocr, host->card); 1403 ret = mmc_init_card(host, host->ocr, host->card);
1369 mmc_release_host(host); 1404 mmc_release_host(host);
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 0ed2cc5f35b6..a0e172042e65 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -230,6 +230,10 @@ mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode)
230 return 0; 230 return 0;
231} 231}
232 232
233/*
234 * NOTE: void *buf, caller for the buf is required to use DMA-capable
235 * buffer or on-stack buffer (with some overhead in callee).
236 */
233static int 237static int
234mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host, 238mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
235 u32 opcode, void *buf, unsigned len) 239 u32 opcode, void *buf, unsigned len)
@@ -239,13 +243,19 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
239 struct mmc_data data = {0}; 243 struct mmc_data data = {0};
240 struct scatterlist sg; 244 struct scatterlist sg;
241 void *data_buf; 245 void *data_buf;
246 int is_on_stack;
242 247
243 /* dma onto stack is unsafe/nonportable, but callers to this 248 is_on_stack = object_is_on_stack(buf);
244 * routine normally provide temporary on-stack buffers ... 249 if (is_on_stack) {
245 */ 250 /*
246 data_buf = kmalloc(len, GFP_KERNEL); 251 * dma onto stack is unsafe/nonportable, but callers to this
247 if (data_buf == NULL) 252 * routine normally provide temporary on-stack buffers ...
248 return -ENOMEM; 253 */
254 data_buf = kmalloc(len, GFP_KERNEL);
255 if (!data_buf)
256 return -ENOMEM;
257 } else
258 data_buf = buf;
249 259
250 mrq.cmd = &cmd; 260 mrq.cmd = &cmd;
251 mrq.data = &data; 261 mrq.data = &data;
@@ -280,8 +290,10 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
280 290
281 mmc_wait_for_req(host, &mrq); 291 mmc_wait_for_req(host, &mrq);
282 292
283 memcpy(buf, data_buf, len); 293 if (is_on_stack) {
284 kfree(data_buf); 294 memcpy(buf, data_buf, len);
295 kfree(data_buf);
296 }
285 297
286 if (cmd.error) 298 if (cmd.error)
287 return cmd.error; 299 return cmd.error;
@@ -294,24 +306,32 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
294int mmc_send_csd(struct mmc_card *card, u32 *csd) 306int mmc_send_csd(struct mmc_card *card, u32 *csd)
295{ 307{
296 int ret, i; 308 int ret, i;
309 u32 *csd_tmp;
297 310
298 if (!mmc_host_is_spi(card->host)) 311 if (!mmc_host_is_spi(card->host))
299 return mmc_send_cxd_native(card->host, card->rca << 16, 312 return mmc_send_cxd_native(card->host, card->rca << 16,
300 csd, MMC_SEND_CSD); 313 csd, MMC_SEND_CSD);
301 314
302 ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16); 315 csd_tmp = kmalloc(16, GFP_KERNEL);
316 if (!csd_tmp)
317 return -ENOMEM;
318
319 ret = mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd_tmp, 16);
303 if (ret) 320 if (ret)
304 return ret; 321 goto err;
305 322
306 for (i = 0;i < 4;i++) 323 for (i = 0;i < 4;i++)
307 csd[i] = be32_to_cpu(csd[i]); 324 csd[i] = be32_to_cpu(csd_tmp[i]);
308 325
309 return 0; 326err:
327 kfree(csd_tmp);
328 return ret;
310} 329}
311 330
312int mmc_send_cid(struct mmc_host *host, u32 *cid) 331int mmc_send_cid(struct mmc_host *host, u32 *cid)
313{ 332{
314 int ret, i; 333 int ret, i;
334 u32 *cid_tmp;
315 335
316 if (!mmc_host_is_spi(host)) { 336 if (!mmc_host_is_spi(host)) {
317 if (!host->card) 337 if (!host->card)
@@ -320,14 +340,20 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
320 cid, MMC_SEND_CID); 340 cid, MMC_SEND_CID);
321 } 341 }
322 342
323 ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16); 343 cid_tmp = kmalloc(16, GFP_KERNEL);
344 if (!cid_tmp)
345 return -ENOMEM;
346
347 ret = mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid_tmp, 16);
324 if (ret) 348 if (ret)
325 return ret; 349 goto err;
326 350
327 for (i = 0;i < 4;i++) 351 for (i = 0;i < 4;i++)
328 cid[i] = be32_to_cpu(cid[i]); 352 cid[i] = be32_to_cpu(cid_tmp[i]);
329 353
330 return 0; 354err:
355 kfree(cid_tmp);
356 return ret;
331} 357}
332 358
333int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd) 359int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
@@ -367,18 +393,19 @@ int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
367} 393}
368 394
369/** 395/**
370 * mmc_switch - modify EXT_CSD register 396 * __mmc_switch - modify EXT_CSD register
371 * @card: the MMC card associated with the data transfer 397 * @card: the MMC card associated with the data transfer
372 * @set: cmd set values 398 * @set: cmd set values
373 * @index: EXT_CSD register index 399 * @index: EXT_CSD register index
374 * @value: value to program into EXT_CSD register 400 * @value: value to program into EXT_CSD register
375 * @timeout_ms: timeout (ms) for operation performed by register write, 401 * @timeout_ms: timeout (ms) for operation performed by register write,
376 * timeout of zero implies maximum possible timeout 402 * timeout of zero implies maximum possible timeout
403 * @use_busy_signal: use the busy signal as response type
377 * 404 *
378 * Modifies the EXT_CSD register for selected card. 405 * Modifies the EXT_CSD register for selected card.
379 */ 406 */
380int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 407int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
381 unsigned int timeout_ms) 408 unsigned int timeout_ms, bool use_busy_signal)
382{ 409{
383 int err; 410 int err;
384 struct mmc_command cmd = {0}; 411 struct mmc_command cmd = {0};
@@ -392,13 +419,23 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
392 (index << 16) | 419 (index << 16) |
393 (value << 8) | 420 (value << 8) |
394 set; 421 set;
395 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; 422 cmd.flags = MMC_CMD_AC;
423 if (use_busy_signal)
424 cmd.flags |= MMC_RSP_SPI_R1B | MMC_RSP_R1B;
425 else
426 cmd.flags |= MMC_RSP_SPI_R1 | MMC_RSP_R1;
427
428
396 cmd.cmd_timeout_ms = timeout_ms; 429 cmd.cmd_timeout_ms = timeout_ms;
397 430
398 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 431 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
399 if (err) 432 if (err)
400 return err; 433 return err;
401 434
435 /* No need to check card status in case of unblocking command */
436 if (!use_busy_signal)
437 return 0;
438
402 /* Must check status to be sure of no errors */ 439 /* Must check status to be sure of no errors */
403 do { 440 do {
404 err = mmc_send_status(card, &status); 441 err = mmc_send_status(card, &status);
@@ -423,6 +460,13 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
423 460
424 return 0; 461 return 0;
425} 462}
463EXPORT_SYMBOL_GPL(__mmc_switch);
464
465int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
466 unsigned int timeout_ms)
467{
468 return __mmc_switch(card, set, index, value, timeout_ms, true);
469}
426EXPORT_SYMBOL_GPL(mmc_switch); 470EXPORT_SYMBOL_GPL(mmc_switch);
427 471
428int mmc_send_status(struct mmc_card *card, u32 *status) 472int mmc_send_status(struct mmc_card *card, u32 *status)
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 236842ec955a..6bf68799fe97 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -193,14 +193,7 @@ static int sdio_bus_remove(struct device *dev)
193} 193}
194 194
195#ifdef CONFIG_PM 195#ifdef CONFIG_PM
196
197static int pm_no_operation(struct device *dev)
198{
199 return 0;
200}
201
202static const struct dev_pm_ops sdio_bus_pm_ops = { 196static const struct dev_pm_ops sdio_bus_pm_ops = {
203 SET_SYSTEM_SLEEP_PM_OPS(pm_no_operation, pm_no_operation)
204 SET_RUNTIME_PM_OPS( 197 SET_RUNTIME_PM_OPS(
205 pm_generic_runtime_suspend, 198 pm_generic_runtime_suspend,
206 pm_generic_runtime_resume, 199 pm_generic_runtime_resume,
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 058242916cef..08c6b3dfe080 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -100,7 +100,13 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
100 100
101 ctx = host->slot.handler_priv; 101 ctx = host->slot.handler_priv;
102 102
103 return gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label); 103 ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label);
104 if (ret < 0)
105 return ret;
106
107 ctx->ro_gpio = gpio;
108
109 return 0;
104} 110}
105EXPORT_SYMBOL(mmc_gpio_request_ro); 111EXPORT_SYMBOL(mmc_gpio_request_ro);
106 112