aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/host/mmci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/host/mmci.c')
-rw-r--r--drivers/mmc/host/mmci.c324
1 files changed, 83 insertions, 241 deletions
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 771c60ab4a32..a084edd37af5 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -13,6 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/ioport.h> 14#include <linux/ioport.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/io.h>
16#include <linux/interrupt.h> 17#include <linux/interrupt.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
@@ -23,6 +24,7 @@
23#include <linux/mmc/pm.h> 24#include <linux/mmc/pm.h>
24#include <linux/mmc/host.h> 25#include <linux/mmc/host.h>
25#include <linux/mmc/card.h> 26#include <linux/mmc/card.h>
27#include <linux/mmc/slot-gpio.h>
26#include <linux/amba/bus.h> 28#include <linux/amba/bus.h>
27#include <linux/clk.h> 29#include <linux/clk.h>
28#include <linux/scatterlist.h> 30#include <linux/scatterlist.h>
@@ -364,7 +366,6 @@ static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
364#ifdef CONFIG_DMA_ENGINE 366#ifdef CONFIG_DMA_ENGINE
365static void mmci_dma_setup(struct mmci_host *host) 367static void mmci_dma_setup(struct mmci_host *host)
366{ 368{
367 struct mmci_platform_data *plat = host->plat;
368 const char *rxname, *txname; 369 const char *rxname, *txname;
369 dma_cap_mask_t mask; 370 dma_cap_mask_t mask;
370 371
@@ -378,25 +379,6 @@ static void mmci_dma_setup(struct mmci_host *host)
378 dma_cap_zero(mask); 379 dma_cap_zero(mask);
379 dma_cap_set(DMA_SLAVE, mask); 380 dma_cap_set(DMA_SLAVE, mask);
380 381
381 if (plat && plat->dma_filter) {
382 if (!host->dma_rx_channel && plat->dma_rx_param) {
383 host->dma_rx_channel = dma_request_channel(mask,
384 plat->dma_filter,
385 plat->dma_rx_param);
386 /* E.g if no DMA hardware is present */
387 if (!host->dma_rx_channel)
388 dev_err(mmc_dev(host->mmc), "no RX DMA channel\n");
389 }
390
391 if (!host->dma_tx_channel && plat->dma_tx_param) {
392 host->dma_tx_channel = dma_request_channel(mask,
393 plat->dma_filter,
394 plat->dma_tx_param);
395 if (!host->dma_tx_channel)
396 dev_warn(mmc_dev(host->mmc), "no TX DMA channel\n");
397 }
398 }
399
400 /* 382 /*
401 * If only an RX channel is specified, the driver will 383 * If only an RX channel is specified, the driver will
402 * attempt to use it bidirectionally, however if it is 384 * attempt to use it bidirectionally, however if it is
@@ -444,11 +426,9 @@ static void mmci_dma_setup(struct mmci_host *host)
444 */ 426 */
445static inline void mmci_dma_release(struct mmci_host *host) 427static inline void mmci_dma_release(struct mmci_host *host)
446{ 428{
447 struct mmci_platform_data *plat = host->plat;
448
449 if (host->dma_rx_channel) 429 if (host->dma_rx_channel)
450 dma_release_channel(host->dma_rx_channel); 430 dma_release_channel(host->dma_rx_channel);
451 if (host->dma_tx_channel && plat->dma_tx_param) 431 if (host->dma_tx_channel)
452 dma_release_channel(host->dma_tx_channel); 432 dma_release_channel(host->dma_tx_channel);
453 host->dma_rx_channel = host->dma_tx_channel = NULL; 433 host->dma_rx_channel = host->dma_tx_channel = NULL;
454} 434}
@@ -1285,7 +1265,7 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1285 * indicating signal direction for the signals in 1265 * indicating signal direction for the signals in
1286 * the SD/MMC bus and feedback-clock usage. 1266 * the SD/MMC bus and feedback-clock usage.
1287 */ 1267 */
1288 pwr |= host->plat->sigdir; 1268 pwr |= host->pwr_reg_add;
1289 1269
1290 if (ios->bus_width == MMC_BUS_WIDTH_4) 1270 if (ios->bus_width == MMC_BUS_WIDTH_4)
1291 pwr &= ~MCI_ST_DATA74DIREN; 1271 pwr &= ~MCI_ST_DATA74DIREN;
@@ -1326,35 +1306,18 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1326 pm_runtime_put_autosuspend(mmc_dev(mmc)); 1306 pm_runtime_put_autosuspend(mmc_dev(mmc));
1327} 1307}
1328 1308
1329static int mmci_get_ro(struct mmc_host *mmc)
1330{
1331 struct mmci_host *host = mmc_priv(mmc);
1332
1333 if (host->gpio_wp == -ENOSYS)
1334 return -ENOSYS;
1335
1336 return gpio_get_value_cansleep(host->gpio_wp);
1337}
1338
1339static int mmci_get_cd(struct mmc_host *mmc) 1309static int mmci_get_cd(struct mmc_host *mmc)
1340{ 1310{
1341 struct mmci_host *host = mmc_priv(mmc); 1311 struct mmci_host *host = mmc_priv(mmc);
1342 struct mmci_platform_data *plat = host->plat; 1312 struct mmci_platform_data *plat = host->plat;
1343 unsigned int status; 1313 unsigned int status = mmc_gpio_get_cd(mmc);
1344 1314
1345 if (host->gpio_cd == -ENOSYS) { 1315 if (status == -ENOSYS) {
1346 if (!plat->status) 1316 if (!plat->status)
1347 return 1; /* Assume always present */ 1317 return 1; /* Assume always present */
1348 1318
1349 status = plat->status(mmc_dev(host->mmc)); 1319 status = plat->status(mmc_dev(host->mmc));
1350 } else 1320 }
1351 status = !!gpio_get_value_cansleep(host->gpio_cd)
1352 ^ plat->cd_invert;
1353
1354 /*
1355 * Use positive logic throughout - status is zero for no card,
1356 * non-zero for card inserted.
1357 */
1358 return status; 1321 return status;
1359} 1322}
1360 1323
@@ -1391,70 +1354,44 @@ static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
1391 return ret; 1354 return ret;
1392} 1355}
1393 1356
1394static irqreturn_t mmci_cd_irq(int irq, void *dev_id)
1395{
1396 struct mmci_host *host = dev_id;
1397
1398 mmc_detect_change(host->mmc, msecs_to_jiffies(500));
1399
1400 return IRQ_HANDLED;
1401}
1402
1403static struct mmc_host_ops mmci_ops = { 1357static struct mmc_host_ops mmci_ops = {
1404 .request = mmci_request, 1358 .request = mmci_request,
1405 .pre_req = mmci_pre_request, 1359 .pre_req = mmci_pre_request,
1406 .post_req = mmci_post_request, 1360 .post_req = mmci_post_request,
1407 .set_ios = mmci_set_ios, 1361 .set_ios = mmci_set_ios,
1408 .get_ro = mmci_get_ro, 1362 .get_ro = mmc_gpio_get_ro,
1409 .get_cd = mmci_get_cd, 1363 .get_cd = mmci_get_cd,
1410 .start_signal_voltage_switch = mmci_sig_volt_switch, 1364 .start_signal_voltage_switch = mmci_sig_volt_switch,
1411}; 1365};
1412 1366
1413#ifdef CONFIG_OF 1367static int mmci_of_parse(struct device_node *np, struct mmc_host *mmc)
1414static void mmci_dt_populate_generic_pdata(struct device_node *np,
1415 struct mmci_platform_data *pdata)
1416{ 1368{
1417 int bus_width = 0; 1369 struct mmci_host *host = mmc_priv(mmc);
1418 1370 int ret = mmc_of_parse(mmc);
1419 pdata->gpio_wp = of_get_named_gpio(np, "wp-gpios", 0);
1420 pdata->gpio_cd = of_get_named_gpio(np, "cd-gpios", 0);
1421 1371
1422 if (of_get_property(np, "cd-inverted", NULL)) 1372 if (ret)
1423 pdata->cd_invert = true; 1373 return ret;
1424 else
1425 pdata->cd_invert = false;
1426 1374
1427 of_property_read_u32(np, "max-frequency", &pdata->f_max); 1375 if (of_get_property(np, "st,sig-dir-dat0", NULL))
1428 if (!pdata->f_max) 1376 host->pwr_reg_add |= MCI_ST_DATA0DIREN;
1429 pr_warn("%s has no 'max-frequency' property\n", np->full_name); 1377 if (of_get_property(np, "st,sig-dir-dat2", NULL))
1378 host->pwr_reg_add |= MCI_ST_DATA2DIREN;
1379 if (of_get_property(np, "st,sig-dir-dat31", NULL))
1380 host->pwr_reg_add |= MCI_ST_DATA31DIREN;
1381 if (of_get_property(np, "st,sig-dir-dat74", NULL))
1382 host->pwr_reg_add |= MCI_ST_DATA74DIREN;
1383 if (of_get_property(np, "st,sig-dir-cmd", NULL))
1384 host->pwr_reg_add |= MCI_ST_CMDDIREN;
1385 if (of_get_property(np, "st,sig-pin-fbclk", NULL))
1386 host->pwr_reg_add |= MCI_ST_FBCLKEN;
1430 1387
1431 if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL)) 1388 if (of_get_property(np, "mmc-cap-mmc-highspeed", NULL))
1432 pdata->capabilities |= MMC_CAP_MMC_HIGHSPEED; 1389 mmc->caps |= MMC_CAP_MMC_HIGHSPEED;
1433 if (of_get_property(np, "mmc-cap-sd-highspeed", NULL)) 1390 if (of_get_property(np, "mmc-cap-sd-highspeed", NULL))
1434 pdata->capabilities |= MMC_CAP_SD_HIGHSPEED; 1391 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
1435 1392
1436 of_property_read_u32(np, "bus-width", &bus_width); 1393 return 0;
1437 switch (bus_width) {
1438 case 0 :
1439 /* No bus-width supplied. */
1440 break;
1441 case 4 :
1442 pdata->capabilities |= MMC_CAP_4_BIT_DATA;
1443 break;
1444 case 8 :
1445 pdata->capabilities |= MMC_CAP_8_BIT_DATA;
1446 break;
1447 default :
1448 pr_warn("%s: Unsupported bus width\n", np->full_name);
1449 }
1450}
1451#else
1452static void mmci_dt_populate_generic_pdata(struct device_node *np,
1453 struct mmci_platform_data *pdata)
1454{
1455 return;
1456} 1394}
1457#endif
1458 1395
1459static int mmci_probe(struct amba_device *dev, 1396static int mmci_probe(struct amba_device *dev,
1460 const struct amba_id *id) 1397 const struct amba_id *id)
@@ -1478,26 +1415,17 @@ static int mmci_probe(struct amba_device *dev,
1478 return -ENOMEM; 1415 return -ENOMEM;
1479 } 1416 }
1480 1417
1481 if (np) 1418 mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);
1482 mmci_dt_populate_generic_pdata(np, plat); 1419 if (!mmc)
1420 return -ENOMEM;
1483 1421
1484 ret = amba_request_regions(dev, DRIVER_NAME); 1422 ret = mmci_of_parse(np, mmc);
1485 if (ret) 1423 if (ret)
1486 goto out; 1424 goto host_free;
1487
1488 mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);
1489 if (!mmc) {
1490 ret = -ENOMEM;
1491 goto rel_regions;
1492 }
1493 1425
1494 host = mmc_priv(mmc); 1426 host = mmc_priv(mmc);
1495 host->mmc = mmc; 1427 host->mmc = mmc;
1496 1428
1497 host->gpio_wp = -ENOSYS;
1498 host->gpio_cd = -ENOSYS;
1499 host->gpio_cd_irq = -1;
1500
1501 host->hw_designer = amba_manf(dev); 1429 host->hw_designer = amba_manf(dev);
1502 host->hw_revision = amba_rev(dev); 1430 host->hw_revision = amba_rev(dev);
1503 dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer); 1431 dev_dbg(mmc_dev(mmc), "designer ID = 0x%02x\n", host->hw_designer);
@@ -1529,10 +1457,11 @@ static int mmci_probe(struct amba_device *dev,
1529 dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n", 1457 dev_dbg(mmc_dev(mmc), "eventual mclk rate: %u Hz\n",
1530 host->mclk); 1458 host->mclk);
1531 } 1459 }
1460
1532 host->phybase = dev->res.start; 1461 host->phybase = dev->res.start;
1533 host->base = ioremap(dev->res.start, resource_size(&dev->res)); 1462 host->base = devm_ioremap_resource(&dev->dev, &dev->res);
1534 if (!host->base) { 1463 if (IS_ERR(host->base)) {
1535 ret = -ENOMEM; 1464 ret = PTR_ERR(host->base);
1536 goto clk_disable; 1465 goto clk_disable;
1537 } 1466 }
1538 1467
@@ -1546,15 +1475,13 @@ static int mmci_probe(struct amba_device *dev,
1546 else 1475 else
1547 mmc->f_min = DIV_ROUND_UP(host->mclk, 512); 1476 mmc->f_min = DIV_ROUND_UP(host->mclk, 512);
1548 /* 1477 /*
1549 * If the platform data supplies a maximum operating 1478 * If no maximum operating frequency is supplied, fall back to use
1550 * frequency, this takes precedence. Else, we fall back 1479 * the module parameter, which has a (low) default value in case it
1551 * to using the module parameter, which has a (low) 1480 * is not specified. Either value must not exceed the clock rate into
1552 * default value in case it is not specified. Either 1481 * the block, of course.
1553 * value must not exceed the clock rate into the block,
1554 * of course.
1555 */ 1482 */
1556 if (plat->f_max) 1483 if (mmc->f_max)
1557 mmc->f_max = min(host->mclk, plat->f_max); 1484 mmc->f_max = min(host->mclk, mmc->f_max);
1558 else 1485 else
1559 mmc->f_max = min(host->mclk, fmax); 1486 mmc->f_max = min(host->mclk, fmax);
1560 dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max); 1487 dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max);
@@ -1566,8 +1493,15 @@ static int mmci_probe(struct amba_device *dev,
1566 else if (plat->ocr_mask) 1493 else if (plat->ocr_mask)
1567 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n"); 1494 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
1568 1495
1569 mmc->caps = plat->capabilities; 1496 /* DT takes precedence over platform data. */
1570 mmc->caps2 = plat->capabilities2; 1497 if (!np) {
1498 if (!plat->cd_invert)
1499 mmc->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
1500 mmc->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
1501 }
1502
1503 /* We support these capabilities. */
1504 mmc->caps |= MMC_CAP_CMD23;
1571 1505
1572 if (variant->busy_detect) { 1506 if (variant->busy_detect) {
1573 mmci_ops.card_busy = mmci_card_busy; 1507 mmci_ops.card_busy = mmci_card_busy;
@@ -1579,7 +1513,7 @@ static int mmci_probe(struct amba_device *dev,
1579 mmc->ops = &mmci_ops; 1513 mmc->ops = &mmci_ops;
1580 1514
1581 /* We support these PM capabilities. */ 1515 /* We support these PM capabilities. */
1582 mmc->pm_caps = MMC_PM_KEEP_POWER; 1516 mmc->pm_caps |= MMC_PM_KEEP_POWER;
1583 1517
1584 /* 1518 /*
1585 * We can do SGIO 1519 * We can do SGIO
@@ -1616,62 +1550,30 @@ static int mmci_probe(struct amba_device *dev,
1616 writel(0, host->base + MMCIMASK1); 1550 writel(0, host->base + MMCIMASK1);
1617 writel(0xfff, host->base + MMCICLEAR); 1551 writel(0xfff, host->base + MMCICLEAR);
1618 1552
1619 if (plat->gpio_cd == -EPROBE_DEFER) { 1553 /* If DT, cd/wp gpios must be supplied through it. */
1620 ret = -EPROBE_DEFER; 1554 if (!np && gpio_is_valid(plat->gpio_cd)) {
1621 goto err_gpio_cd; 1555 ret = mmc_gpio_request_cd(mmc, plat->gpio_cd, 0);
1622 } 1556 if (ret)
1623 if (gpio_is_valid(plat->gpio_cd)) { 1557 goto clk_disable;
1624 ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)");
1625 if (ret == 0)
1626 ret = gpio_direction_input(plat->gpio_cd);
1627 if (ret == 0)
1628 host->gpio_cd = plat->gpio_cd;
1629 else if (ret != -ENOSYS)
1630 goto err_gpio_cd;
1631
1632 /*
1633 * A gpio pin that will detect cards when inserted and removed
1634 * will most likely want to trigger on the edges if it is
1635 * 0 when ejected and 1 when inserted (or mutatis mutandis
1636 * for the inverted case) so we request triggers on both
1637 * edges.
1638 */
1639 ret = request_any_context_irq(gpio_to_irq(plat->gpio_cd),
1640 mmci_cd_irq,
1641 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
1642 DRIVER_NAME " (cd)", host);
1643 if (ret >= 0)
1644 host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd);
1645 }
1646 if (plat->gpio_wp == -EPROBE_DEFER) {
1647 ret = -EPROBE_DEFER;
1648 goto err_gpio_wp;
1649 } 1558 }
1650 if (gpio_is_valid(plat->gpio_wp)) { 1559 if (!np && gpio_is_valid(plat->gpio_wp)) {
1651 ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)"); 1560 ret = mmc_gpio_request_ro(mmc, plat->gpio_wp);
1652 if (ret == 0) 1561 if (ret)
1653 ret = gpio_direction_input(plat->gpio_wp); 1562 goto clk_disable;
1654 if (ret == 0)
1655 host->gpio_wp = plat->gpio_wp;
1656 else if (ret != -ENOSYS)
1657 goto err_gpio_wp;
1658 } 1563 }
1659 1564
1660 if ((host->plat->status || host->gpio_cd != -ENOSYS) 1565 ret = devm_request_irq(&dev->dev, dev->irq[0], mmci_irq, IRQF_SHARED,
1661 && host->gpio_cd_irq < 0) 1566 DRIVER_NAME " (cmd)", host);
1662 mmc->caps |= MMC_CAP_NEEDS_POLL;
1663
1664 ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host);
1665 if (ret) 1567 if (ret)
1666 goto unmap; 1568 goto clk_disable;
1667 1569
1668 if (!dev->irq[1]) 1570 if (!dev->irq[1])
1669 host->singleirq = true; 1571 host->singleirq = true;
1670 else { 1572 else {
1671 ret = request_irq(dev->irq[1], mmci_pio_irq, IRQF_SHARED, 1573 ret = devm_request_irq(&dev->dev, dev->irq[1], mmci_pio_irq,
1672 DRIVER_NAME " (pio)", host); 1574 IRQF_SHARED, DRIVER_NAME " (pio)", host);
1673 if (ret) 1575 if (ret)
1674 goto irq0_free; 1576 goto clk_disable;
1675 } 1577 }
1676 1578
1677 writel(MCI_IRQENABLE, host->base + MMCIMASK0); 1579 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
@@ -1693,25 +1595,10 @@ static int mmci_probe(struct amba_device *dev,
1693 1595
1694 return 0; 1596 return 0;
1695 1597
1696 irq0_free:
1697 free_irq(dev->irq[0], host);
1698 unmap:
1699 if (host->gpio_wp != -ENOSYS)
1700 gpio_free(host->gpio_wp);
1701 err_gpio_wp:
1702 if (host->gpio_cd_irq >= 0)
1703 free_irq(host->gpio_cd_irq, host);
1704 if (host->gpio_cd != -ENOSYS)
1705 gpio_free(host->gpio_cd);
1706 err_gpio_cd:
1707 iounmap(host->base);
1708 clk_disable: 1598 clk_disable:
1709 clk_disable_unprepare(host->clk); 1599 clk_disable_unprepare(host->clk);
1710 host_free: 1600 host_free:
1711 mmc_free_host(mmc); 1601 mmc_free_host(mmc);
1712 rel_regions:
1713 amba_release_regions(dev);
1714 out:
1715 return ret; 1602 return ret;
1716} 1603}
1717 1604
@@ -1737,92 +1624,46 @@ static int mmci_remove(struct amba_device *dev)
1737 writel(0, host->base + MMCIDATACTRL); 1624 writel(0, host->base + MMCIDATACTRL);
1738 1625
1739 mmci_dma_release(host); 1626 mmci_dma_release(host);
1740 free_irq(dev->irq[0], host);
1741 if (!host->singleirq)
1742 free_irq(dev->irq[1], host);
1743
1744 if (host->gpio_wp != -ENOSYS)
1745 gpio_free(host->gpio_wp);
1746 if (host->gpio_cd_irq >= 0)
1747 free_irq(host->gpio_cd_irq, host);
1748 if (host->gpio_cd != -ENOSYS)
1749 gpio_free(host->gpio_cd);
1750
1751 iounmap(host->base);
1752 clk_disable_unprepare(host->clk); 1627 clk_disable_unprepare(host->clk);
1753
1754 mmc_free_host(mmc); 1628 mmc_free_host(mmc);
1755
1756 amba_release_regions(dev);
1757 }
1758
1759 return 0;
1760}
1761
1762#ifdef CONFIG_SUSPEND
1763static int mmci_suspend(struct device *dev)
1764{
1765 struct amba_device *adev = to_amba_device(dev);
1766 struct mmc_host *mmc = amba_get_drvdata(adev);
1767
1768 if (mmc) {
1769 struct mmci_host *host = mmc_priv(mmc);
1770 pm_runtime_get_sync(dev);
1771 writel(0, host->base + MMCIMASK0);
1772 } 1629 }
1773 1630
1774 return 0; 1631 return 0;
1775} 1632}
1776 1633
1777static int mmci_resume(struct device *dev) 1634#ifdef CONFIG_PM
1778{
1779 struct amba_device *adev = to_amba_device(dev);
1780 struct mmc_host *mmc = amba_get_drvdata(adev);
1781
1782 if (mmc) {
1783 struct mmci_host *host = mmc_priv(mmc);
1784 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1785 pm_runtime_put(dev);
1786 }
1787
1788 return 0;
1789}
1790#endif
1791
1792#ifdef CONFIG_PM_RUNTIME
1793static void mmci_save(struct mmci_host *host) 1635static void mmci_save(struct mmci_host *host)
1794{ 1636{
1795 unsigned long flags; 1637 unsigned long flags;
1796 1638
1797 if (host->variant->pwrreg_nopower) { 1639 spin_lock_irqsave(&host->lock, flags);
1798 spin_lock_irqsave(&host->lock, flags);
1799 1640
1800 writel(0, host->base + MMCIMASK0); 1641 writel(0, host->base + MMCIMASK0);
1642 if (host->variant->pwrreg_nopower) {
1801 writel(0, host->base + MMCIDATACTRL); 1643 writel(0, host->base + MMCIDATACTRL);
1802 writel(0, host->base + MMCIPOWER); 1644 writel(0, host->base + MMCIPOWER);
1803 writel(0, host->base + MMCICLOCK); 1645 writel(0, host->base + MMCICLOCK);
1804 mmci_reg_delay(host);
1805
1806 spin_unlock_irqrestore(&host->lock, flags);
1807 } 1646 }
1647 mmci_reg_delay(host);
1808 1648
1649 spin_unlock_irqrestore(&host->lock, flags);
1809} 1650}
1810 1651
1811static void mmci_restore(struct mmci_host *host) 1652static void mmci_restore(struct mmci_host *host)
1812{ 1653{
1813 unsigned long flags; 1654 unsigned long flags;
1814 1655
1815 if (host->variant->pwrreg_nopower) { 1656 spin_lock_irqsave(&host->lock, flags);
1816 spin_lock_irqsave(&host->lock, flags);
1817 1657
1658 if (host->variant->pwrreg_nopower) {
1818 writel(host->clk_reg, host->base + MMCICLOCK); 1659 writel(host->clk_reg, host->base + MMCICLOCK);
1819 writel(host->datactrl_reg, host->base + MMCIDATACTRL); 1660 writel(host->datactrl_reg, host->base + MMCIDATACTRL);
1820 writel(host->pwr_reg, host->base + MMCIPOWER); 1661 writel(host->pwr_reg, host->base + MMCIPOWER);
1821 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1822 mmci_reg_delay(host);
1823
1824 spin_unlock_irqrestore(&host->lock, flags);
1825 } 1662 }
1663 writel(MCI_IRQENABLE, host->base + MMCIMASK0);
1664 mmci_reg_delay(host);
1665
1666 spin_unlock_irqrestore(&host->lock, flags);
1826} 1667}
1827 1668
1828static int mmci_runtime_suspend(struct device *dev) 1669static int mmci_runtime_suspend(struct device *dev)
@@ -1857,8 +1698,9 @@ static int mmci_runtime_resume(struct device *dev)
1857#endif 1698#endif
1858 1699
1859static const struct dev_pm_ops mmci_dev_pm_ops = { 1700static const struct dev_pm_ops mmci_dev_pm_ops = {
1860 SET_SYSTEM_SLEEP_PM_OPS(mmci_suspend, mmci_resume) 1701 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1861 SET_RUNTIME_PM_OPS(mmci_runtime_suspend, mmci_runtime_resume, NULL) 1702 pm_runtime_force_resume)
1703 SET_PM_RUNTIME_PM_OPS(mmci_runtime_suspend, mmci_runtime_resume, NULL)
1862}; 1704};
1863 1705
1864static struct amba_id mmci_ids[] = { 1706static struct amba_id mmci_ids[] = {