aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-16 22:10:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-16 22:10:40 -0400
commit3e21e5dda4907ecb21a124517ab0eb1d176e5231 (patch)
treec778d03f2113d7ef3a4e360baa8cd4b198316ed0
parentd9dce51c9b77b803348c787165a884b6e11011f0 (diff)
parent1c447116d017a98c90f8f71c8c5a611e0aa42178 (diff)
Merge tag 'mmc-v4.7' of git://git.linaro.org/people/ulf.hansson/mmc
Pull MMC updates from Ulf Hansson: "MMC core: - Add TRACE support to be able to debug request flow - Extend/improve reset support for (e)MMC - Convert MMC pwrseq to platform device drivers - Use IDA for indexes - Some additional minor improvements MMC host: - sdhci: Re-factoring, clean-ups and improvements - sdhci-acpi|pci: Use MMC_CAP_AGGRESSIVE_PM for Broxton - omap/omap_hsmmc: Convert to use dma_request_chan() - usdhi6rol0: Add support for UHS modes - sh_mmcif: Update runtime PM support - tmio: Wolfram Sang steps in as maintainer - tmio: Add UHS-I mode support - sh_mobile_sdhi: Add UHS-I mode support - tmio/sdhi: Re-factoring, clean-ups and improvements - dw_mmc: Re-factoring and clean-ups - davinci: Convert to use dma_request_chan()" * tag 'mmc-v4.7' of git://git.linaro.org/people/ulf.hansson/mmc: (99 commits) mmc: mmc: Fix partition switch timeout for some eMMCs mmc: sh_mobile_sdhi: enable SDIO IRQs for RCar Gen3 mmc: sdio: fall back to SDIO 1.0 for broken 1.1 cards mmc: sdhci-st: correct name of sd-uhs-sdr50 property MAINTAINERS: update entry for TMIO MMC driver mmc: block: improve logging of handling emmc timeouts mmc: sdhci: removed unneeded function wrappers mmc: core: remove the invalid message in mmc_select_timing mmc: core: fix using wrong io voltage if mmc_select_hs200 fails mmc: sdhci-of-arasan: fix set_clock when a phy is supported mmc: omap: Use dma_request_chan() for requesting DMA channel mmc: mmc: Attempt to flush cache before reset mmc: sh_mobile_sdhi: check return value when changing clk mmc: sh_mobile_sdhi: only change the clock on RCar Gen2+ mmc: tmio/sdhi: introduce flag for RCar 2+ specific features mmc: sh_mobile_sdhi: make clk_update function more compact mmc: omap_hsmmc: Use dma_request_chan() for requesting DMA channel mmc: sdhci-of-at91: add presets setup mmc: usdhi6rol0: add pinctrl to set pin drive strength mmc: usdhi6rol0: add support for UHS modes ...
-rw-r--r--Documentation/devicetree/bindings/mmc/sdhci-st.txt4
-rw-r--r--Documentation/devicetree/bindings/mmc/tmio_mmc.txt3
-rw-r--r--Documentation/devicetree/bindings/mmc/usdhi6rol0.txt6
-rw-r--r--MAINTAINERS9
-rw-r--r--arch/arm/mach-davinci/devices-da8xx.c20
-rw-r--r--arch/arm/mach-davinci/devices.c16
-rw-r--r--arch/sh/boards/board-sh7757lcr.c1
-rw-r--r--arch/sh/boards/mach-ap325rxa/setup.c1
-rw-r--r--arch/sh/boards/mach-ecovec24/setup.c1
-rw-r--r--arch/sh/boards/mach-kfr2r09/setup.c1
-rw-r--r--arch/sh/boards/mach-migor/setup.c1
-rw-r--r--arch/sh/boards/mach-se/7724/setup.c1
-rw-r--r--drivers/mmc/card/block.c45
-rw-r--r--drivers/mmc/core/Kconfig21
-rw-r--r--drivers/mmc/core/Makefile4
-rw-r--r--drivers/mmc/core/core.c12
-rw-r--r--drivers/mmc/core/host.c22
-rw-r--r--drivers/mmc/core/mmc.c64
-rw-r--r--drivers/mmc/core/pwrseq.c108
-rw-r--r--drivers/mmc/core/pwrseq.h19
-rw-r--r--drivers/mmc/core/pwrseq_emmc.c81
-rw-r--r--drivers/mmc/core/pwrseq_simple.c91
-rw-r--r--drivers/mmc/core/sdio_cis.c7
-rw-r--r--drivers/mmc/host/Kconfig4
-rw-r--r--drivers/mmc/host/atmel-mci.c9
-rw-r--r--drivers/mmc/host/davinci_mmc.c151
-rw-r--r--drivers/mmc/host/dw_mmc-exynos.c23
-rw-r--r--drivers/mmc/host/dw_mmc-rockchip.c43
-rw-r--r--drivers/mmc/host/dw_mmc.c11
-rw-r--r--drivers/mmc/host/dw_mmc.h2
-rw-r--r--drivers/mmc/host/mmci.c20
-rw-r--r--drivers/mmc/host/mtk-sd.c19
-rw-r--r--drivers/mmc/host/omap.c48
-rw-r--r--drivers/mmc/host/omap_hsmmc.c90
-rw-r--r--drivers/mmc/host/sdhci-acpi.c9
-rw-r--r--drivers/mmc/host/sdhci-of-arasan.c26
-rw-r--r--drivers/mmc/host/sdhci-of-at91.c74
-rw-r--r--drivers/mmc/host/sdhci-pci-core.c9
-rw-r--r--drivers/mmc/host/sdhci-pic32.c1
-rw-r--r--drivers/mmc/host/sdhci-pltfm.c42
-rw-r--r--drivers/mmc/host/sdhci.c320
-rw-r--r--drivers/mmc/host/sdhci.h10
-rw-r--r--drivers/mmc/host/sh_mmcif.c74
-rw-r--r--drivers/mmc/host/sh_mobile_sdhi.c194
-rw-r--r--drivers/mmc/host/tmio_mmc.h75
-rw-r--r--drivers/mmc/host/tmio_mmc_dma.c1
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c196
-rw-r--r--drivers/mmc/host/usdhi6rol0.c60
-rw-r--r--include/linux/mfd/tmio.h4
-rw-r--r--include/linux/mmc/dw_mmc.h12
-rw-r--r--include/linux/mmc/host.h31
-rw-r--r--include/linux/mmc/sh_mobile_sdhi.h10
-rw-r--r--include/linux/mmc/tmio.h71
-rw-r--r--include/trace/events/mmc.h182
54 files changed, 1262 insertions, 1097 deletions
diff --git a/Documentation/devicetree/bindings/mmc/sdhci-st.txt b/Documentation/devicetree/bindings/mmc/sdhci-st.txt
index 18d950df2749..88faa91125bf 100644
--- a/Documentation/devicetree/bindings/mmc/sdhci-st.txt
+++ b/Documentation/devicetree/bindings/mmc/sdhci-st.txt
@@ -38,7 +38,7 @@ Optional properties:
38- bus-width: Number of data lines. 38- bus-width: Number of data lines.
39 See: Documentation/devicetree/bindings/mmc/mmc.txt. 39 See: Documentation/devicetree/bindings/mmc/mmc.txt.
40 40
41- max-frequency: Can be 200MHz, 100Mz or 50MHz (default) and used for 41- max-frequency: Can be 200MHz, 100Mz or 50MHz (default) and used for
42 configuring the CCONFIG3 in the mmcss. 42 configuring the CCONFIG3 in the mmcss.
43 See: Documentation/devicetree/bindings/mmc/mmc.txt. 43 See: Documentation/devicetree/bindings/mmc/mmc.txt.
44 44
@@ -48,7 +48,7 @@ Optional properties:
48- vqmmc-supply: Phandle to the regulator dt node, mentioned as the vcc/vdd 48- vqmmc-supply: Phandle to the regulator dt node, mentioned as the vcc/vdd
49 supply in eMMC/SD specs. 49 supply in eMMC/SD specs.
50 50
51- sd-uhs--sdr50: To enable the SDR50 in the mmcss. 51- sd-uhs-sdr50: To enable the SDR50 in the mmcss.
52 See: Documentation/devicetree/bindings/mmc/mmc.txt. 52 See: Documentation/devicetree/bindings/mmc/mmc.txt.
53 53
54- sd-uhs-sdr104: To enable the SDR104 in the mmcss. 54- sd-uhs-sdr104: To enable the SDR104 in the mmcss.
diff --git a/Documentation/devicetree/bindings/mmc/tmio_mmc.txt b/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
index 7fb746dd1a68..0f610d4b5b00 100644
--- a/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
+++ b/Documentation/devicetree/bindings/mmc/tmio_mmc.txt
@@ -26,3 +26,6 @@ Required properties:
26 26
27Optional properties: 27Optional properties:
28- toshiba,mmc-wrprotect-disable: write-protect detection is unavailable 28- toshiba,mmc-wrprotect-disable: write-protect detection is unavailable
29- pinctrl-names: should be "default", "state_uhs"
30- pinctrl-0: should contain default/high speed pin ctrl
31- pinctrl-1: should contain uhs mode pin ctrl
diff --git a/Documentation/devicetree/bindings/mmc/usdhi6rol0.txt b/Documentation/devicetree/bindings/mmc/usdhi6rol0.txt
index 8babdaa8623b..6d1b7971d078 100644
--- a/Documentation/devicetree/bindings/mmc/usdhi6rol0.txt
+++ b/Documentation/devicetree/bindings/mmc/usdhi6rol0.txt
@@ -12,6 +12,12 @@ Optional properties:
12 12
13- vmmc-supply: a phandle of a regulator, supplying Vcc to the card 13- vmmc-supply: a phandle of a regulator, supplying Vcc to the card
14- vqmmc-supply: a phandle of a regulator, supplying VccQ to the card 14- vqmmc-supply: a phandle of a regulator, supplying VccQ to the card
15- pinctrl-names: Can contain a "default" entry and a "state_uhs"
16 entry. The state_uhs entry is used together with the default
17 entry when the board requires distinct settings for UHS speeds.
18
19- pinctrl-N: One property for each name listed in pinctrl-names, see
20 ../pinctrl/pinctrl-bindings.txt.
15 21
16Additionally any standard mmc bindings from mmc.txt can be used. 22Additionally any standard mmc bindings from mmc.txt can be used.
17 23
diff --git a/MAINTAINERS b/MAINTAINERS
index ca373daf8b68..d2b9b80ffe30 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11246,14 +11246,13 @@ S: Maintained
11246F: drivers/media/i2c/tc358743* 11246F: drivers/media/i2c/tc358743*
11247F: include/media/i2c/tc358743.h 11247F: include/media/i2c/tc358743.h
11248 11248
11249TMIO MMC DRIVER 11249TMIO/SDHI MMC DRIVER
11250M: Ian Molton <ian@mnementh.co.uk> 11250M: Wolfram Sang <wsa+renesas@sang-engineering.com>
11251L: linux-mmc@vger.kernel.org 11251L: linux-mmc@vger.kernel.org
11252S: Maintained 11252S: Supported
11253F: drivers/mmc/host/tmio_mmc* 11253F: drivers/mmc/host/tmio_mmc*
11254F: drivers/mmc/host/sh_mobile_sdhi.c 11254F: drivers/mmc/host/sh_mobile_sdhi.c
11255F: include/linux/mmc/tmio.h 11255F: include/linux/mfd/tmio.h
11256F: include/linux/mmc/sh_mobile_sdhi.h
11257 11256
11258TMP401 HARDWARE MONITOR DRIVER 11257TMP401 HARDWARE MONITOR DRIVER
11259M: Guenter Roeck <linux@roeck-us.net> 11258M: Guenter Roeck <linux@roeck-us.net>
diff --git a/arch/arm/mach-davinci/devices-da8xx.c b/arch/arm/mach-davinci/devices-da8xx.c
index 725e693639d2..add3771d38f6 100644
--- a/arch/arm/mach-davinci/devices-da8xx.c
+++ b/arch/arm/mach-davinci/devices-da8xx.c
@@ -751,16 +751,6 @@ static struct resource da8xx_mmcsd0_resources[] = {
751 .end = IRQ_DA8XX_MMCSDINT0, 751 .end = IRQ_DA8XX_MMCSDINT0,
752 .flags = IORESOURCE_IRQ, 752 .flags = IORESOURCE_IRQ,
753 }, 753 },
754 { /* DMA RX */
755 .start = DA8XX_DMA_MMCSD0_RX,
756 .end = DA8XX_DMA_MMCSD0_RX,
757 .flags = IORESOURCE_DMA,
758 },
759 { /* DMA TX */
760 .start = DA8XX_DMA_MMCSD0_TX,
761 .end = DA8XX_DMA_MMCSD0_TX,
762 .flags = IORESOURCE_DMA,
763 },
764}; 754};
765 755
766static struct platform_device da8xx_mmcsd0_device = { 756static struct platform_device da8xx_mmcsd0_device = {
@@ -788,16 +778,6 @@ static struct resource da850_mmcsd1_resources[] = {
788 .end = IRQ_DA850_MMCSDINT0_1, 778 .end = IRQ_DA850_MMCSDINT0_1,
789 .flags = IORESOURCE_IRQ, 779 .flags = IORESOURCE_IRQ,
790 }, 780 },
791 { /* DMA RX */
792 .start = DA850_DMA_MMCSD1_RX,
793 .end = DA850_DMA_MMCSD1_RX,
794 .flags = IORESOURCE_DMA,
795 },
796 { /* DMA TX */
797 .start = DA850_DMA_MMCSD1_TX,
798 .end = DA850_DMA_MMCSD1_TX,
799 .flags = IORESOURCE_DMA,
800 },
801}; 781};
802 782
803static struct platform_device da850_mmcsd1_device = { 783static struct platform_device da850_mmcsd1_device = {
diff --git a/arch/arm/mach-davinci/devices.c b/arch/arm/mach-davinci/devices.c
index 6257aa452568..67d26c5bda0b 100644
--- a/arch/arm/mach-davinci/devices.c
+++ b/arch/arm/mach-davinci/devices.c
@@ -144,14 +144,6 @@ static struct resource mmcsd0_resources[] = {
144 .start = IRQ_SDIOINT, 144 .start = IRQ_SDIOINT,
145 .flags = IORESOURCE_IRQ, 145 .flags = IORESOURCE_IRQ,
146 }, 146 },
147 /* DMA channels: RX, then TX */
148 {
149 .start = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCRXEVT),
150 .flags = IORESOURCE_DMA,
151 }, {
152 .start = EDMA_CTLR_CHAN(0, DAVINCI_DMA_MMCTXEVT),
153 .flags = IORESOURCE_DMA,
154 },
155}; 147};
156 148
157static struct platform_device davinci_mmcsd0_device = { 149static struct platform_device davinci_mmcsd0_device = {
@@ -181,14 +173,6 @@ static struct resource mmcsd1_resources[] = {
181 .start = IRQ_DM355_SDIOINT1, 173 .start = IRQ_DM355_SDIOINT1,
182 .flags = IORESOURCE_IRQ, 174 .flags = IORESOURCE_IRQ,
183 }, 175 },
184 /* DMA channels: RX, then TX */
185 {
186 .start = EDMA_CTLR_CHAN(0, 30), /* rx */
187 .flags = IORESOURCE_DMA,
188 }, {
189 .start = EDMA_CTLR_CHAN(0, 31), /* tx */
190 .flags = IORESOURCE_DMA,
191 },
192}; 176};
193 177
194static struct platform_device davinci_mmcsd1_device = { 178static struct platform_device davinci_mmcsd1_device = {
diff --git a/arch/sh/boards/board-sh7757lcr.c b/arch/sh/boards/board-sh7757lcr.c
index 324599bfad14..0104c8199c48 100644
--- a/arch/sh/boards/board-sh7757lcr.c
+++ b/arch/sh/boards/board-sh7757lcr.c
@@ -20,7 +20,6 @@
20#include <linux/mfd/tmio.h> 20#include <linux/mfd/tmio.h>
21#include <linux/mmc/host.h> 21#include <linux/mmc/host.h>
22#include <linux/mmc/sh_mmcif.h> 22#include <linux/mmc/sh_mmcif.h>
23#include <linux/mmc/sh_mobile_sdhi.h>
24#include <linux/sh_eth.h> 23#include <linux/sh_eth.h>
25#include <linux/sh_intc.h> 24#include <linux/sh_intc.h>
26#include <linux/usb/renesas_usbhs.h> 25#include <linux/usb/renesas_usbhs.h>
diff --git a/arch/sh/boards/mach-ap325rxa/setup.c b/arch/sh/boards/mach-ap325rxa/setup.c
index 62c3b81300ed..de8393cb7313 100644
--- a/arch/sh/boards/mach-ap325rxa/setup.c
+++ b/arch/sh/boards/mach-ap325rxa/setup.c
@@ -15,7 +15,6 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/mmc/host.h> 17#include <linux/mmc/host.h>
18#include <linux/mmc/sh_mobile_sdhi.h>
19#include <linux/mtd/physmap.h> 18#include <linux/mtd/physmap.h>
20#include <linux/mtd/sh_flctl.h> 19#include <linux/mtd/sh_flctl.h>
21#include <linux/mfd/tmio.h> 20#include <linux/mfd/tmio.h>
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index a9c0c07386fd..6d612792f6b8 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -13,7 +13,6 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/mmc/host.h> 14#include <linux/mmc/host.h>
15#include <linux/mmc/sh_mmcif.h> 15#include <linux/mmc/sh_mmcif.h>
16#include <linux/mmc/sh_mobile_sdhi.h>
17#include <linux/mtd/physmap.h> 16#include <linux/mtd/physmap.h>
18#include <linux/mfd/tmio.h> 17#include <linux/mfd/tmio.h>
19#include <linux/gpio.h> 18#include <linux/gpio.h>
diff --git a/arch/sh/boards/mach-kfr2r09/setup.c b/arch/sh/boards/mach-kfr2r09/setup.c
index 6bd9230e64e3..5deb2d82f19f 100644
--- a/arch/sh/boards/mach-kfr2r09/setup.c
+++ b/arch/sh/boards/mach-kfr2r09/setup.c
@@ -11,7 +11,6 @@
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/mmc/host.h> 13#include <linux/mmc/host.h>
14#include <linux/mmc/sh_mobile_sdhi.h>
15#include <linux/mfd/tmio.h> 14#include <linux/mfd/tmio.h>
16#include <linux/mtd/physmap.h> 15#include <linux/mtd/physmap.h>
17#include <linux/mtd/onenand.h> 16#include <linux/mtd/onenand.h>
diff --git a/arch/sh/boards/mach-migor/setup.c b/arch/sh/boards/mach-migor/setup.c
index 7a04da3efce4..5de60a77eaa1 100644
--- a/arch/sh/boards/mach-migor/setup.c
+++ b/arch/sh/boards/mach-migor/setup.c
@@ -13,7 +13,6 @@
13#include <linux/input.h> 13#include <linux/input.h>
14#include <linux/input/sh_keysc.h> 14#include <linux/input/sh_keysc.h>
15#include <linux/mmc/host.h> 15#include <linux/mmc/host.h>
16#include <linux/mmc/sh_mobile_sdhi.h>
17#include <linux/mtd/physmap.h> 16#include <linux/mtd/physmap.h>
18#include <linux/mfd/tmio.h> 17#include <linux/mfd/tmio.h>
19#include <linux/mtd/nand.h> 18#include <linux/mtd/nand.h>
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
index e0e1df136642..f1fecd395679 100644
--- a/arch/sh/boards/mach-se/7724/setup.c
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -15,7 +15,6 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/mmc/host.h> 17#include <linux/mmc/host.h>
18#include <linux/mmc/sh_mobile_sdhi.h>
19#include <linux/mfd/tmio.h> 18#include <linux/mfd/tmio.h>
20#include <linux/mtd/physmap.h> 19#include <linux/mtd/physmap.h>
21#include <linux/delay.h> 20#include <linux/delay.h>
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 8a0147dfed27..5f2a3d69344f 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -35,6 +35,7 @@
35#include <linux/capability.h> 35#include <linux/capability.h>
36#include <linux/compat.h> 36#include <linux/compat.h>
37#include <linux/pm_runtime.h> 37#include <linux/pm_runtime.h>
38#include <linux/idr.h>
38 39
39#include <linux/mmc/ioctl.h> 40#include <linux/mmc/ioctl.h>
40#include <linux/mmc/card.h> 41#include <linux/mmc/card.h>
@@ -78,14 +79,14 @@ static int perdev_minors = CONFIG_MMC_BLOCK_MINORS;
78/* 79/*
79 * We've only got one major, so number of mmcblk devices is 80 * We've only got one major, so number of mmcblk devices is
80 * limited to (1 << 20) / number of minors per device. It is also 81 * limited to (1 << 20) / number of minors per device. It is also
81 * currently limited by the size of the static bitmaps below. 82 * limited by the MAX_DEVICES below.
82 */ 83 */
83static int max_devices; 84static int max_devices;
84 85
85#define MAX_DEVICES 256 86#define MAX_DEVICES 256
86 87
87/* TODO: Replace these with struct ida */ 88static DEFINE_IDA(mmc_blk_ida);
88static DECLARE_BITMAP(dev_use, MAX_DEVICES); 89static DEFINE_SPINLOCK(mmc_blk_lock);
89 90
90/* 91/*
91 * There is one mmc_blk_data per slot. 92 * There is one mmc_blk_data per slot.
@@ -178,7 +179,9 @@ static void mmc_blk_put(struct mmc_blk_data *md)
178 int devidx = mmc_get_devidx(md->disk); 179 int devidx = mmc_get_devidx(md->disk);
179 blk_cleanup_queue(md->queue.queue); 180 blk_cleanup_queue(md->queue.queue);
180 181
181 __clear_bit(devidx, dev_use); 182 spin_lock(&mmc_blk_lock);
183 ida_remove(&mmc_blk_ida, devidx);
184 spin_unlock(&mmc_blk_lock);
182 185
183 put_disk(md->disk); 186 put_disk(md->disk);
184 kfree(md); 187 kfree(md);
@@ -945,16 +948,22 @@ static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
945 req->rq_disk->disk_name, "timed out", name, status); 948 req->rq_disk->disk_name, "timed out", name, status);
946 949
947 /* If the status cmd initially failed, retry the r/w cmd */ 950 /* If the status cmd initially failed, retry the r/w cmd */
948 if (!status_valid) 951 if (!status_valid) {
952 pr_err("%s: status not valid, retrying timeout\n",
953 req->rq_disk->disk_name);
949 return ERR_RETRY; 954 return ERR_RETRY;
955 }
950 956
951 /* 957 /*
952 * If it was a r/w cmd crc error, or illegal command 958 * If it was a r/w cmd crc error, or illegal command
953 * (eg, issued in wrong state) then retry - we should 959 * (eg, issued in wrong state) then retry - we should
954 * have corrected the state problem above. 960 * have corrected the state problem above.
955 */ 961 */
956 if (status & (R1_COM_CRC_ERROR | R1_ILLEGAL_COMMAND)) 962 if (status & (R1_COM_CRC_ERROR | R1_ILLEGAL_COMMAND)) {
963 pr_err("%s: command error, retrying timeout\n",
964 req->rq_disk->disk_name);
957 return ERR_RETRY; 965 return ERR_RETRY;
966 }
958 967
959 /* Otherwise abort the command */ 968 /* Otherwise abort the command */
960 return ERR_ABORT; 969 return ERR_ABORT;
@@ -2189,10 +2198,23 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
2189 struct mmc_blk_data *md; 2198 struct mmc_blk_data *md;
2190 int devidx, ret; 2199 int devidx, ret;
2191 2200
2192 devidx = find_first_zero_bit(dev_use, max_devices); 2201again:
2193 if (devidx >= max_devices) 2202 if (!ida_pre_get(&mmc_blk_ida, GFP_KERNEL))
2194 return ERR_PTR(-ENOSPC); 2203 return ERR_PTR(-ENOMEM);
2195 __set_bit(devidx, dev_use); 2204
2205 spin_lock(&mmc_blk_lock);
2206 ret = ida_get_new(&mmc_blk_ida, &devidx);
2207 spin_unlock(&mmc_blk_lock);
2208
2209 if (ret == -EAGAIN)
2210 goto again;
2211 else if (ret)
2212 return ERR_PTR(ret);
2213
2214 if (devidx >= max_devices) {
2215 ret = -ENOSPC;
2216 goto out;
2217 }
2196 2218
2197 md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL); 2219 md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
2198 if (!md) { 2220 if (!md) {
@@ -2289,6 +2311,9 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
2289 err_kfree: 2311 err_kfree:
2290 kfree(md); 2312 kfree(md);
2291 out: 2313 out:
2314 spin_lock(&mmc_blk_lock);
2315 ida_remove(&mmc_blk_ida, devidx);
2316 spin_unlock(&mmc_blk_lock);
2292 return ERR_PTR(ret); 2317 return ERR_PTR(ret);
2293} 2318}
2294 2319
diff --git a/drivers/mmc/core/Kconfig b/drivers/mmc/core/Kconfig
index 4c33d7690f2f..250f223aaa80 100644
--- a/drivers/mmc/core/Kconfig
+++ b/drivers/mmc/core/Kconfig
@@ -1,3 +1,24 @@
1# 1#
2# MMC core configuration 2# MMC core configuration
3# 3#
4config PWRSEQ_EMMC
5 tristate "HW reset support for eMMC"
6 default y
7 depends on OF
8 help
9 This selects Hardware reset support aka pwrseq-emmc for eMMC
10 devices. By default this option is set to y.
11
12 This driver can also be built as a module. If so, the module
13 will be called pwrseq_emmc.
14
15config PWRSEQ_SIMPLE
16 tristate "Simple HW reset support for MMC"
17 default y
18 depends on OF
19 help
20 This selects simple hardware reset support aka pwrseq-simple for MMC
21 devices. By default this option is set to y.
22
23 This driver can also be built as a module. If so, the module
24 will be called pwrseq_simple.
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index 2c25138f28b7..f007151dfdc6 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -8,5 +8,7 @@ mmc_core-y := core.o bus.o host.o \
8 sdio.o sdio_ops.o sdio_bus.o \ 8 sdio.o sdio_ops.o sdio_bus.o \
9 sdio_cis.o sdio_io.o sdio_irq.o \ 9 sdio_cis.o sdio_io.o sdio_irq.o \
10 quirks.o slot-gpio.o 10 quirks.o slot-gpio.o
11mmc_core-$(CONFIG_OF) += pwrseq.o pwrseq_simple.o pwrseq_emmc.o 11mmc_core-$(CONFIG_OF) += pwrseq.o
12obj-$(CONFIG_PWRSEQ_SIMPLE) += pwrseq_simple.o
13obj-$(CONFIG_PWRSEQ_EMMC) += pwrseq_emmc.o
12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o 14mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 41b1e761965f..99275e40bf2f 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -36,6 +36,9 @@
36#include <linux/mmc/sd.h> 36#include <linux/mmc/sd.h>
37#include <linux/mmc/slot-gpio.h> 37#include <linux/mmc/slot-gpio.h>
38 38
39#define CREATE_TRACE_POINTS
40#include <trace/events/mmc.h>
41
39#include "core.h" 42#include "core.h"
40#include "bus.h" 43#include "bus.h"
41#include "host.h" 44#include "host.h"
@@ -140,6 +143,8 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
140 cmd->retries = 0; 143 cmd->retries = 0;
141 } 144 }
142 145
146 trace_mmc_request_done(host, mrq);
147
143 if (err && cmd->retries && !mmc_card_removed(host->card)) { 148 if (err && cmd->retries && !mmc_card_removed(host->card)) {
144 /* 149 /*
145 * Request starter must handle retries - see 150 * Request starter must handle retries - see
@@ -215,6 +220,8 @@ static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
215 } 220 }
216 } 221 }
217 222
223 trace_mmc_request_start(host, mrq);
224
218 host->ops->request(host, mrq); 225 host->ops->request(host, mrq);
219} 226}
220 227
@@ -2449,8 +2456,9 @@ int mmc_hw_reset(struct mmc_host *host)
2449 ret = host->bus_ops->reset(host); 2456 ret = host->bus_ops->reset(host);
2450 mmc_bus_put(host); 2457 mmc_bus_put(host);
2451 2458
2452 if (ret != -EOPNOTSUPP) 2459 if (ret)
2453 pr_warn("%s: tried to reset card\n", mmc_hostname(host)); 2460 pr_warn("%s: tried to reset card, got error %d\n",
2461 mmc_hostname(host), ret);
2454 2462
2455 return ret; 2463 return ret;
2456} 2464}
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 6e4c55a4aab5..e0a3ee16c0d3 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -33,14 +33,14 @@
33 33
34#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev) 34#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
35 35
36static DEFINE_IDR(mmc_host_idr); 36static DEFINE_IDA(mmc_host_ida);
37static DEFINE_SPINLOCK(mmc_host_lock); 37static DEFINE_SPINLOCK(mmc_host_lock);
38 38
39static void mmc_host_classdev_release(struct device *dev) 39static void mmc_host_classdev_release(struct device *dev)
40{ 40{
41 struct mmc_host *host = cls_dev_to_mmc_host(dev); 41 struct mmc_host *host = cls_dev_to_mmc_host(dev);
42 spin_lock(&mmc_host_lock); 42 spin_lock(&mmc_host_lock);
43 idr_remove(&mmc_host_idr, host->index); 43 ida_remove(&mmc_host_ida, host->index);
44 spin_unlock(&mmc_host_lock); 44 spin_unlock(&mmc_host_lock);
45 kfree(host); 45 kfree(host);
46} 46}
@@ -321,14 +321,20 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
321 321
322 /* scanning will be enabled when we're ready */ 322 /* scanning will be enabled when we're ready */
323 host->rescan_disable = 1; 323 host->rescan_disable = 1;
324 idr_preload(GFP_KERNEL); 324
325again:
326 if (!ida_pre_get(&mmc_host_ida, GFP_KERNEL)) {
327 kfree(host);
328 return NULL;
329 }
330
325 spin_lock(&mmc_host_lock); 331 spin_lock(&mmc_host_lock);
326 err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT); 332 err = ida_get_new(&mmc_host_ida, &host->index);
327 if (err >= 0)
328 host->index = err;
329 spin_unlock(&mmc_host_lock); 333 spin_unlock(&mmc_host_lock);
330 idr_preload_end(); 334
331 if (err < 0) { 335 if (err == -EAGAIN) {
336 goto again;
337 } else if (err) {
332 kfree(host); 338 kfree(host);
333 return NULL; 339 return NULL;
334 } 340 }
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 4dbe3df8024b..b81b08f81325 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -333,6 +333,9 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
333 } 333 }
334} 334}
335 335
336/* Minimum partition switch timeout in milliseconds */
337#define MMC_MIN_PART_SWITCH_TIME 300
338
336/* 339/*
337 * Decode extended CSD. 340 * Decode extended CSD.
338 */ 341 */
@@ -397,6 +400,10 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
397 400
398 /* EXT_CSD value is in units of 10ms, but we store in ms */ 401 /* EXT_CSD value is in units of 10ms, but we store in ms */
399 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; 402 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME];
403 /* Some eMMC set the value too low so set a minimum */
404 if (card->ext_csd.part_time &&
405 card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME)
406 card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME;
400 407
401 /* Sleep / awake timeout in 100ns units */ 408 /* Sleep / awake timeout in 100ns units */
402 if (sa_shift > 0 && sa_shift <= 0x17) 409 if (sa_shift > 0 && sa_shift <= 0x17)
@@ -1244,10 +1251,11 @@ static int mmc_select_hs200(struct mmc_card *card)
1244{ 1251{
1245 struct mmc_host *host = card->host; 1252 struct mmc_host *host = card->host;
1246 bool send_status = true; 1253 bool send_status = true;
1247 unsigned int old_timing; 1254 unsigned int old_timing, old_signal_voltage;
1248 int err = -EINVAL; 1255 int err = -EINVAL;
1249 u8 val; 1256 u8 val;
1250 1257
1258 old_signal_voltage = host->ios.signal_voltage;
1251 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V) 1259 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V)
1252 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120); 1260 err = __mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120);
1253 1261
@@ -1256,7 +1264,7 @@ static int mmc_select_hs200(struct mmc_card *card)
1256 1264
1257 /* If fails try again during next card power cycle */ 1265 /* If fails try again during next card power cycle */
1258 if (err) 1266 if (err)
1259 goto err; 1267 return err;
1260 1268
1261 mmc_select_driver_type(card); 1269 mmc_select_driver_type(card);
1262 1270
@@ -1290,9 +1298,14 @@ static int mmc_select_hs200(struct mmc_card *card)
1290 } 1298 }
1291 } 1299 }
1292err: 1300err:
1293 if (err) 1301 if (err) {
1302 /* fall back to the old signal voltage, if fails report error */
1303 if (__mmc_set_signal_voltage(host, old_signal_voltage))
1304 err = -EIO;
1305
1294 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), 1306 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host),
1295 __func__, err); 1307 __func__, err);
1308 }
1296 return err; 1309 return err;
1297} 1310}
1298 1311
@@ -1314,21 +1327,13 @@ static int mmc_select_timing(struct mmc_card *card)
1314 if (err && err != -EBADMSG) 1327 if (err && err != -EBADMSG)
1315 return err; 1328 return err;
1316 1329
1317 if (err) {
1318 pr_warn("%s: switch to %s failed\n",
1319 mmc_card_hs(card) ? "high-speed" :
1320 (mmc_card_hs200(card) ? "hs200" : ""),
1321 mmc_hostname(card->host));
1322 err = 0;
1323 }
1324
1325bus_speed: 1330bus_speed:
1326 /* 1331 /*
1327 * Set the bus speed to the selected bus timing. 1332 * Set the bus speed to the selected bus timing.
1328 * If timing is not selected, backward compatible is the default. 1333 * If timing is not selected, backward compatible is the default.
1329 */ 1334 */
1330 mmc_set_bus_speed(card); 1335 mmc_set_bus_speed(card);
1331 return err; 1336 return 0;
1332} 1337}
1333 1338
1334/* 1339/*
@@ -1483,12 +1488,13 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1483 if (err) 1488 if (err)
1484 goto free_card; 1489 goto free_card;
1485 1490
1486 /* If doing byte addressing, check if required to do sector 1491 /*
1492 * If doing byte addressing, check if required to do sector
1487 * addressing. Handle the case of <2GB cards needing sector 1493 * addressing. Handle the case of <2GB cards needing sector
1488 * addressing. See section 8.1 JEDEC Standard JED84-A441; 1494 * addressing. See section 8.1 JEDEC Standard JED84-A441;
1489 * ocr register has bit 30 set for sector addressing. 1495 * ocr register has bit 30 set for sector addressing.
1490 */ 1496 */
1491 if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30))) 1497 if (rocr & BIT(30))
1492 mmc_card_set_blockaddr(card); 1498 mmc_card_set_blockaddr(card);
1493 1499
1494 /* Erase size depends on CSD and Extended CSD */ 1500 /* Erase size depends on CSD and Extended CSD */
@@ -1957,19 +1963,23 @@ static int mmc_reset(struct mmc_host *host)
1957{ 1963{
1958 struct mmc_card *card = host->card; 1964 struct mmc_card *card = host->card;
1959 1965
1960 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset) 1966 /*
1961 return -EOPNOTSUPP; 1967 * In the case of recovery, we can't expect flushing the cache to work
1962 1968 * always, but we have a go and ignore errors.
1963 if (!mmc_can_reset(card)) 1969 */
1964 return -EOPNOTSUPP; 1970 mmc_flush_cache(host->card);
1965 1971
1966 mmc_set_clock(host, host->f_init); 1972 if ((host->caps & MMC_CAP_HW_RESET) && host->ops->hw_reset &&
1967 1973 mmc_can_reset(card)) {
1968 host->ops->hw_reset(host); 1974 /* If the card accept RST_n signal, send it. */
1969 1975 mmc_set_clock(host, host->f_init);
1970 /* Set initial state and call mmc_set_ios */ 1976 host->ops->hw_reset(host);
1971 mmc_set_initial_state(host); 1977 /* Set initial state and call mmc_set_ios */
1972 1978 mmc_set_initial_state(host);
1979 } else {
1980 /* Do a brute force power cycle */
1981 mmc_power_cycle(host, card->ocr);
1982 }
1973 return mmc_init_card(host, card->ocr, card); 1983 return mmc_init_card(host, card->ocr, card);
1974} 1984}
1975 1985
diff --git a/drivers/mmc/core/pwrseq.c b/drivers/mmc/core/pwrseq.c
index 4c1d1757dbf9..9386c4771814 100644
--- a/drivers/mmc/core/pwrseq.c
+++ b/drivers/mmc/core/pwrseq.c
@@ -8,88 +8,55 @@
8 * MMC power sequence management 8 * MMC power sequence management
9 */ 9 */
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/platform_device.h>
12#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/module.h>
13#include <linux/of.h> 13#include <linux/of.h>
14#include <linux/of_platform.h>
15 14
16#include <linux/mmc/host.h> 15#include <linux/mmc/host.h>
17 16
18#include "pwrseq.h" 17#include "pwrseq.h"
19 18
20struct mmc_pwrseq_match { 19static DEFINE_MUTEX(pwrseq_list_mutex);
21 const char *compatible; 20static LIST_HEAD(pwrseq_list);
22 struct mmc_pwrseq *(*alloc)(struct mmc_host *host, struct device *dev);
23};
24
25static struct mmc_pwrseq_match pwrseq_match[] = {
26 {
27 .compatible = "mmc-pwrseq-simple",
28 .alloc = mmc_pwrseq_simple_alloc,
29 }, {
30 .compatible = "mmc-pwrseq-emmc",
31 .alloc = mmc_pwrseq_emmc_alloc,
32 },
33};
34
35static struct mmc_pwrseq_match *mmc_pwrseq_find(struct device_node *np)
36{
37 struct mmc_pwrseq_match *match = ERR_PTR(-ENODEV);
38 int i;
39
40 for (i = 0; i < ARRAY_SIZE(pwrseq_match); i++) {
41 if (of_device_is_compatible(np, pwrseq_match[i].compatible)) {
42 match = &pwrseq_match[i];
43 break;
44 }
45 }
46
47 return match;
48}
49 21
50int mmc_pwrseq_alloc(struct mmc_host *host) 22int mmc_pwrseq_alloc(struct mmc_host *host)
51{ 23{
52 struct platform_device *pdev;
53 struct device_node *np; 24 struct device_node *np;
54 struct mmc_pwrseq_match *match; 25 struct mmc_pwrseq *p;
55 struct mmc_pwrseq *pwrseq;
56 int ret = 0;
57 26
58 np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0); 27 np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0);
59 if (!np) 28 if (!np)
60 return 0; 29 return 0;
61 30
62 pdev = of_find_device_by_node(np); 31 mutex_lock(&pwrseq_list_mutex);
63 if (!pdev) { 32 list_for_each_entry(p, &pwrseq_list, pwrseq_node) {
64 ret = -ENODEV; 33 if (p->dev->of_node == np) {
65 goto err; 34 if (!try_module_get(p->owner))
66 } 35 dev_err(host->parent,
36 "increasing module refcount failed\n");
37 else
38 host->pwrseq = p;
67 39
68 match = mmc_pwrseq_find(np); 40 break;
69 if (IS_ERR(match)) { 41 }
70 ret = PTR_ERR(match);
71 goto err;
72 } 42 }
73 43
74 pwrseq = match->alloc(host, &pdev->dev); 44 of_node_put(np);
75 if (IS_ERR(pwrseq)) { 45 mutex_unlock(&pwrseq_list_mutex);
76 ret = PTR_ERR(pwrseq); 46
77 goto err; 47 if (!host->pwrseq)
78 } 48 return -EPROBE_DEFER;
79 49
80 host->pwrseq = pwrseq;
81 dev_info(host->parent, "allocated mmc-pwrseq\n"); 50 dev_info(host->parent, "allocated mmc-pwrseq\n");
82 51
83err: 52 return 0;
84 of_node_put(np);
85 return ret;
86} 53}
87 54
88void mmc_pwrseq_pre_power_on(struct mmc_host *host) 55void mmc_pwrseq_pre_power_on(struct mmc_host *host)
89{ 56{
90 struct mmc_pwrseq *pwrseq = host->pwrseq; 57 struct mmc_pwrseq *pwrseq = host->pwrseq;
91 58
92 if (pwrseq && pwrseq->ops && pwrseq->ops->pre_power_on) 59 if (pwrseq && pwrseq->ops->pre_power_on)
93 pwrseq->ops->pre_power_on(host); 60 pwrseq->ops->pre_power_on(host);
94} 61}
95 62
@@ -97,7 +64,7 @@ void mmc_pwrseq_post_power_on(struct mmc_host *host)
97{ 64{
98 struct mmc_pwrseq *pwrseq = host->pwrseq; 65 struct mmc_pwrseq *pwrseq = host->pwrseq;
99 66
100 if (pwrseq && pwrseq->ops && pwrseq->ops->post_power_on) 67 if (pwrseq && pwrseq->ops->post_power_on)
101 pwrseq->ops->post_power_on(host); 68 pwrseq->ops->post_power_on(host);
102} 69}
103 70
@@ -105,7 +72,7 @@ void mmc_pwrseq_power_off(struct mmc_host *host)
105{ 72{
106 struct mmc_pwrseq *pwrseq = host->pwrseq; 73 struct mmc_pwrseq *pwrseq = host->pwrseq;
107 74
108 if (pwrseq && pwrseq->ops && pwrseq->ops->power_off) 75 if (pwrseq && pwrseq->ops->power_off)
109 pwrseq->ops->power_off(host); 76 pwrseq->ops->power_off(host);
110} 77}
111 78
@@ -113,8 +80,31 @@ void mmc_pwrseq_free(struct mmc_host *host)
113{ 80{
114 struct mmc_pwrseq *pwrseq = host->pwrseq; 81 struct mmc_pwrseq *pwrseq = host->pwrseq;
115 82
116 if (pwrseq && pwrseq->ops && pwrseq->ops->free) 83 if (pwrseq) {
117 pwrseq->ops->free(host); 84 module_put(pwrseq->owner);
85 host->pwrseq = NULL;
86 }
87}
88
89int mmc_pwrseq_register(struct mmc_pwrseq *pwrseq)
90{
91 if (!pwrseq || !pwrseq->ops || !pwrseq->dev)
92 return -EINVAL;
118 93
119 host->pwrseq = NULL; 94 mutex_lock(&pwrseq_list_mutex);
95 list_add(&pwrseq->pwrseq_node, &pwrseq_list);
96 mutex_unlock(&pwrseq_list_mutex);
97
98 return 0;
99}
100EXPORT_SYMBOL_GPL(mmc_pwrseq_register);
101
102void mmc_pwrseq_unregister(struct mmc_pwrseq *pwrseq)
103{
104 if (pwrseq) {
105 mutex_lock(&pwrseq_list_mutex);
106 list_del(&pwrseq->pwrseq_node);
107 mutex_unlock(&pwrseq_list_mutex);
108 }
120} 109}
110EXPORT_SYMBOL_GPL(mmc_pwrseq_unregister);
diff --git a/drivers/mmc/core/pwrseq.h b/drivers/mmc/core/pwrseq.h
index 133de0426687..d69e751f148b 100644
--- a/drivers/mmc/core/pwrseq.h
+++ b/drivers/mmc/core/pwrseq.h
@@ -8,32 +8,39 @@
8#ifndef _MMC_CORE_PWRSEQ_H 8#ifndef _MMC_CORE_PWRSEQ_H
9#define _MMC_CORE_PWRSEQ_H 9#define _MMC_CORE_PWRSEQ_H
10 10
11#include <linux/mmc/host.h>
12
11struct mmc_pwrseq_ops { 13struct mmc_pwrseq_ops {
12 void (*pre_power_on)(struct mmc_host *host); 14 void (*pre_power_on)(struct mmc_host *host);
13 void (*post_power_on)(struct mmc_host *host); 15 void (*post_power_on)(struct mmc_host *host);
14 void (*power_off)(struct mmc_host *host); 16 void (*power_off)(struct mmc_host *host);
15 void (*free)(struct mmc_host *host);
16}; 17};
17 18
18struct mmc_pwrseq { 19struct mmc_pwrseq {
19 const struct mmc_pwrseq_ops *ops; 20 const struct mmc_pwrseq_ops *ops;
21 struct device *dev;
22 struct list_head pwrseq_node;
23 struct module *owner;
20}; 24};
21 25
22#ifdef CONFIG_OF 26#ifdef CONFIG_OF
23 27
28int mmc_pwrseq_register(struct mmc_pwrseq *pwrseq);
29void mmc_pwrseq_unregister(struct mmc_pwrseq *pwrseq);
30
24int mmc_pwrseq_alloc(struct mmc_host *host); 31int mmc_pwrseq_alloc(struct mmc_host *host);
25void mmc_pwrseq_pre_power_on(struct mmc_host *host); 32void mmc_pwrseq_pre_power_on(struct mmc_host *host);
26void mmc_pwrseq_post_power_on(struct mmc_host *host); 33void mmc_pwrseq_post_power_on(struct mmc_host *host);
27void mmc_pwrseq_power_off(struct mmc_host *host); 34void mmc_pwrseq_power_off(struct mmc_host *host);
28void mmc_pwrseq_free(struct mmc_host *host); 35void mmc_pwrseq_free(struct mmc_host *host);
29 36
30struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host,
31 struct device *dev);
32struct mmc_pwrseq *mmc_pwrseq_emmc_alloc(struct mmc_host *host,
33 struct device *dev);
34
35#else 37#else
36 38
39static inline int mmc_pwrseq_register(struct mmc_pwrseq *pwrseq)
40{
41 return -ENOSYS;
42}
43static inline void mmc_pwrseq_unregister(struct mmc_pwrseq *pwrseq) {}
37static inline int mmc_pwrseq_alloc(struct mmc_host *host) { return 0; } 44static inline int mmc_pwrseq_alloc(struct mmc_host *host) { return 0; }
38static inline void mmc_pwrseq_pre_power_on(struct mmc_host *host) {} 45static inline void mmc_pwrseq_pre_power_on(struct mmc_host *host) {}
39static inline void mmc_pwrseq_post_power_on(struct mmc_host *host) {} 46static inline void mmc_pwrseq_post_power_on(struct mmc_host *host) {}
diff --git a/drivers/mmc/core/pwrseq_emmc.c b/drivers/mmc/core/pwrseq_emmc.c
index 4a82bc77fe49..adc9c0c614fb 100644
--- a/drivers/mmc/core/pwrseq_emmc.c
+++ b/drivers/mmc/core/pwrseq_emmc.c
@@ -9,6 +9,9 @@
9 */ 9 */
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/module.h>
12#include <linux/slab.h> 15#include <linux/slab.h>
13#include <linux/device.h> 16#include <linux/device.h>
14#include <linux/err.h> 17#include <linux/err.h>
@@ -25,6 +28,8 @@ struct mmc_pwrseq_emmc {
25 struct gpio_desc *reset_gpio; 28 struct gpio_desc *reset_gpio;
26}; 29};
27 30
31#define to_pwrseq_emmc(p) container_of(p, struct mmc_pwrseq_emmc, pwrseq)
32
28static void __mmc_pwrseq_emmc_reset(struct mmc_pwrseq_emmc *pwrseq) 33static void __mmc_pwrseq_emmc_reset(struct mmc_pwrseq_emmc *pwrseq)
29{ 34{
30 gpiod_set_value(pwrseq->reset_gpio, 1); 35 gpiod_set_value(pwrseq->reset_gpio, 1);
@@ -35,27 +40,11 @@ static void __mmc_pwrseq_emmc_reset(struct mmc_pwrseq_emmc *pwrseq)
35 40
36static void mmc_pwrseq_emmc_reset(struct mmc_host *host) 41static void mmc_pwrseq_emmc_reset(struct mmc_host *host)
37{ 42{
38 struct mmc_pwrseq_emmc *pwrseq = container_of(host->pwrseq, 43 struct mmc_pwrseq_emmc *pwrseq = to_pwrseq_emmc(host->pwrseq);
39 struct mmc_pwrseq_emmc, pwrseq);
40 44
41 __mmc_pwrseq_emmc_reset(pwrseq); 45 __mmc_pwrseq_emmc_reset(pwrseq);
42} 46}
43 47
44static void mmc_pwrseq_emmc_free(struct mmc_host *host)
45{
46 struct mmc_pwrseq_emmc *pwrseq = container_of(host->pwrseq,
47 struct mmc_pwrseq_emmc, pwrseq);
48
49 unregister_restart_handler(&pwrseq->reset_nb);
50 gpiod_put(pwrseq->reset_gpio);
51 kfree(pwrseq);
52}
53
54static const struct mmc_pwrseq_ops mmc_pwrseq_emmc_ops = {
55 .post_power_on = mmc_pwrseq_emmc_reset,
56 .free = mmc_pwrseq_emmc_free,
57};
58
59static int mmc_pwrseq_emmc_reset_nb(struct notifier_block *this, 48static int mmc_pwrseq_emmc_reset_nb(struct notifier_block *this,
60 unsigned long mode, void *cmd) 49 unsigned long mode, void *cmd)
61{ 50{
@@ -66,21 +55,22 @@ static int mmc_pwrseq_emmc_reset_nb(struct notifier_block *this,
66 return NOTIFY_DONE; 55 return NOTIFY_DONE;
67} 56}
68 57
69struct mmc_pwrseq *mmc_pwrseq_emmc_alloc(struct mmc_host *host, 58static const struct mmc_pwrseq_ops mmc_pwrseq_emmc_ops = {
70 struct device *dev) 59 .post_power_on = mmc_pwrseq_emmc_reset,
60};
61
62static int mmc_pwrseq_emmc_probe(struct platform_device *pdev)
71{ 63{
72 struct mmc_pwrseq_emmc *pwrseq; 64 struct mmc_pwrseq_emmc *pwrseq;
73 int ret = 0; 65 struct device *dev = &pdev->dev;
74 66
75 pwrseq = kzalloc(sizeof(struct mmc_pwrseq_emmc), GFP_KERNEL); 67 pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL);
76 if (!pwrseq) 68 if (!pwrseq)
77 return ERR_PTR(-ENOMEM); 69 return -ENOMEM;
78 70
79 pwrseq->reset_gpio = gpiod_get(dev, "reset", GPIOD_OUT_LOW); 71 pwrseq->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
80 if (IS_ERR(pwrseq->reset_gpio)) { 72 if (IS_ERR(pwrseq->reset_gpio))
81 ret = PTR_ERR(pwrseq->reset_gpio); 73 return PTR_ERR(pwrseq->reset_gpio);
82 goto free;
83 }
84 74
85 /* 75 /*
86 * register reset handler to ensure emmc reset also from 76 * register reset handler to ensure emmc reset also from
@@ -92,9 +82,38 @@ struct mmc_pwrseq *mmc_pwrseq_emmc_alloc(struct mmc_host *host,
92 register_restart_handler(&pwrseq->reset_nb); 82 register_restart_handler(&pwrseq->reset_nb);
93 83
94 pwrseq->pwrseq.ops = &mmc_pwrseq_emmc_ops; 84 pwrseq->pwrseq.ops = &mmc_pwrseq_emmc_ops;
85 pwrseq->pwrseq.dev = dev;
86 pwrseq->pwrseq.owner = THIS_MODULE;
87 platform_set_drvdata(pdev, pwrseq);
88
89 return mmc_pwrseq_register(&pwrseq->pwrseq);
90}
91
92static int mmc_pwrseq_emmc_remove(struct platform_device *pdev)
93{
94 struct mmc_pwrseq_emmc *pwrseq = platform_get_drvdata(pdev);
95
96 unregister_restart_handler(&pwrseq->reset_nb);
97 mmc_pwrseq_unregister(&pwrseq->pwrseq);
95 98
96 return &pwrseq->pwrseq; 99 return 0;
97free:
98 kfree(pwrseq);
99 return ERR_PTR(ret);
100} 100}
101
102static const struct of_device_id mmc_pwrseq_emmc_of_match[] = {
103 { .compatible = "mmc-pwrseq-emmc",},
104 {/* sentinel */},
105};
106
107MODULE_DEVICE_TABLE(of, mmc_pwrseq_emmc_of_match);
108
109static struct platform_driver mmc_pwrseq_emmc_driver = {
110 .probe = mmc_pwrseq_emmc_probe,
111 .remove = mmc_pwrseq_emmc_remove,
112 .driver = {
113 .name = "pwrseq_emmc",
114 .of_match_table = mmc_pwrseq_emmc_of_match,
115 },
116};
117
118module_platform_driver(mmc_pwrseq_emmc_driver);
119MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c
index bc173e18b71c..450d907c6e6c 100644
--- a/drivers/mmc/core/pwrseq_simple.c
+++ b/drivers/mmc/core/pwrseq_simple.c
@@ -8,7 +8,10 @@
8 * Simple MMC power sequence management 8 * Simple MMC power sequence management
9 */ 9 */
10#include <linux/clk.h> 10#include <linux/clk.h>
11#include <linux/init.h>
11#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/platform_device.h>
14#include <linux/module.h>
12#include <linux/slab.h> 15#include <linux/slab.h>
13#include <linux/device.h> 16#include <linux/device.h>
14#include <linux/err.h> 17#include <linux/err.h>
@@ -25,6 +28,8 @@ struct mmc_pwrseq_simple {
25 struct gpio_descs *reset_gpios; 28 struct gpio_descs *reset_gpios;
26}; 29};
27 30
31#define to_pwrseq_simple(p) container_of(p, struct mmc_pwrseq_simple, pwrseq)
32
28static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq, 33static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq,
29 int value) 34 int value)
30{ 35{
@@ -44,8 +49,7 @@ static void mmc_pwrseq_simple_set_gpios_value(struct mmc_pwrseq_simple *pwrseq,
44 49
45static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host) 50static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
46{ 51{
47 struct mmc_pwrseq_simple *pwrseq = container_of(host->pwrseq, 52 struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
48 struct mmc_pwrseq_simple, pwrseq);
49 53
50 if (!IS_ERR(pwrseq->ext_clk) && !pwrseq->clk_enabled) { 54 if (!IS_ERR(pwrseq->ext_clk) && !pwrseq->clk_enabled) {
51 clk_prepare_enable(pwrseq->ext_clk); 55 clk_prepare_enable(pwrseq->ext_clk);
@@ -57,16 +61,14 @@ static void mmc_pwrseq_simple_pre_power_on(struct mmc_host *host)
57 61
58static void mmc_pwrseq_simple_post_power_on(struct mmc_host *host) 62static void mmc_pwrseq_simple_post_power_on(struct mmc_host *host)
59{ 63{
60 struct mmc_pwrseq_simple *pwrseq = container_of(host->pwrseq, 64 struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
61 struct mmc_pwrseq_simple, pwrseq);
62 65
63 mmc_pwrseq_simple_set_gpios_value(pwrseq, 0); 66 mmc_pwrseq_simple_set_gpios_value(pwrseq, 0);
64} 67}
65 68
66static void mmc_pwrseq_simple_power_off(struct mmc_host *host) 69static void mmc_pwrseq_simple_power_off(struct mmc_host *host)
67{ 70{
68 struct mmc_pwrseq_simple *pwrseq = container_of(host->pwrseq, 71 struct mmc_pwrseq_simple *pwrseq = to_pwrseq_simple(host->pwrseq);
69 struct mmc_pwrseq_simple, pwrseq);
70 72
71 mmc_pwrseq_simple_set_gpios_value(pwrseq, 1); 73 mmc_pwrseq_simple_set_gpios_value(pwrseq, 1);
72 74
@@ -76,59 +78,64 @@ static void mmc_pwrseq_simple_power_off(struct mmc_host *host)
76 } 78 }
77} 79}
78 80
79static void mmc_pwrseq_simple_free(struct mmc_host *host)
80{
81 struct mmc_pwrseq_simple *pwrseq = container_of(host->pwrseq,
82 struct mmc_pwrseq_simple, pwrseq);
83
84 if (!IS_ERR(pwrseq->reset_gpios))
85 gpiod_put_array(pwrseq->reset_gpios);
86
87 if (!IS_ERR(pwrseq->ext_clk))
88 clk_put(pwrseq->ext_clk);
89
90 kfree(pwrseq);
91}
92
93static const struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = { 81static const struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = {
94 .pre_power_on = mmc_pwrseq_simple_pre_power_on, 82 .pre_power_on = mmc_pwrseq_simple_pre_power_on,
95 .post_power_on = mmc_pwrseq_simple_post_power_on, 83 .post_power_on = mmc_pwrseq_simple_post_power_on,
96 .power_off = mmc_pwrseq_simple_power_off, 84 .power_off = mmc_pwrseq_simple_power_off,
97 .free = mmc_pwrseq_simple_free,
98}; 85};
99 86
100struct mmc_pwrseq *mmc_pwrseq_simple_alloc(struct mmc_host *host, 87static const struct of_device_id mmc_pwrseq_simple_of_match[] = {
101 struct device *dev) 88 { .compatible = "mmc-pwrseq-simple",},
89 {/* sentinel */},
90};
91MODULE_DEVICE_TABLE(of, mmc_pwrseq_simple_of_match);
92
93static int mmc_pwrseq_simple_probe(struct platform_device *pdev)
102{ 94{
103 struct mmc_pwrseq_simple *pwrseq; 95 struct mmc_pwrseq_simple *pwrseq;
104 int ret = 0; 96 struct device *dev = &pdev->dev;
105 97
106 pwrseq = kzalloc(sizeof(*pwrseq), GFP_KERNEL); 98 pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL);
107 if (!pwrseq) 99 if (!pwrseq)
108 return ERR_PTR(-ENOMEM); 100 return -ENOMEM;
109 101
110 pwrseq->ext_clk = clk_get(dev, "ext_clock"); 102 pwrseq->ext_clk = devm_clk_get(dev, "ext_clock");
111 if (IS_ERR(pwrseq->ext_clk) && 103 if (IS_ERR(pwrseq->ext_clk) && PTR_ERR(pwrseq->ext_clk) != -ENOENT)
112 PTR_ERR(pwrseq->ext_clk) != -ENOENT) { 104 return PTR_ERR(pwrseq->ext_clk);
113 ret = PTR_ERR(pwrseq->ext_clk);
114 goto free;
115 }
116 105
117 pwrseq->reset_gpios = gpiod_get_array(dev, "reset", GPIOD_OUT_HIGH); 106 pwrseq->reset_gpios = devm_gpiod_get_array(dev, "reset",
107 GPIOD_OUT_HIGH);
118 if (IS_ERR(pwrseq->reset_gpios) && 108 if (IS_ERR(pwrseq->reset_gpios) &&
119 PTR_ERR(pwrseq->reset_gpios) != -ENOENT && 109 PTR_ERR(pwrseq->reset_gpios) != -ENOENT &&
120 PTR_ERR(pwrseq->reset_gpios) != -ENOSYS) { 110 PTR_ERR(pwrseq->reset_gpios) != -ENOSYS) {
121 ret = PTR_ERR(pwrseq->reset_gpios); 111 return PTR_ERR(pwrseq->reset_gpios);
122 goto clk_put;
123 } 112 }
124 113
114 pwrseq->pwrseq.dev = dev;
125 pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops; 115 pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops;
116 pwrseq->pwrseq.owner = THIS_MODULE;
117 platform_set_drvdata(pdev, pwrseq);
126 118
127 return &pwrseq->pwrseq; 119 return mmc_pwrseq_register(&pwrseq->pwrseq);
128clk_put:
129 if (!IS_ERR(pwrseq->ext_clk))
130 clk_put(pwrseq->ext_clk);
131free:
132 kfree(pwrseq);
133 return ERR_PTR(ret);
134} 120}
121
122static int mmc_pwrseq_simple_remove(struct platform_device *pdev)
123{
124 struct mmc_pwrseq_simple *pwrseq = platform_get_drvdata(pdev);
125
126 mmc_pwrseq_unregister(&pwrseq->pwrseq);
127
128 return 0;
129}
130
131static struct platform_driver mmc_pwrseq_simple_driver = {
132 .probe = mmc_pwrseq_simple_probe,
133 .remove = mmc_pwrseq_simple_remove,
134 .driver = {
135 .name = "pwrseq_simple",
136 .of_match_table = mmc_pwrseq_simple_of_match,
137 },
138};
139
140module_platform_driver(mmc_pwrseq_simple_driver);
141MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
index 6f6fc527a263..dcb3dee59fa5 100644
--- a/drivers/mmc/core/sdio_cis.c
+++ b/drivers/mmc/core/sdio_cis.c
@@ -177,8 +177,13 @@ static int cistpl_funce_func(struct mmc_card *card, struct sdio_func *func,
177 vsn = func->card->cccr.sdio_vsn; 177 vsn = func->card->cccr.sdio_vsn;
178 min_size = (vsn == SDIO_SDIO_REV_1_00) ? 28 : 42; 178 min_size = (vsn == SDIO_SDIO_REV_1_00) ? 28 : 42;
179 179
180 if (size < min_size) 180 if (size == 28 && vsn == SDIO_SDIO_REV_1_10) {
181 pr_warn("%s: card has broken SDIO 1.1 CIS, forcing SDIO 1.0\n",
182 mmc_hostname(card->host));
183 vsn = SDIO_SDIO_REV_1_00;
184 } else if (size < min_size) {
181 return -EINVAL; 185 return -EINVAL;
186 }
182 187
183 /* TPLFE_MAX_BLK_SIZE */ 188 /* TPLFE_MAX_BLK_SIZE */
184 func->max_blksize = buf[12] | (buf[13] << 8); 189 func->max_blksize = buf[12] | (buf[13] << 8);
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index e657af0e95fa..0aa484c10c0a 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -677,9 +677,9 @@ config MMC_SH_MMCIF
677 depends on HAS_DMA 677 depends on HAS_DMA
678 depends on SUPERH || ARCH_RENESAS || COMPILE_TEST 678 depends on SUPERH || ARCH_RENESAS || COMPILE_TEST
679 help 679 help
680 This selects the MMC Host Interface controller (MMCIF). 680 This selects the MMC Host Interface controller (MMCIF) found in various
681 Renesas SoCs for SH and ARM architectures.
681 682
682 This driver supports MMCIF in sh7724/sh7757/sh7372.
683 683
684config MMC_JZ4740 684config MMC_JZ4740
685 tristate "JZ4740 SD/Multimedia Card Interface support" 685 tristate "JZ4740 SD/Multimedia Card Interface support"
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 9268c41a8561..0ad8ef565b74 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -1410,8 +1410,6 @@ static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1410 WARN_ON(slot->mrq); 1410 WARN_ON(slot->mrq);
1411 dev_dbg(&host->pdev->dev, "MRQ: cmd %u\n", mrq->cmd->opcode); 1411 dev_dbg(&host->pdev->dev, "MRQ: cmd %u\n", mrq->cmd->opcode);
1412 1412
1413 pm_runtime_get_sync(&host->pdev->dev);
1414
1415 /* 1413 /*
1416 * We may "know" the card is gone even though there's still an 1414 * We may "know" the card is gone even though there's still an
1417 * electrical connection. If so, we really need to communicate 1415 * electrical connection. If so, we really need to communicate
@@ -1442,8 +1440,6 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1442 struct atmel_mci *host = slot->host; 1440 struct atmel_mci *host = slot->host;
1443 unsigned int i; 1441 unsigned int i;
1444 1442
1445 pm_runtime_get_sync(&host->pdev->dev);
1446
1447 slot->sdc_reg &= ~ATMCI_SDCBUS_MASK; 1443 slot->sdc_reg &= ~ATMCI_SDCBUS_MASK;
1448 switch (ios->bus_width) { 1444 switch (ios->bus_width) {
1449 case MMC_BUS_WIDTH_1: 1445 case MMC_BUS_WIDTH_1:
@@ -1576,8 +1572,6 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1576 break; 1572 break;
1577 } 1573 }
1578 1574
1579 pm_runtime_mark_last_busy(&host->pdev->dev);
1580 pm_runtime_put_autosuspend(&host->pdev->dev);
1581} 1575}
1582 1576
1583static int atmci_get_ro(struct mmc_host *mmc) 1577static int atmci_get_ro(struct mmc_host *mmc)
@@ -1669,9 +1663,6 @@ static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq)
1669 spin_unlock(&host->lock); 1663 spin_unlock(&host->lock);
1670 mmc_request_done(prev_mmc, mrq); 1664 mmc_request_done(prev_mmc, mrq);
1671 spin_lock(&host->lock); 1665 spin_lock(&host->lock);
1672
1673 pm_runtime_mark_last_busy(&host->pdev->dev);
1674 pm_runtime_put_autosuspend(&host->pdev->dev);
1675} 1666}
1676 1667
1677static void atmci_command_complete(struct atmel_mci *host, 1668static void atmci_command_complete(struct atmel_mci *host,
diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c
index 693144e7427b..a56373c75983 100644
--- a/drivers/mmc/host/davinci_mmc.c
+++ b/drivers/mmc/host/davinci_mmc.c
@@ -32,12 +32,10 @@
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/dmaengine.h> 33#include <linux/dmaengine.h>
34#include <linux/dma-mapping.h> 34#include <linux/dma-mapping.h>
35#include <linux/edma.h>
36#include <linux/mmc/mmc.h> 35#include <linux/mmc/mmc.h>
37#include <linux/of.h> 36#include <linux/of.h>
38#include <linux/of_device.h> 37#include <linux/of_device.h>
39 38
40#include <linux/platform_data/edma.h>
41#include <linux/platform_data/mmc-davinci.h> 39#include <linux/platform_data/mmc-davinci.h>
42 40
43/* 41/*
@@ -202,7 +200,6 @@ struct mmc_davinci_host {
202 u32 buffer_bytes_left; 200 u32 buffer_bytes_left;
203 u32 bytes_left; 201 u32 bytes_left;
204 202
205 u32 rxdma, txdma;
206 struct dma_chan *dma_tx; 203 struct dma_chan *dma_tx;
207 struct dma_chan *dma_rx; 204 struct dma_chan *dma_rx;
208 bool use_dma; 205 bool use_dma;
@@ -513,35 +510,20 @@ davinci_release_dma_channels(struct mmc_davinci_host *host)
513 510
514static int __init davinci_acquire_dma_channels(struct mmc_davinci_host *host) 511static int __init davinci_acquire_dma_channels(struct mmc_davinci_host *host)
515{ 512{
516 int r; 513 host->dma_tx = dma_request_chan(mmc_dev(host->mmc), "tx");
517 dma_cap_mask_t mask; 514 if (IS_ERR(host->dma_tx)) {
518
519 dma_cap_zero(mask);
520 dma_cap_set(DMA_SLAVE, mask);
521
522 host->dma_tx =
523 dma_request_slave_channel_compat(mask, edma_filter_fn,
524 &host->txdma, mmc_dev(host->mmc), "tx");
525 if (!host->dma_tx) {
526 dev_err(mmc_dev(host->mmc), "Can't get dma_tx channel\n"); 515 dev_err(mmc_dev(host->mmc), "Can't get dma_tx channel\n");
527 return -ENODEV; 516 return PTR_ERR(host->dma_tx);
528 } 517 }
529 518
530 host->dma_rx = 519 host->dma_rx = dma_request_chan(mmc_dev(host->mmc), "rx");
531 dma_request_slave_channel_compat(mask, edma_filter_fn, 520 if (IS_ERR(host->dma_rx)) {
532 &host->rxdma, mmc_dev(host->mmc), "rx");
533 if (!host->dma_rx) {
534 dev_err(mmc_dev(host->mmc), "Can't get dma_rx channel\n"); 521 dev_err(mmc_dev(host->mmc), "Can't get dma_rx channel\n");
535 r = -ENODEV; 522 dma_release_channel(host->dma_tx);
536 goto free_master_write; 523 return PTR_ERR(host->dma_rx);
537 } 524 }
538 525
539 return 0; 526 return 0;
540
541free_master_write:
542 dma_release_channel(host->dma_tx);
543
544 return r;
545} 527}
546 528
547/*----------------------------------------------------------------------*/ 529/*----------------------------------------------------------------------*/
@@ -1223,7 +1205,7 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1223 struct mmc_davinci_host *host = NULL; 1205 struct mmc_davinci_host *host = NULL;
1224 struct mmc_host *mmc = NULL; 1206 struct mmc_host *mmc = NULL;
1225 struct resource *r, *mem = NULL; 1207 struct resource *r, *mem = NULL;
1226 int ret = 0, irq = 0; 1208 int ret, irq;
1227 size_t mem_size; 1209 size_t mem_size;
1228 const struct platform_device_id *id_entry; 1210 const struct platform_device_id *id_entry;
1229 1211
@@ -1233,50 +1215,40 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1233 return -ENOENT; 1215 return -ENOENT;
1234 } 1216 }
1235 1217
1236 ret = -ENODEV;
1237 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1218 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1238 irq = platform_get_irq(pdev, 0); 1219 irq = platform_get_irq(pdev, 0);
1239 if (!r || irq == NO_IRQ) 1220 if (!r || irq == NO_IRQ)
1240 goto out; 1221 return -ENODEV;
1241 1222
1242 ret = -EBUSY;
1243 mem_size = resource_size(r); 1223 mem_size = resource_size(r);
1244 mem = request_mem_region(r->start, mem_size, pdev->name); 1224 mem = devm_request_mem_region(&pdev->dev, r->start, mem_size,
1225 pdev->name);
1245 if (!mem) 1226 if (!mem)
1246 goto out; 1227 return -EBUSY;
1247 1228
1248 ret = -ENOMEM;
1249 mmc = mmc_alloc_host(sizeof(struct mmc_davinci_host), &pdev->dev); 1229 mmc = mmc_alloc_host(sizeof(struct mmc_davinci_host), &pdev->dev);
1250 if (!mmc) 1230 if (!mmc)
1251 goto out; 1231 return -ENOMEM;
1252 1232
1253 host = mmc_priv(mmc); 1233 host = mmc_priv(mmc);
1254 host->mmc = mmc; /* Important */ 1234 host->mmc = mmc; /* Important */
1255 1235
1256 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1257 if (!r)
1258 dev_warn(&pdev->dev, "RX DMA resource not specified\n");
1259 else
1260 host->rxdma = r->start;
1261
1262 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1263 if (!r)
1264 dev_warn(&pdev->dev, "TX DMA resource not specified\n");
1265 else
1266 host->txdma = r->start;
1267
1268 host->mem_res = mem; 1236 host->mem_res = mem;
1269 host->base = ioremap(mem->start, mem_size); 1237 host->base = devm_ioremap(&pdev->dev, mem->start, mem_size);
1270 if (!host->base) 1238 if (!host->base) {
1271 goto out; 1239 ret = -ENOMEM;
1240 goto ioremap_fail;
1241 }
1272 1242
1273 ret = -ENXIO; 1243 host->clk = devm_clk_get(&pdev->dev, NULL);
1274 host->clk = clk_get(&pdev->dev, "MMCSDCLK");
1275 if (IS_ERR(host->clk)) { 1244 if (IS_ERR(host->clk)) {
1276 ret = PTR_ERR(host->clk); 1245 ret = PTR_ERR(host->clk);
1277 goto out; 1246 goto clk_get_fail;
1278 } 1247 }
1279 clk_enable(host->clk); 1248 ret = clk_prepare_enable(host->clk);
1249 if (ret)
1250 goto clk_prepare_enable_fail;
1251
1280 host->mmc_input_clk = clk_get_rate(host->clk); 1252 host->mmc_input_clk = clk_get_rate(host->clk);
1281 1253
1282 init_mmcsd_host(host); 1254 init_mmcsd_host(host);
@@ -1291,8 +1263,13 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1291 host->mmc_irq = irq; 1263 host->mmc_irq = irq;
1292 host->sdio_irq = platform_get_irq(pdev, 1); 1264 host->sdio_irq = platform_get_irq(pdev, 1);
1293 1265
1294 if (host->use_dma && davinci_acquire_dma_channels(host) != 0) 1266 if (host->use_dma) {
1295 host->use_dma = 0; 1267 ret = davinci_acquire_dma_channels(host);
1268 if (ret == -EPROBE_DEFER)
1269 goto dma_probe_defer;
1270 else if (ret)
1271 host->use_dma = 0;
1272 }
1296 1273
1297 /* REVISIT: someday, support IRQ-driven card detection. */ 1274 /* REVISIT: someday, support IRQ-driven card detection. */
1298 mmc->caps |= MMC_CAP_NEEDS_POLL; 1275 mmc->caps |= MMC_CAP_NEEDS_POLL;
@@ -1346,15 +1323,17 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1346 1323
1347 ret = mmc_add_host(mmc); 1324 ret = mmc_add_host(mmc);
1348 if (ret < 0) 1325 if (ret < 0)
1349 goto out; 1326 goto mmc_add_host_fail;
1350 1327
1351 ret = request_irq(irq, mmc_davinci_irq, 0, mmc_hostname(mmc), host); 1328 ret = devm_request_irq(&pdev->dev, irq, mmc_davinci_irq, 0,
1329 mmc_hostname(mmc), host);
1352 if (ret) 1330 if (ret)
1353 goto out; 1331 goto request_irq_fail;
1354 1332
1355 if (host->sdio_irq >= 0) { 1333 if (host->sdio_irq >= 0) {
1356 ret = request_irq(host->sdio_irq, mmc_davinci_sdio_irq, 0, 1334 ret = devm_request_irq(&pdev->dev, host->sdio_irq,
1357 mmc_hostname(mmc), host); 1335 mmc_davinci_sdio_irq, 0,
1336 mmc_hostname(mmc), host);
1358 if (!ret) 1337 if (!ret)
1359 mmc->caps |= MMC_CAP_SDIO_IRQ; 1338 mmc->caps |= MMC_CAP_SDIO_IRQ;
1360 } 1339 }
@@ -1367,28 +1346,18 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev)
1367 1346
1368 return 0; 1347 return 0;
1369 1348
1370out: 1349request_irq_fail:
1350 mmc_remove_host(mmc);
1351mmc_add_host_fail:
1371 mmc_davinci_cpufreq_deregister(host); 1352 mmc_davinci_cpufreq_deregister(host);
1372cpu_freq_fail: 1353cpu_freq_fail:
1373 if (host) { 1354 davinci_release_dma_channels(host);
1374 davinci_release_dma_channels(host); 1355dma_probe_defer:
1375 1356 clk_disable_unprepare(host->clk);
1376 if (host->clk) { 1357clk_prepare_enable_fail:
1377 clk_disable(host->clk); 1358clk_get_fail:
1378 clk_put(host->clk); 1359ioremap_fail:
1379 } 1360 mmc_free_host(mmc);
1380
1381 if (host->base)
1382 iounmap(host->base);
1383 }
1384
1385 if (mmc)
1386 mmc_free_host(mmc);
1387
1388 if (mem)
1389 release_resource(mem);
1390
1391 dev_dbg(&pdev->dev, "probe err %d\n", ret);
1392 1361
1393 return ret; 1362 return ret;
1394} 1363}
@@ -1397,25 +1366,11 @@ static int __exit davinci_mmcsd_remove(struct platform_device *pdev)
1397{ 1366{
1398 struct mmc_davinci_host *host = platform_get_drvdata(pdev); 1367 struct mmc_davinci_host *host = platform_get_drvdata(pdev);
1399 1368
1400 if (host) { 1369 mmc_remove_host(host->mmc);
1401 mmc_davinci_cpufreq_deregister(host); 1370 mmc_davinci_cpufreq_deregister(host);
1402 1371 davinci_release_dma_channels(host);
1403 mmc_remove_host(host->mmc); 1372 clk_disable_unprepare(host->clk);
1404 free_irq(host->mmc_irq, host); 1373 mmc_free_host(host->mmc);
1405 if (host->mmc->caps & MMC_CAP_SDIO_IRQ)
1406 free_irq(host->sdio_irq, host);
1407
1408 davinci_release_dma_channels(host);
1409
1410 clk_disable(host->clk);
1411 clk_put(host->clk);
1412
1413 iounmap(host->base);
1414
1415 release_resource(host->mem_res);
1416
1417 mmc_free_host(host->mmc);
1418 }
1419 1374
1420 return 0; 1375 return 0;
1421} 1376}
diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index 8790f2afc057..7e3a3247b852 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -91,10 +91,14 @@ static inline u8 dw_mci_exynos_get_ciu_div(struct dw_mci *host)
91 return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1; 91 return SDMMC_CLKSEL_GET_DIV(mci_readl(host, CLKSEL)) + 1;
92} 92}
93 93
94static int dw_mci_exynos_priv_init(struct dw_mci *host) 94static void dw_mci_exynos_config_smu(struct dw_mci *host)
95{ 95{
96 struct dw_mci_exynos_priv_data *priv = host->priv; 96 struct dw_mci_exynos_priv_data *priv = host->priv;
97 97
98 /*
99 * If Exynos is provided the Security management,
100 * set for non-ecryption mode at this time.
101 */
98 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU || 102 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU ||
99 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) { 103 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) {
100 mci_writel(host, MPSBEGIN0, 0); 104 mci_writel(host, MPSBEGIN0, 0);
@@ -104,6 +108,13 @@ static int dw_mci_exynos_priv_init(struct dw_mci *host)
104 SDMMC_MPSCTRL_VALID | 108 SDMMC_MPSCTRL_VALID |
105 SDMMC_MPSCTRL_NON_SECURE_WRITE_BIT); 109 SDMMC_MPSCTRL_NON_SECURE_WRITE_BIT);
106 } 110 }
111}
112
113static int dw_mci_exynos_priv_init(struct dw_mci *host)
114{
115 struct dw_mci_exynos_priv_data *priv = host->priv;
116
117 dw_mci_exynos_config_smu(host);
107 118
108 if (priv->ctrl_type >= DW_MCI_TYPE_EXYNOS5420) { 119 if (priv->ctrl_type >= DW_MCI_TYPE_EXYNOS5420) {
109 priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL); 120 priv->saved_strobe_ctrl = mci_readl(host, HS400_DLINE_CTRL);
@@ -115,13 +126,6 @@ static int dw_mci_exynos_priv_init(struct dw_mci *host)
115 DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl); 126 DQS_CTRL_GET_RD_DELAY(priv->saved_strobe_ctrl);
116 } 127 }
117 128
118 return 0;
119}
120
121static int dw_mci_exynos_setup_clock(struct dw_mci *host)
122{
123 struct dw_mci_exynos_priv_data *priv = host->priv;
124
125 host->bus_hz /= (priv->ciu_div + 1); 129 host->bus_hz /= (priv->ciu_div + 1);
126 130
127 return 0; 131 return 0;
@@ -169,7 +173,7 @@ static int dw_mci_exynos_resume(struct device *dev)
169{ 173{
170 struct dw_mci *host = dev_get_drvdata(dev); 174 struct dw_mci *host = dev_get_drvdata(dev);
171 175
172 dw_mci_exynos_priv_init(host); 176 dw_mci_exynos_config_smu(host);
173 return dw_mci_resume(host); 177 return dw_mci_resume(host);
174} 178}
175 179
@@ -489,7 +493,6 @@ static unsigned long exynos_dwmmc_caps[4] = {
489static const struct dw_mci_drv_data exynos_drv_data = { 493static const struct dw_mci_drv_data exynos_drv_data = {
490 .caps = exynos_dwmmc_caps, 494 .caps = exynos_dwmmc_caps,
491 .init = dw_mci_exynos_priv_init, 495 .init = dw_mci_exynos_priv_init,
492 .setup_clock = dw_mci_exynos_setup_clock,
493 .set_ios = dw_mci_exynos_set_ios, 496 .set_ios = dw_mci_exynos_set_ios,
494 .parse_dt = dw_mci_exynos_parse_dt, 497 .parse_dt = dw_mci_exynos_parse_dt,
495 .execute_tuning = dw_mci_exynos_execute_tuning, 498 .execute_tuning = dw_mci_exynos_execute_tuning,
diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index 84e50f3a64b6..8c20b81cafd8 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -26,13 +26,6 @@ struct dw_mci_rockchip_priv_data {
26 int default_sample_phase; 26 int default_sample_phase;
27}; 27};
28 28
29static int dw_mci_rk3288_setup_clock(struct dw_mci *host)
30{
31 host->bus_hz /= RK3288_CLKGEN_DIV;
32
33 return 0;
34}
35
36static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios) 29static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios)
37{ 30{
38 struct dw_mci_rockchip_priv_data *priv = host->priv; 31 struct dw_mci_rockchip_priv_data *priv = host->priv;
@@ -231,18 +224,30 @@ static int dw_mci_rockchip_init(struct dw_mci *host)
231 /* It needs this quirk on all Rockchip SoCs */ 224 /* It needs this quirk on all Rockchip SoCs */
232 host->pdata->quirks |= DW_MCI_QUIRK_BROKEN_DTO; 225 host->pdata->quirks |= DW_MCI_QUIRK_BROKEN_DTO;
233 226
227 if (of_device_is_compatible(host->dev->of_node,
228 "rockchip,rk3288-dw-mshc"))
229 host->bus_hz /= RK3288_CLKGEN_DIV;
230
234 return 0; 231 return 0;
235} 232}
236 233
234/* Common capabilities of RK3288 SoC */
235static unsigned long dw_mci_rk3288_dwmmc_caps[4] = {
236 MMC_CAP_ERASE,
237 MMC_CAP_ERASE,
238 MMC_CAP_ERASE,
239 MMC_CAP_ERASE,
240};
241
237static const struct dw_mci_drv_data rk2928_drv_data = { 242static const struct dw_mci_drv_data rk2928_drv_data = {
238 .init = dw_mci_rockchip_init, 243 .init = dw_mci_rockchip_init,
239}; 244};
240 245
241static const struct dw_mci_drv_data rk3288_drv_data = { 246static const struct dw_mci_drv_data rk3288_drv_data = {
247 .caps = dw_mci_rk3288_dwmmc_caps,
242 .set_ios = dw_mci_rk3288_set_ios, 248 .set_ios = dw_mci_rk3288_set_ios,
243 .execute_tuning = dw_mci_rk3288_execute_tuning, 249 .execute_tuning = dw_mci_rk3288_execute_tuning,
244 .parse_dt = dw_mci_rk3288_parse_dt, 250 .parse_dt = dw_mci_rk3288_parse_dt,
245 .setup_clock = dw_mci_rk3288_setup_clock,
246 .init = dw_mci_rockchip_init, 251 .init = dw_mci_rockchip_init,
247}; 252};
248 253
@@ -269,33 +274,13 @@ static int dw_mci_rockchip_probe(struct platform_device *pdev)
269 return dw_mci_pltfm_register(pdev, drv_data); 274 return dw_mci_pltfm_register(pdev, drv_data);
270} 275}
271 276
272#ifdef CONFIG_PM_SLEEP
273static int dw_mci_rockchip_suspend(struct device *dev)
274{
275 struct dw_mci *host = dev_get_drvdata(dev);
276
277 return dw_mci_suspend(host);
278}
279
280static int dw_mci_rockchip_resume(struct device *dev)
281{
282 struct dw_mci *host = dev_get_drvdata(dev);
283
284 return dw_mci_resume(host);
285}
286#endif /* CONFIG_PM_SLEEP */
287
288static SIMPLE_DEV_PM_OPS(dw_mci_rockchip_pmops,
289 dw_mci_rockchip_suspend,
290 dw_mci_rockchip_resume);
291
292static struct platform_driver dw_mci_rockchip_pltfm_driver = { 277static struct platform_driver dw_mci_rockchip_pltfm_driver = {
293 .probe = dw_mci_rockchip_probe, 278 .probe = dw_mci_rockchip_probe,
294 .remove = dw_mci_pltfm_remove, 279 .remove = dw_mci_pltfm_remove,
295 .driver = { 280 .driver = {
296 .name = "dwmmc_rockchip", 281 .name = "dwmmc_rockchip",
297 .of_match_table = dw_mci_rockchip_match, 282 .of_match_table = dw_mci_rockchip_match,
298 .pm = &dw_mci_rockchip_pmops, 283 .pm = &dw_mci_pltfm_pmops,
299 }, 284 },
300}; 285};
301 286
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 242f9a0769bd..9dd1bd358434 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -680,7 +680,7 @@ static const struct dw_mci_dma_ops dw_mci_idmac_ops = {
680 680
681static void dw_mci_edmac_stop_dma(struct dw_mci *host) 681static void dw_mci_edmac_stop_dma(struct dw_mci *host)
682{ 682{
683 dmaengine_terminate_all(host->dms->ch); 683 dmaengine_terminate_async(host->dms->ch);
684} 684}
685 685
686static int dw_mci_edmac_start_dma(struct dw_mci *host, 686static int dw_mci_edmac_start_dma(struct dw_mci *host,
@@ -3003,15 +3003,6 @@ int dw_mci_probe(struct dw_mci *host)
3003 } 3003 }
3004 } 3004 }
3005 3005
3006 if (drv_data && drv_data->setup_clock) {
3007 ret = drv_data->setup_clock(host);
3008 if (ret) {
3009 dev_err(host->dev,
3010 "implementation specific clock setup failed\n");
3011 goto err_clk_ciu;
3012 }
3013 }
3014
3015 setup_timer(&host->cmd11_timer, 3006 setup_timer(&host->cmd11_timer,
3016 dw_mci_cmd11_timer, (unsigned long)host); 3007 dw_mci_cmd11_timer, (unsigned long)host);
3017 3008
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 68d5da2dfd19..1e8d8380f9cf 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -277,7 +277,6 @@ struct dw_mci_slot {
277 * dw_mci driver data - dw-mshc implementation specific driver data. 277 * dw_mci driver data - dw-mshc implementation specific driver data.
278 * @caps: mmc subsystem specified capabilities of the controller(s). 278 * @caps: mmc subsystem specified capabilities of the controller(s).
279 * @init: early implementation specific initialization. 279 * @init: early implementation specific initialization.
280 * @setup_clock: implementation specific clock configuration.
281 * @set_ios: handle bus specific extensions. 280 * @set_ios: handle bus specific extensions.
282 * @parse_dt: parse implementation specific device tree properties. 281 * @parse_dt: parse implementation specific device tree properties.
283 * @execute_tuning: implementation specific tuning procedure. 282 * @execute_tuning: implementation specific tuning procedure.
@@ -289,7 +288,6 @@ struct dw_mci_slot {
289struct dw_mci_drv_data { 288struct dw_mci_drv_data {
290 unsigned long *caps; 289 unsigned long *caps;
291 int (*init)(struct dw_mci *host); 290 int (*init)(struct dw_mci *host);
292 int (*setup_clock)(struct dw_mci *host);
293 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios); 291 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
294 int (*parse_dt)(struct dw_mci *host); 292 int (*parse_dt)(struct dw_mci *host);
295 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode); 293 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode);
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 2e6c96845c9a..df990bb8c873 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -226,16 +226,11 @@ static int mmci_card_busy(struct mmc_host *mmc)
226 unsigned long flags; 226 unsigned long flags;
227 int busy = 0; 227 int busy = 0;
228 228
229 pm_runtime_get_sync(mmc_dev(mmc));
230
231 spin_lock_irqsave(&host->lock, flags); 229 spin_lock_irqsave(&host->lock, flags);
232 if (readl(host->base + MMCISTATUS) & MCI_ST_CARDBUSY) 230 if (readl(host->base + MMCISTATUS) & MCI_ST_CARDBUSY)
233 busy = 1; 231 busy = 1;
234 spin_unlock_irqrestore(&host->lock, flags); 232 spin_unlock_irqrestore(&host->lock, flags);
235 233
236 pm_runtime_mark_last_busy(mmc_dev(mmc));
237 pm_runtime_put_autosuspend(mmc_dev(mmc));
238
239 return busy; 234 return busy;
240} 235}
241 236
@@ -381,9 +376,6 @@ mmci_request_end(struct mmci_host *host, struct mmc_request *mrq)
381 host->cmd = NULL; 376 host->cmd = NULL;
382 377
383 mmc_request_done(host->mmc, mrq); 378 mmc_request_done(host->mmc, mrq);
384
385 pm_runtime_mark_last_busy(mmc_dev(host->mmc));
386 pm_runtime_put_autosuspend(mmc_dev(host->mmc));
387} 379}
388 380
389static void mmci_set_mask1(struct mmci_host *host, unsigned int mask) 381static void mmci_set_mask1(struct mmci_host *host, unsigned int mask)
@@ -1290,8 +1282,6 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1290 return; 1282 return;
1291 } 1283 }
1292 1284
1293 pm_runtime_get_sync(mmc_dev(mmc));
1294
1295 spin_lock_irqsave(&host->lock, flags); 1285 spin_lock_irqsave(&host->lock, flags);
1296 1286
1297 host->mrq = mrq; 1287 host->mrq = mrq;
@@ -1318,8 +1308,6 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1318 unsigned long flags; 1308 unsigned long flags;
1319 int ret; 1309 int ret;
1320 1310
1321 pm_runtime_get_sync(mmc_dev(mmc));
1322
1323 if (host->plat->ios_handler && 1311 if (host->plat->ios_handler &&
1324 host->plat->ios_handler(mmc_dev(mmc), ios)) 1312 host->plat->ios_handler(mmc_dev(mmc), ios))
1325 dev_err(mmc_dev(mmc), "platform ios_handler failed\n"); 1313 dev_err(mmc_dev(mmc), "platform ios_handler failed\n");
@@ -1414,9 +1402,6 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1414 mmci_reg_delay(host); 1402 mmci_reg_delay(host);
1415 1403
1416 spin_unlock_irqrestore(&host->lock, flags); 1404 spin_unlock_irqrestore(&host->lock, flags);
1417
1418 pm_runtime_mark_last_busy(mmc_dev(mmc));
1419 pm_runtime_put_autosuspend(mmc_dev(mmc));
1420} 1405}
1421 1406
1422static int mmci_get_cd(struct mmc_host *mmc) 1407static int mmci_get_cd(struct mmc_host *mmc)
@@ -1440,8 +1425,6 @@ static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
1440 1425
1441 if (!IS_ERR(mmc->supply.vqmmc)) { 1426 if (!IS_ERR(mmc->supply.vqmmc)) {
1442 1427
1443 pm_runtime_get_sync(mmc_dev(mmc));
1444
1445 switch (ios->signal_voltage) { 1428 switch (ios->signal_voltage) {
1446 case MMC_SIGNAL_VOLTAGE_330: 1429 case MMC_SIGNAL_VOLTAGE_330:
1447 ret = regulator_set_voltage(mmc->supply.vqmmc, 1430 ret = regulator_set_voltage(mmc->supply.vqmmc,
@@ -1459,9 +1442,6 @@ static int mmci_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
1459 1442
1460 if (ret) 1443 if (ret)
1461 dev_warn(mmc_dev(mmc), "Voltage switch failed\n"); 1444 dev_warn(mmc_dev(mmc), "Voltage switch failed\n");
1462
1463 pm_runtime_mark_last_busy(mmc_dev(mmc));
1464 pm_runtime_put_autosuspend(mmc_dev(mmc));
1465 } 1445 }
1466 1446
1467 return ret; 1447 return ret;
diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index b17f30da97da..5642f71f8bf0 100644
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -736,9 +736,6 @@ static void msdc_request_done(struct msdc_host *host, struct mmc_request *mrq)
736 if (mrq->data) 736 if (mrq->data)
737 msdc_unprepare_data(host, mrq); 737 msdc_unprepare_data(host, mrq);
738 mmc_request_done(host->mmc, mrq); 738 mmc_request_done(host->mmc, mrq);
739
740 pm_runtime_mark_last_busy(host->dev);
741 pm_runtime_put_autosuspend(host->dev);
742} 739}
743 740
744/* returns true if command is fully handled; returns false otherwise */ 741/* returns true if command is fully handled; returns false otherwise */
@@ -886,8 +883,6 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
886 WARN_ON(host->mrq); 883 WARN_ON(host->mrq);
887 host->mrq = mrq; 884 host->mrq = mrq;
888 885
889 pm_runtime_get_sync(host->dev);
890
891 if (mrq->data) 886 if (mrq->data)
892 msdc_prepare_data(host, mrq); 887 msdc_prepare_data(host, mrq);
893 888
@@ -1201,8 +1196,6 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1201 struct msdc_host *host = mmc_priv(mmc); 1196 struct msdc_host *host = mmc_priv(mmc);
1202 int ret; 1197 int ret;
1203 1198
1204 pm_runtime_get_sync(host->dev);
1205
1206 msdc_set_buswidth(host, ios->bus_width); 1199 msdc_set_buswidth(host, ios->bus_width);
1207 1200
1208 /* Suspend/Resume will do power off/on */ 1201 /* Suspend/Resume will do power off/on */
@@ -1214,7 +1207,7 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1214 ios->vdd); 1207 ios->vdd);
1215 if (ret) { 1208 if (ret) {
1216 dev_err(host->dev, "Failed to set vmmc power!\n"); 1209 dev_err(host->dev, "Failed to set vmmc power!\n");
1217 goto end; 1210 return;
1218 } 1211 }
1219 } 1212 }
1220 break; 1213 break;
@@ -1242,10 +1235,6 @@ static void msdc_ops_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1242 1235
1243 if (host->mclk != ios->clock || host->timing != ios->timing) 1236 if (host->mclk != ios->clock || host->timing != ios->timing)
1244 msdc_set_mclk(host, ios->timing, ios->clock); 1237 msdc_set_mclk(host, ios->timing, ios->clock);
1245
1246end:
1247 pm_runtime_mark_last_busy(host->dev);
1248 pm_runtime_put_autosuspend(host->dev);
1249} 1238}
1250 1239
1251static u32 test_delay_bit(u32 delay, u32 bit) 1240static u32 test_delay_bit(u32 delay, u32 bit)
@@ -1408,19 +1397,15 @@ static int msdc_execute_tuning(struct mmc_host *mmc, u32 opcode)
1408 struct msdc_host *host = mmc_priv(mmc); 1397 struct msdc_host *host = mmc_priv(mmc);
1409 int ret; 1398 int ret;
1410 1399
1411 pm_runtime_get_sync(host->dev);
1412 ret = msdc_tune_response(mmc, opcode); 1400 ret = msdc_tune_response(mmc, opcode);
1413 if (ret == -EIO) { 1401 if (ret == -EIO) {
1414 dev_err(host->dev, "Tune response fail!\n"); 1402 dev_err(host->dev, "Tune response fail!\n");
1415 goto out; 1403 return ret;
1416 } 1404 }
1417 ret = msdc_tune_data(mmc, opcode); 1405 ret = msdc_tune_data(mmc, opcode);
1418 if (ret == -EIO) 1406 if (ret == -EIO)
1419 dev_err(host->dev, "Tune data fail!\n"); 1407 dev_err(host->dev, "Tune data fail!\n");
1420 1408
1421out:
1422 pm_runtime_mark_last_busy(host->dev);
1423 pm_runtime_put_autosuspend(host->dev);
1424 return ret; 1409 return ret;
1425} 1410}
1426 1411
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index b9958a123594..f23d65eb070d 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -23,7 +23,6 @@
23#include <linux/spinlock.h> 23#include <linux/spinlock.h>
24#include <linux/timer.h> 24#include <linux/timer.h>
25#include <linux/of.h> 25#include <linux/of.h>
26#include <linux/omap-dma.h>
27#include <linux/mmc/host.h> 26#include <linux/mmc/host.h>
28#include <linux/mmc/card.h> 27#include <linux/mmc/card.h>
29#include <linux/mmc/mmc.h> 28#include <linux/mmc/mmc.h>
@@ -1321,8 +1320,6 @@ static int mmc_omap_probe(struct platform_device *pdev)
1321 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; 1320 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data;
1322 struct mmc_omap_host *host = NULL; 1321 struct mmc_omap_host *host = NULL;
1323 struct resource *res; 1322 struct resource *res;
1324 dma_cap_mask_t mask;
1325 unsigned sig = 0;
1326 int i, ret = 0; 1323 int i, ret = 0;
1327 int irq; 1324 int irq;
1328 1325
@@ -1382,29 +1379,34 @@ static int mmc_omap_probe(struct platform_device *pdev)
1382 goto err_free_iclk; 1379 goto err_free_iclk;
1383 } 1380 }
1384 1381
1385 dma_cap_zero(mask);
1386 dma_cap_set(DMA_SLAVE, mask);
1387
1388 host->dma_tx_burst = -1; 1382 host->dma_tx_burst = -1;
1389 host->dma_rx_burst = -1; 1383 host->dma_rx_burst = -1;
1390 1384
1391 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); 1385 host->dma_tx = dma_request_chan(&pdev->dev, "tx");
1392 if (res) 1386 if (IS_ERR(host->dma_tx)) {
1393 sig = res->start; 1387 ret = PTR_ERR(host->dma_tx);
1394 host->dma_tx = dma_request_slave_channel_compat(mask, 1388 if (ret == -EPROBE_DEFER) {
1395 omap_dma_filter_fn, &sig, &pdev->dev, "tx"); 1389 clk_put(host->fclk);
1396 if (!host->dma_tx) 1390 goto err_free_iclk;
1397 dev_warn(host->dev, "unable to obtain TX DMA engine channel %u\n", 1391 }
1398 sig); 1392
1399 1393 host->dma_tx = NULL;
1400 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); 1394 dev_warn(host->dev, "TX DMA channel request failed\n");
1401 if (res) 1395 }
1402 sig = res->start; 1396
1403 host->dma_rx = dma_request_slave_channel_compat(mask, 1397 host->dma_rx = dma_request_chan(&pdev->dev, "rx");
1404 omap_dma_filter_fn, &sig, &pdev->dev, "rx"); 1398 if (IS_ERR(host->dma_rx)) {
1405 if (!host->dma_rx) 1399 ret = PTR_ERR(host->dma_rx);
1406 dev_warn(host->dev, "unable to obtain RX DMA engine channel %u\n", 1400 if (ret == -EPROBE_DEFER) {
1407 sig); 1401 if (host->dma_tx)
1402 dma_release_channel(host->dma_tx);
1403 clk_put(host->fclk);
1404 goto err_free_iclk;
1405 }
1406
1407 host->dma_rx = NULL;
1408 dev_warn(host->dev, "RX DMA channel request failed\n");
1409 }
1408 1410
1409 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host); 1411 ret = request_irq(host->irq, mmc_omap_irq, 0, DRIVER_NAME, host);
1410 if (ret) 1412 if (ret)
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index f9ac3bb5d617..24ebc9a8de89 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -32,7 +32,6 @@
32#include <linux/of_irq.h> 32#include <linux/of_irq.h>
33#include <linux/of_gpio.h> 33#include <linux/of_gpio.h>
34#include <linux/of_device.h> 34#include <linux/of_device.h>
35#include <linux/omap-dmaengine.h>
36#include <linux/mmc/host.h> 35#include <linux/mmc/host.h>
37#include <linux/mmc/core.h> 36#include <linux/mmc/core.h>
38#include <linux/mmc/mmc.h> 37#include <linux/mmc/mmc.h>
@@ -351,15 +350,14 @@ static int omap_hsmmc_set_pbias(struct omap_hsmmc_host *host, bool power_on,
351 return 0; 350 return 0;
352} 351}
353 352
354static int omap_hsmmc_set_power(struct device *dev, int power_on, int vdd) 353static int omap_hsmmc_set_power(struct omap_hsmmc_host *host, int power_on,
354 int vdd)
355{ 355{
356 struct omap_hsmmc_host *host =
357 platform_get_drvdata(to_platform_device(dev));
358 struct mmc_host *mmc = host->mmc; 356 struct mmc_host *mmc = host->mmc;
359 int ret = 0; 357 int ret = 0;
360 358
361 if (mmc_pdata(host)->set_power) 359 if (mmc_pdata(host)->set_power)
362 return mmc_pdata(host)->set_power(dev, power_on, vdd); 360 return mmc_pdata(host)->set_power(host->dev, power_on, vdd);
363 361
364 /* 362 /*
365 * If we don't see a Vcc regulator, assume it's a fixed 363 * If we don't see a Vcc regulator, assume it's a fixed
@@ -369,7 +367,7 @@ static int omap_hsmmc_set_power(struct device *dev, int power_on, int vdd)
369 return 0; 367 return 0;
370 368
371 if (mmc_pdata(host)->before_set_reg) 369 if (mmc_pdata(host)->before_set_reg)
372 mmc_pdata(host)->before_set_reg(dev, power_on, vdd); 370 mmc_pdata(host)->before_set_reg(host->dev, power_on, vdd);
373 371
374 ret = omap_hsmmc_set_pbias(host, false, 0); 372 ret = omap_hsmmc_set_pbias(host, false, 0);
375 if (ret) 373 if (ret)
@@ -403,7 +401,7 @@ static int omap_hsmmc_set_power(struct device *dev, int power_on, int vdd)
403 } 401 }
404 402
405 if (mmc_pdata(host)->after_set_reg) 403 if (mmc_pdata(host)->after_set_reg)
406 mmc_pdata(host)->after_set_reg(dev, power_on, vdd); 404 mmc_pdata(host)->after_set_reg(host->dev, power_on, vdd);
407 405
408 return 0; 406 return 0;
409 407
@@ -968,8 +966,6 @@ static void omap_hsmmc_request_done(struct omap_hsmmc_host *host, struct mmc_req
968 return; 966 return;
969 host->mrq = NULL; 967 host->mrq = NULL;
970 mmc_request_done(host->mmc, mrq); 968 mmc_request_done(host->mmc, mrq);
971 pm_runtime_mark_last_busy(host->dev);
972 pm_runtime_put_autosuspend(host->dev);
973} 969}
974 970
975/* 971/*
@@ -1250,17 +1246,15 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
1250 int ret; 1246 int ret;
1251 1247
1252 /* Disable the clocks */ 1248 /* Disable the clocks */
1253 pm_runtime_put_sync(host->dev);
1254 if (host->dbclk) 1249 if (host->dbclk)
1255 clk_disable_unprepare(host->dbclk); 1250 clk_disable_unprepare(host->dbclk);
1256 1251
1257 /* Turn the power off */ 1252 /* Turn the power off */
1258 ret = omap_hsmmc_set_power(host->dev, 0, 0); 1253 ret = omap_hsmmc_set_power(host, 0, 0);
1259 1254
1260 /* Turn the power ON with given VDD 1.8 or 3.0v */ 1255 /* Turn the power ON with given VDD 1.8 or 3.0v */
1261 if (!ret) 1256 if (!ret)
1262 ret = omap_hsmmc_set_power(host->dev, 1, vdd); 1257 ret = omap_hsmmc_set_power(host, 1, vdd);
1263 pm_runtime_get_sync(host->dev);
1264 if (host->dbclk) 1258 if (host->dbclk)
1265 clk_prepare_enable(host->dbclk); 1259 clk_prepare_enable(host->dbclk);
1266 1260
@@ -1368,8 +1362,6 @@ static void omap_hsmmc_dma_callback(void *param)
1368 1362
1369 host->mrq = NULL; 1363 host->mrq = NULL;
1370 mmc_request_done(host->mmc, mrq); 1364 mmc_request_done(host->mmc, mrq);
1371 pm_runtime_mark_last_busy(host->dev);
1372 pm_runtime_put_autosuspend(host->dev);
1373 } 1365 }
1374} 1366}
1375 1367
@@ -1602,7 +1594,6 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
1602 1594
1603 BUG_ON(host->req_in_progress); 1595 BUG_ON(host->req_in_progress);
1604 BUG_ON(host->dma_ch != -1); 1596 BUG_ON(host->dma_ch != -1);
1605 pm_runtime_get_sync(host->dev);
1606 if (host->protect_card) { 1597 if (host->protect_card) {
1607 if (host->reqs_blocked < 3) { 1598 if (host->reqs_blocked < 3) {
1608 /* 1599 /*
@@ -1619,8 +1610,6 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
1619 req->data->error = -EBADF; 1610 req->data->error = -EBADF;
1620 req->cmd->retries = 0; 1611 req->cmd->retries = 0;
1621 mmc_request_done(mmc, req); 1612 mmc_request_done(mmc, req);
1622 pm_runtime_mark_last_busy(host->dev);
1623 pm_runtime_put_autosuspend(host->dev);
1624 return; 1613 return;
1625 } else if (host->reqs_blocked) 1614 } else if (host->reqs_blocked)
1626 host->reqs_blocked = 0; 1615 host->reqs_blocked = 0;
@@ -1634,8 +1623,6 @@ static void omap_hsmmc_request(struct mmc_host *mmc, struct mmc_request *req)
1634 req->data->error = err; 1623 req->data->error = err;
1635 host->mrq = NULL; 1624 host->mrq = NULL;
1636 mmc_request_done(mmc, req); 1625 mmc_request_done(mmc, req);
1637 pm_runtime_mark_last_busy(host->dev);
1638 pm_runtime_put_autosuspend(host->dev);
1639 return; 1626 return;
1640 } 1627 }
1641 if (req->sbc && !(host->flags & AUTO_CMD23)) { 1628 if (req->sbc && !(host->flags & AUTO_CMD23)) {
@@ -1653,15 +1640,13 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1653 struct omap_hsmmc_host *host = mmc_priv(mmc); 1640 struct omap_hsmmc_host *host = mmc_priv(mmc);
1654 int do_send_init_stream = 0; 1641 int do_send_init_stream = 0;
1655 1642
1656 pm_runtime_get_sync(host->dev);
1657
1658 if (ios->power_mode != host->power_mode) { 1643 if (ios->power_mode != host->power_mode) {
1659 switch (ios->power_mode) { 1644 switch (ios->power_mode) {
1660 case MMC_POWER_OFF: 1645 case MMC_POWER_OFF:
1661 omap_hsmmc_set_power(host->dev, 0, 0); 1646 omap_hsmmc_set_power(host, 0, 0);
1662 break; 1647 break;
1663 case MMC_POWER_UP: 1648 case MMC_POWER_UP:
1664 omap_hsmmc_set_power(host->dev, 1, ios->vdd); 1649 omap_hsmmc_set_power(host, 1, ios->vdd);
1665 break; 1650 break;
1666 case MMC_POWER_ON: 1651 case MMC_POWER_ON:
1667 do_send_init_stream = 1; 1652 do_send_init_stream = 1;
@@ -1698,8 +1683,6 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1698 send_init_stream(host); 1683 send_init_stream(host);
1699 1684
1700 omap_hsmmc_set_bus_mode(host); 1685 omap_hsmmc_set_bus_mode(host);
1701
1702 pm_runtime_put_autosuspend(host->dev);
1703} 1686}
1704 1687
1705static int omap_hsmmc_get_cd(struct mmc_host *mmc) 1688static int omap_hsmmc_get_cd(struct mmc_host *mmc)
@@ -1962,13 +1945,17 @@ MODULE_DEVICE_TABLE(of, omap_mmc_of_match);
1962 1945
1963static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev) 1946static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
1964{ 1947{
1965 struct omap_hsmmc_platform_data *pdata; 1948 struct omap_hsmmc_platform_data *pdata, *legacy;
1966 struct device_node *np = dev->of_node; 1949 struct device_node *np = dev->of_node;
1967 1950
1968 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 1951 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
1969 if (!pdata) 1952 if (!pdata)
1970 return ERR_PTR(-ENOMEM); /* out of memory */ 1953 return ERR_PTR(-ENOMEM); /* out of memory */
1971 1954
1955 legacy = dev_get_platdata(dev);
1956 if (legacy && legacy->name)
1957 pdata->name = legacy->name;
1958
1972 if (of_find_property(np, "ti,dual-volt", NULL)) 1959 if (of_find_property(np, "ti,dual-volt", NULL))
1973 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; 1960 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
1974 1961
@@ -2005,8 +1992,6 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2005 struct resource *res; 1992 struct resource *res;
2006 int ret, irq; 1993 int ret, irq;
2007 const struct of_device_id *match; 1994 const struct of_device_id *match;
2008 dma_cap_mask_t mask;
2009 unsigned tx_req, rx_req;
2010 const struct omap_mmc_of_data *data; 1995 const struct omap_mmc_of_data *data;
2011 void __iomem *base; 1996 void __iomem *base;
2012 1997
@@ -2136,44 +2121,17 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2136 2121
2137 omap_hsmmc_conf_bus_power(host); 2122 omap_hsmmc_conf_bus_power(host);
2138 2123
2139 if (!pdev->dev.of_node) { 2124 host->rx_chan = dma_request_chan(&pdev->dev, "rx");
2140 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); 2125 if (IS_ERR(host->rx_chan)) {
2141 if (!res) { 2126 dev_err(mmc_dev(host->mmc), "RX DMA channel request failed\n");
2142 dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); 2127 ret = PTR_ERR(host->rx_chan);
2143 ret = -ENXIO;
2144 goto err_irq;
2145 }
2146 tx_req = res->start;
2147
2148 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
2149 if (!res) {
2150 dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n");
2151 ret = -ENXIO;
2152 goto err_irq;
2153 }
2154 rx_req = res->start;
2155 }
2156
2157 dma_cap_zero(mask);
2158 dma_cap_set(DMA_SLAVE, mask);
2159
2160 host->rx_chan =
2161 dma_request_slave_channel_compat(mask, omap_dma_filter_fn,
2162 &rx_req, &pdev->dev, "rx");
2163
2164 if (!host->rx_chan) {
2165 dev_err(mmc_dev(host->mmc), "unable to obtain RX DMA engine channel\n");
2166 ret = -ENXIO;
2167 goto err_irq; 2128 goto err_irq;
2168 } 2129 }
2169 2130
2170 host->tx_chan = 2131 host->tx_chan = dma_request_chan(&pdev->dev, "tx");
2171 dma_request_slave_channel_compat(mask, omap_dma_filter_fn, 2132 if (IS_ERR(host->tx_chan)) {
2172 &tx_req, &pdev->dev, "tx"); 2133 dev_err(mmc_dev(host->mmc), "TX DMA channel request failed\n");
2173 2134 ret = PTR_ERR(host->tx_chan);
2174 if (!host->tx_chan) {
2175 dev_err(mmc_dev(host->mmc), "unable to obtain TX DMA engine channel\n");
2176 ret = -ENXIO;
2177 goto err_irq; 2135 goto err_irq;
2178 } 2136 }
2179 2137
@@ -2231,9 +2189,9 @@ err_slot_name:
2231 mmc_remove_host(mmc); 2189 mmc_remove_host(mmc);
2232err_irq: 2190err_irq:
2233 device_init_wakeup(&pdev->dev, false); 2191 device_init_wakeup(&pdev->dev, false);
2234 if (host->tx_chan) 2192 if (!IS_ERR_OR_NULL(host->tx_chan))
2235 dma_release_channel(host->tx_chan); 2193 dma_release_channel(host->tx_chan);
2236 if (host->rx_chan) 2194 if (!IS_ERR_OR_NULL(host->rx_chan))
2237 dma_release_channel(host->rx_chan); 2195 dma_release_channel(host->rx_chan);
2238 pm_runtime_dont_use_autosuspend(host->dev); 2196 pm_runtime_dont_use_autosuspend(host->dev);
2239 pm_runtime_put_sync(host->dev); 2197 pm_runtime_put_sync(host->dev);
diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index bed6a494f52c..b2d70ba6caa7 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -200,8 +200,6 @@ static int bxt_get_cd(struct mmc_host *mmc)
200 if (!gpio_cd) 200 if (!gpio_cd)
201 return 0; 201 return 0;
202 202
203 pm_runtime_get_sync(mmc->parent);
204
205 spin_lock_irqsave(&host->lock, flags); 203 spin_lock_irqsave(&host->lock, flags);
206 204
207 if (host->flags & SDHCI_DEVICE_DEAD) 205 if (host->flags & SDHCI_DEVICE_DEAD)
@@ -211,9 +209,6 @@ static int bxt_get_cd(struct mmc_host *mmc)
211out: 209out:
212 spin_unlock_irqrestore(&host->lock, flags); 210 spin_unlock_irqrestore(&host->lock, flags);
213 211
214 pm_runtime_mark_last_busy(mmc->parent);
215 pm_runtime_put_autosuspend(mmc->parent);
216
217 return ret; 212 return ret;
218} 213}
219 214
@@ -267,8 +262,10 @@ static int sdhci_acpi_sd_probe_slot(struct platform_device *pdev,
267 262
268 /* Platform specific code during sd probe slot goes here */ 263 /* Platform specific code during sd probe slot goes here */
269 264
270 if (hid && !strcmp(hid, "80865ACA")) 265 if (hid && !strcmp(hid, "80865ACA")) {
271 host->mmc_host_ops.get_cd = bxt_get_cd; 266 host->mmc_host_ops.get_cd = bxt_get_cd;
267 host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM;
268 }
272 269
273 return 0; 270 return 0;
274} 271}
diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c
index 2e482b13d25e..b6f4c1d41636 100644
--- a/drivers/mmc/host/sdhci-of-arasan.c
+++ b/drivers/mmc/host/sdhci-of-arasan.c
@@ -55,8 +55,32 @@ static unsigned int sdhci_arasan_get_timeout_clock(struct sdhci_host *host)
55 return freq; 55 return freq;
56} 56}
57 57
58static void sdhci_arasan_set_clock(struct sdhci_host *host, unsigned int clock)
59{
60 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
61 struct sdhci_arasan_data *sdhci_arasan = sdhci_pltfm_priv(pltfm_host);
62 bool ctrl_phy = false;
63
64 if (clock > MMC_HIGH_52_MAX_DTR && (!IS_ERR(sdhci_arasan->phy)))
65 ctrl_phy = true;
66
67 if (ctrl_phy) {
68 spin_unlock_irq(&host->lock);
69 phy_power_off(sdhci_arasan->phy);
70 spin_lock_irq(&host->lock);
71 }
72
73 sdhci_set_clock(host, clock);
74
75 if (ctrl_phy) {
76 spin_unlock_irq(&host->lock);
77 phy_power_on(sdhci_arasan->phy);
78 spin_lock_irq(&host->lock);
79 }
80}
81
58static struct sdhci_ops sdhci_arasan_ops = { 82static struct sdhci_ops sdhci_arasan_ops = {
59 .set_clock = sdhci_set_clock, 83 .set_clock = sdhci_arasan_set_clock,
60 .get_max_clock = sdhci_pltfm_clk_get_max_clock, 84 .get_max_clock = sdhci_pltfm_clk_get_max_clock,
61 .get_timeout_clock = sdhci_arasan_get_timeout_clock, 85 .get_timeout_clock = sdhci_arasan_get_timeout_clock,
62 .set_bus_width = sdhci_set_bus_width, 86 .set_bus_width = sdhci_set_bus_width,
diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c
index 2703aa90d018..25f779e09d8e 100644
--- a/drivers/mmc/host/sdhci-of-at91.c
+++ b/drivers/mmc/host/sdhci-of-at91.c
@@ -15,8 +15,10 @@
15 */ 15 */
16 16
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/delay.h>
18#include <linux/err.h> 19#include <linux/err.h>
19#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/kernel.h>
20#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
21#include <linux/mmc/slot-gpio.h> 23#include <linux/mmc/slot-gpio.h>
22#include <linux/module.h> 24#include <linux/module.h>
@@ -31,14 +33,60 @@
31#define SDMMC_CACR_CAPWREN BIT(0) 33#define SDMMC_CACR_CAPWREN BIT(0)
32#define SDMMC_CACR_KEY (0x46 << 8) 34#define SDMMC_CACR_KEY (0x46 << 8)
33 35
36#define SDHCI_AT91_PRESET_COMMON_CONF 0x400 /* drv type B, programmable clock mode */
37
34struct sdhci_at91_priv { 38struct sdhci_at91_priv {
35 struct clk *hclock; 39 struct clk *hclock;
36 struct clk *gck; 40 struct clk *gck;
37 struct clk *mainck; 41 struct clk *mainck;
38}; 42};
39 43
44static void sdhci_at91_set_clock(struct sdhci_host *host, unsigned int clock)
45{
46 u16 clk;
47 unsigned long timeout;
48
49 host->mmc->actual_clock = 0;
50
51 /*
52 * There is no requirement to disable the internal clock before
53 * changing the SD clock configuration. Moreover, disabling the
54 * internal clock, changing the configuration and re-enabling the
55 * internal clock causes some bugs. It can prevent to get the internal
56 * clock stable flag ready and an unexpected switch to the base clock
57 * when using presets.
58 */
59 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
60 clk &= SDHCI_CLOCK_INT_EN;
61 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
62
63 if (clock == 0)
64 return;
65
66 clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
67
68 clk |= SDHCI_CLOCK_INT_EN;
69 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
70
71 /* Wait max 20 ms */
72 timeout = 20;
73 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
74 & SDHCI_CLOCK_INT_STABLE)) {
75 if (timeout == 0) {
76 pr_err("%s: Internal clock never stabilised.\n",
77 mmc_hostname(host->mmc));
78 return;
79 }
80 timeout--;
81 mdelay(1);
82 }
83
84 clk |= SDHCI_CLOCK_CARD_EN;
85 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
86}
87
40static const struct sdhci_ops sdhci_at91_sama5d2_ops = { 88static const struct sdhci_ops sdhci_at91_sama5d2_ops = {
41 .set_clock = sdhci_set_clock, 89 .set_clock = sdhci_at91_set_clock,
42 .set_bus_width = sdhci_set_bus_width, 90 .set_bus_width = sdhci_set_bus_width,
43 .reset = sdhci_reset, 91 .reset = sdhci_reset,
44 .set_uhs_signaling = sdhci_set_uhs_signaling, 92 .set_uhs_signaling = sdhci_set_uhs_signaling,
@@ -46,7 +94,6 @@ static const struct sdhci_ops sdhci_at91_sama5d2_ops = {
46 94
47static const struct sdhci_pltfm_data soc_data_sama5d2 = { 95static const struct sdhci_pltfm_data soc_data_sama5d2 = {
48 .ops = &sdhci_at91_sama5d2_ops, 96 .ops = &sdhci_at91_sama5d2_ops,
49 .quirks2 = SDHCI_QUIRK2_NEED_DELAY_AFTER_INT_CLK_RST,
50}; 97};
51 98
52static const struct of_device_id sdhci_at91_dt_match[] = { 99static const struct of_device_id sdhci_at91_dt_match[] = {
@@ -119,6 +166,7 @@ static int sdhci_at91_probe(struct platform_device *pdev)
119 unsigned int clk_base, clk_mul; 166 unsigned int clk_base, clk_mul;
120 unsigned int gck_rate, real_gck_rate; 167 unsigned int gck_rate, real_gck_rate;
121 int ret; 168 int ret;
169 unsigned int preset_div;
122 170
123 match = of_match_device(sdhci_at91_dt_match, &pdev->dev); 171 match = of_match_device(sdhci_at91_dt_match, &pdev->dev);
124 if (!match) 172 if (!match)
@@ -186,6 +234,28 @@ static int sdhci_at91_probe(struct platform_device *pdev)
186 clk_mul, real_gck_rate); 234 clk_mul, real_gck_rate);
187 } 235 }
188 236
237 /*
238 * We have to set preset values because it depends on the clk_mul
239 * value. Moreover, SDR104 is supported in a degraded mode since the
240 * maximum sd clock value is 120 MHz instead of 208 MHz. For that
241 * reason, we need to use presets to support SDR104.
242 */
243 preset_div = DIV_ROUND_UP(real_gck_rate, 24000000) - 1;
244 writew(SDHCI_AT91_PRESET_COMMON_CONF | preset_div,
245 host->ioaddr + SDHCI_PRESET_FOR_SDR12);
246 preset_div = DIV_ROUND_UP(real_gck_rate, 50000000) - 1;
247 writew(SDHCI_AT91_PRESET_COMMON_CONF | preset_div,
248 host->ioaddr + SDHCI_PRESET_FOR_SDR25);
249 preset_div = DIV_ROUND_UP(real_gck_rate, 100000000) - 1;
250 writew(SDHCI_AT91_PRESET_COMMON_CONF | preset_div,
251 host->ioaddr + SDHCI_PRESET_FOR_SDR50);
252 preset_div = DIV_ROUND_UP(real_gck_rate, 120000000) - 1;
253 writew(SDHCI_AT91_PRESET_COMMON_CONF | preset_div,
254 host->ioaddr + SDHCI_PRESET_FOR_SDR104);
255 preset_div = DIV_ROUND_UP(real_gck_rate, 50000000) - 1;
256 writew(SDHCI_AT91_PRESET_COMMON_CONF | preset_div,
257 host->ioaddr + SDHCI_PRESET_FOR_DDR50);
258
189 clk_prepare_enable(priv->mainck); 259 clk_prepare_enable(priv->mainck);
190 clk_prepare_enable(priv->gck); 260 clk_prepare_enable(priv->gck);
191 261
diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 79e19017343e..97d4eebd6bf5 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -340,8 +340,6 @@ static int bxt_get_cd(struct mmc_host *mmc)
340 if (!gpio_cd) 340 if (!gpio_cd)
341 return 0; 341 return 0;
342 342
343 pm_runtime_get_sync(mmc->parent);
344
345 spin_lock_irqsave(&host->lock, flags); 343 spin_lock_irqsave(&host->lock, flags);
346 344
347 if (host->flags & SDHCI_DEVICE_DEAD) 345 if (host->flags & SDHCI_DEVICE_DEAD)
@@ -351,9 +349,6 @@ static int bxt_get_cd(struct mmc_host *mmc)
351out: 349out:
352 spin_unlock_irqrestore(&host->lock, flags); 350 spin_unlock_irqrestore(&host->lock, flags);
353 351
354 pm_runtime_mark_last_busy(mmc->parent);
355 pm_runtime_put_autosuspend(mmc->parent);
356
357 return ret; 352 return ret;
358} 353}
359 354
@@ -391,8 +386,10 @@ static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
391 slot->cd_override_level = true; 386 slot->cd_override_level = true;
392 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD || 387 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXT_SD ||
393 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD || 388 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BXTM_SD ||
394 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD) 389 slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_APL_SD) {
395 slot->host->mmc_host_ops.get_cd = bxt_get_cd; 390 slot->host->mmc_host_ops.get_cd = bxt_get_cd;
391 slot->host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM;
392 }
396 393
397 return 0; 394 return 0;
398} 395}
diff --git a/drivers/mmc/host/sdhci-pic32.c b/drivers/mmc/host/sdhci-pic32.c
index 059df707a2fe..72c13b6f05f9 100644
--- a/drivers/mmc/host/sdhci-pic32.c
+++ b/drivers/mmc/host/sdhci-pic32.c
@@ -243,7 +243,6 @@ MODULE_DEVICE_TABLE(of, pic32_sdhci_id_table);
243static struct platform_driver pic32_sdhci_driver = { 243static struct platform_driver pic32_sdhci_driver = {
244 .driver = { 244 .driver = {
245 .name = "pic32-sdhci", 245 .name = "pic32-sdhci",
246 .owner = THIS_MODULE,
247 .of_match_table = of_match_ptr(pic32_sdhci_id_table), 246 .of_match_table = of_match_ptr(pic32_sdhci_id_table),
248 }, 247 },
249 .probe = pic32_sdhci_probe, 248 .probe = pic32_sdhci_probe,
diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c
index 072bb27a65cf..64f287a03cd3 100644
--- a/drivers/mmc/host/sdhci-pltfm.c
+++ b/drivers/mmc/host/sdhci-pltfm.c
@@ -119,16 +119,22 @@ struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
119{ 119{
120 struct sdhci_host *host; 120 struct sdhci_host *host;
121 struct resource *iomem; 121 struct resource *iomem;
122 int ret; 122 void __iomem *ioaddr;
123 int irq, ret;
123 124
124 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 125 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
125 if (!iomem) { 126 ioaddr = devm_ioremap_resource(&pdev->dev, iomem);
126 ret = -ENOMEM; 127 if (IS_ERR(ioaddr)) {
128 ret = PTR_ERR(ioaddr);
127 goto err; 129 goto err;
128 } 130 }
129 131
130 if (resource_size(iomem) < 0x100) 132 irq = platform_get_irq(pdev, 0);
131 dev_err(&pdev->dev, "Invalid iomem size!\n"); 133 if (irq < 0) {
134 dev_err(&pdev->dev, "failed to get IRQ number\n");
135 ret = irq;
136 goto err;
137 }
132 138
133 host = sdhci_alloc_host(&pdev->dev, 139 host = sdhci_alloc_host(&pdev->dev,
134 sizeof(struct sdhci_pltfm_host) + priv_size); 140 sizeof(struct sdhci_pltfm_host) + priv_size);
@@ -138,6 +144,8 @@ struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
138 goto err; 144 goto err;
139 } 145 }
140 146
147 host->ioaddr = ioaddr;
148 host->irq = irq;
141 host->hw_name = dev_name(&pdev->dev); 149 host->hw_name = dev_name(&pdev->dev);
142 if (pdata && pdata->ops) 150 if (pdata && pdata->ops)
143 host->ops = pdata->ops; 151 host->ops = pdata->ops;
@@ -148,22 +156,6 @@ struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
148 host->quirks2 = pdata->quirks2; 156 host->quirks2 = pdata->quirks2;
149 } 157 }
150 158
151 host->irq = platform_get_irq(pdev, 0);
152
153 if (!request_mem_region(iomem->start, resource_size(iomem),
154 mmc_hostname(host->mmc))) {
155 dev_err(&pdev->dev, "cannot request region\n");
156 ret = -EBUSY;
157 goto err_request;
158 }
159
160 host->ioaddr = ioremap(iomem->start, resource_size(iomem));
161 if (!host->ioaddr) {
162 dev_err(&pdev->dev, "failed to remap registers\n");
163 ret = -ENOMEM;
164 goto err_remap;
165 }
166
167 /* 159 /*
168 * Some platforms need to probe the controller to be able to 160 * Some platforms need to probe the controller to be able to
169 * determine which caps should be used. 161 * determine which caps should be used.
@@ -174,11 +166,6 @@ struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
174 platform_set_drvdata(pdev, host); 166 platform_set_drvdata(pdev, host);
175 167
176 return host; 168 return host;
177
178err_remap:
179 release_mem_region(iomem->start, resource_size(iomem));
180err_request:
181 sdhci_free_host(host);
182err: 169err:
183 dev_err(&pdev->dev, "%s failed %d\n", __func__, ret); 170 dev_err(&pdev->dev, "%s failed %d\n", __func__, ret);
184 return ERR_PTR(ret); 171 return ERR_PTR(ret);
@@ -188,10 +175,7 @@ EXPORT_SYMBOL_GPL(sdhci_pltfm_init);
188void sdhci_pltfm_free(struct platform_device *pdev) 175void sdhci_pltfm_free(struct platform_device *pdev)
189{ 176{
190 struct sdhci_host *host = platform_get_drvdata(pdev); 177 struct sdhci_host *host = platform_get_drvdata(pdev);
191 struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
192 178
193 iounmap(host->ioaddr);
194 release_mem_region(iomem->start, resource_size(iomem));
195 sdhci_free_host(host); 179 sdhci_free_host(host);
196} 180}
197EXPORT_SYMBOL_GPL(sdhci_pltfm_free); 181EXPORT_SYMBOL_GPL(sdhci_pltfm_free);
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 6bd3d1794966..e010ea4eb6f5 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -38,11 +38,6 @@
38#define DBG(f, x...) \ 38#define DBG(f, x...) \
39 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x) 39 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
40 40
41#if defined(CONFIG_LEDS_CLASS) || (defined(CONFIG_LEDS_CLASS_MODULE) && \
42 defined(CONFIG_MMC_SDHCI_MODULE))
43#define SDHCI_USE_LEDS_CLASS
44#endif
45
46#define MAX_TUNING_LOOP 40 41#define MAX_TUNING_LOOP 40
47 42
48static unsigned int debug_quirks = 0; 43static unsigned int debug_quirks = 0;
@@ -53,29 +48,7 @@ static void sdhci_finish_data(struct sdhci_host *);
53static void sdhci_finish_command(struct sdhci_host *); 48static void sdhci_finish_command(struct sdhci_host *);
54static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode); 49static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode);
55static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable); 50static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
56static int sdhci_do_get_cd(struct sdhci_host *host); 51static int sdhci_get_cd(struct mmc_host *mmc);
57
58#ifdef CONFIG_PM
59static int sdhci_runtime_pm_get(struct sdhci_host *host);
60static int sdhci_runtime_pm_put(struct sdhci_host *host);
61static void sdhci_runtime_pm_bus_on(struct sdhci_host *host);
62static void sdhci_runtime_pm_bus_off(struct sdhci_host *host);
63#else
64static inline int sdhci_runtime_pm_get(struct sdhci_host *host)
65{
66 return 0;
67}
68static inline int sdhci_runtime_pm_put(struct sdhci_host *host)
69{
70 return 0;
71}
72static void sdhci_runtime_pm_bus_on(struct sdhci_host *host)
73{
74}
75static void sdhci_runtime_pm_bus_off(struct sdhci_host *host)
76{
77}
78#endif
79 52
80static void sdhci_dumpregs(struct sdhci_host *host) 53static void sdhci_dumpregs(struct sdhci_host *host)
81{ 54{
@@ -171,6 +144,22 @@ static void sdhci_disable_card_detection(struct sdhci_host *host)
171 sdhci_set_card_detection(host, false); 144 sdhci_set_card_detection(host, false);
172} 145}
173 146
147static void sdhci_runtime_pm_bus_on(struct sdhci_host *host)
148{
149 if (host->bus_on)
150 return;
151 host->bus_on = true;
152 pm_runtime_get_noresume(host->mmc->parent);
153}
154
155static void sdhci_runtime_pm_bus_off(struct sdhci_host *host)
156{
157 if (!host->bus_on)
158 return;
159 host->bus_on = false;
160 pm_runtime_put_noidle(host->mmc->parent);
161}
162
174void sdhci_reset(struct sdhci_host *host, u8 mask) 163void sdhci_reset(struct sdhci_host *host, u8 mask)
175{ 164{
176 unsigned long timeout; 165 unsigned long timeout;
@@ -204,7 +193,7 @@ EXPORT_SYMBOL_GPL(sdhci_reset);
204static void sdhci_do_reset(struct sdhci_host *host, u8 mask) 193static void sdhci_do_reset(struct sdhci_host *host, u8 mask)
205{ 194{
206 if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { 195 if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) {
207 if (!sdhci_do_get_cd(host)) 196 if (!sdhci_get_cd(host->mmc))
208 return; 197 return;
209 } 198 }
210 199
@@ -252,7 +241,7 @@ static void sdhci_reinit(struct sdhci_host *host)
252 sdhci_enable_card_detection(host); 241 sdhci_enable_card_detection(host);
253} 242}
254 243
255static void sdhci_activate_led(struct sdhci_host *host) 244static void __sdhci_led_activate(struct sdhci_host *host)
256{ 245{
257 u8 ctrl; 246 u8 ctrl;
258 247
@@ -261,7 +250,7 @@ static void sdhci_activate_led(struct sdhci_host *host)
261 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); 250 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
262} 251}
263 252
264static void sdhci_deactivate_led(struct sdhci_host *host) 253static void __sdhci_led_deactivate(struct sdhci_host *host)
265{ 254{
266 u8 ctrl; 255 u8 ctrl;
267 256
@@ -270,9 +259,9 @@ static void sdhci_deactivate_led(struct sdhci_host *host)
270 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); 259 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
271} 260}
272 261
273#ifdef SDHCI_USE_LEDS_CLASS 262#if IS_REACHABLE(CONFIG_LEDS_CLASS)
274static void sdhci_led_control(struct led_classdev *led, 263static void sdhci_led_control(struct led_classdev *led,
275 enum led_brightness brightness) 264 enum led_brightness brightness)
276{ 265{
277 struct sdhci_host *host = container_of(led, struct sdhci_host, led); 266 struct sdhci_host *host = container_of(led, struct sdhci_host, led);
278 unsigned long flags; 267 unsigned long flags;
@@ -283,12 +272,62 @@ static void sdhci_led_control(struct led_classdev *led,
283 goto out; 272 goto out;
284 273
285 if (brightness == LED_OFF) 274 if (brightness == LED_OFF)
286 sdhci_deactivate_led(host); 275 __sdhci_led_deactivate(host);
287 else 276 else
288 sdhci_activate_led(host); 277 __sdhci_led_activate(host);
289out: 278out:
290 spin_unlock_irqrestore(&host->lock, flags); 279 spin_unlock_irqrestore(&host->lock, flags);
291} 280}
281
282static int sdhci_led_register(struct sdhci_host *host)
283{
284 struct mmc_host *mmc = host->mmc;
285
286 snprintf(host->led_name, sizeof(host->led_name),
287 "%s::", mmc_hostname(mmc));
288
289 host->led.name = host->led_name;
290 host->led.brightness = LED_OFF;
291 host->led.default_trigger = mmc_hostname(mmc);
292 host->led.brightness_set = sdhci_led_control;
293
294 return led_classdev_register(mmc_dev(mmc), &host->led);
295}
296
297static void sdhci_led_unregister(struct sdhci_host *host)
298{
299 led_classdev_unregister(&host->led);
300}
301
302static inline void sdhci_led_activate(struct sdhci_host *host)
303{
304}
305
306static inline void sdhci_led_deactivate(struct sdhci_host *host)
307{
308}
309
310#else
311
312static inline int sdhci_led_register(struct sdhci_host *host)
313{
314 return 0;
315}
316
317static inline void sdhci_led_unregister(struct sdhci_host *host)
318{
319}
320
321static inline void sdhci_led_activate(struct sdhci_host *host)
322{
323 __sdhci_led_activate(host);
324}
325
326static inline void sdhci_led_deactivate(struct sdhci_host *host)
327{
328 __sdhci_led_deactivate(host);
329}
330
292#endif 331#endif
293 332
294/*****************************************************************************\ 333/*****************************************************************************\
@@ -1091,23 +1130,14 @@ static u16 sdhci_get_preset_value(struct sdhci_host *host)
1091 return preset; 1130 return preset;
1092} 1131}
1093 1132
1094void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) 1133u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock,
1134 unsigned int *actual_clock)
1095{ 1135{
1096 int div = 0; /* Initialized for compiler warning */ 1136 int div = 0; /* Initialized for compiler warning */
1097 int real_div = div, clk_mul = 1; 1137 int real_div = div, clk_mul = 1;
1098 u16 clk = 0; 1138 u16 clk = 0;
1099 unsigned long timeout;
1100 bool switch_base_clk = false; 1139 bool switch_base_clk = false;
1101 1140
1102 host->mmc->actual_clock = 0;
1103
1104 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
1105 if (host->quirks2 & SDHCI_QUIRK2_NEED_DELAY_AFTER_INT_CLK_RST)
1106 mdelay(1);
1107
1108 if (clock == 0)
1109 return;
1110
1111 if (host->version >= SDHCI_SPEC_300) { 1141 if (host->version >= SDHCI_SPEC_300) {
1112 if (host->preset_enabled) { 1142 if (host->preset_enabled) {
1113 u16 pre_val; 1143 u16 pre_val;
@@ -1184,10 +1214,29 @@ void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1184 1214
1185clock_set: 1215clock_set:
1186 if (real_div) 1216 if (real_div)
1187 host->mmc->actual_clock = (host->max_clk * clk_mul) / real_div; 1217 *actual_clock = (host->max_clk * clk_mul) / real_div;
1188 clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT; 1218 clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
1189 clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN) 1219 clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
1190 << SDHCI_DIVIDER_HI_SHIFT; 1220 << SDHCI_DIVIDER_HI_SHIFT;
1221
1222 return clk;
1223}
1224EXPORT_SYMBOL_GPL(sdhci_calc_clk);
1225
1226void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1227{
1228 u16 clk;
1229 unsigned long timeout;
1230
1231 host->mmc->actual_clock = 0;
1232
1233 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
1234
1235 if (clock == 0)
1236 return;
1237
1238 clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock);
1239
1191 clk |= SDHCI_CLOCK_INT_EN; 1240 clk |= SDHCI_CLOCK_INT_EN;
1192 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); 1241 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
1193 1242
@@ -1319,8 +1368,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1319 1368
1320 host = mmc_priv(mmc); 1369 host = mmc_priv(mmc);
1321 1370
1322 sdhci_runtime_pm_get(host);
1323
1324 /* Firstly check card presence */ 1371 /* Firstly check card presence */
1325 present = mmc->ops->get_cd(mmc); 1372 present = mmc->ops->get_cd(mmc);
1326 1373
@@ -1328,9 +1375,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1328 1375
1329 WARN_ON(host->mrq != NULL); 1376 WARN_ON(host->mrq != NULL);
1330 1377
1331#ifndef SDHCI_USE_LEDS_CLASS 1378 sdhci_led_activate(host);
1332 sdhci_activate_led(host);
1333#endif
1334 1379
1335 /* 1380 /*
1336 * Ensure we don't send the STOP for non-SET_BLOCK_COUNTED 1381 * Ensure we don't send the STOP for non-SET_BLOCK_COUNTED
@@ -1405,11 +1450,11 @@ void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing)
1405} 1450}
1406EXPORT_SYMBOL_GPL(sdhci_set_uhs_signaling); 1451EXPORT_SYMBOL_GPL(sdhci_set_uhs_signaling);
1407 1452
1408static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios) 1453static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1409{ 1454{
1455 struct sdhci_host *host = mmc_priv(mmc);
1410 unsigned long flags; 1456 unsigned long flags;
1411 u8 ctrl; 1457 u8 ctrl;
1412 struct mmc_host *mmc = host->mmc;
1413 1458
1414 spin_lock_irqsave(&host->lock, flags); 1459 spin_lock_irqsave(&host->lock, flags);
1415 1460
@@ -1563,18 +1608,10 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1563 spin_unlock_irqrestore(&host->lock, flags); 1608 spin_unlock_irqrestore(&host->lock, flags);
1564} 1609}
1565 1610
1566static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 1611static int sdhci_get_cd(struct mmc_host *mmc)
1567{ 1612{
1568 struct sdhci_host *host = mmc_priv(mmc); 1613 struct sdhci_host *host = mmc_priv(mmc);
1569 1614 int gpio_cd = mmc_gpio_get_cd(mmc);
1570 sdhci_runtime_pm_get(host);
1571 sdhci_do_set_ios(host, ios);
1572 sdhci_runtime_pm_put(host);
1573}
1574
1575static int sdhci_do_get_cd(struct sdhci_host *host)
1576{
1577 int gpio_cd = mmc_gpio_get_cd(host->mmc);
1578 1615
1579 if (host->flags & SDHCI_DEVICE_DEAD) 1616 if (host->flags & SDHCI_DEVICE_DEAD)
1580 return 0; 1617 return 0;
@@ -1598,17 +1635,6 @@ static int sdhci_do_get_cd(struct sdhci_host *host)
1598 return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); 1635 return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
1599} 1636}
1600 1637
1601static int sdhci_get_cd(struct mmc_host *mmc)
1602{
1603 struct sdhci_host *host = mmc_priv(mmc);
1604 int ret;
1605
1606 sdhci_runtime_pm_get(host);
1607 ret = sdhci_do_get_cd(host);
1608 sdhci_runtime_pm_put(host);
1609 return ret;
1610}
1611
1612static int sdhci_check_ro(struct sdhci_host *host) 1638static int sdhci_check_ro(struct sdhci_host *host)
1613{ 1639{
1614 unsigned long flags; 1640 unsigned long flags;
@@ -1633,8 +1659,9 @@ static int sdhci_check_ro(struct sdhci_host *host)
1633 1659
1634#define SAMPLE_COUNT 5 1660#define SAMPLE_COUNT 5
1635 1661
1636static int sdhci_do_get_ro(struct sdhci_host *host) 1662static int sdhci_get_ro(struct mmc_host *mmc)
1637{ 1663{
1664 struct sdhci_host *host = mmc_priv(mmc);
1638 int i, ro_count; 1665 int i, ro_count;
1639 1666
1640 if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT)) 1667 if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT))
@@ -1659,17 +1686,6 @@ static void sdhci_hw_reset(struct mmc_host *mmc)
1659 host->ops->hw_reset(host); 1686 host->ops->hw_reset(host);
1660} 1687}
1661 1688
1662static int sdhci_get_ro(struct mmc_host *mmc)
1663{
1664 struct sdhci_host *host = mmc_priv(mmc);
1665 int ret;
1666
1667 sdhci_runtime_pm_get(host);
1668 ret = sdhci_do_get_ro(host);
1669 sdhci_runtime_pm_put(host);
1670 return ret;
1671}
1672
1673static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable) 1689static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable)
1674{ 1690{
1675 if (!(host->flags & SDHCI_DEVICE_DEAD)) { 1691 if (!(host->flags & SDHCI_DEVICE_DEAD)) {
@@ -1689,8 +1705,6 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1689 struct sdhci_host *host = mmc_priv(mmc); 1705 struct sdhci_host *host = mmc_priv(mmc);
1690 unsigned long flags; 1706 unsigned long flags;
1691 1707
1692 sdhci_runtime_pm_get(host);
1693
1694 spin_lock_irqsave(&host->lock, flags); 1708 spin_lock_irqsave(&host->lock, flags);
1695 if (enable) 1709 if (enable)
1696 host->flags |= SDHCI_SDIO_IRQ_ENABLED; 1710 host->flags |= SDHCI_SDIO_IRQ_ENABLED;
@@ -1699,14 +1713,12 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1699 1713
1700 sdhci_enable_sdio_irq_nolock(host, enable); 1714 sdhci_enable_sdio_irq_nolock(host, enable);
1701 spin_unlock_irqrestore(&host->lock, flags); 1715 spin_unlock_irqrestore(&host->lock, flags);
1702
1703 sdhci_runtime_pm_put(host);
1704} 1716}
1705 1717
1706static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host, 1718static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1707 struct mmc_ios *ios) 1719 struct mmc_ios *ios)
1708{ 1720{
1709 struct mmc_host *mmc = host->mmc; 1721 struct sdhci_host *host = mmc_priv(mmc);
1710 u16 ctrl; 1722 u16 ctrl;
1711 int ret; 1723 int ret;
1712 1724
@@ -1794,29 +1806,13 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1794 } 1806 }
1795} 1807}
1796 1808
1797static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1798 struct mmc_ios *ios)
1799{
1800 struct sdhci_host *host = mmc_priv(mmc);
1801 int err;
1802
1803 if (host->version < SDHCI_SPEC_300)
1804 return 0;
1805 sdhci_runtime_pm_get(host);
1806 err = sdhci_do_start_signal_voltage_switch(host, ios);
1807 sdhci_runtime_pm_put(host);
1808 return err;
1809}
1810
1811static int sdhci_card_busy(struct mmc_host *mmc) 1809static int sdhci_card_busy(struct mmc_host *mmc)
1812{ 1810{
1813 struct sdhci_host *host = mmc_priv(mmc); 1811 struct sdhci_host *host = mmc_priv(mmc);
1814 u32 present_state; 1812 u32 present_state;
1815 1813
1816 sdhci_runtime_pm_get(host);
1817 /* Check whether DAT[3:0] is 0000 */ 1814 /* Check whether DAT[3:0] is 0000 */
1818 present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); 1815 present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
1819 sdhci_runtime_pm_put(host);
1820 1816
1821 return !(present_state & SDHCI_DATA_LVL_MASK); 1817 return !(present_state & SDHCI_DATA_LVL_MASK);
1822} 1818}
@@ -1843,7 +1839,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1843 unsigned int tuning_count = 0; 1839 unsigned int tuning_count = 0;
1844 bool hs400_tuning; 1840 bool hs400_tuning;
1845 1841
1846 sdhci_runtime_pm_get(host);
1847 spin_lock_irqsave(&host->lock, flags); 1842 spin_lock_irqsave(&host->lock, flags);
1848 1843
1849 hs400_tuning = host->flags & SDHCI_HS400_TUNING; 1844 hs400_tuning = host->flags & SDHCI_HS400_TUNING;
@@ -1879,8 +1874,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1879 break; 1874 break;
1880 1875
1881 case MMC_TIMING_UHS_SDR50: 1876 case MMC_TIMING_UHS_SDR50:
1882 if (host->flags & SDHCI_SDR50_NEEDS_TUNING || 1877 if (host->flags & SDHCI_SDR50_NEEDS_TUNING)
1883 host->flags & SDHCI_SDR104_NEEDS_TUNING)
1884 break; 1878 break;
1885 /* FALLTHROUGH */ 1879 /* FALLTHROUGH */
1886 1880
@@ -1891,7 +1885,6 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1891 if (host->ops->platform_execute_tuning) { 1885 if (host->ops->platform_execute_tuning) {
1892 spin_unlock_irqrestore(&host->lock, flags); 1886 spin_unlock_irqrestore(&host->lock, flags);
1893 err = host->ops->platform_execute_tuning(host, opcode); 1887 err = host->ops->platform_execute_tuning(host, opcode);
1894 sdhci_runtime_pm_put(host);
1895 return err; 1888 return err;
1896 } 1889 }
1897 1890
@@ -2023,8 +2016,6 @@ out:
2023 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); 2016 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE);
2024out_unlock: 2017out_unlock:
2025 spin_unlock_irqrestore(&host->lock, flags); 2018 spin_unlock_irqrestore(&host->lock, flags);
2026 sdhci_runtime_pm_put(host);
2027
2028 return err; 2019 return err;
2029} 2020}
2030 2021
@@ -2105,7 +2096,7 @@ static void sdhci_card_event(struct mmc_host *mmc)
2105 if (host->ops->card_event) 2096 if (host->ops->card_event)
2106 host->ops->card_event(host); 2097 host->ops->card_event(host);
2107 2098
2108 present = sdhci_do_get_cd(host); 2099 present = sdhci_get_cd(host->mmc);
2109 2100
2110 spin_lock_irqsave(&host->lock, flags); 2101 spin_lock_irqsave(&host->lock, flags);
2111 2102
@@ -2214,15 +2205,12 @@ static void sdhci_tasklet_finish(unsigned long param)
2214 host->cmd = NULL; 2205 host->cmd = NULL;
2215 host->data = NULL; 2206 host->data = NULL;
2216 2207
2217#ifndef SDHCI_USE_LEDS_CLASS 2208 sdhci_led_deactivate(host);
2218 sdhci_deactivate_led(host);
2219#endif
2220 2209
2221 mmiowb(); 2210 mmiowb();
2222 spin_unlock_irqrestore(&host->lock, flags); 2211 spin_unlock_irqrestore(&host->lock, flags);
2223 2212
2224 mmc_request_done(host->mmc, mrq); 2213 mmc_request_done(host->mmc, mrq);
2225 sdhci_runtime_pm_put(host);
2226} 2214}
2227 2215
2228static void sdhci_timeout_timer(unsigned long data) 2216static void sdhci_timeout_timer(unsigned long data)
@@ -2679,7 +2667,7 @@ int sdhci_resume_host(struct sdhci_host *host)
2679 sdhci_init(host, 0); 2667 sdhci_init(host, 0);
2680 host->pwr = 0; 2668 host->pwr = 0;
2681 host->clock = 0; 2669 host->clock = 0;
2682 sdhci_do_set_ios(host, &host->mmc->ios); 2670 sdhci_set_ios(host->mmc, &host->mmc->ios);
2683 } else { 2671 } else {
2684 sdhci_init(host, (host->mmc->pm_flags & MMC_PM_KEEP_POWER)); 2672 sdhci_init(host, (host->mmc->pm_flags & MMC_PM_KEEP_POWER));
2685 mmiowb(); 2673 mmiowb();
@@ -2703,33 +2691,6 @@ int sdhci_resume_host(struct sdhci_host *host)
2703 2691
2704EXPORT_SYMBOL_GPL(sdhci_resume_host); 2692EXPORT_SYMBOL_GPL(sdhci_resume_host);
2705 2693
2706static int sdhci_runtime_pm_get(struct sdhci_host *host)
2707{
2708 return pm_runtime_get_sync(host->mmc->parent);
2709}
2710
2711static int sdhci_runtime_pm_put(struct sdhci_host *host)
2712{
2713 pm_runtime_mark_last_busy(host->mmc->parent);
2714 return pm_runtime_put_autosuspend(host->mmc->parent);
2715}
2716
2717static void sdhci_runtime_pm_bus_on(struct sdhci_host *host)
2718{
2719 if (host->bus_on)
2720 return;
2721 host->bus_on = true;
2722 pm_runtime_get_noresume(host->mmc->parent);
2723}
2724
2725static void sdhci_runtime_pm_bus_off(struct sdhci_host *host)
2726{
2727 if (!host->bus_on)
2728 return;
2729 host->bus_on = false;
2730 pm_runtime_put_noidle(host->mmc->parent);
2731}
2732
2733int sdhci_runtime_suspend_host(struct sdhci_host *host) 2694int sdhci_runtime_suspend_host(struct sdhci_host *host)
2734{ 2695{
2735 unsigned long flags; 2696 unsigned long flags;
@@ -2768,8 +2729,8 @@ int sdhci_runtime_resume_host(struct sdhci_host *host)
2768 /* Force clock and power re-program */ 2729 /* Force clock and power re-program */
2769 host->pwr = 0; 2730 host->pwr = 0;
2770 host->clock = 0; 2731 host->clock = 0;
2771 sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios); 2732 sdhci_start_signal_voltage_switch(host->mmc, &host->mmc->ios);
2772 sdhci_do_set_ios(host, &host->mmc->ios); 2733 sdhci_set_ios(host->mmc, &host->mmc->ios);
2773 2734
2774 if ((host_flags & SDHCI_PV_ENABLED) && 2735 if ((host_flags & SDHCI_PV_ENABLED) &&
2775 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) { 2736 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
@@ -3014,7 +2975,8 @@ int sdhci_add_host(struct sdhci_host *host)
3014 if (!host->ops->get_max_clock) { 2975 if (!host->ops->get_max_clock) {
3015 pr_err("%s: Hardware doesn't specify base clock frequency.\n", 2976 pr_err("%s: Hardware doesn't specify base clock frequency.\n",
3016 mmc_hostname(mmc)); 2977 mmc_hostname(mmc));
3017 return -ENODEV; 2978 ret = -ENODEV;
2979 goto undma;
3018 } 2980 }
3019 host->max_clk = host->ops->get_max_clock(host); 2981 host->max_clk = host->ops->get_max_clock(host);
3020 } 2982 }
@@ -3051,7 +3013,7 @@ int sdhci_add_host(struct sdhci_host *host)
3051 } else 3013 } else
3052 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; 3014 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200;
3053 3015
3054 if (!mmc->f_max || (mmc->f_max && (mmc->f_max > max_clk))) 3016 if (!mmc->f_max || mmc->f_max > max_clk)
3055 mmc->f_max = max_clk; 3017 mmc->f_max = max_clk;
3056 3018
3057 if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { 3019 if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) {
@@ -3064,7 +3026,8 @@ int sdhci_add_host(struct sdhci_host *host)
3064 } else { 3026 } else {
3065 pr_err("%s: Hardware doesn't specify timeout clock frequency.\n", 3027 pr_err("%s: Hardware doesn't specify timeout clock frequency.\n",
3066 mmc_hostname(mmc)); 3028 mmc_hostname(mmc));
3067 return -ENODEV; 3029 ret = -ENODEV;
3030 goto undma;
3068 } 3031 }
3069 } 3032 }
3070 3033
@@ -3118,8 +3081,9 @@ int sdhci_add_host(struct sdhci_host *host)
3118 mmc->caps |= MMC_CAP_NEEDS_POLL; 3081 mmc->caps |= MMC_CAP_NEEDS_POLL;
3119 3082
3120 /* If there are external regulators, get them */ 3083 /* If there are external regulators, get them */
3121 if (mmc_regulator_get_supply(mmc) == -EPROBE_DEFER) 3084 ret = mmc_regulator_get_supply(mmc);
3122 return -EPROBE_DEFER; 3085 if (ret == -EPROBE_DEFER)
3086 goto undma;
3123 3087
3124 /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */ 3088 /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
3125 if (!IS_ERR(mmc->supply.vqmmc)) { 3089 if (!IS_ERR(mmc->supply.vqmmc)) {
@@ -3174,10 +3138,6 @@ int sdhci_add_host(struct sdhci_host *host)
3174 if (caps[1] & SDHCI_USE_SDR50_TUNING) 3138 if (caps[1] & SDHCI_USE_SDR50_TUNING)
3175 host->flags |= SDHCI_SDR50_NEEDS_TUNING; 3139 host->flags |= SDHCI_SDR50_NEEDS_TUNING;
3176 3140
3177 /* Does the host need tuning for SDR104 / HS200? */
3178 if (mmc->caps2 & MMC_CAP2_HS200)
3179 host->flags |= SDHCI_SDR104_NEEDS_TUNING;
3180
3181 /* Driver Type(s) (A, C, D) supported by the host */ 3141 /* Driver Type(s) (A, C, D) supported by the host */
3182 if (caps[1] & SDHCI_DRIVER_TYPE_A) 3142 if (caps[1] & SDHCI_DRIVER_TYPE_A)
3183 mmc->caps |= MMC_CAP_DRIVER_TYPE_A; 3143 mmc->caps |= MMC_CAP_DRIVER_TYPE_A;
@@ -3276,7 +3236,8 @@ int sdhci_add_host(struct sdhci_host *host)
3276 if (mmc->ocr_avail == 0) { 3236 if (mmc->ocr_avail == 0) {
3277 pr_err("%s: Hardware doesn't report any support voltages.\n", 3237 pr_err("%s: Hardware doesn't report any support voltages.\n",
3278 mmc_hostname(mmc)); 3238 mmc_hostname(mmc));
3279 return -ENODEV; 3239 ret = -ENODEV;
3240 goto unreg;
3280 } 3241 }
3281 3242
3282 spin_lock_init(&host->lock); 3243 spin_lock_init(&host->lock);
@@ -3360,25 +3321,18 @@ int sdhci_add_host(struct sdhci_host *host)
3360 sdhci_dumpregs(host); 3321 sdhci_dumpregs(host);
3361#endif 3322#endif
3362 3323
3363#ifdef SDHCI_USE_LEDS_CLASS 3324 ret = sdhci_led_register(host);
3364 snprintf(host->led_name, sizeof(host->led_name),
3365 "%s::", mmc_hostname(mmc));
3366 host->led.name = host->led_name;
3367 host->led.brightness = LED_OFF;
3368 host->led.default_trigger = mmc_hostname(mmc);
3369 host->led.brightness_set = sdhci_led_control;
3370
3371 ret = led_classdev_register(mmc_dev(mmc), &host->led);
3372 if (ret) { 3325 if (ret) {
3373 pr_err("%s: Failed to register LED device: %d\n", 3326 pr_err("%s: Failed to register LED device: %d\n",
3374 mmc_hostname(mmc), ret); 3327 mmc_hostname(mmc), ret);
3375 goto reset; 3328 goto unirq;
3376 } 3329 }
3377#endif
3378 3330
3379 mmiowb(); 3331 mmiowb();
3380 3332
3381 mmc_add_host(mmc); 3333 ret = mmc_add_host(mmc);
3334 if (ret)
3335 goto unled;
3382 3336
3383 pr_info("%s: SDHCI controller on %s [%s] using %s\n", 3337 pr_info("%s: SDHCI controller on %s [%s] using %s\n",
3384 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), 3338 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
@@ -3390,15 +3344,25 @@ int sdhci_add_host(struct sdhci_host *host)
3390 3344
3391 return 0; 3345 return 0;
3392 3346
3393#ifdef SDHCI_USE_LEDS_CLASS 3347unled:
3394reset: 3348 sdhci_led_unregister(host);
3349unirq:
3395 sdhci_do_reset(host, SDHCI_RESET_ALL); 3350 sdhci_do_reset(host, SDHCI_RESET_ALL);
3396 sdhci_writel(host, 0, SDHCI_INT_ENABLE); 3351 sdhci_writel(host, 0, SDHCI_INT_ENABLE);
3397 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); 3352 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);
3398 free_irq(host->irq, host); 3353 free_irq(host->irq, host);
3399#endif
3400untasklet: 3354untasklet:
3401 tasklet_kill(&host->finish_tasklet); 3355 tasklet_kill(&host->finish_tasklet);
3356unreg:
3357 if (!IS_ERR(mmc->supply.vqmmc))
3358 regulator_disable(mmc->supply.vqmmc);
3359undma:
3360 if (host->align_buffer)
3361 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz +
3362 host->adma_table_sz, host->align_buffer,
3363 host->align_addr);
3364 host->adma_table = NULL;
3365 host->align_buffer = NULL;
3402 3366
3403 return ret; 3367 return ret;
3404} 3368}
@@ -3430,9 +3394,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3430 3394
3431 mmc_remove_host(mmc); 3395 mmc_remove_host(mmc);
3432 3396
3433#ifdef SDHCI_USE_LEDS_CLASS 3397 sdhci_led_unregister(host);
3434 led_classdev_unregister(&host->led);
3435#endif
3436 3398
3437 if (!dead) 3399 if (!dead)
3438 sdhci_do_reset(host, SDHCI_RESET_ALL); 3400 sdhci_do_reset(host, SDHCI_RESET_ALL);
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 0f39f4f84d10..609f87ca536b 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -417,11 +417,6 @@ struct sdhci_host {
417#define SDHCI_QUIRK2_ACMD23_BROKEN (1<<14) 417#define SDHCI_QUIRK2_ACMD23_BROKEN (1<<14)
418/* Broken Clock divider zero in controller */ 418/* Broken Clock divider zero in controller */
419#define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN (1<<15) 419#define SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN (1<<15)
420/*
421 * When internal clock is disabled, a delay is needed before modifying the
422 * SD clock frequency or enabling back the internal clock.
423 */
424#define SDHCI_QUIRK2_NEED_DELAY_AFTER_INT_CLK_RST (1<<16)
425 420
426 int irq; /* Device IRQ */ 421 int irq; /* Device IRQ */
427 void __iomem *ioaddr; /* Mapped address */ 422 void __iomem *ioaddr; /* Mapped address */
@@ -433,7 +428,7 @@ struct sdhci_host {
433 struct mmc_host_ops mmc_host_ops; /* MMC host ops */ 428 struct mmc_host_ops mmc_host_ops; /* MMC host ops */
434 u64 dma_mask; /* custom DMA mask */ 429 u64 dma_mask; /* custom DMA mask */
435 430
436#if defined(CONFIG_LEDS_CLASS) || defined(CONFIG_LEDS_CLASS_MODULE) 431#if IS_ENABLED(CONFIG_LEDS_CLASS)
437 struct led_classdev led; /* LED control */ 432 struct led_classdev led; /* LED control */
438 char led_name[32]; 433 char led_name[32];
439#endif 434#endif
@@ -450,7 +445,6 @@ struct sdhci_host {
450#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */ 445#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
451#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */ 446#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
452#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */ 447#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
453#define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
454#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */ 448#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */
455#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */ 449#define SDHCI_HS400_TUNING (1<<13) /* Tuning for HS400 */
456 450
@@ -661,6 +655,8 @@ static inline bool sdhci_sdio_irq_enabled(struct sdhci_host *host)
661 return !!(host->flags & SDHCI_SDIO_IRQ_ENABLED); 655 return !!(host->flags & SDHCI_SDIO_IRQ_ENABLED);
662} 656}
663 657
658u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock,
659 unsigned int *actual_clock);
664void sdhci_set_clock(struct sdhci_host *host, unsigned int clock); 660void sdhci_set_clock(struct sdhci_host *host, unsigned int clock);
665void sdhci_set_power(struct sdhci_host *host, unsigned char mode, 661void sdhci_set_power(struct sdhci_host *host, unsigned char mode,
666 unsigned short vdd); 662 unsigned short vdd);
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index d9a655f47d41..dd64b8663984 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -248,7 +248,6 @@ struct sh_mmcif_host {
248 int sg_idx; 248 int sg_idx;
249 int sg_blkidx; 249 int sg_blkidx;
250 bool power; 250 bool power;
251 bool card_present;
252 bool ccs_enable; /* Command Completion Signal support */ 251 bool ccs_enable; /* Command Completion Signal support */
253 bool clk_ctrl2_enable; 252 bool clk_ctrl2_enable;
254 struct mutex thread_lock; 253 struct mutex thread_lock;
@@ -1064,16 +1063,6 @@ static void sh_mmcif_clk_setup(struct sh_mmcif_host *host)
1064 host->mmc->f_max, host->mmc->f_min); 1063 host->mmc->f_max, host->mmc->f_min);
1065} 1064}
1066 1065
1067static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios)
1068{
1069 struct mmc_host *mmc = host->mmc;
1070
1071 if (!IS_ERR(mmc->supply.vmmc))
1072 /* Errors ignored... */
1073 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
1074 ios->power_mode ? ios->vdd : 0);
1075}
1076
1077static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 1066static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1078{ 1067{
1079 struct sh_mmcif_host *host = mmc_priv(mmc); 1068 struct sh_mmcif_host *host = mmc_priv(mmc);
@@ -1091,42 +1080,32 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1091 host->state = STATE_IOS; 1080 host->state = STATE_IOS;
1092 spin_unlock_irqrestore(&host->lock, flags); 1081 spin_unlock_irqrestore(&host->lock, flags);
1093 1082
1094 if (ios->power_mode == MMC_POWER_UP) { 1083 switch (ios->power_mode) {
1095 if (!host->card_present) { 1084 case MMC_POWER_UP:
1096 /* See if we also get DMA */ 1085 if (!IS_ERR(mmc->supply.vmmc))
1086 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, ios->vdd);
1087 if (!host->power) {
1088 clk_prepare_enable(host->clk);
1089 pm_runtime_get_sync(dev);
1090 sh_mmcif_sync_reset(host);
1097 sh_mmcif_request_dma(host); 1091 sh_mmcif_request_dma(host);
1098 host->card_present = true; 1092 host->power = true;
1099 }
1100 sh_mmcif_set_power(host, ios);
1101 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) {
1102 /* clock stop */
1103 sh_mmcif_clock_control(host, 0);
1104 if (ios->power_mode == MMC_POWER_OFF) {
1105 if (host->card_present) {
1106 sh_mmcif_release_dma(host);
1107 host->card_present = false;
1108 }
1109 } 1093 }
1094 break;
1095 case MMC_POWER_OFF:
1096 if (!IS_ERR(mmc->supply.vmmc))
1097 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0);
1110 if (host->power) { 1098 if (host->power) {
1111 pm_runtime_put_sync(dev); 1099 sh_mmcif_clock_control(host, 0);
1100 sh_mmcif_release_dma(host);
1101 pm_runtime_put(dev);
1112 clk_disable_unprepare(host->clk); 1102 clk_disable_unprepare(host->clk);
1113 host->power = false; 1103 host->power = false;
1114 if (ios->power_mode == MMC_POWER_OFF)
1115 sh_mmcif_set_power(host, ios);
1116 }
1117 host->state = STATE_IDLE;
1118 return;
1119 }
1120
1121 if (ios->clock) {
1122 if (!host->power) {
1123 clk_prepare_enable(host->clk);
1124
1125 pm_runtime_get_sync(dev);
1126 host->power = true;
1127 sh_mmcif_sync_reset(host);
1128 } 1104 }
1105 break;
1106 case MMC_POWER_ON:
1129 sh_mmcif_clock_control(host, ios->clock); 1107 sh_mmcif_clock_control(host, ios->clock);
1108 break;
1130 } 1109 }
1131 1110
1132 host->timing = ios->timing; 1111 host->timing = ios->timing;
@@ -1519,23 +1498,23 @@ static int sh_mmcif_probe(struct platform_device *pdev)
1519 1498
1520 platform_set_drvdata(pdev, host); 1499 platform_set_drvdata(pdev, host);
1521 1500
1522 pm_runtime_enable(dev);
1523 host->power = false;
1524
1525 host->clk = devm_clk_get(dev, NULL); 1501 host->clk = devm_clk_get(dev, NULL);
1526 if (IS_ERR(host->clk)) { 1502 if (IS_ERR(host->clk)) {
1527 ret = PTR_ERR(host->clk); 1503 ret = PTR_ERR(host->clk);
1528 dev_err(dev, "cannot get clock: %d\n", ret); 1504 dev_err(dev, "cannot get clock: %d\n", ret);
1529 goto err_pm; 1505 goto err_host;
1530 } 1506 }
1531 1507
1532 ret = clk_prepare_enable(host->clk); 1508 ret = clk_prepare_enable(host->clk);
1533 if (ret < 0) 1509 if (ret < 0)
1534 goto err_pm; 1510 goto err_host;
1535 1511
1536 sh_mmcif_clk_setup(host); 1512 sh_mmcif_clk_setup(host);
1537 1513
1538 ret = pm_runtime_resume(dev); 1514 pm_runtime_enable(dev);
1515 host->power = false;
1516
1517 ret = pm_runtime_get_sync(dev);
1539 if (ret < 0) 1518 if (ret < 0)
1540 goto err_clk; 1519 goto err_clk;
1541 1520
@@ -1579,12 +1558,13 @@ static int sh_mmcif_probe(struct platform_device *pdev)
1579 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0xffff, 1558 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0xffff,
1580 clk_get_rate(host->clk) / 1000000UL); 1559 clk_get_rate(host->clk) / 1000000UL);
1581 1560
1561 pm_runtime_put(dev);
1582 clk_disable_unprepare(host->clk); 1562 clk_disable_unprepare(host->clk);
1583 return ret; 1563 return ret;
1584 1564
1585err_clk: 1565err_clk:
1586 clk_disable_unprepare(host->clk); 1566 clk_disable_unprepare(host->clk);
1587err_pm: 1567 pm_runtime_put_sync(dev);
1588 pm_runtime_disable(dev); 1568 pm_runtime_disable(dev);
1589err_host: 1569err_host:
1590 mmc_free_host(mmc); 1570 mmc_free_host(mmc);
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c
index 9aa147959276..f750f9494410 100644
--- a/drivers/mmc/host/sh_mobile_sdhi.c
+++ b/drivers/mmc/host/sh_mobile_sdhi.c
@@ -28,10 +28,12 @@
28#include <linux/of_device.h> 28#include <linux/of_device.h>
29#include <linux/platform_device.h> 29#include <linux/platform_device.h>
30#include <linux/mmc/host.h> 30#include <linux/mmc/host.h>
31#include <linux/mmc/sh_mobile_sdhi.h>
32#include <linux/mfd/tmio.h> 31#include <linux/mfd/tmio.h>
33#include <linux/sh_dma.h> 32#include <linux/sh_dma.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/pinctrl/consumer.h>
35#include <linux/pinctrl/pinctrl-state.h>
36#include <linux/regulator/consumer.h>
35 37
36#include "tmio_mmc.h" 38#include "tmio_mmc.h"
37 39
@@ -48,10 +50,8 @@ struct sh_mobile_sdhi_of_data {
48 unsigned bus_shift; 50 unsigned bus_shift;
49}; 51};
50 52
51static const struct sh_mobile_sdhi_of_data sh_mobile_sdhi_of_cfg[] = { 53static const struct sh_mobile_sdhi_of_data of_default_cfg = {
52 { 54 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
53 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
54 },
55}; 55};
56 56
57static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = { 57static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = {
@@ -62,7 +62,7 @@ static const struct sh_mobile_sdhi_of_data of_rcar_gen1_compatible = {
62 62
63static const struct sh_mobile_sdhi_of_data of_rcar_gen2_compatible = { 63static const struct sh_mobile_sdhi_of_data of_rcar_gen2_compatible = {
64 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE | 64 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
65 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_FAST_CLK_CHG, 65 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2,
66 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ, 66 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
67 .dma_buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES, 67 .dma_buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES,
68 .dma_rx_offset = 0x2000, 68 .dma_rx_offset = 0x2000,
@@ -70,17 +70,16 @@ static const struct sh_mobile_sdhi_of_data of_rcar_gen2_compatible = {
70 70
71static const struct sh_mobile_sdhi_of_data of_rcar_gen3_compatible = { 71static const struct sh_mobile_sdhi_of_data of_rcar_gen3_compatible = {
72 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE | 72 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT | TMIO_MMC_WRPROTECT_DISABLE |
73 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_FAST_CLK_CHG, 73 TMIO_MMC_CLK_ACTUAL | TMIO_MMC_MIN_RCAR2,
74 .capabilities = MMC_CAP_SD_HIGHSPEED, 74 .capabilities = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
75 .bus_shift = 2, 75 .bus_shift = 2,
76}; 76};
77 77
78static const struct of_device_id sh_mobile_sdhi_of_match[] = { 78static const struct of_device_id sh_mobile_sdhi_of_match[] = {
79 { .compatible = "renesas,sdhi-shmobile" }, 79 { .compatible = "renesas,sdhi-shmobile" },
80 { .compatible = "renesas,sdhi-sh7372" }, 80 { .compatible = "renesas,sdhi-sh73a0", .data = &of_default_cfg, },
81 { .compatible = "renesas,sdhi-sh73a0", .data = &sh_mobile_sdhi_of_cfg[0], }, 81 { .compatible = "renesas,sdhi-r8a73a4", .data = &of_default_cfg, },
82 { .compatible = "renesas,sdhi-r8a73a4", .data = &sh_mobile_sdhi_of_cfg[0], }, 82 { .compatible = "renesas,sdhi-r8a7740", .data = &of_default_cfg, },
83 { .compatible = "renesas,sdhi-r8a7740", .data = &sh_mobile_sdhi_of_cfg[0], },
84 { .compatible = "renesas,sdhi-r8a7778", .data = &of_rcar_gen1_compatible, }, 83 { .compatible = "renesas,sdhi-r8a7778", .data = &of_rcar_gen1_compatible, },
85 { .compatible = "renesas,sdhi-r8a7779", .data = &of_rcar_gen1_compatible, }, 84 { .compatible = "renesas,sdhi-r8a7779", .data = &of_rcar_gen1_compatible, },
86 { .compatible = "renesas,sdhi-r8a7790", .data = &of_rcar_gen2_compatible, }, 85 { .compatible = "renesas,sdhi-r8a7790", .data = &of_rcar_gen2_compatible, },
@@ -97,6 +96,8 @@ struct sh_mobile_sdhi {
97 struct clk *clk; 96 struct clk *clk;
98 struct tmio_mmc_data mmc_data; 97 struct tmio_mmc_data mmc_data;
99 struct tmio_mmc_dma dma_priv; 98 struct tmio_mmc_dma dma_priv;
99 struct pinctrl *pinctrl;
100 struct pinctrl_state *pins_default, *pins_uhs;
100}; 101};
101 102
102static void sh_mobile_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width) 103static void sh_mobile_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width)
@@ -131,16 +132,28 @@ static void sh_mobile_sdhi_sdbuf_width(struct tmio_mmc_host *host, int width)
131 sd_ctrl_write16(host, EXT_ACC, val); 132 sd_ctrl_write16(host, EXT_ACC, val);
132} 133}
133 134
134static int sh_mobile_sdhi_clk_enable(struct platform_device *pdev, unsigned int *f) 135static int sh_mobile_sdhi_clk_enable(struct tmio_mmc_host *host)
135{ 136{
136 struct mmc_host *mmc = platform_get_drvdata(pdev); 137 struct mmc_host *mmc = host->mmc;
137 struct tmio_mmc_host *host = mmc_priv(mmc);
138 struct sh_mobile_sdhi *priv = host_to_priv(host); 138 struct sh_mobile_sdhi *priv = host_to_priv(host);
139 int ret = clk_prepare_enable(priv->clk); 139 int ret = clk_prepare_enable(priv->clk);
140 if (ret < 0) 140 if (ret < 0)
141 return ret; 141 return ret;
142 142
143 *f = clk_get_rate(priv->clk); 143 /*
144 * The clock driver may not know what maximum frequency
145 * actually works, so it should be set with the max-frequency
146 * property which will already have been read to f_max. If it
147 * was missing, assume the current frequency is the maximum.
148 */
149 if (!mmc->f_max)
150 mmc->f_max = clk_get_rate(priv->clk);
151
152 /*
153 * Minimum frequency is the minimum input clock frequency
154 * divided by our maximum divider.
155 */
156 mmc->f_min = max(clk_round_rate(priv->clk, 1) / 512, 1L);
144 157
145 /* enable 16bit data access on SDBUF as default */ 158 /* enable 16bit data access on SDBUF as default */
146 sh_mobile_sdhi_sdbuf_width(host, 16); 159 sh_mobile_sdhi_sdbuf_width(host, 16);
@@ -148,19 +161,92 @@ static int sh_mobile_sdhi_clk_enable(struct platform_device *pdev, unsigned int
148 return 0; 161 return 0;
149} 162}
150 163
151static void sh_mobile_sdhi_clk_disable(struct platform_device *pdev) 164static unsigned int sh_mobile_sdhi_clk_update(struct tmio_mmc_host *host,
165 unsigned int new_clock)
166{
167 struct sh_mobile_sdhi *priv = host_to_priv(host);
168 unsigned int freq, diff, best_freq = 0, diff_min = ~0;
169 int i, ret;
170
171 /* tested only on RCar Gen2+ currently; may work for others */
172 if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2))
173 return clk_get_rate(priv->clk);
174
175 /*
176 * We want the bus clock to be as close as possible to, but no
177 * greater than, new_clock. As we can divide by 1 << i for
178 * any i in [0, 9] we want the input clock to be as close as
179 * possible, but no greater than, new_clock << i.
180 */
181 for (i = min(9, ilog2(UINT_MAX / new_clock)); i >= 0; i--) {
182 freq = clk_round_rate(priv->clk, new_clock << i);
183 if (freq > (new_clock << i)) {
184 /* Too fast; look for a slightly slower option */
185 freq = clk_round_rate(priv->clk,
186 (new_clock << i) / 4 * 3);
187 if (freq > (new_clock << i))
188 continue;
189 }
190
191 diff = new_clock - (freq >> i);
192 if (diff <= diff_min) {
193 best_freq = freq;
194 diff_min = diff;
195 }
196 }
197
198 ret = clk_set_rate(priv->clk, best_freq);
199
200 return ret == 0 ? best_freq : clk_get_rate(priv->clk);
201}
202
203static void sh_mobile_sdhi_clk_disable(struct tmio_mmc_host *host)
152{ 204{
153 struct mmc_host *mmc = platform_get_drvdata(pdev);
154 struct tmio_mmc_host *host = mmc_priv(mmc);
155 struct sh_mobile_sdhi *priv = host_to_priv(host); 205 struct sh_mobile_sdhi *priv = host_to_priv(host);
206
156 clk_disable_unprepare(priv->clk); 207 clk_disable_unprepare(priv->clk);
157} 208}
158 209
210static int sh_mobile_sdhi_start_signal_voltage_switch(struct mmc_host *mmc,
211 struct mmc_ios *ios)
212{
213 struct tmio_mmc_host *host = mmc_priv(mmc);
214 struct sh_mobile_sdhi *priv = host_to_priv(host);
215 struct pinctrl_state *pin_state;
216 int ret;
217
218 switch (ios->signal_voltage) {
219 case MMC_SIGNAL_VOLTAGE_330:
220 pin_state = priv->pins_default;
221 break;
222 case MMC_SIGNAL_VOLTAGE_180:
223 pin_state = priv->pins_uhs;
224 break;
225 default:
226 return -EINVAL;
227 }
228
229 /*
230 * If anything is missing, assume signal voltage is fixed at
231 * 3.3V and succeed/fail accordingly.
232 */
233 if (IS_ERR(priv->pinctrl) || IS_ERR(pin_state))
234 return ios->signal_voltage ==
235 MMC_SIGNAL_VOLTAGE_330 ? 0 : -EINVAL;
236
237 ret = mmc_regulator_set_vqmmc(host->mmc, ios);
238 if (ret)
239 return ret;
240
241 return pinctrl_select_state(priv->pinctrl, pin_state);
242}
243
159static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host) 244static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host)
160{ 245{
161 int timeout = 1000; 246 int timeout = 1000;
162 247
163 while (--timeout && !(sd_ctrl_read16(host, CTL_STATUS2) & (1 << 13))) 248 while (--timeout && !(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS)
249 & TMIO_STAT_SCLKDIVEN))
164 udelay(1); 250 udelay(1);
165 251
166 if (!timeout) { 252 if (!timeout) {
@@ -226,7 +312,6 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
226 struct tmio_mmc_host *host; 312 struct tmio_mmc_host *host;
227 struct resource *res; 313 struct resource *res;
228 int irq, ret, i = 0; 314 int irq, ret, i = 0;
229 bool multiplexed_isr = true;
230 struct tmio_mmc_dma *dma_priv; 315 struct tmio_mmc_dma *dma_priv;
231 316
232 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 317 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -247,6 +332,14 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
247 goto eprobe; 332 goto eprobe;
248 } 333 }
249 334
335 priv->pinctrl = devm_pinctrl_get(&pdev->dev);
336 if (!IS_ERR(priv->pinctrl)) {
337 priv->pins_default = pinctrl_lookup_state(priv->pinctrl,
338 PINCTRL_STATE_DEFAULT);
339 priv->pins_uhs = pinctrl_lookup_state(priv->pinctrl,
340 "state_uhs");
341 }
342
250 host = tmio_mmc_host_alloc(pdev); 343 host = tmio_mmc_host_alloc(pdev);
251 if (!host) { 344 if (!host) {
252 ret = -ENOMEM; 345 ret = -ENOMEM;
@@ -267,8 +360,10 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
267 host->dma = dma_priv; 360 host->dma = dma_priv;
268 host->write16_hook = sh_mobile_sdhi_write16_hook; 361 host->write16_hook = sh_mobile_sdhi_write16_hook;
269 host->clk_enable = sh_mobile_sdhi_clk_enable; 362 host->clk_enable = sh_mobile_sdhi_clk_enable;
363 host->clk_update = sh_mobile_sdhi_clk_update;
270 host->clk_disable = sh_mobile_sdhi_clk_disable; 364 host->clk_disable = sh_mobile_sdhi_clk_disable;
271 host->multi_io_quirk = sh_mobile_sdhi_multi_io_quirk; 365 host->multi_io_quirk = sh_mobile_sdhi_multi_io_quirk;
366 host->start_signal_voltage_switch = sh_mobile_sdhi_start_signal_voltage_switch;
272 367
273 /* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */ 368 /* Orginally registers were 16 bit apart, could be 32 or 64 nowadays */
274 if (!host->bus_shift && resource_size(res) > 0x100) /* old way to determine the shift */ 369 if (!host->bus_shift && resource_size(res) > 0x100) /* old way to determine the shift */
@@ -308,63 +403,24 @@ static int sh_mobile_sdhi_probe(struct platform_device *pdev)
308 if (ret < 0) 403 if (ret < 0)
309 goto efree; 404 goto efree;
310 405
311 /* 406 while (1) {
312 * Allow one or more specific (named) ISRs or 407 irq = platform_get_irq(pdev, i);
313 * one or more multiplexed (un-named) ISRs. 408 if (irq < 0)
314 */ 409 break;
315 410 i++;
316 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT); 411 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0,
317 if (irq >= 0) {
318 multiplexed_isr = false;
319 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_card_detect_irq, 0,
320 dev_name(&pdev->dev), host);
321 if (ret)
322 goto eirq;
323 }
324
325 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO);
326 if (irq >= 0) {
327 multiplexed_isr = false;
328 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdio_irq, 0,
329 dev_name(&pdev->dev), host); 412 dev_name(&pdev->dev), host);
330 if (ret) 413 if (ret)
331 goto eirq; 414 goto eirq;
332 } 415 }
333 416
334 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDCARD); 417 /* There must be at least one IRQ source */
335 if (irq >= 0) { 418 if (!i) {
336 multiplexed_isr = false;
337 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_sdcard_irq, 0,
338 dev_name(&pdev->dev), host);
339 if (ret)
340 goto eirq;
341 } else if (!multiplexed_isr) {
342 dev_err(&pdev->dev,
343 "Principal SD-card IRQ is missing among named interrupts\n");
344 ret = irq; 419 ret = irq;
345 goto eirq; 420 goto eirq;
346 } 421 }
347 422
348 if (multiplexed_isr) { 423 dev_info(&pdev->dev, "%s base at 0x%08lx max clock rate %u MHz\n",
349 while (1) {
350 irq = platform_get_irq(pdev, i);
351 if (irq < 0)
352 break;
353 i++;
354 ret = devm_request_irq(&pdev->dev, irq, tmio_mmc_irq, 0,
355 dev_name(&pdev->dev), host);
356 if (ret)
357 goto eirq;
358 }
359
360 /* There must be at least one IRQ source */
361 if (!i) {
362 ret = irq;
363 goto eirq;
364 }
365 }
366
367 dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n",
368 mmc_hostname(host->mmc), (unsigned long) 424 mmc_hostname(host->mmc), (unsigned long)
369 (platform_get_resource(pdev, IORESOURCE_MEM, 0)->start), 425 (platform_get_resource(pdev, IORESOURCE_MEM, 0)->start),
370 host->mmc->f_max / 1000000); 426 host->mmc->f_max / 1000000);
diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
index 4a597f5a53e2..1aac2ad8edf2 100644
--- a/drivers/mmc/host/tmio_mmc.h
+++ b/drivers/mmc/host/tmio_mmc.h
@@ -1,6 +1,8 @@
1/* 1/*
2 * linux/drivers/mmc/host/tmio_mmc.h 2 * linux/drivers/mmc/host/tmio_mmc.h
3 * 3 *
4 * Copyright (C) 2016 Sang Engineering, Wolfram Sang
5 * Copyright (C) 2015-16 Renesas Electronics Corporation
4 * Copyright (C) 2007 Ian Molton 6 * Copyright (C) 2007 Ian Molton
5 * Copyright (C) 2004 Ian Molton 7 * Copyright (C) 2004 Ian Molton
6 * 8 *
@@ -18,12 +20,67 @@
18 20
19#include <linux/dmaengine.h> 21#include <linux/dmaengine.h>
20#include <linux/highmem.h> 22#include <linux/highmem.h>
21#include <linux/mmc/tmio.h>
22#include <linux/mutex.h> 23#include <linux/mutex.h>
23#include <linux/pagemap.h> 24#include <linux/pagemap.h>
24#include <linux/scatterlist.h> 25#include <linux/scatterlist.h>
25#include <linux/spinlock.h> 26#include <linux/spinlock.h>
26 27
28#define CTL_SD_CMD 0x00
29#define CTL_ARG_REG 0x04
30#define CTL_STOP_INTERNAL_ACTION 0x08
31#define CTL_XFER_BLK_COUNT 0xa
32#define CTL_RESPONSE 0x0c
33/* driver merges STATUS and following STATUS2 */
34#define CTL_STATUS 0x1c
35/* driver merges IRQ_MASK and following IRQ_MASK2 */
36#define CTL_IRQ_MASK 0x20
37#define CTL_SD_CARD_CLK_CTL 0x24
38#define CTL_SD_XFER_LEN 0x26
39#define CTL_SD_MEM_CARD_OPT 0x28
40#define CTL_SD_ERROR_DETAIL_STATUS 0x2c
41#define CTL_SD_DATA_PORT 0x30
42#define CTL_TRANSACTION_CTL 0x34
43#define CTL_SDIO_STATUS 0x36
44#define CTL_SDIO_IRQ_MASK 0x38
45#define CTL_DMA_ENABLE 0xd8
46#define CTL_RESET_SD 0xe0
47#define CTL_VERSION 0xe2
48#define CTL_SDIO_REGS 0x100
49#define CTL_CLK_AND_WAIT_CTL 0x138
50#define CTL_RESET_SDIO 0x1e0
51
52/* Definitions for values the CTRL_STATUS register can take. */
53#define TMIO_STAT_CMDRESPEND BIT(0)
54#define TMIO_STAT_DATAEND BIT(2)
55#define TMIO_STAT_CARD_REMOVE BIT(3)
56#define TMIO_STAT_CARD_INSERT BIT(4)
57#define TMIO_STAT_SIGSTATE BIT(5)
58#define TMIO_STAT_WRPROTECT BIT(7)
59#define TMIO_STAT_CARD_REMOVE_A BIT(8)
60#define TMIO_STAT_CARD_INSERT_A BIT(9)
61#define TMIO_STAT_SIGSTATE_A BIT(10)
62
63/* These belong technically to CTRL_STATUS2, but the driver merges them */
64#define TMIO_STAT_CMD_IDX_ERR BIT(16)
65#define TMIO_STAT_CRCFAIL BIT(17)
66#define TMIO_STAT_STOPBIT_ERR BIT(18)
67#define TMIO_STAT_DATATIMEOUT BIT(19)
68#define TMIO_STAT_RXOVERFLOW BIT(20)
69#define TMIO_STAT_TXUNDERRUN BIT(21)
70#define TMIO_STAT_CMDTIMEOUT BIT(22)
71#define TMIO_STAT_DAT0 BIT(23) /* only known on R-Car so far */
72#define TMIO_STAT_RXRDY BIT(24)
73#define TMIO_STAT_TXRQ BIT(25)
74#define TMIO_STAT_ILL_FUNC BIT(29) /* only when !TMIO_MMC_HAS_IDLE_WAIT */
75#define TMIO_STAT_SCLKDIVEN BIT(29) /* only when TMIO_MMC_HAS_IDLE_WAIT */
76#define TMIO_STAT_CMD_BUSY BIT(30)
77#define TMIO_STAT_ILL_ACCESS BIT(31)
78
79#define CLK_CTL_DIV_MASK 0xff
80#define CLK_CTL_SCLKEN BIT(8)
81
82#define TMIO_BBS 512 /* Boot block size */
83
27/* Definitions for values the CTRL_SDIO_STATUS register can take. */ 84/* Definitions for values the CTRL_SDIO_STATUS register can take. */
28#define TMIO_SDIO_STAT_IOIRQ 0x0001 85#define TMIO_SDIO_STAT_IOIRQ 0x0001
29#define TMIO_SDIO_STAT_EXPUB52 0x4000 86#define TMIO_SDIO_STAT_EXPUB52 0x4000
@@ -95,10 +152,14 @@ struct tmio_mmc_host {
95 bool sdio_irq_enabled; 152 bool sdio_irq_enabled;
96 153
97 int (*write16_hook)(struct tmio_mmc_host *host, int addr); 154 int (*write16_hook)(struct tmio_mmc_host *host, int addr);
98 int (*clk_enable)(struct platform_device *pdev, unsigned int *f); 155 int (*clk_enable)(struct tmio_mmc_host *host);
99 void (*clk_disable)(struct platform_device *pdev); 156 unsigned int (*clk_update)(struct tmio_mmc_host *host,
157 unsigned int new_clock);
158 void (*clk_disable)(struct tmio_mmc_host *host);
100 int (*multi_io_quirk)(struct mmc_card *card, 159 int (*multi_io_quirk)(struct mmc_card *card,
101 unsigned int direction, int blk_size); 160 unsigned int direction, int blk_size);
161 int (*start_signal_voltage_switch)(struct mmc_host *mmc,
162 struct mmc_ios *ios);
102}; 163};
103 164
104struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev); 165struct tmio_mmc_host *tmio_mmc_host_alloc(struct platform_device *pdev);
@@ -111,9 +172,6 @@ void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
111void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i); 172void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
112void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i); 173void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
113irqreturn_t tmio_mmc_irq(int irq, void *devid); 174irqreturn_t tmio_mmc_irq(int irq, void *devid);
114irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
115irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
116irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
117 175
118static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg, 176static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
119 unsigned long *flags) 177 unsigned long *flags)
@@ -177,7 +235,7 @@ static inline void sd_ctrl_read16_rep(struct tmio_mmc_host *host, int addr,
177 readsw(host->ctl + (addr << host->bus_shift), buf, count); 235 readsw(host->ctl + (addr << host->bus_shift), buf, count);
178} 236}
179 237
180static inline u32 sd_ctrl_read32(struct tmio_mmc_host *host, int addr) 238static inline u32 sd_ctrl_read16_and_16_as_32(struct tmio_mmc_host *host, int addr)
181{ 239{
182 return readw(host->ctl + (addr << host->bus_shift)) | 240 return readw(host->ctl + (addr << host->bus_shift)) |
183 readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16; 241 readw(host->ctl + ((addr + 2) << host->bus_shift)) << 16;
@@ -199,11 +257,10 @@ static inline void sd_ctrl_write16_rep(struct tmio_mmc_host *host, int addr,
199 writesw(host->ctl + (addr << host->bus_shift), buf, count); 257 writesw(host->ctl + (addr << host->bus_shift), buf, count);
200} 258}
201 259
202static inline void sd_ctrl_write32(struct tmio_mmc_host *host, int addr, u32 val) 260static inline void sd_ctrl_write32_as_16_and_16(struct tmio_mmc_host *host, int addr, u32 val)
203{ 261{
204 writew(val, host->ctl + (addr << host->bus_shift)); 262 writew(val, host->ctl + (addr << host->bus_shift));
205 writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift)); 263 writew(val >> 16, host->ctl + ((addr + 2) << host->bus_shift));
206} 264}
207 265
208
209#endif 266#endif
diff --git a/drivers/mmc/host/tmio_mmc_dma.c b/drivers/mmc/host/tmio_mmc_dma.c
index 7fb0c034dcb6..fa8a936a3d9b 100644
--- a/drivers/mmc/host/tmio_mmc_dma.c
+++ b/drivers/mmc/host/tmio_mmc_dma.c
@@ -15,7 +15,6 @@
15#include <linux/dmaengine.h> 15#include <linux/dmaengine.h>
16#include <linux/mfd/tmio.h> 16#include <linux/mfd/tmio.h>
17#include <linux/mmc/host.h> 17#include <linux/mmc/host.h>
18#include <linux/mmc/tmio.h>
19#include <linux/pagemap.h> 18#include <linux/pagemap.h>
20#include <linux/scatterlist.h> 19#include <linux/scatterlist.h>
21 20
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index 0521b4662748..f44e2ab7aea2 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -39,7 +39,6 @@
39#include <linux/mmc/host.h> 39#include <linux/mmc/host.h>
40#include <linux/mmc/mmc.h> 40#include <linux/mmc/mmc.h>
41#include <linux/mmc/slot-gpio.h> 41#include <linux/mmc/slot-gpio.h>
42#include <linux/mmc/tmio.h>
43#include <linux/module.h> 42#include <linux/module.h>
44#include <linux/pagemap.h> 43#include <linux/pagemap.h>
45#include <linux/platform_device.h> 44#include <linux/platform_device.h>
@@ -56,18 +55,18 @@
56void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i) 55void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
57{ 56{
58 host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ); 57 host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ);
59 sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask); 58 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
60} 59}
61 60
62void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i) 61void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
63{ 62{
64 host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ); 63 host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ);
65 sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask); 64 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
66} 65}
67 66
68static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i) 67static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i)
69{ 68{
70 sd_ctrl_write32(host, CTL_STATUS, ~i); 69 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, ~i);
71} 70}
72 71
73static void tmio_mmc_init_sg(struct tmio_mmc_host *host, struct mmc_data *data) 72static void tmio_mmc_init_sg(struct tmio_mmc_host *host, struct mmc_data *data)
@@ -154,31 +153,16 @@ static void tmio_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
154 } 153 }
155} 154}
156 155
157static void tmio_mmc_set_clock(struct tmio_mmc_host *host, 156static void tmio_mmc_clk_start(struct tmio_mmc_host *host)
158 unsigned int new_clock)
159{ 157{
160 u32 clk = 0, clock; 158 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
161 159 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
162 if (new_clock) { 160 msleep(host->pdata->flags & TMIO_MMC_MIN_RCAR2 ? 1 : 10);
163 for (clock = host->mmc->f_min, clk = 0x80000080;
164 new_clock >= (clock << 1);
165 clk >>= 1)
166 clock <<= 1;
167
168 /* 1/1 clock is option */
169 if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) &&
170 ((clk >> 22) & 0x1))
171 clk |= 0xff;
172 }
173
174 if (host->set_clk_div)
175 host->set_clk_div(host->pdev, (clk >> 22) & 1);
176 161
177 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & 162 if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) {
178 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); 163 sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100);
179 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK);
180 if (!(host->pdata->flags & TMIO_MMC_FAST_CLK_CHG))
181 msleep(10); 164 msleep(10);
165 }
182} 166}
183 167
184static void tmio_mmc_clk_stop(struct tmio_mmc_host *host) 168static void tmio_mmc_clk_stop(struct tmio_mmc_host *host)
@@ -190,19 +174,41 @@ static void tmio_mmc_clk_stop(struct tmio_mmc_host *host)
190 174
191 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN & 175 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
192 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL)); 176 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
193 msleep(host->pdata->flags & TMIO_MMC_FAST_CLK_CHG ? 5 : 10); 177 msleep(host->pdata->flags & TMIO_MMC_MIN_RCAR2 ? 5 : 10);
194} 178}
195 179
196static void tmio_mmc_clk_start(struct tmio_mmc_host *host) 180static void tmio_mmc_set_clock(struct tmio_mmc_host *host,
181 unsigned int new_clock)
197{ 182{
198 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN | 183 u32 clk = 0, clock;
199 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
200 msleep(host->pdata->flags & TMIO_MMC_FAST_CLK_CHG ? 1 : 10);
201 184
202 if (host->pdata->flags & TMIO_MMC_HAVE_HIGH_REG) { 185 if (new_clock == 0) {
203 sd_ctrl_write16(host, CTL_CLK_AND_WAIT_CTL, 0x0100); 186 tmio_mmc_clk_stop(host);
204 msleep(10); 187 return;
205 } 188 }
189
190 if (host->clk_update)
191 clock = host->clk_update(host, new_clock) / 512;
192 else
193 clock = host->mmc->f_min;
194
195 for (clk = 0x80000080; new_clock >= (clock << 1); clk >>= 1)
196 clock <<= 1;
197
198 /* 1/1 clock is option */
199 if ((host->pdata->flags & TMIO_MMC_CLK_ACTUAL) && ((clk >> 22) & 0x1))
200 clk |= 0xff;
201
202 if (host->set_clk_div)
203 host->set_clk_div(host->pdev, (clk >> 22) & 1);
204
205 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, ~CLK_CTL_SCLKEN &
206 sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL));
207 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk & CLK_CTL_DIV_MASK);
208 if (!(host->pdata->flags & TMIO_MMC_MIN_RCAR2))
209 msleep(10);
210
211 tmio_mmc_clk_start(host);
206} 212}
207 213
208static void tmio_mmc_reset(struct tmio_mmc_host *host) 214static void tmio_mmc_reset(struct tmio_mmc_host *host)
@@ -264,9 +270,6 @@ static void tmio_mmc_reset_work(struct work_struct *work)
264 270
265 tmio_mmc_abort_dma(host); 271 tmio_mmc_abort_dma(host);
266 mmc_request_done(host->mmc, mrq); 272 mmc_request_done(host->mmc, mrq);
267
268 pm_runtime_mark_last_busy(mmc_dev(host->mmc));
269 pm_runtime_put_autosuspend(mmc_dev(host->mmc));
270} 273}
271 274
272/* called with host->lock held, interrupts disabled */ 275/* called with host->lock held, interrupts disabled */
@@ -296,9 +299,6 @@ static void tmio_mmc_finish_request(struct tmio_mmc_host *host)
296 tmio_mmc_abort_dma(host); 299 tmio_mmc_abort_dma(host);
297 300
298 mmc_request_done(host->mmc, mrq); 301 mmc_request_done(host->mmc, mrq);
299
300 pm_runtime_mark_last_busy(mmc_dev(host->mmc));
301 pm_runtime_put_autosuspend(mmc_dev(host->mmc));
302} 302}
303 303
304static void tmio_mmc_done_work(struct work_struct *work) 304static void tmio_mmc_done_work(struct work_struct *work)
@@ -375,7 +375,7 @@ static int tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command
375 tmio_mmc_enable_mmc_irqs(host, irq_mask); 375 tmio_mmc_enable_mmc_irqs(host, irq_mask);
376 376
377 /* Fire off the command */ 377 /* Fire off the command */
378 sd_ctrl_write32(host, CTL_ARG_REG, cmd->arg); 378 sd_ctrl_write32_as_16_and_16(host, CTL_ARG_REG, cmd->arg);
379 sd_ctrl_write16(host, CTL_SD_CMD, c); 379 sd_ctrl_write16(host, CTL_SD_CMD, c);
380 380
381 return 0; 381 return 0;
@@ -530,7 +530,7 @@ static void tmio_mmc_data_irq(struct tmio_mmc_host *host)
530 goto out; 530 goto out;
531 531
532 if (host->chan_tx && (data->flags & MMC_DATA_WRITE) && !host->force_pio) { 532 if (host->chan_tx && (data->flags & MMC_DATA_WRITE) && !host->force_pio) {
533 u32 status = sd_ctrl_read32(host, CTL_STATUS); 533 u32 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS);
534 bool done = false; 534 bool done = false;
535 535
536 /* 536 /*
@@ -542,7 +542,7 @@ static void tmio_mmc_data_irq(struct tmio_mmc_host *host)
542 * waiting for one more interrupt fixes the problem. 542 * waiting for one more interrupt fixes the problem.
543 */ 543 */
544 if (host->pdata->flags & TMIO_MMC_HAS_IDLE_WAIT) { 544 if (host->pdata->flags & TMIO_MMC_HAS_IDLE_WAIT) {
545 if (status & TMIO_STAT_ILL_FUNC) 545 if (status & TMIO_STAT_SCLKDIVEN)
546 done = true; 546 done = true;
547 } else { 547 } else {
548 if (!(status & TMIO_STAT_CMD_BUSY)) 548 if (!(status & TMIO_STAT_CMD_BUSY))
@@ -585,7 +585,7 @@ static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host,
585 */ 585 */
586 586
587 for (i = 3, addr = CTL_RESPONSE ; i >= 0 ; i--, addr += 4) 587 for (i = 3, addr = CTL_RESPONSE ; i >= 0 ; i--, addr += 4)
588 cmd->resp[i] = sd_ctrl_read32(host, addr); 588 cmd->resp[i] = sd_ctrl_read16_and_16_as_32(host, addr);
589 589
590 if (cmd->flags & MMC_RSP_136) { 590 if (cmd->flags & MMC_RSP_136) {
591 cmd->resp[0] = (cmd->resp[0] << 8) | (cmd->resp[1] >> 24); 591 cmd->resp[0] = (cmd->resp[0] << 8) | (cmd->resp[1] >> 24);
@@ -625,19 +625,6 @@ out:
625 spin_unlock(&host->lock); 625 spin_unlock(&host->lock);
626} 626}
627 627
628static void tmio_mmc_card_irq_status(struct tmio_mmc_host *host,
629 int *ireg, int *status)
630{
631 *status = sd_ctrl_read32(host, CTL_STATUS);
632 *ireg = *status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask;
633
634 pr_debug_status(*status);
635 pr_debug_status(*ireg);
636
637 /* Clear the status except the interrupt status */
638 sd_ctrl_write32(host, CTL_STATUS, TMIO_MASK_IRQ);
639}
640
641static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host, 628static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host,
642 int ireg, int status) 629 int ireg, int status)
643{ 630{
@@ -657,18 +644,6 @@ static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host,
657 return false; 644 return false;
658} 645}
659 646
660irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid)
661{
662 unsigned int ireg, status;
663 struct tmio_mmc_host *host = devid;
664
665 tmio_mmc_card_irq_status(host, &ireg, &status);
666 __tmio_mmc_card_detect_irq(host, ireg, status);
667
668 return IRQ_HANDLED;
669}
670EXPORT_SYMBOL(tmio_mmc_card_detect_irq);
671
672static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host, 647static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host,
673 int ireg, int status) 648 int ireg, int status)
674{ 649{
@@ -698,19 +673,7 @@ static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host,
698 return false; 673 return false;
699} 674}
700 675
701irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid) 676static void tmio_mmc_sdio_irq(int irq, void *devid)
702{
703 unsigned int ireg, status;
704 struct tmio_mmc_host *host = devid;
705
706 tmio_mmc_card_irq_status(host, &ireg, &status);
707 __tmio_mmc_sdcard_irq(host, ireg, status);
708
709 return IRQ_HANDLED;
710}
711EXPORT_SYMBOL(tmio_mmc_sdcard_irq);
712
713irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid)
714{ 677{
715 struct tmio_mmc_host *host = devid; 678 struct tmio_mmc_host *host = devid;
716 struct mmc_host *mmc = host->mmc; 679 struct mmc_host *mmc = host->mmc;
@@ -719,7 +682,7 @@ irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid)
719 unsigned int sdio_status; 682 unsigned int sdio_status;
720 683
721 if (!(pdata->flags & TMIO_MMC_SDIO_IRQ)) 684 if (!(pdata->flags & TMIO_MMC_SDIO_IRQ))
722 return IRQ_HANDLED; 685 return;
723 686
724 status = sd_ctrl_read16(host, CTL_SDIO_STATUS); 687 status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
725 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdcard_irq_mask; 688 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdcard_irq_mask;
@@ -732,19 +695,22 @@ irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid)
732 695
733 if (mmc->caps & MMC_CAP_SDIO_IRQ && ireg & TMIO_SDIO_STAT_IOIRQ) 696 if (mmc->caps & MMC_CAP_SDIO_IRQ && ireg & TMIO_SDIO_STAT_IOIRQ)
734 mmc_signal_sdio_irq(mmc); 697 mmc_signal_sdio_irq(mmc);
735
736 return IRQ_HANDLED;
737} 698}
738EXPORT_SYMBOL(tmio_mmc_sdio_irq);
739 699
740irqreturn_t tmio_mmc_irq(int irq, void *devid) 700irqreturn_t tmio_mmc_irq(int irq, void *devid)
741{ 701{
742 struct tmio_mmc_host *host = devid; 702 struct tmio_mmc_host *host = devid;
743 unsigned int ireg, status; 703 unsigned int ireg, status;
744 704
745 pr_debug("MMC IRQ begin\n"); 705 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS);
706 ireg = status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask;
707
708 pr_debug_status(status);
709 pr_debug_status(ireg);
710
711 /* Clear the status except the interrupt status */
712 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, TMIO_MASK_IRQ);
746 713
747 tmio_mmc_card_irq_status(host, &ireg, &status);
748 if (__tmio_mmc_card_detect_irq(host, ireg, status)) 714 if (__tmio_mmc_card_detect_irq(host, ireg, status))
749 return IRQ_HANDLED; 715 return IRQ_HANDLED;
750 if (__tmio_mmc_sdcard_irq(host, ireg, status)) 716 if (__tmio_mmc_sdcard_irq(host, ireg, status))
@@ -812,8 +778,6 @@ static void tmio_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
812 778
813 spin_unlock_irqrestore(&host->lock, flags); 779 spin_unlock_irqrestore(&host->lock, flags);
814 780
815 pm_runtime_get_sync(mmc_dev(mmc));
816
817 if (mrq->data) { 781 if (mrq->data) {
818 ret = tmio_mmc_start_data(host, mrq->data); 782 ret = tmio_mmc_start_data(host, mrq->data);
819 if (ret) 783 if (ret)
@@ -832,24 +796,14 @@ fail:
832 host->mrq = NULL; 796 host->mrq = NULL;
833 mrq->cmd->error = ret; 797 mrq->cmd->error = ret;
834 mmc_request_done(mmc, mrq); 798 mmc_request_done(mmc, mrq);
835
836 pm_runtime_mark_last_busy(mmc_dev(mmc));
837 pm_runtime_put_autosuspend(mmc_dev(mmc));
838} 799}
839 800
840static int tmio_mmc_clk_update(struct tmio_mmc_host *host) 801static int tmio_mmc_clk_enable(struct tmio_mmc_host *host)
841{ 802{
842 struct mmc_host *mmc = host->mmc;
843 int ret;
844
845 if (!host->clk_enable) 803 if (!host->clk_enable)
846 return -ENOTSUPP; 804 return -ENOTSUPP;
847 805
848 ret = host->clk_enable(host->pdev, &mmc->f_max); 806 return host->clk_enable(host);
849 if (!ret)
850 mmc->f_min = mmc->f_max / 512;
851
852 return ret;
853} 807}
854 808
855static void tmio_mmc_power_on(struct tmio_mmc_host *host, unsigned short vdd) 809static void tmio_mmc_power_on(struct tmio_mmc_host *host, unsigned short vdd)
@@ -925,8 +879,6 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
925 struct device *dev = &host->pdev->dev; 879 struct device *dev = &host->pdev->dev;
926 unsigned long flags; 880 unsigned long flags;
927 881
928 pm_runtime_get_sync(mmc_dev(mmc));
929
930 mutex_lock(&host->ios_lock); 882 mutex_lock(&host->ios_lock);
931 883
932 spin_lock_irqsave(&host->lock, flags); 884 spin_lock_irqsave(&host->lock, flags);
@@ -959,14 +911,12 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
959 tmio_mmc_clk_stop(host); 911 tmio_mmc_clk_stop(host);
960 break; 912 break;
961 case MMC_POWER_UP: 913 case MMC_POWER_UP:
962 tmio_mmc_set_clock(host, ios->clock);
963 tmio_mmc_power_on(host, ios->vdd); 914 tmio_mmc_power_on(host, ios->vdd);
964 tmio_mmc_clk_start(host); 915 tmio_mmc_set_clock(host, ios->clock);
965 tmio_mmc_set_bus_width(host, ios->bus_width); 916 tmio_mmc_set_bus_width(host, ios->bus_width);
966 break; 917 break;
967 case MMC_POWER_ON: 918 case MMC_POWER_ON:
968 tmio_mmc_set_clock(host, ios->clock); 919 tmio_mmc_set_clock(host, ios->clock);
969 tmio_mmc_clk_start(host);
970 tmio_mmc_set_bus_width(host, ios->bus_width); 920 tmio_mmc_set_bus_width(host, ios->bus_width);
971 break; 921 break;
972 } 922 }
@@ -983,9 +933,6 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
983 host->clk_cache = ios->clock; 933 host->clk_cache = ios->clock;
984 934
985 mutex_unlock(&host->ios_lock); 935 mutex_unlock(&host->ios_lock);
986
987 pm_runtime_mark_last_busy(mmc_dev(mmc));
988 pm_runtime_put_autosuspend(mmc_dev(mmc));
989} 936}
990 937
991static int tmio_mmc_get_ro(struct mmc_host *mmc) 938static int tmio_mmc_get_ro(struct mmc_host *mmc)
@@ -996,11 +943,8 @@ static int tmio_mmc_get_ro(struct mmc_host *mmc)
996 if (ret >= 0) 943 if (ret >= 0)
997 return ret; 944 return ret;
998 945
999 pm_runtime_get_sync(mmc_dev(mmc));
1000 ret = !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) || 946 ret = !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) ||
1001 (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT)); 947 (sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT));
1002 pm_runtime_mark_last_busy(mmc_dev(mmc));
1003 pm_runtime_put_autosuspend(mmc_dev(mmc));
1004 948
1005 return ret; 949 return ret;
1006} 950}
@@ -1016,12 +960,20 @@ static int tmio_multi_io_quirk(struct mmc_card *card,
1016 return blk_size; 960 return blk_size;
1017} 961}
1018 962
1019static const struct mmc_host_ops tmio_mmc_ops = { 963static int tmio_mmc_card_busy(struct mmc_host *mmc)
964{
965 struct tmio_mmc_host *host = mmc_priv(mmc);
966
967 return !(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & TMIO_STAT_DAT0);
968}
969
970static struct mmc_host_ops tmio_mmc_ops = {
1020 .request = tmio_mmc_request, 971 .request = tmio_mmc_request,
1021 .set_ios = tmio_mmc_set_ios, 972 .set_ios = tmio_mmc_set_ios,
1022 .get_ro = tmio_mmc_get_ro, 973 .get_ro = tmio_mmc_get_ro,
1023 .get_cd = mmc_gpio_get_cd, 974 .get_cd = mmc_gpio_get_cd,
1024 .enable_sdio_irq = tmio_mmc_enable_sdio_irq, 975 .enable_sdio_irq = tmio_mmc_enable_sdio_irq,
976 .card_busy = tmio_mmc_card_busy,
1025 .multi_io_quirk = tmio_multi_io_quirk, 977 .multi_io_quirk = tmio_multi_io_quirk,
1026}; 978};
1027 979
@@ -1120,7 +1072,9 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
1120 goto host_free; 1072 goto host_free;
1121 } 1073 }
1122 1074
1075 tmio_mmc_ops.start_signal_voltage_switch = _host->start_signal_voltage_switch;
1123 mmc->ops = &tmio_mmc_ops; 1076 mmc->ops = &tmio_mmc_ops;
1077
1124 mmc->caps |= MMC_CAP_4_BIT_DATA | pdata->capabilities; 1078 mmc->caps |= MMC_CAP_4_BIT_DATA | pdata->capabilities;
1125 mmc->caps2 |= pdata->capabilities2; 1079 mmc->caps2 |= pdata->capabilities2;
1126 mmc->max_segs = 32; 1080 mmc->max_segs = 32;
@@ -1135,7 +1089,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
1135 mmc->caps & MMC_CAP_NONREMOVABLE || 1089 mmc->caps & MMC_CAP_NONREMOVABLE ||
1136 mmc->slot.cd_irq >= 0); 1090 mmc->slot.cd_irq >= 0);
1137 1091
1138 if (tmio_mmc_clk_update(_host) < 0) { 1092 if (tmio_mmc_clk_enable(_host) < 0) {
1139 mmc->f_max = pdata->hclk; 1093 mmc->f_max = pdata->hclk;
1140 mmc->f_min = mmc->f_max / 512; 1094 mmc->f_min = mmc->f_max / 512;
1141 } 1095 }
@@ -1159,7 +1113,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host *_host,
1159 tmio_mmc_clk_stop(_host); 1113 tmio_mmc_clk_stop(_host);
1160 tmio_mmc_reset(_host); 1114 tmio_mmc_reset(_host);
1161 1115
1162 _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK); 1116 _host->sdcard_irq_mask = sd_ctrl_read16_and_16_as_32(_host, CTL_IRQ_MASK);
1163 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL); 1117 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL);
1164 1118
1165 /* Unmask the IRQs we want to know about */ 1119 /* Unmask the IRQs we want to know about */
@@ -1251,7 +1205,7 @@ int tmio_mmc_host_runtime_suspend(struct device *dev)
1251 tmio_mmc_clk_stop(host); 1205 tmio_mmc_clk_stop(host);
1252 1206
1253 if (host->clk_disable) 1207 if (host->clk_disable)
1254 host->clk_disable(host->pdev); 1208 host->clk_disable(host);
1255 1209
1256 return 0; 1210 return 0;
1257} 1211}
@@ -1263,12 +1217,10 @@ int tmio_mmc_host_runtime_resume(struct device *dev)
1263 struct tmio_mmc_host *host = mmc_priv(mmc); 1217 struct tmio_mmc_host *host = mmc_priv(mmc);
1264 1218
1265 tmio_mmc_reset(host); 1219 tmio_mmc_reset(host);
1266 tmio_mmc_clk_update(host); 1220 tmio_mmc_clk_enable(host);
1267 1221
1268 if (host->clk_cache) { 1222 if (host->clk_cache)
1269 tmio_mmc_set_clock(host, host->clk_cache); 1223 tmio_mmc_set_clock(host, host->clk_cache);
1270 tmio_mmc_clk_start(host);
1271 }
1272 1224
1273 tmio_mmc_enable_dma(host, true); 1225 tmio_mmc_enable_dma(host, true);
1274 1226
diff --git a/drivers/mmc/host/usdhi6rol0.c b/drivers/mmc/host/usdhi6rol0.c
index 807c06e203c3..1bd5f1a18d4e 100644
--- a/drivers/mmc/host/usdhi6rol0.c
+++ b/drivers/mmc/host/usdhi6rol0.c
@@ -22,6 +22,7 @@
22#include <linux/mmc/sdio.h> 22#include <linux/mmc/sdio.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/pagemap.h> 24#include <linux/pagemap.h>
25#include <linux/pinctrl/consumer.h>
25#include <linux/platform_device.h> 26#include <linux/platform_device.h>
26#include <linux/scatterlist.h> 27#include <linux/scatterlist.h>
27#include <linux/string.h> 28#include <linux/string.h>
@@ -198,6 +199,11 @@ struct usdhi6_host {
198 struct dma_chan *chan_rx; 199 struct dma_chan *chan_rx;
199 struct dma_chan *chan_tx; 200 struct dma_chan *chan_tx;
200 bool dma_active; 201 bool dma_active;
202
203 /* Pin control */
204 struct pinctrl *pinctrl;
205 struct pinctrl_state *pins_default;
206 struct pinctrl_state *pins_uhs;
201}; 207};
202 208
203/* I/O primitives */ 209/* I/O primitives */
@@ -1147,12 +1153,45 @@ static void usdhi6_enable_sdio_irq(struct mmc_host *mmc, int enable)
1147 } 1153 }
1148} 1154}
1149 1155
1156static int usdhi6_set_pinstates(struct usdhi6_host *host, int voltage)
1157{
1158 if (IS_ERR(host->pins_uhs))
1159 return 0;
1160
1161 switch (voltage) {
1162 case MMC_SIGNAL_VOLTAGE_180:
1163 case MMC_SIGNAL_VOLTAGE_120:
1164 return pinctrl_select_state(host->pinctrl,
1165 host->pins_uhs);
1166
1167 default:
1168 return pinctrl_select_state(host->pinctrl,
1169 host->pins_default);
1170 }
1171}
1172
1173static int usdhi6_sig_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
1174{
1175 int ret;
1176
1177 ret = mmc_regulator_set_vqmmc(mmc, ios);
1178 if (ret < 0)
1179 return ret;
1180
1181 ret = usdhi6_set_pinstates(mmc_priv(mmc), ios->signal_voltage);
1182 if (ret)
1183 dev_warn_once(mmc_dev(mmc),
1184 "Failed to set pinstate err=%d\n", ret);
1185 return ret;
1186}
1187
1150static struct mmc_host_ops usdhi6_ops = { 1188static struct mmc_host_ops usdhi6_ops = {
1151 .request = usdhi6_request, 1189 .request = usdhi6_request,
1152 .set_ios = usdhi6_set_ios, 1190 .set_ios = usdhi6_set_ios,
1153 .get_cd = usdhi6_get_cd, 1191 .get_cd = usdhi6_get_cd,
1154 .get_ro = usdhi6_get_ro, 1192 .get_ro = usdhi6_get_ro,
1155 .enable_sdio_irq = usdhi6_enable_sdio_irq, 1193 .enable_sdio_irq = usdhi6_enable_sdio_irq,
1194 .start_signal_voltage_switch = usdhi6_sig_volt_switch,
1156}; 1195};
1157 1196
1158/* State machine handlers */ 1197/* State machine handlers */
@@ -1730,6 +1769,25 @@ static int usdhi6_probe(struct platform_device *pdev)
1730 host->wait = USDHI6_WAIT_FOR_REQUEST; 1769 host->wait = USDHI6_WAIT_FOR_REQUEST;
1731 host->timeout = msecs_to_jiffies(4000); 1770 host->timeout = msecs_to_jiffies(4000);
1732 1771
1772 host->pinctrl = devm_pinctrl_get(&pdev->dev);
1773 if (IS_ERR(host->pinctrl)) {
1774 ret = PTR_ERR(host->pinctrl);
1775 goto e_free_mmc;
1776 }
1777
1778 host->pins_uhs = pinctrl_lookup_state(host->pinctrl, "state_uhs");
1779 if (!IS_ERR(host->pins_uhs)) {
1780 host->pins_default = pinctrl_lookup_state(host->pinctrl,
1781 PINCTRL_STATE_DEFAULT);
1782
1783 if (IS_ERR(host->pins_default)) {
1784 dev_err(dev,
1785 "UHS pinctrl requires a default pin state.\n");
1786 ret = PTR_ERR(host->pins_default);
1787 goto e_free_mmc;
1788 }
1789 }
1790
1733 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1791 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1734 host->base = devm_ioremap_resource(dev, res); 1792 host->base = devm_ioremap_resource(dev, res);
1735 if (IS_ERR(host->base)) { 1793 if (IS_ERR(host->base)) {
@@ -1785,7 +1843,7 @@ static int usdhi6_probe(struct platform_device *pdev)
1785 1843
1786 mmc->ops = &usdhi6_ops; 1844 mmc->ops = &usdhi6_ops;
1787 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED | 1845 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED |
1788 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_DDR50 | MMC_CAP_SDIO_IRQ; 1846 MMC_CAP_SDIO_IRQ;
1789 /* Set .max_segs to some random number. Feel free to adjust. */ 1847 /* Set .max_segs to some random number. Feel free to adjust. */
1790 mmc->max_segs = 32; 1848 mmc->max_segs = 32;
1791 mmc->max_blk_size = 512; 1849 mmc->max_blk_size = 512;
diff --git a/include/linux/mfd/tmio.h b/include/linux/mfd/tmio.h
index 05d58ee5e6a7..7a26286db895 100644
--- a/include/linux/mfd/tmio.h
+++ b/include/linux/mfd/tmio.h
@@ -66,8 +66,8 @@
66 */ 66 */
67#define TMIO_MMC_SDIO_IRQ (1 << 2) 67#define TMIO_MMC_SDIO_IRQ (1 << 2)
68 68
69/* Some controllers don't need to wait 10ms for clock changes */ 69/* Some features are only available or tested on RCar Gen2 or later */
70#define TMIO_MMC_FAST_CLK_CHG (1 << 3) 70#define TMIO_MMC_MIN_RCAR2 (1 << 3)
71 71
72/* 72/*
73 * Some controllers require waiting for the SD bus to become 73 * Some controllers require waiting for the SD bus to become
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index 7b41c6db1bb6..f7ed271a1d54 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -36,7 +36,6 @@ enum {
36 EVENT_XFER_COMPLETE, 36 EVENT_XFER_COMPLETE,
37 EVENT_DATA_COMPLETE, 37 EVENT_DATA_COMPLETE,
38 EVENT_DATA_ERROR, 38 EVENT_DATA_ERROR,
39 EVENT_XFER_ERROR
40}; 39};
41 40
42struct mmc_data; 41struct mmc_data;
@@ -55,6 +54,7 @@ struct dw_mci_dma_slave {
55/** 54/**
56 * struct dw_mci - MMC controller state shared between all slots 55 * struct dw_mci - MMC controller state shared between all slots
57 * @lock: Spinlock protecting the queue and associated data. 56 * @lock: Spinlock protecting the queue and associated data.
57 * @irq_lock: Spinlock protecting the INTMASK setting.
58 * @regs: Pointer to MMIO registers. 58 * @regs: Pointer to MMIO registers.
59 * @fifo_reg: Pointer to MMIO registers for data FIFO 59 * @fifo_reg: Pointer to MMIO registers for data FIFO
60 * @sg: Scatterlist entry currently being processed by PIO code, if any. 60 * @sg: Scatterlist entry currently being processed by PIO code, if any.
@@ -65,6 +65,9 @@ struct dw_mci_dma_slave {
65 * @cmd: The command currently being sent to the card, or NULL. 65 * @cmd: The command currently being sent to the card, or NULL.
66 * @data: The data currently being transferred, or NULL if no data 66 * @data: The data currently being transferred, or NULL if no data
67 * transfer is in progress. 67 * transfer is in progress.
68 * @stop_abort: The command currently prepared for stoping transfer.
69 * @prev_blksz: The former transfer blksz record.
70 * @timing: Record of current ios timing.
68 * @use_dma: Whether DMA channel is initialized or not. 71 * @use_dma: Whether DMA channel is initialized or not.
69 * @using_dma: Whether DMA is in use for the current transfer. 72 * @using_dma: Whether DMA is in use for the current transfer.
70 * @dma_64bit_address: Whether DMA supports 64-bit address mode or not. 73 * @dma_64bit_address: Whether DMA supports 64-bit address mode or not.
@@ -72,7 +75,10 @@ struct dw_mci_dma_slave {
72 * @sg_cpu: Virtual address of DMA buffer. 75 * @sg_cpu: Virtual address of DMA buffer.
73 * @dma_ops: Pointer to platform-specific DMA callbacks. 76 * @dma_ops: Pointer to platform-specific DMA callbacks.
74 * @cmd_status: Snapshot of SR taken upon completion of the current 77 * @cmd_status: Snapshot of SR taken upon completion of the current
78 * @ring_size: Buffer size for idma descriptors.
75 * command. Only valid when EVENT_CMD_COMPLETE is pending. 79 * command. Only valid when EVENT_CMD_COMPLETE is pending.
80 * @dms: structure of slave-dma private data.
81 * @phy_regs: physical address of controller's register map
76 * @data_status: Snapshot of SR taken upon completion of the current 82 * @data_status: Snapshot of SR taken upon completion of the current
77 * data transfer. Only valid when EVENT_DATA_COMPLETE or 83 * data transfer. Only valid when EVENT_DATA_COMPLETE or
78 * EVENT_DATA_ERROR is pending. 84 * EVENT_DATA_ERROR is pending.
@@ -80,7 +86,6 @@ struct dw_mci_dma_slave {
80 * to be sent. 86 * to be sent.
81 * @dir_status: Direction of current transfer. 87 * @dir_status: Direction of current transfer.
82 * @tasklet: Tasklet running the request state machine. 88 * @tasklet: Tasklet running the request state machine.
83 * @card_tasklet: Tasklet handling card detect.
84 * @pending_events: Bitmask of events flagged by the interrupt handler 89 * @pending_events: Bitmask of events flagged by the interrupt handler
85 * to be processed by the tasklet. 90 * to be processed by the tasklet.
86 * @completed_events: Bitmask of events which the state machine has 91 * @completed_events: Bitmask of events which the state machine has
@@ -91,6 +96,7 @@ struct dw_mci_dma_slave {
91 * rate and timeout calculations. 96 * rate and timeout calculations.
92 * @current_speed: Configured rate of the controller. 97 * @current_speed: Configured rate of the controller.
93 * @num_slots: Number of slots available. 98 * @num_slots: Number of slots available.
99 * @fifoth_val: The value of FIFOTH register.
94 * @verid: Denote Version ID. 100 * @verid: Denote Version ID.
95 * @dev: Device associated with the MMC controller. 101 * @dev: Device associated with the MMC controller.
96 * @pdata: Platform data associated with the MMC controller. 102 * @pdata: Platform data associated with the MMC controller.
@@ -107,9 +113,11 @@ struct dw_mci_dma_slave {
107 * @push_data: Pointer to FIFO push function. 113 * @push_data: Pointer to FIFO push function.
108 * @pull_data: Pointer to FIFO pull function. 114 * @pull_data: Pointer to FIFO pull function.
109 * @quirks: Set of quirks that apply to specific versions of the IP. 115 * @quirks: Set of quirks that apply to specific versions of the IP.
116 * @vqmmc_enabled: Status of vqmmc, should be true or false.
110 * @irq_flags: The flags to be passed to request_irq. 117 * @irq_flags: The flags to be passed to request_irq.
111 * @irq: The irq value to be passed to request_irq. 118 * @irq: The irq value to be passed to request_irq.
112 * @sdio_id0: Number of slot0 in the SDIO interrupt registers. 119 * @sdio_id0: Number of slot0 in the SDIO interrupt registers.
120 * @cmd11_timer: Timer for SD3.0 voltage switch over scheme.
113 * @dto_timer: Timer for broken data transfer over scheme. 121 * @dto_timer: Timer for broken data transfer over scheme.
114 * 122 *
115 * Locking 123 * Locking
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 8dd4d290ab0d..85800b48241f 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -93,28 +93,39 @@ struct mmc_host_ops {
93 void (*pre_req)(struct mmc_host *host, struct mmc_request *req, 93 void (*pre_req)(struct mmc_host *host, struct mmc_request *req,
94 bool is_first_req); 94 bool is_first_req);
95 void (*request)(struct mmc_host *host, struct mmc_request *req); 95 void (*request)(struct mmc_host *host, struct mmc_request *req);
96
97 /*
98 * Avoid calling the next three functions too often or in a "fast
99 * path", since underlaying controller might implement them in an
100 * expensive and/or slow way. Also note that these functions might
101 * sleep, so don't call them in the atomic contexts!
102 */
103
104 /*
105 * Notes to the set_ios callback:
106 * ios->clock might be 0. For some controllers, setting 0Hz
107 * as any other frequency works. However, some controllers
108 * explicitly need to disable the clock. Otherwise e.g. voltage
109 * switching might fail because the SDCLK is not really quiet.
110 */
111 void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
112
96 /* 113 /*
97 * Avoid calling these three functions too often or in a "fast path",
98 * since underlaying controller might implement them in an expensive
99 * and/or slow way.
100 *
101 * Also note that these functions might sleep, so don't call them
102 * in the atomic contexts!
103 *
104 * Return values for the get_ro callback should be: 114 * Return values for the get_ro callback should be:
105 * 0 for a read/write card 115 * 0 for a read/write card
106 * 1 for a read-only card 116 * 1 for a read-only card
107 * -ENOSYS when not supported (equal to NULL callback) 117 * -ENOSYS when not supported (equal to NULL callback)
108 * or a negative errno value when something bad happened 118 * or a negative errno value when something bad happened
109 * 119 */
120 int (*get_ro)(struct mmc_host *host);
121
122 /*
110 * Return values for the get_cd callback should be: 123 * Return values for the get_cd callback should be:
111 * 0 for a absent card 124 * 0 for a absent card
112 * 1 for a present card 125 * 1 for a present card
113 * -ENOSYS when not supported (equal to NULL callback) 126 * -ENOSYS when not supported (equal to NULL callback)
114 * or a negative errno value when something bad happened 127 * or a negative errno value when something bad happened
115 */ 128 */
116 void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
117 int (*get_ro)(struct mmc_host *host);
118 int (*get_cd)(struct mmc_host *host); 129 int (*get_cd)(struct mmc_host *host);
119 130
120 void (*enable_sdio_irq)(struct mmc_host *host, int enable); 131 void (*enable_sdio_irq)(struct mmc_host *host, int enable);
diff --git a/include/linux/mmc/sh_mobile_sdhi.h b/include/linux/mmc/sh_mobile_sdhi.h
deleted file mode 100644
index 95d6f0314a7d..000000000000
--- a/include/linux/mmc/sh_mobile_sdhi.h
+++ /dev/null
@@ -1,10 +0,0 @@
1#ifndef LINUX_MMC_SH_MOBILE_SDHI_H
2#define LINUX_MMC_SH_MOBILE_SDHI_H
3
4#include <linux/types.h>
5
6#define SH_MOBILE_SDHI_IRQ_CARD_DETECT "card_detect"
7#define SH_MOBILE_SDHI_IRQ_SDCARD "sdcard"
8#define SH_MOBILE_SDHI_IRQ_SDIO "sdio"
9
10#endif /* LINUX_MMC_SH_MOBILE_SDHI_H */
diff --git a/include/linux/mmc/tmio.h b/include/linux/mmc/tmio.h
deleted file mode 100644
index 5f5cd80e9765..000000000000
--- a/include/linux/mmc/tmio.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * include/linux/mmc/tmio.h
3 *
4 * Copyright (C) 2016 Sang Engineering, Wolfram Sang
5 * Copyright (C) 2015-16 Renesas Electronics Corporation
6 * Copyright (C) 2007 Ian Molton
7 * Copyright (C) 2004 Ian Molton
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * Driver for the MMC / SD / SDIO cell found in:
14 *
15 * TC6393XB TC6391XB TC6387XB T7L66XB ASIC3
16 */
17#ifndef LINUX_MMC_TMIO_H
18#define LINUX_MMC_TMIO_H
19
20#define CTL_SD_CMD 0x00
21#define CTL_ARG_REG 0x04
22#define CTL_STOP_INTERNAL_ACTION 0x08
23#define CTL_XFER_BLK_COUNT 0xa
24#define CTL_RESPONSE 0x0c
25#define CTL_STATUS 0x1c
26#define CTL_STATUS2 0x1e
27#define CTL_IRQ_MASK 0x20
28#define CTL_SD_CARD_CLK_CTL 0x24
29#define CTL_SD_XFER_LEN 0x26
30#define CTL_SD_MEM_CARD_OPT 0x28
31#define CTL_SD_ERROR_DETAIL_STATUS 0x2c
32#define CTL_SD_DATA_PORT 0x30
33#define CTL_TRANSACTION_CTL 0x34
34#define CTL_SDIO_STATUS 0x36
35#define CTL_SDIO_IRQ_MASK 0x38
36#define CTL_DMA_ENABLE 0xd8
37#define CTL_RESET_SD 0xe0
38#define CTL_VERSION 0xe2
39#define CTL_SDIO_REGS 0x100
40#define CTL_CLK_AND_WAIT_CTL 0x138
41#define CTL_RESET_SDIO 0x1e0
42
43/* Definitions for values the CTRL_STATUS register can take. */
44#define TMIO_STAT_CMDRESPEND 0x00000001
45#define TMIO_STAT_DATAEND 0x00000004
46#define TMIO_STAT_CARD_REMOVE 0x00000008
47#define TMIO_STAT_CARD_INSERT 0x00000010
48#define TMIO_STAT_SIGSTATE 0x00000020
49#define TMIO_STAT_WRPROTECT 0x00000080
50#define TMIO_STAT_CARD_REMOVE_A 0x00000100
51#define TMIO_STAT_CARD_INSERT_A 0x00000200
52#define TMIO_STAT_SIGSTATE_A 0x00000400
53#define TMIO_STAT_CMD_IDX_ERR 0x00010000
54#define TMIO_STAT_CRCFAIL 0x00020000
55#define TMIO_STAT_STOPBIT_ERR 0x00040000
56#define TMIO_STAT_DATATIMEOUT 0x00080000
57#define TMIO_STAT_RXOVERFLOW 0x00100000
58#define TMIO_STAT_TXUNDERRUN 0x00200000
59#define TMIO_STAT_CMDTIMEOUT 0x00400000
60#define TMIO_STAT_RXRDY 0x01000000
61#define TMIO_STAT_TXRQ 0x02000000
62#define TMIO_STAT_ILL_FUNC 0x20000000
63#define TMIO_STAT_CMD_BUSY 0x40000000
64#define TMIO_STAT_ILL_ACCESS 0x80000000
65
66#define CLK_CTL_DIV_MASK 0xff
67#define CLK_CTL_SCLKEN BIT(8)
68
69#define TMIO_BBS 512 /* Boot block size */
70
71#endif /* LINUX_MMC_TMIO_H */
diff --git a/include/trace/events/mmc.h b/include/trace/events/mmc.h
new file mode 100644
index 000000000000..a72f9b94c80b
--- /dev/null
+++ b/include/trace/events/mmc.h
@@ -0,0 +1,182 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM mmc
3
4#if !defined(_TRACE_MMC_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_MMC_H
6
7#include <linux/blkdev.h>
8#include <linux/mmc/core.h>
9#include <linux/mmc/host.h>
10#include <linux/tracepoint.h>
11
12TRACE_EVENT(mmc_request_start,
13
14 TP_PROTO(struct mmc_host *host, struct mmc_request *mrq),
15
16 TP_ARGS(host, mrq),
17
18 TP_STRUCT__entry(
19 __field(u32, cmd_opcode)
20 __field(u32, cmd_arg)
21 __field(unsigned int, cmd_flags)
22 __field(unsigned int, cmd_retries)
23 __field(u32, stop_opcode)
24 __field(u32, stop_arg)
25 __field(unsigned int, stop_flags)
26 __field(unsigned int, stop_retries)
27 __field(u32, sbc_opcode)
28 __field(u32, sbc_arg)
29 __field(unsigned int, sbc_flags)
30 __field(unsigned int, sbc_retries)
31 __field(unsigned int, blocks)
32 __field(unsigned int, blksz)
33 __field(unsigned int, data_flags)
34 __field(unsigned int, can_retune)
35 __field(unsigned int, doing_retune)
36 __field(unsigned int, retune_now)
37 __field(int, need_retune)
38 __field(int, hold_retune)
39 __field(unsigned int, retune_period)
40 __field(struct mmc_request *, mrq)
41 __string(name, mmc_hostname(host))
42 ),
43
44 TP_fast_assign(
45 __entry->cmd_opcode = mrq->cmd->opcode;
46 __entry->cmd_arg = mrq->cmd->arg;
47 __entry->cmd_flags = mrq->cmd->flags;
48 __entry->cmd_retries = mrq->cmd->retries;
49 __entry->stop_opcode = mrq->stop ? mrq->stop->opcode : 0;
50 __entry->stop_arg = mrq->stop ? mrq->stop->arg : 0;
51 __entry->stop_flags = mrq->stop ? mrq->stop->flags : 0;
52 __entry->stop_retries = mrq->stop ? mrq->stop->retries : 0;
53 __entry->sbc_opcode = mrq->sbc ? mrq->sbc->opcode : 0;
54 __entry->sbc_arg = mrq->sbc ? mrq->sbc->arg : 0;
55 __entry->sbc_flags = mrq->sbc ? mrq->sbc->flags : 0;
56 __entry->sbc_retries = mrq->sbc ? mrq->sbc->retries : 0;
57 __entry->blksz = mrq->data ? mrq->data->blksz : 0;
58 __entry->blocks = mrq->data ? mrq->data->blocks : 0;
59 __entry->data_flags = mrq->data ? mrq->data->flags : 0;
60 __entry->can_retune = host->can_retune;
61 __entry->doing_retune = host->doing_retune;
62 __entry->retune_now = host->retune_now;
63 __entry->need_retune = host->need_retune;
64 __entry->hold_retune = host->hold_retune;
65 __entry->retune_period = host->retune_period;
66 __assign_str(name, mmc_hostname(host));
67 __entry->mrq = mrq;
68 ),
69
70 TP_printk("%s: start struct mmc_request[%p]: "
71 "cmd_opcode=%u cmd_arg=0x%x cmd_flags=0x%x cmd_retries=%u "
72 "stop_opcode=%u stop_arg=0x%x stop_flags=0x%x stop_retries=%u "
73 "sbc_opcode=%u sbc_arg=0x%x sbc_flags=0x%x sbc_retires=%u "
74 "blocks=%u block_size=%u data_flags=0x%x "
75 "can_retune=%u doing_retune=%u retune_now=%u "
76 "need_retune=%d hold_retune=%d retune_period=%u",
77 __get_str(name), __entry->mrq,
78 __entry->cmd_opcode, __entry->cmd_arg,
79 __entry->cmd_flags, __entry->cmd_retries,
80 __entry->stop_opcode, __entry->stop_arg,
81 __entry->stop_flags, __entry->stop_retries,
82 __entry->sbc_opcode, __entry->sbc_arg,
83 __entry->sbc_flags, __entry->sbc_retries,
84 __entry->blocks, __entry->blksz, __entry->data_flags,
85 __entry->can_retune, __entry->doing_retune,
86 __entry->retune_now, __entry->need_retune,
87 __entry->hold_retune, __entry->retune_period)
88);
89
90TRACE_EVENT(mmc_request_done,
91
92 TP_PROTO(struct mmc_host *host, struct mmc_request *mrq),
93
94 TP_ARGS(host, mrq),
95
96 TP_STRUCT__entry(
97 __field(u32, cmd_opcode)
98 __field(int, cmd_err)
99 __array(u32, cmd_resp, 4)
100 __field(unsigned int, cmd_retries)
101 __field(u32, stop_opcode)
102 __field(int, stop_err)
103 __array(u32, stop_resp, 4)
104 __field(unsigned int, stop_retries)
105 __field(u32, sbc_opcode)
106 __field(int, sbc_err)
107 __array(u32, sbc_resp, 4)
108 __field(unsigned int, sbc_retries)
109 __field(unsigned int, bytes_xfered)
110 __field(int, data_err)
111 __field(unsigned int, can_retune)
112 __field(unsigned int, doing_retune)
113 __field(unsigned int, retune_now)
114 __field(int, need_retune)
115 __field(int, hold_retune)
116 __field(unsigned int, retune_period)
117 __field(struct mmc_request *, mrq)
118 __string(name, mmc_hostname(host))
119 ),
120
121 TP_fast_assign(
122 __entry->cmd_opcode = mrq->cmd->opcode;
123 __entry->cmd_err = mrq->cmd->error;
124 memcpy(__entry->cmd_resp, mrq->cmd->resp, 4);
125 __entry->cmd_retries = mrq->cmd->retries;
126 __entry->stop_opcode = mrq->stop ? mrq->stop->opcode : 0;
127 __entry->stop_err = mrq->stop ? mrq->stop->error : 0;
128 __entry->stop_resp[0] = mrq->stop ? mrq->stop->resp[0] : 0;
129 __entry->stop_resp[1] = mrq->stop ? mrq->stop->resp[1] : 0;
130 __entry->stop_resp[2] = mrq->stop ? mrq->stop->resp[2] : 0;
131 __entry->stop_resp[3] = mrq->stop ? mrq->stop->resp[3] : 0;
132 __entry->stop_retries = mrq->stop ? mrq->stop->retries : 0;
133 __entry->sbc_opcode = mrq->sbc ? mrq->sbc->opcode : 0;
134 __entry->sbc_err = mrq->sbc ? mrq->sbc->error : 0;
135 __entry->sbc_resp[0] = mrq->sbc ? mrq->sbc->resp[0] : 0;
136 __entry->sbc_resp[1] = mrq->sbc ? mrq->sbc->resp[1] : 0;
137 __entry->sbc_resp[2] = mrq->sbc ? mrq->sbc->resp[2] : 0;
138 __entry->sbc_resp[3] = mrq->sbc ? mrq->sbc->resp[3] : 0;
139 __entry->sbc_retries = mrq->sbc ? mrq->sbc->retries : 0;
140 __entry->bytes_xfered = mrq->data ? mrq->data->bytes_xfered : 0;
141 __entry->data_err = mrq->data ? mrq->data->error : 0;
142 __entry->can_retune = host->can_retune;
143 __entry->doing_retune = host->doing_retune;
144 __entry->retune_now = host->retune_now;
145 __entry->need_retune = host->need_retune;
146 __entry->hold_retune = host->hold_retune;
147 __entry->retune_period = host->retune_period;
148 __assign_str(name, mmc_hostname(host));
149 __entry->mrq = mrq;
150 ),
151
152 TP_printk("%s: end struct mmc_request[%p]: "
153 "cmd_opcode=%u cmd_err=%d cmd_resp=0x%x 0x%x 0x%x 0x%x "
154 "cmd_retries=%u stop_opcode=%u stop_err=%d "
155 "stop_resp=0x%x 0x%x 0x%x 0x%x stop_retries=%u "
156 "sbc_opcode=%u sbc_err=%d sbc_resp=0x%x 0x%x 0x%x 0x%x "
157 "sbc_retries=%u bytes_xfered=%u data_err=%d "
158 "can_retune=%u doing_retune=%u retune_now=%u need_retune=%d "
159 "hold_retune=%d retune_period=%u",
160 __get_str(name), __entry->mrq,
161 __entry->cmd_opcode, __entry->cmd_err,
162 __entry->cmd_resp[0], __entry->cmd_resp[1],
163 __entry->cmd_resp[2], __entry->cmd_resp[3],
164 __entry->cmd_retries,
165 __entry->stop_opcode, __entry->stop_err,
166 __entry->stop_resp[0], __entry->stop_resp[1],
167 __entry->stop_resp[2], __entry->stop_resp[3],
168 __entry->stop_retries,
169 __entry->sbc_opcode, __entry->sbc_err,
170 __entry->sbc_resp[0], __entry->sbc_resp[1],
171 __entry->sbc_resp[2], __entry->sbc_resp[3],
172 __entry->sbc_retries,
173 __entry->bytes_xfered, __entry->data_err,
174 __entry->can_retune, __entry->doing_retune,
175 __entry->retune_now, __entry->need_retune,
176 __entry->hold_retune, __entry->retune_period)
177);
178
179#endif /* _TRACE_MMC_H */
180
181/* This part must be outside protection */
182#include <trace/define_trace.h>