aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mmc/host')
-rw-r--r--drivers/mmc/host/atmel-mci-regs.h14
-rw-r--r--drivers/mmc/host/atmel-mci.c26
-rw-r--r--drivers/mmc/host/dw_mmc.c51
-rw-r--r--drivers/mmc/host/mmci.c19
-rw-r--r--drivers/mmc/host/mxs-mmc.c28
-rw-r--r--drivers/mmc/host/omap.c18
-rw-r--r--drivers/mmc/host/omap_hsmmc.c31
-rw-r--r--drivers/mmc/host/s3cmci.c10
-rw-r--r--drivers/mmc/host/sdhci-dove.c51
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c9
-rw-r--r--drivers/mmc/host/sdhci-pci.c1
-rw-r--r--drivers/mmc/host/sdhci-pxav2.c54
-rw-r--r--drivers/mmc/host/sdhci-pxav3.c52
-rw-r--r--drivers/mmc/host/sdhci-s3c.c2
-rw-r--r--drivers/mmc/host/sdhci-spear.c4
-rw-r--r--drivers/mmc/host/sdhci-tegra.c11
-rw-r--r--drivers/mmc/host/sdhci.c148
-rw-r--r--drivers/mmc/host/sdhci.h1
-rw-r--r--drivers/mmc/host/sh_mmcif.c185
-rw-r--r--drivers/mmc/host/sh_mobile_sdhi.c66
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c132
21 files changed, 657 insertions, 256 deletions
diff --git a/drivers/mmc/host/atmel-mci-regs.h b/drivers/mmc/host/atmel-mci-regs.h
index 787aba1682bb..ab56f7db5315 100644
--- a/drivers/mmc/host/atmel-mci-regs.h
+++ b/drivers/mmc/host/atmel-mci-regs.h
@@ -140,4 +140,18 @@
140#define atmci_writel(port,reg,value) \ 140#define atmci_writel(port,reg,value) \
141 __raw_writel((value), (port)->regs + reg) 141 __raw_writel((value), (port)->regs + reg)
142 142
143/*
144 * Fix sconfig's burst size according to atmel MCI. We need to convert them as:
145 * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
146 *
147 * This can be done by finding most significant bit set.
148 */
149static inline unsigned int atmci_convert_chksize(unsigned int maxburst)
150{
151 if (maxburst > 1)
152 return fls(maxburst) - 2;
153 else
154 return 0;
155}
156
143#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */ 157#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 420aca642b14..322412cec4ee 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -391,11 +391,17 @@ static int atmci_regs_show(struct seq_file *s, void *v)
391 clk_disable(host->mck); 391 clk_disable(host->mck);
392 spin_unlock_bh(&host->lock); 392 spin_unlock_bh(&host->lock);
393 393
394 seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u\n", 394 seq_printf(s, "MR:\t0x%08x%s%s ",
395 buf[ATMCI_MR / 4], 395 buf[ATMCI_MR / 4],
396 buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "", 396 buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "",
397 buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "", 397 buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "");
398 buf[ATMCI_MR / 4] & 0xff); 398 if (host->caps.has_odd_clk_div)
399 seq_printf(s, "{CLKDIV,CLKODD}=%u\n",
400 ((buf[ATMCI_MR / 4] & 0xff) << 1)
401 | ((buf[ATMCI_MR / 4] >> 16) & 1));
402 else
403 seq_printf(s, "CLKDIV=%u\n",
404 (buf[ATMCI_MR / 4] & 0xff));
399 seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]); 405 seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]);
400 seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]); 406 seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]);
401 seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]); 407 seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]);
@@ -910,6 +916,7 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
910 enum dma_data_direction direction; 916 enum dma_data_direction direction;
911 enum dma_transfer_direction slave_dirn; 917 enum dma_transfer_direction slave_dirn;
912 unsigned int sglen; 918 unsigned int sglen;
919 u32 maxburst;
913 u32 iflags; 920 u32 iflags;
914 921
915 data->error = -EINPROGRESS; 922 data->error = -EINPROGRESS;
@@ -943,17 +950,18 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
943 if (!chan) 950 if (!chan)
944 return -ENODEV; 951 return -ENODEV;
945 952
946 if (host->caps.has_dma)
947 atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(3) | ATMCI_DMAEN);
948
949 if (data->flags & MMC_DATA_READ) { 953 if (data->flags & MMC_DATA_READ) {
950 direction = DMA_FROM_DEVICE; 954 direction = DMA_FROM_DEVICE;
951 host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM; 955 host->dma_conf.direction = slave_dirn = DMA_DEV_TO_MEM;
956 maxburst = atmci_convert_chksize(host->dma_conf.src_maxburst);
952 } else { 957 } else {
953 direction = DMA_TO_DEVICE; 958 direction = DMA_TO_DEVICE;
954 host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV; 959 host->dma_conf.direction = slave_dirn = DMA_MEM_TO_DEV;
960 maxburst = atmci_convert_chksize(host->dma_conf.dst_maxburst);
955 } 961 }
956 962
963 atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(maxburst) | ATMCI_DMAEN);
964
957 sglen = dma_map_sg(chan->device->dev, data->sg, 965 sglen = dma_map_sg(chan->device->dev, data->sg,
958 data->sg_len, direction); 966 data->sg_len, direction);
959 967
@@ -1683,7 +1691,6 @@ static void atmci_tasklet_func(unsigned long priv)
1683 1691
1684 dev_dbg(&host->pdev->dev, "FSM: cmd ready\n"); 1692 dev_dbg(&host->pdev->dev, "FSM: cmd ready\n");
1685 host->cmd = NULL; 1693 host->cmd = NULL;
1686 host->data = NULL;
1687 data->bytes_xfered = data->blocks * data->blksz; 1694 data->bytes_xfered = data->blocks * data->blksz;
1688 data->error = 0; 1695 data->error = 0;
1689 atmci_command_complete(host, mrq->stop); 1696 atmci_command_complete(host, mrq->stop);
@@ -1697,6 +1704,7 @@ static void atmci_tasklet_func(unsigned long priv)
1697 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); 1704 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
1698 state = STATE_WAITING_NOTBUSY; 1705 state = STATE_WAITING_NOTBUSY;
1699 } 1706 }
1707 host->data = NULL;
1700 break; 1708 break;
1701 1709
1702 case STATE_END_REQUEST: 1710 case STATE_END_REQUEST:
@@ -2314,6 +2322,8 @@ static int __init atmci_probe(struct platform_device *pdev)
2314 2322
2315 platform_set_drvdata(pdev, host); 2323 platform_set_drvdata(pdev, host);
2316 2324
2325 setup_timer(&host->timer, atmci_timeout_timer, (unsigned long)host);
2326
2317 /* We need at least one slot to succeed */ 2327 /* We need at least one slot to succeed */
2318 nr_slots = 0; 2328 nr_slots = 0;
2319 ret = -ENODEV; 2329 ret = -ENODEV;
@@ -2352,8 +2362,6 @@ static int __init atmci_probe(struct platform_device *pdev)
2352 } 2362 }
2353 } 2363 }
2354 2364
2355 setup_timer(&host->timer, atmci_timeout_timer, (unsigned long)host);
2356
2357 dev_info(&pdev->dev, 2365 dev_info(&pdev->dev,
2358 "Atmel MCI controller at 0x%08lx irq %d, %u slots\n", 2366 "Atmel MCI controller at 0x%08lx irq %d, %u slots\n",
2359 host->mapbase, irq, nr_slots); 2367 host->mapbase, irq, nr_slots);
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 9bbf45f8c538..72dc3cde646d 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -405,11 +405,23 @@ static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
405static int dw_mci_idmac_init(struct dw_mci *host) 405static int dw_mci_idmac_init(struct dw_mci *host)
406{ 406{
407 struct idmac_desc *p; 407 struct idmac_desc *p;
408 int i; 408 int i, dma_support;
409 409
410 /* Number of descriptors in the ring buffer */ 410 /* Number of descriptors in the ring buffer */
411 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); 411 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
412 412
413 /* Check if Hardware Configuration Register has support for DMA */
414 dma_support = (mci_readl(host, HCON) >> 16) & 0x3;
415
416 if (!dma_support || dma_support > 2) {
417 dev_err(&host->dev,
418 "Host Controller does not support IDMA Tx.\n");
419 host->dma_ops = NULL;
420 return -ENODEV;
421 }
422
423 dev_info(&host->dev, "Using internal DMA controller.\n");
424
413 /* Forward link the descriptor list */ 425 /* Forward link the descriptor list */
414 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) 426 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
415 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1)); 427 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1));
@@ -418,6 +430,8 @@ static int dw_mci_idmac_init(struct dw_mci *host)
418 p->des3 = host->sg_dma; 430 p->des3 = host->sg_dma;
419 p->des0 = IDMAC_DES0_ER; 431 p->des0 = IDMAC_DES0_ER;
420 432
433 mci_writel(host, BMOD, SDMMC_IDMAC_SWRESET);
434
421 /* Mask out interrupts - get Tx & Rx complete only */ 435 /* Mask out interrupts - get Tx & Rx complete only */
422 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI | 436 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI |
423 SDMMC_IDMAC_INT_TI); 437 SDMMC_IDMAC_INT_TI);
@@ -615,14 +629,15 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot)
615 u32 div; 629 u32 div;
616 630
617 if (slot->clock != host->current_speed) { 631 if (slot->clock != host->current_speed) {
618 if (host->bus_hz % slot->clock) 632 div = host->bus_hz / slot->clock;
633 if (host->bus_hz % slot->clock && host->bus_hz > slot->clock)
619 /* 634 /*
620 * move the + 1 after the divide to prevent 635 * move the + 1 after the divide to prevent
621 * over-clocking the card. 636 * over-clocking the card.
622 */ 637 */
623 div = ((host->bus_hz / slot->clock) >> 1) + 1; 638 div += 1;
624 else 639
625 div = (host->bus_hz / slot->clock) >> 1; 640 div = (host->bus_hz != slot->clock) ? DIV_ROUND_UP(div, 2) : 0;
626 641
627 dev_info(&slot->mmc->class_dev, 642 dev_info(&slot->mmc->class_dev,
628 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ" 643 "Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ"
@@ -939,8 +954,8 @@ static void dw_mci_command_complete(struct dw_mci *host, struct mmc_command *cmd
939 mdelay(20); 954 mdelay(20);
940 955
941 if (cmd->data) { 956 if (cmd->data) {
942 host->data = NULL;
943 dw_mci_stop_dma(host); 957 dw_mci_stop_dma(host);
958 host->data = NULL;
944 } 959 }
945 } 960 }
946} 961}
@@ -1623,7 +1638,6 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
1623 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) { 1638 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
1624 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI); 1639 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI);
1625 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); 1640 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
1626 set_bit(EVENT_DATA_COMPLETE, &host->pending_events);
1627 host->dma_ops->complete(host); 1641 host->dma_ops->complete(host);
1628 } 1642 }
1629#endif 1643#endif
@@ -1725,7 +1739,8 @@ static void dw_mci_work_routine_card(struct work_struct *work)
1725 1739
1726#ifdef CONFIG_MMC_DW_IDMAC 1740#ifdef CONFIG_MMC_DW_IDMAC
1727 ctrl = mci_readl(host, BMOD); 1741 ctrl = mci_readl(host, BMOD);
1728 ctrl |= 0x01; /* Software reset of DMA */ 1742 /* Software reset of DMA */
1743 ctrl |= SDMMC_IDMAC_SWRESET;
1729 mci_writel(host, BMOD, ctrl); 1744 mci_writel(host, BMOD, ctrl);
1730#endif 1745#endif
1731 1746
@@ -1873,7 +1888,6 @@ static void dw_mci_init_dma(struct dw_mci *host)
1873 /* Determine which DMA interface to use */ 1888 /* Determine which DMA interface to use */
1874#ifdef CONFIG_MMC_DW_IDMAC 1889#ifdef CONFIG_MMC_DW_IDMAC
1875 host->dma_ops = &dw_mci_idmac_ops; 1890 host->dma_ops = &dw_mci_idmac_ops;
1876 dev_info(&host->dev, "Using internal DMA controller.\n");
1877#endif 1891#endif
1878 1892
1879 if (!host->dma_ops) 1893 if (!host->dma_ops)
@@ -1950,10 +1964,6 @@ int dw_mci_probe(struct dw_mci *host)
1950 spin_lock_init(&host->lock); 1964 spin_lock_init(&host->lock);
1951 INIT_LIST_HEAD(&host->queue); 1965 INIT_LIST_HEAD(&host->queue);
1952 1966
1953
1954 host->dma_ops = host->pdata->dma_ops;
1955 dw_mci_init_dma(host);
1956
1957 /* 1967 /*
1958 * Get the host data width - this assumes that HCON has been set with 1968 * Get the host data width - this assumes that HCON has been set with
1959 * the correct values. 1969 * the correct values.
@@ -1981,10 +1991,11 @@ int dw_mci_probe(struct dw_mci *host)
1981 } 1991 }
1982 1992
1983 /* Reset all blocks */ 1993 /* Reset all blocks */
1984 if (!mci_wait_reset(&host->dev, host)) { 1994 if (!mci_wait_reset(&host->dev, host))
1985 ret = -ENODEV; 1995 return -ENODEV;
1986 goto err_dmaunmap; 1996
1987 } 1997 host->dma_ops = host->pdata->dma_ops;
1998 dw_mci_init_dma(host);
1988 1999
1989 /* Clear the interrupts for the host controller */ 2000 /* Clear the interrupts for the host controller */
1990 mci_writel(host, RINTSTS, 0xFFFFFFFF); 2001 mci_writel(host, RINTSTS, 0xFFFFFFFF);
@@ -2170,14 +2181,14 @@ int dw_mci_resume(struct dw_mci *host)
2170 if (host->vmmc) 2181 if (host->vmmc)
2171 regulator_enable(host->vmmc); 2182 regulator_enable(host->vmmc);
2172 2183
2173 if (host->dma_ops->init)
2174 host->dma_ops->init(host);
2175
2176 if (!mci_wait_reset(&host->dev, host)) { 2184 if (!mci_wait_reset(&host->dev, host)) {
2177 ret = -ENODEV; 2185 ret = -ENODEV;
2178 return ret; 2186 return ret;
2179 } 2187 }
2180 2188
2189 if (host->use_dma && host->dma_ops->init)
2190 host->dma_ops->init(host);
2191
2181 /* Restore the old value at FIFOTH register */ 2192 /* Restore the old value at FIFOTH register */
2182 mci_writel(host, FIFOTH, host->fifoth_val); 2193 mci_writel(host, FIFOTH, host->fifoth_val);
2183 2194
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index f0fcce40cd8d..50ff19a62368 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -1216,12 +1216,7 @@ static void mmci_dt_populate_generic_pdata(struct device_node *np,
1216 int bus_width = 0; 1216 int bus_width = 0;
1217 1217
1218 pdata->gpio_wp = of_get_named_gpio(np, "wp-gpios", 0); 1218 pdata->gpio_wp = of_get_named_gpio(np, "wp-gpios", 0);
1219 if (!pdata->gpio_wp)
1220 pdata->gpio_wp = -1;
1221
1222 pdata->gpio_cd = of_get_named_gpio(np, "cd-gpios", 0); 1219 pdata->gpio_cd = of_get_named_gpio(np, "cd-gpios", 0);
1223 if (!pdata->gpio_cd)
1224 pdata->gpio_cd = -1;
1225 1220
1226 if (of_get_property(np, "cd-inverted", NULL)) 1221 if (of_get_property(np, "cd-inverted", NULL))
1227 pdata->cd_invert = true; 1222 pdata->cd_invert = true;
@@ -1276,6 +1271,12 @@ static int __devinit mmci_probe(struct amba_device *dev,
1276 return -EINVAL; 1271 return -EINVAL;
1277 } 1272 }
1278 1273
1274 if (!plat) {
1275 plat = devm_kzalloc(&dev->dev, sizeof(*plat), GFP_KERNEL);
1276 if (!plat)
1277 return -ENOMEM;
1278 }
1279
1279 if (np) 1280 if (np)
1280 mmci_dt_populate_generic_pdata(np, plat); 1281 mmci_dt_populate_generic_pdata(np, plat);
1281 1282
@@ -1424,6 +1425,10 @@ static int __devinit mmci_probe(struct amba_device *dev,
1424 writel(0, host->base + MMCIMASK1); 1425 writel(0, host->base + MMCIMASK1);
1425 writel(0xfff, host->base + MMCICLEAR); 1426 writel(0xfff, host->base + MMCICLEAR);
1426 1427
1428 if (plat->gpio_cd == -EPROBE_DEFER) {
1429 ret = -EPROBE_DEFER;
1430 goto err_gpio_cd;
1431 }
1427 if (gpio_is_valid(plat->gpio_cd)) { 1432 if (gpio_is_valid(plat->gpio_cd)) {
1428 ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)"); 1433 ret = gpio_request(plat->gpio_cd, DRIVER_NAME " (cd)");
1429 if (ret == 0) 1434 if (ret == 0)
@@ -1447,6 +1452,10 @@ static int __devinit mmci_probe(struct amba_device *dev,
1447 if (ret >= 0) 1452 if (ret >= 0)
1448 host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd); 1453 host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd);
1449 } 1454 }
1455 if (plat->gpio_wp == -EPROBE_DEFER) {
1456 ret = -EPROBE_DEFER;
1457 goto err_gpio_wp;
1458 }
1450 if (gpio_is_valid(plat->gpio_wp)) { 1459 if (gpio_is_valid(plat->gpio_wp)) {
1451 ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)"); 1460 ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)");
1452 if (ret == 0) 1461 if (ret == 0)
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index 34a90266ab11..a51f9309ffbb 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -164,16 +164,23 @@ struct mxs_mmc_host {
164 spinlock_t lock; 164 spinlock_t lock;
165 int sdio_irq_en; 165 int sdio_irq_en;
166 int wp_gpio; 166 int wp_gpio;
167 bool wp_inverted;
167}; 168};
168 169
169static int mxs_mmc_get_ro(struct mmc_host *mmc) 170static int mxs_mmc_get_ro(struct mmc_host *mmc)
170{ 171{
171 struct mxs_mmc_host *host = mmc_priv(mmc); 172 struct mxs_mmc_host *host = mmc_priv(mmc);
173 int ret;
172 174
173 if (!gpio_is_valid(host->wp_gpio)) 175 if (!gpio_is_valid(host->wp_gpio))
174 return -EINVAL; 176 return -EINVAL;
175 177
176 return gpio_get_value(host->wp_gpio); 178 ret = gpio_get_value(host->wp_gpio);
179
180 if (host->wp_inverted)
181 ret = !ret;
182
183 return ret;
177} 184}
178 185
179static int mxs_mmc_get_cd(struct mmc_host *mmc) 186static int mxs_mmc_get_cd(struct mmc_host *mmc)
@@ -707,6 +714,8 @@ static int mxs_mmc_probe(struct platform_device *pdev)
707 struct pinctrl *pinctrl; 714 struct pinctrl *pinctrl;
708 int ret = 0, irq_err, irq_dma; 715 int ret = 0, irq_err, irq_dma;
709 dma_cap_mask_t mask; 716 dma_cap_mask_t mask;
717 struct regulator *reg_vmmc;
718 enum of_gpio_flags flags;
710 719
711 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 720 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
712 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); 721 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
@@ -747,6 +756,16 @@ static int mxs_mmc_probe(struct platform_device *pdev)
747 host->mmc = mmc; 756 host->mmc = mmc;
748 host->sdio_irq_en = 0; 757 host->sdio_irq_en = 0;
749 758
759 reg_vmmc = devm_regulator_get(&pdev->dev, "vmmc");
760 if (!IS_ERR(reg_vmmc)) {
761 ret = regulator_enable(reg_vmmc);
762 if (ret) {
763 dev_err(&pdev->dev,
764 "Failed to enable vmmc regulator: %d\n", ret);
765 goto out_mmc_free;
766 }
767 }
768
750 pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 769 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
751 if (IS_ERR(pinctrl)) { 770 if (IS_ERR(pinctrl)) {
752 ret = PTR_ERR(pinctrl); 771 ret = PTR_ERR(pinctrl);
@@ -785,7 +804,10 @@ static int mxs_mmc_probe(struct platform_device *pdev)
785 mmc->caps |= MMC_CAP_4_BIT_DATA; 804 mmc->caps |= MMC_CAP_4_BIT_DATA;
786 else if (bus_width == 8) 805 else if (bus_width == 8)
787 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; 806 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA;
788 host->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); 807 host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0,
808 &flags);
809 if (flags & OF_GPIO_ACTIVE_LOW)
810 host->wp_inverted = 1;
789 } else { 811 } else {
790 if (pdata->flags & SLOTF_8_BIT_CAPABLE) 812 if (pdata->flags & SLOTF_8_BIT_CAPABLE)
791 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; 813 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA;
@@ -894,8 +916,8 @@ static struct platform_driver mxs_mmc_driver = {
894 .owner = THIS_MODULE, 916 .owner = THIS_MODULE,
895#ifdef CONFIG_PM 917#ifdef CONFIG_PM
896 .pm = &mxs_mmc_pm_ops, 918 .pm = &mxs_mmc_pm_ops,
897 .of_match_table = mxs_mmc_dt_ids,
898#endif 919#endif
920 .of_match_table = mxs_mmc_dt_ids,
899 }, 921 },
900}; 922};
901 923
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 552196c764d4..3e8dcf8d2e05 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -1300,7 +1300,7 @@ static const struct mmc_host_ops mmc_omap_ops = {
1300 .set_ios = mmc_omap_set_ios, 1300 .set_ios = mmc_omap_set_ios,
1301}; 1301};
1302 1302
1303static int __init mmc_omap_new_slot(struct mmc_omap_host *host, int id) 1303static int __devinit mmc_omap_new_slot(struct mmc_omap_host *host, int id)
1304{ 1304{
1305 struct mmc_omap_slot *slot = NULL; 1305 struct mmc_omap_slot *slot = NULL;
1306 struct mmc_host *mmc; 1306 struct mmc_host *mmc;
@@ -1485,24 +1485,26 @@ static int __devinit mmc_omap_probe(struct platform_device *pdev)
1485 } 1485 }
1486 1486
1487 host->nr_slots = pdata->nr_slots; 1487 host->nr_slots = pdata->nr_slots;
1488 host->reg_shift = (cpu_is_omap7xx() ? 1 : 2);
1489
1490 host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0);
1491 if (!host->mmc_omap_wq)
1492 goto err_plat_cleanup;
1493
1488 for (i = 0; i < pdata->nr_slots; i++) { 1494 for (i = 0; i < pdata->nr_slots; i++) {
1489 ret = mmc_omap_new_slot(host, i); 1495 ret = mmc_omap_new_slot(host, i);
1490 if (ret < 0) { 1496 if (ret < 0) {
1491 while (--i >= 0) 1497 while (--i >= 0)
1492 mmc_omap_remove_slot(host->slots[i]); 1498 mmc_omap_remove_slot(host->slots[i]);
1493 1499
1494 goto err_plat_cleanup; 1500 goto err_destroy_wq;
1495 } 1501 }
1496 } 1502 }
1497 1503
1498 host->reg_shift = (cpu_is_omap7xx() ? 1 : 2);
1499
1500 host->mmc_omap_wq = alloc_workqueue("mmc_omap", 0, 0);
1501 if (!host->mmc_omap_wq)
1502 goto err_plat_cleanup;
1503
1504 return 0; 1504 return 0;
1505 1505
1506err_destroy_wq:
1507 destroy_workqueue(host->mmc_omap_wq);
1506err_plat_cleanup: 1508err_plat_cleanup:
1507 if (pdata->cleanup) 1509 if (pdata->cleanup)
1508 pdata->cleanup(&pdev->dev); 1510 pdata->cleanup(&pdev->dev);
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 9a7a60aeb19e..bc28627af66b 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -85,7 +85,6 @@
85#define BRR_ENABLE (1 << 5) 85#define BRR_ENABLE (1 << 5)
86#define DTO_ENABLE (1 << 20) 86#define DTO_ENABLE (1 << 20)
87#define INIT_STREAM (1 << 1) 87#define INIT_STREAM (1 << 1)
88#define ACEN_ACMD12 (1 << 2)
89#define DP_SELECT (1 << 21) 88#define DP_SELECT (1 << 21)
90#define DDIR (1 << 4) 89#define DDIR (1 << 4)
91#define DMA_EN 0x1 90#define DMA_EN 0x1
@@ -117,7 +116,6 @@
117#define OMAP_MMC_MAX_CLOCK 52000000 116#define OMAP_MMC_MAX_CLOCK 52000000
118#define DRIVER_NAME "omap_hsmmc" 117#define DRIVER_NAME "omap_hsmmc"
119 118
120#define AUTO_CMD12 (1 << 0) /* Auto CMD12 support */
121/* 119/*
122 * One controller can have multiple slots, like on some omap boards using 120 * One controller can have multiple slots, like on some omap boards using
123 * omap.c controller driver. Luckily this is not currently done on any known 121 * omap.c controller driver. Luckily this is not currently done on any known
@@ -177,7 +175,6 @@ struct omap_hsmmc_host {
177 int reqs_blocked; 175 int reqs_blocked;
178 int use_reg; 176 int use_reg;
179 int req_in_progress; 177 int req_in_progress;
180 unsigned int flags;
181 struct omap_hsmmc_next next_data; 178 struct omap_hsmmc_next next_data;
182 179
183 struct omap_mmc_platform_data *pdata; 180 struct omap_mmc_platform_data *pdata;
@@ -773,8 +770,6 @@ omap_hsmmc_start_command(struct omap_hsmmc_host *host, struct mmc_command *cmd,
773 cmdtype = 0x3; 770 cmdtype = 0x3;
774 771
775 cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22); 772 cmdreg = (cmd->opcode << 24) | (resptype << 16) | (cmdtype << 22);
776 if ((host->flags & AUTO_CMD12) && mmc_op_multi(cmd->opcode))
777 cmdreg |= ACEN_ACMD12;
778 773
779 if (data) { 774 if (data) {
780 cmdreg |= DP_SELECT | MSBS | BCE; 775 cmdreg |= DP_SELECT | MSBS | BCE;
@@ -847,14 +842,11 @@ omap_hsmmc_xfer_done(struct omap_hsmmc_host *host, struct mmc_data *data)
847 else 842 else
848 data->bytes_xfered = 0; 843 data->bytes_xfered = 0;
849 844
850 if (data->stop && ((!(host->flags & AUTO_CMD12)) || data->error)) { 845 if (!data->stop) {
851 omap_hsmmc_start_command(host, data->stop, NULL);
852 } else {
853 if (data->stop)
854 data->stop->resp[0] = OMAP_HSMMC_READ(host->base,
855 RSP76);
856 omap_hsmmc_request_done(host, data->mrq); 846 omap_hsmmc_request_done(host, data->mrq);
847 return;
857 } 848 }
849 omap_hsmmc_start_command(host, data->stop, NULL);
858} 850}
859 851
860/* 852/*
@@ -1097,7 +1089,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
1097 /* Disable the clocks */ 1089 /* Disable the clocks */
1098 pm_runtime_put_sync(host->dev); 1090 pm_runtime_put_sync(host->dev);
1099 if (host->dbclk) 1091 if (host->dbclk)
1100 clk_disable(host->dbclk); 1092 clk_disable_unprepare(host->dbclk);
1101 1093
1102 /* Turn the power off */ 1094 /* Turn the power off */
1103 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); 1095 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
@@ -1108,7 +1100,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
1108 vdd); 1100 vdd);
1109 pm_runtime_get_sync(host->dev); 1101 pm_runtime_get_sync(host->dev);
1110 if (host->dbclk) 1102 if (host->dbclk)
1111 clk_enable(host->dbclk); 1103 clk_prepare_enable(host->dbclk);
1112 1104
1113 if (ret != 0) 1105 if (ret != 0)
1114 goto err; 1106 goto err;
@@ -1859,7 +1851,6 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1859 host->mapbase = res->start + pdata->reg_offset; 1851 host->mapbase = res->start + pdata->reg_offset;
1860 host->base = ioremap(host->mapbase, SZ_4K); 1852 host->base = ioremap(host->mapbase, SZ_4K);
1861 host->power_mode = MMC_POWER_OFF; 1853 host->power_mode = MMC_POWER_OFF;
1862 host->flags = AUTO_CMD12;
1863 host->next_data.cookie = 1; 1854 host->next_data.cookie = 1;
1864 1855
1865 platform_set_drvdata(pdev, host); 1856 platform_set_drvdata(pdev, host);
@@ -1908,7 +1899,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1908 if (IS_ERR(host->dbclk)) { 1899 if (IS_ERR(host->dbclk)) {
1909 dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n"); 1900 dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n");
1910 host->dbclk = NULL; 1901 host->dbclk = NULL;
1911 } else if (clk_enable(host->dbclk) != 0) { 1902 } else if (clk_prepare_enable(host->dbclk) != 0) {
1912 dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); 1903 dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n");
1913 clk_put(host->dbclk); 1904 clk_put(host->dbclk);
1914 host->dbclk = NULL; 1905 host->dbclk = NULL;
@@ -1940,6 +1931,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1940 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); 1931 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1941 if (!res) { 1932 if (!res) {
1942 dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); 1933 dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n");
1934 ret = -ENXIO;
1943 goto err_irq; 1935 goto err_irq;
1944 } 1936 }
1945 host->dma_line_tx = res->start; 1937 host->dma_line_tx = res->start;
@@ -1947,6 +1939,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1947 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); 1939 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1948 if (!res) { 1940 if (!res) {
1949 dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); 1941 dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n");
1942 ret = -ENXIO;
1950 goto err_irq; 1943 goto err_irq;
1951 } 1944 }
1952 host->dma_line_rx = res->start; 1945 host->dma_line_rx = res->start;
@@ -2032,7 +2025,7 @@ err_irq:
2032 pm_runtime_disable(host->dev); 2025 pm_runtime_disable(host->dev);
2033 clk_put(host->fclk); 2026 clk_put(host->fclk);
2034 if (host->dbclk) { 2027 if (host->dbclk) {
2035 clk_disable(host->dbclk); 2028 clk_disable_unprepare(host->dbclk);
2036 clk_put(host->dbclk); 2029 clk_put(host->dbclk);
2037 } 2030 }
2038err1: 2031err1:
@@ -2067,7 +2060,7 @@ static int __devexit omap_hsmmc_remove(struct platform_device *pdev)
2067 pm_runtime_disable(host->dev); 2060 pm_runtime_disable(host->dev);
2068 clk_put(host->fclk); 2061 clk_put(host->fclk);
2069 if (host->dbclk) { 2062 if (host->dbclk) {
2070 clk_disable(host->dbclk); 2063 clk_disable_unprepare(host->dbclk);
2071 clk_put(host->dbclk); 2064 clk_put(host->dbclk);
2072 } 2065 }
2073 2066
@@ -2125,7 +2118,7 @@ static int omap_hsmmc_suspend(struct device *dev)
2125 } 2118 }
2126 2119
2127 if (host->dbclk) 2120 if (host->dbclk)
2128 clk_disable(host->dbclk); 2121 clk_disable_unprepare(host->dbclk);
2129err: 2122err:
2130 pm_runtime_put_sync(host->dev); 2123 pm_runtime_put_sync(host->dev);
2131 return ret; 2124 return ret;
@@ -2146,7 +2139,7 @@ static int omap_hsmmc_resume(struct device *dev)
2146 pm_runtime_get_sync(host->dev); 2139 pm_runtime_get_sync(host->dev);
2147 2140
2148 if (host->dbclk) 2141 if (host->dbclk)
2149 clk_enable(host->dbclk); 2142 clk_prepare_enable(host->dbclk);
2150 2143
2151 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) 2144 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
2152 omap_hsmmc_conf_bus_power(host); 2145 omap_hsmmc_conf_bus_power(host);
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index c3622a69f432..bd5a5cce122c 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -26,7 +26,6 @@
26#include <mach/dma.h> 26#include <mach/dma.h>
27 27
28#include <mach/regs-sdi.h> 28#include <mach/regs-sdi.h>
29#include <mach/regs-gpio.h>
30 29
31#include <plat/mci.h> 30#include <plat/mci.h>
32 31
@@ -1237,12 +1236,9 @@ static void s3cmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1237 switch (ios->power_mode) { 1236 switch (ios->power_mode) {
1238 case MMC_POWER_ON: 1237 case MMC_POWER_ON:
1239 case MMC_POWER_UP: 1238 case MMC_POWER_UP:
1240 s3c2410_gpio_cfgpin(S3C2410_GPE(5), S3C2410_GPE5_SDCLK); 1239 /* Configure GPE5...GPE10 pins in SD mode */
1241 s3c2410_gpio_cfgpin(S3C2410_GPE(6), S3C2410_GPE6_SDCMD); 1240 s3c_gpio_cfgall_range(S3C2410_GPE(5), 6, S3C_GPIO_SFN(2),
1242 s3c2410_gpio_cfgpin(S3C2410_GPE(7), S3C2410_GPE7_SDDAT0); 1241 S3C_GPIO_PULL_NONE);
1243 s3c2410_gpio_cfgpin(S3C2410_GPE(8), S3C2410_GPE8_SDDAT1);
1244 s3c2410_gpio_cfgpin(S3C2410_GPE(9), S3C2410_GPE9_SDDAT2);
1245 s3c2410_gpio_cfgpin(S3C2410_GPE(10), S3C2410_GPE10_SDDAT3);
1246 1242
1247 if (host->pdata->set_power) 1243 if (host->pdata->set_power)
1248 host->pdata->set_power(ios->power_mode, ios->vdd); 1244 host->pdata->set_power(ios->power_mode, ios->vdd);
diff --git a/drivers/mmc/host/sdhci-dove.c b/drivers/mmc/host/sdhci-dove.c
index 177f697b5835..a6e53a1ebb08 100644
--- a/drivers/mmc/host/sdhci-dove.c
+++ b/drivers/mmc/host/sdhci-dove.c
@@ -20,11 +20,17 @@
20 */ 20 */
21 21
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/clk.h>
24#include <linux/err.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/mmc/host.h> 26#include <linux/mmc/host.h>
25 27
26#include "sdhci-pltfm.h" 28#include "sdhci-pltfm.h"
27 29
30struct sdhci_dove_priv {
31 struct clk *clk;
32};
33
28static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) 34static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
29{ 35{
30 u16 ret; 36 u16 ret;
@@ -66,16 +72,57 @@ static struct sdhci_pltfm_data sdhci_dove_pdata = {
66 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | 72 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
67 SDHCI_QUIRK_NO_BUSY_IRQ | 73 SDHCI_QUIRK_NO_BUSY_IRQ |
68 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | 74 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
69 SDHCI_QUIRK_FORCE_DMA, 75 SDHCI_QUIRK_FORCE_DMA |
76 SDHCI_QUIRK_NO_HISPD_BIT,
70}; 77};
71 78
72static int __devinit sdhci_dove_probe(struct platform_device *pdev) 79static int __devinit sdhci_dove_probe(struct platform_device *pdev)
73{ 80{
74 return sdhci_pltfm_register(pdev, &sdhci_dove_pdata); 81 struct sdhci_host *host;
82 struct sdhci_pltfm_host *pltfm_host;
83 struct sdhci_dove_priv *priv;
84 int ret;
85
86 ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
87 if (ret)
88 goto sdhci_dove_register_fail;
89
90 priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
91 GFP_KERNEL);
92 if (!priv) {
93 dev_err(&pdev->dev, "unable to allocate private data");
94 ret = -ENOMEM;
95 goto sdhci_dove_allocate_fail;
96 }
97
98 host = platform_get_drvdata(pdev);
99 pltfm_host = sdhci_priv(host);
100 pltfm_host->priv = priv;
101
102 priv->clk = clk_get(&pdev->dev, NULL);
103 if (!IS_ERR(priv->clk))
104 clk_prepare_enable(priv->clk);
105 return 0;
106
107sdhci_dove_allocate_fail:
108 sdhci_pltfm_unregister(pdev);
109sdhci_dove_register_fail:
110 return ret;
75} 111}
76 112
77static int __devexit sdhci_dove_remove(struct platform_device *pdev) 113static int __devexit sdhci_dove_remove(struct platform_device *pdev)
78{ 114{
115 struct sdhci_host *host = platform_get_drvdata(pdev);
116 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
117 struct sdhci_dove_priv *priv = pltfm_host->priv;
118
119 if (priv->clk) {
120 if (!IS_ERR(priv->clk)) {
121 clk_disable_unprepare(priv->clk);
122 clk_put(priv->clk);
123 }
124 devm_kfree(&pdev->dev, priv->clk);
125 }
79 return sdhci_pltfm_unregister(pdev); 126 return sdhci_pltfm_unregister(pdev);
80} 127}
81 128
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index ebbe984e5d00..e23f8134591c 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -299,6 +299,8 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
299 299
300static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) 300static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
301{ 301{
302 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
303 struct pltfm_imx_data *imx_data = pltfm_host->priv;
302 u32 new_val; 304 u32 new_val;
303 305
304 switch (reg) { 306 switch (reg) {
@@ -315,8 +317,11 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
315 SDHCI_CTRL_D3CD); 317 SDHCI_CTRL_D3CD);
316 /* ensure the endianess */ 318 /* ensure the endianess */
317 new_val |= ESDHC_HOST_CONTROL_LE; 319 new_val |= ESDHC_HOST_CONTROL_LE;
318 /* DMA mode bits are shifted */ 320 /* bits 8&9 are reserved on mx25 */
319 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5; 321 if (!is_imx25_esdhc(imx_data)) {
322 /* DMA mode bits are shifted */
323 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
324 }
320 325
321 esdhc_clrset_le(host, 0xffff, new_val, reg); 326 esdhc_clrset_le(host, 0xffff, new_val, reg);
322 return; 327 return;
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 69ef0beae104..504da715a41a 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -157,6 +157,7 @@ static const struct sdhci_pci_fixes sdhci_ene_714 = {
157static const struct sdhci_pci_fixes sdhci_cafe = { 157static const struct sdhci_pci_fixes sdhci_cafe = {
158 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | 158 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
159 SDHCI_QUIRK_NO_BUSY_IRQ | 159 SDHCI_QUIRK_NO_BUSY_IRQ |
160 SDHCI_QUIRK_BROKEN_CARD_DETECTION |
160 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, 161 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
161}; 162};
162 163
diff --git a/drivers/mmc/host/sdhci-pxav2.c b/drivers/mmc/host/sdhci-pxav2.c
index dbb75bfbcffb..b6ee8857e226 100644
--- a/drivers/mmc/host/sdhci-pxav2.c
+++ b/drivers/mmc/host/sdhci-pxav2.c
@@ -28,6 +28,9 @@
28#include <linux/mmc/host.h> 28#include <linux/mmc/host.h>
29#include <linux/platform_data/pxa_sdhci.h> 29#include <linux/platform_data/pxa_sdhci.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/of.h>
32#include <linux/of_device.h>
33
31#include "sdhci.h" 34#include "sdhci.h"
32#include "sdhci-pltfm.h" 35#include "sdhci-pltfm.h"
33 36
@@ -121,6 +124,48 @@ static struct sdhci_ops pxav2_sdhci_ops = {
121 .platform_8bit_width = pxav2_mmc_set_width, 124 .platform_8bit_width = pxav2_mmc_set_width,
122}; 125};
123 126
127#ifdef CONFIG_OF
128static const struct of_device_id sdhci_pxav2_of_match[] = {
129 {
130 .compatible = "mrvl,pxav2-mmc",
131 },
132 {},
133};
134MODULE_DEVICE_TABLE(of, sdhci_pxav2_of_match);
135
136static struct sdhci_pxa_platdata *pxav2_get_mmc_pdata(struct device *dev)
137{
138 struct sdhci_pxa_platdata *pdata;
139 struct device_node *np = dev->of_node;
140 u32 bus_width;
141 u32 clk_delay_cycles;
142
143 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
144 if (!pdata)
145 return NULL;
146
147 if (of_find_property(np, "non-removable", NULL))
148 pdata->flags |= PXA_FLAG_CARD_PERMANENT;
149
150 of_property_read_u32(np, "bus-width", &bus_width);
151 if (bus_width == 8)
152 pdata->flags |= PXA_FLAG_SD_8_BIT_CAPABLE_SLOT;
153
154 of_property_read_u32(np, "mrvl,clk-delay-cycles", &clk_delay_cycles);
155 if (clk_delay_cycles > 0) {
156 pdata->clk_delay_sel = 1;
157 pdata->clk_delay_cycles = clk_delay_cycles;
158 }
159
160 return pdata;
161}
162#else
163static inline struct sdhci_pxa_platdata *pxav2_get_mmc_pdata(struct device *dev)
164{
165 return NULL;
166}
167#endif
168
124static int __devinit sdhci_pxav2_probe(struct platform_device *pdev) 169static int __devinit sdhci_pxav2_probe(struct platform_device *pdev)
125{ 170{
126 struct sdhci_pltfm_host *pltfm_host; 171 struct sdhci_pltfm_host *pltfm_host;
@@ -128,6 +173,8 @@ static int __devinit sdhci_pxav2_probe(struct platform_device *pdev)
128 struct device *dev = &pdev->dev; 173 struct device *dev = &pdev->dev;
129 struct sdhci_host *host = NULL; 174 struct sdhci_host *host = NULL;
130 struct sdhci_pxa *pxa = NULL; 175 struct sdhci_pxa *pxa = NULL;
176 const struct of_device_id *match;
177
131 int ret; 178 int ret;
132 struct clk *clk; 179 struct clk *clk;
133 180
@@ -156,6 +203,10 @@ static int __devinit sdhci_pxav2_probe(struct platform_device *pdev)
156 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL 203 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
157 | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN; 204 | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN;
158 205
206 match = of_match_device(of_match_ptr(sdhci_pxav2_of_match), &pdev->dev);
207 if (match) {
208 pdata = pxav2_get_mmc_pdata(dev);
209 }
159 if (pdata) { 210 if (pdata) {
160 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { 211 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) {
161 /* on-chip device */ 212 /* on-chip device */
@@ -218,6 +269,9 @@ static struct platform_driver sdhci_pxav2_driver = {
218 .driver = { 269 .driver = {
219 .name = "sdhci-pxav2", 270 .name = "sdhci-pxav2",
220 .owner = THIS_MODULE, 271 .owner = THIS_MODULE,
272#ifdef CONFIG_OF
273 .of_match_table = sdhci_pxav2_of_match,
274#endif
221 .pm = SDHCI_PLTFM_PMOPS, 275 .pm = SDHCI_PLTFM_PMOPS,
222 }, 276 },
223 .probe = sdhci_pxav2_probe, 277 .probe = sdhci_pxav2_probe,
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index f29695683556..07fe3834fe0b 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -28,6 +28,9 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/of.h>
32#include <linux/of_device.h>
33
31#include "sdhci.h" 34#include "sdhci.h"
32#include "sdhci-pltfm.h" 35#include "sdhci-pltfm.h"
33 36
@@ -164,6 +167,46 @@ static struct sdhci_ops pxav3_sdhci_ops = {
164 .platform_send_init_74_clocks = pxav3_gen_init_74_clocks, 167 .platform_send_init_74_clocks = pxav3_gen_init_74_clocks,
165}; 168};
166 169
170#ifdef CONFIG_OF
171static const struct of_device_id sdhci_pxav3_of_match[] = {
172 {
173 .compatible = "mrvl,pxav3-mmc",
174 },
175 {},
176};
177MODULE_DEVICE_TABLE(of, sdhci_pxav3_of_match);
178
179static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
180{
181 struct sdhci_pxa_platdata *pdata;
182 struct device_node *np = dev->of_node;
183 u32 bus_width;
184 u32 clk_delay_cycles;
185
186 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
187 if (!pdata)
188 return NULL;
189
190 if (of_find_property(np, "non-removable", NULL))
191 pdata->flags |= PXA_FLAG_CARD_PERMANENT;
192
193 of_property_read_u32(np, "bus-width", &bus_width);
194 if (bus_width == 8)
195 pdata->flags |= PXA_FLAG_SD_8_BIT_CAPABLE_SLOT;
196
197 of_property_read_u32(np, "mrvl,clk-delay-cycles", &clk_delay_cycles);
198 if (clk_delay_cycles > 0)
199 pdata->clk_delay_cycles = clk_delay_cycles;
200
201 return pdata;
202}
203#else
204static inline struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
205{
206 return NULL;
207}
208#endif
209
167static int __devinit sdhci_pxav3_probe(struct platform_device *pdev) 210static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
168{ 211{
169 struct sdhci_pltfm_host *pltfm_host; 212 struct sdhci_pltfm_host *pltfm_host;
@@ -171,6 +214,8 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
171 struct device *dev = &pdev->dev; 214 struct device *dev = &pdev->dev;
172 struct sdhci_host *host = NULL; 215 struct sdhci_host *host = NULL;
173 struct sdhci_pxa *pxa = NULL; 216 struct sdhci_pxa *pxa = NULL;
217 const struct of_device_id *match;
218
174 int ret; 219 int ret;
175 struct clk *clk; 220 struct clk *clk;
176 221
@@ -202,6 +247,10 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
202 /* enable 1/8V DDR capable */ 247 /* enable 1/8V DDR capable */
203 host->mmc->caps |= MMC_CAP_1_8V_DDR; 248 host->mmc->caps |= MMC_CAP_1_8V_DDR;
204 249
250 match = of_match_device(of_match_ptr(sdhci_pxav3_of_match), &pdev->dev);
251 if (match)
252 pdata = pxav3_get_mmc_pdata(dev);
253
205 if (pdata) { 254 if (pdata) {
206 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { 255 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) {
207 /* on-chip device */ 256 /* on-chip device */
@@ -263,6 +312,9 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
263static struct platform_driver sdhci_pxav3_driver = { 312static struct platform_driver sdhci_pxav3_driver = {
264 .driver = { 313 .driver = {
265 .name = "sdhci-pxav3", 314 .name = "sdhci-pxav3",
315#ifdef CONFIG_OF
316 .of_match_table = sdhci_pxav3_of_match,
317#endif
266 .owner = THIS_MODULE, 318 .owner = THIS_MODULE,
267 .pm = SDHCI_PLTFM_PMOPS, 319 .pm = SDHCI_PLTFM_PMOPS,
268 }, 320 },
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 55a164fcaa15..a50c205ea208 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -404,7 +404,7 @@ static void sdhci_s3c_setup_card_detect_gpio(struct sdhci_s3c *sc)
404 if (sc->ext_cd_irq && 404 if (sc->ext_cd_irq &&
405 request_threaded_irq(sc->ext_cd_irq, NULL, 405 request_threaded_irq(sc->ext_cd_irq, NULL,
406 sdhci_s3c_gpio_card_detect_thread, 406 sdhci_s3c_gpio_card_detect_thread,
407 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 407 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
408 dev_name(dev), sc) == 0) { 408 dev_name(dev), sc) == 0) {
409 int status = gpio_get_value(sc->ext_cd_gpio); 409 int status = gpio_get_value(sc->ext_cd_gpio);
410 if (pdata->ext_cd_gpio_invert) 410 if (pdata->ext_cd_gpio_invert)
diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
index 1fe32dfa7cd4..423da8194cd8 100644
--- a/drivers/mmc/host/sdhci-spear.c
+++ b/drivers/mmc/host/sdhci-spear.c
@@ -4,7 +4,7 @@
4 * Support of SDHCI platform devices for spear soc family 4 * Support of SDHCI platform devices for spear soc family
5 * 5 *
6 * Copyright (C) 2010 ST Microelectronics 6 * Copyright (C) 2010 ST Microelectronics
7 * Viresh Kumar<viresh.kumar@st.com> 7 * Viresh Kumar <viresh.linux@gmail.com>
8 * 8 *
9 * Inspired by sdhci-pltfm.c 9 * Inspired by sdhci-pltfm.c
10 * 10 *
@@ -289,5 +289,5 @@ static struct platform_driver sdhci_driver = {
289module_platform_driver(sdhci_driver); 289module_platform_driver(sdhci_driver);
290 290
291MODULE_DESCRIPTION("SPEAr Secure Digital Host Controller Interface driver"); 291MODULE_DESCRIPTION("SPEAr Secure Digital Host Controller Interface driver");
292MODULE_AUTHOR("Viresh Kumar <viresh.kumar@st.com>"); 292MODULE_AUTHOR("Viresh Kumar <viresh.linux@gmail.com>");
293MODULE_LICENSE("GPL v2"); 293MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index b38d8a78f6a0..0810ccc23d7e 100644
--- a/drivers/mmc/host/sdhci-tegra.c
+++ b/drivers/mmc/host/sdhci-tegra.c
@@ -223,6 +223,7 @@ static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata(
223{ 223{
224 struct tegra_sdhci_platform_data *plat; 224 struct tegra_sdhci_platform_data *plat;
225 struct device_node *np = pdev->dev.of_node; 225 struct device_node *np = pdev->dev.of_node;
226 u32 bus_width;
226 227
227 if (!np) 228 if (!np)
228 return NULL; 229 return NULL;
@@ -236,7 +237,9 @@ static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata(
236 plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0); 237 plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
237 plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); 238 plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
238 plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0); 239 plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0);
239 if (of_find_property(np, "support-8bit", NULL)) 240
241 if (of_property_read_u32(np, "bus-width", &bus_width) == 0 &&
242 bus_width == 8)
240 plat->is_8bit = 1; 243 plat->is_8bit = 1;
241 244
242 return plat; 245 return plat;
@@ -334,7 +337,7 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
334 rc = PTR_ERR(clk); 337 rc = PTR_ERR(clk);
335 goto err_clk_get; 338 goto err_clk_get;
336 } 339 }
337 clk_enable(clk); 340 clk_prepare_enable(clk);
338 pltfm_host->clk = clk; 341 pltfm_host->clk = clk;
339 342
340 host->mmc->pm_caps = plat->pm_flags; 343 host->mmc->pm_caps = plat->pm_flags;
@@ -349,7 +352,7 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
349 return 0; 352 return 0;
350 353
351err_add_host: 354err_add_host:
352 clk_disable(pltfm_host->clk); 355 clk_disable_unprepare(pltfm_host->clk);
353 clk_put(pltfm_host->clk); 356 clk_put(pltfm_host->clk);
354err_clk_get: 357err_clk_get:
355 if (gpio_is_valid(plat->wp_gpio)) 358 if (gpio_is_valid(plat->wp_gpio))
@@ -390,7 +393,7 @@ static int __devexit sdhci_tegra_remove(struct platform_device *pdev)
390 if (gpio_is_valid(plat->power_gpio)) 393 if (gpio_is_valid(plat->power_gpio))
391 gpio_free(plat->power_gpio); 394 gpio_free(plat->power_gpio);
392 395
393 clk_disable(pltfm_host->clk); 396 clk_disable_unprepare(pltfm_host->clk);
394 clk_put(pltfm_host->clk); 397 clk_put(pltfm_host->clk);
395 398
396 sdhci_pltfm_free(pdev); 399 sdhci_pltfm_free(pdev);
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index e626732aff77..9a11dc39921c 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -27,6 +27,7 @@
27 27
28#include <linux/mmc/mmc.h> 28#include <linux/mmc/mmc.h>
29#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
30#include <linux/mmc/card.h>
30 31
31#include "sdhci.h" 32#include "sdhci.h"
32 33
@@ -244,6 +245,19 @@ static void sdhci_init(struct sdhci_host *host, int soft)
244static void sdhci_reinit(struct sdhci_host *host) 245static void sdhci_reinit(struct sdhci_host *host)
245{ 246{
246 sdhci_init(host, 0); 247 sdhci_init(host, 0);
248 /*
249 * Retuning stuffs are affected by different cards inserted and only
250 * applicable to UHS-I cards. So reset these fields to their initial
251 * value when card is removed.
252 */
253 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
254 host->flags &= ~SDHCI_USING_RETUNING_TIMER;
255
256 del_timer_sync(&host->tuning_timer);
257 host->flags &= ~SDHCI_NEEDS_RETUNING;
258 host->mmc->max_blk_count =
259 (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535;
260 }
247 sdhci_enable_card_detection(host); 261 sdhci_enable_card_detection(host);
248} 262}
249 263
@@ -680,8 +694,8 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
680 } 694 }
681 695
682 if (count >= 0xF) { 696 if (count >= 0xF) {
683 pr_warning("%s: Too large timeout 0x%x requested for CMD%d!\n", 697 DBG("%s: Too large timeout 0x%x requested for CMD%d!\n",
684 mmc_hostname(host->mmc), count, cmd->opcode); 698 mmc_hostname(host->mmc), count, cmd->opcode);
685 count = 0xE; 699 count = 0xE;
686 } 700 }
687 701
@@ -1245,6 +1259,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1245 struct sdhci_host *host; 1259 struct sdhci_host *host;
1246 bool present; 1260 bool present;
1247 unsigned long flags; 1261 unsigned long flags;
1262 u32 tuning_opcode;
1248 1263
1249 host = mmc_priv(mmc); 1264 host = mmc_priv(mmc);
1250 1265
@@ -1292,8 +1307,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1292 */ 1307 */
1293 if ((host->flags & SDHCI_NEEDS_RETUNING) && 1308 if ((host->flags & SDHCI_NEEDS_RETUNING) &&
1294 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) { 1309 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) {
1310 /* eMMC uses cmd21 while sd and sdio use cmd19 */
1311 tuning_opcode = mmc->card->type == MMC_TYPE_MMC ?
1312 MMC_SEND_TUNING_BLOCK_HS200 :
1313 MMC_SEND_TUNING_BLOCK;
1295 spin_unlock_irqrestore(&host->lock, flags); 1314 spin_unlock_irqrestore(&host->lock, flags);
1296 sdhci_execute_tuning(mmc, mrq->cmd->opcode); 1315 sdhci_execute_tuning(mmc, tuning_opcode);
1297 spin_lock_irqsave(&host->lock, flags); 1316 spin_lock_irqsave(&host->lock, flags);
1298 1317
1299 /* Restore original mmc_request structure */ 1318 /* Restore original mmc_request structure */
@@ -1663,11 +1682,15 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1663 pwr = sdhci_readb(host, SDHCI_POWER_CONTROL); 1682 pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
1664 pwr &= ~SDHCI_POWER_ON; 1683 pwr &= ~SDHCI_POWER_ON;
1665 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1684 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1685 if (host->vmmc)
1686 regulator_disable(host->vmmc);
1666 1687
1667 /* Wait for 1ms as per the spec */ 1688 /* Wait for 1ms as per the spec */
1668 usleep_range(1000, 1500); 1689 usleep_range(1000, 1500);
1669 pwr |= SDHCI_POWER_ON; 1690 pwr |= SDHCI_POWER_ON;
1670 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1691 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1692 if (host->vmmc)
1693 regulator_enable(host->vmmc);
1671 1694
1672 pr_info(DRIVER_NAME ": Switching to 1.8V signalling " 1695 pr_info(DRIVER_NAME ": Switching to 1.8V signalling "
1673 "voltage failed, retrying with S18R set to 0\n"); 1696 "voltage failed, retrying with S18R set to 0\n");
@@ -1855,6 +1878,7 @@ out:
1855 */ 1878 */
1856 if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count && 1879 if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
1857 (host->tuning_mode == SDHCI_TUNING_MODE_1)) { 1880 (host->tuning_mode == SDHCI_TUNING_MODE_1)) {
1881 host->flags |= SDHCI_USING_RETUNING_TIMER;
1858 mod_timer(&host->tuning_timer, jiffies + 1882 mod_timer(&host->tuning_timer, jiffies +
1859 host->tuning_count * HZ); 1883 host->tuning_count * HZ);
1860 /* Tuning mode 1 limits the maximum data length to 4MB */ 1884 /* Tuning mode 1 limits the maximum data length to 4MB */
@@ -1872,10 +1896,10 @@ out:
1872 * try tuning again at a later time, when the re-tuning timer expires. 1896 * try tuning again at a later time, when the re-tuning timer expires.
1873 * So for these controllers, we return 0. Since there might be other 1897 * So for these controllers, we return 0. Since there might be other
1874 * controllers who do not have this capability, we return error for 1898 * controllers who do not have this capability, we return error for
1875 * them. 1899 * them. SDHCI_USING_RETUNING_TIMER means the host is currently using
1900 * a retuning timer to do the retuning for the card.
1876 */ 1901 */
1877 if (err && host->tuning_count && 1902 if (err && (host->flags & SDHCI_USING_RETUNING_TIMER))
1878 host->tuning_mode == SDHCI_TUNING_MODE_1)
1879 err = 0; 1903 err = 0;
1880 1904
1881 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier); 1905 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier);
@@ -2382,7 +2406,6 @@ out:
2382int sdhci_suspend_host(struct sdhci_host *host) 2406int sdhci_suspend_host(struct sdhci_host *host)
2383{ 2407{
2384 int ret; 2408 int ret;
2385 bool has_tuning_timer;
2386 2409
2387 if (host->ops->platform_suspend) 2410 if (host->ops->platform_suspend)
2388 host->ops->platform_suspend(host); 2411 host->ops->platform_suspend(host);
@@ -2390,16 +2413,14 @@ int sdhci_suspend_host(struct sdhci_host *host)
2390 sdhci_disable_card_detection(host); 2413 sdhci_disable_card_detection(host);
2391 2414
2392 /* Disable tuning since we are suspending */ 2415 /* Disable tuning since we are suspending */
2393 has_tuning_timer = host->version >= SDHCI_SPEC_300 && 2416 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2394 host->tuning_count && host->tuning_mode == SDHCI_TUNING_MODE_1;
2395 if (has_tuning_timer) {
2396 del_timer_sync(&host->tuning_timer); 2417 del_timer_sync(&host->tuning_timer);
2397 host->flags &= ~SDHCI_NEEDS_RETUNING; 2418 host->flags &= ~SDHCI_NEEDS_RETUNING;
2398 } 2419 }
2399 2420
2400 ret = mmc_suspend_host(host->mmc); 2421 ret = mmc_suspend_host(host->mmc);
2401 if (ret) { 2422 if (ret) {
2402 if (has_tuning_timer) { 2423 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2403 host->flags |= SDHCI_NEEDS_RETUNING; 2424 host->flags |= SDHCI_NEEDS_RETUNING;
2404 mod_timer(&host->tuning_timer, jiffies + 2425 mod_timer(&host->tuning_timer, jiffies +
2405 host->tuning_count * HZ); 2426 host->tuning_count * HZ);
@@ -2450,8 +2471,7 @@ int sdhci_resume_host(struct sdhci_host *host)
2450 host->ops->platform_resume(host); 2471 host->ops->platform_resume(host);
2451 2472
2452 /* Set the re-tuning expiration flag */ 2473 /* Set the re-tuning expiration flag */
2453 if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && 2474 if (host->flags & SDHCI_USING_RETUNING_TIMER)
2454 (host->tuning_mode == SDHCI_TUNING_MODE_1))
2455 host->flags |= SDHCI_NEEDS_RETUNING; 2475 host->flags |= SDHCI_NEEDS_RETUNING;
2456 2476
2457 return ret; 2477 return ret;
@@ -2490,8 +2510,7 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host)
2490 int ret = 0; 2510 int ret = 0;
2491 2511
2492 /* Disable tuning since we are suspending */ 2512 /* Disable tuning since we are suspending */
2493 if (host->version >= SDHCI_SPEC_300 && 2513 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2494 host->tuning_mode == SDHCI_TUNING_MODE_1) {
2495 del_timer_sync(&host->tuning_timer); 2514 del_timer_sync(&host->tuning_timer);
2496 host->flags &= ~SDHCI_NEEDS_RETUNING; 2515 host->flags &= ~SDHCI_NEEDS_RETUNING;
2497 } 2516 }
@@ -2532,8 +2551,7 @@ int sdhci_runtime_resume_host(struct sdhci_host *host)
2532 sdhci_do_enable_preset_value(host, true); 2551 sdhci_do_enable_preset_value(host, true);
2533 2552
2534 /* Set the re-tuning expiration flag */ 2553 /* Set the re-tuning expiration flag */
2535 if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && 2554 if (host->flags & SDHCI_USING_RETUNING_TIMER)
2536 (host->tuning_mode == SDHCI_TUNING_MODE_1))
2537 host->flags |= SDHCI_NEEDS_RETUNING; 2555 host->flags |= SDHCI_NEEDS_RETUNING;
2538 2556
2539 spin_lock_irqsave(&host->lock, flags); 2557 spin_lock_irqsave(&host->lock, flags);
@@ -2584,7 +2602,7 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
2584int sdhci_add_host(struct sdhci_host *host) 2602int sdhci_add_host(struct sdhci_host *host)
2585{ 2603{
2586 struct mmc_host *mmc; 2604 struct mmc_host *mmc;
2587 u32 caps[2]; 2605 u32 caps[2] = {0, 0};
2588 u32 max_current_caps; 2606 u32 max_current_caps;
2589 unsigned int ocr_avail; 2607 unsigned int ocr_avail;
2590 int ret; 2608 int ret;
@@ -2614,8 +2632,10 @@ int sdhci_add_host(struct sdhci_host *host)
2614 caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : 2632 caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
2615 sdhci_readl(host, SDHCI_CAPABILITIES); 2633 sdhci_readl(host, SDHCI_CAPABILITIES);
2616 2634
2617 caps[1] = (host->version >= SDHCI_SPEC_300) ? 2635 if (host->version >= SDHCI_SPEC_300)
2618 sdhci_readl(host, SDHCI_CAPABILITIES_1) : 0; 2636 caps[1] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ?
2637 host->caps1 :
2638 sdhci_readl(host, SDHCI_CAPABILITIES_1);
2619 2639
2620 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) 2640 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
2621 host->flags |= SDHCI_USE_SDMA; 2641 host->flags |= SDHCI_USE_SDMA;
@@ -2779,7 +2799,7 @@ int sdhci_add_host(struct sdhci_host *host)
2779 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 2799 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
2780 2800
2781 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && 2801 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
2782 mmc_card_is_removable(mmc)) 2802 !(host->mmc->caps & MMC_CAP_NONREMOVABLE))
2783 mmc->caps |= MMC_CAP_NEEDS_POLL; 2803 mmc->caps |= MMC_CAP_NEEDS_POLL;
2784 2804
2785 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */ 2805 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */
@@ -2837,6 +2857,30 @@ int sdhci_add_host(struct sdhci_host *host)
2837 SDHCI_RETUNING_MODE_SHIFT; 2857 SDHCI_RETUNING_MODE_SHIFT;
2838 2858
2839 ocr_avail = 0; 2859 ocr_avail = 0;
2860
2861 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
2862 if (IS_ERR(host->vmmc)) {
2863 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
2864 host->vmmc = NULL;
2865 }
2866
2867#ifdef CONFIG_REGULATOR
2868 if (host->vmmc) {
2869 ret = regulator_is_supported_voltage(host->vmmc, 3300000,
2870 3300000);
2871 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_330)))
2872 caps[0] &= ~SDHCI_CAN_VDD_330;
2873 ret = regulator_is_supported_voltage(host->vmmc, 3000000,
2874 3000000);
2875 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_300)))
2876 caps[0] &= ~SDHCI_CAN_VDD_300;
2877 ret = regulator_is_supported_voltage(host->vmmc, 1800000,
2878 1800000);
2879 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180)))
2880 caps[0] &= ~SDHCI_CAN_VDD_180;
2881 }
2882#endif /* CONFIG_REGULATOR */
2883
2840 /* 2884 /*
2841 * According to SD Host Controller spec v3.00, if the Host System 2885 * According to SD Host Controller spec v3.00, if the Host System
2842 * can afford more than 150mA, Host Driver should set XPC to 1. Also 2886 * can afford more than 150mA, Host Driver should set XPC to 1. Also
@@ -2845,55 +2889,45 @@ int sdhci_add_host(struct sdhci_host *host)
2845 * value. 2889 * value.
2846 */ 2890 */
2847 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); 2891 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
2892 if (!max_current_caps && host->vmmc) {
2893 u32 curr = regulator_get_current_limit(host->vmmc);
2894 if (curr > 0) {
2895
2896 /* convert to SDHCI_MAX_CURRENT format */
2897 curr = curr/1000; /* convert to mA */
2898 curr = curr/SDHCI_MAX_CURRENT_MULTIPLIER;
2899
2900 curr = min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT);
2901 max_current_caps =
2902 (curr << SDHCI_MAX_CURRENT_330_SHIFT) |
2903 (curr << SDHCI_MAX_CURRENT_300_SHIFT) |
2904 (curr << SDHCI_MAX_CURRENT_180_SHIFT);
2905 }
2906 }
2848 2907
2849 if (caps[0] & SDHCI_CAN_VDD_330) { 2908 if (caps[0] & SDHCI_CAN_VDD_330) {
2850 int max_current_330;
2851
2852 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; 2909 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
2853 2910
2854 max_current_330 = ((max_current_caps & 2911 mmc->max_current_330 = ((max_current_caps &
2855 SDHCI_MAX_CURRENT_330_MASK) >> 2912 SDHCI_MAX_CURRENT_330_MASK) >>
2856 SDHCI_MAX_CURRENT_330_SHIFT) * 2913 SDHCI_MAX_CURRENT_330_SHIFT) *
2857 SDHCI_MAX_CURRENT_MULTIPLIER; 2914 SDHCI_MAX_CURRENT_MULTIPLIER;
2858
2859 if (max_current_330 > 150)
2860 mmc->caps |= MMC_CAP_SET_XPC_330;
2861 } 2915 }
2862 if (caps[0] & SDHCI_CAN_VDD_300) { 2916 if (caps[0] & SDHCI_CAN_VDD_300) {
2863 int max_current_300;
2864
2865 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; 2917 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
2866 2918
2867 max_current_300 = ((max_current_caps & 2919 mmc->max_current_300 = ((max_current_caps &
2868 SDHCI_MAX_CURRENT_300_MASK) >> 2920 SDHCI_MAX_CURRENT_300_MASK) >>
2869 SDHCI_MAX_CURRENT_300_SHIFT) * 2921 SDHCI_MAX_CURRENT_300_SHIFT) *
2870 SDHCI_MAX_CURRENT_MULTIPLIER; 2922 SDHCI_MAX_CURRENT_MULTIPLIER;
2871
2872 if (max_current_300 > 150)
2873 mmc->caps |= MMC_CAP_SET_XPC_300;
2874 } 2923 }
2875 if (caps[0] & SDHCI_CAN_VDD_180) { 2924 if (caps[0] & SDHCI_CAN_VDD_180) {
2876 int max_current_180;
2877
2878 ocr_avail |= MMC_VDD_165_195; 2925 ocr_avail |= MMC_VDD_165_195;
2879 2926
2880 max_current_180 = ((max_current_caps & 2927 mmc->max_current_180 = ((max_current_caps &
2881 SDHCI_MAX_CURRENT_180_MASK) >> 2928 SDHCI_MAX_CURRENT_180_MASK) >>
2882 SDHCI_MAX_CURRENT_180_SHIFT) * 2929 SDHCI_MAX_CURRENT_180_SHIFT) *
2883 SDHCI_MAX_CURRENT_MULTIPLIER; 2930 SDHCI_MAX_CURRENT_MULTIPLIER;
2884
2885 if (max_current_180 > 150)
2886 mmc->caps |= MMC_CAP_SET_XPC_180;
2887
2888 /* Maximum current capabilities of the host at 1.8V */
2889 if (max_current_180 >= 800)
2890 mmc->caps |= MMC_CAP_MAX_CURRENT_800;
2891 else if (max_current_180 >= 600)
2892 mmc->caps |= MMC_CAP_MAX_CURRENT_600;
2893 else if (max_current_180 >= 400)
2894 mmc->caps |= MMC_CAP_MAX_CURRENT_400;
2895 else
2896 mmc->caps |= MMC_CAP_MAX_CURRENT_200;
2897 } 2931 }
2898 2932
2899 mmc->ocr_avail = ocr_avail; 2933 mmc->ocr_avail = ocr_avail;
@@ -2992,13 +3026,10 @@ int sdhci_add_host(struct sdhci_host *host)
2992 3026
2993 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, 3027 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
2994 mmc_hostname(mmc), host); 3028 mmc_hostname(mmc), host);
2995 if (ret) 3029 if (ret) {
3030 pr_err("%s: Failed to request IRQ %d: %d\n",
3031 mmc_hostname(mmc), host->irq, ret);
2996 goto untasklet; 3032 goto untasklet;
2997
2998 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
2999 if (IS_ERR(host->vmmc)) {
3000 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
3001 host->vmmc = NULL;
3002 } 3033 }
3003 3034
3004 sdhci_init(host, 0); 3035 sdhci_init(host, 0);
@@ -3016,8 +3047,11 @@ int sdhci_add_host(struct sdhci_host *host)
3016 host->led.brightness_set = sdhci_led_control; 3047 host->led.brightness_set = sdhci_led_control;
3017 3048
3018 ret = led_classdev_register(mmc_dev(mmc), &host->led); 3049 ret = led_classdev_register(mmc_dev(mmc), &host->led);
3019 if (ret) 3050 if (ret) {
3051 pr_err("%s: Failed to register LED device: %d\n",
3052 mmc_hostname(mmc), ret);
3020 goto reset; 3053 goto reset;
3054 }
3021#endif 3055#endif
3022 3056
3023 mmiowb(); 3057 mmiowb();
@@ -3081,8 +3115,6 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3081 free_irq(host->irq, host); 3115 free_irq(host->irq, host);
3082 3116
3083 del_timer_sync(&host->timer); 3117 del_timer_sync(&host->timer);
3084 if (host->version >= SDHCI_SPEC_300)
3085 del_timer_sync(&host->tuning_timer);
3086 3118
3087 tasklet_kill(&host->card_tasklet); 3119 tasklet_kill(&host->card_tasklet);
3088 tasklet_kill(&host->finish_tasklet); 3120 tasklet_kill(&host->finish_tasklet);
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index f761f23d2a28..97653ea8942b 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -205,6 +205,7 @@
205#define SDHCI_CAPABILITIES_1 0x44 205#define SDHCI_CAPABILITIES_1 0x44
206 206
207#define SDHCI_MAX_CURRENT 0x48 207#define SDHCI_MAX_CURRENT 0x48
208#define SDHCI_MAX_CURRENT_LIMIT 0xFF
208#define SDHCI_MAX_CURRENT_330_MASK 0x0000FF 209#define SDHCI_MAX_CURRENT_330_MASK 0x0000FF
209#define SDHCI_MAX_CURRENT_330_SHIFT 0 210#define SDHCI_MAX_CURRENT_330_SHIFT 0
210#define SDHCI_MAX_CURRENT_300_MASK 0x00FF00 211#define SDHCI_MAX_CURRENT_300_MASK 0x00FF00
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 0f07d2878c49..5d8142773fac 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -54,6 +54,8 @@
54#include <linux/mmc/mmc.h> 54#include <linux/mmc/mmc.h>
55#include <linux/mmc/sdio.h> 55#include <linux/mmc/sdio.h>
56#include <linux/mmc/sh_mmcif.h> 56#include <linux/mmc/sh_mmcif.h>
57#include <linux/mmc/slot-gpio.h>
58#include <linux/mod_devicetable.h>
57#include <linux/pagemap.h> 59#include <linux/pagemap.h>
58#include <linux/platform_device.h> 60#include <linux/platform_device.h>
59#include <linux/pm_qos.h> 61#include <linux/pm_qos.h>
@@ -379,6 +381,9 @@ static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
379 381
380 host->dma_active = false; 382 host->dma_active = false;
381 383
384 if (!pdata)
385 return;
386
382 if (pdata->slave_id_tx <= 0 || pdata->slave_id_rx <= 0) 387 if (pdata->slave_id_tx <= 0 || pdata->slave_id_rx <= 0)
383 return; 388 return;
384 389
@@ -452,13 +457,14 @@ static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
452static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) 457static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
453{ 458{
454 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; 459 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
460 bool sup_pclk = p ? p->sup_pclk : false;
455 461
456 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); 462 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
457 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR); 463 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR);
458 464
459 if (!clk) 465 if (!clk)
460 return; 466 return;
461 if (p->sup_pclk && clk == host->clk) 467 if (sup_pclk && clk == host->clk)
462 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); 468 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
463 else 469 else
464 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & 470 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
@@ -900,21 +906,15 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
900 906
901 switch (mrq->cmd->opcode) { 907 switch (mrq->cmd->opcode) {
902 /* MMCIF does not support SD/SDIO command */ 908 /* MMCIF does not support SD/SDIO command */
903 case SD_IO_SEND_OP_COND: 909 case MMC_SLEEP_AWAKE: /* = SD_IO_SEND_OP_COND (5) */
910 case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
911 if ((mrq->cmd->flags & MMC_CMD_MASK) != MMC_CMD_BCR)
912 break;
904 case MMC_APP_CMD: 913 case MMC_APP_CMD:
905 host->state = STATE_IDLE; 914 host->state = STATE_IDLE;
906 mrq->cmd->error = -ETIMEDOUT; 915 mrq->cmd->error = -ETIMEDOUT;
907 mmc_request_done(mmc, mrq); 916 mmc_request_done(mmc, mrq);
908 return; 917 return;
909 case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
910 if (!mrq->data) {
911 /* send_if_cond cmd (not support) */
912 host->state = STATE_IDLE;
913 mrq->cmd->error = -ETIMEDOUT;
914 mmc_request_done(mmc, mrq);
915 return;
916 }
917 break;
918 default: 918 default:
919 break; 919 break;
920 } 920 }
@@ -924,10 +924,35 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
924 sh_mmcif_start_cmd(host, mrq); 924 sh_mmcif_start_cmd(host, mrq);
925} 925}
926 926
927static int sh_mmcif_clk_update(struct sh_mmcif_host *host)
928{
929 int ret = clk_enable(host->hclk);
930
931 if (!ret) {
932 host->clk = clk_get_rate(host->hclk);
933 host->mmc->f_max = host->clk / 2;
934 host->mmc->f_min = host->clk / 512;
935 }
936
937 return ret;
938}
939
940static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios)
941{
942 struct sh_mmcif_plat_data *pd = host->pd->dev.platform_data;
943 struct mmc_host *mmc = host->mmc;
944
945 if (pd && pd->set_pwr)
946 pd->set_pwr(host->pd, ios->power_mode != MMC_POWER_OFF);
947 if (!IS_ERR(mmc->supply.vmmc))
948 /* Errors ignored... */
949 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
950 ios->power_mode ? ios->vdd : 0);
951}
952
927static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 953static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
928{ 954{
929 struct sh_mmcif_host *host = mmc_priv(mmc); 955 struct sh_mmcif_host *host = mmc_priv(mmc);
930 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
931 unsigned long flags; 956 unsigned long flags;
932 957
933 spin_lock_irqsave(&host->lock, flags); 958 spin_lock_irqsave(&host->lock, flags);
@@ -945,6 +970,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
945 sh_mmcif_request_dma(host, host->pd->dev.platform_data); 970 sh_mmcif_request_dma(host, host->pd->dev.platform_data);
946 host->card_present = true; 971 host->card_present = true;
947 } 972 }
973 sh_mmcif_set_power(host, ios);
948 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) { 974 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) {
949 /* clock stop */ 975 /* clock stop */
950 sh_mmcif_clock_control(host, 0); 976 sh_mmcif_clock_control(host, 0);
@@ -956,9 +982,10 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
956 } 982 }
957 if (host->power) { 983 if (host->power) {
958 pm_runtime_put(&host->pd->dev); 984 pm_runtime_put(&host->pd->dev);
985 clk_disable(host->hclk);
959 host->power = false; 986 host->power = false;
960 if (p->down_pwr && ios->power_mode == MMC_POWER_OFF) 987 if (ios->power_mode == MMC_POWER_OFF)
961 p->down_pwr(host->pd); 988 sh_mmcif_set_power(host, ios);
962 } 989 }
963 host->state = STATE_IDLE; 990 host->state = STATE_IDLE;
964 return; 991 return;
@@ -966,8 +993,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
966 993
967 if (ios->clock) { 994 if (ios->clock) {
968 if (!host->power) { 995 if (!host->power) {
969 if (p->set_pwr) 996 sh_mmcif_clk_update(host);
970 p->set_pwr(host->pd, ios->power_mode);
971 pm_runtime_get_sync(&host->pd->dev); 997 pm_runtime_get_sync(&host->pd->dev);
972 host->power = true; 998 host->power = true;
973 sh_mmcif_sync_reset(host); 999 sh_mmcif_sync_reset(host);
@@ -983,8 +1009,12 @@ static int sh_mmcif_get_cd(struct mmc_host *mmc)
983{ 1009{
984 struct sh_mmcif_host *host = mmc_priv(mmc); 1010 struct sh_mmcif_host *host = mmc_priv(mmc);
985 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; 1011 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
1012 int ret = mmc_gpio_get_cd(mmc);
1013
1014 if (ret >= 0)
1015 return ret;
986 1016
987 if (!p->get_cd) 1017 if (!p || !p->get_cd)
988 return -ENOSYS; 1018 return -ENOSYS;
989 else 1019 else
990 return p->get_cd(host->pd); 1020 return p->get_cd(host->pd);
@@ -1250,12 +1280,28 @@ static void mmcif_timeout_work(struct work_struct *work)
1250 mmc_request_done(host->mmc, mrq); 1280 mmc_request_done(host->mmc, mrq);
1251} 1281}
1252 1282
1283static void sh_mmcif_init_ocr(struct sh_mmcif_host *host)
1284{
1285 struct sh_mmcif_plat_data *pd = host->pd->dev.platform_data;
1286 struct mmc_host *mmc = host->mmc;
1287
1288 mmc_regulator_get_supply(mmc);
1289
1290 if (!pd)
1291 return;
1292
1293 if (!mmc->ocr_avail)
1294 mmc->ocr_avail = pd->ocr;
1295 else if (pd->ocr)
1296 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
1297}
1298
1253static int __devinit sh_mmcif_probe(struct platform_device *pdev) 1299static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1254{ 1300{
1255 int ret = 0, irq[2]; 1301 int ret = 0, irq[2];
1256 struct mmc_host *mmc; 1302 struct mmc_host *mmc;
1257 struct sh_mmcif_host *host; 1303 struct sh_mmcif_host *host;
1258 struct sh_mmcif_plat_data *pd; 1304 struct sh_mmcif_plat_data *pd = pdev->dev.platform_data;
1259 struct resource *res; 1305 struct resource *res;
1260 void __iomem *reg; 1306 void __iomem *reg;
1261 char clk_name[8]; 1307 char clk_name[8];
@@ -1276,42 +1322,26 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1276 dev_err(&pdev->dev, "ioremap error.\n"); 1322 dev_err(&pdev->dev, "ioremap error.\n");
1277 return -ENOMEM; 1323 return -ENOMEM;
1278 } 1324 }
1279 pd = pdev->dev.platform_data; 1325
1280 if (!pd) {
1281 dev_err(&pdev->dev, "sh_mmcif plat data error.\n");
1282 ret = -ENXIO;
1283 goto clean_up;
1284 }
1285 mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev); 1326 mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev);
1286 if (!mmc) { 1327 if (!mmc) {
1287 ret = -ENOMEM; 1328 ret = -ENOMEM;
1288 goto clean_up; 1329 goto ealloch;
1289 } 1330 }
1290 host = mmc_priv(mmc); 1331 host = mmc_priv(mmc);
1291 host->mmc = mmc; 1332 host->mmc = mmc;
1292 host->addr = reg; 1333 host->addr = reg;
1293 host->timeout = 1000; 1334 host->timeout = 1000;
1294 1335
1295 snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id);
1296 host->hclk = clk_get(&pdev->dev, clk_name);
1297 if (IS_ERR(host->hclk)) {
1298 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
1299 ret = PTR_ERR(host->hclk);
1300 goto clean_up1;
1301 }
1302 clk_enable(host->hclk);
1303 host->clk = clk_get_rate(host->hclk);
1304 host->pd = pdev; 1336 host->pd = pdev;
1305 1337
1306 spin_lock_init(&host->lock); 1338 spin_lock_init(&host->lock);
1307 1339
1308 mmc->ops = &sh_mmcif_ops; 1340 mmc->ops = &sh_mmcif_ops;
1309 mmc->f_max = host->clk / 2; 1341 sh_mmcif_init_ocr(host);
1310 mmc->f_min = host->clk / 512; 1342
1311 if (pd->ocr)
1312 mmc->ocr_avail = pd->ocr;
1313 mmc->caps = MMC_CAP_MMC_HIGHSPEED; 1343 mmc->caps = MMC_CAP_MMC_HIGHSPEED;
1314 if (pd->caps) 1344 if (pd && pd->caps)
1315 mmc->caps |= pd->caps; 1345 mmc->caps |= pd->caps;
1316 mmc->max_segs = 32; 1346 mmc->max_segs = 32;
1317 mmc->max_blk_size = 512; 1347 mmc->max_blk_size = 512;
@@ -1319,34 +1349,52 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1319 mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size; 1349 mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size;
1320 mmc->max_seg_size = mmc->max_req_size; 1350 mmc->max_seg_size = mmc->max_req_size;
1321 1351
1322 sh_mmcif_sync_reset(host);
1323 platform_set_drvdata(pdev, host); 1352 platform_set_drvdata(pdev, host);
1324 1353
1325 pm_runtime_enable(&pdev->dev); 1354 pm_runtime_enable(&pdev->dev);
1326 host->power = false; 1355 host->power = false;
1327 1356
1357 snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id);
1358 host->hclk = clk_get(&pdev->dev, clk_name);
1359 if (IS_ERR(host->hclk)) {
1360 ret = PTR_ERR(host->hclk);
1361 dev_err(&pdev->dev, "cannot get clock \"%s\": %d\n", clk_name, ret);
1362 goto eclkget;
1363 }
1364 ret = sh_mmcif_clk_update(host);
1365 if (ret < 0)
1366 goto eclkupdate;
1367
1328 ret = pm_runtime_resume(&pdev->dev); 1368 ret = pm_runtime_resume(&pdev->dev);
1329 if (ret < 0) 1369 if (ret < 0)
1330 goto clean_up2; 1370 goto eresume;
1331 1371
1332 INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work); 1372 INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work);
1333 1373
1374 sh_mmcif_sync_reset(host);
1334 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1375 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1335 1376
1336 ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:error", host); 1377 ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:error", host);
1337 if (ret) { 1378 if (ret) {
1338 dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n"); 1379 dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n");
1339 goto clean_up3; 1380 goto ereqirq0;
1340 } 1381 }
1341 ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host); 1382 ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host);
1342 if (ret) { 1383 if (ret) {
1343 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n"); 1384 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n");
1344 goto clean_up4; 1385 goto ereqirq1;
1386 }
1387
1388 if (pd && pd->use_cd_gpio) {
1389 ret = mmc_gpio_request_cd(mmc, pd->cd_gpio);
1390 if (ret < 0)
1391 goto erqcd;
1345 } 1392 }
1346 1393
1394 clk_disable(host->hclk);
1347 ret = mmc_add_host(mmc); 1395 ret = mmc_add_host(mmc);
1348 if (ret < 0) 1396 if (ret < 0)
1349 goto clean_up5; 1397 goto emmcaddh;
1350 1398
1351 dev_pm_qos_expose_latency_limit(&pdev->dev, 100); 1399 dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
1352 1400
@@ -1355,33 +1403,42 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1355 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff); 1403 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff);
1356 return ret; 1404 return ret;
1357 1405
1358clean_up5: 1406emmcaddh:
1407 if (pd && pd->use_cd_gpio)
1408 mmc_gpio_free_cd(mmc);
1409erqcd:
1359 free_irq(irq[1], host); 1410 free_irq(irq[1], host);
1360clean_up4: 1411ereqirq1:
1361 free_irq(irq[0], host); 1412 free_irq(irq[0], host);
1362clean_up3: 1413ereqirq0:
1363 pm_runtime_suspend(&pdev->dev); 1414 pm_runtime_suspend(&pdev->dev);
1364clean_up2: 1415eresume:
1365 pm_runtime_disable(&pdev->dev);
1366 clk_disable(host->hclk); 1416 clk_disable(host->hclk);
1367clean_up1: 1417eclkupdate:
1418 clk_put(host->hclk);
1419eclkget:
1420 pm_runtime_disable(&pdev->dev);
1368 mmc_free_host(mmc); 1421 mmc_free_host(mmc);
1369clean_up: 1422ealloch:
1370 if (reg) 1423 iounmap(reg);
1371 iounmap(reg);
1372 return ret; 1424 return ret;
1373} 1425}
1374 1426
1375static int __devexit sh_mmcif_remove(struct platform_device *pdev) 1427static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1376{ 1428{
1377 struct sh_mmcif_host *host = platform_get_drvdata(pdev); 1429 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1430 struct sh_mmcif_plat_data *pd = pdev->dev.platform_data;
1378 int irq[2]; 1431 int irq[2];
1379 1432
1380 host->dying = true; 1433 host->dying = true;
1434 clk_enable(host->hclk);
1381 pm_runtime_get_sync(&pdev->dev); 1435 pm_runtime_get_sync(&pdev->dev);
1382 1436
1383 dev_pm_qos_hide_latency_limit(&pdev->dev); 1437 dev_pm_qos_hide_latency_limit(&pdev->dev);
1384 1438
1439 if (pd && pd->use_cd_gpio)
1440 mmc_gpio_free_cd(host->mmc);
1441
1385 mmc_remove_host(host->mmc); 1442 mmc_remove_host(host->mmc);
1386 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1443 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1387 1444
@@ -1403,9 +1460,9 @@ static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1403 1460
1404 platform_set_drvdata(pdev, NULL); 1461 platform_set_drvdata(pdev, NULL);
1405 1462
1406 clk_disable(host->hclk);
1407 mmc_free_host(host->mmc); 1463 mmc_free_host(host->mmc);
1408 pm_runtime_put_sync(&pdev->dev); 1464 pm_runtime_put_sync(&pdev->dev);
1465 clk_disable(host->hclk);
1409 pm_runtime_disable(&pdev->dev); 1466 pm_runtime_disable(&pdev->dev);
1410 1467
1411 return 0; 1468 return 0;
@@ -1414,24 +1471,18 @@ static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1414#ifdef CONFIG_PM 1471#ifdef CONFIG_PM
1415static int sh_mmcif_suspend(struct device *dev) 1472static int sh_mmcif_suspend(struct device *dev)
1416{ 1473{
1417 struct platform_device *pdev = to_platform_device(dev); 1474 struct sh_mmcif_host *host = dev_get_drvdata(dev);
1418 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1419 int ret = mmc_suspend_host(host->mmc); 1475 int ret = mmc_suspend_host(host->mmc);
1420 1476
1421 if (!ret) { 1477 if (!ret)
1422 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1478 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1423 clk_disable(host->hclk);
1424 }
1425 1479
1426 return ret; 1480 return ret;
1427} 1481}
1428 1482
1429static int sh_mmcif_resume(struct device *dev) 1483static int sh_mmcif_resume(struct device *dev)
1430{ 1484{
1431 struct platform_device *pdev = to_platform_device(dev); 1485 struct sh_mmcif_host *host = dev_get_drvdata(dev);
1432 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1433
1434 clk_enable(host->hclk);
1435 1486
1436 return mmc_resume_host(host->mmc); 1487 return mmc_resume_host(host->mmc);
1437} 1488}
@@ -1440,6 +1491,12 @@ static int sh_mmcif_resume(struct device *dev)
1440#define sh_mmcif_resume NULL 1491#define sh_mmcif_resume NULL
1441#endif /* CONFIG_PM */ 1492#endif /* CONFIG_PM */
1442 1493
1494static const struct of_device_id mmcif_of_match[] = {
1495 { .compatible = "renesas,sh-mmcif" },
1496 { }
1497};
1498MODULE_DEVICE_TABLE(of, mmcif_of_match);
1499
1443static const struct dev_pm_ops sh_mmcif_dev_pm_ops = { 1500static const struct dev_pm_ops sh_mmcif_dev_pm_ops = {
1444 .suspend = sh_mmcif_suspend, 1501 .suspend = sh_mmcif_suspend,
1445 .resume = sh_mmcif_resume, 1502 .resume = sh_mmcif_resume,
@@ -1451,6 +1508,8 @@ static struct platform_driver sh_mmcif_driver = {
1451 .driver = { 1508 .driver = {
1452 .name = DRIVER_NAME, 1509 .name = DRIVER_NAME,
1453 .pm = &sh_mmcif_dev_pm_ops, 1510 .pm = &sh_mmcif_dev_pm_ops,
1511 .owner = THIS_MODULE,
1512 .of_match_table = mmcif_of_match,
1454 }, 1513 },
1455}; 1514};
1456 1515
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c
index b8d7004cf04a..0bdc146178db 100644
--- a/drivers/mmc/host/sh_mobile_sdhi.c
+++ b/drivers/mmc/host/sh_mobile_sdhi.c
@@ -21,6 +21,7 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/mod_devicetable.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/platform_device.h> 26#include <linux/platform_device.h>
26#include <linux/mmc/host.h> 27#include <linux/mmc/host.h>
@@ -39,22 +40,39 @@ struct sh_mobile_sdhi {
39 struct tmio_mmc_dma dma_priv; 40 struct tmio_mmc_dma dma_priv;
40}; 41};
41 42
43static int sh_mobile_sdhi_clk_enable(struct platform_device *pdev, unsigned int *f)
44{
45 struct mmc_host *mmc = dev_get_drvdata(&pdev->dev);
46 struct tmio_mmc_host *host = mmc_priv(mmc);
47 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
48 int ret = clk_enable(priv->clk);
49 if (ret < 0)
50 return ret;
51
52 *f = clk_get_rate(priv->clk);
53 return 0;
54}
55
56static void sh_mobile_sdhi_clk_disable(struct platform_device *pdev)
57{
58 struct mmc_host *mmc = dev_get_drvdata(&pdev->dev);
59 struct tmio_mmc_host *host = mmc_priv(mmc);
60 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
61 clk_disable(priv->clk);
62}
63
42static void sh_mobile_sdhi_set_pwr(struct platform_device *pdev, int state) 64static void sh_mobile_sdhi_set_pwr(struct platform_device *pdev, int state)
43{ 65{
44 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 66 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
45 67
46 if (p && p->set_pwr) 68 p->set_pwr(pdev, state);
47 p->set_pwr(pdev, state);
48} 69}
49 70
50static int sh_mobile_sdhi_get_cd(struct platform_device *pdev) 71static int sh_mobile_sdhi_get_cd(struct platform_device *pdev)
51{ 72{
52 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 73 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
53 74
54 if (p && p->get_cd) 75 return p->get_cd(pdev);
55 return p->get_cd(pdev);
56 else
57 return -ENOSYS;
58} 76}
59 77
60static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host) 78static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host)
@@ -116,12 +134,14 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
116 } 134 }
117 135
118 mmc_data = &priv->mmc_data; 136 mmc_data = &priv->mmc_data;
119 p->pdata = mmc_data;
120 137
121 if (p->init) { 138 if (p) {
122 ret = p->init(pdev, &sdhi_ops); 139 p->pdata = mmc_data;
123 if (ret) 140 if (p->init) {
124 goto einit; 141 ret = p->init(pdev, &sdhi_ops);
142 if (ret)
143 goto einit;
144 }
125 } 145 }
126 146
127 snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id); 147 snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id);
@@ -132,9 +152,8 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
132 goto eclkget; 152 goto eclkget;
133 } 153 }
134 154
135 mmc_data->hclk = clk_get_rate(priv->clk); 155 mmc_data->clk_enable = sh_mobile_sdhi_clk_enable;
136 mmc_data->set_pwr = sh_mobile_sdhi_set_pwr; 156 mmc_data->clk_disable = sh_mobile_sdhi_clk_disable;
137 mmc_data->get_cd = sh_mobile_sdhi_get_cd;
138 mmc_data->capabilities = MMC_CAP_MMC_HIGHSPEED; 157 mmc_data->capabilities = MMC_CAP_MMC_HIGHSPEED;
139 if (p) { 158 if (p) {
140 mmc_data->flags = p->tmio_flags; 159 mmc_data->flags = p->tmio_flags;
@@ -142,7 +161,12 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
142 mmc_data->write16_hook = sh_mobile_sdhi_write16_hook; 161 mmc_data->write16_hook = sh_mobile_sdhi_write16_hook;
143 mmc_data->ocr_mask = p->tmio_ocr_mask; 162 mmc_data->ocr_mask = p->tmio_ocr_mask;
144 mmc_data->capabilities |= p->tmio_caps; 163 mmc_data->capabilities |= p->tmio_caps;
164 mmc_data->capabilities2 |= p->tmio_caps2;
145 mmc_data->cd_gpio = p->cd_gpio; 165 mmc_data->cd_gpio = p->cd_gpio;
166 if (p->set_pwr)
167 mmc_data->set_pwr = sh_mobile_sdhi_set_pwr;
168 if (p->get_cd)
169 mmc_data->get_cd = sh_mobile_sdhi_get_cd;
146 170
147 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) { 171 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) {
148 priv->param_tx.shdma_slave.slave_id = p->dma_slave_tx; 172 priv->param_tx.shdma_slave.slave_id = p->dma_slave_tx;
@@ -248,7 +272,7 @@ eirq_card_detect:
248eprobe: 272eprobe:
249 clk_put(priv->clk); 273 clk_put(priv->clk);
250eclkget: 274eclkget:
251 if (p->cleanup) 275 if (p && p->cleanup)
252 p->cleanup(pdev); 276 p->cleanup(pdev);
253einit: 277einit:
254 kfree(priv); 278 kfree(priv);
@@ -263,7 +287,8 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev)
263 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 287 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
264 int i = 0, irq; 288 int i = 0, irq;
265 289
266 p->pdata = NULL; 290 if (p)
291 p->pdata = NULL;
267 292
268 tmio_mmc_host_remove(host); 293 tmio_mmc_host_remove(host);
269 294
@@ -276,7 +301,7 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev)
276 301
277 clk_put(priv->clk); 302 clk_put(priv->clk);
278 303
279 if (p->cleanup) 304 if (p && p->cleanup)
280 p->cleanup(pdev); 305 p->cleanup(pdev);
281 306
282 kfree(priv); 307 kfree(priv);
@@ -291,11 +316,18 @@ static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
291 .runtime_resume = tmio_mmc_host_runtime_resume, 316 .runtime_resume = tmio_mmc_host_runtime_resume,
292}; 317};
293 318
319static const struct of_device_id sh_mobile_sdhi_of_match[] = {
320 { .compatible = "renesas,shmobile-sdhi" },
321 { }
322};
323MODULE_DEVICE_TABLE(of, sh_mobile_sdhi_of_match);
324
294static struct platform_driver sh_mobile_sdhi_driver = { 325static struct platform_driver sh_mobile_sdhi_driver = {
295 .driver = { 326 .driver = {
296 .name = "sh_mobile_sdhi", 327 .name = "sh_mobile_sdhi",
297 .owner = THIS_MODULE, 328 .owner = THIS_MODULE,
298 .pm = &tmio_mmc_dev_pm_ops, 329 .pm = &tmio_mmc_dev_pm_ops,
330 .of_match_table = sh_mobile_sdhi_of_match,
299 }, 331 },
300 .probe = sh_mobile_sdhi_probe, 332 .probe = sh_mobile_sdhi_probe,
301 .remove = __devexit_p(sh_mobile_sdhi_remove), 333 .remove = __devexit_p(sh_mobile_sdhi_remove),
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index 9a7996ade58e..0d8a9bbe30be 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -34,8 +34,9 @@
34#include <linux/io.h> 34#include <linux/io.h>
35#include <linux/irq.h> 35#include <linux/irq.h>
36#include <linux/mfd/tmio.h> 36#include <linux/mfd/tmio.h>
37#include <linux/mmc/cd-gpio.h>
38#include <linux/mmc/host.h> 37#include <linux/mmc/host.h>
38#include <linux/mmc/mmc.h>
39#include <linux/mmc/slot-gpio.h>
39#include <linux/mmc/tmio.h> 40#include <linux/mmc/tmio.h>
40#include <linux/module.h> 41#include <linux/module.h>
41#include <linux/pagemap.h> 42#include <linux/pagemap.h>
@@ -305,8 +306,8 @@ static int tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command
305 int c = cmd->opcode; 306 int c = cmd->opcode;
306 u32 irq_mask = TMIO_MASK_CMD; 307 u32 irq_mask = TMIO_MASK_CMD;
307 308
308 /* Command 12 is handled by hardware */ 309 /* CMD12 is handled by hardware */
309 if (cmd->opcode == 12 && !cmd->arg) { 310 if (cmd->opcode == MMC_STOP_TRANSMISSION && !cmd->arg) {
310 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001); 311 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001);
311 return 0; 312 return 0;
312 } 313 }
@@ -449,7 +450,7 @@ void tmio_mmc_do_data_irq(struct tmio_mmc_host *host)
449 } 450 }
450 451
451 if (stop) { 452 if (stop) {
452 if (stop->opcode == 12 && !stop->arg) 453 if (stop->opcode == MMC_STOP_TRANSMISSION && !stop->arg)
453 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000); 454 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000);
454 else 455 else
455 BUG(); 456 BUG();
@@ -751,6 +752,34 @@ fail:
751 mmc_request_done(mmc, mrq); 752 mmc_request_done(mmc, mrq);
752} 753}
753 754
755static int tmio_mmc_clk_update(struct mmc_host *mmc)
756{
757 struct tmio_mmc_host *host = mmc_priv(mmc);
758 struct tmio_mmc_data *pdata = host->pdata;
759 int ret;
760
761 if (!pdata->clk_enable)
762 return -ENOTSUPP;
763
764 ret = pdata->clk_enable(host->pdev, &mmc->f_max);
765 if (!ret)
766 mmc->f_min = mmc->f_max / 512;
767
768 return ret;
769}
770
771static void tmio_mmc_set_power(struct tmio_mmc_host *host, struct mmc_ios *ios)
772{
773 struct mmc_host *mmc = host->mmc;
774
775 if (host->set_pwr)
776 host->set_pwr(host->pdev, ios->power_mode != MMC_POWER_OFF);
777 if (!IS_ERR(mmc->supply.vmmc))
778 /* Errors ignored... */
779 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
780 ios->power_mode ? ios->vdd : 0);
781}
782
754/* Set MMC clock / power. 783/* Set MMC clock / power.
755 * Note: This controller uses a simple divider scheme therefore it cannot 784 * Note: This controller uses a simple divider scheme therefore it cannot
756 * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as 785 * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
@@ -797,32 +826,37 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
797 */ 826 */
798 if (ios->power_mode == MMC_POWER_ON && ios->clock) { 827 if (ios->power_mode == MMC_POWER_ON && ios->clock) {
799 if (!host->power) { 828 if (!host->power) {
829 tmio_mmc_clk_update(mmc);
800 pm_runtime_get_sync(dev); 830 pm_runtime_get_sync(dev);
801 host->power = true; 831 host->power = true;
802 } 832 }
803 tmio_mmc_set_clock(host, ios->clock); 833 tmio_mmc_set_clock(host, ios->clock);
804 /* power up SD bus */ 834 /* power up SD bus */
805 if (host->set_pwr) 835 tmio_mmc_set_power(host, ios);
806 host->set_pwr(host->pdev, 1);
807 /* start bus clock */ 836 /* start bus clock */
808 tmio_mmc_clk_start(host); 837 tmio_mmc_clk_start(host);
809 } else if (ios->power_mode != MMC_POWER_UP) { 838 } else if (ios->power_mode != MMC_POWER_UP) {
810 if (host->set_pwr && ios->power_mode == MMC_POWER_OFF) 839 if (ios->power_mode == MMC_POWER_OFF)
811 host->set_pwr(host->pdev, 0); 840 tmio_mmc_set_power(host, ios);
812 if (host->power) { 841 if (host->power) {
842 struct tmio_mmc_data *pdata = host->pdata;
843 tmio_mmc_clk_stop(host);
813 host->power = false; 844 host->power = false;
814 pm_runtime_put(dev); 845 pm_runtime_put(dev);
846 if (pdata->clk_disable)
847 pdata->clk_disable(host->pdev);
815 } 848 }
816 tmio_mmc_clk_stop(host);
817 } 849 }
818 850
819 switch (ios->bus_width) { 851 if (host->power) {
820 case MMC_BUS_WIDTH_1: 852 switch (ios->bus_width) {
821 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0); 853 case MMC_BUS_WIDTH_1:
822 break; 854 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0);
823 case MMC_BUS_WIDTH_4: 855 break;
824 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0); 856 case MMC_BUS_WIDTH_4:
825 break; 857 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0);
858 break;
859 }
826 } 860 }
827 861
828 /* Let things settle. delay taken from winCE driver */ 862 /* Let things settle. delay taken from winCE driver */
@@ -841,6 +875,9 @@ static int tmio_mmc_get_ro(struct mmc_host *mmc)
841{ 875{
842 struct tmio_mmc_host *host = mmc_priv(mmc); 876 struct tmio_mmc_host *host = mmc_priv(mmc);
843 struct tmio_mmc_data *pdata = host->pdata; 877 struct tmio_mmc_data *pdata = host->pdata;
878 int ret = mmc_gpio_get_ro(mmc);
879 if (ret >= 0)
880 return ret;
844 881
845 return !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) || 882 return !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) ||
846 (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT)); 883 (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT));
@@ -850,6 +887,9 @@ static int tmio_mmc_get_cd(struct mmc_host *mmc)
850{ 887{
851 struct tmio_mmc_host *host = mmc_priv(mmc); 888 struct tmio_mmc_host *host = mmc_priv(mmc);
852 struct tmio_mmc_data *pdata = host->pdata; 889 struct tmio_mmc_data *pdata = host->pdata;
890 int ret = mmc_gpio_get_cd(mmc);
891 if (ret >= 0)
892 return ret;
853 893
854 if (!pdata->get_cd) 894 if (!pdata->get_cd)
855 return -ENOSYS; 895 return -ENOSYS;
@@ -865,6 +905,19 @@ static const struct mmc_host_ops tmio_mmc_ops = {
865 .enable_sdio_irq = tmio_mmc_enable_sdio_irq, 905 .enable_sdio_irq = tmio_mmc_enable_sdio_irq,
866}; 906};
867 907
908static void tmio_mmc_init_ocr(struct tmio_mmc_host *host)
909{
910 struct tmio_mmc_data *pdata = host->pdata;
911 struct mmc_host *mmc = host->mmc;
912
913 mmc_regulator_get_supply(mmc);
914
915 if (!mmc->ocr_avail)
916 mmc->ocr_avail = pdata->ocr_mask ? : MMC_VDD_32_33 | MMC_VDD_33_34;
917 else if (pdata->ocr_mask)
918 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
919}
920
868int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, 921int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
869 struct platform_device *pdev, 922 struct platform_device *pdev,
870 struct tmio_mmc_data *pdata) 923 struct tmio_mmc_data *pdata)
@@ -904,18 +957,14 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
904 957
905 mmc->ops = &tmio_mmc_ops; 958 mmc->ops = &tmio_mmc_ops;
906 mmc->caps = MMC_CAP_4_BIT_DATA | pdata->capabilities; 959 mmc->caps = MMC_CAP_4_BIT_DATA | pdata->capabilities;
907 mmc->f_max = pdata->hclk; 960 mmc->caps2 = pdata->capabilities2;
908 mmc->f_min = mmc->f_max / 512;
909 mmc->max_segs = 32; 961 mmc->max_segs = 32;
910 mmc->max_blk_size = 512; 962 mmc->max_blk_size = 512;
911 mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) * 963 mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) *
912 mmc->max_segs; 964 mmc->max_segs;
913 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; 965 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
914 mmc->max_seg_size = mmc->max_req_size; 966 mmc->max_seg_size = mmc->max_req_size;
915 if (pdata->ocr_mask) 967 tmio_mmc_init_ocr(_host);
916 mmc->ocr_avail = pdata->ocr_mask;
917 else
918 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
919 968
920 _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD || 969 _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD ||
921 mmc->caps & MMC_CAP_NEEDS_POLL || 970 mmc->caps & MMC_CAP_NEEDS_POLL ||
@@ -927,6 +976,11 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
927 if (ret < 0) 976 if (ret < 0)
928 goto pm_disable; 977 goto pm_disable;
929 978
979 if (tmio_mmc_clk_update(mmc) < 0) {
980 mmc->f_max = pdata->hclk;
981 mmc->f_min = mmc->f_max / 512;
982 }
983
930 /* 984 /*
931 * There are 4 different scenarios for the card detection: 985 * There are 4 different scenarios for the card detection:
932 * 1) an external gpio irq handles the cd (best for power savings) 986 * 1) an external gpio irq handles the cd (best for power savings)
@@ -937,7 +991,6 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
937 * While we increment the runtime PM counter for all scenarios when 991 * While we increment the runtime PM counter for all scenarios when
938 * the mmc core activates us by calling an appropriate set_ios(), we 992 * the mmc core activates us by calling an appropriate set_ios(), we
939 * must additionally ensure that in case 2) the tmio mmc hardware stays 993 * must additionally ensure that in case 2) the tmio mmc hardware stays
940 * additionally ensure that in case 2) the tmio mmc hardware stays
941 * powered on during runtime for the card detection to work. 994 * powered on during runtime for the card detection to work.
942 */ 995 */
943 if (_host->native_hotplug) 996 if (_host->native_hotplug)
@@ -948,6 +1001,17 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
948 1001
949 _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK); 1002 _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK);
950 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL); 1003 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL);
1004
1005 /* Unmask the IRQs we want to know about */
1006 if (!_host->chan_rx)
1007 irq_mask |= TMIO_MASK_READOP;
1008 if (!_host->chan_tx)
1009 irq_mask |= TMIO_MASK_WRITEOP;
1010 if (!_host->native_hotplug)
1011 irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT);
1012
1013 _host->sdcard_irq_mask &= ~irq_mask;
1014
951 if (pdata->flags & TMIO_MMC_SDIO_IRQ) 1015 if (pdata->flags & TMIO_MMC_SDIO_IRQ)
952 tmio_mmc_enable_sdio_irq(mmc, 0); 1016 tmio_mmc_enable_sdio_irq(mmc, 0);
953 1017
@@ -961,22 +1025,18 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
961 /* See if we also get DMA */ 1025 /* See if we also get DMA */
962 tmio_mmc_request_dma(_host, pdata); 1026 tmio_mmc_request_dma(_host, pdata);
963 1027
964 mmc_add_host(mmc); 1028 ret = mmc_add_host(mmc);
1029 if (pdata->clk_disable)
1030 pdata->clk_disable(pdev);
1031 if (ret < 0) {
1032 tmio_mmc_host_remove(_host);
1033 return ret;
1034 }
965 1035
966 dev_pm_qos_expose_latency_limit(&pdev->dev, 100); 1036 dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
967 1037
968 /* Unmask the IRQs we want to know about */
969 if (!_host->chan_rx)
970 irq_mask |= TMIO_MASK_READOP;
971 if (!_host->chan_tx)
972 irq_mask |= TMIO_MASK_WRITEOP;
973 if (!_host->native_hotplug)
974 irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT);
975
976 tmio_mmc_enable_mmc_irqs(_host, irq_mask);
977
978 if (pdata->flags & TMIO_MMC_USE_GPIO_CD) { 1038 if (pdata->flags & TMIO_MMC_USE_GPIO_CD) {
979 ret = mmc_cd_gpio_request(mmc, pdata->cd_gpio); 1039 ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio);
980 if (ret < 0) { 1040 if (ret < 0) {
981 tmio_mmc_host_remove(_host); 1041 tmio_mmc_host_remove(_host);
982 return ret; 1042 return ret;
@@ -1008,7 +1068,7 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
1008 * This means we can miss a card-eject, but this is anyway 1068 * This means we can miss a card-eject, but this is anyway
1009 * possible, because of delayed processing of hotplug events. 1069 * possible, because of delayed processing of hotplug events.
1010 */ 1070 */
1011 mmc_cd_gpio_free(mmc); 1071 mmc_gpio_free_cd(mmc);
1012 1072
1013 if (!host->native_hotplug) 1073 if (!host->native_hotplug)
1014 pm_runtime_get_sync(&pdev->dev); 1074 pm_runtime_get_sync(&pdev->dev);