aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-22 19:36:08 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-22 19:36:08 -0400
commita6be1fcbc57f95bb47ef3c8e4ee3d83731b8f21e (patch)
tree88d762edfd97e7cdb0b41b8fe20c1ddb204c28c9
parent5b160bd426946c85f32b15e5d34d62d2618a5a87 (diff)
parent30b87c60e9cbfcdfce22aa652fc1e5d061fcb733 (diff)
Merge tag 'mmc-merge-for-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
Pull MMC updates from Chris Ball: "MMC highlights for 3.6: Core: - Rename cd-gpio to slot-gpio and extend it to support more slot GPIO functions, such as write-protect. - Add a function to get regulators (Vdd and Vccq) for a host. Drivers: - sdhci-pxav2, sdhci-pxav3: Add device tree support. - sdhi: Add device tree support. - sh_mmcif: Add support for regulators, device tree, slot-gpio. - tmio: Add regulator support, use slot-gpio." * tag 'mmc-merge-for-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (62 commits) mmc: sdhci-dove: Prepare for common clock framework mmc: sdhci-dove: Add SDHCI_QUIRK_NO_HISPD_BIT mmc: omap_hsmmc: ensure probe returns error upon resource failure mmc: mxs-mmc: Add wp-inverted property mmc: esdhc: Fix DMA_MASK to not break mx25 DMA access mmc: core: reset signal voltage on power up mmc: sd: Fix sd current limit setting mmc: omap_hsmmc: add clk_prepare and clk_unprepare mmc: sdhci: When a UHS switch fails, cycle power if regulator is used mmc: atmel-mci: modify CLKDIV displaying in debugfs mmc: atmel-mci: fix incorrect setting of host->data to NULL mmc: sdhci: poll for card even when card is logically unremovable mmc: sdhci: Introduce new flag SDHCI_USING_RETUNING_TIMER mmc: sdio: Change pr_warning to pr_warn_ratelimited mmc: core: Simplify and fix for SD switch processing mmc: sdhci: restore host settings when card is removed mmc: sdhci: fix incorrect command used in tuning mmc: sdhci-pci: CaFe has broken card detection mmc: sdhci: Report failure reasons for all cases in sdhci_add_host() mmc: s3cmci: Convert s3cmci driver to gpiolib API ...
-rw-r--r--Documentation/devicetree/bindings/mmc/fsl-esdhc.txt25
-rw-r--r--Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt8
-rw-r--r--Documentation/devicetree/bindings/mmc/mmc-spi-slot.txt8
-rw-r--r--Documentation/devicetree/bindings/mmc/mmc.txt10
-rw-r--r--Documentation/devicetree/bindings/mmc/mmci.txt12
-rw-r--r--Documentation/devicetree/bindings/mmc/mxs-mmc.txt8
-rw-r--r--Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt8
-rw-r--r--Documentation/devicetree/bindings/mmc/sdhci-pxa.txt21
-rw-r--r--Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt7
-rw-r--r--drivers/mmc/card/block.c36
-rw-r--r--drivers/mmc/core/Makefile2
-rw-r--r--drivers/mmc/core/cd-gpio.c83
-rw-r--r--drivers/mmc/core/core.c90
-rw-r--r--drivers/mmc/core/host.c6
-rw-r--r--drivers/mmc/core/mmc.c3
-rw-r--r--drivers/mmc/core/mmc_ops.c1
-rw-r--r--drivers/mmc/core/sd.c171
-rw-r--r--drivers/mmc/core/sdio.c7
-rw-r--r--drivers/mmc/core/sdio_cis.c2
-rw-r--r--drivers/mmc/core/slot-gpio.c188
-rw-r--r--drivers/mmc/host/atmel-mci.c14
-rw-r--r--drivers/mmc/host/dw_mmc.c17
-rw-r--r--drivers/mmc/host/mxs-mmc.c26
-rw-r--r--drivers/mmc/host/omap_hsmmc.c16
-rw-r--r--drivers/mmc/host/s3cmci.c10
-rw-r--r--drivers/mmc/host/sdhci-dove.c51
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c9
-rw-r--r--drivers/mmc/host/sdhci-pci.c1
-rw-r--r--drivers/mmc/host/sdhci-pxav2.c54
-rw-r--r--drivers/mmc/host/sdhci-pxav3.c52
-rw-r--r--drivers/mmc/host/sdhci.c144
-rw-r--r--drivers/mmc/host/sdhci.h1
-rw-r--r--drivers/mmc/host/sh_mmcif.c185
-rw-r--r--drivers/mmc/host/sh_mobile_sdhi.c66
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c132
-rw-r--r--include/linux/mfd/tmio.h4
-rw-r--r--include/linux/mmc/card.h1
-rw-r--r--include/linux/mmc/cd-gpio.h18
-rw-r--r--include/linux/mmc/host.h48
-rw-r--r--include/linux/mmc/sdhci.h4
-rw-r--r--include/linux/mmc/sh_mmcif.h2
-rw-r--r--include/linux/mmc/sh_mobile_sdhi.h1
-rw-r--r--include/linux/mmc/slot-gpio.h24
43 files changed, 1057 insertions, 519 deletions
diff --git a/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt b/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
index 0d93b4b0e0e3..bd9be0b5bc20 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
@@ -3,21 +3,22 @@
3The Enhanced Secure Digital Host Controller provides an interface 3The Enhanced Secure Digital Host Controller provides an interface
4for MMC, SD, and SDIO types of memory cards. 4for MMC, SD, and SDIO types of memory cards.
5 5
6This file documents differences between the core properties described
7by mmc.txt and the properties used by the sdhci-esdhc driver.
8
6Required properties: 9Required properties:
7 - compatible : should be
8 "fsl,<chip>-esdhc", "fsl,esdhc"
9 - reg : should contain eSDHC registers location and length.
10 - interrupts : should contain eSDHC interrupt.
11 - interrupt-parent : interrupt source phandle. 10 - interrupt-parent : interrupt source phandle.
12 - clock-frequency : specifies eSDHC base clock frequency. 11 - clock-frequency : specifies eSDHC base clock frequency.
13 - sdhci,wp-inverted : (optional) specifies that eSDHC controller 12
14 reports inverted write-protect state; New devices should use 13Optional properties:
15 the generic "wp-inverted" property. 14 - sdhci,wp-inverted : specifies that eSDHC controller reports
16 - sdhci,1-bit-only : (optional) specifies that a controller can 15 inverted write-protect state; New devices should use the generic
17 only handle 1-bit data transfers. New devices should use the 16 "wp-inverted" property.
18 generic "bus-width = <1>" property. 17 - sdhci,1-bit-only : specifies that a controller can only handle
19 - sdhci,auto-cmd12: (optional) specifies that a controller can 18 1-bit data transfers. New devices should use the generic
20 only handle auto CMD12. 19 "bus-width = <1>" property.
20 - sdhci,auto-cmd12: specifies that a controller can only handle auto
21 CMD12.
21 22
22Example: 23Example:
23 24
diff --git a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
index fea541ee8b34..70cd49b1caa8 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-imx-esdhc.txt
@@ -3,17 +3,15 @@
3The Enhanced Secure Digital Host Controller on Freescale i.MX family 3The Enhanced Secure Digital Host Controller on Freescale i.MX family
4provides an interface for MMC, SD, and SDIO types of memory cards. 4provides an interface for MMC, SD, and SDIO types of memory cards.
5 5
6This file documents differences between the core properties described
7by mmc.txt and the properties used by the sdhci-esdhc-imx driver.
8
6Required properties: 9Required properties:
7- compatible : Should be "fsl,<chip>-esdhc" 10- compatible : Should be "fsl,<chip>-esdhc"
8- reg : Should contain eSDHC registers location and length
9- interrupts : Should contain eSDHC interrupt
10 11
11Optional properties: 12Optional properties:
12- non-removable : Indicate the card is wired to host permanently
13- fsl,cd-internal : Indicate to use controller internal card detection 13- fsl,cd-internal : Indicate to use controller internal card detection
14- fsl,wp-internal : Indicate to use controller internal write protection 14- fsl,wp-internal : Indicate to use controller internal write protection
15- cd-gpios : Specify GPIOs for card detection
16- wp-gpios : Specify GPIOs for write protection
17 15
18Examples: 16Examples:
19 17
diff --git a/Documentation/devicetree/bindings/mmc/mmc-spi-slot.txt b/Documentation/devicetree/bindings/mmc/mmc-spi-slot.txt
index d64aea5a4203..0e5e2ec4001d 100644
--- a/Documentation/devicetree/bindings/mmc/mmc-spi-slot.txt
+++ b/Documentation/devicetree/bindings/mmc/mmc-spi-slot.txt
@@ -1,8 +1,9 @@
1MMC/SD/SDIO slot directly connected to a SPI bus 1MMC/SD/SDIO slot directly connected to a SPI bus
2 2
3This file documents differences between the core properties described
4by mmc.txt and the properties used by the mmc_spi driver.
5
3Required properties: 6Required properties:
4- compatible : should be "mmc-spi-slot".
5- reg : should specify SPI address (chip-select number).
6- spi-max-frequency : maximum frequency for this device (Hz). 7- spi-max-frequency : maximum frequency for this device (Hz).
7- voltage-ranges : two cells are required, first cell specifies minimum 8- voltage-ranges : two cells are required, first cell specifies minimum
8 slot voltage (mV), second cell specifies maximum slot voltage (mV). 9 slot voltage (mV), second cell specifies maximum slot voltage (mV).
@@ -11,8 +12,7 @@ Required properties:
11Optional properties: 12Optional properties:
12- gpios : may specify GPIOs in this order: Card-Detect GPIO, 13- gpios : may specify GPIOs in this order: Card-Detect GPIO,
13 Write-Protect GPIO. Note that this does not follow the 14 Write-Protect GPIO. Note that this does not follow the
14 binding from mmc.txt, for historic reasons. 15 binding from mmc.txt, for historical reasons.
15- interrupts : the interrupt of a card detect interrupt.
16- interrupt-parent : the phandle for the interrupt controller that 16- interrupt-parent : the phandle for the interrupt controller that
17 services interrupts for this device. 17 services interrupts for this device.
18 18
diff --git a/Documentation/devicetree/bindings/mmc/mmc.txt b/Documentation/devicetree/bindings/mmc/mmc.txt
index 6e70dcde0a71..8a6811f4a02f 100644
--- a/Documentation/devicetree/bindings/mmc/mmc.txt
+++ b/Documentation/devicetree/bindings/mmc/mmc.txt
@@ -2,13 +2,17 @@ These properties are common to multiple MMC host controllers. Any host
2that requires the respective functionality should implement them using 2that requires the respective functionality should implement them using
3these definitions. 3these definitions.
4 4
5Interpreted by the OF core:
6- reg: Registers location and length.
7- interrupts: Interrupts used by the MMC controller.
8
5Required properties: 9Required properties:
6- bus-width: Number of data lines, can be <1>, <4>, or <8> 10- bus-width: Number of data lines, can be <1>, <4>, or <8>
7 11
8Optional properties: 12Optional properties:
9- cd-gpios : Specify GPIOs for card detection, see gpio binding 13- cd-gpios: Specify GPIOs for card detection, see gpio binding
10- wp-gpios : Specify GPIOs for write protection, see gpio binding 14- wp-gpios: Specify GPIOs for write protection, see gpio binding
11- cd-inverted: when present, polarity on the wp gpio line is inverted 15- cd-inverted: when present, polarity on the cd gpio line is inverted
12- wp-inverted: when present, polarity on the wp gpio line is inverted 16- wp-inverted: when present, polarity on the wp gpio line is inverted
13- non-removable: non-removable slot (like eMMC) 17- non-removable: non-removable slot (like eMMC)
14- max-frequency: maximum operating clock frequency 18- max-frequency: maximum operating clock frequency
diff --git a/Documentation/devicetree/bindings/mmc/mmci.txt b/Documentation/devicetree/bindings/mmc/mmci.txt
index 14a81d526118..2b584cae352a 100644
--- a/Documentation/devicetree/bindings/mmc/mmci.txt
+++ b/Documentation/devicetree/bindings/mmc/mmci.txt
@@ -1,19 +1,15 @@
1* ARM PrimeCell MultiMedia Card Interface (MMCI) PL180/1 1* ARM PrimeCell MultiMedia Card Interface (MMCI) PL180/1
2 2
3The ARM PrimeCell MMCI PL180 and PL181 provides and interface for 3The ARM PrimeCell MMCI PL180 and PL181 provides an interface for
4reading and writing to MultiMedia and SD cards alike. 4reading and writing to MultiMedia and SD cards alike.
5 5
6This file documents differences between the core properties described
7by mmc.txt and the properties used by the mmci driver.
8
6Required properties: 9Required properties:
7- compatible : contains "arm,pl18x", "arm,primecell". 10- compatible : contains "arm,pl18x", "arm,primecell".
8- reg : contains pl18x registers and length.
9- interrupts : contains the device IRQ(s).
10- arm,primecell-periphid : contains the PrimeCell Peripheral ID. 11- arm,primecell-periphid : contains the PrimeCell Peripheral ID.
11 12
12Optional properties: 13Optional properties:
13- wp-gpios : contains any write protect (ro) gpios
14- cd-gpios : contains any card detection gpios
15- cd-inverted : indicates whether the cd gpio is inverted
16- max-frequency : contains the maximum operating frequency
17- bus-width : number of data lines, can be <1>, <4>, or <8>
18- mmc-cap-mmc-highspeed : indicates whether MMC is high speed capable 14- mmc-cap-mmc-highspeed : indicates whether MMC is high speed capable
19- mmc-cap-sd-highspeed : indicates whether SD is high speed capable 15- mmc-cap-sd-highspeed : indicates whether SD is high speed capable
diff --git a/Documentation/devicetree/bindings/mmc/mxs-mmc.txt b/Documentation/devicetree/bindings/mmc/mxs-mmc.txt
index 14d870a9e3db..54949f6faede 100644
--- a/Documentation/devicetree/bindings/mmc/mxs-mmc.txt
+++ b/Documentation/devicetree/bindings/mmc/mxs-mmc.txt
@@ -3,16 +3,14 @@
3The Freescale MXS Synchronous Serial Ports (SSP) can act as a MMC controller 3The Freescale MXS Synchronous Serial Ports (SSP) can act as a MMC controller
4to support MMC, SD, and SDIO types of memory cards. 4to support MMC, SD, and SDIO types of memory cards.
5 5
6This file documents differences between the core properties in mmc.txt
7and the properties used by the mxsmmc driver.
8
6Required properties: 9Required properties:
7- compatible: Should be "fsl,<chip>-mmc". The supported chips include 10- compatible: Should be "fsl,<chip>-mmc". The supported chips include
8 imx23 and imx28. 11 imx23 and imx28.
9- reg: Should contain registers location and length
10- interrupts: Should contain ERROR and DMA interrupts 12- interrupts: Should contain ERROR and DMA interrupts
11- fsl,ssp-dma-channel: APBH DMA channel for the SSP 13- fsl,ssp-dma-channel: APBH DMA channel for the SSP
12- bus-width: Number of data lines, can be <1>, <4>, or <8>
13
14Optional properties:
15- wp-gpios: Specify GPIOs for write protection
16 14
17Examples: 15Examples:
18 16
diff --git a/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt b/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt
index f77c3031607f..c6d7b11db9eb 100644
--- a/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt
+++ b/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt
@@ -3,15 +3,13 @@
3This controller on Tegra family SoCs provides an interface for MMC, SD, 3This controller on Tegra family SoCs provides an interface for MMC, SD,
4and SDIO types of memory cards. 4and SDIO types of memory cards.
5 5
6This file documents differences between the core properties described
7by mmc.txt and the properties used by the sdhci-tegra driver.
8
6Required properties: 9Required properties:
7- compatible : Should be "nvidia,<chip>-sdhci" 10- compatible : Should be "nvidia,<chip>-sdhci"
8- reg : Should contain SD/MMC registers location and length
9- interrupts : Should contain SD/MMC interrupt
10- bus-width : Number of data lines, can be <1>, <4>, or <8>
11 11
12Optional properties: 12Optional properties:
13- cd-gpios : Specify GPIOs for card detection
14- wp-gpios : Specify GPIOs for write protection
15- power-gpios : Specify GPIOs for power control 13- power-gpios : Specify GPIOs for power control
16 14
17Example: 15Example:
diff --git a/Documentation/devicetree/bindings/mmc/sdhci-pxa.txt b/Documentation/devicetree/bindings/mmc/sdhci-pxa.txt
new file mode 100644
index 000000000000..dbe98a3c183a
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/sdhci-pxa.txt
@@ -0,0 +1,21 @@
1* Marvell sdhci-pxa v2/v3 controller
2
3This file documents differences between the core properties in mmc.txt
4and the properties used by the sdhci-pxav2 and sdhci-pxav3 drivers.
5
6Required properties:
7- compatible: Should be "mrvl,pxav2-mmc" or "mrvl,pxav3-mmc".
8
9Optional properties:
10- mrvl,clk-delay-cycles: Specify a number of cycles to delay for tuning.
11
12Example:
13
14sdhci@d4280800 {
15 compatible = "mrvl,pxav3-mmc";
16 reg = <0xd4280800 0x800>;
17 bus-width = <8>;
18 interrupts = <27>;
19 non-removable;
20 mrvl,clk-delay-cycles = <31>;
21};
diff --git a/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt b/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt
index 8a53958c9a9f..be76a23b34c4 100644
--- a/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt
+++ b/Documentation/devicetree/bindings/mmc/ti-omap-hsmmc.txt
@@ -3,21 +3,20 @@
3The Highspeed MMC Host Controller on TI OMAP family 3The Highspeed MMC Host Controller on TI OMAP family
4provides an interface for MMC, SD, and SDIO types of memory cards. 4provides an interface for MMC, SD, and SDIO types of memory cards.
5 5
6This file documents differences between the core properties described
7by mmc.txt and the properties used by the omap_hsmmc driver.
8
6Required properties: 9Required properties:
7- compatible: 10- compatible:
8 Should be "ti,omap2-hsmmc", for OMAP2 controllers 11 Should be "ti,omap2-hsmmc", for OMAP2 controllers
9 Should be "ti,omap3-hsmmc", for OMAP3 controllers 12 Should be "ti,omap3-hsmmc", for OMAP3 controllers
10 Should be "ti,omap4-hsmmc", for OMAP4 controllers 13 Should be "ti,omap4-hsmmc", for OMAP4 controllers
11- ti,hwmods: Must be "mmc<n>", n is controller instance starting 1 14- ti,hwmods: Must be "mmc<n>", n is controller instance starting 1
12- reg : should contain hsmmc registers location and length
13 15
14Optional properties: 16Optional properties:
15ti,dual-volt: boolean, supports dual voltage cards 17ti,dual-volt: boolean, supports dual voltage cards
16<supply-name>-supply: phandle to the regulator device tree node 18<supply-name>-supply: phandle to the regulator device tree node
17"supply-name" examples are "vmmc", "vmmc_aux" etc 19"supply-name" examples are "vmmc", "vmmc_aux" etc
18bus-width: Number of data lines, default assumed is 1 if the property is missing.
19cd-gpios: GPIOs for card detection
20wp-gpios: GPIOs for write protection
21ti,non-removable: non-removable slot (like eMMC) 20ti,non-removable: non-removable slot (like eMMC)
22ti,needs-special-reset: Requires a special softreset sequence 21ti,needs-special-reset: Requires a special softreset sequence
23 22
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 276d21ce6bc1..f1c84decb192 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -850,9 +850,7 @@ out:
850 goto retry; 850 goto retry;
851 if (!err) 851 if (!err)
852 mmc_blk_reset_success(md, type); 852 mmc_blk_reset_success(md, type);
853 spin_lock_irq(&md->lock); 853 blk_end_request(req, err, blk_rq_bytes(req));
854 __blk_end_request(req, err, blk_rq_bytes(req));
855 spin_unlock_irq(&md->lock);
856 854
857 return err ? 0 : 1; 855 return err ? 0 : 1;
858} 856}
@@ -934,9 +932,7 @@ out_retry:
934 if (!err) 932 if (!err)
935 mmc_blk_reset_success(md, type); 933 mmc_blk_reset_success(md, type);
936out: 934out:
937 spin_lock_irq(&md->lock); 935 blk_end_request(req, err, blk_rq_bytes(req));
938 __blk_end_request(req, err, blk_rq_bytes(req));
939 spin_unlock_irq(&md->lock);
940 936
941 return err ? 0 : 1; 937 return err ? 0 : 1;
942} 938}
@@ -951,9 +947,7 @@ static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
951 if (ret) 947 if (ret)
952 ret = -EIO; 948 ret = -EIO;
953 949
954 spin_lock_irq(&md->lock); 950 blk_end_request_all(req, ret);
955 __blk_end_request_all(req, ret);
956 spin_unlock_irq(&md->lock);
957 951
958 return ret ? 0 : 1; 952 return ret ? 0 : 1;
959} 953}
@@ -1252,14 +1246,10 @@ static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
1252 1246
1253 blocks = mmc_sd_num_wr_blocks(card); 1247 blocks = mmc_sd_num_wr_blocks(card);
1254 if (blocks != (u32)-1) { 1248 if (blocks != (u32)-1) {
1255 spin_lock_irq(&md->lock); 1249 ret = blk_end_request(req, 0, blocks << 9);
1256 ret = __blk_end_request(req, 0, blocks << 9);
1257 spin_unlock_irq(&md->lock);
1258 } 1250 }
1259 } else { 1251 } else {
1260 spin_lock_irq(&md->lock); 1252 ret = blk_end_request(req, 0, brq->data.bytes_xfered);
1261 ret = __blk_end_request(req, 0, brq->data.bytes_xfered);
1262 spin_unlock_irq(&md->lock);
1263 } 1253 }
1264 return ret; 1254 return ret;
1265} 1255}
@@ -1311,10 +1301,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1311 * A block was successfully transferred. 1301 * A block was successfully transferred.
1312 */ 1302 */
1313 mmc_blk_reset_success(md, type); 1303 mmc_blk_reset_success(md, type);
1314 spin_lock_irq(&md->lock); 1304 ret = blk_end_request(req, 0,
1315 ret = __blk_end_request(req, 0,
1316 brq->data.bytes_xfered); 1305 brq->data.bytes_xfered);
1317 spin_unlock_irq(&md->lock);
1318 /* 1306 /*
1319 * If the blk_end_request function returns non-zero even 1307 * If the blk_end_request function returns non-zero even
1320 * though all data has been transferred and no errors 1308 * though all data has been transferred and no errors
@@ -1364,10 +1352,8 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1364 * time, so we only reach here after trying to 1352 * time, so we only reach here after trying to
1365 * read a single sector. 1353 * read a single sector.
1366 */ 1354 */
1367 spin_lock_irq(&md->lock); 1355 ret = blk_end_request(req, -EIO,
1368 ret = __blk_end_request(req, -EIO,
1369 brq->data.blksz); 1356 brq->data.blksz);
1370 spin_unlock_irq(&md->lock);
1371 if (!ret) 1357 if (!ret)
1372 goto start_new_req; 1358 goto start_new_req;
1373 break; 1359 break;
@@ -1388,12 +1374,10 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1388 return 1; 1374 return 1;
1389 1375
1390 cmd_abort: 1376 cmd_abort:
1391 spin_lock_irq(&md->lock);
1392 if (mmc_card_removed(card)) 1377 if (mmc_card_removed(card))
1393 req->cmd_flags |= REQ_QUIET; 1378 req->cmd_flags |= REQ_QUIET;
1394 while (ret) 1379 while (ret)
1395 ret = __blk_end_request(req, -EIO, blk_rq_cur_bytes(req)); 1380 ret = blk_end_request(req, -EIO, blk_rq_cur_bytes(req));
1396 spin_unlock_irq(&md->lock);
1397 1381
1398 start_new_req: 1382 start_new_req:
1399 if (rqc) { 1383 if (rqc) {
@@ -1417,9 +1401,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
1417 ret = mmc_blk_part_switch(card, md); 1401 ret = mmc_blk_part_switch(card, md);
1418 if (ret) { 1402 if (ret) {
1419 if (req) { 1403 if (req) {
1420 spin_lock_irq(&md->lock); 1404 blk_end_request_all(req, -EIO);
1421 __blk_end_request_all(req, -EIO);
1422 spin_unlock_irq(&md->lock);
1423 } 1405 }
1424 ret = 0; 1406 ret = 0;
1425 goto out; 1407 goto out;
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index dca4428380f1..38ed210ce2f3 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -7,6 +7,6 @@ mmc_core-y := core.o bus.o host.o \
7 mmc.o mmc_ops.o sd.o sd_ops.o \ 7 mmc.o mmc_ops.o sd.o sd_ops.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 cd-gpio.o 10 quirks.o slot-gpio.o
11 11
12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o 12mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o
diff --git a/drivers/mmc/core/cd-gpio.c b/drivers/mmc/core/cd-gpio.c
deleted file mode 100644
index 8f5dc08d6598..000000000000
--- a/drivers/mmc/core/cd-gpio.c
+++ /dev/null
@@ -1,83 +0,0 @@
1/*
2 * Generic GPIO card-detect helper
3 *
4 * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/err.h>
12#include <linux/gpio.h>
13#include <linux/interrupt.h>
14#include <linux/jiffies.h>
15#include <linux/mmc/cd-gpio.h>
16#include <linux/mmc/host.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19
20struct mmc_cd_gpio {
21 unsigned int gpio;
22 char label[0];
23};
24
25static irqreturn_t mmc_cd_gpio_irqt(int irq, void *dev_id)
26{
27 /* Schedule a card detection after a debounce timeout */
28 mmc_detect_change(dev_id, msecs_to_jiffies(100));
29 return IRQ_HANDLED;
30}
31
32int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio)
33{
34 size_t len = strlen(dev_name(host->parent)) + 4;
35 struct mmc_cd_gpio *cd;
36 int irq = gpio_to_irq(gpio);
37 int ret;
38
39 if (irq < 0)
40 return irq;
41
42 cd = kmalloc(sizeof(*cd) + len, GFP_KERNEL);
43 if (!cd)
44 return -ENOMEM;
45
46 snprintf(cd->label, len, "%s cd", dev_name(host->parent));
47
48 ret = gpio_request_one(gpio, GPIOF_DIR_IN, cd->label);
49 if (ret < 0)
50 goto egpioreq;
51
52 ret = request_threaded_irq(irq, NULL, mmc_cd_gpio_irqt,
53 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
54 IRQF_ONESHOT, cd->label, host);
55 if (ret < 0)
56 goto eirqreq;
57
58 cd->gpio = gpio;
59 host->hotplug.irq = irq;
60 host->hotplug.handler_priv = cd;
61
62 return 0;
63
64eirqreq:
65 gpio_free(gpio);
66egpioreq:
67 kfree(cd);
68 return ret;
69}
70EXPORT_SYMBOL(mmc_cd_gpio_request);
71
72void mmc_cd_gpio_free(struct mmc_host *host)
73{
74 struct mmc_cd_gpio *cd = host->hotplug.handler_priv;
75
76 if (!cd)
77 return;
78
79 free_irq(host->hotplug.irq, host);
80 gpio_free(cd->gpio);
81 kfree(cd);
82}
83EXPORT_SYMBOL(mmc_cd_gpio_free);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 0b6141d29dbd..8ac5246e2ab2 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -404,6 +404,7 @@ int mmc_interrupt_hpi(struct mmc_card *card)
404{ 404{
405 int err; 405 int err;
406 u32 status; 406 u32 status;
407 unsigned long prg_wait;
407 408
408 BUG_ON(!card); 409 BUG_ON(!card);
409 410
@@ -419,30 +420,38 @@ int mmc_interrupt_hpi(struct mmc_card *card)
419 goto out; 420 goto out;
420 } 421 }
421 422
422 /* 423 switch (R1_CURRENT_STATE(status)) {
423 * If the card status is in PRG-state, we can send the HPI command. 424 case R1_STATE_IDLE:
424 */ 425 case R1_STATE_READY:
425 if (R1_CURRENT_STATE(status) == R1_STATE_PRG) { 426 case R1_STATE_STBY:
426 do { 427 /*
427 /* 428 * In idle states, HPI is not needed and the caller
428 * We don't know when the HPI command will finish 429 * can issue the next intended command immediately
429 * processing, so we need to resend HPI until out 430 */
430 * of prg-state, and keep checking the card status 431 goto out;
431 * with SEND_STATUS. If a timeout error occurs when 432 case R1_STATE_PRG:
432 * sending the HPI command, we are already out of 433 break;
433 * prg-state. 434 default:
434 */ 435 /* In all other states, it's illegal to issue HPI */
435 err = mmc_send_hpi_cmd(card, &status); 436 pr_debug("%s: HPI cannot be sent. Card state=%d\n",
436 if (err) 437 mmc_hostname(card->host), R1_CURRENT_STATE(status));
437 pr_debug("%s: abort HPI (%d error)\n", 438 err = -EINVAL;
438 mmc_hostname(card->host), err); 439 goto out;
440 }
439 441
440 err = mmc_send_status(card, &status); 442 err = mmc_send_hpi_cmd(card, &status);
441 if (err) 443 if (err)
442 break; 444 goto out;
443 } while (R1_CURRENT_STATE(status) == R1_STATE_PRG); 445
444 } else 446 prg_wait = jiffies + msecs_to_jiffies(card->ext_csd.out_of_int_time);
445 pr_debug("%s: Left prg-state\n", mmc_hostname(card->host)); 447 do {
448 err = mmc_send_status(card, &status);
449
450 if (!err && R1_CURRENT_STATE(status) == R1_STATE_TRAN)
451 break;
452 if (time_after(jiffies, prg_wait))
453 err = -ETIMEDOUT;
454 } while (!err);
446 455
447out: 456out:
448 mmc_release_host(card->host); 457 mmc_release_host(card->host);
@@ -941,7 +950,7 @@ int mmc_regulator_get_ocrmask(struct regulator *supply)
941 950
942 return result; 951 return result;
943} 952}
944EXPORT_SYMBOL(mmc_regulator_get_ocrmask); 953EXPORT_SYMBOL_GPL(mmc_regulator_get_ocrmask);
945 954
946/** 955/**
947 * mmc_regulator_set_ocr - set regulator to match host->ios voltage 956 * mmc_regulator_set_ocr - set regulator to match host->ios voltage
@@ -1011,7 +1020,30 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc,
1011 "could not set regulator OCR (%d)\n", result); 1020 "could not set regulator OCR (%d)\n", result);
1012 return result; 1021 return result;
1013} 1022}
1014EXPORT_SYMBOL(mmc_regulator_set_ocr); 1023EXPORT_SYMBOL_GPL(mmc_regulator_set_ocr);
1024
1025int mmc_regulator_get_supply(struct mmc_host *mmc)
1026{
1027 struct device *dev = mmc_dev(mmc);
1028 struct regulator *supply;
1029 int ret;
1030
1031 supply = devm_regulator_get(dev, "vmmc");
1032 mmc->supply.vmmc = supply;
1033 mmc->supply.vqmmc = devm_regulator_get(dev, "vqmmc");
1034
1035 if (IS_ERR(supply))
1036 return PTR_ERR(supply);
1037
1038 ret = mmc_regulator_get_ocrmask(supply);
1039 if (ret > 0)
1040 mmc->ocr_avail = ret;
1041 else
1042 dev_warn(mmc_dev(mmc), "Failed getting OCR mask: %d\n", ret);
1043
1044 return 0;
1045}
1046EXPORT_SYMBOL_GPL(mmc_regulator_get_supply);
1015 1047
1016#endif /* CONFIG_REGULATOR */ 1048#endif /* CONFIG_REGULATOR */
1017 1049
@@ -1180,6 +1212,9 @@ static void mmc_power_up(struct mmc_host *host)
1180 host->ios.timing = MMC_TIMING_LEGACY; 1212 host->ios.timing = MMC_TIMING_LEGACY;
1181 mmc_set_ios(host); 1213 mmc_set_ios(host);
1182 1214
1215 /* Set signal voltage to 3.3V */
1216 mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, false);
1217
1183 /* 1218 /*
1184 * This delay should be sufficient to allow the power supply 1219 * This delay should be sufficient to allow the power supply
1185 * to reach the minimum voltage. 1220 * to reach the minimum voltage.
@@ -1931,9 +1966,6 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
1931 */ 1966 */
1932 mmc_hw_reset_for_init(host); 1967 mmc_hw_reset_for_init(host);
1933 1968
1934 /* Initialization should be done at 3.3 V I/O voltage. */
1935 mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);
1936
1937 /* 1969 /*
1938 * sdio_reset sends CMD52 to reset card. Since we do not know 1970 * sdio_reset sends CMD52 to reset card. Since we do not know
1939 * if the card is being re-initialized, just send it. CMD52 1971 * if the card is being re-initialized, just send it. CMD52
@@ -2075,6 +2107,7 @@ void mmc_rescan(struct work_struct *work)
2075void mmc_start_host(struct mmc_host *host) 2107void mmc_start_host(struct mmc_host *host)
2076{ 2108{
2077 host->f_init = max(freqs[0], host->f_min); 2109 host->f_init = max(freqs[0], host->f_min);
2110 host->rescan_disable = 0;
2078 mmc_power_up(host); 2111 mmc_power_up(host);
2079 mmc_detect_change(host, 0); 2112 mmc_detect_change(host, 0);
2080} 2113}
@@ -2088,6 +2121,7 @@ void mmc_stop_host(struct mmc_host *host)
2088 spin_unlock_irqrestore(&host->lock, flags); 2121 spin_unlock_irqrestore(&host->lock, flags);
2089#endif 2122#endif
2090 2123
2124 host->rescan_disable = 1;
2091 cancel_delayed_work_sync(&host->detect); 2125 cancel_delayed_work_sync(&host->detect);
2092 mmc_flush_scheduled_work(); 2126 mmc_flush_scheduled_work();
2093 2127
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 91c84c7a1829..597f189b4427 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -32,6 +32,7 @@
32static void mmc_host_classdev_release(struct device *dev) 32static void mmc_host_classdev_release(struct device *dev)
33{ 33{
34 struct mmc_host *host = cls_dev_to_mmc_host(dev); 34 struct mmc_host *host = cls_dev_to_mmc_host(dev);
35 mutex_destroy(&host->slot.lock);
35 kfree(host); 36 kfree(host);
36} 37}
37 38
@@ -312,6 +313,8 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
312 if (!host) 313 if (!host)
313 return NULL; 314 return NULL;
314 315
316 /* scanning will be enabled when we're ready */
317 host->rescan_disable = 1;
315 spin_lock(&mmc_host_lock); 318 spin_lock(&mmc_host_lock);
316 err = idr_get_new(&mmc_host_idr, host, &host->index); 319 err = idr_get_new(&mmc_host_idr, host, &host->index);
317 spin_unlock(&mmc_host_lock); 320 spin_unlock(&mmc_host_lock);
@@ -327,6 +330,9 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
327 330
328 mmc_host_clk_init(host); 331 mmc_host_clk_init(host);
329 332
333 mutex_init(&host->slot.lock);
334 host->slot.cd_irq = -EINVAL;
335
330 spin_lock_init(&host->lock); 336 spin_lock_init(&host->lock);
331 init_waitqueue_head(&host->wq); 337 init_waitqueue_head(&host->wq);
332 INIT_DELAYED_WORK(&host->detect, mmc_rescan); 338 INIT_DELAYED_WORK(&host->detect, mmc_rescan);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 4f4489aa6bae..396b25891bb9 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -818,9 +818,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
818 if (!mmc_host_is_spi(host)) 818 if (!mmc_host_is_spi(host))
819 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN); 819 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN);
820 820
821 /* Initialization should be done at 3.3 V I/O voltage. */
822 mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);
823
824 /* 821 /*
825 * Since we're changing the OCR value, we seem to 822 * Since we're changing the OCR value, we seem to
826 * need to tell some cards to go back to the idle 823 * need to tell some cards to go back to the idle
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 69370f494e05..0ed2cc5f35b6 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -569,7 +569,6 @@ int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status)
569 569
570 cmd.opcode = opcode; 570 cmd.opcode = opcode;
571 cmd.arg = card->rca << 16 | 1; 571 cmd.arg = card->rca << 16 | 1;
572 cmd.cmd_timeout_ms = card->ext_csd.out_of_int_time;
573 572
574 err = mmc_wait_for_cmd(card->host, &cmd, 0); 573 err = mmc_wait_for_cmd(card->host, &cmd, 0);
575 if (err) { 574 if (err) {
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index b2b43f624b9e..74972c241dff 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -244,7 +244,7 @@ static int mmc_read_ssr(struct mmc_card *card)
244 * bitfield positions accordingly. 244 * bitfield positions accordingly.
245 */ 245 */
246 au = UNSTUFF_BITS(ssr, 428 - 384, 4); 246 au = UNSTUFF_BITS(ssr, 428 - 384, 4);
247 if (au > 0 || au <= 9) { 247 if (au > 0 && au <= 9) {
248 card->ssr.au = 1 << (au + 4); 248 card->ssr.au = 1 << (au + 4);
249 es = UNSTUFF_BITS(ssr, 408 - 384, 16); 249 es = UNSTUFF_BITS(ssr, 408 - 384, 16);
250 et = UNSTUFF_BITS(ssr, 402 - 384, 6); 250 et = UNSTUFF_BITS(ssr, 402 - 384, 6);
@@ -290,8 +290,12 @@ static int mmc_read_switch(struct mmc_card *card)
290 return -ENOMEM; 290 return -ENOMEM;
291 } 291 }
292 292
293 /* Find out the supported Bus Speed Modes. */ 293 /*
294 err = mmc_sd_switch(card, 0, 0, 1, status); 294 * Find out the card's support bits with a mode 0 operation.
295 * The argument does not matter, as the support bits do not
296 * change with the arguments.
297 */
298 err = mmc_sd_switch(card, 0, 0, 0, status);
295 if (err) { 299 if (err) {
296 /* 300 /*
297 * If the host or the card can't do the switch, 301 * If the host or the card can't do the switch,
@@ -312,46 +316,8 @@ static int mmc_read_switch(struct mmc_card *card)
312 316
313 if (card->scr.sda_spec3) { 317 if (card->scr.sda_spec3) {
314 card->sw_caps.sd3_bus_mode = status[13]; 318 card->sw_caps.sd3_bus_mode = status[13];
315 319 /* Driver Strengths supported by the card */
316 /* Find out Driver Strengths supported by the card */
317 err = mmc_sd_switch(card, 0, 2, 1, status);
318 if (err) {
319 /*
320 * If the host or the card can't do the switch,
321 * fail more gracefully.
322 */
323 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
324 goto out;
325
326 pr_warning("%s: problem reading "
327 "Driver Strength.\n",
328 mmc_hostname(card->host));
329 err = 0;
330
331 goto out;
332 }
333
334 card->sw_caps.sd3_drv_type = status[9]; 320 card->sw_caps.sd3_drv_type = status[9];
335
336 /* Find out Current Limits supported by the card */
337 err = mmc_sd_switch(card, 0, 3, 1, status);
338 if (err) {
339 /*
340 * If the host or the card can't do the switch,
341 * fail more gracefully.
342 */
343 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
344 goto out;
345
346 pr_warning("%s: problem reading "
347 "Current Limit.\n",
348 mmc_hostname(card->host));
349 err = 0;
350
351 goto out;
352 }
353
354 card->sw_caps.sd3_curr_limit = status[7];
355 } 321 }
356 322
357out: 323out:
@@ -551,60 +517,80 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
551 return 0; 517 return 0;
552} 518}
553 519
520/* Get host's max current setting at its current voltage */
521static u32 sd_get_host_max_current(struct mmc_host *host)
522{
523 u32 voltage, max_current;
524
525 voltage = 1 << host->ios.vdd;
526 switch (voltage) {
527 case MMC_VDD_165_195:
528 max_current = host->max_current_180;
529 break;
530 case MMC_VDD_29_30:
531 case MMC_VDD_30_31:
532 max_current = host->max_current_300;
533 break;
534 case MMC_VDD_32_33:
535 case MMC_VDD_33_34:
536 max_current = host->max_current_330;
537 break;
538 default:
539 max_current = 0;
540 }
541
542 return max_current;
543}
544
554static int sd_set_current_limit(struct mmc_card *card, u8 *status) 545static int sd_set_current_limit(struct mmc_card *card, u8 *status)
555{ 546{
556 int current_limit = 0; 547 int current_limit = SD_SET_CURRENT_NO_CHANGE;
557 int err; 548 int err;
549 u32 max_current;
558 550
559 /* 551 /*
560 * Current limit switch is only defined for SDR50, SDR104, and DDR50 552 * Current limit switch is only defined for SDR50, SDR104, and DDR50
561 * bus speed modes. For other bus speed modes, we set the default 553 * bus speed modes. For other bus speed modes, we do not change the
562 * current limit of 200mA. 554 * current limit.
563 */ 555 */
564 if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) || 556 if ((card->sd_bus_speed != UHS_SDR50_BUS_SPEED) &&
565 (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) || 557 (card->sd_bus_speed != UHS_SDR104_BUS_SPEED) &&
566 (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) { 558 (card->sd_bus_speed != UHS_DDR50_BUS_SPEED))
567 if (card->host->caps & MMC_CAP_MAX_CURRENT_800) { 559 return 0;
568 if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800) 560
569 current_limit = SD_SET_CURRENT_LIMIT_800; 561 /*
570 else if (card->sw_caps.sd3_curr_limit & 562 * Host has different current capabilities when operating at
571 SD_MAX_CURRENT_600) 563 * different voltages, so find out its max current first.
572 current_limit = SD_SET_CURRENT_LIMIT_600; 564 */
573 else if (card->sw_caps.sd3_curr_limit & 565 max_current = sd_get_host_max_current(card->host);
574 SD_MAX_CURRENT_400) 566
575 current_limit = SD_SET_CURRENT_LIMIT_400; 567 /*
576 else if (card->sw_caps.sd3_curr_limit & 568 * We only check host's capability here, if we set a limit that is
577 SD_MAX_CURRENT_200) 569 * higher than the card's maximum current, the card will be using its
578 current_limit = SD_SET_CURRENT_LIMIT_200; 570 * maximum current, e.g. if the card's maximum current is 300ma, and
579 } else if (card->host->caps & MMC_CAP_MAX_CURRENT_600) { 571 * when we set current limit to 200ma, the card will draw 200ma, and
580 if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600) 572 * when we set current limit to 400/600/800ma, the card will draw its
581 current_limit = SD_SET_CURRENT_LIMIT_600; 573 * maximum 300ma from the host.
582 else if (card->sw_caps.sd3_curr_limit & 574 */
583 SD_MAX_CURRENT_400) 575 if (max_current >= 800)
584 current_limit = SD_SET_CURRENT_LIMIT_400; 576 current_limit = SD_SET_CURRENT_LIMIT_800;
585 else if (card->sw_caps.sd3_curr_limit & 577 else if (max_current >= 600)
586 SD_MAX_CURRENT_200) 578 current_limit = SD_SET_CURRENT_LIMIT_600;
587 current_limit = SD_SET_CURRENT_LIMIT_200; 579 else if (max_current >= 400)
588 } else if (card->host->caps & MMC_CAP_MAX_CURRENT_400) { 580 current_limit = SD_SET_CURRENT_LIMIT_400;
589 if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400) 581 else if (max_current >= 200)
590 current_limit = SD_SET_CURRENT_LIMIT_400;
591 else if (card->sw_caps.sd3_curr_limit &
592 SD_MAX_CURRENT_200)
593 current_limit = SD_SET_CURRENT_LIMIT_200;
594 } else if (card->host->caps & MMC_CAP_MAX_CURRENT_200) {
595 if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200)
596 current_limit = SD_SET_CURRENT_LIMIT_200;
597 }
598 } else
599 current_limit = SD_SET_CURRENT_LIMIT_200; 582 current_limit = SD_SET_CURRENT_LIMIT_200;
600 583
601 err = mmc_sd_switch(card, 1, 3, current_limit, status); 584 if (current_limit != SD_SET_CURRENT_NO_CHANGE) {
602 if (err) 585 err = mmc_sd_switch(card, 1, 3, current_limit, status);
603 return err; 586 if (err)
587 return err;
604 588
605 if (((status[15] >> 4) & 0x0F) != current_limit) 589 if (((status[15] >> 4) & 0x0F) != current_limit)
606 pr_warning("%s: Problem setting current limit!\n", 590 pr_warning("%s: Problem setting current limit!\n",
607 mmc_hostname(card->host)); 591 mmc_hostname(card->host));
592
593 }
608 594
609 return 0; 595 return 0;
610} 596}
@@ -726,6 +712,7 @@ struct device_type sd_type = {
726int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) 712int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
727{ 713{
728 int err; 714 int err;
715 u32 max_current;
729 716
730 /* 717 /*
731 * Since we're changing the OCR value, we seem to 718 * Since we're changing the OCR value, we seem to
@@ -753,9 +740,12 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
753 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50)) 740 MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR104 | MMC_CAP_UHS_DDR50))
754 ocr |= SD_OCR_S18R; 741 ocr |= SD_OCR_S18R;
755 742
756 /* If the host can supply more than 150mA, XPC should be set to 1. */ 743 /*
757 if (host->caps & (MMC_CAP_SET_XPC_330 | MMC_CAP_SET_XPC_300 | 744 * If the host can supply more than 150mA at current voltage,
758 MMC_CAP_SET_XPC_180)) 745 * XPC should be set to 1.
746 */
747 max_current = sd_get_host_max_current(host);
748 if (max_current > 150)
759 ocr |= SD_OCR_XPC; 749 ocr |= SD_OCR_XPC;
760 750
761try_again: 751try_again:
@@ -911,9 +901,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
911 BUG_ON(!host); 901 BUG_ON(!host);
912 WARN_ON(!host->claimed); 902 WARN_ON(!host->claimed);
913 903
914 /* The initialization should be done at 3.3 V I/O voltage. */
915 mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);
916
917 err = mmc_sd_get_cid(host, ocr, cid, &rocr); 904 err = mmc_sd_get_cid(host, ocr, cid, &rocr);
918 if (err) 905 if (err)
919 return err; 906 return err;
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 41c5fd8848f4..d4619e2ec030 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -591,9 +591,6 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
591 * Inform the card of the voltage 591 * Inform the card of the voltage
592 */ 592 */
593 if (!powered_resume) { 593 if (!powered_resume) {
594 /* The initialization should be done at 3.3 V I/O voltage. */
595 mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);
596
597 err = mmc_send_io_op_cond(host, host->ocr, &ocr); 594 err = mmc_send_io_op_cond(host, host->ocr, &ocr);
598 if (err) 595 if (err)
599 goto err; 596 goto err;
@@ -1006,10 +1003,6 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
1006 * restore the correct voltage setting of the card. 1003 * restore the correct voltage setting of the card.
1007 */ 1004 */
1008 1005
1009 /* The initialization should be done at 3.3 V I/O voltage. */
1010 if (!mmc_card_keep_power(host))
1011 mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330, 0);
1012
1013 sdio_reset(host); 1006 sdio_reset(host);
1014 mmc_go_idle(host); 1007 mmc_go_idle(host);
1015 mmc_send_if_cond(host, host->ocr_avail); 1008 mmc_send_if_cond(host, host->ocr_avail);
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
index f1c7ed8f4d85..8e94e555b788 100644
--- a/drivers/mmc/core/sdio_cis.c
+++ b/drivers/mmc/core/sdio_cis.c
@@ -313,7 +313,7 @@ static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
313 313
314 if (ret == -ENOENT) { 314 if (ret == -ENOENT) {
315 /* warn about unknown tuples */ 315 /* warn about unknown tuples */
316 pr_warning("%s: queuing unknown" 316 pr_warn_ratelimited("%s: queuing unknown"
317 " CIS tuple 0x%02x (%u bytes)\n", 317 " CIS tuple 0x%02x (%u bytes)\n",
318 mmc_hostname(card->host), 318 mmc_hostname(card->host),
319 tpl_code, tpl_link); 319 tpl_code, tpl_link);
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
new file mode 100644
index 000000000000..058242916cef
--- /dev/null
+++ b/drivers/mmc/core/slot-gpio.c
@@ -0,0 +1,188 @@
1/*
2 * Generic GPIO card-detect helper
3 *
4 * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/err.h>
12#include <linux/gpio.h>
13#include <linux/interrupt.h>
14#include <linux/jiffies.h>
15#include <linux/mmc/host.h>
16#include <linux/mmc/slot-gpio.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19
20struct mmc_gpio {
21 int ro_gpio;
22 int cd_gpio;
23 char *ro_label;
24 char cd_label[0];
25};
26
27static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
28{
29 /* Schedule a card detection after a debounce timeout */
30 mmc_detect_change(dev_id, msecs_to_jiffies(100));
31 return IRQ_HANDLED;
32}
33
34static int mmc_gpio_alloc(struct mmc_host *host)
35{
36 size_t len = strlen(dev_name(host->parent)) + 4;
37 struct mmc_gpio *ctx;
38
39 mutex_lock(&host->slot.lock);
40
41 ctx = host->slot.handler_priv;
42 if (!ctx) {
43 /*
44 * devm_kzalloc() can be called after device_initialize(), even
45 * before device_add(), i.e., between mmc_alloc_host() and
46 * mmc_add_host()
47 */
48 ctx = devm_kzalloc(&host->class_dev, sizeof(*ctx) + 2 * len,
49 GFP_KERNEL);
50 if (ctx) {
51 ctx->ro_label = ctx->cd_label + len;
52 snprintf(ctx->cd_label, len, "%s cd", dev_name(host->parent));
53 snprintf(ctx->ro_label, len, "%s ro", dev_name(host->parent));
54 ctx->cd_gpio = -EINVAL;
55 ctx->ro_gpio = -EINVAL;
56 host->slot.handler_priv = ctx;
57 }
58 }
59
60 mutex_unlock(&host->slot.lock);
61
62 return ctx ? 0 : -ENOMEM;
63}
64
65int mmc_gpio_get_ro(struct mmc_host *host)
66{
67 struct mmc_gpio *ctx = host->slot.handler_priv;
68
69 if (!ctx || !gpio_is_valid(ctx->ro_gpio))
70 return -ENOSYS;
71
72 return !gpio_get_value_cansleep(ctx->ro_gpio) ^
73 !!(host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH);
74}
75EXPORT_SYMBOL(mmc_gpio_get_ro);
76
77int mmc_gpio_get_cd(struct mmc_host *host)
78{
79 struct mmc_gpio *ctx = host->slot.handler_priv;
80
81 if (!ctx || !gpio_is_valid(ctx->cd_gpio))
82 return -ENOSYS;
83
84 return !gpio_get_value_cansleep(ctx->cd_gpio) ^
85 !!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH);
86}
87EXPORT_SYMBOL(mmc_gpio_get_cd);
88
89int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio)
90{
91 struct mmc_gpio *ctx;
92 int ret;
93
94 if (!gpio_is_valid(gpio))
95 return -EINVAL;
96
97 ret = mmc_gpio_alloc(host);
98 if (ret < 0)
99 return ret;
100
101 ctx = host->slot.handler_priv;
102
103 return gpio_request_one(gpio, GPIOF_DIR_IN, ctx->ro_label);
104}
105EXPORT_SYMBOL(mmc_gpio_request_ro);
106
107int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio)
108{
109 struct mmc_gpio *ctx;
110 int irq = gpio_to_irq(gpio);
111 int ret;
112
113 ret = mmc_gpio_alloc(host);
114 if (ret < 0)
115 return ret;
116
117 ctx = host->slot.handler_priv;
118
119 ret = gpio_request_one(gpio, GPIOF_DIR_IN, ctx->cd_label);
120 if (ret < 0)
121 /*
122 * don't bother freeing memory. It might still get used by other
123 * slot functions, in any case it will be freed, when the device
124 * is destroyed.
125 */
126 return ret;
127
128 /*
129 * Even if gpio_to_irq() returns a valid IRQ number, the platform might
130 * still prefer to poll, e.g., because that IRQ number is already used
131 * by another unit and cannot be shared.
132 */
133 if (irq >= 0 && host->caps & MMC_CAP_NEEDS_POLL)
134 irq = -EINVAL;
135
136 if (irq >= 0) {
137 ret = request_threaded_irq(irq, NULL, mmc_gpio_cd_irqt,
138 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
139 ctx->cd_label, host);
140 if (ret < 0)
141 irq = ret;
142 }
143
144 host->slot.cd_irq = irq;
145
146 if (irq < 0)
147 host->caps |= MMC_CAP_NEEDS_POLL;
148
149 ctx->cd_gpio = gpio;
150
151 return 0;
152}
153EXPORT_SYMBOL(mmc_gpio_request_cd);
154
155void mmc_gpio_free_ro(struct mmc_host *host)
156{
157 struct mmc_gpio *ctx = host->slot.handler_priv;
158 int gpio;
159
160 if (!ctx || !gpio_is_valid(ctx->ro_gpio))
161 return;
162
163 gpio = ctx->ro_gpio;
164 ctx->ro_gpio = -EINVAL;
165
166 gpio_free(gpio);
167}
168EXPORT_SYMBOL(mmc_gpio_free_ro);
169
170void mmc_gpio_free_cd(struct mmc_host *host)
171{
172 struct mmc_gpio *ctx = host->slot.handler_priv;
173 int gpio;
174
175 if (!ctx || !gpio_is_valid(ctx->cd_gpio))
176 return;
177
178 if (host->slot.cd_irq >= 0) {
179 free_irq(host->slot.cd_irq, host);
180 host->slot.cd_irq = -EINVAL;
181 }
182
183 gpio = ctx->cd_gpio;
184 ctx->cd_gpio = -EINVAL;
185
186 gpio_free(gpio);
187}
188EXPORT_SYMBOL(mmc_gpio_free_cd);
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index f2c115e06438..322412cec4ee 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -391,11 +391,17 @@ static int atmci_regs_show(struct seq_file *s, void *v)
391 clk_disable(host->mck); 391 clk_disable(host->mck);
392 spin_unlock_bh(&host->lock); 392 spin_unlock_bh(&host->lock);
393 393
394 seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u\n", 394 seq_printf(s, "MR:\t0x%08x%s%s ",
395 buf[ATMCI_MR / 4], 395 buf[ATMCI_MR / 4],
396 buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "", 396 buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "",
397 buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "", 397 buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "");
398 buf[ATMCI_MR / 4] & 0xff); 398 if (host->caps.has_odd_clk_div)
399 seq_printf(s, "{CLKDIV,CLKODD}=%u\n",
400 ((buf[ATMCI_MR / 4] & 0xff) << 1)
401 | ((buf[ATMCI_MR / 4] >> 16) & 1));
402 else
403 seq_printf(s, "CLKDIV=%u\n",
404 (buf[ATMCI_MR / 4] & 0xff));
399 seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]); 405 seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]);
400 seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]); 406 seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]);
401 seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]); 407 seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]);
@@ -1685,7 +1691,6 @@ static void atmci_tasklet_func(unsigned long priv)
1685 1691
1686 dev_dbg(&host->pdev->dev, "FSM: cmd ready\n"); 1692 dev_dbg(&host->pdev->dev, "FSM: cmd ready\n");
1687 host->cmd = NULL; 1693 host->cmd = NULL;
1688 host->data = NULL;
1689 data->bytes_xfered = data->blocks * data->blksz; 1694 data->bytes_xfered = data->blocks * data->blksz;
1690 data->error = 0; 1695 data->error = 0;
1691 atmci_command_complete(host, mrq->stop); 1696 atmci_command_complete(host, mrq->stop);
@@ -1699,6 +1704,7 @@ static void atmci_tasklet_func(unsigned long priv)
1699 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY); 1704 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
1700 state = STATE_WAITING_NOTBUSY; 1705 state = STATE_WAITING_NOTBUSY;
1701 } 1706 }
1707 host->data = NULL;
1702 break; 1708 break;
1703 1709
1704 case STATE_END_REQUEST: 1710 case STATE_END_REQUEST:
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 1ca5e72ceb65..72dc3cde646d 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -405,11 +405,23 @@ static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
405static int dw_mci_idmac_init(struct dw_mci *host) 405static int dw_mci_idmac_init(struct dw_mci *host)
406{ 406{
407 struct idmac_desc *p; 407 struct idmac_desc *p;
408 int i; 408 int i, dma_support;
409 409
410 /* Number of descriptors in the ring buffer */ 410 /* Number of descriptors in the ring buffer */
411 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); 411 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
412 412
413 /* Check if Hardware Configuration Register has support for DMA */
414 dma_support = (mci_readl(host, HCON) >> 16) & 0x3;
415
416 if (!dma_support || dma_support > 2) {
417 dev_err(&host->dev,
418 "Host Controller does not support IDMA Tx.\n");
419 host->dma_ops = NULL;
420 return -ENODEV;
421 }
422
423 dev_info(&host->dev, "Using internal DMA controller.\n");
424
413 /* Forward link the descriptor list */ 425 /* Forward link the descriptor list */
414 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) 426 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
415 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1)); 427 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1));
@@ -1876,7 +1888,6 @@ static void dw_mci_init_dma(struct dw_mci *host)
1876 /* Determine which DMA interface to use */ 1888 /* Determine which DMA interface to use */
1877#ifdef CONFIG_MMC_DW_IDMAC 1889#ifdef CONFIG_MMC_DW_IDMAC
1878 host->dma_ops = &dw_mci_idmac_ops; 1890 host->dma_ops = &dw_mci_idmac_ops;
1879 dev_info(&host->dev, "Using internal DMA controller.\n");
1880#endif 1891#endif
1881 1892
1882 if (!host->dma_ops) 1893 if (!host->dma_ops)
@@ -2175,7 +2186,7 @@ int dw_mci_resume(struct dw_mci *host)
2175 return ret; 2186 return ret;
2176 } 2187 }
2177 2188
2178 if (host->dma_ops->init) 2189 if (host->use_dma && host->dma_ops->init)
2179 host->dma_ops->init(host); 2190 host->dma_ops->init(host);
2180 2191
2181 /* Restore the old value at FIFOTH register */ 2192 /* Restore the old value at FIFOTH register */
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index 277161d279b8..a51f9309ffbb 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -164,16 +164,23 @@ struct mxs_mmc_host {
164 spinlock_t lock; 164 spinlock_t lock;
165 int sdio_irq_en; 165 int sdio_irq_en;
166 int wp_gpio; 166 int wp_gpio;
167 bool wp_inverted;
167}; 168};
168 169
169static int mxs_mmc_get_ro(struct mmc_host *mmc) 170static int mxs_mmc_get_ro(struct mmc_host *mmc)
170{ 171{
171 struct mxs_mmc_host *host = mmc_priv(mmc); 172 struct mxs_mmc_host *host = mmc_priv(mmc);
173 int ret;
172 174
173 if (!gpio_is_valid(host->wp_gpio)) 175 if (!gpio_is_valid(host->wp_gpio))
174 return -EINVAL; 176 return -EINVAL;
175 177
176 return gpio_get_value(host->wp_gpio); 178 ret = gpio_get_value(host->wp_gpio);
179
180 if (host->wp_inverted)
181 ret = !ret;
182
183 return ret;
177} 184}
178 185
179static int mxs_mmc_get_cd(struct mmc_host *mmc) 186static int mxs_mmc_get_cd(struct mmc_host *mmc)
@@ -707,6 +714,8 @@ static int mxs_mmc_probe(struct platform_device *pdev)
707 struct pinctrl *pinctrl; 714 struct pinctrl *pinctrl;
708 int ret = 0, irq_err, irq_dma; 715 int ret = 0, irq_err, irq_dma;
709 dma_cap_mask_t mask; 716 dma_cap_mask_t mask;
717 struct regulator *reg_vmmc;
718 enum of_gpio_flags flags;
710 719
711 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 720 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
712 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); 721 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
@@ -747,6 +756,16 @@ static int mxs_mmc_probe(struct platform_device *pdev)
747 host->mmc = mmc; 756 host->mmc = mmc;
748 host->sdio_irq_en = 0; 757 host->sdio_irq_en = 0;
749 758
759 reg_vmmc = devm_regulator_get(&pdev->dev, "vmmc");
760 if (!IS_ERR(reg_vmmc)) {
761 ret = regulator_enable(reg_vmmc);
762 if (ret) {
763 dev_err(&pdev->dev,
764 "Failed to enable vmmc regulator: %d\n", ret);
765 goto out_mmc_free;
766 }
767 }
768
750 pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 769 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
751 if (IS_ERR(pinctrl)) { 770 if (IS_ERR(pinctrl)) {
752 ret = PTR_ERR(pinctrl); 771 ret = PTR_ERR(pinctrl);
@@ -785,7 +804,10 @@ static int mxs_mmc_probe(struct platform_device *pdev)
785 mmc->caps |= MMC_CAP_4_BIT_DATA; 804 mmc->caps |= MMC_CAP_4_BIT_DATA;
786 else if (bus_width == 8) 805 else if (bus_width == 8)
787 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; 806 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA;
788 host->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0); 807 host->wp_gpio = of_get_named_gpio_flags(np, "wp-gpios", 0,
808 &flags);
809 if (flags & OF_GPIO_ACTIVE_LOW)
810 host->wp_inverted = 1;
789 } else { 811 } else {
790 if (pdata->flags & SLOTF_8_BIT_CAPABLE) 812 if (pdata->flags & SLOTF_8_BIT_CAPABLE)
791 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA; 813 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA;
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 389a3eedfc24..bc28627af66b 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -1089,7 +1089,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
1089 /* Disable the clocks */ 1089 /* Disable the clocks */
1090 pm_runtime_put_sync(host->dev); 1090 pm_runtime_put_sync(host->dev);
1091 if (host->dbclk) 1091 if (host->dbclk)
1092 clk_disable(host->dbclk); 1092 clk_disable_unprepare(host->dbclk);
1093 1093
1094 /* Turn the power off */ 1094 /* Turn the power off */
1095 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); 1095 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0);
@@ -1100,7 +1100,7 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
1100 vdd); 1100 vdd);
1101 pm_runtime_get_sync(host->dev); 1101 pm_runtime_get_sync(host->dev);
1102 if (host->dbclk) 1102 if (host->dbclk)
1103 clk_enable(host->dbclk); 1103 clk_prepare_enable(host->dbclk);
1104 1104
1105 if (ret != 0) 1105 if (ret != 0)
1106 goto err; 1106 goto err;
@@ -1899,7 +1899,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1899 if (IS_ERR(host->dbclk)) { 1899 if (IS_ERR(host->dbclk)) {
1900 dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n"); 1900 dev_warn(mmc_dev(host->mmc), "Failed to get debounce clk\n");
1901 host->dbclk = NULL; 1901 host->dbclk = NULL;
1902 } else if (clk_enable(host->dbclk) != 0) { 1902 } else if (clk_prepare_enable(host->dbclk) != 0) {
1903 dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n"); 1903 dev_warn(mmc_dev(host->mmc), "Failed to enable debounce clk\n");
1904 clk_put(host->dbclk); 1904 clk_put(host->dbclk);
1905 host->dbclk = NULL; 1905 host->dbclk = NULL;
@@ -1931,6 +1931,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1931 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); 1931 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1932 if (!res) { 1932 if (!res) {
1933 dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n"); 1933 dev_err(mmc_dev(host->mmc), "cannot get DMA TX channel\n");
1934 ret = -ENXIO;
1934 goto err_irq; 1935 goto err_irq;
1935 } 1936 }
1936 host->dma_line_tx = res->start; 1937 host->dma_line_tx = res->start;
@@ -1938,6 +1939,7 @@ static int __devinit omap_hsmmc_probe(struct platform_device *pdev)
1938 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); 1939 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1939 if (!res) { 1940 if (!res) {
1940 dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n"); 1941 dev_err(mmc_dev(host->mmc), "cannot get DMA RX channel\n");
1942 ret = -ENXIO;
1941 goto err_irq; 1943 goto err_irq;
1942 } 1944 }
1943 host->dma_line_rx = res->start; 1945 host->dma_line_rx = res->start;
@@ -2023,7 +2025,7 @@ err_irq:
2023 pm_runtime_disable(host->dev); 2025 pm_runtime_disable(host->dev);
2024 clk_put(host->fclk); 2026 clk_put(host->fclk);
2025 if (host->dbclk) { 2027 if (host->dbclk) {
2026 clk_disable(host->dbclk); 2028 clk_disable_unprepare(host->dbclk);
2027 clk_put(host->dbclk); 2029 clk_put(host->dbclk);
2028 } 2030 }
2029err1: 2031err1:
@@ -2058,7 +2060,7 @@ static int __devexit omap_hsmmc_remove(struct platform_device *pdev)
2058 pm_runtime_disable(host->dev); 2060 pm_runtime_disable(host->dev);
2059 clk_put(host->fclk); 2061 clk_put(host->fclk);
2060 if (host->dbclk) { 2062 if (host->dbclk) {
2061 clk_disable(host->dbclk); 2063 clk_disable_unprepare(host->dbclk);
2062 clk_put(host->dbclk); 2064 clk_put(host->dbclk);
2063 } 2065 }
2064 2066
@@ -2116,7 +2118,7 @@ static int omap_hsmmc_suspend(struct device *dev)
2116 } 2118 }
2117 2119
2118 if (host->dbclk) 2120 if (host->dbclk)
2119 clk_disable(host->dbclk); 2121 clk_disable_unprepare(host->dbclk);
2120err: 2122err:
2121 pm_runtime_put_sync(host->dev); 2123 pm_runtime_put_sync(host->dev);
2122 return ret; 2124 return ret;
@@ -2137,7 +2139,7 @@ static int omap_hsmmc_resume(struct device *dev)
2137 pm_runtime_get_sync(host->dev); 2139 pm_runtime_get_sync(host->dev);
2138 2140
2139 if (host->dbclk) 2141 if (host->dbclk)
2140 clk_enable(host->dbclk); 2142 clk_prepare_enable(host->dbclk);
2141 2143
2142 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER)) 2144 if (!(host->mmc->pm_flags & MMC_PM_KEEP_POWER))
2143 omap_hsmmc_conf_bus_power(host); 2145 omap_hsmmc_conf_bus_power(host);
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index c3622a69f432..bd5a5cce122c 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -26,7 +26,6 @@
26#include <mach/dma.h> 26#include <mach/dma.h>
27 27
28#include <mach/regs-sdi.h> 28#include <mach/regs-sdi.h>
29#include <mach/regs-gpio.h>
30 29
31#include <plat/mci.h> 30#include <plat/mci.h>
32 31
@@ -1237,12 +1236,9 @@ static void s3cmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1237 switch (ios->power_mode) { 1236 switch (ios->power_mode) {
1238 case MMC_POWER_ON: 1237 case MMC_POWER_ON:
1239 case MMC_POWER_UP: 1238 case MMC_POWER_UP:
1240 s3c2410_gpio_cfgpin(S3C2410_GPE(5), S3C2410_GPE5_SDCLK); 1239 /* Configure GPE5...GPE10 pins in SD mode */
1241 s3c2410_gpio_cfgpin(S3C2410_GPE(6), S3C2410_GPE6_SDCMD); 1240 s3c_gpio_cfgall_range(S3C2410_GPE(5), 6, S3C_GPIO_SFN(2),
1242 s3c2410_gpio_cfgpin(S3C2410_GPE(7), S3C2410_GPE7_SDDAT0); 1241 S3C_GPIO_PULL_NONE);
1243 s3c2410_gpio_cfgpin(S3C2410_GPE(8), S3C2410_GPE8_SDDAT1);
1244 s3c2410_gpio_cfgpin(S3C2410_GPE(9), S3C2410_GPE9_SDDAT2);
1245 s3c2410_gpio_cfgpin(S3C2410_GPE(10), S3C2410_GPE10_SDDAT3);
1246 1242
1247 if (host->pdata->set_power) 1243 if (host->pdata->set_power)
1248 host->pdata->set_power(ios->power_mode, ios->vdd); 1244 host->pdata->set_power(ios->power_mode, ios->vdd);
diff --git a/drivers/mmc/host/sdhci-dove.c b/drivers/mmc/host/sdhci-dove.c
index 177f697b5835..a6e53a1ebb08 100644
--- a/drivers/mmc/host/sdhci-dove.c
+++ b/drivers/mmc/host/sdhci-dove.c
@@ -20,11 +20,17 @@
20 */ 20 */
21 21
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/clk.h>
24#include <linux/err.h>
23#include <linux/module.h> 25#include <linux/module.h>
24#include <linux/mmc/host.h> 26#include <linux/mmc/host.h>
25 27
26#include "sdhci-pltfm.h" 28#include "sdhci-pltfm.h"
27 29
30struct sdhci_dove_priv {
31 struct clk *clk;
32};
33
28static u16 sdhci_dove_readw(struct sdhci_host *host, int reg) 34static u16 sdhci_dove_readw(struct sdhci_host *host, int reg)
29{ 35{
30 u16 ret; 36 u16 ret;
@@ -66,16 +72,57 @@ static struct sdhci_pltfm_data sdhci_dove_pdata = {
66 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | 72 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
67 SDHCI_QUIRK_NO_BUSY_IRQ | 73 SDHCI_QUIRK_NO_BUSY_IRQ |
68 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL | 74 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
69 SDHCI_QUIRK_FORCE_DMA, 75 SDHCI_QUIRK_FORCE_DMA |
76 SDHCI_QUIRK_NO_HISPD_BIT,
70}; 77};
71 78
72static int __devinit sdhci_dove_probe(struct platform_device *pdev) 79static int __devinit sdhci_dove_probe(struct platform_device *pdev)
73{ 80{
74 return sdhci_pltfm_register(pdev, &sdhci_dove_pdata); 81 struct sdhci_host *host;
82 struct sdhci_pltfm_host *pltfm_host;
83 struct sdhci_dove_priv *priv;
84 int ret;
85
86 ret = sdhci_pltfm_register(pdev, &sdhci_dove_pdata);
87 if (ret)
88 goto sdhci_dove_register_fail;
89
90 priv = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_dove_priv),
91 GFP_KERNEL);
92 if (!priv) {
93 dev_err(&pdev->dev, "unable to allocate private data");
94 ret = -ENOMEM;
95 goto sdhci_dove_allocate_fail;
96 }
97
98 host = platform_get_drvdata(pdev);
99 pltfm_host = sdhci_priv(host);
100 pltfm_host->priv = priv;
101
102 priv->clk = clk_get(&pdev->dev, NULL);
103 if (!IS_ERR(priv->clk))
104 clk_prepare_enable(priv->clk);
105 return 0;
106
107sdhci_dove_allocate_fail:
108 sdhci_pltfm_unregister(pdev);
109sdhci_dove_register_fail:
110 return ret;
75} 111}
76 112
77static int __devexit sdhci_dove_remove(struct platform_device *pdev) 113static int __devexit sdhci_dove_remove(struct platform_device *pdev)
78{ 114{
115 struct sdhci_host *host = platform_get_drvdata(pdev);
116 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
117 struct sdhci_dove_priv *priv = pltfm_host->priv;
118
119 if (priv->clk) {
120 if (!IS_ERR(priv->clk)) {
121 clk_disable_unprepare(priv->clk);
122 clk_put(priv->clk);
123 }
124 devm_kfree(&pdev->dev, priv->clk);
125 }
79 return sdhci_pltfm_unregister(pdev); 126 return sdhci_pltfm_unregister(pdev);
80} 127}
81 128
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index ebbe984e5d00..e23f8134591c 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -299,6 +299,8 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
299 299
300static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg) 300static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
301{ 301{
302 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
303 struct pltfm_imx_data *imx_data = pltfm_host->priv;
302 u32 new_val; 304 u32 new_val;
303 305
304 switch (reg) { 306 switch (reg) {
@@ -315,8 +317,11 @@ static void esdhc_writeb_le(struct sdhci_host *host, u8 val, int reg)
315 SDHCI_CTRL_D3CD); 317 SDHCI_CTRL_D3CD);
316 /* ensure the endianess */ 318 /* ensure the endianess */
317 new_val |= ESDHC_HOST_CONTROL_LE; 319 new_val |= ESDHC_HOST_CONTROL_LE;
318 /* DMA mode bits are shifted */ 320 /* bits 8&9 are reserved on mx25 */
319 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5; 321 if (!is_imx25_esdhc(imx_data)) {
322 /* DMA mode bits are shifted */
323 new_val |= (val & SDHCI_CTRL_DMA_MASK) << 5;
324 }
320 325
321 esdhc_clrset_le(host, 0xffff, new_val, reg); 326 esdhc_clrset_le(host, 0xffff, new_val, reg);
322 return; 327 return;
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 69ef0beae104..504da715a41a 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -157,6 +157,7 @@ static const struct sdhci_pci_fixes sdhci_ene_714 = {
157static const struct sdhci_pci_fixes sdhci_cafe = { 157static const struct sdhci_pci_fixes sdhci_cafe = {
158 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER | 158 .quirks = SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER |
159 SDHCI_QUIRK_NO_BUSY_IRQ | 159 SDHCI_QUIRK_NO_BUSY_IRQ |
160 SDHCI_QUIRK_BROKEN_CARD_DETECTION |
160 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL, 161 SDHCI_QUIRK_BROKEN_TIMEOUT_VAL,
161}; 162};
162 163
diff --git a/drivers/mmc/host/sdhci-pxav2.c b/drivers/mmc/host/sdhci-pxav2.c
index dbb75bfbcffb..b6ee8857e226 100644
--- a/drivers/mmc/host/sdhci-pxav2.c
+++ b/drivers/mmc/host/sdhci-pxav2.c
@@ -28,6 +28,9 @@
28#include <linux/mmc/host.h> 28#include <linux/mmc/host.h>
29#include <linux/platform_data/pxa_sdhci.h> 29#include <linux/platform_data/pxa_sdhci.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/of.h>
32#include <linux/of_device.h>
33
31#include "sdhci.h" 34#include "sdhci.h"
32#include "sdhci-pltfm.h" 35#include "sdhci-pltfm.h"
33 36
@@ -121,6 +124,48 @@ static struct sdhci_ops pxav2_sdhci_ops = {
121 .platform_8bit_width = pxav2_mmc_set_width, 124 .platform_8bit_width = pxav2_mmc_set_width,
122}; 125};
123 126
127#ifdef CONFIG_OF
128static const struct of_device_id sdhci_pxav2_of_match[] = {
129 {
130 .compatible = "mrvl,pxav2-mmc",
131 },
132 {},
133};
134MODULE_DEVICE_TABLE(of, sdhci_pxav2_of_match);
135
136static struct sdhci_pxa_platdata *pxav2_get_mmc_pdata(struct device *dev)
137{
138 struct sdhci_pxa_platdata *pdata;
139 struct device_node *np = dev->of_node;
140 u32 bus_width;
141 u32 clk_delay_cycles;
142
143 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
144 if (!pdata)
145 return NULL;
146
147 if (of_find_property(np, "non-removable", NULL))
148 pdata->flags |= PXA_FLAG_CARD_PERMANENT;
149
150 of_property_read_u32(np, "bus-width", &bus_width);
151 if (bus_width == 8)
152 pdata->flags |= PXA_FLAG_SD_8_BIT_CAPABLE_SLOT;
153
154 of_property_read_u32(np, "mrvl,clk-delay-cycles", &clk_delay_cycles);
155 if (clk_delay_cycles > 0) {
156 pdata->clk_delay_sel = 1;
157 pdata->clk_delay_cycles = clk_delay_cycles;
158 }
159
160 return pdata;
161}
162#else
163static inline struct sdhci_pxa_platdata *pxav2_get_mmc_pdata(struct device *dev)
164{
165 return NULL;
166}
167#endif
168
124static int __devinit sdhci_pxav2_probe(struct platform_device *pdev) 169static int __devinit sdhci_pxav2_probe(struct platform_device *pdev)
125{ 170{
126 struct sdhci_pltfm_host *pltfm_host; 171 struct sdhci_pltfm_host *pltfm_host;
@@ -128,6 +173,8 @@ static int __devinit sdhci_pxav2_probe(struct platform_device *pdev)
128 struct device *dev = &pdev->dev; 173 struct device *dev = &pdev->dev;
129 struct sdhci_host *host = NULL; 174 struct sdhci_host *host = NULL;
130 struct sdhci_pxa *pxa = NULL; 175 struct sdhci_pxa *pxa = NULL;
176 const struct of_device_id *match;
177
131 int ret; 178 int ret;
132 struct clk *clk; 179 struct clk *clk;
133 180
@@ -156,6 +203,10 @@ static int __devinit sdhci_pxav2_probe(struct platform_device *pdev)
156 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL 203 | SDHCI_QUIRK_BROKEN_TIMEOUT_VAL
157 | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN; 204 | SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN;
158 205
206 match = of_match_device(of_match_ptr(sdhci_pxav2_of_match), &pdev->dev);
207 if (match) {
208 pdata = pxav2_get_mmc_pdata(dev);
209 }
159 if (pdata) { 210 if (pdata) {
160 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { 211 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) {
161 /* on-chip device */ 212 /* on-chip device */
@@ -218,6 +269,9 @@ static struct platform_driver sdhci_pxav2_driver = {
218 .driver = { 269 .driver = {
219 .name = "sdhci-pxav2", 270 .name = "sdhci-pxav2",
220 .owner = THIS_MODULE, 271 .owner = THIS_MODULE,
272#ifdef CONFIG_OF
273 .of_match_table = sdhci_pxav2_of_match,
274#endif
221 .pm = SDHCI_PLTFM_PMOPS, 275 .pm = SDHCI_PLTFM_PMOPS,
222 }, 276 },
223 .probe = sdhci_pxav2_probe, 277 .probe = sdhci_pxav2_probe,
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index f29695683556..07fe3834fe0b 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -28,6 +28,9 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/of.h>
32#include <linux/of_device.h>
33
31#include "sdhci.h" 34#include "sdhci.h"
32#include "sdhci-pltfm.h" 35#include "sdhci-pltfm.h"
33 36
@@ -164,6 +167,46 @@ static struct sdhci_ops pxav3_sdhci_ops = {
164 .platform_send_init_74_clocks = pxav3_gen_init_74_clocks, 167 .platform_send_init_74_clocks = pxav3_gen_init_74_clocks,
165}; 168};
166 169
170#ifdef CONFIG_OF
171static const struct of_device_id sdhci_pxav3_of_match[] = {
172 {
173 .compatible = "mrvl,pxav3-mmc",
174 },
175 {},
176};
177MODULE_DEVICE_TABLE(of, sdhci_pxav3_of_match);
178
179static struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
180{
181 struct sdhci_pxa_platdata *pdata;
182 struct device_node *np = dev->of_node;
183 u32 bus_width;
184 u32 clk_delay_cycles;
185
186 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
187 if (!pdata)
188 return NULL;
189
190 if (of_find_property(np, "non-removable", NULL))
191 pdata->flags |= PXA_FLAG_CARD_PERMANENT;
192
193 of_property_read_u32(np, "bus-width", &bus_width);
194 if (bus_width == 8)
195 pdata->flags |= PXA_FLAG_SD_8_BIT_CAPABLE_SLOT;
196
197 of_property_read_u32(np, "mrvl,clk-delay-cycles", &clk_delay_cycles);
198 if (clk_delay_cycles > 0)
199 pdata->clk_delay_cycles = clk_delay_cycles;
200
201 return pdata;
202}
203#else
204static inline struct sdhci_pxa_platdata *pxav3_get_mmc_pdata(struct device *dev)
205{
206 return NULL;
207}
208#endif
209
167static int __devinit sdhci_pxav3_probe(struct platform_device *pdev) 210static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
168{ 211{
169 struct sdhci_pltfm_host *pltfm_host; 212 struct sdhci_pltfm_host *pltfm_host;
@@ -171,6 +214,8 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
171 struct device *dev = &pdev->dev; 214 struct device *dev = &pdev->dev;
172 struct sdhci_host *host = NULL; 215 struct sdhci_host *host = NULL;
173 struct sdhci_pxa *pxa = NULL; 216 struct sdhci_pxa *pxa = NULL;
217 const struct of_device_id *match;
218
174 int ret; 219 int ret;
175 struct clk *clk; 220 struct clk *clk;
176 221
@@ -202,6 +247,10 @@ static int __devinit sdhci_pxav3_probe(struct platform_device *pdev)
202 /* enable 1/8V DDR capable */ 247 /* enable 1/8V DDR capable */
203 host->mmc->caps |= MMC_CAP_1_8V_DDR; 248 host->mmc->caps |= MMC_CAP_1_8V_DDR;
204 249
250 match = of_match_device(of_match_ptr(sdhci_pxav3_of_match), &pdev->dev);
251 if (match)
252 pdata = pxav3_get_mmc_pdata(dev);
253
205 if (pdata) { 254 if (pdata) {
206 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) { 255 if (pdata->flags & PXA_FLAG_CARD_PERMANENT) {
207 /* on-chip device */ 256 /* on-chip device */
@@ -263,6 +312,9 @@ static int __devexit sdhci_pxav3_remove(struct platform_device *pdev)
263static struct platform_driver sdhci_pxav3_driver = { 312static struct platform_driver sdhci_pxav3_driver = {
264 .driver = { 313 .driver = {
265 .name = "sdhci-pxav3", 314 .name = "sdhci-pxav3",
315#ifdef CONFIG_OF
316 .of_match_table = sdhci_pxav3_of_match,
317#endif
266 .owner = THIS_MODULE, 318 .owner = THIS_MODULE,
267 .pm = SDHCI_PLTFM_PMOPS, 319 .pm = SDHCI_PLTFM_PMOPS,
268 }, 320 },
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index f4b8b4db3a9a..9a11dc39921c 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -27,6 +27,7 @@
27 27
28#include <linux/mmc/mmc.h> 28#include <linux/mmc/mmc.h>
29#include <linux/mmc/host.h> 29#include <linux/mmc/host.h>
30#include <linux/mmc/card.h>
30 31
31#include "sdhci.h" 32#include "sdhci.h"
32 33
@@ -244,6 +245,19 @@ static void sdhci_init(struct sdhci_host *host, int soft)
244static void sdhci_reinit(struct sdhci_host *host) 245static void sdhci_reinit(struct sdhci_host *host)
245{ 246{
246 sdhci_init(host, 0); 247 sdhci_init(host, 0);
248 /*
249 * Retuning stuffs are affected by different cards inserted and only
250 * applicable to UHS-I cards. So reset these fields to their initial
251 * value when card is removed.
252 */
253 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
254 host->flags &= ~SDHCI_USING_RETUNING_TIMER;
255
256 del_timer_sync(&host->tuning_timer);
257 host->flags &= ~SDHCI_NEEDS_RETUNING;
258 host->mmc->max_blk_count =
259 (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535;
260 }
247 sdhci_enable_card_detection(host); 261 sdhci_enable_card_detection(host);
248} 262}
249 263
@@ -1245,6 +1259,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1245 struct sdhci_host *host; 1259 struct sdhci_host *host;
1246 bool present; 1260 bool present;
1247 unsigned long flags; 1261 unsigned long flags;
1262 u32 tuning_opcode;
1248 1263
1249 host = mmc_priv(mmc); 1264 host = mmc_priv(mmc);
1250 1265
@@ -1292,8 +1307,12 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1292 */ 1307 */
1293 if ((host->flags & SDHCI_NEEDS_RETUNING) && 1308 if ((host->flags & SDHCI_NEEDS_RETUNING) &&
1294 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) { 1309 !(present_state & (SDHCI_DOING_WRITE | SDHCI_DOING_READ))) {
1310 /* eMMC uses cmd21 while sd and sdio use cmd19 */
1311 tuning_opcode = mmc->card->type == MMC_TYPE_MMC ?
1312 MMC_SEND_TUNING_BLOCK_HS200 :
1313 MMC_SEND_TUNING_BLOCK;
1295 spin_unlock_irqrestore(&host->lock, flags); 1314 spin_unlock_irqrestore(&host->lock, flags);
1296 sdhci_execute_tuning(mmc, mrq->cmd->opcode); 1315 sdhci_execute_tuning(mmc, tuning_opcode);
1297 spin_lock_irqsave(&host->lock, flags); 1316 spin_lock_irqsave(&host->lock, flags);
1298 1317
1299 /* Restore original mmc_request structure */ 1318 /* Restore original mmc_request structure */
@@ -1663,11 +1682,15 @@ static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1663 pwr = sdhci_readb(host, SDHCI_POWER_CONTROL); 1682 pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
1664 pwr &= ~SDHCI_POWER_ON; 1683 pwr &= ~SDHCI_POWER_ON;
1665 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1684 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1685 if (host->vmmc)
1686 regulator_disable(host->vmmc);
1666 1687
1667 /* Wait for 1ms as per the spec */ 1688 /* Wait for 1ms as per the spec */
1668 usleep_range(1000, 1500); 1689 usleep_range(1000, 1500);
1669 pwr |= SDHCI_POWER_ON; 1690 pwr |= SDHCI_POWER_ON;
1670 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1691 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1692 if (host->vmmc)
1693 regulator_enable(host->vmmc);
1671 1694
1672 pr_info(DRIVER_NAME ": Switching to 1.8V signalling " 1695 pr_info(DRIVER_NAME ": Switching to 1.8V signalling "
1673 "voltage failed, retrying with S18R set to 0\n"); 1696 "voltage failed, retrying with S18R set to 0\n");
@@ -1855,6 +1878,7 @@ out:
1855 */ 1878 */
1856 if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count && 1879 if (!(host->flags & SDHCI_NEEDS_RETUNING) && host->tuning_count &&
1857 (host->tuning_mode == SDHCI_TUNING_MODE_1)) { 1880 (host->tuning_mode == SDHCI_TUNING_MODE_1)) {
1881 host->flags |= SDHCI_USING_RETUNING_TIMER;
1858 mod_timer(&host->tuning_timer, jiffies + 1882 mod_timer(&host->tuning_timer, jiffies +
1859 host->tuning_count * HZ); 1883 host->tuning_count * HZ);
1860 /* Tuning mode 1 limits the maximum data length to 4MB */ 1884 /* Tuning mode 1 limits the maximum data length to 4MB */
@@ -1872,10 +1896,10 @@ out:
1872 * try tuning again at a later time, when the re-tuning timer expires. 1896 * try tuning again at a later time, when the re-tuning timer expires.
1873 * So for these controllers, we return 0. Since there might be other 1897 * So for these controllers, we return 0. Since there might be other
1874 * controllers who do not have this capability, we return error for 1898 * controllers who do not have this capability, we return error for
1875 * them. 1899 * them. SDHCI_USING_RETUNING_TIMER means the host is currently using
1900 * a retuning timer to do the retuning for the card.
1876 */ 1901 */
1877 if (err && host->tuning_count && 1902 if (err && (host->flags & SDHCI_USING_RETUNING_TIMER))
1878 host->tuning_mode == SDHCI_TUNING_MODE_1)
1879 err = 0; 1903 err = 0;
1880 1904
1881 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier); 1905 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier);
@@ -2382,7 +2406,6 @@ out:
2382int sdhci_suspend_host(struct sdhci_host *host) 2406int sdhci_suspend_host(struct sdhci_host *host)
2383{ 2407{
2384 int ret; 2408 int ret;
2385 bool has_tuning_timer;
2386 2409
2387 if (host->ops->platform_suspend) 2410 if (host->ops->platform_suspend)
2388 host->ops->platform_suspend(host); 2411 host->ops->platform_suspend(host);
@@ -2390,16 +2413,14 @@ int sdhci_suspend_host(struct sdhci_host *host)
2390 sdhci_disable_card_detection(host); 2413 sdhci_disable_card_detection(host);
2391 2414
2392 /* Disable tuning since we are suspending */ 2415 /* Disable tuning since we are suspending */
2393 has_tuning_timer = host->version >= SDHCI_SPEC_300 && 2416 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2394 host->tuning_count && host->tuning_mode == SDHCI_TUNING_MODE_1;
2395 if (has_tuning_timer) {
2396 del_timer_sync(&host->tuning_timer); 2417 del_timer_sync(&host->tuning_timer);
2397 host->flags &= ~SDHCI_NEEDS_RETUNING; 2418 host->flags &= ~SDHCI_NEEDS_RETUNING;
2398 } 2419 }
2399 2420
2400 ret = mmc_suspend_host(host->mmc); 2421 ret = mmc_suspend_host(host->mmc);
2401 if (ret) { 2422 if (ret) {
2402 if (has_tuning_timer) { 2423 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2403 host->flags |= SDHCI_NEEDS_RETUNING; 2424 host->flags |= SDHCI_NEEDS_RETUNING;
2404 mod_timer(&host->tuning_timer, jiffies + 2425 mod_timer(&host->tuning_timer, jiffies +
2405 host->tuning_count * HZ); 2426 host->tuning_count * HZ);
@@ -2450,8 +2471,7 @@ int sdhci_resume_host(struct sdhci_host *host)
2450 host->ops->platform_resume(host); 2471 host->ops->platform_resume(host);
2451 2472
2452 /* Set the re-tuning expiration flag */ 2473 /* Set the re-tuning expiration flag */
2453 if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && 2474 if (host->flags & SDHCI_USING_RETUNING_TIMER)
2454 (host->tuning_mode == SDHCI_TUNING_MODE_1))
2455 host->flags |= SDHCI_NEEDS_RETUNING; 2475 host->flags |= SDHCI_NEEDS_RETUNING;
2456 2476
2457 return ret; 2477 return ret;
@@ -2490,8 +2510,7 @@ int sdhci_runtime_suspend_host(struct sdhci_host *host)
2490 int ret = 0; 2510 int ret = 0;
2491 2511
2492 /* Disable tuning since we are suspending */ 2512 /* Disable tuning since we are suspending */
2493 if (host->version >= SDHCI_SPEC_300 && 2513 if (host->flags & SDHCI_USING_RETUNING_TIMER) {
2494 host->tuning_mode == SDHCI_TUNING_MODE_1) {
2495 del_timer_sync(&host->tuning_timer); 2514 del_timer_sync(&host->tuning_timer);
2496 host->flags &= ~SDHCI_NEEDS_RETUNING; 2515 host->flags &= ~SDHCI_NEEDS_RETUNING;
2497 } 2516 }
@@ -2532,8 +2551,7 @@ int sdhci_runtime_resume_host(struct sdhci_host *host)
2532 sdhci_do_enable_preset_value(host, true); 2551 sdhci_do_enable_preset_value(host, true);
2533 2552
2534 /* Set the re-tuning expiration flag */ 2553 /* Set the re-tuning expiration flag */
2535 if ((host->version >= SDHCI_SPEC_300) && host->tuning_count && 2554 if (host->flags & SDHCI_USING_RETUNING_TIMER)
2536 (host->tuning_mode == SDHCI_TUNING_MODE_1))
2537 host->flags |= SDHCI_NEEDS_RETUNING; 2555 host->flags |= SDHCI_NEEDS_RETUNING;
2538 2556
2539 spin_lock_irqsave(&host->lock, flags); 2557 spin_lock_irqsave(&host->lock, flags);
@@ -2584,7 +2602,7 @@ EXPORT_SYMBOL_GPL(sdhci_alloc_host);
2584int sdhci_add_host(struct sdhci_host *host) 2602int sdhci_add_host(struct sdhci_host *host)
2585{ 2603{
2586 struct mmc_host *mmc; 2604 struct mmc_host *mmc;
2587 u32 caps[2]; 2605 u32 caps[2] = {0, 0};
2588 u32 max_current_caps; 2606 u32 max_current_caps;
2589 unsigned int ocr_avail; 2607 unsigned int ocr_avail;
2590 int ret; 2608 int ret;
@@ -2614,8 +2632,10 @@ int sdhci_add_host(struct sdhci_host *host)
2614 caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps : 2632 caps[0] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ? host->caps :
2615 sdhci_readl(host, SDHCI_CAPABILITIES); 2633 sdhci_readl(host, SDHCI_CAPABILITIES);
2616 2634
2617 caps[1] = (host->version >= SDHCI_SPEC_300) ? 2635 if (host->version >= SDHCI_SPEC_300)
2618 sdhci_readl(host, SDHCI_CAPABILITIES_1) : 0; 2636 caps[1] = (host->quirks & SDHCI_QUIRK_MISSING_CAPS) ?
2637 host->caps1 :
2638 sdhci_readl(host, SDHCI_CAPABILITIES_1);
2619 2639
2620 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) 2640 if (host->quirks & SDHCI_QUIRK_FORCE_DMA)
2621 host->flags |= SDHCI_USE_SDMA; 2641 host->flags |= SDHCI_USE_SDMA;
@@ -2779,7 +2799,7 @@ int sdhci_add_host(struct sdhci_host *host)
2779 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED; 2799 mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
2780 2800
2781 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && 2801 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) &&
2782 mmc_card_is_removable(mmc)) 2802 !(host->mmc->caps & MMC_CAP_NONREMOVABLE))
2783 mmc->caps |= MMC_CAP_NEEDS_POLL; 2803 mmc->caps |= MMC_CAP_NEEDS_POLL;
2784 2804
2785 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */ 2805 /* Any UHS-I mode in caps implies SDR12 and SDR25 support. */
@@ -2837,6 +2857,30 @@ int sdhci_add_host(struct sdhci_host *host)
2837 SDHCI_RETUNING_MODE_SHIFT; 2857 SDHCI_RETUNING_MODE_SHIFT;
2838 2858
2839 ocr_avail = 0; 2859 ocr_avail = 0;
2860
2861 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
2862 if (IS_ERR(host->vmmc)) {
2863 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
2864 host->vmmc = NULL;
2865 }
2866
2867#ifdef CONFIG_REGULATOR
2868 if (host->vmmc) {
2869 ret = regulator_is_supported_voltage(host->vmmc, 3300000,
2870 3300000);
2871 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_330)))
2872 caps[0] &= ~SDHCI_CAN_VDD_330;
2873 ret = regulator_is_supported_voltage(host->vmmc, 3000000,
2874 3000000);
2875 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_300)))
2876 caps[0] &= ~SDHCI_CAN_VDD_300;
2877 ret = regulator_is_supported_voltage(host->vmmc, 1800000,
2878 1800000);
2879 if ((ret <= 0) || (!(caps[0] & SDHCI_CAN_VDD_180)))
2880 caps[0] &= ~SDHCI_CAN_VDD_180;
2881 }
2882#endif /* CONFIG_REGULATOR */
2883
2840 /* 2884 /*
2841 * According to SD Host Controller spec v3.00, if the Host System 2885 * According to SD Host Controller spec v3.00, if the Host System
2842 * can afford more than 150mA, Host Driver should set XPC to 1. Also 2886 * can afford more than 150mA, Host Driver should set XPC to 1. Also
@@ -2845,55 +2889,45 @@ int sdhci_add_host(struct sdhci_host *host)
2845 * value. 2889 * value.
2846 */ 2890 */
2847 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); 2891 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT);
2892 if (!max_current_caps && host->vmmc) {
2893 u32 curr = regulator_get_current_limit(host->vmmc);
2894 if (curr > 0) {
2895
2896 /* convert to SDHCI_MAX_CURRENT format */
2897 curr = curr/1000; /* convert to mA */
2898 curr = curr/SDHCI_MAX_CURRENT_MULTIPLIER;
2899
2900 curr = min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT);
2901 max_current_caps =
2902 (curr << SDHCI_MAX_CURRENT_330_SHIFT) |
2903 (curr << SDHCI_MAX_CURRENT_300_SHIFT) |
2904 (curr << SDHCI_MAX_CURRENT_180_SHIFT);
2905 }
2906 }
2848 2907
2849 if (caps[0] & SDHCI_CAN_VDD_330) { 2908 if (caps[0] & SDHCI_CAN_VDD_330) {
2850 int max_current_330;
2851
2852 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34; 2909 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
2853 2910
2854 max_current_330 = ((max_current_caps & 2911 mmc->max_current_330 = ((max_current_caps &
2855 SDHCI_MAX_CURRENT_330_MASK) >> 2912 SDHCI_MAX_CURRENT_330_MASK) >>
2856 SDHCI_MAX_CURRENT_330_SHIFT) * 2913 SDHCI_MAX_CURRENT_330_SHIFT) *
2857 SDHCI_MAX_CURRENT_MULTIPLIER; 2914 SDHCI_MAX_CURRENT_MULTIPLIER;
2858
2859 if (max_current_330 > 150)
2860 mmc->caps |= MMC_CAP_SET_XPC_330;
2861 } 2915 }
2862 if (caps[0] & SDHCI_CAN_VDD_300) { 2916 if (caps[0] & SDHCI_CAN_VDD_300) {
2863 int max_current_300;
2864
2865 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31; 2917 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
2866 2918
2867 max_current_300 = ((max_current_caps & 2919 mmc->max_current_300 = ((max_current_caps &
2868 SDHCI_MAX_CURRENT_300_MASK) >> 2920 SDHCI_MAX_CURRENT_300_MASK) >>
2869 SDHCI_MAX_CURRENT_300_SHIFT) * 2921 SDHCI_MAX_CURRENT_300_SHIFT) *
2870 SDHCI_MAX_CURRENT_MULTIPLIER; 2922 SDHCI_MAX_CURRENT_MULTIPLIER;
2871
2872 if (max_current_300 > 150)
2873 mmc->caps |= MMC_CAP_SET_XPC_300;
2874 } 2923 }
2875 if (caps[0] & SDHCI_CAN_VDD_180) { 2924 if (caps[0] & SDHCI_CAN_VDD_180) {
2876 int max_current_180;
2877
2878 ocr_avail |= MMC_VDD_165_195; 2925 ocr_avail |= MMC_VDD_165_195;
2879 2926
2880 max_current_180 = ((max_current_caps & 2927 mmc->max_current_180 = ((max_current_caps &
2881 SDHCI_MAX_CURRENT_180_MASK) >> 2928 SDHCI_MAX_CURRENT_180_MASK) >>
2882 SDHCI_MAX_CURRENT_180_SHIFT) * 2929 SDHCI_MAX_CURRENT_180_SHIFT) *
2883 SDHCI_MAX_CURRENT_MULTIPLIER; 2930 SDHCI_MAX_CURRENT_MULTIPLIER;
2884
2885 if (max_current_180 > 150)
2886 mmc->caps |= MMC_CAP_SET_XPC_180;
2887
2888 /* Maximum current capabilities of the host at 1.8V */
2889 if (max_current_180 >= 800)
2890 mmc->caps |= MMC_CAP_MAX_CURRENT_800;
2891 else if (max_current_180 >= 600)
2892 mmc->caps |= MMC_CAP_MAX_CURRENT_600;
2893 else if (max_current_180 >= 400)
2894 mmc->caps |= MMC_CAP_MAX_CURRENT_400;
2895 else
2896 mmc->caps |= MMC_CAP_MAX_CURRENT_200;
2897 } 2931 }
2898 2932
2899 mmc->ocr_avail = ocr_avail; 2933 mmc->ocr_avail = ocr_avail;
@@ -2992,13 +3026,10 @@ int sdhci_add_host(struct sdhci_host *host)
2992 3026
2993 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED, 3027 ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
2994 mmc_hostname(mmc), host); 3028 mmc_hostname(mmc), host);
2995 if (ret) 3029 if (ret) {
3030 pr_err("%s: Failed to request IRQ %d: %d\n",
3031 mmc_hostname(mmc), host->irq, ret);
2996 goto untasklet; 3032 goto untasklet;
2997
2998 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
2999 if (IS_ERR(host->vmmc)) {
3000 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
3001 host->vmmc = NULL;
3002 } 3033 }
3003 3034
3004 sdhci_init(host, 0); 3035 sdhci_init(host, 0);
@@ -3016,8 +3047,11 @@ int sdhci_add_host(struct sdhci_host *host)
3016 host->led.brightness_set = sdhci_led_control; 3047 host->led.brightness_set = sdhci_led_control;
3017 3048
3018 ret = led_classdev_register(mmc_dev(mmc), &host->led); 3049 ret = led_classdev_register(mmc_dev(mmc), &host->led);
3019 if (ret) 3050 if (ret) {
3051 pr_err("%s: Failed to register LED device: %d\n",
3052 mmc_hostname(mmc), ret);
3020 goto reset; 3053 goto reset;
3054 }
3021#endif 3055#endif
3022 3056
3023 mmiowb(); 3057 mmiowb();
@@ -3081,8 +3115,6 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3081 free_irq(host->irq, host); 3115 free_irq(host->irq, host);
3082 3116
3083 del_timer_sync(&host->timer); 3117 del_timer_sync(&host->timer);
3084 if (host->version >= SDHCI_SPEC_300)
3085 del_timer_sync(&host->tuning_timer);
3086 3118
3087 tasklet_kill(&host->card_tasklet); 3119 tasklet_kill(&host->card_tasklet);
3088 tasklet_kill(&host->finish_tasklet); 3120 tasklet_kill(&host->finish_tasklet);
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index f761f23d2a28..97653ea8942b 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -205,6 +205,7 @@
205#define SDHCI_CAPABILITIES_1 0x44 205#define SDHCI_CAPABILITIES_1 0x44
206 206
207#define SDHCI_MAX_CURRENT 0x48 207#define SDHCI_MAX_CURRENT 0x48
208#define SDHCI_MAX_CURRENT_LIMIT 0xFF
208#define SDHCI_MAX_CURRENT_330_MASK 0x0000FF 209#define SDHCI_MAX_CURRENT_330_MASK 0x0000FF
209#define SDHCI_MAX_CURRENT_330_SHIFT 0 210#define SDHCI_MAX_CURRENT_330_SHIFT 0
210#define SDHCI_MAX_CURRENT_300_MASK 0x00FF00 211#define SDHCI_MAX_CURRENT_300_MASK 0x00FF00
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 724b35e85a26..b2af7136cd27 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -54,6 +54,8 @@
54#include <linux/mmc/mmc.h> 54#include <linux/mmc/mmc.h>
55#include <linux/mmc/sdio.h> 55#include <linux/mmc/sdio.h>
56#include <linux/mmc/sh_mmcif.h> 56#include <linux/mmc/sh_mmcif.h>
57#include <linux/mmc/slot-gpio.h>
58#include <linux/mod_devicetable.h>
57#include <linux/pagemap.h> 59#include <linux/pagemap.h>
58#include <linux/platform_device.h> 60#include <linux/platform_device.h>
59#include <linux/pm_qos.h> 61#include <linux/pm_qos.h>
@@ -384,6 +386,9 @@ static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
384 struct sh_dmae_slave *tx, *rx; 386 struct sh_dmae_slave *tx, *rx;
385 host->dma_active = false; 387 host->dma_active = false;
386 388
389 if (!pdata)
390 return;
391
387 /* We can only either use DMA for both Tx and Rx or not use it at all */ 392 /* We can only either use DMA for both Tx and Rx or not use it at all */
388 if (pdata->dma) { 393 if (pdata->dma) {
389 dev_warn(&host->pd->dev, 394 dev_warn(&host->pd->dev,
@@ -444,13 +449,14 @@ static void sh_mmcif_release_dma(struct sh_mmcif_host *host)
444static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk) 449static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
445{ 450{
446 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; 451 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
452 bool sup_pclk = p ? p->sup_pclk : false;
447 453
448 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE); 454 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_ENABLE);
449 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR); 455 sh_mmcif_bitclr(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR);
450 456
451 if (!clk) 457 if (!clk)
452 return; 458 return;
453 if (p->sup_pclk && clk == host->clk) 459 if (sup_pclk && clk == host->clk)
454 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK); 460 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_SUP_PCLK);
455 else 461 else
456 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR & 462 sh_mmcif_bitset(host, MMCIF_CE_CLK_CTRL, CLK_CLEAR &
@@ -892,21 +898,15 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
892 898
893 switch (mrq->cmd->opcode) { 899 switch (mrq->cmd->opcode) {
894 /* MMCIF does not support SD/SDIO command */ 900 /* MMCIF does not support SD/SDIO command */
895 case SD_IO_SEND_OP_COND: 901 case MMC_SLEEP_AWAKE: /* = SD_IO_SEND_OP_COND (5) */
902 case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
903 if ((mrq->cmd->flags & MMC_CMD_MASK) != MMC_CMD_BCR)
904 break;
896 case MMC_APP_CMD: 905 case MMC_APP_CMD:
897 host->state = STATE_IDLE; 906 host->state = STATE_IDLE;
898 mrq->cmd->error = -ETIMEDOUT; 907 mrq->cmd->error = -ETIMEDOUT;
899 mmc_request_done(mmc, mrq); 908 mmc_request_done(mmc, mrq);
900 return; 909 return;
901 case MMC_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
902 if (!mrq->data) {
903 /* send_if_cond cmd (not support) */
904 host->state = STATE_IDLE;
905 mrq->cmd->error = -ETIMEDOUT;
906 mmc_request_done(mmc, mrq);
907 return;
908 }
909 break;
910 default: 910 default:
911 break; 911 break;
912 } 912 }
@@ -916,10 +916,35 @@ static void sh_mmcif_request(struct mmc_host *mmc, struct mmc_request *mrq)
916 sh_mmcif_start_cmd(host, mrq); 916 sh_mmcif_start_cmd(host, mrq);
917} 917}
918 918
919static int sh_mmcif_clk_update(struct sh_mmcif_host *host)
920{
921 int ret = clk_enable(host->hclk);
922
923 if (!ret) {
924 host->clk = clk_get_rate(host->hclk);
925 host->mmc->f_max = host->clk / 2;
926 host->mmc->f_min = host->clk / 512;
927 }
928
929 return ret;
930}
931
932static void sh_mmcif_set_power(struct sh_mmcif_host *host, struct mmc_ios *ios)
933{
934 struct sh_mmcif_plat_data *pd = host->pd->dev.platform_data;
935 struct mmc_host *mmc = host->mmc;
936
937 if (pd && pd->set_pwr)
938 pd->set_pwr(host->pd, ios->power_mode != MMC_POWER_OFF);
939 if (!IS_ERR(mmc->supply.vmmc))
940 /* Errors ignored... */
941 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
942 ios->power_mode ? ios->vdd : 0);
943}
944
919static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 945static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
920{ 946{
921 struct sh_mmcif_host *host = mmc_priv(mmc); 947 struct sh_mmcif_host *host = mmc_priv(mmc);
922 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
923 unsigned long flags; 948 unsigned long flags;
924 949
925 spin_lock_irqsave(&host->lock, flags); 950 spin_lock_irqsave(&host->lock, flags);
@@ -937,6 +962,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
937 sh_mmcif_request_dma(host, host->pd->dev.platform_data); 962 sh_mmcif_request_dma(host, host->pd->dev.platform_data);
938 host->card_present = true; 963 host->card_present = true;
939 } 964 }
965 sh_mmcif_set_power(host, ios);
940 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) { 966 } else if (ios->power_mode == MMC_POWER_OFF || !ios->clock) {
941 /* clock stop */ 967 /* clock stop */
942 sh_mmcif_clock_control(host, 0); 968 sh_mmcif_clock_control(host, 0);
@@ -948,9 +974,10 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
948 } 974 }
949 if (host->power) { 975 if (host->power) {
950 pm_runtime_put(&host->pd->dev); 976 pm_runtime_put(&host->pd->dev);
977 clk_disable(host->hclk);
951 host->power = false; 978 host->power = false;
952 if (p->down_pwr && ios->power_mode == MMC_POWER_OFF) 979 if (ios->power_mode == MMC_POWER_OFF)
953 p->down_pwr(host->pd); 980 sh_mmcif_set_power(host, ios);
954 } 981 }
955 host->state = STATE_IDLE; 982 host->state = STATE_IDLE;
956 return; 983 return;
@@ -958,8 +985,7 @@ static void sh_mmcif_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
958 985
959 if (ios->clock) { 986 if (ios->clock) {
960 if (!host->power) { 987 if (!host->power) {
961 if (p->set_pwr) 988 sh_mmcif_clk_update(host);
962 p->set_pwr(host->pd, ios->power_mode);
963 pm_runtime_get_sync(&host->pd->dev); 989 pm_runtime_get_sync(&host->pd->dev);
964 host->power = true; 990 host->power = true;
965 sh_mmcif_sync_reset(host); 991 sh_mmcif_sync_reset(host);
@@ -975,8 +1001,12 @@ static int sh_mmcif_get_cd(struct mmc_host *mmc)
975{ 1001{
976 struct sh_mmcif_host *host = mmc_priv(mmc); 1002 struct sh_mmcif_host *host = mmc_priv(mmc);
977 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data; 1003 struct sh_mmcif_plat_data *p = host->pd->dev.platform_data;
1004 int ret = mmc_gpio_get_cd(mmc);
1005
1006 if (ret >= 0)
1007 return ret;
978 1008
979 if (!p->get_cd) 1009 if (!p || !p->get_cd)
980 return -ENOSYS; 1010 return -ENOSYS;
981 else 1011 else
982 return p->get_cd(host->pd); 1012 return p->get_cd(host->pd);
@@ -1242,12 +1272,28 @@ static void mmcif_timeout_work(struct work_struct *work)
1242 mmc_request_done(host->mmc, mrq); 1272 mmc_request_done(host->mmc, mrq);
1243} 1273}
1244 1274
1275static void sh_mmcif_init_ocr(struct sh_mmcif_host *host)
1276{
1277 struct sh_mmcif_plat_data *pd = host->pd->dev.platform_data;
1278 struct mmc_host *mmc = host->mmc;
1279
1280 mmc_regulator_get_supply(mmc);
1281
1282 if (!pd)
1283 return;
1284
1285 if (!mmc->ocr_avail)
1286 mmc->ocr_avail = pd->ocr;
1287 else if (pd->ocr)
1288 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
1289}
1290
1245static int __devinit sh_mmcif_probe(struct platform_device *pdev) 1291static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1246{ 1292{
1247 int ret = 0, irq[2]; 1293 int ret = 0, irq[2];
1248 struct mmc_host *mmc; 1294 struct mmc_host *mmc;
1249 struct sh_mmcif_host *host; 1295 struct sh_mmcif_host *host;
1250 struct sh_mmcif_plat_data *pd; 1296 struct sh_mmcif_plat_data *pd = pdev->dev.platform_data;
1251 struct resource *res; 1297 struct resource *res;
1252 void __iomem *reg; 1298 void __iomem *reg;
1253 char clk_name[8]; 1299 char clk_name[8];
@@ -1268,42 +1314,26 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1268 dev_err(&pdev->dev, "ioremap error.\n"); 1314 dev_err(&pdev->dev, "ioremap error.\n");
1269 return -ENOMEM; 1315 return -ENOMEM;
1270 } 1316 }
1271 pd = pdev->dev.platform_data; 1317
1272 if (!pd) {
1273 dev_err(&pdev->dev, "sh_mmcif plat data error.\n");
1274 ret = -ENXIO;
1275 goto clean_up;
1276 }
1277 mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev); 1318 mmc = mmc_alloc_host(sizeof(struct sh_mmcif_host), &pdev->dev);
1278 if (!mmc) { 1319 if (!mmc) {
1279 ret = -ENOMEM; 1320 ret = -ENOMEM;
1280 goto clean_up; 1321 goto ealloch;
1281 } 1322 }
1282 host = mmc_priv(mmc); 1323 host = mmc_priv(mmc);
1283 host->mmc = mmc; 1324 host->mmc = mmc;
1284 host->addr = reg; 1325 host->addr = reg;
1285 host->timeout = 1000; 1326 host->timeout = 1000;
1286 1327
1287 snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id);
1288 host->hclk = clk_get(&pdev->dev, clk_name);
1289 if (IS_ERR(host->hclk)) {
1290 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
1291 ret = PTR_ERR(host->hclk);
1292 goto clean_up1;
1293 }
1294 clk_enable(host->hclk);
1295 host->clk = clk_get_rate(host->hclk);
1296 host->pd = pdev; 1328 host->pd = pdev;
1297 1329
1298 spin_lock_init(&host->lock); 1330 spin_lock_init(&host->lock);
1299 1331
1300 mmc->ops = &sh_mmcif_ops; 1332 mmc->ops = &sh_mmcif_ops;
1301 mmc->f_max = host->clk / 2; 1333 sh_mmcif_init_ocr(host);
1302 mmc->f_min = host->clk / 512; 1334
1303 if (pd->ocr)
1304 mmc->ocr_avail = pd->ocr;
1305 mmc->caps = MMC_CAP_MMC_HIGHSPEED; 1335 mmc->caps = MMC_CAP_MMC_HIGHSPEED;
1306 if (pd->caps) 1336 if (pd && pd->caps)
1307 mmc->caps |= pd->caps; 1337 mmc->caps |= pd->caps;
1308 mmc->max_segs = 32; 1338 mmc->max_segs = 32;
1309 mmc->max_blk_size = 512; 1339 mmc->max_blk_size = 512;
@@ -1311,34 +1341,52 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1311 mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size; 1341 mmc->max_blk_count = mmc->max_req_size / mmc->max_blk_size;
1312 mmc->max_seg_size = mmc->max_req_size; 1342 mmc->max_seg_size = mmc->max_req_size;
1313 1343
1314 sh_mmcif_sync_reset(host);
1315 platform_set_drvdata(pdev, host); 1344 platform_set_drvdata(pdev, host);
1316 1345
1317 pm_runtime_enable(&pdev->dev); 1346 pm_runtime_enable(&pdev->dev);
1318 host->power = false; 1347 host->power = false;
1319 1348
1349 snprintf(clk_name, sizeof(clk_name), "mmc%d", pdev->id);
1350 host->hclk = clk_get(&pdev->dev, clk_name);
1351 if (IS_ERR(host->hclk)) {
1352 ret = PTR_ERR(host->hclk);
1353 dev_err(&pdev->dev, "cannot get clock \"%s\": %d\n", clk_name, ret);
1354 goto eclkget;
1355 }
1356 ret = sh_mmcif_clk_update(host);
1357 if (ret < 0)
1358 goto eclkupdate;
1359
1320 ret = pm_runtime_resume(&pdev->dev); 1360 ret = pm_runtime_resume(&pdev->dev);
1321 if (ret < 0) 1361 if (ret < 0)
1322 goto clean_up2; 1362 goto eresume;
1323 1363
1324 INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work); 1364 INIT_DELAYED_WORK(&host->timeout_work, mmcif_timeout_work);
1325 1365
1366 sh_mmcif_sync_reset(host);
1326 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1367 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1327 1368
1328 ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:error", host); 1369 ret = request_threaded_irq(irq[0], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:error", host);
1329 if (ret) { 1370 if (ret) {
1330 dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n"); 1371 dev_err(&pdev->dev, "request_irq error (sh_mmc:error)\n");
1331 goto clean_up3; 1372 goto ereqirq0;
1332 } 1373 }
1333 ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host); 1374 ret = request_threaded_irq(irq[1], sh_mmcif_intr, sh_mmcif_irqt, 0, "sh_mmc:int", host);
1334 if (ret) { 1375 if (ret) {
1335 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n"); 1376 dev_err(&pdev->dev, "request_irq error (sh_mmc:int)\n");
1336 goto clean_up4; 1377 goto ereqirq1;
1378 }
1379
1380 if (pd && pd->use_cd_gpio) {
1381 ret = mmc_gpio_request_cd(mmc, pd->cd_gpio);
1382 if (ret < 0)
1383 goto erqcd;
1337 } 1384 }
1338 1385
1386 clk_disable(host->hclk);
1339 ret = mmc_add_host(mmc); 1387 ret = mmc_add_host(mmc);
1340 if (ret < 0) 1388 if (ret < 0)
1341 goto clean_up5; 1389 goto emmcaddh;
1342 1390
1343 dev_pm_qos_expose_latency_limit(&pdev->dev, 100); 1391 dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
1344 1392
@@ -1347,33 +1395,42 @@ static int __devinit sh_mmcif_probe(struct platform_device *pdev)
1347 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff); 1395 sh_mmcif_readl(host->addr, MMCIF_CE_VERSION) & 0x0000ffff);
1348 return ret; 1396 return ret;
1349 1397
1350clean_up5: 1398emmcaddh:
1399 if (pd && pd->use_cd_gpio)
1400 mmc_gpio_free_cd(mmc);
1401erqcd:
1351 free_irq(irq[1], host); 1402 free_irq(irq[1], host);
1352clean_up4: 1403ereqirq1:
1353 free_irq(irq[0], host); 1404 free_irq(irq[0], host);
1354clean_up3: 1405ereqirq0:
1355 pm_runtime_suspend(&pdev->dev); 1406 pm_runtime_suspend(&pdev->dev);
1356clean_up2: 1407eresume:
1357 pm_runtime_disable(&pdev->dev);
1358 clk_disable(host->hclk); 1408 clk_disable(host->hclk);
1359clean_up1: 1409eclkupdate:
1410 clk_put(host->hclk);
1411eclkget:
1412 pm_runtime_disable(&pdev->dev);
1360 mmc_free_host(mmc); 1413 mmc_free_host(mmc);
1361clean_up: 1414ealloch:
1362 if (reg) 1415 iounmap(reg);
1363 iounmap(reg);
1364 return ret; 1416 return ret;
1365} 1417}
1366 1418
1367static int __devexit sh_mmcif_remove(struct platform_device *pdev) 1419static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1368{ 1420{
1369 struct sh_mmcif_host *host = platform_get_drvdata(pdev); 1421 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1422 struct sh_mmcif_plat_data *pd = pdev->dev.platform_data;
1370 int irq[2]; 1423 int irq[2];
1371 1424
1372 host->dying = true; 1425 host->dying = true;
1426 clk_enable(host->hclk);
1373 pm_runtime_get_sync(&pdev->dev); 1427 pm_runtime_get_sync(&pdev->dev);
1374 1428
1375 dev_pm_qos_hide_latency_limit(&pdev->dev); 1429 dev_pm_qos_hide_latency_limit(&pdev->dev);
1376 1430
1431 if (pd && pd->use_cd_gpio)
1432 mmc_gpio_free_cd(host->mmc);
1433
1377 mmc_remove_host(host->mmc); 1434 mmc_remove_host(host->mmc);
1378 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1435 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1379 1436
@@ -1395,9 +1452,9 @@ static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1395 1452
1396 platform_set_drvdata(pdev, NULL); 1453 platform_set_drvdata(pdev, NULL);
1397 1454
1398 clk_disable(host->hclk);
1399 mmc_free_host(host->mmc); 1455 mmc_free_host(host->mmc);
1400 pm_runtime_put_sync(&pdev->dev); 1456 pm_runtime_put_sync(&pdev->dev);
1457 clk_disable(host->hclk);
1401 pm_runtime_disable(&pdev->dev); 1458 pm_runtime_disable(&pdev->dev);
1402 1459
1403 return 0; 1460 return 0;
@@ -1406,24 +1463,18 @@ static int __devexit sh_mmcif_remove(struct platform_device *pdev)
1406#ifdef CONFIG_PM 1463#ifdef CONFIG_PM
1407static int sh_mmcif_suspend(struct device *dev) 1464static int sh_mmcif_suspend(struct device *dev)
1408{ 1465{
1409 struct platform_device *pdev = to_platform_device(dev); 1466 struct sh_mmcif_host *host = dev_get_drvdata(dev);
1410 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1411 int ret = mmc_suspend_host(host->mmc); 1467 int ret = mmc_suspend_host(host->mmc);
1412 1468
1413 if (!ret) { 1469 if (!ret)
1414 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL); 1470 sh_mmcif_writel(host->addr, MMCIF_CE_INT_MASK, MASK_ALL);
1415 clk_disable(host->hclk);
1416 }
1417 1471
1418 return ret; 1472 return ret;
1419} 1473}
1420 1474
1421static int sh_mmcif_resume(struct device *dev) 1475static int sh_mmcif_resume(struct device *dev)
1422{ 1476{
1423 struct platform_device *pdev = to_platform_device(dev); 1477 struct sh_mmcif_host *host = dev_get_drvdata(dev);
1424 struct sh_mmcif_host *host = platform_get_drvdata(pdev);
1425
1426 clk_enable(host->hclk);
1427 1478
1428 return mmc_resume_host(host->mmc); 1479 return mmc_resume_host(host->mmc);
1429} 1480}
@@ -1432,6 +1483,12 @@ static int sh_mmcif_resume(struct device *dev)
1432#define sh_mmcif_resume NULL 1483#define sh_mmcif_resume NULL
1433#endif /* CONFIG_PM */ 1484#endif /* CONFIG_PM */
1434 1485
1486static const struct of_device_id mmcif_of_match[] = {
1487 { .compatible = "renesas,sh-mmcif" },
1488 { }
1489};
1490MODULE_DEVICE_TABLE(of, mmcif_of_match);
1491
1435static const struct dev_pm_ops sh_mmcif_dev_pm_ops = { 1492static const struct dev_pm_ops sh_mmcif_dev_pm_ops = {
1436 .suspend = sh_mmcif_suspend, 1493 .suspend = sh_mmcif_suspend,
1437 .resume = sh_mmcif_resume, 1494 .resume = sh_mmcif_resume,
@@ -1443,6 +1500,8 @@ static struct platform_driver sh_mmcif_driver = {
1443 .driver = { 1500 .driver = {
1444 .name = DRIVER_NAME, 1501 .name = DRIVER_NAME,
1445 .pm = &sh_mmcif_dev_pm_ops, 1502 .pm = &sh_mmcif_dev_pm_ops,
1503 .owner = THIS_MODULE,
1504 .of_match_table = mmcif_of_match,
1446 }, 1505 },
1447}; 1506};
1448 1507
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c
index 934b68e9efc3..a842939e4655 100644
--- a/drivers/mmc/host/sh_mobile_sdhi.c
+++ b/drivers/mmc/host/sh_mobile_sdhi.c
@@ -21,6 +21,7 @@
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/mod_devicetable.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/platform_device.h> 26#include <linux/platform_device.h>
26#include <linux/mmc/host.h> 27#include <linux/mmc/host.h>
@@ -39,22 +40,39 @@ struct sh_mobile_sdhi {
39 struct tmio_mmc_dma dma_priv; 40 struct tmio_mmc_dma dma_priv;
40}; 41};
41 42
43static int sh_mobile_sdhi_clk_enable(struct platform_device *pdev, unsigned int *f)
44{
45 struct mmc_host *mmc = dev_get_drvdata(&pdev->dev);
46 struct tmio_mmc_host *host = mmc_priv(mmc);
47 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
48 int ret = clk_enable(priv->clk);
49 if (ret < 0)
50 return ret;
51
52 *f = clk_get_rate(priv->clk);
53 return 0;
54}
55
56static void sh_mobile_sdhi_clk_disable(struct platform_device *pdev)
57{
58 struct mmc_host *mmc = dev_get_drvdata(&pdev->dev);
59 struct tmio_mmc_host *host = mmc_priv(mmc);
60 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
61 clk_disable(priv->clk);
62}
63
42static void sh_mobile_sdhi_set_pwr(struct platform_device *pdev, int state) 64static void sh_mobile_sdhi_set_pwr(struct platform_device *pdev, int state)
43{ 65{
44 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 66 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
45 67
46 if (p && p->set_pwr) 68 p->set_pwr(pdev, state);
47 p->set_pwr(pdev, state);
48} 69}
49 70
50static int sh_mobile_sdhi_get_cd(struct platform_device *pdev) 71static int sh_mobile_sdhi_get_cd(struct platform_device *pdev)
51{ 72{
52 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 73 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
53 74
54 if (p && p->get_cd) 75 return p->get_cd(pdev);
55 return p->get_cd(pdev);
56 else
57 return -ENOSYS;
58} 76}
59 77
60static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host) 78static int sh_mobile_sdhi_wait_idle(struct tmio_mmc_host *host)
@@ -116,12 +134,14 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
116 } 134 }
117 135
118 mmc_data = &priv->mmc_data; 136 mmc_data = &priv->mmc_data;
119 p->pdata = mmc_data;
120 137
121 if (p->init) { 138 if (p) {
122 ret = p->init(pdev, &sdhi_ops); 139 p->pdata = mmc_data;
123 if (ret) 140 if (p->init) {
124 goto einit; 141 ret = p->init(pdev, &sdhi_ops);
142 if (ret)
143 goto einit;
144 }
125 } 145 }
126 146
127 snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id); 147 snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id);
@@ -132,9 +152,8 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
132 goto eclkget; 152 goto eclkget;
133 } 153 }
134 154
135 mmc_data->hclk = clk_get_rate(priv->clk); 155 mmc_data->clk_enable = sh_mobile_sdhi_clk_enable;
136 mmc_data->set_pwr = sh_mobile_sdhi_set_pwr; 156 mmc_data->clk_disable = sh_mobile_sdhi_clk_disable;
137 mmc_data->get_cd = sh_mobile_sdhi_get_cd;
138 mmc_data->capabilities = MMC_CAP_MMC_HIGHSPEED; 157 mmc_data->capabilities = MMC_CAP_MMC_HIGHSPEED;
139 if (p) { 158 if (p) {
140 mmc_data->flags = p->tmio_flags; 159 mmc_data->flags = p->tmio_flags;
@@ -142,7 +161,12 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
142 mmc_data->write16_hook = sh_mobile_sdhi_write16_hook; 161 mmc_data->write16_hook = sh_mobile_sdhi_write16_hook;
143 mmc_data->ocr_mask = p->tmio_ocr_mask; 162 mmc_data->ocr_mask = p->tmio_ocr_mask;
144 mmc_data->capabilities |= p->tmio_caps; 163 mmc_data->capabilities |= p->tmio_caps;
164 mmc_data->capabilities2 |= p->tmio_caps2;
145 mmc_data->cd_gpio = p->cd_gpio; 165 mmc_data->cd_gpio = p->cd_gpio;
166 if (p->set_pwr)
167 mmc_data->set_pwr = sh_mobile_sdhi_set_pwr;
168 if (p->get_cd)
169 mmc_data->get_cd = sh_mobile_sdhi_get_cd;
146 170
147 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) { 171 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0) {
148 priv->param_tx.slave_id = p->dma_slave_tx; 172 priv->param_tx.slave_id = p->dma_slave_tx;
@@ -248,7 +272,7 @@ eirq_card_detect:
248eprobe: 272eprobe:
249 clk_put(priv->clk); 273 clk_put(priv->clk);
250eclkget: 274eclkget:
251 if (p->cleanup) 275 if (p && p->cleanup)
252 p->cleanup(pdev); 276 p->cleanup(pdev);
253einit: 277einit:
254 kfree(priv); 278 kfree(priv);
@@ -263,7 +287,8 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev)
263 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 287 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
264 int i = 0, irq; 288 int i = 0, irq;
265 289
266 p->pdata = NULL; 290 if (p)
291 p->pdata = NULL;
267 292
268 tmio_mmc_host_remove(host); 293 tmio_mmc_host_remove(host);
269 294
@@ -276,7 +301,7 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev)
276 301
277 clk_put(priv->clk); 302 clk_put(priv->clk);
278 303
279 if (p->cleanup) 304 if (p && p->cleanup)
280 p->cleanup(pdev); 305 p->cleanup(pdev);
281 306
282 kfree(priv); 307 kfree(priv);
@@ -291,11 +316,18 @@ static const struct dev_pm_ops tmio_mmc_dev_pm_ops = {
291 .runtime_resume = tmio_mmc_host_runtime_resume, 316 .runtime_resume = tmio_mmc_host_runtime_resume,
292}; 317};
293 318
319static const struct of_device_id sh_mobile_sdhi_of_match[] = {
320 { .compatible = "renesas,shmobile-sdhi" },
321 { }
322};
323MODULE_DEVICE_TABLE(of, sh_mobile_sdhi_of_match);
324
294static struct platform_driver sh_mobile_sdhi_driver = { 325static struct platform_driver sh_mobile_sdhi_driver = {
295 .driver = { 326 .driver = {
296 .name = "sh_mobile_sdhi", 327 .name = "sh_mobile_sdhi",
297 .owner = THIS_MODULE, 328 .owner = THIS_MODULE,
298 .pm = &tmio_mmc_dev_pm_ops, 329 .pm = &tmio_mmc_dev_pm_ops,
330 .of_match_table = sh_mobile_sdhi_of_match,
299 }, 331 },
300 .probe = sh_mobile_sdhi_probe, 332 .probe = sh_mobile_sdhi_probe,
301 .remove = __devexit_p(sh_mobile_sdhi_remove), 333 .remove = __devexit_p(sh_mobile_sdhi_remove),
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index 9a7996ade58e..0d8a9bbe30be 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -34,8 +34,9 @@
34#include <linux/io.h> 34#include <linux/io.h>
35#include <linux/irq.h> 35#include <linux/irq.h>
36#include <linux/mfd/tmio.h> 36#include <linux/mfd/tmio.h>
37#include <linux/mmc/cd-gpio.h>
38#include <linux/mmc/host.h> 37#include <linux/mmc/host.h>
38#include <linux/mmc/mmc.h>
39#include <linux/mmc/slot-gpio.h>
39#include <linux/mmc/tmio.h> 40#include <linux/mmc/tmio.h>
40#include <linux/module.h> 41#include <linux/module.h>
41#include <linux/pagemap.h> 42#include <linux/pagemap.h>
@@ -305,8 +306,8 @@ static int tmio_mmc_start_command(struct tmio_mmc_host *host, struct mmc_command
305 int c = cmd->opcode; 306 int c = cmd->opcode;
306 u32 irq_mask = TMIO_MASK_CMD; 307 u32 irq_mask = TMIO_MASK_CMD;
307 308
308 /* Command 12 is handled by hardware */ 309 /* CMD12 is handled by hardware */
309 if (cmd->opcode == 12 && !cmd->arg) { 310 if (cmd->opcode == MMC_STOP_TRANSMISSION && !cmd->arg) {
310 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001); 311 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x001);
311 return 0; 312 return 0;
312 } 313 }
@@ -449,7 +450,7 @@ void tmio_mmc_do_data_irq(struct tmio_mmc_host *host)
449 } 450 }
450 451
451 if (stop) { 452 if (stop) {
452 if (stop->opcode == 12 && !stop->arg) 453 if (stop->opcode == MMC_STOP_TRANSMISSION && !stop->arg)
453 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000); 454 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0x000);
454 else 455 else
455 BUG(); 456 BUG();
@@ -751,6 +752,34 @@ fail:
751 mmc_request_done(mmc, mrq); 752 mmc_request_done(mmc, mrq);
752} 753}
753 754
755static int tmio_mmc_clk_update(struct mmc_host *mmc)
756{
757 struct tmio_mmc_host *host = mmc_priv(mmc);
758 struct tmio_mmc_data *pdata = host->pdata;
759 int ret;
760
761 if (!pdata->clk_enable)
762 return -ENOTSUPP;
763
764 ret = pdata->clk_enable(host->pdev, &mmc->f_max);
765 if (!ret)
766 mmc->f_min = mmc->f_max / 512;
767
768 return ret;
769}
770
771static void tmio_mmc_set_power(struct tmio_mmc_host *host, struct mmc_ios *ios)
772{
773 struct mmc_host *mmc = host->mmc;
774
775 if (host->set_pwr)
776 host->set_pwr(host->pdev, ios->power_mode != MMC_POWER_OFF);
777 if (!IS_ERR(mmc->supply.vmmc))
778 /* Errors ignored... */
779 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc,
780 ios->power_mode ? ios->vdd : 0);
781}
782
754/* Set MMC clock / power. 783/* Set MMC clock / power.
755 * Note: This controller uses a simple divider scheme therefore it cannot 784 * Note: This controller uses a simple divider scheme therefore it cannot
756 * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as 785 * run a MMC card at full speed (20MHz). The max clock is 24MHz on SD, but as
@@ -797,32 +826,37 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
797 */ 826 */
798 if (ios->power_mode == MMC_POWER_ON && ios->clock) { 827 if (ios->power_mode == MMC_POWER_ON && ios->clock) {
799 if (!host->power) { 828 if (!host->power) {
829 tmio_mmc_clk_update(mmc);
800 pm_runtime_get_sync(dev); 830 pm_runtime_get_sync(dev);
801 host->power = true; 831 host->power = true;
802 } 832 }
803 tmio_mmc_set_clock(host, ios->clock); 833 tmio_mmc_set_clock(host, ios->clock);
804 /* power up SD bus */ 834 /* power up SD bus */
805 if (host->set_pwr) 835 tmio_mmc_set_power(host, ios);
806 host->set_pwr(host->pdev, 1);
807 /* start bus clock */ 836 /* start bus clock */
808 tmio_mmc_clk_start(host); 837 tmio_mmc_clk_start(host);
809 } else if (ios->power_mode != MMC_POWER_UP) { 838 } else if (ios->power_mode != MMC_POWER_UP) {
810 if (host->set_pwr && ios->power_mode == MMC_POWER_OFF) 839 if (ios->power_mode == MMC_POWER_OFF)
811 host->set_pwr(host->pdev, 0); 840 tmio_mmc_set_power(host, ios);
812 if (host->power) { 841 if (host->power) {
842 struct tmio_mmc_data *pdata = host->pdata;
843 tmio_mmc_clk_stop(host);
813 host->power = false; 844 host->power = false;
814 pm_runtime_put(dev); 845 pm_runtime_put(dev);
846 if (pdata->clk_disable)
847 pdata->clk_disable(host->pdev);
815 } 848 }
816 tmio_mmc_clk_stop(host);
817 } 849 }
818 850
819 switch (ios->bus_width) { 851 if (host->power) {
820 case MMC_BUS_WIDTH_1: 852 switch (ios->bus_width) {
821 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0); 853 case MMC_BUS_WIDTH_1:
822 break; 854 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0);
823 case MMC_BUS_WIDTH_4: 855 break;
824 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0); 856 case MMC_BUS_WIDTH_4:
825 break; 857 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x00e0);
858 break;
859 }
826 } 860 }
827 861
828 /* Let things settle. delay taken from winCE driver */ 862 /* Let things settle. delay taken from winCE driver */
@@ -841,6 +875,9 @@ static int tmio_mmc_get_ro(struct mmc_host *mmc)
841{ 875{
842 struct tmio_mmc_host *host = mmc_priv(mmc); 876 struct tmio_mmc_host *host = mmc_priv(mmc);
843 struct tmio_mmc_data *pdata = host->pdata; 877 struct tmio_mmc_data *pdata = host->pdata;
878 int ret = mmc_gpio_get_ro(mmc);
879 if (ret >= 0)
880 return ret;
844 881
845 return !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) || 882 return !((pdata->flags & TMIO_MMC_WRPROTECT_DISABLE) ||
846 (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT)); 883 (sd_ctrl_read32(host, CTL_STATUS) & TMIO_STAT_WRPROTECT));
@@ -850,6 +887,9 @@ static int tmio_mmc_get_cd(struct mmc_host *mmc)
850{ 887{
851 struct tmio_mmc_host *host = mmc_priv(mmc); 888 struct tmio_mmc_host *host = mmc_priv(mmc);
852 struct tmio_mmc_data *pdata = host->pdata; 889 struct tmio_mmc_data *pdata = host->pdata;
890 int ret = mmc_gpio_get_cd(mmc);
891 if (ret >= 0)
892 return ret;
853 893
854 if (!pdata->get_cd) 894 if (!pdata->get_cd)
855 return -ENOSYS; 895 return -ENOSYS;
@@ -865,6 +905,19 @@ static const struct mmc_host_ops tmio_mmc_ops = {
865 .enable_sdio_irq = tmio_mmc_enable_sdio_irq, 905 .enable_sdio_irq = tmio_mmc_enable_sdio_irq,
866}; 906};
867 907
908static void tmio_mmc_init_ocr(struct tmio_mmc_host *host)
909{
910 struct tmio_mmc_data *pdata = host->pdata;
911 struct mmc_host *mmc = host->mmc;
912
913 mmc_regulator_get_supply(mmc);
914
915 if (!mmc->ocr_avail)
916 mmc->ocr_avail = pdata->ocr_mask ? : MMC_VDD_32_33 | MMC_VDD_33_34;
917 else if (pdata->ocr_mask)
918 dev_warn(mmc_dev(mmc), "Platform OCR mask is ignored\n");
919}
920
868int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host, 921int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
869 struct platform_device *pdev, 922 struct platform_device *pdev,
870 struct tmio_mmc_data *pdata) 923 struct tmio_mmc_data *pdata)
@@ -904,18 +957,14 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
904 957
905 mmc->ops = &tmio_mmc_ops; 958 mmc->ops = &tmio_mmc_ops;
906 mmc->caps = MMC_CAP_4_BIT_DATA | pdata->capabilities; 959 mmc->caps = MMC_CAP_4_BIT_DATA | pdata->capabilities;
907 mmc->f_max = pdata->hclk; 960 mmc->caps2 = pdata->capabilities2;
908 mmc->f_min = mmc->f_max / 512;
909 mmc->max_segs = 32; 961 mmc->max_segs = 32;
910 mmc->max_blk_size = 512; 962 mmc->max_blk_size = 512;
911 mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) * 963 mmc->max_blk_count = (PAGE_CACHE_SIZE / mmc->max_blk_size) *
912 mmc->max_segs; 964 mmc->max_segs;
913 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count; 965 mmc->max_req_size = mmc->max_blk_size * mmc->max_blk_count;
914 mmc->max_seg_size = mmc->max_req_size; 966 mmc->max_seg_size = mmc->max_req_size;
915 if (pdata->ocr_mask) 967 tmio_mmc_init_ocr(_host);
916 mmc->ocr_avail = pdata->ocr_mask;
917 else
918 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
919 968
920 _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD || 969 _host->native_hotplug = !(pdata->flags & TMIO_MMC_USE_GPIO_CD ||
921 mmc->caps & MMC_CAP_NEEDS_POLL || 970 mmc->caps & MMC_CAP_NEEDS_POLL ||
@@ -927,6 +976,11 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
927 if (ret < 0) 976 if (ret < 0)
928 goto pm_disable; 977 goto pm_disable;
929 978
979 if (tmio_mmc_clk_update(mmc) < 0) {
980 mmc->f_max = pdata->hclk;
981 mmc->f_min = mmc->f_max / 512;
982 }
983
930 /* 984 /*
931 * There are 4 different scenarios for the card detection: 985 * There are 4 different scenarios for the card detection:
932 * 1) an external gpio irq handles the cd (best for power savings) 986 * 1) an external gpio irq handles the cd (best for power savings)
@@ -937,7 +991,6 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
937 * While we increment the runtime PM counter for all scenarios when 991 * While we increment the runtime PM counter for all scenarios when
938 * the mmc core activates us by calling an appropriate set_ios(), we 992 * the mmc core activates us by calling an appropriate set_ios(), we
939 * must additionally ensure that in case 2) the tmio mmc hardware stays 993 * must additionally ensure that in case 2) the tmio mmc hardware stays
940 * additionally ensure that in case 2) the tmio mmc hardware stays
941 * powered on during runtime for the card detection to work. 994 * powered on during runtime for the card detection to work.
942 */ 995 */
943 if (_host->native_hotplug) 996 if (_host->native_hotplug)
@@ -948,6 +1001,17 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
948 1001
949 _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK); 1002 _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK);
950 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL); 1003 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL);
1004
1005 /* Unmask the IRQs we want to know about */
1006 if (!_host->chan_rx)
1007 irq_mask |= TMIO_MASK_READOP;
1008 if (!_host->chan_tx)
1009 irq_mask |= TMIO_MASK_WRITEOP;
1010 if (!_host->native_hotplug)
1011 irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT);
1012
1013 _host->sdcard_irq_mask &= ~irq_mask;
1014
951 if (pdata->flags & TMIO_MMC_SDIO_IRQ) 1015 if (pdata->flags & TMIO_MMC_SDIO_IRQ)
952 tmio_mmc_enable_sdio_irq(mmc, 0); 1016 tmio_mmc_enable_sdio_irq(mmc, 0);
953 1017
@@ -961,22 +1025,18 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
961 /* See if we also get DMA */ 1025 /* See if we also get DMA */
962 tmio_mmc_request_dma(_host, pdata); 1026 tmio_mmc_request_dma(_host, pdata);
963 1027
964 mmc_add_host(mmc); 1028 ret = mmc_add_host(mmc);
1029 if (pdata->clk_disable)
1030 pdata->clk_disable(pdev);
1031 if (ret < 0) {
1032 tmio_mmc_host_remove(_host);
1033 return ret;
1034 }
965 1035
966 dev_pm_qos_expose_latency_limit(&pdev->dev, 100); 1036 dev_pm_qos_expose_latency_limit(&pdev->dev, 100);
967 1037
968 /* Unmask the IRQs we want to know about */
969 if (!_host->chan_rx)
970 irq_mask |= TMIO_MASK_READOP;
971 if (!_host->chan_tx)
972 irq_mask |= TMIO_MASK_WRITEOP;
973 if (!_host->native_hotplug)
974 irq_mask &= ~(TMIO_STAT_CARD_REMOVE | TMIO_STAT_CARD_INSERT);
975
976 tmio_mmc_enable_mmc_irqs(_host, irq_mask);
977
978 if (pdata->flags & TMIO_MMC_USE_GPIO_CD) { 1038 if (pdata->flags & TMIO_MMC_USE_GPIO_CD) {
979 ret = mmc_cd_gpio_request(mmc, pdata->cd_gpio); 1039 ret = mmc_gpio_request_cd(mmc, pdata->cd_gpio);
980 if (ret < 0) { 1040 if (ret < 0) {
981 tmio_mmc_host_remove(_host); 1041 tmio_mmc_host_remove(_host);
982 return ret; 1042 return ret;
@@ -1008,7 +1068,7 @@ void tmio_mmc_host_remove(struct tmio_mmc_host *host)
1008 * This means we can miss a card-eject, but this is anyway 1068 * This means we can miss a card-eject, but this is anyway
1009 * possible, because of delayed processing of hotplug events. 1069 * possible, because of delayed processing of hotplug events.
1010 */ 1070 */
1011 mmc_cd_gpio_free(mmc); 1071 mmc_gpio_free_cd(mmc);
1012 1072
1013 if (!host->native_hotplug) 1073 if (!host->native_hotplug)
1014 pm_runtime_get_sync(&pdev->dev); 1074 pm_runtime_get_sync(&pdev->dev);
diff --git a/include/linux/mfd/tmio.h b/include/linux/mfd/tmio.h
index f5171dbf8850..d83af39815ab 100644
--- a/include/linux/mfd/tmio.h
+++ b/include/linux/mfd/tmio.h
@@ -101,6 +101,7 @@ struct tmio_mmc_host;
101struct tmio_mmc_data { 101struct tmio_mmc_data {
102 unsigned int hclk; 102 unsigned int hclk;
103 unsigned long capabilities; 103 unsigned long capabilities;
104 unsigned long capabilities2;
104 unsigned long flags; 105 unsigned long flags;
105 u32 ocr_mask; /* available voltages */ 106 u32 ocr_mask; /* available voltages */
106 struct tmio_mmc_dma *dma; 107 struct tmio_mmc_dma *dma;
@@ -110,6 +111,9 @@ struct tmio_mmc_data {
110 void (*set_clk_div)(struct platform_device *host, int state); 111 void (*set_clk_div)(struct platform_device *host, int state);
111 int (*get_cd)(struct platform_device *host); 112 int (*get_cd)(struct platform_device *host);
112 int (*write16_hook)(struct tmio_mmc_host *host, int addr); 113 int (*write16_hook)(struct tmio_mmc_host *host, int addr);
114 /* clock management callbacks */
115 int (*clk_enable)(struct platform_device *pdev, unsigned int *f);
116 void (*clk_disable)(struct platform_device *pdev);
113}; 117};
114 118
115/* 119/*
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index d76513b5b263..111aca5e97f3 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -149,6 +149,7 @@ struct sd_switch_caps {
149#define SD_SET_CURRENT_LIMIT_400 1 149#define SD_SET_CURRENT_LIMIT_400 1
150#define SD_SET_CURRENT_LIMIT_600 2 150#define SD_SET_CURRENT_LIMIT_600 2
151#define SD_SET_CURRENT_LIMIT_800 3 151#define SD_SET_CURRENT_LIMIT_800 3
152#define SD_SET_CURRENT_NO_CHANGE (-1)
152 153
153#define SD_MAX_CURRENT_200 (1 << SD_SET_CURRENT_LIMIT_200) 154#define SD_MAX_CURRENT_200 (1 << SD_SET_CURRENT_LIMIT_200)
154#define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400) 155#define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400)
diff --git a/include/linux/mmc/cd-gpio.h b/include/linux/mmc/cd-gpio.h
deleted file mode 100644
index cefaba038ccb..000000000000
--- a/include/linux/mmc/cd-gpio.h
+++ /dev/null
@@ -1,18 +0,0 @@
1/*
2 * Generic GPIO card-detect helper header
3 *
4 * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef MMC_CD_GPIO_H
12#define MMC_CD_GPIO_H
13
14struct mmc_host;
15int mmc_cd_gpio_request(struct mmc_host *host, unsigned int gpio);
16void mmc_cd_gpio_free(struct mmc_host *host);
17
18#endif
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 0707d228d7f1..f578a71d82a6 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -11,6 +11,7 @@
11#define LINUX_MMC_HOST_H 11#define LINUX_MMC_HOST_H
12 12
13#include <linux/leds.h> 13#include <linux/leds.h>
14#include <linux/mutex.h>
14#include <linux/sched.h> 15#include <linux/sched.h>
15#include <linux/device.h> 16#include <linux/device.h>
16#include <linux/fault-inject.h> 17#include <linux/fault-inject.h>
@@ -150,11 +151,31 @@ struct mmc_async_req {
150 int (*err_check) (struct mmc_card *, struct mmc_async_req *); 151 int (*err_check) (struct mmc_card *, struct mmc_async_req *);
151}; 152};
152 153
153struct mmc_hotplug { 154/**
154 unsigned int irq; 155 * struct mmc_slot - MMC slot functions
156 *
157 * @cd_irq: MMC/SD-card slot hotplug detection IRQ or -EINVAL
158 * @lock: protect the @handler_priv pointer
159 * @handler_priv: MMC/SD-card slot context
160 *
161 * Some MMC/SD host controllers implement slot-functions like card and
162 * write-protect detection natively. However, a large number of controllers
163 * leave these functions to the CPU. This struct provides a hook to attach
164 * such slot-function drivers.
165 */
166struct mmc_slot {
167 int cd_irq;
168 struct mutex lock;
155 void *handler_priv; 169 void *handler_priv;
156}; 170};
157 171
172struct regulator;
173
174struct mmc_supply {
175 struct regulator *vmmc; /* Card power supply */
176 struct regulator *vqmmc; /* Optional Vccq supply */
177};
178
158struct mmc_host { 179struct mmc_host {
159 struct device *parent; 180 struct device *parent;
160 struct device class_dev; 181 struct device class_dev;
@@ -168,6 +189,9 @@ struct mmc_host {
168 u32 ocr_avail_sd; /* SD-specific OCR */ 189 u32 ocr_avail_sd; /* SD-specific OCR */
169 u32 ocr_avail_mmc; /* MMC-specific OCR */ 190 u32 ocr_avail_mmc; /* MMC-specific OCR */
170 struct notifier_block pm_notify; 191 struct notifier_block pm_notify;
192 u32 max_current_330;
193 u32 max_current_300;
194 u32 max_current_180;
171 195
172#define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */ 196#define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */
173#define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */ 197#define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */
@@ -211,16 +235,9 @@ struct mmc_host {
211#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50 mode */ 235#define MMC_CAP_UHS_SDR50 (1 << 17) /* Host supports UHS SDR50 mode */
212#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104 mode */ 236#define MMC_CAP_UHS_SDR104 (1 << 18) /* Host supports UHS SDR104 mode */
213#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50 mode */ 237#define MMC_CAP_UHS_DDR50 (1 << 19) /* Host supports UHS DDR50 mode */
214#define MMC_CAP_SET_XPC_330 (1 << 20) /* Host supports >150mA current at 3.3V */
215#define MMC_CAP_SET_XPC_300 (1 << 21) /* Host supports >150mA current at 3.0V */
216#define MMC_CAP_SET_XPC_180 (1 << 22) /* Host supports >150mA current at 1.8V */
217#define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */ 238#define MMC_CAP_DRIVER_TYPE_A (1 << 23) /* Host supports Driver Type A */
218#define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */ 239#define MMC_CAP_DRIVER_TYPE_C (1 << 24) /* Host supports Driver Type C */
219#define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */ 240#define MMC_CAP_DRIVER_TYPE_D (1 << 25) /* Host supports Driver Type D */
220#define MMC_CAP_MAX_CURRENT_200 (1 << 26) /* Host max current limit is 200mA */
221#define MMC_CAP_MAX_CURRENT_400 (1 << 27) /* Host max current limit is 400mA */
222#define MMC_CAP_MAX_CURRENT_600 (1 << 28) /* Host max current limit is 600mA */
223#define MMC_CAP_MAX_CURRENT_800 (1 << 29) /* Host max current limit is 800mA */
224#define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */ 241#define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */
225#define MMC_CAP_HW_RESET (1 << 31) /* Hardware reset */ 242#define MMC_CAP_HW_RESET (1 << 31) /* Hardware reset */
226 243
@@ -238,6 +255,8 @@ struct mmc_host {
238#define MMC_CAP2_BROKEN_VOLTAGE (1 << 7) /* Use the broken voltage */ 255#define MMC_CAP2_BROKEN_VOLTAGE (1 << 7) /* Use the broken voltage */
239#define MMC_CAP2_DETECT_ON_ERR (1 << 8) /* On I/O err check card removal */ 256#define MMC_CAP2_DETECT_ON_ERR (1 << 8) /* On I/O err check card removal */
240#define MMC_CAP2_HC_ERASE_SZ (1 << 9) /* High-capacity erase size */ 257#define MMC_CAP2_HC_ERASE_SZ (1 << 9) /* High-capacity erase size */
258#define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10) /* Card-detect signal active high */
259#define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11) /* Write-protect signal active high */
241 260
242 mmc_pm_flag_t pm_caps; /* supported pm features */ 261 mmc_pm_flag_t pm_caps; /* supported pm features */
243 unsigned int power_notify_type; 262 unsigned int power_notify_type;
@@ -290,7 +309,7 @@ struct mmc_host {
290 309
291 struct delayed_work detect; 310 struct delayed_work detect;
292 int detect_change; /* card detect flag */ 311 int detect_change; /* card detect flag */
293 struct mmc_hotplug hotplug; 312 struct mmc_slot slot;
294 313
295 const struct mmc_bus_ops *bus_ops; /* current bus driver */ 314 const struct mmc_bus_ops *bus_ops; /* current bus driver */
296 unsigned int bus_refs; /* reference counter */ 315 unsigned int bus_refs; /* reference counter */
@@ -309,6 +328,7 @@ struct mmc_host {
309#ifdef CONFIG_REGULATOR 328#ifdef CONFIG_REGULATOR
310 bool regulator_enabled; /* regulator state */ 329 bool regulator_enabled; /* regulator state */
311#endif 330#endif
331 struct mmc_supply supply;
312 332
313 struct dentry *debugfs_root; 333 struct dentry *debugfs_root;
314 334
@@ -357,13 +377,12 @@ static inline void mmc_signal_sdio_irq(struct mmc_host *host)
357 wake_up_process(host->sdio_irq_thread); 377 wake_up_process(host->sdio_irq_thread);
358} 378}
359 379
360struct regulator;
361
362#ifdef CONFIG_REGULATOR 380#ifdef CONFIG_REGULATOR
363int mmc_regulator_get_ocrmask(struct regulator *supply); 381int mmc_regulator_get_ocrmask(struct regulator *supply);
364int mmc_regulator_set_ocr(struct mmc_host *mmc, 382int mmc_regulator_set_ocr(struct mmc_host *mmc,
365 struct regulator *supply, 383 struct regulator *supply,
366 unsigned short vdd_bit); 384 unsigned short vdd_bit);
385int mmc_regulator_get_supply(struct mmc_host *mmc);
367#else 386#else
368static inline int mmc_regulator_get_ocrmask(struct regulator *supply) 387static inline int mmc_regulator_get_ocrmask(struct regulator *supply)
369{ 388{
@@ -376,6 +395,11 @@ static inline int mmc_regulator_set_ocr(struct mmc_host *mmc,
376{ 395{
377 return 0; 396 return 0;
378} 397}
398
399static inline int mmc_regulator_get_supply(struct mmc_host *mmc)
400{
401 return 0;
402}
379#endif 403#endif
380 404
381int mmc_card_awake(struct mmc_host *host); 405int mmc_card_awake(struct mmc_host *host);
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index e9051e1cb1ce..ac83b105bedd 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -122,6 +122,7 @@ struct sdhci_host {
122#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */ 122#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
123#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */ 123#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
124#define SDHCI_HS200_NEEDS_TUNING (1<<10) /* HS200 needs tuning */ 124#define SDHCI_HS200_NEEDS_TUNING (1<<10) /* HS200 needs tuning */
125#define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
125 126
126 unsigned int version; /* SDHCI spec. version */ 127 unsigned int version; /* SDHCI spec. version */
127 128
@@ -155,7 +156,8 @@ struct sdhci_host {
155 156
156 struct timer_list timer; /* Timer for timeouts */ 157 struct timer_list timer; /* Timer for timeouts */
157 158
158 unsigned int caps; /* Alternative capabilities */ 159 unsigned int caps; /* Alternative CAPABILITY_0 */
160 unsigned int caps1; /* Alternative CAPABILITY_1 */
159 161
160 unsigned int ocr_avail_sdio; /* OCR bit masks */ 162 unsigned int ocr_avail_sdio; /* OCR bit masks */
161 unsigned int ocr_avail_sd; 163 unsigned int ocr_avail_sd;
diff --git a/include/linux/mmc/sh_mmcif.h b/include/linux/mmc/sh_mmcif.h
index 05f0e3db1c12..c2f73cbb4d5c 100644
--- a/include/linux/mmc/sh_mmcif.h
+++ b/include/linux/mmc/sh_mmcif.h
@@ -44,6 +44,8 @@ struct sh_mmcif_plat_data {
44 struct sh_mmcif_dma *dma; /* Deprecated. Instead */ 44 struct sh_mmcif_dma *dma; /* Deprecated. Instead */
45 unsigned int slave_id_tx; /* use embedded slave_id_[tr]x */ 45 unsigned int slave_id_tx; /* use embedded slave_id_[tr]x */
46 unsigned int slave_id_rx; 46 unsigned int slave_id_rx;
47 bool use_cd_gpio : 1;
48 unsigned int cd_gpio;
47 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */ 49 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */
48 unsigned long caps; 50 unsigned long caps;
49 u32 ocr; 51 u32 ocr;
diff --git a/include/linux/mmc/sh_mobile_sdhi.h b/include/linux/mmc/sh_mobile_sdhi.h
index e94e620aeddc..b65679ffa880 100644
--- a/include/linux/mmc/sh_mobile_sdhi.h
+++ b/include/linux/mmc/sh_mobile_sdhi.h
@@ -23,6 +23,7 @@ struct sh_mobile_sdhi_info {
23 int dma_slave_rx; 23 int dma_slave_rx;
24 unsigned long tmio_flags; 24 unsigned long tmio_flags;
25 unsigned long tmio_caps; 25 unsigned long tmio_caps;
26 unsigned long tmio_caps2;
26 u32 tmio_ocr_mask; /* available MMC voltages */ 27 u32 tmio_ocr_mask; /* available MMC voltages */
27 unsigned int cd_gpio; 28 unsigned int cd_gpio;
28 struct tmio_mmc_data *pdata; 29 struct tmio_mmc_data *pdata;
diff --git a/include/linux/mmc/slot-gpio.h b/include/linux/mmc/slot-gpio.h
new file mode 100644
index 000000000000..7d88d27bfafa
--- /dev/null
+++ b/include/linux/mmc/slot-gpio.h
@@ -0,0 +1,24 @@
1/*
2 * Generic GPIO card-detect helper header
3 *
4 * Copyright (C) 2011, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#ifndef MMC_SLOT_GPIO_H
12#define MMC_SLOT_GPIO_H
13
14struct mmc_host;
15
16int mmc_gpio_get_ro(struct mmc_host *host);
17int mmc_gpio_request_ro(struct mmc_host *host, unsigned int gpio);
18void mmc_gpio_free_ro(struct mmc_host *host);
19
20int mmc_gpio_get_cd(struct mmc_host *host);
21int mmc_gpio_request_cd(struct mmc_host *host, unsigned int gpio);
22void mmc_gpio_free_cd(struct mmc_host *host);
23
24#endif