aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-26 12:31:09 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-26 12:31:09 -0500
commited5dc2372dba46e0ecd08791b1a0399d313e5cff (patch)
tree571319985b59a2963fb7580c24ee2aa1696359e2 /drivers/mmc/core
parent0512c04a2b5d29a33d96d315e1d14c55f5148aa7 (diff)
parent0e786102949d7461859c6ce9f39c2c8d28e42db3 (diff)
Merge tag 'mmc-updates-for-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
Pull MMC update from Chris Ball: "MMC highlights for 3.9: Core: - Support for packed commands in eMMC 4.5. (This requires a host capability to be turned on. It increases write throughput by 20%+, but may also increase average write latency; more testing needed.) - Add DT bindings for capability flags. - Add mmc_of_parse() for shared DT parsing between drivers. Drivers: - android-goldfish: New MMC driver for the Android Goldfish emulator. - mvsdio: Add DT bindings, pinctrl, use slot-gpio for card detection. - omap_hsmmc: Fix boot hangs with RPMB partitions. - sdhci-bcm2835: New driver for controller used by Raspberry Pi. - sdhci-esdhc-imx: Add 8-bit data, auto CMD23 support, use slot-gpio. - sh_mmcif: Add support for eMMC DDR, bundled MMCIF IRQs. - tmio_mmc: Add DT bindings, support for vccq regulator" * tag 'mmc-updates-for-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (92 commits) mmc: tegra: assume CONFIG_OF, remove platform data mmc: add DT bindings for more MMC capability flags mmc: tmio: add support for the VccQ regulator mmc: tmio: remove unused and deprecated symbols mmc: sh_mobile_sdhi: use managed resource allocations mmc: sh_mobile_sdhi: remove unused .pdata field mmc: tmio-mmc: parse device-tree bindings mmc: tmio-mmc: define device-tree bindings mmc: sh_mmcif: use mmc_of_parse() to parse standard MMC DT bindings mmc: (cosmetic) remove "extern" from function declarations mmc: provide a standard MMC device-tree binding parser centrally mmc: detailed definition of CD and WP MMC line polarities in DT mmc: sdhi, tmio: only check flags in tmio-mmc driver proper mmc: sdhci: Fix parameter of sdhci_do_start_signal_voltage_switch() mmc: sdhci: check voltage range only on regulators aware of voltage value mmc: bcm2835: set SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK mmc: support packed write command for eMMC4.5 devices mmc: add packed command feature of eMMC4.5 mmc: rtsx: remove driving adjustment mmc: use regulator_can_change_voltage() instead of regulator_count_voltages ...
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r--drivers/mmc/core/bus.c1
-rw-r--r--drivers/mmc/core/core.c246
-rw-r--r--drivers/mmc/core/core.h6
-rw-r--r--drivers/mmc/core/host.c123
-rw-r--r--drivers/mmc/core/mmc.c46
-rw-r--r--drivers/mmc/core/mmc_ops.c1
-rw-r--r--drivers/mmc/core/sd.c44
-rw-r--r--drivers/mmc/core/sdio.c54
-rw-r--r--drivers/mmc/core/slot-gpio.c57
9 files changed, 495 insertions, 83 deletions
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 420cb6753c1e..e219c97a02a4 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -321,6 +321,7 @@ int mmc_add_card(struct mmc_card *card)
321#ifdef CONFIG_DEBUG_FS 321#ifdef CONFIG_DEBUG_FS
322 mmc_add_card_debugfs(card); 322 mmc_add_card_debugfs(card);
323#endif 323#endif
324 mmc_init_context_info(card->host);
324 325
325 ret = device_add(&card->dev); 326 ret = device_add(&card->dev);
326 if (ret) 327 if (ret)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index aaed7687cf09..08a3cf2a7610 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -319,11 +319,45 @@ out:
319} 319}
320EXPORT_SYMBOL(mmc_start_bkops); 320EXPORT_SYMBOL(mmc_start_bkops);
321 321
322/*
323 * mmc_wait_data_done() - done callback for data request
324 * @mrq: done data request
325 *
326 * Wakes up mmc context, passed as a callback to host controller driver
327 */
328static void mmc_wait_data_done(struct mmc_request *mrq)
329{
330 mrq->host->context_info.is_done_rcv = true;
331 wake_up_interruptible(&mrq->host->context_info.wait);
332}
333
322static void mmc_wait_done(struct mmc_request *mrq) 334static void mmc_wait_done(struct mmc_request *mrq)
323{ 335{
324 complete(&mrq->completion); 336 complete(&mrq->completion);
325} 337}
326 338
339/*
340 *__mmc_start_data_req() - starts data request
341 * @host: MMC host to start the request
342 * @mrq: data request to start
343 *
344 * Sets the done callback to be called when request is completed by the card.
345 * Starts data mmc request execution
346 */
347static int __mmc_start_data_req(struct mmc_host *host, struct mmc_request *mrq)
348{
349 mrq->done = mmc_wait_data_done;
350 mrq->host = host;
351 if (mmc_card_removed(host->card)) {
352 mrq->cmd->error = -ENOMEDIUM;
353 mmc_wait_data_done(mrq);
354 return -ENOMEDIUM;
355 }
356 mmc_start_request(host, mrq);
357
358 return 0;
359}
360
327static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) 361static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq)
328{ 362{
329 init_completion(&mrq->completion); 363 init_completion(&mrq->completion);
@@ -337,6 +371,62 @@ static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq)
337 return 0; 371 return 0;
338} 372}
339 373
374/*
375 * mmc_wait_for_data_req_done() - wait for request completed
376 * @host: MMC host to prepare the command.
377 * @mrq: MMC request to wait for
378 *
379 * Blocks MMC context till host controller will ack end of data request
380 * execution or new request notification arrives from the block layer.
381 * Handles command retries.
382 *
383 * Returns enum mmc_blk_status after checking errors.
384 */
385static int mmc_wait_for_data_req_done(struct mmc_host *host,
386 struct mmc_request *mrq,
387 struct mmc_async_req *next_req)
388{
389 struct mmc_command *cmd;
390 struct mmc_context_info *context_info = &host->context_info;
391 int err;
392 unsigned long flags;
393
394 while (1) {
395 wait_event_interruptible(context_info->wait,
396 (context_info->is_done_rcv ||
397 context_info->is_new_req));
398 spin_lock_irqsave(&context_info->lock, flags);
399 context_info->is_waiting_last_req = false;
400 spin_unlock_irqrestore(&context_info->lock, flags);
401 if (context_info->is_done_rcv) {
402 context_info->is_done_rcv = false;
403 context_info->is_new_req = false;
404 cmd = mrq->cmd;
405 if (!cmd->error || !cmd->retries ||
406 mmc_card_removed(host->card)) {
407 err = host->areq->err_check(host->card,
408 host->areq);
409 break; /* return err */
410 } else {
411 pr_info("%s: req failed (CMD%u): %d, retrying...\n",
412 mmc_hostname(host),
413 cmd->opcode, cmd->error);
414 cmd->retries--;
415 cmd->error = 0;
416 host->ops->request(host, mrq);
417 continue; /* wait for done/new event again */
418 }
419 } else if (context_info->is_new_req) {
420 context_info->is_new_req = false;
421 if (!next_req) {
422 err = MMC_BLK_NEW_REQUEST;
423 break; /* return err */
424 }
425 }
426 }
427 return err;
428}
429
340static void mmc_wait_for_req_done(struct mmc_host *host, 430static void mmc_wait_for_req_done(struct mmc_host *host,
341 struct mmc_request *mrq) 431 struct mmc_request *mrq)
342{ 432{
@@ -426,8 +516,16 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
426 mmc_pre_req(host, areq->mrq, !host->areq); 516 mmc_pre_req(host, areq->mrq, !host->areq);
427 517
428 if (host->areq) { 518 if (host->areq) {
429 mmc_wait_for_req_done(host, host->areq->mrq); 519 err = mmc_wait_for_data_req_done(host, host->areq->mrq, areq);
430 err = host->areq->err_check(host->card, host->areq); 520 if (err == MMC_BLK_NEW_REQUEST) {
521 if (error)
522 *error = err;
523 /*
524 * The previous request was not completed,
525 * nothing to return
526 */
527 return NULL;
528 }
431 /* 529 /*
432 * Check BKOPS urgency for each R1 response 530 * Check BKOPS urgency for each R1 response
433 */ 531 */
@@ -439,14 +537,14 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
439 } 537 }
440 538
441 if (!err && areq) 539 if (!err && areq)
442 start_err = __mmc_start_req(host, areq->mrq); 540 start_err = __mmc_start_data_req(host, areq->mrq);
443 541
444 if (host->areq) 542 if (host->areq)
445 mmc_post_req(host, host->areq->mrq, 0); 543 mmc_post_req(host, host->areq->mrq, 0);
446 544
447 /* Cancel a prepared request if it was not started. */ 545 /* Cancel a prepared request if it was not started. */
448 if ((err || start_err) && areq) 546 if ((err || start_err) && areq)
449 mmc_post_req(host, areq->mrq, -EINVAL); 547 mmc_post_req(host, areq->mrq, -EINVAL);
450 548
451 if (err) 549 if (err)
452 host->areq = NULL; 550 host->areq = NULL;
@@ -1137,7 +1235,7 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc,
1137 */ 1235 */
1138 voltage = regulator_get_voltage(supply); 1236 voltage = regulator_get_voltage(supply);
1139 1237
1140 if (regulator_count_voltages(supply) == 1) 1238 if (!regulator_can_change_voltage(supply))
1141 min_uV = max_uV = voltage; 1239 min_uV = max_uV = voltage;
1142 1240
1143 if (voltage < 0) 1241 if (voltage < 0)
@@ -1219,10 +1317,30 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
1219 return ocr; 1317 return ocr;
1220} 1318}
1221 1319
1222int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, bool cmd11) 1320int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
1321{
1322 int err = 0;
1323 int old_signal_voltage = host->ios.signal_voltage;
1324
1325 host->ios.signal_voltage = signal_voltage;
1326 if (host->ops->start_signal_voltage_switch) {
1327 mmc_host_clk_hold(host);
1328 err = host->ops->start_signal_voltage_switch(host, &host->ios);
1329 mmc_host_clk_release(host);
1330 }
1331
1332 if (err)
1333 host->ios.signal_voltage = old_signal_voltage;
1334
1335 return err;
1336
1337}
1338
1339int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
1223{ 1340{
1224 struct mmc_command cmd = {0}; 1341 struct mmc_command cmd = {0};
1225 int err = 0; 1342 int err = 0;
1343 u32 clock;
1226 1344
1227 BUG_ON(!host); 1345 BUG_ON(!host);
1228 1346
@@ -1230,27 +1348,81 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, bool cmd11
1230 * Send CMD11 only if the request is to switch the card to 1348 * Send CMD11 only if the request is to switch the card to
1231 * 1.8V signalling. 1349 * 1.8V signalling.
1232 */ 1350 */
1233 if ((signal_voltage != MMC_SIGNAL_VOLTAGE_330) && cmd11) { 1351 if (signal_voltage == MMC_SIGNAL_VOLTAGE_330)
1234 cmd.opcode = SD_SWITCH_VOLTAGE; 1352 return __mmc_set_signal_voltage(host, signal_voltage);
1235 cmd.arg = 0;
1236 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
1237 1353
1238 err = mmc_wait_for_cmd(host, &cmd, 0); 1354 /*
1239 if (err) 1355 * If we cannot switch voltages, return failure so the caller
1240 return err; 1356 * can continue without UHS mode
1357 */
1358 if (!host->ops->start_signal_voltage_switch)
1359 return -EPERM;
1360 if (!host->ops->card_busy)
1361 pr_warning("%s: cannot verify signal voltage switch\n",
1362 mmc_hostname(host));
1363
1364 cmd.opcode = SD_SWITCH_VOLTAGE;
1365 cmd.arg = 0;
1366 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
1241 1367
1242 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) 1368 err = mmc_wait_for_cmd(host, &cmd, 0);
1243 return -EIO; 1369 if (err)
1370 return err;
1371
1372 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR))
1373 return -EIO;
1374
1375 mmc_host_clk_hold(host);
1376 /*
1377 * The card should drive cmd and dat[0:3] low immediately
1378 * after the response of cmd11, but wait 1 ms to be sure
1379 */
1380 mmc_delay(1);
1381 if (host->ops->card_busy && !host->ops->card_busy(host)) {
1382 err = -EAGAIN;
1383 goto power_cycle;
1244 } 1384 }
1385 /*
1386 * During a signal voltage level switch, the clock must be gated
1387 * for 5 ms according to the SD spec
1388 */
1389 clock = host->ios.clock;
1390 host->ios.clock = 0;
1391 mmc_set_ios(host);
1245 1392
1246 host->ios.signal_voltage = signal_voltage; 1393 if (__mmc_set_signal_voltage(host, signal_voltage)) {
1394 /*
1395 * Voltages may not have been switched, but we've already
1396 * sent CMD11, so a power cycle is required anyway
1397 */
1398 err = -EAGAIN;
1399 goto power_cycle;
1400 }
1247 1401
1248 if (host->ops->start_signal_voltage_switch) { 1402 /* Keep clock gated for at least 5 ms */
1249 mmc_host_clk_hold(host); 1403 mmc_delay(5);
1250 err = host->ops->start_signal_voltage_switch(host, &host->ios); 1404 host->ios.clock = clock;
1251 mmc_host_clk_release(host); 1405 mmc_set_ios(host);
1406
1407 /* Wait for at least 1 ms according to spec */
1408 mmc_delay(1);
1409
1410 /*
1411 * Failure to switch is indicated by the card holding
1412 * dat[0:3] low
1413 */
1414 if (host->ops->card_busy && host->ops->card_busy(host))
1415 err = -EAGAIN;
1416
1417power_cycle:
1418 if (err) {
1419 pr_debug("%s: Signal voltage switch failed, "
1420 "power cycling card\n", mmc_hostname(host));
1421 mmc_power_cycle(host);
1252 } 1422 }
1253 1423
1424 mmc_host_clk_release(host);
1425
1254 return err; 1426 return err;
1255} 1427}
1256 1428
@@ -1314,7 +1486,7 @@ static void mmc_power_up(struct mmc_host *host)
1314 mmc_set_ios(host); 1486 mmc_set_ios(host);
1315 1487
1316 /* Set signal voltage to 3.3V */ 1488 /* Set signal voltage to 3.3V */
1317 mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, false); 1489 __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330);
1318 1490
1319 /* 1491 /*
1320 * This delay should be sufficient to allow the power supply 1492 * This delay should be sufficient to allow the power supply
@@ -1372,6 +1544,14 @@ void mmc_power_off(struct mmc_host *host)
1372 mmc_host_clk_release(host); 1544 mmc_host_clk_release(host);
1373} 1545}
1374 1546
1547void mmc_power_cycle(struct mmc_host *host)
1548{
1549 mmc_power_off(host);
1550 /* Wait at least 1 ms according to SD spec */
1551 mmc_delay(1);
1552 mmc_power_up(host);
1553}
1554
1375/* 1555/*
1376 * Cleanup when the last reference to the bus operator is dropped. 1556 * Cleanup when the last reference to the bus operator is dropped.
1377 */ 1557 */
@@ -2388,6 +2568,7 @@ EXPORT_SYMBOL(mmc_flush_cache);
2388 * Turn the cache ON/OFF. 2568 * Turn the cache ON/OFF.
2389 * Turning the cache OFF shall trigger flushing of the data 2569 * Turning the cache OFF shall trigger flushing of the data
2390 * to the non-volatile storage. 2570 * to the non-volatile storage.
2571 * This function should be called with host claimed
2391 */ 2572 */
2392int mmc_cache_ctrl(struct mmc_host *host, u8 enable) 2573int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2393{ 2574{
@@ -2399,7 +2580,6 @@ int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2399 mmc_card_is_removable(host)) 2580 mmc_card_is_removable(host))
2400 return err; 2581 return err;
2401 2582
2402 mmc_claim_host(host);
2403 if (card && mmc_card_mmc(card) && 2583 if (card && mmc_card_mmc(card) &&
2404 (card->ext_csd.cache_size > 0)) { 2584 (card->ext_csd.cache_size > 0)) {
2405 enable = !!enable; 2585 enable = !!enable;
@@ -2417,7 +2597,6 @@ int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2417 card->ext_csd.cache_ctrl = enable; 2597 card->ext_csd.cache_ctrl = enable;
2418 } 2598 }
2419 } 2599 }
2420 mmc_release_host(host);
2421 2600
2422 return err; 2601 return err;
2423} 2602}
@@ -2436,10 +2615,6 @@ int mmc_suspend_host(struct mmc_host *host)
2436 cancel_delayed_work(&host->detect); 2615 cancel_delayed_work(&host->detect);
2437 mmc_flush_scheduled_work(); 2616 mmc_flush_scheduled_work();
2438 2617
2439 err = mmc_cache_ctrl(host, 0);
2440 if (err)
2441 goto out;
2442
2443 mmc_bus_get(host); 2618 mmc_bus_get(host);
2444 if (host->bus_ops && !host->bus_dead) { 2619 if (host->bus_ops && !host->bus_dead) {
2445 if (host->bus_ops->suspend) { 2620 if (host->bus_ops->suspend) {
@@ -2581,6 +2756,23 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2581} 2756}
2582#endif 2757#endif
2583 2758
2759/**
2760 * mmc_init_context_info() - init synchronization context
2761 * @host: mmc host
2762 *
2763 * Init struct context_info needed to implement asynchronous
2764 * request mechanism, used by mmc core, host driver and mmc requests
2765 * supplier.
2766 */
2767void mmc_init_context_info(struct mmc_host *host)
2768{
2769 spin_lock_init(&host->context_info.lock);
2770 host->context_info.is_new_req = false;
2771 host->context_info.is_done_rcv = false;
2772 host->context_info.is_waiting_last_req = false;
2773 init_waitqueue_head(&host->context_info.wait);
2774}
2775
2584static int __init mmc_init(void) 2776static int __init mmc_init(void)
2585{ 2777{
2586 int ret; 2778 int ret;
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 3bdafbca354f..b9f18a2a8874 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -40,11 +40,12 @@ void mmc_set_ungated(struct mmc_host *host);
40void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); 40void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
41void mmc_set_bus_width(struct mmc_host *host, unsigned int width); 41void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
42u32 mmc_select_voltage(struct mmc_host *host, u32 ocr); 42u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
43int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, 43int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
44 bool cmd11); 44int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
45void mmc_set_timing(struct mmc_host *host, unsigned int timing); 45void mmc_set_timing(struct mmc_host *host, unsigned int timing);
46void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); 46void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
47void mmc_power_off(struct mmc_host *host); 47void mmc_power_off(struct mmc_host *host);
48void mmc_power_cycle(struct mmc_host *host);
48 49
49static inline void mmc_delay(unsigned int ms) 50static inline void mmc_delay(unsigned int ms)
50{ 51{
@@ -76,5 +77,6 @@ void mmc_remove_host_debugfs(struct mmc_host *host);
76void mmc_add_card_debugfs(struct mmc_card *card); 77void mmc_add_card_debugfs(struct mmc_card *card);
77void mmc_remove_card_debugfs(struct mmc_card *card); 78void mmc_remove_card_debugfs(struct mmc_card *card);
78 79
80void mmc_init_context_info(struct mmc_host *host);
79#endif 81#endif
80 82
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index ee2e16b17017..821cd8224137 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -15,6 +15,8 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/idr.h> 17#include <linux/idr.h>
18#include <linux/of.h>
19#include <linux/of_gpio.h>
18#include <linux/pagemap.h> 20#include <linux/pagemap.h>
19#include <linux/export.h> 21#include <linux/export.h>
20#include <linux/leds.h> 22#include <linux/leds.h>
@@ -23,6 +25,7 @@
23 25
24#include <linux/mmc/host.h> 26#include <linux/mmc/host.h>
25#include <linux/mmc/card.h> 27#include <linux/mmc/card.h>
28#include <linux/mmc/slot-gpio.h>
26 29
27#include "core.h" 30#include "core.h"
28#include "host.h" 31#include "host.h"
@@ -295,6 +298,126 @@ static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
295#endif 298#endif
296 299
297/** 300/**
301 * mmc_of_parse() - parse host's device-tree node
302 * @host: host whose node should be parsed.
303 *
304 * To keep the rest of the MMC subsystem unaware of whether DT has been
305 * used to to instantiate and configure this host instance or not, we
306 * parse the properties and set respective generic mmc-host flags and
307 * parameters.
308 */
309void mmc_of_parse(struct mmc_host *host)
310{
311 struct device_node *np;
312 u32 bus_width;
313 bool explicit_inv_wp, gpio_inv_wp = false;
314 enum of_gpio_flags flags;
315 int len, ret, gpio;
316
317 if (!host->parent || !host->parent->of_node)
318 return;
319
320 np = host->parent->of_node;
321
322 /* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
323 if (of_property_read_u32(np, "bus-width", &bus_width) < 0) {
324 dev_dbg(host->parent,
325 "\"bus-width\" property is missing, assuming 1 bit.\n");
326 bus_width = 1;
327 }
328
329 switch (bus_width) {
330 case 8:
331 host->caps |= MMC_CAP_8_BIT_DATA;
332 /* Hosts capable of 8-bit transfers can also do 4 bits */
333 case 4:
334 host->caps |= MMC_CAP_4_BIT_DATA;
335 break;
336 case 1:
337 break;
338 default:
339 dev_err(host->parent,
340 "Invalid \"bus-width\" value %ud!\n", bus_width);
341 }
342
343 /* f_max is obtained from the optional "max-frequency" property */
344 of_property_read_u32(np, "max-frequency", &host->f_max);
345
346 /*
347 * Configure CD and WP pins. They are both by default active low to
348 * match the SDHCI spec. If GPIOs are provided for CD and / or WP, the
349 * mmc-gpio helpers are used to attach, configure and use them. If
350 * polarity inversion is specified in DT, one of MMC_CAP2_CD_ACTIVE_HIGH
351 * and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the
352 * "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability
353 * is set. If the "non-removable" property is found, the
354 * MMC_CAP_NONREMOVABLE capability is set and no card-detection
355 * configuration is performed.
356 */
357
358 /* Parse Card Detection */
359 if (of_find_property(np, "non-removable", &len)) {
360 host->caps |= MMC_CAP_NONREMOVABLE;
361 } else {
362 bool explicit_inv_cd, gpio_inv_cd = false;
363
364 explicit_inv_cd = of_property_read_bool(np, "cd-inverted");
365
366 if (of_find_property(np, "broken-cd", &len))
367 host->caps |= MMC_CAP_NEEDS_POLL;
368
369 gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &flags);
370 if (gpio_is_valid(gpio)) {
371 if (!(flags & OF_GPIO_ACTIVE_LOW))
372 gpio_inv_cd = true;
373
374 ret = mmc_gpio_request_cd(host, gpio);
375 if (ret < 0)
376 dev_err(host->parent,
377 "Failed to request CD GPIO #%d: %d!\n",
378 gpio, ret);
379 else
380 dev_info(host->parent, "Got CD GPIO #%d.\n",
381 gpio);
382 }
383
384 if (explicit_inv_cd ^ gpio_inv_cd)
385 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
386 }
387
388 /* Parse Write Protection */
389 explicit_inv_wp = of_property_read_bool(np, "wp-inverted");
390
391 gpio = of_get_named_gpio_flags(np, "wp-gpios", 0, &flags);
392 if (gpio_is_valid(gpio)) {
393 if (!(flags & OF_GPIO_ACTIVE_LOW))
394 gpio_inv_wp = true;
395
396 ret = mmc_gpio_request_ro(host, gpio);
397 if (ret < 0)
398 dev_err(host->parent,
399 "Failed to request WP GPIO: %d!\n", ret);
400 }
401 if (explicit_inv_wp ^ gpio_inv_wp)
402 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
403
404 if (of_find_property(np, "cap-sd-highspeed", &len))
405 host->caps |= MMC_CAP_SD_HIGHSPEED;
406 if (of_find_property(np, "cap-mmc-highspeed", &len))
407 host->caps |= MMC_CAP_MMC_HIGHSPEED;
408 if (of_find_property(np, "cap-power-off-card", &len))
409 host->caps |= MMC_CAP_POWER_OFF_CARD;
410 if (of_find_property(np, "cap-sdio-irq", &len))
411 host->caps |= MMC_CAP_SDIO_IRQ;
412 if (of_find_property(np, "keep-power-in-suspend", &len))
413 host->pm_caps |= MMC_PM_KEEP_POWER;
414 if (of_find_property(np, "enable-sdio-wakeup", &len))
415 host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
416}
417
418EXPORT_SYMBOL(mmc_of_parse);
419
420/**
298 * mmc_alloc_host - initialise the per-host structure. 421 * mmc_alloc_host - initialise the per-host structure.
299 * @extra: sizeof private data structure 422 * @extra: sizeof private data structure
300 * @dev: pointer to host device model structure 423 * @dev: pointer to host device model structure
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index e6e39111e05b..c8f3d6e0684e 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -496,7 +496,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
496 * RPMB regions are defined in multiples of 128K. 496 * RPMB regions are defined in multiples of 128K.
497 */ 497 */
498 card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; 498 card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT];
499 if (ext_csd[EXT_CSD_RPMB_MULT]) { 499 if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) {
500 mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17, 500 mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17,
501 EXT_CSD_PART_CONFIG_ACC_RPMB, 501 EXT_CSD_PART_CONFIG_ACC_RPMB,
502 "rpmb", 0, false, 502 "rpmb", 0, false,
@@ -538,6 +538,11 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
538 } else { 538 } else {
539 card->ext_csd.data_tag_unit_size = 0; 539 card->ext_csd.data_tag_unit_size = 0;
540 } 540 }
541
542 card->ext_csd.max_packed_writes =
543 ext_csd[EXT_CSD_MAX_PACKED_WRITES];
544 card->ext_csd.max_packed_reads =
545 ext_csd[EXT_CSD_MAX_PACKED_READS];
541 } else { 546 } else {
542 card->ext_csd.data_sector_size = 512; 547 card->ext_csd.data_sector_size = 512;
543 } 548 }
@@ -769,11 +774,11 @@ static int mmc_select_hs200(struct mmc_card *card)
769 774
770 if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V && 775 if (card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_2V &&
771 host->caps2 & MMC_CAP2_HS200_1_2V_SDR) 776 host->caps2 & MMC_CAP2_HS200_1_2V_SDR)
772 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120, 0); 777 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
773 778
774 if (err && card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_8V && 779 if (err && card->ext_csd.card_type & EXT_CSD_CARD_TYPE_SDR_1_8V &&
775 host->caps2 & MMC_CAP2_HS200_1_8V_SDR) 780 host->caps2 & MMC_CAP2_HS200_1_8V_SDR)
776 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, 0); 781 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
777 782
778 /* If fails try again during next card power cycle */ 783 /* If fails try again during next card power cycle */
779 if (err) 784 if (err)
@@ -1221,8 +1226,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1221 * WARNING: eMMC rules are NOT the same as SD DDR 1226 * WARNING: eMMC rules are NOT the same as SD DDR
1222 */ 1227 */
1223 if (ddr == MMC_1_2V_DDR_MODE) { 1228 if (ddr == MMC_1_2V_DDR_MODE) {
1224 err = mmc_set_signal_voltage(host, 1229 err = __mmc_set_signal_voltage(host,
1225 MMC_SIGNAL_VOLTAGE_120, 0); 1230 MMC_SIGNAL_VOLTAGE_120);
1226 if (err) 1231 if (err)
1227 goto err; 1232 goto err;
1228 } 1233 }
@@ -1275,6 +1280,29 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1275 } 1280 }
1276 } 1281 }
1277 1282
1283 /*
1284 * The mandatory minimum values are defined for packed command.
1285 * read: 5, write: 3
1286 */
1287 if (card->ext_csd.max_packed_writes >= 3 &&
1288 card->ext_csd.max_packed_reads >= 5 &&
1289 host->caps2 & MMC_CAP2_PACKED_CMD) {
1290 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1291 EXT_CSD_EXP_EVENTS_CTRL,
1292 EXT_CSD_PACKED_EVENT_EN,
1293 card->ext_csd.generic_cmd6_time);
1294 if (err && err != -EBADMSG)
1295 goto free_card;
1296 if (err) {
1297 pr_warn("%s: Enabling packed event failed\n",
1298 mmc_hostname(card->host));
1299 card->ext_csd.packed_event_en = 0;
1300 err = 0;
1301 } else {
1302 card->ext_csd.packed_event_en = 1;
1303 }
1304 }
1305
1278 if (!oldcard) 1306 if (!oldcard)
1279 host->card = card; 1307 host->card = card;
1280 1308
@@ -1379,6 +1407,11 @@ static int mmc_suspend(struct mmc_host *host)
1379 BUG_ON(!host->card); 1407 BUG_ON(!host->card);
1380 1408
1381 mmc_claim_host(host); 1409 mmc_claim_host(host);
1410
1411 err = mmc_cache_ctrl(host, 0);
1412 if (err)
1413 goto out;
1414
1382 if (mmc_can_poweroff_notify(host->card)) 1415 if (mmc_can_poweroff_notify(host->card))
1383 err = mmc_poweroff_notify(host->card, EXT_CSD_POWER_OFF_SHORT); 1416 err = mmc_poweroff_notify(host->card, EXT_CSD_POWER_OFF_SHORT);
1384 else if (mmc_card_can_sleep(host)) 1417 else if (mmc_card_can_sleep(host))
@@ -1386,8 +1419,9 @@ static int mmc_suspend(struct mmc_host *host)
1386 else if (!mmc_host_is_spi(host)) 1419 else if (!mmc_host_is_spi(host))
1387 err = mmc_deselect_cards(host); 1420 err = mmc_deselect_cards(host);
1388 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1421 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
1389 mmc_release_host(host);
1390 1422
1423out:
1424 mmc_release_host(host);
1391 return err; 1425 return err;
1392} 1426}
1393 1427
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 6d8f7012d73a..49f04bc9d0eb 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -363,6 +363,7 @@ int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
363 return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD, 363 return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD,
364 ext_csd, 512); 364 ext_csd, 512);
365} 365}
366EXPORT_SYMBOL_GPL(mmc_send_ext_csd);
366 367
367int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp) 368int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp)
368{ 369{
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 74972c241dff..9e645e19cec6 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -444,8 +444,7 @@ static void sd_update_bus_speed_mode(struct mmc_card *card)
444 * If the host doesn't support any of the UHS-I modes, fallback on 444 * If the host doesn't support any of the UHS-I modes, fallback on
445 * default speed. 445 * default speed.
446 */ 446 */
447 if (!(card->host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | 447 if (!mmc_host_uhs(card->host)) {
448 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))) {
449 card->sd_bus_speed = 0; 448 card->sd_bus_speed = 0;
450 return; 449 return;
451 } 450 }
@@ -713,6 +712,14 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
713{ 712{
714 int err; 713 int err;
715 u32 max_current; 714 u32 max_current;
715 int retries = 10;
716
717try_again:
718 if (!retries) {
719 ocr &= ~SD_OCR_S18R;
720 pr_warning("%s: Skipping voltage switch\n",
721 mmc_hostname(host));
722 }
716 723
717 /* 724 /*
718 * Since we're changing the OCR value, we seem to 725 * Since we're changing the OCR value, we seem to
@@ -734,10 +741,10 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
734 741
735 /* 742 /*
736 * If the host supports one of UHS-I modes, request the card 743 * If the host supports one of UHS-I modes, request the card
737 * to switch to 1.8V signaling level. 744 * to switch to 1.8V signaling level. If the card has failed
745 * repeatedly to switch however, skip this.
738 */ 746 */
739 if (host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | 747 if (retries && mmc_host_uhs(host))
740 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
741 ocr |= SD_OCR_S18R; 748 ocr |= SD_OCR_S18R;
742 749
743 /* 750 /*
@@ -748,7 +755,6 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
748 if (max_current > 150) 755 if (max_current > 150)
749 ocr |= SD_OCR_XPC; 756 ocr |= SD_OCR_XPC;
750 757
751try_again:
752 err = mmc_send_app_op_cond(host, ocr, rocr); 758 err = mmc_send_app_op_cond(host, ocr, rocr);
753 if (err) 759 if (err)
754 return err; 760 return err;
@@ -759,9 +765,12 @@ try_again:
759 */ 765 */
760 if (!mmc_host_is_spi(host) && rocr && 766 if (!mmc_host_is_spi(host) && rocr &&
761 ((*rocr & 0x41000000) == 0x41000000)) { 767 ((*rocr & 0x41000000) == 0x41000000)) {
762 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, true); 768 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
763 if (err) { 769 if (err == -EAGAIN) {
764 ocr &= ~SD_OCR_S18R; 770 retries--;
771 goto try_again;
772 } else if (err) {
773 retries = 0;
765 goto try_again; 774 goto try_again;
766 } 775 }
767 } 776 }
@@ -960,16 +969,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
960 969
961 /* Card is an ultra-high-speed card */ 970 /* Card is an ultra-high-speed card */
962 mmc_card_set_uhs(card); 971 mmc_card_set_uhs(card);
963
964 /*
965 * Since initialization is now complete, enable preset
966 * value registers for UHS-I cards.
967 */
968 if (host->ops->enable_preset_value) {
969 mmc_host_clk_hold(card->host);
970 host->ops->enable_preset_value(host, true);
971 mmc_host_clk_release(card->host);
972 }
973 } else { 972 } else {
974 /* 973 /*
975 * Attempt to change to high-speed (if supported) 974 * Attempt to change to high-speed (if supported)
@@ -1148,13 +1147,6 @@ int mmc_attach_sd(struct mmc_host *host)
1148 BUG_ON(!host); 1147 BUG_ON(!host);
1149 WARN_ON(!host->claimed); 1148 WARN_ON(!host->claimed);
1150 1149
1151 /* Disable preset value enable if already set since last time */
1152 if (host->ops->enable_preset_value) {
1153 mmc_host_clk_hold(host);
1154 host->ops->enable_preset_value(host, false);
1155 mmc_host_clk_release(host);
1156 }
1157
1158 err = mmc_send_app_op_cond(host, 0, &ocr); 1150 err = mmc_send_app_op_cond(host, 0, &ocr);
1159 if (err) 1151 if (err)
1160 return err; 1152 return err;
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 2273ce6b6c1a..aa0719a4dfd1 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -157,10 +157,7 @@ static int sdio_read_cccr(struct mmc_card *card, u32 ocr)
157 if (ret) 157 if (ret)
158 goto out; 158 goto out;
159 159
160 if (card->host->caps & 160 if (mmc_host_uhs(card->host)) {
161 (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 |
162 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 |
163 MMC_CAP_UHS_DDR50)) {
164 if (data & SDIO_UHS_DDR50) 161 if (data & SDIO_UHS_DDR50)
165 card->sw_caps.sd3_bus_mode 162 card->sw_caps.sd3_bus_mode
166 |= SD_MODE_UHS_DDR50; 163 |= SD_MODE_UHS_DDR50;
@@ -478,8 +475,7 @@ static int sdio_set_bus_speed_mode(struct mmc_card *card)
478 * If the host doesn't support any of the UHS-I modes, fallback on 475 * If the host doesn't support any of the UHS-I modes, fallback on
479 * default speed. 476 * default speed.
480 */ 477 */
481 if (!(card->host->caps & (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | 478 if (!mmc_host_uhs(card->host))
482 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50)))
483 return 0; 479 return 0;
484 480
485 bus_speed = SDIO_SPEED_SDR12; 481 bus_speed = SDIO_SPEED_SDR12;
@@ -489,23 +485,27 @@ static int sdio_set_bus_speed_mode(struct mmc_card *card)
489 bus_speed = SDIO_SPEED_SDR104; 485 bus_speed = SDIO_SPEED_SDR104;
490 timing = MMC_TIMING_UHS_SDR104; 486 timing = MMC_TIMING_UHS_SDR104;
491 card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR; 487 card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
488 card->sd_bus_speed = UHS_SDR104_BUS_SPEED;
492 } else if ((card->host->caps & MMC_CAP_UHS_DDR50) && 489 } else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
493 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) { 490 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) {
494 bus_speed = SDIO_SPEED_DDR50; 491 bus_speed = SDIO_SPEED_DDR50;
495 timing = MMC_TIMING_UHS_DDR50; 492 timing = MMC_TIMING_UHS_DDR50;
496 card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR; 493 card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
494 card->sd_bus_speed = UHS_DDR50_BUS_SPEED;
497 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | 495 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
498 MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode & 496 MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode &
499 SD_MODE_UHS_SDR50)) { 497 SD_MODE_UHS_SDR50)) {
500 bus_speed = SDIO_SPEED_SDR50; 498 bus_speed = SDIO_SPEED_SDR50;
501 timing = MMC_TIMING_UHS_SDR50; 499 timing = MMC_TIMING_UHS_SDR50;
502 card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR; 500 card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
501 card->sd_bus_speed = UHS_SDR50_BUS_SPEED;
503 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | 502 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
504 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) && 503 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
505 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) { 504 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) {
506 bus_speed = SDIO_SPEED_SDR25; 505 bus_speed = SDIO_SPEED_SDR25;
507 timing = MMC_TIMING_UHS_SDR25; 506 timing = MMC_TIMING_UHS_SDR25;
508 card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR; 507 card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
508 card->sd_bus_speed = UHS_SDR25_BUS_SPEED;
509 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | 509 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
510 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 | 510 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
511 MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode & 511 MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode &
@@ -513,6 +513,7 @@ static int sdio_set_bus_speed_mode(struct mmc_card *card)
513 bus_speed = SDIO_SPEED_SDR12; 513 bus_speed = SDIO_SPEED_SDR12;
514 timing = MMC_TIMING_UHS_SDR12; 514 timing = MMC_TIMING_UHS_SDR12;
515 card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR; 515 card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
516 card->sd_bus_speed = UHS_SDR12_BUS_SPEED;
516 } 517 }
517 518
518 err = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed); 519 err = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed);
@@ -583,10 +584,19 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
583{ 584{
584 struct mmc_card *card; 585 struct mmc_card *card;
585 int err; 586 int err;
587 int retries = 10;
586 588
587 BUG_ON(!host); 589 BUG_ON(!host);
588 WARN_ON(!host->claimed); 590 WARN_ON(!host->claimed);
589 591
592try_again:
593 if (!retries) {
594 pr_warning("%s: Skipping voltage switch\n",
595 mmc_hostname(host));
596 ocr &= ~R4_18V_PRESENT;
597 host->ocr &= ~R4_18V_PRESENT;
598 }
599
590 /* 600 /*
591 * Inform the card of the voltage 601 * Inform the card of the voltage
592 */ 602 */
@@ -645,14 +655,16 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
645 * systems that claim 1.8v signalling in fact do not support 655 * systems that claim 1.8v signalling in fact do not support
646 * it. 656 * it.
647 */ 657 */
648 if ((ocr & R4_18V_PRESENT) && 658 if (!powered_resume && (ocr & R4_18V_PRESENT) && mmc_host_uhs(host)) {
649 (host->caps & 659 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180);
650 (MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | 660 if (err == -EAGAIN) {
651 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | 661 sdio_reset(host);
652 MMC_CAP_UHS_DDR50))) { 662 mmc_go_idle(host);
653 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180, 663 mmc_send_if_cond(host, host->ocr_avail);
654 true); 664 mmc_remove_card(card);
655 if (err) { 665 retries--;
666 goto try_again;
667 } else if (err) {
656 ocr &= ~R4_18V_PRESENT; 668 ocr &= ~R4_18V_PRESENT;
657 host->ocr &= ~R4_18V_PRESENT; 669 host->ocr &= ~R4_18V_PRESENT;
658 } 670 }
@@ -937,10 +949,12 @@ static int mmc_sdio_resume(struct mmc_host *host)
937 mmc_claim_host(host); 949 mmc_claim_host(host);
938 950
939 /* No need to reinitialize powered-resumed nonremovable cards */ 951 /* No need to reinitialize powered-resumed nonremovable cards */
940 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) 952 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) {
953 sdio_reset(host);
954 mmc_go_idle(host);
941 err = mmc_sdio_init_card(host, host->ocr, host->card, 955 err = mmc_sdio_init_card(host, host->ocr, host->card,
942 mmc_card_keep_power(host)); 956 mmc_card_keep_power(host));
943 else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { 957 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
944 /* We may have switched to 1-bit mode during suspend */ 958 /* We may have switched to 1-bit mode during suspend */
945 err = sdio_enable_4bit_bus(host->card); 959 err = sdio_enable_4bit_bus(host->card);
946 if (err > 0) { 960 if (err > 0) {
@@ -1020,6 +1034,10 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
1020 goto out; 1034 goto out;
1021 } 1035 }
1022 1036
1037 if (mmc_host_uhs(host))
1038 /* to query card if 1.8V signalling is supported */
1039 host->ocr |= R4_18V_PRESENT;
1040
1023 ret = mmc_sdio_init_card(host, host->ocr, host->card, 1041 ret = mmc_sdio_init_card(host, host->ocr, host->card,
1024 mmc_card_keep_power(host)); 1042 mmc_card_keep_power(host));
1025 if (!ret && host->sdio_irqs) 1043 if (!ret && host->sdio_irqs)
@@ -1085,6 +1103,10 @@ int mmc_attach_sdio(struct mmc_host *host)
1085 /* 1103 /*
1086 * Detect and init the card. 1104 * Detect and init the card.
1087 */ 1105 */
1106 if (mmc_host_uhs(host))
1107 /* to query card if 1.8V signalling is supported */
1108 host->ocr |= R4_18V_PRESENT;
1109
1088 err = mmc_sdio_init_card(host, host->ocr, NULL, 0); 1110 err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
1089 if (err) { 1111 if (err) {
1090 if (err == -EAGAIN) { 1112 if (err == -EAGAIN) {
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 16a1c0b6f264..324235105519 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -92,6 +92,20 @@ int mmc_gpio_get_cd(struct mmc_host *host)
92} 92}
93EXPORT_SYMBOL(mmc_gpio_get_cd); 93EXPORT_SYMBOL(mmc_gpio_get_cd);
94 94
95/**
96 * mmc_gpio_request_ro - request a gpio for write-protection
97 * @host: mmc host
98 * @gpio: gpio number requested
99 *
100 * As devm_* managed functions are used in mmc_gpio_request_ro(), client
101 * drivers do not need to explicitly call mmc_gpio_free_ro() for freeing up,
102 * if the requesting and freeing are only needed at probing and unbinding time
103 * for once. However, if client drivers do something special like runtime
104 * switching for write-protection, they are responsible for calling
105 * mmc_gpio_request_ro() and mmc_gpio_free_ro() as a pair on their own.
106 *
107 * Returns zero on success, else an error.
108 */
95int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio) 109int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
96{ 110{
97 struct mmc_gpio *ctx; 111 struct mmc_gpio *ctx;
@@ -106,7 +120,8 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
106 120
107 ctx = host->slot.handler_priv; 121 ctx = host->slot.handler_priv;
108 122
109 ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label); 123 ret = devm_gpio_request_one(&host->class_dev, gpio, GPIOF_DIR_IN,
124 ctx->ro_label);
110 if (ret < 0) 125 if (ret < 0)
111 return ret; 126 return ret;
112 127
@@ -116,6 +131,20 @@ int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
116} 131}
117EXPORT_SYMBOL(mmc_gpio_request_ro); 132EXPORT_SYMBOL(mmc_gpio_request_ro);
118 133
134/**
135 * mmc_gpio_request_cd - request a gpio for card-detection
136 * @host: mmc host
137 * @gpio: gpio number requested
138 *
139 * As devm_* managed functions are used in mmc_gpio_request_cd(), client
140 * drivers do not need to explicitly call mmc_gpio_free_cd() for freeing up,
141 * if the requesting and freeing are only needed at probing and unbinding time
142 * for once. However, if client drivers do something special like runtime
143 * switching for card-detection, they are responsible for calling
144 * mmc_gpio_request_cd() and mmc_gpio_free_cd() as a pair on their own.
145 *
146 * Returns zero on success, else an error.
147 */
119int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio) 148int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
120{ 149{
121 struct mmc_gpio *ctx; 150 struct mmc_gpio *ctx;
@@ -128,7 +157,8 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
128 157
129 ctx = host->slot.handler_priv; 158 ctx = host->slot.handler_priv;
130 159
131 ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->cd_label); 160 ret = devm_gpio_request_one(&host->class_dev, gpio, GPIOF_DIR_IN,
161 ctx->cd_label);
132 if (ret < 0) 162 if (ret < 0)
133 /* 163 /*
134 * don't bother freeing memory. It might still get used by other 164 * don't bother freeing memory. It might still get used by other
@@ -146,7 +176,8 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
146 irq = -EINVAL; 176 irq = -EINVAL;
147 177
148 if (irq >= 0) { 178 if (irq >= 0) {
149 ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt, 179 ret = devm_request_threaded_irq(&host->class_dev, irq,
180 NULL, mmc_gpio_cd_irqt,
150 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 181 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
151 ctx->cd_label, host); 182 ctx->cd_label, host);
152 if (ret < 0) 183 if (ret < 0)
@@ -164,6 +195,13 @@ int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
164} 195}
165EXPORT_SYMBOL(mmc_gpio_request_cd); 196EXPORT_SYMBOL(mmc_gpio_request_cd);
166 197
198/**
199 * mmc_gpio_free_ro - free the write-protection gpio
200 * @host: mmc host
201 *
202 * It's provided only for cases that client drivers need to manually free
203 * up the write-protection gpio requested by mmc_gpio_request_ro().
204 */
167void mmc_gpio_free_ro(struct mmc_host *host) 205void mmc_gpio_free_ro(struct mmc_host *host)
168{ 206{
169 struct mmc_gpio *ctx = host->slot.handler_priv; 207 struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -175,10 +213,17 @@ void mmc_gpio_free_ro(struct mmc_host *host)
175 gpio = ctx->ro_gpio; 213 gpio = ctx->ro_gpio;
176 ctx->ro_gpio = -EINVAL; 214 ctx->ro_gpio = -EINVAL;
177 215
178 gpio_free(gpio); 216 devm_gpio_free(&host->class_dev, gpio);
179} 217}
180EXPORT_SYMBOL(mmc_gpio_free_ro); 218EXPORT_SYMBOL(mmc_gpio_free_ro);
181 219
220/**
221 * mmc_gpio_free_cd - free the card-detection gpio
222 * @host: mmc host
223 *
224 * It's provided only for cases that client drivers need to manually free
225 * up the card-detection gpio requested by mmc_gpio_request_cd().
226 */
182void mmc_gpio_free_cd(struct mmc_host *host) 227void mmc_gpio_free_cd(struct mmc_host *host)
183{ 228{
184 struct mmc_gpio *ctx = host->slot.handler_priv; 229 struct mmc_gpio *ctx = host->slot.handler_priv;
@@ -188,13 +233,13 @@ void mmc_gpio_free_cd(struct mmc_host *host)
188 return; 233 return;
189 234
190 if (host->slot.cd_irq >= 0) { 235 if (host->slot.cd_irq >= 0) {
191 free_irq(host->slot.cd_irq, host); 236 devm_free_irq(&host->class_dev, host->slot.cd_irq, host);
192 host->slot.cd_irq = -EINVAL; 237 host->slot.cd_irq = -EINVAL;
193 } 238 }
194 239
195 gpio = ctx->cd_gpio; 240 gpio = ctx->cd_gpio;
196 ctx->cd_gpio = -EINVAL; 241 ctx->cd_gpio = -EINVAL;
197 242
198 gpio_free(gpio); 243 devm_gpio_free(&host->class_dev, gpio);
199} 244}
200EXPORT_SYMBOL(mmc_gpio_free_cd); 245EXPORT_SYMBOL(mmc_gpio_free_cd);