aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-10-28 17:16:11 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-10-28 17:16:11 -0400
commit46b51ea2099fa2082342e52b8284aa828429b80b (patch)
tree0a0d7bfe1aff036c86a2e7beacbd91398008bfb6
parent1fdb24e969110fafea36d3b393bea438f702c87f (diff)
parenta6029e1f75bb484c1f5bc68b6a8572e4024795bc (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (83 commits) mmc: fix compile error when CONFIG_BLOCK is not enabled mmc: core: Cleanup eMMC4.5 conditionals mmc: omap_hsmmc: if multiblock reads are broken, disable them mmc: core: add workaround for controllers with broken multiblock reads mmc: core: Prevent too long response times for suspend mmc: recognise SDIO cards with SDIO_CCCR_REV 3.00 mmc: sd: Handle SD3.0 cards not supporting UHS-I bus speed mode mmc: core: support HPI send command mmc: core: Add cache control for eMMC4.5 device mmc: core: Modify the timeout value for writing power class mmc: core: new discard feature support at eMMC v4.5 mmc: core: mmc sanitize feature support for v4.5 mmc: dw_mmc: modify DATA register offset mmc: sdhci-pci: add flag for devices that can support runtime PM mmc: omap_hsmmc: ensure pbias configuration is always done mmc: core: Add Power Off Notify Feature eMMC 4.5 mmc: sdhci-s3c: fix potential NULL dereference mmc: replace printk with appropriate display macro mmc: core: Add default timeout value for CMD6 mmc: sdhci-pci: add runtime pm support ...
-rw-r--r--Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt27
-rw-r--r--Documentation/fault-injection/fault-injection.txt8
-rw-r--r--arch/arm/mach-at91/at91sam9260_devices.c2
-rw-r--r--arch/arm/mach-msm/devices-msm7x00.c24
-rw-r--r--arch/arm/mach-msm/devices-qsd8x50.c24
-rw-r--r--arch/arm/mach-msm/include/mach/mmc.h9
-rw-r--r--arch/arm/mach-shmobile/board-ag5evm.c6
-rw-r--r--arch/arm/mach-shmobile/board-mackerel.c6
-rw-r--r--arch/arm/plat-omap/include/plat/mmc.h19
-rw-r--r--drivers/mmc/card/block.c310
-rw-r--r--drivers/mmc/card/mmc_test.c65
-rw-r--r--drivers/mmc/card/queue.c8
-rw-r--r--drivers/mmc/card/sdio_uart.c10
-rw-r--r--drivers/mmc/core/bus.c6
-rw-r--r--drivers/mmc/core/core.c426
-rw-r--r--drivers/mmc/core/core.h1
-rw-r--r--drivers/mmc/core/debugfs.c28
-rw-r--r--drivers/mmc/core/host.c11
-rw-r--r--drivers/mmc/core/mmc.c287
-rw-r--r--drivers/mmc/core/mmc_ops.c39
-rw-r--r--drivers/mmc/core/mmc_ops.h1
-rw-r--r--drivers/mmc/core/quirks.c11
-rw-r--r--drivers/mmc/core/sd.c49
-rw-r--r--drivers/mmc/core/sd_ops.c8
-rw-r--r--drivers/mmc/core/sdio.c11
-rw-r--r--drivers/mmc/core/sdio_bus.c2
-rw-r--r--drivers/mmc/core/sdio_cis.c4
-rw-r--r--drivers/mmc/core/sdio_irq.c6
-rw-r--r--drivers/mmc/core/sdio_ops.c9
-rw-r--r--drivers/mmc/host/Kconfig16
-rw-r--r--drivers/mmc/host/at91_mci.c6
-rw-r--r--drivers/mmc/host/atmel-mci-regs.h220
-rw-r--r--drivers/mmc/host/atmel-mci.c823
-rw-r--r--drivers/mmc/host/au1xmmc.c10
-rw-r--r--drivers/mmc/host/dw_mmc.c104
-rw-r--r--drivers/mmc/host/dw_mmc.h15
-rw-r--r--drivers/mmc/host/imxmmc.c2
-rw-r--r--drivers/mmc/host/mmc_spi.c1
-rw-r--r--drivers/mmc/host/mmci.c4
-rw-r--r--drivers/mmc/host/msm_sdcc.c86
-rw-r--r--drivers/mmc/host/msm_sdcc.h6
-rw-r--r--drivers/mmc/host/mvsdio.c14
-rw-r--r--drivers/mmc/host/mxcmmc.c2
-rw-r--r--drivers/mmc/host/mxs-mmc.c1
-rw-r--r--drivers/mmc/host/omap_hsmmc.c32
-rw-r--r--drivers/mmc/host/pxamci.c2
-rw-r--r--drivers/mmc/host/s3cmci.c4
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c80
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c19
-rw-r--r--drivers/mmc/host/sdhci-of-hlwd.c1
-rw-r--r--drivers/mmc/host/sdhci-pci.c268
-rw-r--r--drivers/mmc/host/sdhci-pltfm.c1
-rw-r--r--drivers/mmc/host/sdhci-pxav2.c5
-rw-r--r--drivers/mmc/host/sdhci-pxav3.c1
-rw-r--r--drivers/mmc/host/sdhci-s3c.c34
-rw-r--r--drivers/mmc/host/sdhci-spear.c3
-rw-r--r--drivers/mmc/host/sdhci-tegra.c55
-rw-r--r--drivers/mmc/host/sdhci.c358
-rw-r--r--drivers/mmc/host/sdhci.h7
-rw-r--r--drivers/mmc/host/sdricoh_cs.c1
-rw-r--r--drivers/mmc/host/sh_mmcif.c21
-rw-r--r--drivers/mmc/host/sh_mobile_sdhi.c99
-rw-r--r--drivers/mmc/host/tifm_sd.c19
-rw-r--r--drivers/mmc/host/tmio_mmc.c4
-rw-r--r--drivers/mmc/host/tmio_mmc.h7
-rw-r--r--drivers/mmc/host/tmio_mmc_pio.c151
-rw-r--r--drivers/mmc/host/via-sdmmc.c3
-rw-r--r--drivers/mmc/host/wbsd.c22
-rw-r--r--include/linux/atmel-mci.h4
-rw-r--r--include/linux/atmel_pdc.h2
-rw-r--r--include/linux/mmc/card.h58
-rw-r--r--include/linux/mmc/core.h9
-rw-r--r--include/linux/mmc/dw_mmc.h4
-rw-r--r--include/linux/mmc/host.h29
-rw-r--r--include/linux/mmc/mmc.h38
-rw-r--r--include/linux/mmc/sdhci.h8
-rw-r--r--include/linux/mmc/sdio.h2
-rw-r--r--include/linux/mmc/sh_mmcif.h4
-rw-r--r--include/linux/mmc/sh_mobile_sdhi.h4
-rw-r--r--lib/Kconfig.debug11
-rw-r--r--lib/fault-inject.c5
81 files changed, 3093 insertions, 1009 deletions
diff --git a/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt b/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt
new file mode 100644
index 000000000000..7e51154679a6
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/nvidia-sdhci.txt
@@ -0,0 +1,27 @@
1* NVIDIA Tegra Secure Digital Host Controller
2
3This controller on Tegra family SoCs provides an interface for MMC, SD,
4and SDIO types of memory cards.
5
6Required properties:
7- compatible : Should be "nvidia,<chip>-sdhci"
8- reg : Should contain SD/MMC registers location and length
9- interrupts : Should contain SD/MMC interrupt
10
11Optional properties:
12- cd-gpios : Specify GPIOs for card detection
13- wp-gpios : Specify GPIOs for write protection
14- power-gpios : Specify GPIOs for power control
15- support-8bit : Boolean, indicates if 8-bit mode should be used.
16
17Example:
18
19sdhci@c8000200 {
20 compatible = "nvidia,tegra20-sdhci";
21 reg = <0xc8000200 0x200>;
22 interrupts = <47>;
23 cd-gpios = <&gpio 69 0>; /* gpio PI5 */
24 wp-gpios = <&gpio 57 0>; /* gpio PH1 */
25 power-gpios = <&gpio 155 0>; /* gpio PT3 */
26 support-8bit;
27};
diff --git a/Documentation/fault-injection/fault-injection.txt b/Documentation/fault-injection/fault-injection.txt
index 82a5d250d75e..ba4be8b77093 100644
--- a/Documentation/fault-injection/fault-injection.txt
+++ b/Documentation/fault-injection/fault-injection.txt
@@ -21,6 +21,11 @@ o fail_make_request
21 /sys/block/<device>/make-it-fail or 21 /sys/block/<device>/make-it-fail or
22 /sys/block/<device>/<partition>/make-it-fail. (generic_make_request()) 22 /sys/block/<device>/<partition>/make-it-fail. (generic_make_request())
23 23
24o fail_mmc_request
25
26 injects MMC data errors on devices permitted by setting
27 debugfs entries under /sys/kernel/debug/mmc0/fail_mmc_request
28
24Configure fault-injection capabilities behavior 29Configure fault-injection capabilities behavior
25----------------------------------------------- 30-----------------------------------------------
26 31
@@ -115,7 +120,8 @@ use the boot option:
115 120
116 failslab= 121 failslab=
117 fail_page_alloc= 122 fail_page_alloc=
118 fail_make_request=<interval>,<probability>,<space>,<times> 123 fail_make_request=
124 mmc_core.fail_request=<interval>,<probability>,<space>,<times>
119 125
120How to add new fault injection capability 126How to add new fault injection capability
121----------------------------------------- 127-----------------------------------------
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c
index a53b3de9daa2..3c2b580b9d75 100644
--- a/arch/arm/mach-at91/at91sam9260_devices.c
+++ b/arch/arm/mach-at91/at91sam9260_devices.c
@@ -319,7 +319,7 @@ void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
319 if (!data) 319 if (!data)
320 return; 320 return;
321 321
322 for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) { 322 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
323 if (data->slot[i].bus_width) { 323 if (data->slot[i].bus_width) {
324 /* input/irq */ 324 /* input/irq */
325 if (data->slot[i].detect_pin) { 325 if (data->slot[i].detect_pin) {
diff --git a/arch/arm/mach-msm/devices-msm7x00.c b/arch/arm/mach-msm/devices-msm7x00.c
index c4f5e26feb4d..993780f490ad 100644
--- a/arch/arm/mach-msm/devices-msm7x00.c
+++ b/arch/arm/mach-msm/devices-msm7x00.c
@@ -176,12 +176,6 @@ static struct resource resources_sdc1[] = {
176 .name = "cmd_irq", 176 .name = "cmd_irq",
177 }, 177 },
178 { 178 {
179 .start = INT_SDC1_1,
180 .end = INT_SDC1_1,
181 .flags = IORESOURCE_IRQ,
182 .name = "pio_irq",
183 },
184 {
185 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 179 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
186 .name = "status_irq" 180 .name = "status_irq"
187 }, 181 },
@@ -204,12 +198,6 @@ static struct resource resources_sdc2[] = {
204 .flags = IORESOURCE_IRQ, 198 .flags = IORESOURCE_IRQ,
205 .name = "cmd_irq", 199 .name = "cmd_irq",
206 }, 200 },
207 {
208 .start = INT_SDC2_1,
209 .end = INT_SDC2_1,
210 .flags = IORESOURCE_IRQ,
211 .name = "pio_irq",
212 },
213 { 201 {
214 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 202 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
215 .name = "status_irq" 203 .name = "status_irq"
@@ -233,12 +221,6 @@ static struct resource resources_sdc3[] = {
233 .flags = IORESOURCE_IRQ, 221 .flags = IORESOURCE_IRQ,
234 .name = "cmd_irq", 222 .name = "cmd_irq",
235 }, 223 },
236 {
237 .start = INT_SDC3_1,
238 .end = INT_SDC3_1,
239 .flags = IORESOURCE_IRQ,
240 .name = "pio_irq",
241 },
242 { 224 {
243 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 225 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
244 .name = "status_irq" 226 .name = "status_irq"
@@ -262,12 +244,6 @@ static struct resource resources_sdc4[] = {
262 .flags = IORESOURCE_IRQ, 244 .flags = IORESOURCE_IRQ,
263 .name = "cmd_irq", 245 .name = "cmd_irq",
264 }, 246 },
265 {
266 .start = INT_SDC4_1,
267 .end = INT_SDC4_1,
268 .flags = IORESOURCE_IRQ,
269 .name = "pio_irq",
270 },
271 { 247 {
272 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 248 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
273 .name = "status_irq" 249 .name = "status_irq"
diff --git a/arch/arm/mach-msm/devices-qsd8x50.c b/arch/arm/mach-msm/devices-qsd8x50.c
index 12d8deb78d9c..131633b12a34 100644
--- a/arch/arm/mach-msm/devices-qsd8x50.c
+++ b/arch/arm/mach-msm/devices-qsd8x50.c
@@ -140,12 +140,6 @@ static struct resource resources_sdc1[] = {
140 .name = "cmd_irq", 140 .name = "cmd_irq",
141 }, 141 },
142 { 142 {
143 .start = INT_SDC1_1,
144 .end = INT_SDC1_1,
145 .flags = IORESOURCE_IRQ,
146 .name = "pio_irq",
147 },
148 {
149 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 143 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
150 .name = "status_irq" 144 .name = "status_irq"
151 }, 145 },
@@ -168,12 +162,6 @@ static struct resource resources_sdc2[] = {
168 .flags = IORESOURCE_IRQ, 162 .flags = IORESOURCE_IRQ,
169 .name = "cmd_irq", 163 .name = "cmd_irq",
170 }, 164 },
171 {
172 .start = INT_SDC2_1,
173 .end = INT_SDC2_1,
174 .flags = IORESOURCE_IRQ,
175 .name = "pio_irq",
176 },
177 { 165 {
178 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 166 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
179 .name = "status_irq" 167 .name = "status_irq"
@@ -197,12 +185,6 @@ static struct resource resources_sdc3[] = {
197 .flags = IORESOURCE_IRQ, 185 .flags = IORESOURCE_IRQ,
198 .name = "cmd_irq", 186 .name = "cmd_irq",
199 }, 187 },
200 {
201 .start = INT_SDC3_1,
202 .end = INT_SDC3_1,
203 .flags = IORESOURCE_IRQ,
204 .name = "pio_irq",
205 },
206 { 188 {
207 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 189 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
208 .name = "status_irq" 190 .name = "status_irq"
@@ -226,12 +208,6 @@ static struct resource resources_sdc4[] = {
226 .flags = IORESOURCE_IRQ, 208 .flags = IORESOURCE_IRQ,
227 .name = "cmd_irq", 209 .name = "cmd_irq",
228 }, 210 },
229 {
230 .start = INT_SDC4_1,
231 .end = INT_SDC4_1,
232 .flags = IORESOURCE_IRQ,
233 .name = "pio_irq",
234 },
235 { 211 {
236 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED, 212 .flags = IORESOURCE_IRQ | IORESOURCE_DISABLED,
237 .name = "status_irq" 213 .name = "status_irq"
diff --git a/arch/arm/mach-msm/include/mach/mmc.h b/arch/arm/mach-msm/include/mach/mmc.h
index 5631b51cec46..ffcd9e3a6a7e 100644
--- a/arch/arm/mach-msm/include/mach/mmc.h
+++ b/arch/arm/mach-msm/include/mach/mmc.h
@@ -8,13 +8,6 @@
8#include <linux/mmc/card.h> 8#include <linux/mmc/card.h>
9#include <linux/mmc/sdio_func.h> 9#include <linux/mmc/sdio_func.h>
10 10
11struct embedded_sdio_data {
12 struct sdio_cis cis;
13 struct sdio_cccr cccr;
14 struct sdio_embedded_func *funcs;
15 int num_funcs;
16};
17
18struct msm_mmc_gpio { 11struct msm_mmc_gpio {
19 unsigned no; 12 unsigned no;
20 const char *name; 13 const char *name;
@@ -29,9 +22,9 @@ struct msm_mmc_platform_data {
29 unsigned int ocr_mask; /* available voltages */ 22 unsigned int ocr_mask; /* available voltages */
30 u32 (*translate_vdd)(struct device *, unsigned int); 23 u32 (*translate_vdd)(struct device *, unsigned int);
31 unsigned int (*status)(struct device *); 24 unsigned int (*status)(struct device *);
32 struct embedded_sdio_data *embedded_sdio;
33 int (*register_status_notify)(void (*callback)(int card_present, void *dev_id), void *dev_id); 25 int (*register_status_notify)(void (*callback)(int card_present, void *dev_id), void *dev_id);
34 struct msm_mmc_gpio_data *gpio_data; 26 struct msm_mmc_gpio_data *gpio_data;
27 void (*init_card)(struct mmc_card *card);
35}; 28};
36 29
37#endif 30#endif
diff --git a/arch/arm/mach-shmobile/board-ag5evm.c b/arch/arm/mach-shmobile/board-ag5evm.c
index 5fde49da399a..475342bcc95c 100644
--- a/arch/arm/mach-shmobile/board-ag5evm.c
+++ b/arch/arm/mach-shmobile/board-ag5evm.c
@@ -355,14 +355,17 @@ static struct resource sdhi0_resources[] = {
355 .flags = IORESOURCE_MEM, 355 .flags = IORESOURCE_MEM,
356 }, 356 },
357 [1] = { 357 [1] = {
358 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
358 .start = gic_spi(83), 359 .start = gic_spi(83),
359 .flags = IORESOURCE_IRQ, 360 .flags = IORESOURCE_IRQ,
360 }, 361 },
361 [2] = { 362 [2] = {
363 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
362 .start = gic_spi(84), 364 .start = gic_spi(84),
363 .flags = IORESOURCE_IRQ, 365 .flags = IORESOURCE_IRQ,
364 }, 366 },
365 [3] = { 367 [3] = {
368 .name = SH_MOBILE_SDHI_IRQ_SDIO,
366 .start = gic_spi(85), 369 .start = gic_spi(85),
367 .flags = IORESOURCE_IRQ, 370 .flags = IORESOURCE_IRQ,
368 }, 371 },
@@ -398,14 +401,17 @@ static struct resource sdhi1_resources[] = {
398 .flags = IORESOURCE_MEM, 401 .flags = IORESOURCE_MEM,
399 }, 402 },
400 [1] = { 403 [1] = {
404 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
401 .start = gic_spi(87), 405 .start = gic_spi(87),
402 .flags = IORESOURCE_IRQ, 406 .flags = IORESOURCE_IRQ,
403 }, 407 },
404 [2] = { 408 [2] = {
409 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
405 .start = gic_spi(88), 410 .start = gic_spi(88),
406 .flags = IORESOURCE_IRQ, 411 .flags = IORESOURCE_IRQ,
407 }, 412 },
408 [3] = { 413 [3] = {
414 .name = SH_MOBILE_SDHI_IRQ_SDIO,
409 .start = gic_spi(89), 415 .start = gic_spi(89),
410 .flags = IORESOURCE_IRQ, 416 .flags = IORESOURCE_IRQ,
411 }, 417 },
diff --git a/arch/arm/mach-shmobile/board-mackerel.c b/arch/arm/mach-shmobile/board-mackerel.c
index 7d073c121941..4de92dc570b0 100644
--- a/arch/arm/mach-shmobile/board-mackerel.c
+++ b/arch/arm/mach-shmobile/board-mackerel.c
@@ -1072,14 +1072,17 @@ static struct resource sdhi1_resources[] = {
1072 .flags = IORESOURCE_MEM, 1072 .flags = IORESOURCE_MEM,
1073 }, 1073 },
1074 [1] = { 1074 [1] = {
1075 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
1075 .start = evt2irq(0x0e80), /* SDHI1_SDHI1I0 */ 1076 .start = evt2irq(0x0e80), /* SDHI1_SDHI1I0 */
1076 .flags = IORESOURCE_IRQ, 1077 .flags = IORESOURCE_IRQ,
1077 }, 1078 },
1078 [2] = { 1079 [2] = {
1080 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1079 .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */ 1081 .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
1080 .flags = IORESOURCE_IRQ, 1082 .flags = IORESOURCE_IRQ,
1081 }, 1083 },
1082 [3] = { 1084 [3] = {
1085 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1083 .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */ 1086 .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
1084 .flags = IORESOURCE_IRQ, 1087 .flags = IORESOURCE_IRQ,
1085 }, 1088 },
@@ -1123,14 +1126,17 @@ static struct resource sdhi2_resources[] = {
1123 .flags = IORESOURCE_MEM, 1126 .flags = IORESOURCE_MEM,
1124 }, 1127 },
1125 [1] = { 1128 [1] = {
1129 .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
1126 .start = evt2irq(0x1200), /* SDHI2_SDHI2I0 */ 1130 .start = evt2irq(0x1200), /* SDHI2_SDHI2I0 */
1127 .flags = IORESOURCE_IRQ, 1131 .flags = IORESOURCE_IRQ,
1128 }, 1132 },
1129 [2] = { 1133 [2] = {
1134 .name = SH_MOBILE_SDHI_IRQ_SDCARD,
1130 .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */ 1135 .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
1131 .flags = IORESOURCE_IRQ, 1136 .flags = IORESOURCE_IRQ,
1132 }, 1137 },
1133 [3] = { 1138 [3] = {
1139 .name = SH_MOBILE_SDHI_IRQ_SDIO,
1134 .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */ 1140 .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
1135 .flags = IORESOURCE_IRQ, 1141 .flags = IORESOURCE_IRQ,
1136 }, 1142 },
diff --git a/arch/arm/plat-omap/include/plat/mmc.h b/arch/arm/plat-omap/include/plat/mmc.h
index c7b874186c27..94cf70afb236 100644
--- a/arch/arm/plat-omap/include/plat/mmc.h
+++ b/arch/arm/plat-omap/include/plat/mmc.h
@@ -31,7 +31,24 @@
31 31
32#define OMAP_MMC_MAX_SLOTS 2 32#define OMAP_MMC_MAX_SLOTS 2
33 33
34#define OMAP_HSMMC_SUPPORTS_DUAL_VOLT BIT(1) 34/*
35 * struct omap_mmc_dev_attr.flags possibilities
36 *
37 * OMAP_HSMMC_SUPPORTS_DUAL_VOLT: Some HSMMC controller instances can
38 * operate with either 1.8Vdc or 3.0Vdc card voltages; this flag
39 * should be set if this is the case. See for example Section 22.5.3
40 * "MMC/SD/SDIO1 Bus Voltage Selection" of the OMAP34xx Multimedia
41 * Device Silicon Revision 3.1.x Revision ZR (July 2011) (SWPU223R).
42 *
43 * OMAP_HSMMC_BROKEN_MULTIBLOCK_READ: Multiple-block read transfers
44 * don't work correctly on some MMC controller instances on some
45 * OMAP3 SoCs; this flag should be set if this is the case. See
46 * for example Advisory 2.1.1.128 "MMC: Multiple Block Read
47 * Operation Issue" in _OMAP3530/3525/3515/3503 Silicon Errata_
48 * Revision F (October 2010) (SPRZ278F).
49 */
50#define OMAP_HSMMC_SUPPORTS_DUAL_VOLT BIT(0)
51#define OMAP_HSMMC_BROKEN_MULTIBLOCK_READ BIT(1)
35 52
36struct omap_mmc_dev_attr { 53struct omap_mmc_dev_attr {
37 u8 flags; 54 u8 flags;
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 4c1a648d00fc..a1cb21f95302 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -94,6 +94,11 @@ struct mmc_blk_data {
94 unsigned int read_only; 94 unsigned int read_only;
95 unsigned int part_type; 95 unsigned int part_type;
96 unsigned int name_idx; 96 unsigned int name_idx;
97 unsigned int reset_done;
98#define MMC_BLK_READ BIT(0)
99#define MMC_BLK_WRITE BIT(1)
100#define MMC_BLK_DISCARD BIT(2)
101#define MMC_BLK_SECDISCARD BIT(3)
97 102
98 /* 103 /*
99 * Only set in main mmc_blk_data associated 104 * Only set in main mmc_blk_data associated
@@ -109,11 +114,11 @@ static DEFINE_MUTEX(open_lock);
109enum mmc_blk_status { 114enum mmc_blk_status {
110 MMC_BLK_SUCCESS = 0, 115 MMC_BLK_SUCCESS = 0,
111 MMC_BLK_PARTIAL, 116 MMC_BLK_PARTIAL,
112 MMC_BLK_RETRY,
113 MMC_BLK_RETRY_SINGLE,
114 MMC_BLK_DATA_ERR,
115 MMC_BLK_CMD_ERR, 117 MMC_BLK_CMD_ERR,
118 MMC_BLK_RETRY,
116 MMC_BLK_ABORT, 119 MMC_BLK_ABORT,
120 MMC_BLK_DATA_ERR,
121 MMC_BLK_ECC_ERR,
117}; 122};
118 123
119module_param(perdev_minors, int, 0444); 124module_param(perdev_minors, int, 0444);
@@ -291,7 +296,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
291 struct mmc_card *card; 296 struct mmc_card *card;
292 struct mmc_command cmd = {0}; 297 struct mmc_command cmd = {0};
293 struct mmc_data data = {0}; 298 struct mmc_data data = {0};
294 struct mmc_request mrq = {0}; 299 struct mmc_request mrq = {NULL};
295 struct scatterlist sg; 300 struct scatterlist sg;
296 int err; 301 int err;
297 302
@@ -442,19 +447,24 @@ static inline int mmc_blk_part_switch(struct mmc_card *card,
442{ 447{
443 int ret; 448 int ret;
444 struct mmc_blk_data *main_md = mmc_get_drvdata(card); 449 struct mmc_blk_data *main_md = mmc_get_drvdata(card);
450
445 if (main_md->part_curr == md->part_type) 451 if (main_md->part_curr == md->part_type)
446 return 0; 452 return 0;
447 453
448 if (mmc_card_mmc(card)) { 454 if (mmc_card_mmc(card)) {
449 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; 455 u8 part_config = card->ext_csd.part_config;
450 card->ext_csd.part_config |= md->part_type; 456
457 part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
458 part_config |= md->part_type;
451 459
452 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 460 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
453 EXT_CSD_PART_CONFIG, card->ext_csd.part_config, 461 EXT_CSD_PART_CONFIG, part_config,
454 card->ext_csd.part_time); 462 card->ext_csd.part_time);
455 if (ret) 463 if (ret)
456 return ret; 464 return ret;
457} 465
466 card->ext_csd.part_config = part_config;
467 }
458 468
459 main_md->part_curr = md->part_type; 469 main_md->part_curr = md->part_type;
460 return 0; 470 return 0;
@@ -466,7 +476,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
466 u32 result; 476 u32 result;
467 __be32 *blocks; 477 __be32 *blocks;
468 478
469 struct mmc_request mrq = {0}; 479 struct mmc_request mrq = {NULL};
470 struct mmc_command cmd = {0}; 480 struct mmc_command cmd = {0};
471 struct mmc_data data = {0}; 481 struct mmc_data data = {0};
472 unsigned int timeout_us; 482 unsigned int timeout_us;
@@ -616,7 +626,7 @@ static int mmc_blk_cmd_error(struct request *req, const char *name, int error,
616 * Otherwise we don't understand what happened, so abort. 626 * Otherwise we don't understand what happened, so abort.
617 */ 627 */
618static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req, 628static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
619 struct mmc_blk_request *brq) 629 struct mmc_blk_request *brq, int *ecc_err)
620{ 630{
621 bool prev_cmd_status_valid = true; 631 bool prev_cmd_status_valid = true;
622 u32 status, stop_status = 0; 632 u32 status, stop_status = 0;
@@ -641,6 +651,12 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
641 if (err) 651 if (err)
642 return ERR_ABORT; 652 return ERR_ABORT;
643 653
654 /* Flag ECC errors */
655 if ((status & R1_CARD_ECC_FAILED) ||
656 (brq->stop.resp[0] & R1_CARD_ECC_FAILED) ||
657 (brq->cmd.resp[0] & R1_CARD_ECC_FAILED))
658 *ecc_err = 1;
659
644 /* 660 /*
645 * Check the current card state. If it is in some data transfer 661 * Check the current card state. If it is in some data transfer
646 * mode, tell it to stop (and hopefully transition back to TRAN.) 662 * mode, tell it to stop (and hopefully transition back to TRAN.)
@@ -658,6 +674,8 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
658 */ 674 */
659 if (err) 675 if (err)
660 return ERR_ABORT; 676 return ERR_ABORT;
677 if (stop_status & R1_CARD_ECC_FAILED)
678 *ecc_err = 1;
661 } 679 }
662 680
663 /* Check for set block count errors */ 681 /* Check for set block count errors */
@@ -670,6 +688,10 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
670 return mmc_blk_cmd_error(req, "r/w cmd", brq->cmd.error, 688 return mmc_blk_cmd_error(req, "r/w cmd", brq->cmd.error,
671 prev_cmd_status_valid, status); 689 prev_cmd_status_valid, status);
672 690
691 /* Data errors */
692 if (!brq->stop.error)
693 return ERR_CONTINUE;
694
673 /* Now for stop errors. These aren't fatal to the transfer. */ 695 /* Now for stop errors. These aren't fatal to the transfer. */
674 pr_err("%s: error %d sending stop command, original cmd response %#x, card status %#x\n", 696 pr_err("%s: error %d sending stop command, original cmd response %#x, card status %#x\n",
675 req->rq_disk->disk_name, brq->stop.error, 697 req->rq_disk->disk_name, brq->stop.error,
@@ -686,12 +708,45 @@ static int mmc_blk_cmd_recovery(struct mmc_card *card, struct request *req,
686 return ERR_CONTINUE; 708 return ERR_CONTINUE;
687} 709}
688 710
711static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
712 int type)
713{
714 int err;
715
716 if (md->reset_done & type)
717 return -EEXIST;
718
719 md->reset_done |= type;
720 err = mmc_hw_reset(host);
721 /* Ensure we switch back to the correct partition */
722 if (err != -EOPNOTSUPP) {
723 struct mmc_blk_data *main_md = mmc_get_drvdata(host->card);
724 int part_err;
725
726 main_md->part_curr = main_md->part_type;
727 part_err = mmc_blk_part_switch(host->card, md);
728 if (part_err) {
729 /*
730 * We have failed to get back into the correct
731 * partition, so we need to abort the whole request.
732 */
733 return -ENODEV;
734 }
735 }
736 return err;
737}
738
739static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
740{
741 md->reset_done &= ~type;
742}
743
689static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req) 744static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
690{ 745{
691 struct mmc_blk_data *md = mq->data; 746 struct mmc_blk_data *md = mq->data;
692 struct mmc_card *card = md->queue.card; 747 struct mmc_card *card = md->queue.card;
693 unsigned int from, nr, arg; 748 unsigned int from, nr, arg;
694 int err = 0; 749 int err = 0, type = MMC_BLK_DISCARD;
695 750
696 if (!mmc_can_erase(card)) { 751 if (!mmc_can_erase(card)) {
697 err = -EOPNOTSUPP; 752 err = -EOPNOTSUPP;
@@ -701,11 +756,13 @@ static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
701 from = blk_rq_pos(req); 756 from = blk_rq_pos(req);
702 nr = blk_rq_sectors(req); 757 nr = blk_rq_sectors(req);
703 758
704 if (mmc_can_trim(card)) 759 if (mmc_can_discard(card))
760 arg = MMC_DISCARD_ARG;
761 else if (mmc_can_trim(card))
705 arg = MMC_TRIM_ARG; 762 arg = MMC_TRIM_ARG;
706 else 763 else
707 arg = MMC_ERASE_ARG; 764 arg = MMC_ERASE_ARG;
708 765retry:
709 if (card->quirks & MMC_QUIRK_INAND_CMD38) { 766 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
710 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 767 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
711 INAND_CMD38_ARG_EXT_CSD, 768 INAND_CMD38_ARG_EXT_CSD,
@@ -718,6 +775,10 @@ static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
718 } 775 }
719 err = mmc_erase(card, from, nr, arg); 776 err = mmc_erase(card, from, nr, arg);
720out: 777out:
778 if (err == -EIO && !mmc_blk_reset(md, card->host, type))
779 goto retry;
780 if (!err)
781 mmc_blk_reset_success(md, type);
721 spin_lock_irq(&md->lock); 782 spin_lock_irq(&md->lock);
722 __blk_end_request(req, err, blk_rq_bytes(req)); 783 __blk_end_request(req, err, blk_rq_bytes(req));
723 spin_unlock_irq(&md->lock); 784 spin_unlock_irq(&md->lock);
@@ -731,13 +792,20 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
731 struct mmc_blk_data *md = mq->data; 792 struct mmc_blk_data *md = mq->data;
732 struct mmc_card *card = md->queue.card; 793 struct mmc_card *card = md->queue.card;
733 unsigned int from, nr, arg; 794 unsigned int from, nr, arg;
734 int err = 0; 795 int err = 0, type = MMC_BLK_SECDISCARD;
735 796
736 if (!mmc_can_secure_erase_trim(card)) { 797 if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
737 err = -EOPNOTSUPP; 798 err = -EOPNOTSUPP;
738 goto out; 799 goto out;
739 } 800 }
740 801
802 /* The sanitize operation is supported at v4.5 only */
803 if (mmc_can_sanitize(card)) {
804 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
805 EXT_CSD_SANITIZE_START, 1, 0);
806 goto out;
807 }
808
741 from = blk_rq_pos(req); 809 from = blk_rq_pos(req);
742 nr = blk_rq_sectors(req); 810 nr = blk_rq_sectors(req);
743 811
@@ -745,7 +813,7 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
745 arg = MMC_SECURE_TRIM1_ARG; 813 arg = MMC_SECURE_TRIM1_ARG;
746 else 814 else
747 arg = MMC_SECURE_ERASE_ARG; 815 arg = MMC_SECURE_ERASE_ARG;
748 816retry:
749 if (card->quirks & MMC_QUIRK_INAND_CMD38) { 817 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
750 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 818 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
751 INAND_CMD38_ARG_EXT_CSD, 819 INAND_CMD38_ARG_EXT_CSD,
@@ -769,6 +837,10 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
769 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG); 837 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
770 } 838 }
771out: 839out:
840 if (err == -EIO && !mmc_blk_reset(md, card->host, type))
841 goto retry;
842 if (!err)
843 mmc_blk_reset_success(md, type);
772 spin_lock_irq(&md->lock); 844 spin_lock_irq(&md->lock);
773 __blk_end_request(req, err, blk_rq_bytes(req)); 845 __blk_end_request(req, err, blk_rq_bytes(req));
774 spin_unlock_irq(&md->lock); 846 spin_unlock_irq(&md->lock);
@@ -779,16 +851,18 @@ out:
779static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req) 851static int mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
780{ 852{
781 struct mmc_blk_data *md = mq->data; 853 struct mmc_blk_data *md = mq->data;
854 struct mmc_card *card = md->queue.card;
855 int ret = 0;
856
857 ret = mmc_flush_cache(card);
858 if (ret)
859 ret = -EIO;
782 860
783 /*
784 * No-op, only service this because we need REQ_FUA for reliable
785 * writes.
786 */
787 spin_lock_irq(&md->lock); 861 spin_lock_irq(&md->lock);
788 __blk_end_request_all(req, 0); 862 __blk_end_request_all(req, ret);
789 spin_unlock_irq(&md->lock); 863 spin_unlock_irq(&md->lock);
790 864
791 return 1; 865 return ret ? 0 : 1;
792} 866}
793 867
794/* 868/*
@@ -825,11 +899,11 @@ static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
825static int mmc_blk_err_check(struct mmc_card *card, 899static int mmc_blk_err_check(struct mmc_card *card,
826 struct mmc_async_req *areq) 900 struct mmc_async_req *areq)
827{ 901{
828 enum mmc_blk_status ret = MMC_BLK_SUCCESS;
829 struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req, 902 struct mmc_queue_req *mq_mrq = container_of(areq, struct mmc_queue_req,
830 mmc_active); 903 mmc_active);
831 struct mmc_blk_request *brq = &mq_mrq->brq; 904 struct mmc_blk_request *brq = &mq_mrq->brq;
832 struct request *req = mq_mrq->req; 905 struct request *req = mq_mrq->req;
906 int ecc_err = 0;
833 907
834 /* 908 /*
835 * sbc.error indicates a problem with the set block count 909 * sbc.error indicates a problem with the set block count
@@ -841,8 +915,9 @@ static int mmc_blk_err_check(struct mmc_card *card,
841 * stop.error indicates a problem with the stop command. Data 915 * stop.error indicates a problem with the stop command. Data
842 * may have been transferred, or may still be transferring. 916 * may have been transferred, or may still be transferring.
843 */ 917 */
844 if (brq->sbc.error || brq->cmd.error || brq->stop.error) { 918 if (brq->sbc.error || brq->cmd.error || brq->stop.error ||
845 switch (mmc_blk_cmd_recovery(card, req, brq)) { 919 brq->data.error) {
920 switch (mmc_blk_cmd_recovery(card, req, brq, &ecc_err)) {
846 case ERR_RETRY: 921 case ERR_RETRY:
847 return MMC_BLK_RETRY; 922 return MMC_BLK_RETRY;
848 case ERR_ABORT: 923 case ERR_ABORT:
@@ -873,7 +948,7 @@ static int mmc_blk_err_check(struct mmc_card *card,
873 do { 948 do {
874 int err = get_card_status(card, &status, 5); 949 int err = get_card_status(card, &status, 5);
875 if (err) { 950 if (err) {
876 printk(KERN_ERR "%s: error %d requesting status\n", 951 pr_err("%s: error %d requesting status\n",
877 req->rq_disk->disk_name, err); 952 req->rq_disk->disk_name, err);
878 return MMC_BLK_CMD_ERR; 953 return MMC_BLK_CMD_ERR;
879 } 954 }
@@ -894,23 +969,21 @@ static int mmc_blk_err_check(struct mmc_card *card,
894 brq->cmd.resp[0], brq->stop.resp[0]); 969 brq->cmd.resp[0], brq->stop.resp[0]);
895 970
896 if (rq_data_dir(req) == READ) { 971 if (rq_data_dir(req) == READ) {
897 if (brq->data.blocks > 1) { 972 if (ecc_err)
898 /* Redo read one sector at a time */ 973 return MMC_BLK_ECC_ERR;
899 pr_warning("%s: retrying using single block read\n",
900 req->rq_disk->disk_name);
901 return MMC_BLK_RETRY_SINGLE;
902 }
903 return MMC_BLK_DATA_ERR; 974 return MMC_BLK_DATA_ERR;
904 } else { 975 } else {
905 return MMC_BLK_CMD_ERR; 976 return MMC_BLK_CMD_ERR;
906 } 977 }
907 } 978 }
908 979
909 if (ret == MMC_BLK_SUCCESS && 980 if (!brq->data.bytes_xfered)
910 blk_rq_bytes(req) != brq->data.bytes_xfered) 981 return MMC_BLK_RETRY;
911 ret = MMC_BLK_PARTIAL;
912 982
913 return ret; 983 if (blk_rq_bytes(req) != brq->data.bytes_xfered)
984 return MMC_BLK_PARTIAL;
985
986 return MMC_BLK_SUCCESS;
914} 987}
915 988
916static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, 989static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
@@ -957,13 +1030,20 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
957 if (brq->data.blocks > card->host->max_blk_count) 1030 if (brq->data.blocks > card->host->max_blk_count)
958 brq->data.blocks = card->host->max_blk_count; 1031 brq->data.blocks = card->host->max_blk_count;
959 1032
960 /* 1033 if (brq->data.blocks > 1) {
961 * After a read error, we redo the request one sector at a time 1034 /*
962 * in order to accurately determine which sectors can be read 1035 * After a read error, we redo the request one sector
963 * successfully. 1036 * at a time in order to accurately determine which
964 */ 1037 * sectors can be read successfully.
965 if (disable_multi && brq->data.blocks > 1) 1038 */
966 brq->data.blocks = 1; 1039 if (disable_multi)
1040 brq->data.blocks = 1;
1041
1042 /* Some controllers can't do multiblock reads due to hw bugs */
1043 if (card->host->caps2 & MMC_CAP2_NO_MULTI_READ &&
1044 rq_data_dir(req) == READ)
1045 brq->data.blocks = 1;
1046 }
967 1047
968 if (brq->data.blocks > 1 || do_rel_wr) { 1048 if (brq->data.blocks > 1 || do_rel_wr) {
969 /* SPI multiblock writes terminate using a special 1049 /* SPI multiblock writes terminate using a special
@@ -1049,12 +1129,41 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
1049 mmc_queue_bounce_pre(mqrq); 1129 mmc_queue_bounce_pre(mqrq);
1050} 1130}
1051 1131
1132static int mmc_blk_cmd_err(struct mmc_blk_data *md, struct mmc_card *card,
1133 struct mmc_blk_request *brq, struct request *req,
1134 int ret)
1135{
1136 /*
1137 * If this is an SD card and we're writing, we can first
1138 * mark the known good sectors as ok.
1139 *
1140 * If the card is not SD, we can still ok written sectors
1141 * as reported by the controller (which might be less than
1142 * the real number of written sectors, but never more).
1143 */
1144 if (mmc_card_sd(card)) {
1145 u32 blocks;
1146
1147 blocks = mmc_sd_num_wr_blocks(card);
1148 if (blocks != (u32)-1) {
1149 spin_lock_irq(&md->lock);
1150 ret = __blk_end_request(req, 0, blocks << 9);
1151 spin_unlock_irq(&md->lock);
1152 }
1153 } else {
1154 spin_lock_irq(&md->lock);
1155 ret = __blk_end_request(req, 0, brq->data.bytes_xfered);
1156 spin_unlock_irq(&md->lock);
1157 }
1158 return ret;
1159}
1160
1052static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc) 1161static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1053{ 1162{
1054 struct mmc_blk_data *md = mq->data; 1163 struct mmc_blk_data *md = mq->data;
1055 struct mmc_card *card = md->queue.card; 1164 struct mmc_card *card = md->queue.card;
1056 struct mmc_blk_request *brq = &mq->mqrq_cur->brq; 1165 struct mmc_blk_request *brq = &mq->mqrq_cur->brq;
1057 int ret = 1, disable_multi = 0, retry = 0; 1166 int ret = 1, disable_multi = 0, retry = 0, type;
1058 enum mmc_blk_status status; 1167 enum mmc_blk_status status;
1059 struct mmc_queue_req *mq_rq; 1168 struct mmc_queue_req *mq_rq;
1060 struct request *req; 1169 struct request *req;
@@ -1076,6 +1185,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1076 mq_rq = container_of(areq, struct mmc_queue_req, mmc_active); 1185 mq_rq = container_of(areq, struct mmc_queue_req, mmc_active);
1077 brq = &mq_rq->brq; 1186 brq = &mq_rq->brq;
1078 req = mq_rq->req; 1187 req = mq_rq->req;
1188 type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
1079 mmc_queue_bounce_post(mq_rq); 1189 mmc_queue_bounce_post(mq_rq);
1080 1190
1081 switch (status) { 1191 switch (status) {
@@ -1084,18 +1194,18 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1084 /* 1194 /*
1085 * A block was successfully transferred. 1195 * A block was successfully transferred.
1086 */ 1196 */
1197 mmc_blk_reset_success(md, type);
1087 spin_lock_irq(&md->lock); 1198 spin_lock_irq(&md->lock);
1088 ret = __blk_end_request(req, 0, 1199 ret = __blk_end_request(req, 0,
1089 brq->data.bytes_xfered); 1200 brq->data.bytes_xfered);
1090 spin_unlock_irq(&md->lock); 1201 spin_unlock_irq(&md->lock);
1202 /*
1203 * If the blk_end_request function returns non-zero even
1204 * though all data has been transferred and no errors
1205 * were returned by the host controller, it's a bug.
1206 */
1091 if (status == MMC_BLK_SUCCESS && ret) { 1207 if (status == MMC_BLK_SUCCESS && ret) {
1092 /* 1208 pr_err("%s BUG rq_tot %d d_xfer %d\n",
1093 * The blk_end_request has returned non zero
1094 * even though all data is transfered and no
1095 * erros returned by host.
1096 * If this happen it's a bug.
1097 */
1098 printk(KERN_ERR "%s BUG rq_tot %d d_xfer %d\n",
1099 __func__, blk_rq_bytes(req), 1209 __func__, blk_rq_bytes(req),
1100 brq->data.bytes_xfered); 1210 brq->data.bytes_xfered);
1101 rqc = NULL; 1211 rqc = NULL;
@@ -1103,16 +1213,36 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1103 } 1213 }
1104 break; 1214 break;
1105 case MMC_BLK_CMD_ERR: 1215 case MMC_BLK_CMD_ERR:
1106 goto cmd_err; 1216 ret = mmc_blk_cmd_err(md, card, brq, req, ret);
1107 case MMC_BLK_RETRY_SINGLE: 1217 if (!mmc_blk_reset(md, card->host, type))
1108 disable_multi = 1; 1218 break;
1109 break; 1219 goto cmd_abort;
1110 case MMC_BLK_RETRY: 1220 case MMC_BLK_RETRY:
1111 if (retry++ < 5) 1221 if (retry++ < 5)
1112 break; 1222 break;
1223 /* Fall through */
1113 case MMC_BLK_ABORT: 1224 case MMC_BLK_ABORT:
1225 if (!mmc_blk_reset(md, card->host, type))
1226 break;
1114 goto cmd_abort; 1227 goto cmd_abort;
1115 case MMC_BLK_DATA_ERR: 1228 case MMC_BLK_DATA_ERR: {
1229 int err;
1230
1231 err = mmc_blk_reset(md, card->host, type);
1232 if (!err)
1233 break;
1234 if (err == -ENODEV)
1235 goto cmd_abort;
1236 /* Fall through */
1237 }
1238 case MMC_BLK_ECC_ERR:
1239 if (brq->data.blocks > 1) {
1240 /* Redo read one sector at a time */
1241 pr_warning("%s: retrying using single block read\n",
1242 req->rq_disk->disk_name);
1243 disable_multi = 1;
1244 break;
1245 }
1116 /* 1246 /*
1117 * After an error, we redo I/O one sector at a 1247 * After an error, we redo I/O one sector at a
1118 * time, so we only reach here after trying to 1248 * time, so we only reach here after trying to
@@ -1129,7 +1259,7 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1129 1259
1130 if (ret) { 1260 if (ret) {
1131 /* 1261 /*
1132 * In case of a none complete request 1262 * In case of a incomplete request
1133 * prepare it again and resend. 1263 * prepare it again and resend.
1134 */ 1264 */
1135 mmc_blk_rw_rq_prep(mq_rq, card, disable_multi, mq); 1265 mmc_blk_rw_rq_prep(mq_rq, card, disable_multi, mq);
@@ -1139,30 +1269,6 @@ static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
1139 1269
1140 return 1; 1270 return 1;
1141 1271
1142 cmd_err:
1143 /*
1144 * If this is an SD card and we're writing, we can first
1145 * mark the known good sectors as ok.
1146 *
1147 * If the card is not SD, we can still ok written sectors
1148 * as reported by the controller (which might be less than
1149 * the real number of written sectors, but never more).
1150 */
1151 if (mmc_card_sd(card)) {
1152 u32 blocks;
1153
1154 blocks = mmc_sd_num_wr_blocks(card);
1155 if (blocks != (u32)-1) {
1156 spin_lock_irq(&md->lock);
1157 ret = __blk_end_request(req, 0, blocks << 9);
1158 spin_unlock_irq(&md->lock);
1159 }
1160 } else {
1161 spin_lock_irq(&md->lock);
1162 ret = __blk_end_request(req, 0, brq->data.bytes_xfered);
1163 spin_unlock_irq(&md->lock);
1164 }
1165
1166 cmd_abort: 1272 cmd_abort:
1167 spin_lock_irq(&md->lock); 1273 spin_lock_irq(&md->lock);
1168 while (ret) 1274 while (ret)
@@ -1190,6 +1296,11 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
1190 1296
1191 ret = mmc_blk_part_switch(card, md); 1297 ret = mmc_blk_part_switch(card, md);
1192 if (ret) { 1298 if (ret) {
1299 if (req) {
1300 spin_lock_irq(&md->lock);
1301 __blk_end_request_all(req, -EIO);
1302 spin_unlock_irq(&md->lock);
1303 }
1193 ret = 0; 1304 ret = 0;
1194 goto out; 1305 goto out;
1195 } 1306 }
@@ -1374,32 +1485,35 @@ static int mmc_blk_alloc_part(struct mmc_card *card,
1374 1485
1375 string_get_size((u64)get_capacity(part_md->disk) << 9, STRING_UNITS_2, 1486 string_get_size((u64)get_capacity(part_md->disk) << 9, STRING_UNITS_2,
1376 cap_str, sizeof(cap_str)); 1487 cap_str, sizeof(cap_str));
1377 printk(KERN_INFO "%s: %s %s partition %u %s\n", 1488 pr_info("%s: %s %s partition %u %s\n",
1378 part_md->disk->disk_name, mmc_card_id(card), 1489 part_md->disk->disk_name, mmc_card_id(card),
1379 mmc_card_name(card), part_md->part_type, cap_str); 1490 mmc_card_name(card), part_md->part_type, cap_str);
1380 return 0; 1491 return 0;
1381} 1492}
1382 1493
1494/* MMC Physical partitions consist of two boot partitions and
1495 * up to four general purpose partitions.
1496 * For each partition enabled in EXT_CSD a block device will be allocatedi
1497 * to provide access to the partition.
1498 */
1499
1383static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md) 1500static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md)
1384{ 1501{
1385 int ret = 0; 1502 int idx, ret = 0;
1386 1503
1387 if (!mmc_card_mmc(card)) 1504 if (!mmc_card_mmc(card))
1388 return 0; 1505 return 0;
1389 1506
1390 if (card->ext_csd.boot_size) { 1507 for (idx = 0; idx < card->nr_parts; idx++) {
1391 ret = mmc_blk_alloc_part(card, md, EXT_CSD_PART_CONFIG_ACC_BOOT0, 1508 if (card->part[idx].size) {
1392 card->ext_csd.boot_size >> 9, 1509 ret = mmc_blk_alloc_part(card, md,
1393 true, 1510 card->part[idx].part_cfg,
1394 "boot0"); 1511 card->part[idx].size >> 9,
1395 if (ret) 1512 card->part[idx].force_ro,
1396 return ret; 1513 card->part[idx].name);
1397 ret = mmc_blk_alloc_part(card, md, EXT_CSD_PART_CONFIG_ACC_BOOT1, 1514 if (ret)
1398 card->ext_csd.boot_size >> 9, 1515 return ret;
1399 true, 1516 }
1400 "boot1");
1401 if (ret)
1402 return ret;
1403 } 1517 }
1404 1518
1405 return ret; 1519 return ret;
@@ -1415,7 +1529,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
1415 mmc_release_host(card->host); 1529 mmc_release_host(card->host);
1416 1530
1417 if (err) { 1531 if (err) {
1418 printk(KERN_ERR "%s: unable to set block size to 512: %d\n", 1532 pr_err("%s: unable to set block size to 512: %d\n",
1419 md->disk->disk_name, err); 1533 md->disk->disk_name, err);
1420 return -EINVAL; 1534 return -EINVAL;
1421 } 1535 }
@@ -1517,7 +1631,7 @@ static int mmc_blk_probe(struct mmc_card *card)
1517 1631
1518 string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2, 1632 string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2,
1519 cap_str, sizeof(cap_str)); 1633 cap_str, sizeof(cap_str));
1520 printk(KERN_INFO "%s: %s %s %s %s\n", 1634 pr_info("%s: %s %s %s %s\n",
1521 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card), 1635 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
1522 cap_str, md->read_only ? "(ro)" : ""); 1636 cap_str, md->read_only ? "(ro)" : "");
1523 1637
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 2bf229acd3b8..b038c4a9468b 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -22,6 +22,7 @@
22#include <linux/debugfs.h> 22#include <linux/debugfs.h>
23#include <linux/uaccess.h> 23#include <linux/uaccess.h>
24#include <linux/seq_file.h> 24#include <linux/seq_file.h>
25#include <linux/module.h>
25 26
26#define RESULT_OK 0 27#define RESULT_OK 0
27#define RESULT_FAIL 1 28#define RESULT_FAIL 1
@@ -250,7 +251,7 @@ static int mmc_test_wait_busy(struct mmc_test_card *test)
250 if (!busy && mmc_test_busy(&cmd)) { 251 if (!busy && mmc_test_busy(&cmd)) {
251 busy = 1; 252 busy = 1;
252 if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) 253 if (test->card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
253 printk(KERN_INFO "%s: Warning: Host did not " 254 pr_info("%s: Warning: Host did not "
254 "wait for busy state to end.\n", 255 "wait for busy state to end.\n",
255 mmc_hostname(test->card->host)); 256 mmc_hostname(test->card->host));
256 } 257 }
@@ -552,7 +553,7 @@ static void mmc_test_print_rate(struct mmc_test_card *test, uint64_t bytes,
552 rate = mmc_test_rate(bytes, &ts); 553 rate = mmc_test_rate(bytes, &ts);
553 iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */ 554 iops = mmc_test_rate(100, &ts); /* I/O ops per sec x 100 */
554 555
555 printk(KERN_INFO "%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu " 556 pr_info("%s: Transfer of %u sectors (%u%s KiB) took %lu.%09lu "
556 "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n", 557 "seconds (%u kB/s, %u KiB/s, %u.%02u IOPS)\n",
557 mmc_hostname(test->card->host), sectors, sectors >> 1, 558 mmc_hostname(test->card->host), sectors, sectors >> 1,
558 (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec, 559 (sectors & 1 ? ".5" : ""), (unsigned long)ts.tv_sec,
@@ -578,7 +579,7 @@ static void mmc_test_print_avg_rate(struct mmc_test_card *test, uint64_t bytes,
578 rate = mmc_test_rate(tot, &ts); 579 rate = mmc_test_rate(tot, &ts);
579 iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */ 580 iops = mmc_test_rate(count * 100, &ts); /* I/O ops per sec x 100 */
580 581
581 printk(KERN_INFO "%s: Transfer of %u x %u sectors (%u x %u%s KiB) took " 582 pr_info("%s: Transfer of %u x %u sectors (%u x %u%s KiB) took "
582 "%lu.%09lu seconds (%u kB/s, %u KiB/s, " 583 "%lu.%09lu seconds (%u kB/s, %u KiB/s, "
583 "%u.%02u IOPS, sg_len %d)\n", 584 "%u.%02u IOPS, sg_len %d)\n",
584 mmc_hostname(test->card->host), count, sectors, count, 585 mmc_hostname(test->card->host), count, sectors, count,
@@ -1408,7 +1409,7 @@ static int mmc_test_multi_read_high(struct mmc_test_card *test)
1408 1409
1409static int mmc_test_no_highmem(struct mmc_test_card *test) 1410static int mmc_test_no_highmem(struct mmc_test_card *test)
1410{ 1411{
1411 printk(KERN_INFO "%s: Highmem not configured - test skipped\n", 1412 pr_info("%s: Highmem not configured - test skipped\n",
1412 mmc_hostname(test->card->host)); 1413 mmc_hostname(test->card->host));
1413 return 0; 1414 return 0;
1414} 1415}
@@ -1435,7 +1436,7 @@ static int mmc_test_area_map(struct mmc_test_card *test, unsigned long sz,
1435 t->max_seg_sz, &t->sg_len, min_sg_len); 1436 t->max_seg_sz, &t->sg_len, min_sg_len);
1436 } 1437 }
1437 if (err) 1438 if (err)
1438 printk(KERN_INFO "%s: Failed to map sg list\n", 1439 pr_info("%s: Failed to map sg list\n",
1439 mmc_hostname(test->card->host)); 1440 mmc_hostname(test->card->host));
1440 return err; 1441 return err;
1441} 1442}
@@ -2135,7 +2136,7 @@ static int mmc_test_rw_multiple(struct mmc_test_card *test,
2135 2136
2136 return ret; 2137 return ret;
2137 err: 2138 err:
2138 printk(KERN_INFO "[%s] error\n", __func__); 2139 pr_info("[%s] error\n", __func__);
2139 return ret; 2140 return ret;
2140} 2141}
2141 2142
@@ -2149,7 +2150,7 @@ static int mmc_test_rw_multiple_size(struct mmc_test_card *test,
2149 2150
2150 if (rw->do_nonblock_req && 2151 if (rw->do_nonblock_req &&
2151 ((!pre_req && post_req) || (pre_req && !post_req))) { 2152 ((!pre_req && post_req) || (pre_req && !post_req))) {
2152 printk(KERN_INFO "error: only one of pre/post is defined\n"); 2153 pr_info("error: only one of pre/post is defined\n");
2153 return -EINVAL; 2154 return -EINVAL;
2154 } 2155 }
2155 2156
@@ -2328,6 +2329,31 @@ static int mmc_test_profile_sglen_r_nonblock_perf(struct mmc_test_card *test)
2328 return mmc_test_rw_multiple_sg_len(test, &test_data); 2329 return mmc_test_rw_multiple_sg_len(test, &test_data);
2329} 2330}
2330 2331
2332/*
2333 * eMMC hardware reset.
2334 */
2335static int mmc_test_hw_reset(struct mmc_test_card *test)
2336{
2337 struct mmc_card *card = test->card;
2338 struct mmc_host *host = card->host;
2339 int err;
2340
2341 err = mmc_hw_reset_check(host);
2342 if (!err)
2343 return RESULT_OK;
2344
2345 if (err == -ENOSYS)
2346 return RESULT_FAIL;
2347
2348 if (err != -EOPNOTSUPP)
2349 return err;
2350
2351 if (!mmc_can_reset(card))
2352 return RESULT_UNSUP_CARD;
2353
2354 return RESULT_UNSUP_HOST;
2355}
2356
2331static const struct mmc_test_case mmc_test_cases[] = { 2357static const struct mmc_test_case mmc_test_cases[] = {
2332 { 2358 {
2333 .name = "Basic write (no data verification)", 2359 .name = "Basic write (no data verification)",
@@ -2650,6 +2676,11 @@ static const struct mmc_test_case mmc_test_cases[] = {
2650 .run = mmc_test_profile_sglen_r_nonblock_perf, 2676 .run = mmc_test_profile_sglen_r_nonblock_perf,
2651 .cleanup = mmc_test_area_cleanup, 2677 .cleanup = mmc_test_area_cleanup,
2652 }, 2678 },
2679
2680 {
2681 .name = "eMMC hardware reset",
2682 .run = mmc_test_hw_reset,
2683 },
2653}; 2684};
2654 2685
2655static DEFINE_MUTEX(mmc_test_lock); 2686static DEFINE_MUTEX(mmc_test_lock);
@@ -2660,7 +2691,7 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
2660{ 2691{
2661 int i, ret; 2692 int i, ret;
2662 2693
2663 printk(KERN_INFO "%s: Starting tests of card %s...\n", 2694 pr_info("%s: Starting tests of card %s...\n",
2664 mmc_hostname(test->card->host), mmc_card_id(test->card)); 2695 mmc_hostname(test->card->host), mmc_card_id(test->card));
2665 2696
2666 mmc_claim_host(test->card->host); 2697 mmc_claim_host(test->card->host);
@@ -2671,14 +2702,14 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
2671 if (testcase && ((i + 1) != testcase)) 2702 if (testcase && ((i + 1) != testcase))
2672 continue; 2703 continue;
2673 2704
2674 printk(KERN_INFO "%s: Test case %d. %s...\n", 2705 pr_info("%s: Test case %d. %s...\n",
2675 mmc_hostname(test->card->host), i + 1, 2706 mmc_hostname(test->card->host), i + 1,
2676 mmc_test_cases[i].name); 2707 mmc_test_cases[i].name);
2677 2708
2678 if (mmc_test_cases[i].prepare) { 2709 if (mmc_test_cases[i].prepare) {
2679 ret = mmc_test_cases[i].prepare(test); 2710 ret = mmc_test_cases[i].prepare(test);
2680 if (ret) { 2711 if (ret) {
2681 printk(KERN_INFO "%s: Result: Prepare " 2712 pr_info("%s: Result: Prepare "
2682 "stage failed! (%d)\n", 2713 "stage failed! (%d)\n",
2683 mmc_hostname(test->card->host), 2714 mmc_hostname(test->card->host),
2684 ret); 2715 ret);
@@ -2708,25 +2739,25 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
2708 ret = mmc_test_cases[i].run(test); 2739 ret = mmc_test_cases[i].run(test);
2709 switch (ret) { 2740 switch (ret) {
2710 case RESULT_OK: 2741 case RESULT_OK:
2711 printk(KERN_INFO "%s: Result: OK\n", 2742 pr_info("%s: Result: OK\n",
2712 mmc_hostname(test->card->host)); 2743 mmc_hostname(test->card->host));
2713 break; 2744 break;
2714 case RESULT_FAIL: 2745 case RESULT_FAIL:
2715 printk(KERN_INFO "%s: Result: FAILED\n", 2746 pr_info("%s: Result: FAILED\n",
2716 mmc_hostname(test->card->host)); 2747 mmc_hostname(test->card->host));
2717 break; 2748 break;
2718 case RESULT_UNSUP_HOST: 2749 case RESULT_UNSUP_HOST:
2719 printk(KERN_INFO "%s: Result: UNSUPPORTED " 2750 pr_info("%s: Result: UNSUPPORTED "
2720 "(by host)\n", 2751 "(by host)\n",
2721 mmc_hostname(test->card->host)); 2752 mmc_hostname(test->card->host));
2722 break; 2753 break;
2723 case RESULT_UNSUP_CARD: 2754 case RESULT_UNSUP_CARD:
2724 printk(KERN_INFO "%s: Result: UNSUPPORTED " 2755 pr_info("%s: Result: UNSUPPORTED "
2725 "(by card)\n", 2756 "(by card)\n",
2726 mmc_hostname(test->card->host)); 2757 mmc_hostname(test->card->host));
2727 break; 2758 break;
2728 default: 2759 default:
2729 printk(KERN_INFO "%s: Result: ERROR (%d)\n", 2760 pr_info("%s: Result: ERROR (%d)\n",
2730 mmc_hostname(test->card->host), ret); 2761 mmc_hostname(test->card->host), ret);
2731 } 2762 }
2732 2763
@@ -2737,7 +2768,7 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
2737 if (mmc_test_cases[i].cleanup) { 2768 if (mmc_test_cases[i].cleanup) {
2738 ret = mmc_test_cases[i].cleanup(test); 2769 ret = mmc_test_cases[i].cleanup(test);
2739 if (ret) { 2770 if (ret) {
2740 printk(KERN_INFO "%s: Warning: Cleanup " 2771 pr_info("%s: Warning: Cleanup "
2741 "stage failed! (%d)\n", 2772 "stage failed! (%d)\n",
2742 mmc_hostname(test->card->host), 2773 mmc_hostname(test->card->host),
2743 ret); 2774 ret);
@@ -2747,7 +2778,7 @@ static void mmc_test_run(struct mmc_test_card *test, int testcase)
2747 2778
2748 mmc_release_host(test->card->host); 2779 mmc_release_host(test->card->host);
2749 2780
2750 printk(KERN_INFO "%s: Tests completed.\n", 2781 pr_info("%s: Tests completed.\n",
2751 mmc_hostname(test->card->host)); 2782 mmc_hostname(test->card->host));
2752} 2783}
2753 2784
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 45fb362e3f01..dcad59cbfef1 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -108,7 +108,7 @@ static void mmc_request(struct request_queue *q)
108 wake_up_process(mq->thread); 108 wake_up_process(mq->thread);
109} 109}
110 110
111struct scatterlist *mmc_alloc_sg(int sg_len, int *err) 111static struct scatterlist *mmc_alloc_sg(int sg_len, int *err)
112{ 112{
113 struct scatterlist *sg; 113 struct scatterlist *sg;
114 114
@@ -140,7 +140,7 @@ static void mmc_queue_setup_discard(struct request_queue *q,
140 /* granularity must not be greater than max. discard */ 140 /* granularity must not be greater than max. discard */
141 if (card->pref_erase > max_discard) 141 if (card->pref_erase > max_discard)
142 q->limits.discard_granularity = 0; 142 q->limits.discard_granularity = 0;
143 if (mmc_can_secure_erase_trim(card)) 143 if (mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))
144 queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, q); 144 queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, q);
145} 145}
146 146
@@ -197,13 +197,13 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
197 if (bouncesz > 512) { 197 if (bouncesz > 512) {
198 mqrq_cur->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); 198 mqrq_cur->bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
199 if (!mqrq_cur->bounce_buf) { 199 if (!mqrq_cur->bounce_buf) {
200 printk(KERN_WARNING "%s: unable to " 200 pr_warning("%s: unable to "
201 "allocate bounce cur buffer\n", 201 "allocate bounce cur buffer\n",
202 mmc_card_name(card)); 202 mmc_card_name(card));
203 } 203 }
204 mqrq_prev->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); 204 mqrq_prev->bounce_buf = kmalloc(bouncesz, GFP_KERNEL);
205 if (!mqrq_prev->bounce_buf) { 205 if (!mqrq_prev->bounce_buf) {
206 printk(KERN_WARNING "%s: unable to " 206 pr_warning("%s: unable to "
207 "allocate bounce prev buffer\n", 207 "allocate bounce prev buffer\n",
208 mmc_card_name(card)); 208 mmc_card_name(card));
209 kfree(mqrq_cur->bounce_buf); 209 kfree(mqrq_cur->bounce_buf);
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
index c8c9edb3d7cb..2c151e18c9e8 100644
--- a/drivers/mmc/card/sdio_uart.c
+++ b/drivers/mmc/card/sdio_uart.c
@@ -1082,7 +1082,7 @@ static int sdio_uart_probe(struct sdio_func *func,
1082 return -ENOMEM; 1082 return -ENOMEM;
1083 1083
1084 if (func->class == SDIO_CLASS_UART) { 1084 if (func->class == SDIO_CLASS_UART) {
1085 printk(KERN_WARNING "%s: need info on UART class basic setup\n", 1085 pr_warning("%s: need info on UART class basic setup\n",
1086 sdio_func_id(func)); 1086 sdio_func_id(func));
1087 kfree(port); 1087 kfree(port);
1088 return -ENOSYS; 1088 return -ENOSYS;
@@ -1101,23 +1101,23 @@ static int sdio_uart_probe(struct sdio_func *func,
1101 break; 1101 break;
1102 } 1102 }
1103 if (!tpl) { 1103 if (!tpl) {
1104 printk(KERN_WARNING 1104 pr_warning(
1105 "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n", 1105 "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n",
1106 sdio_func_id(func)); 1106 sdio_func_id(func));
1107 kfree(port); 1107 kfree(port);
1108 return -EINVAL; 1108 return -EINVAL;
1109 } 1109 }
1110 printk(KERN_DEBUG "%s: Register ID = 0x%02x, Exp ID = 0x%02x\n", 1110 pr_debug("%s: Register ID = 0x%02x, Exp ID = 0x%02x\n",
1111 sdio_func_id(func), tpl->data[2], tpl->data[3]); 1111 sdio_func_id(func), tpl->data[2], tpl->data[3]);
1112 port->regs_offset = (tpl->data[4] << 0) | 1112 port->regs_offset = (tpl->data[4] << 0) |
1113 (tpl->data[5] << 8) | 1113 (tpl->data[5] << 8) |
1114 (tpl->data[6] << 16); 1114 (tpl->data[6] << 16);
1115 printk(KERN_DEBUG "%s: regs offset = 0x%x\n", 1115 pr_debug("%s: regs offset = 0x%x\n",
1116 sdio_func_id(func), port->regs_offset); 1116 sdio_func_id(func), port->regs_offset);
1117 port->uartclk = tpl->data[7] * 115200; 1117 port->uartclk = tpl->data[7] * 115200;
1118 if (port->uartclk == 0) 1118 if (port->uartclk == 0)
1119 port->uartclk = 115200; 1119 port->uartclk = 115200;
1120 printk(KERN_DEBUG "%s: clk %d baudcode %u 4800-div %u\n", 1120 pr_debug("%s: clk %d baudcode %u 4800-div %u\n",
1121 sdio_func_id(func), port->uartclk, 1121 sdio_func_id(func), port->uartclk,
1122 tpl->data[7], tpl->data[8] | (tpl->data[9] << 8)); 1122 tpl->data[7], tpl->data[8] | (tpl->data[9] << 8));
1123 } else { 1123 } else {
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 393d817ed040..46b6e84d953e 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -295,7 +295,7 @@ int mmc_add_card(struct mmc_card *card)
295 } 295 }
296 296
297 if (mmc_host_is_spi(card->host)) { 297 if (mmc_host_is_spi(card->host)) {
298 printk(KERN_INFO "%s: new %s%s%s card on SPI\n", 298 pr_info("%s: new %s%s%s card on SPI\n",
299 mmc_hostname(card->host), 299 mmc_hostname(card->host),
300 mmc_card_highspeed(card) ? "high speed " : "", 300 mmc_card_highspeed(card) ? "high speed " : "",
301 mmc_card_ddr_mode(card) ? "DDR " : "", 301 mmc_card_ddr_mode(card) ? "DDR " : "",
@@ -334,10 +334,10 @@ void mmc_remove_card(struct mmc_card *card)
334 334
335 if (mmc_card_present(card)) { 335 if (mmc_card_present(card)) {
336 if (mmc_host_is_spi(card->host)) { 336 if (mmc_host_is_spi(card->host)) {
337 printk(KERN_INFO "%s: SPI card removed\n", 337 pr_info("%s: SPI card removed\n",
338 mmc_hostname(card->host)); 338 mmc_hostname(card->host));
339 } else { 339 } else {
340 printk(KERN_INFO "%s: card %04x removed\n", 340 pr_info("%s: card %04x removed\n",
341 mmc_hostname(card->host), card->rca); 341 mmc_hostname(card->host), card->rca);
342 } 342 }
343 device_del(&card->dev); 343 device_del(&card->dev);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index b27b94078c21..5278ffb20e74 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -24,6 +24,8 @@
24#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
25#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
26#include <linux/suspend.h> 26#include <linux/suspend.h>
27#include <linux/fault-inject.h>
28#include <linux/random.h>
27 29
28#include <linux/mmc/card.h> 30#include <linux/mmc/card.h>
29#include <linux/mmc/host.h> 31#include <linux/mmc/host.h>
@@ -83,6 +85,43 @@ static void mmc_flush_scheduled_work(void)
83 flush_workqueue(workqueue); 85 flush_workqueue(workqueue);
84} 86}
85 87
88#ifdef CONFIG_FAIL_MMC_REQUEST
89
90/*
91 * Internal function. Inject random data errors.
92 * If mmc_data is NULL no errors are injected.
93 */
94static void mmc_should_fail_request(struct mmc_host *host,
95 struct mmc_request *mrq)
96{
97 struct mmc_command *cmd = mrq->cmd;
98 struct mmc_data *data = mrq->data;
99 static const int data_errors[] = {
100 -ETIMEDOUT,
101 -EILSEQ,
102 -EIO,
103 };
104
105 if (!data)
106 return;
107
108 if (cmd->error || data->error ||
109 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks))
110 return;
111
112 data->error = data_errors[random32() % ARRAY_SIZE(data_errors)];
113 data->bytes_xfered = (random32() % (data->bytes_xfered >> 9)) << 9;
114}
115
116#else /* CONFIG_FAIL_MMC_REQUEST */
117
118static inline void mmc_should_fail_request(struct mmc_host *host,
119 struct mmc_request *mrq)
120{
121}
122
123#endif /* CONFIG_FAIL_MMC_REQUEST */
124
86/** 125/**
87 * mmc_request_done - finish processing an MMC request 126 * mmc_request_done - finish processing an MMC request
88 * @host: MMC host which completed request 127 * @host: MMC host which completed request
@@ -102,13 +141,15 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
102 } 141 }
103 142
104 if (err && cmd->retries) { 143 if (err && cmd->retries) {
105 pr_debug("%s: req failed (CMD%u): %d, retrying...\n", 144 /*
106 mmc_hostname(host), cmd->opcode, err); 145 * Request starter must handle retries - see
107 146 * mmc_wait_for_req_done().
108 cmd->retries--; 147 */
109 cmd->error = 0; 148 if (mrq->done)
110 host->ops->request(host, mrq); 149 mrq->done(mrq);
111 } else { 150 } else {
151 mmc_should_fail_request(host, mrq);
152
112 led_trigger_event(host->led, LED_OFF); 153 led_trigger_event(host->led, LED_OFF);
113 154
114 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n", 155 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
@@ -212,7 +253,21 @@ static void __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq)
212static void mmc_wait_for_req_done(struct mmc_host *host, 253static void mmc_wait_for_req_done(struct mmc_host *host,
213 struct mmc_request *mrq) 254 struct mmc_request *mrq)
214{ 255{
215 wait_for_completion(&mrq->completion); 256 struct mmc_command *cmd;
257
258 while (1) {
259 wait_for_completion(&mrq->completion);
260
261 cmd = mrq->cmd;
262 if (!cmd->error || !cmd->retries)
263 break;
264
265 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
266 mmc_hostname(host), cmd->opcode, cmd->error);
267 cmd->retries--;
268 cmd->error = 0;
269 host->ops->request(host, mrq);
270 }
216} 271}
217 272
218/** 273/**
@@ -279,8 +334,14 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
279 mmc_wait_for_req_done(host, host->areq->mrq); 334 mmc_wait_for_req_done(host, host->areq->mrq);
280 err = host->areq->err_check(host->card, host->areq); 335 err = host->areq->err_check(host->card, host->areq);
281 if (err) { 336 if (err) {
337 /* post process the completed failed request */
282 mmc_post_req(host, host->areq->mrq, 0); 338 mmc_post_req(host, host->areq->mrq, 0);
283 if (areq) 339 if (areq)
340 /*
341 * Cancel the new prepared request, because
342 * it can't run until the failed
343 * request has been properly handled.
344 */
284 mmc_post_req(host, areq->mrq, -EINVAL); 345 mmc_post_req(host, areq->mrq, -EINVAL);
285 346
286 host->areq = NULL; 347 host->areq = NULL;
@@ -319,6 +380,63 @@ void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
319EXPORT_SYMBOL(mmc_wait_for_req); 380EXPORT_SYMBOL(mmc_wait_for_req);
320 381
321/** 382/**
383 * mmc_interrupt_hpi - Issue for High priority Interrupt
384 * @card: the MMC card associated with the HPI transfer
385 *
386 * Issued High Priority Interrupt, and check for card status
387 * util out-of prg-state.
388 */
389int mmc_interrupt_hpi(struct mmc_card *card)
390{
391 int err;
392 u32 status;
393
394 BUG_ON(!card);
395
396 if (!card->ext_csd.hpi_en) {
397 pr_info("%s: HPI enable bit unset\n", mmc_hostname(card->host));
398 return 1;
399 }
400
401 mmc_claim_host(card->host);
402 err = mmc_send_status(card, &status);
403 if (err) {
404 pr_err("%s: Get card status fail\n", mmc_hostname(card->host));
405 goto out;
406 }
407
408 /*
409 * If the card status is in PRG-state, we can send the HPI command.
410 */
411 if (R1_CURRENT_STATE(status) == R1_STATE_PRG) {
412 do {
413 /*
414 * We don't know when the HPI command will finish
415 * processing, so we need to resend HPI until out
416 * of prg-state, and keep checking the card status
417 * with SEND_STATUS. If a timeout error occurs when
418 * sending the HPI command, we are already out of
419 * prg-state.
420 */
421 err = mmc_send_hpi_cmd(card, &status);
422 if (err)
423 pr_debug("%s: abort HPI (%d error)\n",
424 mmc_hostname(card->host), err);
425
426 err = mmc_send_status(card, &status);
427 if (err)
428 break;
429 } while (R1_CURRENT_STATE(status) == R1_STATE_PRG);
430 } else
431 pr_debug("%s: Left prg-state\n", mmc_hostname(card->host));
432
433out:
434 mmc_release_host(card->host);
435 return err;
436}
437EXPORT_SYMBOL(mmc_interrupt_hpi);
438
439/**
322 * mmc_wait_for_cmd - start a command and wait for completion 440 * mmc_wait_for_cmd - start a command and wait for completion
323 * @host: MMC host to start command 441 * @host: MMC host to start command
324 * @cmd: MMC command to start 442 * @cmd: MMC command to start
@@ -330,7 +448,7 @@ EXPORT_SYMBOL(mmc_wait_for_req);
330 */ 448 */
331int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries) 449int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries)
332{ 450{
333 struct mmc_request mrq = {0}; 451 struct mmc_request mrq = {NULL};
334 452
335 WARN_ON(!host->claimed); 453 WARN_ON(!host->claimed);
336 454
@@ -1119,13 +1237,11 @@ static void mmc_power_up(struct mmc_host *host)
1119 bit = fls(host->ocr_avail) - 1; 1237 bit = fls(host->ocr_avail) - 1;
1120 1238
1121 host->ios.vdd = bit; 1239 host->ios.vdd = bit;
1122 if (mmc_host_is_spi(host)) { 1240 if (mmc_host_is_spi(host))
1123 host->ios.chip_select = MMC_CS_HIGH; 1241 host->ios.chip_select = MMC_CS_HIGH;
1124 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL; 1242 else
1125 } else {
1126 host->ios.chip_select = MMC_CS_DONTCARE; 1243 host->ios.chip_select = MMC_CS_DONTCARE;
1127 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 1244 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
1128 }
1129 host->ios.power_mode = MMC_POWER_UP; 1245 host->ios.power_mode = MMC_POWER_UP;
1130 host->ios.bus_width = MMC_BUS_WIDTH_1; 1246 host->ios.bus_width = MMC_BUS_WIDTH_1;
1131 host->ios.timing = MMC_TIMING_LEGACY; 1247 host->ios.timing = MMC_TIMING_LEGACY;
@@ -1151,13 +1267,45 @@ static void mmc_power_up(struct mmc_host *host)
1151 mmc_host_clk_release(host); 1267 mmc_host_clk_release(host);
1152} 1268}
1153 1269
1154static void mmc_power_off(struct mmc_host *host) 1270void mmc_power_off(struct mmc_host *host)
1155{ 1271{
1272 struct mmc_card *card;
1273 unsigned int notify_type;
1274 unsigned int timeout;
1275 int err;
1276
1156 mmc_host_clk_hold(host); 1277 mmc_host_clk_hold(host);
1157 1278
1279 card = host->card;
1158 host->ios.clock = 0; 1280 host->ios.clock = 0;
1159 host->ios.vdd = 0; 1281 host->ios.vdd = 0;
1160 1282
1283 if (card && mmc_card_mmc(card) &&
1284 (card->poweroff_notify_state == MMC_POWERED_ON)) {
1285
1286 if (host->power_notify_type == MMC_HOST_PW_NOTIFY_SHORT) {
1287 notify_type = EXT_CSD_POWER_OFF_SHORT;
1288 timeout = card->ext_csd.generic_cmd6_time;
1289 card->poweroff_notify_state = MMC_POWEROFF_SHORT;
1290 } else {
1291 notify_type = EXT_CSD_POWER_OFF_LONG;
1292 timeout = card->ext_csd.power_off_longtime;
1293 card->poweroff_notify_state = MMC_POWEROFF_LONG;
1294 }
1295
1296 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1297 EXT_CSD_POWER_OFF_NOTIFICATION,
1298 notify_type, timeout);
1299
1300 if (err && err != -EBADMSG)
1301 pr_err("Device failed to respond within %d poweroff "
1302 "time. Forcefully powering down the device\n",
1303 timeout);
1304
1305 /* Set the card state to no notification after the poweroff */
1306 card->poweroff_notify_state = MMC_NO_POWER_NOTIFICATION;
1307 }
1308
1161 /* 1309 /*
1162 * Reset ocr mask to be the highest possible voltage supported for 1310 * Reset ocr mask to be the highest possible voltage supported for
1163 * this mmc host. This value will be used at next power up. 1311 * this mmc host. This value will be used at next power up.
@@ -1173,6 +1321,13 @@ static void mmc_power_off(struct mmc_host *host)
1173 host->ios.timing = MMC_TIMING_LEGACY; 1321 host->ios.timing = MMC_TIMING_LEGACY;
1174 mmc_set_ios(host); 1322 mmc_set_ios(host);
1175 1323
1324 /*
1325 * Some configurations, such as the 802.11 SDIO card in the OLPC
1326 * XO-1.5, require a short delay after poweroff before the card
1327 * can be successfully turned on again.
1328 */
1329 mmc_delay(1);
1330
1176 mmc_host_clk_release(host); 1331 mmc_host_clk_release(host);
1177} 1332}
1178 1333
@@ -1241,8 +1396,7 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
1241} 1396}
1242 1397
1243/* 1398/*
1244 * Remove the current bus handler from a host. Assumes that there are 1399 * Remove the current bus handler from a host.
1245 * no interesting cards left, so the bus is powered down.
1246 */ 1400 */
1247void mmc_detach_bus(struct mmc_host *host) 1401void mmc_detach_bus(struct mmc_host *host)
1248{ 1402{
@@ -1259,8 +1413,6 @@ void mmc_detach_bus(struct mmc_host *host)
1259 1413
1260 spin_unlock_irqrestore(&host->lock, flags); 1414 spin_unlock_irqrestore(&host->lock, flags);
1261 1415
1262 mmc_power_off(host);
1263
1264 mmc_bus_put(host); 1416 mmc_bus_put(host);
1265} 1417}
1266 1418
@@ -1478,9 +1630,9 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1478 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; 1630 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1479 err = mmc_wait_for_cmd(card->host, &cmd, 0); 1631 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1480 if (err) { 1632 if (err) {
1481 printk(KERN_ERR "mmc_erase: group start error %d, " 1633 pr_err("mmc_erase: group start error %d, "
1482 "status %#x\n", err, cmd.resp[0]); 1634 "status %#x\n", err, cmd.resp[0]);
1483 err = -EINVAL; 1635 err = -EIO;
1484 goto out; 1636 goto out;
1485 } 1637 }
1486 1638
@@ -1493,9 +1645,9 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1493 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; 1645 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
1494 err = mmc_wait_for_cmd(card->host, &cmd, 0); 1646 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1495 if (err) { 1647 if (err) {
1496 printk(KERN_ERR "mmc_erase: group end error %d, status %#x\n", 1648 pr_err("mmc_erase: group end error %d, status %#x\n",
1497 err, cmd.resp[0]); 1649 err, cmd.resp[0]);
1498 err = -EINVAL; 1650 err = -EIO;
1499 goto out; 1651 goto out;
1500 } 1652 }
1501 1653
@@ -1506,7 +1658,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1506 cmd.cmd_timeout_ms = mmc_erase_timeout(card, arg, qty); 1658 cmd.cmd_timeout_ms = mmc_erase_timeout(card, arg, qty);
1507 err = mmc_wait_for_cmd(card->host, &cmd, 0); 1659 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1508 if (err) { 1660 if (err) {
1509 printk(KERN_ERR "mmc_erase: erase error %d, status %#x\n", 1661 pr_err("mmc_erase: erase error %d, status %#x\n",
1510 err, cmd.resp[0]); 1662 err, cmd.resp[0]);
1511 err = -EIO; 1663 err = -EIO;
1512 goto out; 1664 goto out;
@@ -1523,7 +1675,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from,
1523 /* Do not retry else we can't see errors */ 1675 /* Do not retry else we can't see errors */
1524 err = mmc_wait_for_cmd(card->host, &cmd, 0); 1676 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1525 if (err || (cmd.resp[0] & 0xFDF92000)) { 1677 if (err || (cmd.resp[0] & 0xFDF92000)) {
1526 printk(KERN_ERR "error %d requesting status %#x\n", 1678 pr_err("error %d requesting status %#x\n",
1527 err, cmd.resp[0]); 1679 err, cmd.resp[0]);
1528 err = -EIO; 1680 err = -EIO;
1529 goto out; 1681 goto out;
@@ -1614,10 +1766,32 @@ int mmc_can_trim(struct mmc_card *card)
1614{ 1766{
1615 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN) 1767 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
1616 return 1; 1768 return 1;
1769 if (mmc_can_discard(card))
1770 return 1;
1617 return 0; 1771 return 0;
1618} 1772}
1619EXPORT_SYMBOL(mmc_can_trim); 1773EXPORT_SYMBOL(mmc_can_trim);
1620 1774
1775int mmc_can_discard(struct mmc_card *card)
1776{
1777 /*
1778 * As there's no way to detect the discard support bit at v4.5
1779 * use the s/w feature support filed.
1780 */
1781 if (card->ext_csd.feature_support & MMC_DISCARD_FEATURE)
1782 return 1;
1783 return 0;
1784}
1785EXPORT_SYMBOL(mmc_can_discard);
1786
1787int mmc_can_sanitize(struct mmc_card *card)
1788{
1789 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE)
1790 return 1;
1791 return 0;
1792}
1793EXPORT_SYMBOL(mmc_can_sanitize);
1794
1621int mmc_can_secure_erase_trim(struct mmc_card *card) 1795int mmc_can_secure_erase_trim(struct mmc_card *card)
1622{ 1796{
1623 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN) 1797 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)
@@ -1727,6 +1901,94 @@ int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen)
1727} 1901}
1728EXPORT_SYMBOL(mmc_set_blocklen); 1902EXPORT_SYMBOL(mmc_set_blocklen);
1729 1903
1904static void mmc_hw_reset_for_init(struct mmc_host *host)
1905{
1906 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
1907 return;
1908 mmc_host_clk_hold(host);
1909 host->ops->hw_reset(host);
1910 mmc_host_clk_release(host);
1911}
1912
1913int mmc_can_reset(struct mmc_card *card)
1914{
1915 u8 rst_n_function;
1916
1917 if (!mmc_card_mmc(card))
1918 return 0;
1919 rst_n_function = card->ext_csd.rst_n_function;
1920 if ((rst_n_function & EXT_CSD_RST_N_EN_MASK) != EXT_CSD_RST_N_ENABLED)
1921 return 0;
1922 return 1;
1923}
1924EXPORT_SYMBOL(mmc_can_reset);
1925
1926static int mmc_do_hw_reset(struct mmc_host *host, int check)
1927{
1928 struct mmc_card *card = host->card;
1929
1930 if (!host->bus_ops->power_restore)
1931 return -EOPNOTSUPP;
1932
1933 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
1934 return -EOPNOTSUPP;
1935
1936 if (!card)
1937 return -EINVAL;
1938
1939 if (!mmc_can_reset(card))
1940 return -EOPNOTSUPP;
1941
1942 mmc_host_clk_hold(host);
1943 mmc_set_clock(host, host->f_init);
1944
1945 host->ops->hw_reset(host);
1946
1947 /* If the reset has happened, then a status command will fail */
1948 if (check) {
1949 struct mmc_command cmd = {0};
1950 int err;
1951
1952 cmd.opcode = MMC_SEND_STATUS;
1953 if (!mmc_host_is_spi(card->host))
1954 cmd.arg = card->rca << 16;
1955 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
1956 err = mmc_wait_for_cmd(card->host, &cmd, 0);
1957 if (!err) {
1958 mmc_host_clk_release(host);
1959 return -ENOSYS;
1960 }
1961 }
1962
1963 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_DDR);
1964 if (mmc_host_is_spi(host)) {
1965 host->ios.chip_select = MMC_CS_HIGH;
1966 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
1967 } else {
1968 host->ios.chip_select = MMC_CS_DONTCARE;
1969 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
1970 }
1971 host->ios.bus_width = MMC_BUS_WIDTH_1;
1972 host->ios.timing = MMC_TIMING_LEGACY;
1973 mmc_set_ios(host);
1974
1975 mmc_host_clk_release(host);
1976
1977 return host->bus_ops->power_restore(host);
1978}
1979
1980int mmc_hw_reset(struct mmc_host *host)
1981{
1982 return mmc_do_hw_reset(host, 0);
1983}
1984EXPORT_SYMBOL(mmc_hw_reset);
1985
1986int mmc_hw_reset_check(struct mmc_host *host)
1987{
1988 return mmc_do_hw_reset(host, 1);
1989}
1990EXPORT_SYMBOL(mmc_hw_reset_check);
1991
1730static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) 1992static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
1731{ 1993{
1732 host->f_init = freq; 1994 host->f_init = freq;
@@ -1738,6 +2000,12 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
1738 mmc_power_up(host); 2000 mmc_power_up(host);
1739 2001
1740 /* 2002 /*
2003 * Some eMMCs (with VCCQ always on) may not be reset after power up, so
2004 * do a hardware reset if possible.
2005 */
2006 mmc_hw_reset_for_init(host);
2007
2008 /*
1741 * sdio_reset sends CMD52 to reset card. Since we do not know 2009 * sdio_reset sends CMD52 to reset card. Since we do not know
1742 * if the card is being re-initialized, just send it. CMD52 2010 * if the card is being re-initialized, just send it. CMD52
1743 * should be ignored by SD/eMMC cards. 2011 * should be ignored by SD/eMMC cards.
@@ -1845,6 +2113,7 @@ void mmc_stop_host(struct mmc_host *host)
1845 2113
1846 mmc_claim_host(host); 2114 mmc_claim_host(host);
1847 mmc_detach_bus(host); 2115 mmc_detach_bus(host);
2116 mmc_power_off(host);
1848 mmc_release_host(host); 2117 mmc_release_host(host);
1849 mmc_bus_put(host); 2118 mmc_bus_put(host);
1850 return; 2119 return;
@@ -1946,6 +2215,65 @@ int mmc_card_can_sleep(struct mmc_host *host)
1946} 2215}
1947EXPORT_SYMBOL(mmc_card_can_sleep); 2216EXPORT_SYMBOL(mmc_card_can_sleep);
1948 2217
2218/*
2219 * Flush the cache to the non-volatile storage.
2220 */
2221int mmc_flush_cache(struct mmc_card *card)
2222{
2223 struct mmc_host *host = card->host;
2224 int err = 0;
2225
2226 if (!(host->caps2 & MMC_CAP2_CACHE_CTRL))
2227 return err;
2228
2229 if (mmc_card_mmc(card) &&
2230 (card->ext_csd.cache_size > 0) &&
2231 (card->ext_csd.cache_ctrl & 1)) {
2232 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
2233 EXT_CSD_FLUSH_CACHE, 1, 0);
2234 if (err)
2235 pr_err("%s: cache flush error %d\n",
2236 mmc_hostname(card->host), err);
2237 }
2238
2239 return err;
2240}
2241EXPORT_SYMBOL(mmc_flush_cache);
2242
2243/*
2244 * Turn the cache ON/OFF.
2245 * Turning the cache OFF shall trigger flushing of the data
2246 * to the non-volatile storage.
2247 */
2248int mmc_cache_ctrl(struct mmc_host *host, u8 enable)
2249{
2250 struct mmc_card *card = host->card;
2251 int err = 0;
2252
2253 if (!(host->caps2 & MMC_CAP2_CACHE_CTRL) ||
2254 mmc_card_is_removable(host))
2255 return err;
2256
2257 if (card && mmc_card_mmc(card) &&
2258 (card->ext_csd.cache_size > 0)) {
2259 enable = !!enable;
2260
2261 if (card->ext_csd.cache_ctrl ^ enable)
2262 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
2263 EXT_CSD_CACHE_CTRL, enable, 0);
2264 if (err)
2265 pr_err("%s: cache %s error %d\n",
2266 mmc_hostname(card->host),
2267 enable ? "on" : "off",
2268 err);
2269 else
2270 card->ext_csd.cache_ctrl = enable;
2271 }
2272
2273 return err;
2274}
2275EXPORT_SYMBOL(mmc_cache_ctrl);
2276
1949#ifdef CONFIG_PM 2277#ifdef CONFIG_PM
1950 2278
1951/** 2279/**
@@ -1960,23 +2288,39 @@ int mmc_suspend_host(struct mmc_host *host)
1960 cancel_delayed_work(&host->disable); 2288 cancel_delayed_work(&host->disable);
1961 cancel_delayed_work(&host->detect); 2289 cancel_delayed_work(&host->detect);
1962 mmc_flush_scheduled_work(); 2290 mmc_flush_scheduled_work();
2291 err = mmc_cache_ctrl(host, 0);
2292 if (err)
2293 goto out;
1963 2294
1964 mmc_bus_get(host); 2295 mmc_bus_get(host);
1965 if (host->bus_ops && !host->bus_dead) { 2296 if (host->bus_ops && !host->bus_dead) {
1966 if (host->bus_ops->suspend) 2297
1967 err = host->bus_ops->suspend(host); 2298 /*
1968 if (err == -ENOSYS || !host->bus_ops->resume) { 2299 * A long response time is not acceptable for device drivers
1969 /* 2300 * when doing suspend. Prevent mmc_claim_host in the suspend
1970 * We simply "remove" the card in this case. 2301 * sequence, to potentially wait "forever" by trying to
1971 * It will be redetected on resume. 2302 * pre-claim the host.
1972 */ 2303 */
1973 if (host->bus_ops->remove) 2304 if (mmc_try_claim_host(host)) {
1974 host->bus_ops->remove(host); 2305 if (host->bus_ops->suspend)
1975 mmc_claim_host(host); 2306 err = host->bus_ops->suspend(host);
1976 mmc_detach_bus(host); 2307 if (err == -ENOSYS || !host->bus_ops->resume) {
1977 mmc_release_host(host); 2308 /*
1978 host->pm_flags = 0; 2309 * We simply "remove" the card in this case.
1979 err = 0; 2310 * It will be redetected on resume.
2311 */
2312 if (host->bus_ops->remove)
2313 host->bus_ops->remove(host);
2314 mmc_claim_host(host);
2315 mmc_detach_bus(host);
2316 mmc_power_off(host);
2317 mmc_release_host(host);
2318 host->pm_flags = 0;
2319 err = 0;
2320 }
2321 mmc_do_release_host(host);
2322 } else {
2323 err = -EBUSY;
1980 } 2324 }
1981 } 2325 }
1982 mmc_bus_put(host); 2326 mmc_bus_put(host);
@@ -1984,6 +2328,7 @@ int mmc_suspend_host(struct mmc_host *host)
1984 if (!err && !mmc_card_keep_power(host)) 2328 if (!err && !mmc_card_keep_power(host))
1985 mmc_power_off(host); 2329 mmc_power_off(host);
1986 2330
2331out:
1987 return err; 2332 return err;
1988} 2333}
1989 2334
@@ -2018,7 +2363,7 @@ int mmc_resume_host(struct mmc_host *host)
2018 BUG_ON(!host->bus_ops->resume); 2363 BUG_ON(!host->bus_ops->resume);
2019 err = host->bus_ops->resume(host); 2364 err = host->bus_ops->resume(host);
2020 if (err) { 2365 if (err) {
2021 printk(KERN_WARNING "%s: error %d during resume " 2366 pr_warning("%s: error %d during resume "
2022 "(card was removed?)\n", 2367 "(card was removed?)\n",
2023 mmc_hostname(host), err); 2368 mmc_hostname(host), err);
2024 err = 0; 2369 err = 0;
@@ -2049,6 +2394,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2049 2394
2050 spin_lock_irqsave(&host->lock, flags); 2395 spin_lock_irqsave(&host->lock, flags);
2051 host->rescan_disable = 1; 2396 host->rescan_disable = 1;
2397 host->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT;
2052 spin_unlock_irqrestore(&host->lock, flags); 2398 spin_unlock_irqrestore(&host->lock, flags);
2053 cancel_delayed_work_sync(&host->detect); 2399 cancel_delayed_work_sync(&host->detect);
2054 2400
@@ -2061,6 +2407,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2061 host->bus_ops->remove(host); 2407 host->bus_ops->remove(host);
2062 2408
2063 mmc_detach_bus(host); 2409 mmc_detach_bus(host);
2410 mmc_power_off(host);
2064 mmc_release_host(host); 2411 mmc_release_host(host);
2065 host->pm_flags = 0; 2412 host->pm_flags = 0;
2066 break; 2413 break;
@@ -2071,6 +2418,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2071 2418
2072 spin_lock_irqsave(&host->lock, flags); 2419 spin_lock_irqsave(&host->lock, flags);
2073 host->rescan_disable = 0; 2420 host->rescan_disable = 0;
2421 host->power_notify_type = MMC_HOST_PW_NOTIFY_LONG;
2074 spin_unlock_irqrestore(&host->lock, flags); 2422 spin_unlock_irqrestore(&host->lock, flags);
2075 mmc_detect_change(host, 0); 2423 mmc_detect_change(host, 0);
2076 2424
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index d9411ed2a39b..14664f1fb16f 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -43,6 +43,7 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage,
43 bool cmd11); 43 bool cmd11);
44void mmc_set_timing(struct mmc_host *host, unsigned int timing); 44void mmc_set_timing(struct mmc_host *host, unsigned int timing);
45void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); 45void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
46void mmc_power_off(struct mmc_host *host);
46 47
47static inline void mmc_delay(unsigned int ms) 48static inline void mmc_delay(unsigned int ms)
48{ 49{
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 998797ed67a6..6045ea469362 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -7,11 +7,13 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#include <linux/moduleparam.h>
10#include <linux/debugfs.h> 11#include <linux/debugfs.h>
11#include <linux/fs.h> 12#include <linux/fs.h>
12#include <linux/seq_file.h> 13#include <linux/seq_file.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <linux/stat.h> 15#include <linux/stat.h>
16#include <linux/fault-inject.h>
15 17
16#include <linux/mmc/card.h> 18#include <linux/mmc/card.h>
17#include <linux/mmc/host.h> 19#include <linux/mmc/host.h>
@@ -19,6 +21,14 @@
19#include "core.h" 21#include "core.h"
20#include "mmc_ops.h" 22#include "mmc_ops.h"
21 23
24#ifdef CONFIG_FAIL_MMC_REQUEST
25
26static DECLARE_FAULT_ATTR(fail_default_attr);
27static char *fail_request;
28module_param(fail_request, charp, 0);
29
30#endif /* CONFIG_FAIL_MMC_REQUEST */
31
22/* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */ 32/* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */
23static int mmc_ios_show(struct seq_file *s, void *data) 33static int mmc_ios_show(struct seq_file *s, void *data)
24{ 34{
@@ -113,6 +123,15 @@ static int mmc_ios_show(struct seq_file *s, void *data)
113 case MMC_TIMING_SD_HS: 123 case MMC_TIMING_SD_HS:
114 str = "sd high-speed"; 124 str = "sd high-speed";
115 break; 125 break;
126 case MMC_TIMING_UHS_SDR50:
127 str = "sd uhs SDR50";
128 break;
129 case MMC_TIMING_UHS_SDR104:
130 str = "sd uhs SDR104";
131 break;
132 case MMC_TIMING_UHS_DDR50:
133 str = "sd uhs DDR50";
134 break;
116 default: 135 default:
117 str = "invalid"; 136 str = "invalid";
118 break; 137 break;
@@ -188,6 +207,15 @@ void mmc_add_host_debugfs(struct mmc_host *host)
188 root, &host->clk_delay)) 207 root, &host->clk_delay))
189 goto err_node; 208 goto err_node;
190#endif 209#endif
210#ifdef CONFIG_FAIL_MMC_REQUEST
211 if (fail_request)
212 setup_fault_attr(&fail_default_attr, fail_request);
213 host->fail_mmc_request = fail_default_attr;
214 if (IS_ERR(fault_create_debugfs_attr("fail_mmc_request",
215 root,
216 &host->fail_mmc_request)))
217 goto err_node;
218#endif
191 return; 219 return;
192 220
193err_node: 221err_node:
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 793d0a0dad8d..ca2e4f50f615 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -301,6 +301,17 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
301 host->max_blk_size = 512; 301 host->max_blk_size = 512;
302 host->max_blk_count = PAGE_CACHE_SIZE / 512; 302 host->max_blk_count = PAGE_CACHE_SIZE / 512;
303 303
304 /*
305 * Enable runtime power management by default. This flag was added due
306 * to runtime power management causing disruption for some users, but
307 * the power on/off code has been improved since then.
308 *
309 * We'll enable this flag by default as an experiment, and if no
310 * problems are reported, we will follow up later and remove the flag
311 * altogether.
312 */
313 host->caps = MMC_CAP_POWER_OFF_CARD;
314
304 return host; 315 return host;
305 316
306free: 317free:
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 5700b1cbdfec..36270449dd9d 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -101,7 +101,7 @@ static int mmc_decode_cid(struct mmc_card *card)
101 break; 101 break;
102 102
103 default: 103 default:
104 printk(KERN_ERR "%s: card has unknown MMCA version %d\n", 104 pr_err("%s: card has unknown MMCA version %d\n",
105 mmc_hostname(card->host), card->csd.mmca_vsn); 105 mmc_hostname(card->host), card->csd.mmca_vsn);
106 return -EINVAL; 106 return -EINVAL;
107 } 107 }
@@ -135,7 +135,7 @@ static int mmc_decode_csd(struct mmc_card *card)
135 */ 135 */
136 csd->structure = UNSTUFF_BITS(resp, 126, 2); 136 csd->structure = UNSTUFF_BITS(resp, 126, 2);
137 if (csd->structure == 0) { 137 if (csd->structure == 0) {
138 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", 138 pr_err("%s: unrecognised CSD structure version %d\n",
139 mmc_hostname(card->host), csd->structure); 139 mmc_hostname(card->host), csd->structure);
140 return -EINVAL; 140 return -EINVAL;
141 } 141 }
@@ -195,7 +195,7 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
195 */ 195 */
196 ext_csd = kmalloc(512, GFP_KERNEL); 196 ext_csd = kmalloc(512, GFP_KERNEL);
197 if (!ext_csd) { 197 if (!ext_csd) {
198 printk(KERN_ERR "%s: could not allocate a buffer to " 198 pr_err("%s: could not allocate a buffer to "
199 "receive the ext_csd.\n", mmc_hostname(card->host)); 199 "receive the ext_csd.\n", mmc_hostname(card->host));
200 return -ENOMEM; 200 return -ENOMEM;
201 } 201 }
@@ -217,12 +217,12 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
217 * stored in their CSD. 217 * stored in their CSD.
218 */ 218 */
219 if (card->csd.capacity == (4096 * 512)) { 219 if (card->csd.capacity == (4096 * 512)) {
220 printk(KERN_ERR "%s: unable to read EXT_CSD " 220 pr_err("%s: unable to read EXT_CSD "
221 "on a possible high capacity card. " 221 "on a possible high capacity card. "
222 "Card will be ignored.\n", 222 "Card will be ignored.\n",
223 mmc_hostname(card->host)); 223 mmc_hostname(card->host));
224 } else { 224 } else {
225 printk(KERN_WARNING "%s: unable to read " 225 pr_warning("%s: unable to read "
226 "EXT_CSD, performance might " 226 "EXT_CSD, performance might "
227 "suffer.\n", 227 "suffer.\n",
228 mmc_hostname(card->host)); 228 mmc_hostname(card->host));
@@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
239 */ 239 */
240static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) 240static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
241{ 241{
242 int err = 0; 242 int err = 0, idx;
243 unsigned int part_size;
244 u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
243 245
244 BUG_ON(!card); 246 BUG_ON(!card);
245 247
@@ -250,7 +252,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
250 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; 252 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
251 if (card->csd.structure == 3) { 253 if (card->csd.structure == 3) {
252 if (card->ext_csd.raw_ext_csd_structure > 2) { 254 if (card->ext_csd.raw_ext_csd_structure > 2) {
253 printk(KERN_ERR "%s: unrecognised EXT_CSD structure " 255 pr_err("%s: unrecognised EXT_CSD structure "
254 "version %d\n", mmc_hostname(card->host), 256 "version %d\n", mmc_hostname(card->host),
255 card->ext_csd.raw_ext_csd_structure); 257 card->ext_csd.raw_ext_csd_structure);
256 err = -EINVAL; 258 err = -EINVAL;
@@ -260,7 +262,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
260 262
261 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; 263 card->ext_csd.rev = ext_csd[EXT_CSD_REV];
262 if (card->ext_csd.rev > 6) { 264 if (card->ext_csd.rev > 6) {
263 printk(KERN_ERR "%s: unrecognised EXT_CSD revision %d\n", 265 pr_err("%s: unrecognised EXT_CSD revision %d\n",
264 mmc_hostname(card->host), card->ext_csd.rev); 266 mmc_hostname(card->host), card->ext_csd.rev);
265 err = -EINVAL; 267 err = -EINVAL;
266 goto out; 268 goto out;
@@ -306,7 +308,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
306 break; 308 break;
307 default: 309 default:
308 /* MMC v4 spec says this cannot happen */ 310 /* MMC v4 spec says this cannot happen */
309 printk(KERN_WARNING "%s: card is mmc v4 but doesn't " 311 pr_warning("%s: card is mmc v4 but doesn't "
310 "support any high-speed modes.\n", 312 "support any high-speed modes.\n",
311 mmc_hostname(card->host)); 313 mmc_hostname(card->host));
312 } 314 }
@@ -340,7 +342,14 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
340 * There are two boot regions of equal size, defined in 342 * There are two boot regions of equal size, defined in
341 * multiples of 128K. 343 * multiples of 128K.
342 */ 344 */
343 card->ext_csd.boot_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; 345 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) {
346 for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) {
347 part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
348 mmc_part_add(card, part_size,
349 EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx,
350 "boot%d", idx, true);
351 }
352 }
344 } 353 }
345 354
346 card->ext_csd.raw_hc_erase_gap_size = 355 card->ext_csd.raw_hc_erase_gap_size =
@@ -359,11 +368,12 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
359 * card has the Enhanced area enabled. If so, export enhanced 368 * card has the Enhanced area enabled. If so, export enhanced
360 * area offset and size to user by adding sysfs interface. 369 * area offset and size to user by adding sysfs interface.
361 */ 370 */
371 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
362 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) && 372 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
363 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) { 373 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
364 u8 hc_erase_grp_sz = 374 hc_erase_grp_sz =
365 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; 375 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
366 u8 hc_wp_grp_sz = 376 hc_wp_grp_sz =
367 ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; 377 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
368 378
369 card->ext_csd.enhanced_area_en = 1; 379 card->ext_csd.enhanced_area_en = 1;
@@ -392,6 +402,41 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
392 card->ext_csd.enhanced_area_offset = -EINVAL; 402 card->ext_csd.enhanced_area_offset = -EINVAL;
393 card->ext_csd.enhanced_area_size = -EINVAL; 403 card->ext_csd.enhanced_area_size = -EINVAL;
394 } 404 }
405
406 /*
407 * General purpose partition feature support --
408 * If ext_csd has the size of general purpose partitions,
409 * set size, part_cfg, partition name in mmc_part.
410 */
411 if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
412 EXT_CSD_PART_SUPPORT_PART_EN) {
413 if (card->ext_csd.enhanced_area_en != 1) {
414 hc_erase_grp_sz =
415 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
416 hc_wp_grp_sz =
417 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
418
419 card->ext_csd.enhanced_area_en = 1;
420 }
421
422 for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) {
423 if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] &&
424 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] &&
425 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
426 continue;
427 part_size =
428 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
429 << 16) +
430 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
431 << 8) +
432 ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
433 part_size *= (size_t)(hc_erase_grp_sz *
434 hc_wp_grp_sz);
435 mmc_part_add(card, part_size << 19,
436 EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
437 "gp%d", idx, false);
438 }
439 }
395 card->ext_csd.sec_trim_mult = 440 card->ext_csd.sec_trim_mult =
396 ext_csd[EXT_CSD_SEC_TRIM_MULT]; 441 ext_csd[EXT_CSD_SEC_TRIM_MULT];
397 card->ext_csd.sec_erase_mult = 442 card->ext_csd.sec_erase_mult =
@@ -402,14 +447,48 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
402 ext_csd[EXT_CSD_TRIM_MULT]; 447 ext_csd[EXT_CSD_TRIM_MULT];
403 } 448 }
404 449
405 if (card->ext_csd.rev >= 5) 450 if (card->ext_csd.rev >= 5) {
451 /* check whether the eMMC card supports HPI */
452 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) {
453 card->ext_csd.hpi = 1;
454 if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2)
455 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION;
456 else
457 card->ext_csd.hpi_cmd = MMC_SEND_STATUS;
458 /*
459 * Indicate the maximum timeout to close
460 * a command interrupted by HPI
461 */
462 card->ext_csd.out_of_int_time =
463 ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10;
464 }
465
406 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; 466 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
467 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION];
468 }
407 469
470 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT];
408 if (ext_csd[EXT_CSD_ERASED_MEM_CONT]) 471 if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
409 card->erased_byte = 0xFF; 472 card->erased_byte = 0xFF;
410 else 473 else
411 card->erased_byte = 0x0; 474 card->erased_byte = 0x0;
412 475
476 /* eMMC v4.5 or later */
477 if (card->ext_csd.rev >= 6) {
478 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE;
479
480 card->ext_csd.generic_cmd6_time = 10 *
481 ext_csd[EXT_CSD_GENERIC_CMD6_TIME];
482 card->ext_csd.power_off_longtime = 10 *
483 ext_csd[EXT_CSD_POWER_OFF_LONG_TIME];
484
485 card->ext_csd.cache_size =
486 ext_csd[EXT_CSD_CACHE_SIZE + 0] << 0 |
487 ext_csd[EXT_CSD_CACHE_SIZE + 1] << 8 |
488 ext_csd[EXT_CSD_CACHE_SIZE + 2] << 16 |
489 ext_csd[EXT_CSD_CACHE_SIZE + 3] << 24;
490 }
491
413out: 492out:
414 return err; 493 return err;
415} 494}
@@ -530,6 +609,86 @@ static struct device_type mmc_type = {
530}; 609};
531 610
532/* 611/*
612 * Select the PowerClass for the current bus width
613 * If power class is defined for 4/8 bit bus in the
614 * extended CSD register, select it by executing the
615 * mmc_switch command.
616 */
617static int mmc_select_powerclass(struct mmc_card *card,
618 unsigned int bus_width, u8 *ext_csd)
619{
620 int err = 0;
621 unsigned int pwrclass_val;
622 unsigned int index = 0;
623 struct mmc_host *host;
624
625 BUG_ON(!card);
626
627 host = card->host;
628 BUG_ON(!host);
629
630 if (ext_csd == NULL)
631 return 0;
632
633 /* Power class selection is supported for versions >= 4.0 */
634 if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
635 return 0;
636
637 /* Power class values are defined only for 4/8 bit bus */
638 if (bus_width == EXT_CSD_BUS_WIDTH_1)
639 return 0;
640
641 switch (1 << host->ios.vdd) {
642 case MMC_VDD_165_195:
643 if (host->ios.clock <= 26000000)
644 index = EXT_CSD_PWR_CL_26_195;
645 else if (host->ios.clock <= 52000000)
646 index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
647 EXT_CSD_PWR_CL_52_195 :
648 EXT_CSD_PWR_CL_DDR_52_195;
649 else if (host->ios.clock <= 200000000)
650 index = EXT_CSD_PWR_CL_200_195;
651 break;
652 case MMC_VDD_32_33:
653 case MMC_VDD_33_34:
654 case MMC_VDD_34_35:
655 case MMC_VDD_35_36:
656 if (host->ios.clock <= 26000000)
657 index = EXT_CSD_PWR_CL_26_360;
658 else if (host->ios.clock <= 52000000)
659 index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
660 EXT_CSD_PWR_CL_52_360 :
661 EXT_CSD_PWR_CL_DDR_52_360;
662 else if (host->ios.clock <= 200000000)
663 index = EXT_CSD_PWR_CL_200_360;
664 break;
665 default:
666 pr_warning("%s: Voltage range not supported "
667 "for power class.\n", mmc_hostname(host));
668 return -EINVAL;
669 }
670
671 pwrclass_val = ext_csd[index];
672
673 if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8))
674 pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >>
675 EXT_CSD_PWR_CL_8BIT_SHIFT;
676 else
677 pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >>
678 EXT_CSD_PWR_CL_4BIT_SHIFT;
679
680 /* If the power class is different from the default value */
681 if (pwrclass_val > 0) {
682 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
683 EXT_CSD_POWER_CLASS,
684 pwrclass_val,
685 card->ext_csd.generic_cmd6_time);
686 }
687
688 return err;
689}
690
691/*
533 * Handle the detection and initialisation of a card. 692 * Handle the detection and initialisation of a card.
534 * 693 *
535 * In the case of a resume, "oldcard" will contain the card 694 * In the case of a resume, "oldcard" will contain the card
@@ -548,11 +707,16 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
548 BUG_ON(!host); 707 BUG_ON(!host);
549 WARN_ON(!host->claimed); 708 WARN_ON(!host->claimed);
550 709
710 /* Set correct bus mode for MMC before attempting init */
711 if (!mmc_host_is_spi(host))
712 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN);
713
551 /* 714 /*
552 * Since we're changing the OCR value, we seem to 715 * Since we're changing the OCR value, we seem to
553 * need to tell some cards to go back to the idle 716 * need to tell some cards to go back to the idle
554 * state. We wait 1ms to give cards time to 717 * state. We wait 1ms to give cards time to
555 * respond. 718 * respond.
719 * mmc_go_idle is needed for eMMC that are asleep
556 */ 720 */
557 mmc_go_idle(host); 721 mmc_go_idle(host);
558 722
@@ -668,7 +832,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
668 */ 832 */
669 if (card->ext_csd.enhanced_area_en) { 833 if (card->ext_csd.enhanced_area_en) {
670 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 834 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
671 EXT_CSD_ERASE_GROUP_DEF, 1, 0); 835 EXT_CSD_ERASE_GROUP_DEF, 1,
836 card->ext_csd.generic_cmd6_time);
672 837
673 if (err && err != -EBADMSG) 838 if (err && err != -EBADMSG)
674 goto free_card; 839 goto free_card;
@@ -706,17 +871,35 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
706 } 871 }
707 872
708 /* 873 /*
874 * If the host supports the power_off_notify capability then
875 * set the notification byte in the ext_csd register of device
876 */
877 if ((host->caps2 & MMC_CAP2_POWEROFF_NOTIFY) &&
878 (card->poweroff_notify_state == MMC_NO_POWER_NOTIFICATION)) {
879 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
880 EXT_CSD_POWER_OFF_NOTIFICATION,
881 EXT_CSD_POWER_ON,
882 card->ext_csd.generic_cmd6_time);
883 if (err && err != -EBADMSG)
884 goto free_card;
885 }
886
887 if (!err)
888 card->poweroff_notify_state = MMC_POWERED_ON;
889
890 /*
709 * Activate high speed (if supported) 891 * Activate high speed (if supported)
710 */ 892 */
711 if ((card->ext_csd.hs_max_dtr != 0) && 893 if ((card->ext_csd.hs_max_dtr != 0) &&
712 (host->caps & MMC_CAP_MMC_HIGHSPEED)) { 894 (host->caps & MMC_CAP_MMC_HIGHSPEED)) {
713 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 895 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
714 EXT_CSD_HS_TIMING, 1, 0); 896 EXT_CSD_HS_TIMING, 1,
897 card->ext_csd.generic_cmd6_time);
715 if (err && err != -EBADMSG) 898 if (err && err != -EBADMSG)
716 goto free_card; 899 goto free_card;
717 900
718 if (err) { 901 if (err) {
719 printk(KERN_WARNING "%s: switch to highspeed failed\n", 902 pr_warning("%s: switch to highspeed failed\n",
720 mmc_hostname(card->host)); 903 mmc_hostname(card->host));
721 err = 0; 904 err = 0;
722 } else { 905 } else {
@@ -726,6 +909,22 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
726 } 909 }
727 910
728 /* 911 /*
912 * Enable HPI feature (if supported)
913 */
914 if (card->ext_csd.hpi) {
915 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
916 EXT_CSD_HPI_MGMT, 1, 0);
917 if (err && err != -EBADMSG)
918 goto free_card;
919 if (err) {
920 pr_warning("%s: Enabling HPI failed\n",
921 mmc_hostname(card->host));
922 err = 0;
923 } else
924 card->ext_csd.hpi_en = 1;
925 }
926
927 /*
729 * Compute bus speed. 928 * Compute bus speed.
730 */ 929 */
731 max_dtr = (unsigned int)-1; 930 max_dtr = (unsigned int)-1;
@@ -780,10 +979,18 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
780 bus_width = bus_widths[idx]; 979 bus_width = bus_widths[idx];
781 if (bus_width == MMC_BUS_WIDTH_1) 980 if (bus_width == MMC_BUS_WIDTH_1)
782 ddr = 0; /* no DDR for 1-bit width */ 981 ddr = 0; /* no DDR for 1-bit width */
982 err = mmc_select_powerclass(card, ext_csd_bits[idx][0],
983 ext_csd);
984 if (err)
985 pr_err("%s: power class selection to "
986 "bus width %d failed\n",
987 mmc_hostname(card->host),
988 1 << bus_width);
989
783 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 990 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
784 EXT_CSD_BUS_WIDTH, 991 EXT_CSD_BUS_WIDTH,
785 ext_csd_bits[idx][0], 992 ext_csd_bits[idx][0],
786 0); 993 card->ext_csd.generic_cmd6_time);
787 if (!err) { 994 if (!err) {
788 mmc_set_bus_width(card->host, bus_width); 995 mmc_set_bus_width(card->host, bus_width);
789 996
@@ -803,13 +1010,21 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
803 } 1010 }
804 1011
805 if (!err && ddr) { 1012 if (!err && ddr) {
1013 err = mmc_select_powerclass(card, ext_csd_bits[idx][1],
1014 ext_csd);
1015 if (err)
1016 pr_err("%s: power class selection to "
1017 "bus width %d ddr %d failed\n",
1018 mmc_hostname(card->host),
1019 1 << bus_width, ddr);
1020
806 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1021 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
807 EXT_CSD_BUS_WIDTH, 1022 EXT_CSD_BUS_WIDTH,
808 ext_csd_bits[idx][1], 1023 ext_csd_bits[idx][1],
809 0); 1024 card->ext_csd.generic_cmd6_time);
810 } 1025 }
811 if (err) { 1026 if (err) {
812 printk(KERN_WARNING "%s: switch to bus width %d ddr %d " 1027 pr_warning("%s: switch to bus width %d ddr %d "
813 "failed\n", mmc_hostname(card->host), 1028 "failed\n", mmc_hostname(card->host),
814 1 << bus_width, ddr); 1029 1 << bus_width, ddr);
815 goto free_card; 1030 goto free_card;
@@ -840,6 +1055,23 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
840 } 1055 }
841 } 1056 }
842 1057
1058 /*
1059 * If cache size is higher than 0, this indicates
1060 * the existence of cache and it can be turned on.
1061 */
1062 if ((host->caps2 & MMC_CAP2_CACHE_CTRL) &&
1063 card->ext_csd.cache_size > 0) {
1064 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1065 EXT_CSD_CACHE_CTRL, 1, 0);
1066 if (err && err != -EBADMSG)
1067 goto free_card;
1068
1069 /*
1070 * Only if no error, cache is turned on successfully.
1071 */
1072 card->ext_csd.cache_ctrl = err ? 0 : 1;
1073 }
1074
843 if (!oldcard) 1075 if (!oldcard)
844 host->card = card; 1076 host->card = card;
845 1077
@@ -891,6 +1123,7 @@ static void mmc_detect(struct mmc_host *host)
891 1123
892 mmc_claim_host(host); 1124 mmc_claim_host(host);
893 mmc_detach_bus(host); 1125 mmc_detach_bus(host);
1126 mmc_power_off(host);
894 mmc_release_host(host); 1127 mmc_release_host(host);
895 } 1128 }
896} 1129}
@@ -900,16 +1133,20 @@ static void mmc_detect(struct mmc_host *host)
900 */ 1133 */
901static int mmc_suspend(struct mmc_host *host) 1134static int mmc_suspend(struct mmc_host *host)
902{ 1135{
1136 int err = 0;
1137
903 BUG_ON(!host); 1138 BUG_ON(!host);
904 BUG_ON(!host->card); 1139 BUG_ON(!host->card);
905 1140
906 mmc_claim_host(host); 1141 mmc_claim_host(host);
907 if (!mmc_host_is_spi(host)) 1142 if (mmc_card_can_sleep(host))
1143 err = mmc_card_sleep(host);
1144 else if (!mmc_host_is_spi(host))
908 mmc_deselect_cards(host); 1145 mmc_deselect_cards(host);
909 host->card->state &= ~MMC_STATE_HIGHSPEED; 1146 host->card->state &= ~MMC_STATE_HIGHSPEED;
910 mmc_release_host(host); 1147 mmc_release_host(host);
911 1148
912 return 0; 1149 return err;
913} 1150}
914 1151
915/* 1152/*
@@ -1016,6 +1253,10 @@ int mmc_attach_mmc(struct mmc_host *host)
1016 BUG_ON(!host); 1253 BUG_ON(!host);
1017 WARN_ON(!host->claimed); 1254 WARN_ON(!host->claimed);
1018 1255
1256 /* Set correct bus mode for MMC before attempting attach */
1257 if (!mmc_host_is_spi(host))
1258 mmc_set_bus_mode(host, MMC_BUSMODE_OPENDRAIN);
1259
1019 err = mmc_send_op_cond(host, 0, &ocr); 1260 err = mmc_send_op_cond(host, 0, &ocr);
1020 if (err) 1261 if (err)
1021 return err; 1262 return err;
@@ -1038,7 +1279,7 @@ int mmc_attach_mmc(struct mmc_host *host)
1038 * support. 1279 * support.
1039 */ 1280 */
1040 if (ocr & 0x7F) { 1281 if (ocr & 0x7F) {
1041 printk(KERN_WARNING "%s: card claims to support voltages " 1282 pr_warning("%s: card claims to support voltages "
1042 "below the defined range. These will be ignored.\n", 1283 "below the defined range. These will be ignored.\n",
1043 mmc_hostname(host)); 1284 mmc_hostname(host));
1044 ocr &= ~0x7F; 1285 ocr &= ~0x7F;
@@ -1077,7 +1318,7 @@ remove_card:
1077err: 1318err:
1078 mmc_detach_bus(host); 1319 mmc_detach_bus(host);
1079 1320
1080 printk(KERN_ERR "%s: error %d whilst initialising MMC card\n", 1321 pr_err("%s: error %d whilst initialising MMC card\n",
1081 mmc_hostname(host), err); 1322 mmc_hostname(host), err);
1082 1323
1083 return err; 1324 return err;
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 770c3d06f5dc..007863eea4fb 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -233,7 +233,7 @@ static int
233mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host, 233mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
234 u32 opcode, void *buf, unsigned len) 234 u32 opcode, void *buf, unsigned len)
235{ 235{
236 struct mmc_request mrq = {0}; 236 struct mmc_request mrq = {NULL};
237 struct mmc_command cmd = {0}; 237 struct mmc_command cmd = {0};
238 struct mmc_data data = {0}; 238 struct mmc_data data = {0};
239 struct scatterlist sg; 239 struct scatterlist sg;
@@ -414,7 +414,7 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
414 return -EBADMSG; 414 return -EBADMSG;
415 } else { 415 } else {
416 if (status & 0xFDFFA000) 416 if (status & 0xFDFFA000)
417 printk(KERN_WARNING "%s: unexpected status %#x after " 417 pr_warning("%s: unexpected status %#x after "
418 "switch", mmc_hostname(card->host), status); 418 "switch", mmc_hostname(card->host), status);
419 if (status & R1_SWITCH_ERROR) 419 if (status & R1_SWITCH_ERROR)
420 return -EBADMSG; 420 return -EBADMSG;
@@ -454,7 +454,7 @@ static int
454mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode, 454mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
455 u8 len) 455 u8 len)
456{ 456{
457 struct mmc_request mrq = {0}; 457 struct mmc_request mrq = {NULL};
458 struct mmc_command cmd = {0}; 458 struct mmc_command cmd = {0};
459 struct mmc_data data = {0}; 459 struct mmc_data data = {0};
460 struct scatterlist sg; 460 struct scatterlist sg;
@@ -476,7 +476,7 @@ mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
476 else if (len == 4) 476 else if (len == 4)
477 test_buf = testdata_4bit; 477 test_buf = testdata_4bit;
478 else { 478 else {
479 printk(KERN_ERR "%s: Invalid bus_width %d\n", 479 pr_err("%s: Invalid bus_width %d\n",
480 mmc_hostname(host), len); 480 mmc_hostname(host), len);
481 kfree(data_buf); 481 kfree(data_buf);
482 return -EINVAL; 482 return -EINVAL;
@@ -547,3 +547,34 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width)
547 err = mmc_send_bus_test(card, card->host, MMC_BUS_TEST_R, width); 547 err = mmc_send_bus_test(card, card->host, MMC_BUS_TEST_R, width);
548 return err; 548 return err;
549} 549}
550
551int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status)
552{
553 struct mmc_command cmd = {0};
554 unsigned int opcode;
555 unsigned int flags;
556 int err;
557
558 opcode = card->ext_csd.hpi_cmd;
559 if (opcode == MMC_STOP_TRANSMISSION)
560 flags = MMC_RSP_R1 | MMC_CMD_AC;
561 else if (opcode == MMC_SEND_STATUS)
562 flags = MMC_RSP_R1 | MMC_CMD_AC;
563
564 cmd.opcode = opcode;
565 cmd.arg = card->rca << 16 | 1;
566 cmd.flags = flags;
567 cmd.cmd_timeout_ms = card->ext_csd.out_of_int_time;
568
569 err = mmc_wait_for_cmd(card->host, &cmd, 0);
570 if (err) {
571 pr_warn("%s: error %d interrupting operation. "
572 "HPI command response %#x\n", mmc_hostname(card->host),
573 err, cmd.resp[0]);
574 return err;
575 }
576 if (status)
577 *status = cmd.resp[0];
578
579 return 0;
580}
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
index 9276946fa5b7..3dd8941c2980 100644
--- a/drivers/mmc/core/mmc_ops.h
+++ b/drivers/mmc/core/mmc_ops.h
@@ -26,6 +26,7 @@ int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp);
26int mmc_spi_set_crc(struct mmc_host *host, int use_crc); 26int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
27int mmc_card_sleepawake(struct mmc_host *host, int sleep); 27int mmc_card_sleepawake(struct mmc_host *host, int sleep);
28int mmc_bus_test(struct mmc_card *card, u8 bus_width); 28int mmc_bus_test(struct mmc_card *card, u8 bus_width);
29int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status);
29 30
30#endif 31#endif
31 32
diff --git a/drivers/mmc/core/quirks.c b/drivers/mmc/core/quirks.c
index 3a596217029e..6c3cf98a62eb 100644
--- a/drivers/mmc/core/quirks.c
+++ b/drivers/mmc/core/quirks.c
@@ -21,6 +21,14 @@
21#define SDIO_DEVICE_ID_TI_WL1271 0x4076 21#define SDIO_DEVICE_ID_TI_WL1271 0x4076
22#endif 22#endif
23 23
24#ifndef SDIO_VENDOR_ID_STE
25#define SDIO_VENDOR_ID_STE 0x0020
26#endif
27
28#ifndef SDIO_DEVICE_ID_STE_CW1200
29#define SDIO_DEVICE_ID_STE_CW1200 0x2280
30#endif
31
24/* 32/*
25 * This hook just adds a quirk for all sdio devices 33 * This hook just adds a quirk for all sdio devices
26 */ 34 */
@@ -46,6 +54,9 @@ static const struct mmc_fixup mmc_fixup_methods[] = {
46 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271, 54 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
47 add_quirk, MMC_QUIRK_DISABLE_CD), 55 add_quirk, MMC_QUIRK_DISABLE_CD),
48 56
57 SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200,
58 add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512),
59
49 END_FIXUP 60 END_FIXUP
50}; 61};
51 62
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 0370e03e3142..a230e7f9d77a 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -163,7 +163,7 @@ static int mmc_decode_csd(struct mmc_card *card)
163 csd->erase_size = 1; 163 csd->erase_size = 1;
164 break; 164 break;
165 default: 165 default:
166 printk(KERN_ERR "%s: unrecognised CSD structure version %d\n", 166 pr_err("%s: unrecognised CSD structure version %d\n",
167 mmc_hostname(card->host), csd_struct); 167 mmc_hostname(card->host), csd_struct);
168 return -EINVAL; 168 return -EINVAL;
169 } 169 }
@@ -187,7 +187,7 @@ static int mmc_decode_scr(struct mmc_card *card)
187 187
188 scr_struct = UNSTUFF_BITS(resp, 60, 4); 188 scr_struct = UNSTUFF_BITS(resp, 60, 4);
189 if (scr_struct != 0) { 189 if (scr_struct != 0) {
190 printk(KERN_ERR "%s: unrecognised SCR structure version %d\n", 190 pr_err("%s: unrecognised SCR structure version %d\n",
191 mmc_hostname(card->host), scr_struct); 191 mmc_hostname(card->host), scr_struct);
192 return -EINVAL; 192 return -EINVAL;
193 } 193 }
@@ -218,7 +218,7 @@ static int mmc_read_ssr(struct mmc_card *card)
218 u32 *ssr; 218 u32 *ssr;
219 219
220 if (!(card->csd.cmdclass & CCC_APP_SPEC)) { 220 if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
221 printk(KERN_WARNING "%s: card lacks mandatory SD Status " 221 pr_warning("%s: card lacks mandatory SD Status "
222 "function.\n", mmc_hostname(card->host)); 222 "function.\n", mmc_hostname(card->host));
223 return 0; 223 return 0;
224 } 224 }
@@ -229,7 +229,7 @@ static int mmc_read_ssr(struct mmc_card *card)
229 229
230 err = mmc_app_sd_status(card, ssr); 230 err = mmc_app_sd_status(card, ssr);
231 if (err) { 231 if (err) {
232 printk(KERN_WARNING "%s: problem reading SD Status " 232 pr_warning("%s: problem reading SD Status "
233 "register.\n", mmc_hostname(card->host)); 233 "register.\n", mmc_hostname(card->host));
234 err = 0; 234 err = 0;
235 goto out; 235 goto out;
@@ -253,7 +253,7 @@ static int mmc_read_ssr(struct mmc_card *card)
253 card->ssr.erase_offset = eo * 1000; 253 card->ssr.erase_offset = eo * 1000;
254 } 254 }
255 } else { 255 } else {
256 printk(KERN_WARNING "%s: SD Status: Invalid Allocation Unit " 256 pr_warning("%s: SD Status: Invalid Allocation Unit "
257 "size.\n", mmc_hostname(card->host)); 257 "size.\n", mmc_hostname(card->host));
258 } 258 }
259out: 259out:
@@ -273,7 +273,7 @@ static int mmc_read_switch(struct mmc_card *card)
273 return 0; 273 return 0;
274 274
275 if (!(card->csd.cmdclass & CCC_SWITCH)) { 275 if (!(card->csd.cmdclass & CCC_SWITCH)) {
276 printk(KERN_WARNING "%s: card lacks mandatory switch " 276 pr_warning("%s: card lacks mandatory switch "
277 "function, performance might suffer.\n", 277 "function, performance might suffer.\n",
278 mmc_hostname(card->host)); 278 mmc_hostname(card->host));
279 return 0; 279 return 0;
@@ -283,7 +283,7 @@ static int mmc_read_switch(struct mmc_card *card)
283 283
284 status = kmalloc(64, GFP_KERNEL); 284 status = kmalloc(64, GFP_KERNEL);
285 if (!status) { 285 if (!status) {
286 printk(KERN_ERR "%s: could not allocate a buffer for " 286 pr_err("%s: could not allocate a buffer for "
287 "switch capabilities.\n", 287 "switch capabilities.\n",
288 mmc_hostname(card->host)); 288 mmc_hostname(card->host));
289 return -ENOMEM; 289 return -ENOMEM;
@@ -299,13 +299,16 @@ static int mmc_read_switch(struct mmc_card *card)
299 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) 299 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
300 goto out; 300 goto out;
301 301
302 printk(KERN_WARNING "%s: problem reading Bus Speed modes.\n", 302 pr_warning("%s: problem reading Bus Speed modes.\n",
303 mmc_hostname(card->host)); 303 mmc_hostname(card->host));
304 err = 0; 304 err = 0;
305 305
306 goto out; 306 goto out;
307 } 307 }
308 308
309 if (status[13] & UHS_SDR50_BUS_SPEED)
310 card->sw_caps.hs_max_dtr = 50000000;
311
309 if (card->scr.sda_spec3) { 312 if (card->scr.sda_spec3) {
310 card->sw_caps.sd3_bus_mode = status[13]; 313 card->sw_caps.sd3_bus_mode = status[13];
311 314
@@ -319,7 +322,7 @@ static int mmc_read_switch(struct mmc_card *card)
319 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) 322 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
320 goto out; 323 goto out;
321 324
322 printk(KERN_WARNING "%s: problem reading " 325 pr_warning("%s: problem reading "
323 "Driver Strength.\n", 326 "Driver Strength.\n",
324 mmc_hostname(card->host)); 327 mmc_hostname(card->host));
325 err = 0; 328 err = 0;
@@ -339,7 +342,7 @@ static int mmc_read_switch(struct mmc_card *card)
339 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) 342 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT)
340 goto out; 343 goto out;
341 344
342 printk(KERN_WARNING "%s: problem reading " 345 pr_warning("%s: problem reading "
343 "Current Limit.\n", 346 "Current Limit.\n",
344 mmc_hostname(card->host)); 347 mmc_hostname(card->host));
345 err = 0; 348 err = 0;
@@ -348,9 +351,6 @@ static int mmc_read_switch(struct mmc_card *card)
348 } 351 }
349 352
350 card->sw_caps.sd3_curr_limit = status[7]; 353 card->sw_caps.sd3_curr_limit = status[7];
351 } else {
352 if (status[13] & 0x02)
353 card->sw_caps.hs_max_dtr = 50000000;
354 } 354 }
355 355
356out: 356out:
@@ -383,7 +383,7 @@ int mmc_sd_switch_hs(struct mmc_card *card)
383 383
384 status = kmalloc(64, GFP_KERNEL); 384 status = kmalloc(64, GFP_KERNEL);
385 if (!status) { 385 if (!status) {
386 printk(KERN_ERR "%s: could not allocate a buffer for " 386 pr_err("%s: could not allocate a buffer for "
387 "switch capabilities.\n", mmc_hostname(card->host)); 387 "switch capabilities.\n", mmc_hostname(card->host));
388 return -ENOMEM; 388 return -ENOMEM;
389 } 389 }
@@ -393,7 +393,7 @@ int mmc_sd_switch_hs(struct mmc_card *card)
393 goto out; 393 goto out;
394 394
395 if ((status[16] & 0xF) != 1) { 395 if ((status[16] & 0xF) != 1) {
396 printk(KERN_WARNING "%s: Problem switching card " 396 pr_warning("%s: Problem switching card "
397 "into high-speed mode!\n", 397 "into high-speed mode!\n",
398 mmc_hostname(card->host)); 398 mmc_hostname(card->host));
399 err = 0; 399 err = 0;
@@ -459,7 +459,7 @@ static int sd_select_driver_type(struct mmc_card *card, u8 *status)
459 return err; 459 return err;
460 460
461 if ((status[15] & 0xF) != drive_strength) { 461 if ((status[15] & 0xF) != drive_strength) {
462 printk(KERN_WARNING "%s: Problem setting drive strength!\n", 462 pr_warning("%s: Problem setting drive strength!\n",
463 mmc_hostname(card->host)); 463 mmc_hostname(card->host));
464 return 0; 464 return 0;
465 } 465 }
@@ -538,7 +538,7 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
538 return err; 538 return err;
539 539
540 if ((status[16] & 0xF) != card->sd_bus_speed) 540 if ((status[16] & 0xF) != card->sd_bus_speed)
541 printk(KERN_WARNING "%s: Problem setting bus speed mode!\n", 541 pr_warning("%s: Problem setting bus speed mode!\n",
542 mmc_hostname(card->host)); 542 mmc_hostname(card->host));
543 else { 543 else {
544 mmc_set_timing(card->host, timing); 544 mmc_set_timing(card->host, timing);
@@ -600,7 +600,7 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
600 return err; 600 return err;
601 601
602 if (((status[15] >> 4) & 0x0F) != current_limit) 602 if (((status[15] >> 4) & 0x0F) != current_limit)
603 printk(KERN_WARNING "%s: Problem setting current limit!\n", 603 pr_warning("%s: Problem setting current limit!\n",
604 mmc_hostname(card->host)); 604 mmc_hostname(card->host));
605 605
606 return 0; 606 return 0;
@@ -622,7 +622,7 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
622 622
623 status = kmalloc(64, GFP_KERNEL); 623 status = kmalloc(64, GFP_KERNEL);
624 if (!status) { 624 if (!status) {
625 printk(KERN_ERR "%s: could not allocate a buffer for " 625 pr_err("%s: could not allocate a buffer for "
626 "switch capabilities.\n", mmc_hostname(card->host)); 626 "switch capabilities.\n", mmc_hostname(card->host));
627 return -ENOMEM; 627 return -ENOMEM;
628 } 628 }
@@ -852,7 +852,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
852 ro = host->ops->get_ro(host); 852 ro = host->ops->get_ro(host);
853 853
854 if (ro < 0) { 854 if (ro < 0) {
855 printk(KERN_WARNING "%s: host does not " 855 pr_warning("%s: host does not "
856 "support reading read-only " 856 "support reading read-only "
857 "switch. assuming write-enable.\n", 857 "switch. assuming write-enable.\n",
858 mmc_hostname(host)); 858 mmc_hostname(host));
@@ -929,8 +929,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
929 err = mmc_send_relative_addr(host, &card->rca); 929 err = mmc_send_relative_addr(host, &card->rca);
930 if (err) 930 if (err)
931 return err; 931 return err;
932
933 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
934 } 932 }
935 933
936 if (!oldcard) { 934 if (!oldcard) {
@@ -1043,6 +1041,7 @@ static void mmc_sd_detect(struct mmc_host *host)
1043 1041
1044 mmc_claim_host(host); 1042 mmc_claim_host(host);
1045 mmc_detach_bus(host); 1043 mmc_detach_bus(host);
1044 mmc_power_off(host);
1046 mmc_release_host(host); 1045 mmc_release_host(host);
1047 } 1046 }
1048} 1047}
@@ -1167,7 +1166,7 @@ int mmc_attach_sd(struct mmc_host *host)
1167 * support. 1166 * support.
1168 */ 1167 */
1169 if (ocr & 0x7F) { 1168 if (ocr & 0x7F) {
1170 printk(KERN_WARNING "%s: card claims to support voltages " 1169 pr_warning("%s: card claims to support voltages "
1171 "below the defined range. These will be ignored.\n", 1170 "below the defined range. These will be ignored.\n",
1172 mmc_hostname(host)); 1171 mmc_hostname(host));
1173 ocr &= ~0x7F; 1172 ocr &= ~0x7F;
@@ -1175,7 +1174,7 @@ int mmc_attach_sd(struct mmc_host *host)
1175 1174
1176 if ((ocr & MMC_VDD_165_195) && 1175 if ((ocr & MMC_VDD_165_195) &&
1177 !(host->ocr_avail_sd & MMC_VDD_165_195)) { 1176 !(host->ocr_avail_sd & MMC_VDD_165_195)) {
1178 printk(KERN_WARNING "%s: SD card claims to support the " 1177 pr_warning("%s: SD card claims to support the "
1179 "incompletely defined 'low voltage range'. This " 1178 "incompletely defined 'low voltage range'. This "
1180 "will be ignored.\n", mmc_hostname(host)); 1179 "will be ignored.\n", mmc_hostname(host));
1181 ocr &= ~MMC_VDD_165_195; 1180 ocr &= ~MMC_VDD_165_195;
@@ -1214,7 +1213,7 @@ remove_card:
1214err: 1213err:
1215 mmc_detach_bus(host); 1214 mmc_detach_bus(host);
1216 1215
1217 printk(KERN_ERR "%s: error %d whilst initialising SD card\n", 1216 pr_err("%s: error %d whilst initialising SD card\n",
1218 mmc_hostname(host), err); 1217 mmc_hostname(host), err);
1219 1218
1220 return err; 1219 return err;
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 021fed153804..46a785419fab 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -67,7 +67,7 @@ EXPORT_SYMBOL_GPL(mmc_app_cmd);
67int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card, 67int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
68 struct mmc_command *cmd, int retries) 68 struct mmc_command *cmd, int retries)
69{ 69{
70 struct mmc_request mrq = {0}; 70 struct mmc_request mrq = {NULL};
71 71
72 int i, err; 72 int i, err;
73 73
@@ -244,7 +244,7 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
244int mmc_app_send_scr(struct mmc_card *card, u32 *scr) 244int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
245{ 245{
246 int err; 246 int err;
247 struct mmc_request mrq = {0}; 247 struct mmc_request mrq = {NULL};
248 struct mmc_command cmd = {0}; 248 struct mmc_command cmd = {0};
249 struct mmc_data data = {0}; 249 struct mmc_data data = {0};
250 struct scatterlist sg; 250 struct scatterlist sg;
@@ -303,7 +303,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
303int mmc_sd_switch(struct mmc_card *card, int mode, int group, 303int mmc_sd_switch(struct mmc_card *card, int mode, int group,
304 u8 value, u8 *resp) 304 u8 value, u8 *resp)
305{ 305{
306 struct mmc_request mrq = {0}; 306 struct mmc_request mrq = {NULL};
307 struct mmc_command cmd = {0}; 307 struct mmc_command cmd = {0};
308 struct mmc_data data = {0}; 308 struct mmc_data data = {0};
309 struct scatterlist sg; 309 struct scatterlist sg;
@@ -348,7 +348,7 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
348int mmc_app_sd_status(struct mmc_card *card, void *ssr) 348int mmc_app_sd_status(struct mmc_card *card, void *ssr)
349{ 349{
350 int err; 350 int err;
351 struct mmc_request mrq = {0}; 351 struct mmc_request mrq = {NULL};
352 struct mmc_command cmd = {0}; 352 struct mmc_command cmd = {0};
353 struct mmc_data data = {0}; 353 struct mmc_data data = {0};
354 struct scatterlist sg; 354 struct scatterlist sg;
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 262fff019177..3ab565e32a6a 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -111,8 +111,8 @@ static int sdio_read_cccr(struct mmc_card *card)
111 111
112 cccr_vsn = data & 0x0f; 112 cccr_vsn = data & 0x0f;
113 113
114 if (cccr_vsn > SDIO_CCCR_REV_1_20) { 114 if (cccr_vsn > SDIO_CCCR_REV_3_00) {
115 printk(KERN_ERR "%s: unrecognised CCCR structure version %d\n", 115 pr_err("%s: unrecognised CCCR structure version %d\n",
116 mmc_hostname(card->host), cccr_vsn); 116 mmc_hostname(card->host), cccr_vsn);
117 return -EINVAL; 117 return -EINVAL;
118 } 118 }
@@ -408,8 +408,6 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
408 */ 408 */
409 if (oldcard) 409 if (oldcard)
410 oldcard->rca = card->rca; 410 oldcard->rca = card->rca;
411
412 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
413 } 411 }
414 412
415 /* 413 /*
@@ -597,6 +595,7 @@ out:
597 595
598 mmc_claim_host(host); 596 mmc_claim_host(host);
599 mmc_detach_bus(host); 597 mmc_detach_bus(host);
598 mmc_power_off(host);
600 mmc_release_host(host); 599 mmc_release_host(host);
601 } 600 }
602} 601}
@@ -778,7 +777,7 @@ int mmc_attach_sdio(struct mmc_host *host)
778 * support. 777 * support.
779 */ 778 */
780 if (ocr & 0x7F) { 779 if (ocr & 0x7F) {
781 printk(KERN_WARNING "%s: card claims to support voltages " 780 pr_warning("%s: card claims to support voltages "
782 "below the defined range. These will be ignored.\n", 781 "below the defined range. These will be ignored.\n",
783 mmc_hostname(host)); 782 mmc_hostname(host));
784 ocr &= ~0x7F; 783 ocr &= ~0x7F;
@@ -875,7 +874,7 @@ remove:
875err: 874err:
876 mmc_detach_bus(host); 875 mmc_detach_bus(host);
877 876
878 printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n", 877 pr_err("%s: error %d whilst initialising SDIO card\n",
879 mmc_hostname(host), err); 878 mmc_hostname(host), err);
880 879
881 return err; 880 return err;
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index e4e6822d09e3..c643b2f78bf1 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -173,7 +173,7 @@ static int sdio_bus_remove(struct device *dev)
173 drv->remove(func); 173 drv->remove(func);
174 174
175 if (func->irq_handler) { 175 if (func->irq_handler) {
176 printk(KERN_WARNING "WARNING: driver %s did not remove " 176 pr_warning("WARNING: driver %s did not remove "
177 "its interrupt handler!\n", drv->name); 177 "its interrupt handler!\n", drv->name);
178 sdio_claim_host(func); 178 sdio_claim_host(func);
179 sdio_release_irq(func); 179 sdio_release_irq(func);
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
index 541bdb89e0c5..f1c7ed8f4d85 100644
--- a/drivers/mmc/core/sdio_cis.c
+++ b/drivers/mmc/core/sdio_cis.c
@@ -132,7 +132,7 @@ static int cis_tpl_parse(struct mmc_card *card, struct sdio_func *func,
132 ret = -EINVAL; 132 ret = -EINVAL;
133 } 133 }
134 if (ret && ret != -EILSEQ && ret != -ENOENT) { 134 if (ret && ret != -EILSEQ && ret != -ENOENT) {
135 printk(KERN_ERR "%s: bad %s tuple 0x%02x (%u bytes)\n", 135 pr_err("%s: bad %s tuple 0x%02x (%u bytes)\n",
136 mmc_hostname(card->host), tpl_descr, code, size); 136 mmc_hostname(card->host), tpl_descr, code, size);
137 } 137 }
138 } else { 138 } else {
@@ -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 printk(KERN_WARNING "%s: queuing unknown" 316 pr_warning("%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/sdio_irq.c b/drivers/mmc/core/sdio_irq.c
index 03ead028d2ce..b644dd59c16e 100644
--- a/drivers/mmc/core/sdio_irq.c
+++ b/drivers/mmc/core/sdio_irq.c
@@ -45,7 +45,7 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
45 45
46 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending); 46 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending);
47 if (ret) { 47 if (ret) {
48 printk(KERN_DEBUG "%s: error %d reading SDIO_CCCR_INTx\n", 48 pr_debug("%s: error %d reading SDIO_CCCR_INTx\n",
49 mmc_card_id(card), ret); 49 mmc_card_id(card), ret);
50 return ret; 50 return ret;
51 } 51 }
@@ -55,7 +55,7 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
55 if (pending & (1 << i)) { 55 if (pending & (1 << i)) {
56 func = card->sdio_func[i - 1]; 56 func = card->sdio_func[i - 1];
57 if (!func) { 57 if (!func) {
58 printk(KERN_WARNING "%s: pending IRQ for " 58 pr_warning("%s: pending IRQ for "
59 "non-existent function\n", 59 "non-existent function\n",
60 mmc_card_id(card)); 60 mmc_card_id(card));
61 ret = -EINVAL; 61 ret = -EINVAL;
@@ -63,7 +63,7 @@ static int process_sdio_pending_irqs(struct mmc_card *card)
63 func->irq_handler(func); 63 func->irq_handler(func);
64 count++; 64 count++;
65 } else { 65 } else {
66 printk(KERN_WARNING "%s: pending IRQ with no handler\n", 66 pr_warning("%s: pending IRQ with no handler\n",
67 sdio_func_id(func)); 67 sdio_func_id(func));
68 ret = -EINVAL; 68 ret = -EINVAL;
69 } 69 }
diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c
index f087d876c573..b0517cc06200 100644
--- a/drivers/mmc/core/sdio_ops.c
+++ b/drivers/mmc/core/sdio_ops.c
@@ -121,7 +121,7 @@ int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
121int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, 121int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
122 unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz) 122 unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz)
123{ 123{
124 struct mmc_request mrq = {0}; 124 struct mmc_request mrq = {NULL};
125 struct mmc_command cmd = {0}; 125 struct mmc_command cmd = {0};
126 struct mmc_data data = {0}; 126 struct mmc_data data = {0};
127 struct scatterlist sg; 127 struct scatterlist sg;
@@ -144,8 +144,11 @@ int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
144 cmd.arg |= fn << 28; 144 cmd.arg |= fn << 28;
145 cmd.arg |= incr_addr ? 0x04000000 : 0x00000000; 145 cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
146 cmd.arg |= addr << 9; 146 cmd.arg |= addr << 9;
147 if (blocks == 1 && blksz <= 512) 147 if (blocks == 1 && blksz < 512)
148 cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */ 148 cmd.arg |= blksz; /* byte mode */
149 else if (blocks == 1 && blksz == 512 &&
150 !(mmc_card_broken_byte_mode_512(card)))
151 cmd.arg |= 0; /* byte mode, 0==512 */
149 else 152 else
150 cmd.arg |= 0x08000000 | blocks; /* block mode */ 153 cmd.arg |= 0x08000000 | blocks; /* block mode */
151 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC; 154 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 8c87096531e9..87d5067ba629 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -130,13 +130,13 @@ config MMC_SDHCI_CNS3XXX
130 If unsure, say N. 130 If unsure, say N.
131 131
132config MMC_SDHCI_ESDHC_IMX 132config MMC_SDHCI_ESDHC_IMX
133 tristate "SDHCI platform support for the Freescale eSDHC i.MX controller" 133 tristate "SDHCI support for the Freescale eSDHC/uSDHC i.MX controller"
134 depends on ARCH_MX25 || ARCH_MX35 || ARCH_MX5 134 depends on ARCH_MXC
135 depends on MMC_SDHCI_PLTFM 135 depends on MMC_SDHCI_PLTFM
136 select MMC_SDHCI_IO_ACCESSORS 136 select MMC_SDHCI_IO_ACCESSORS
137 help 137 help
138 This selects the Freescale eSDHC controller support on the platform 138 This selects the Freescale eSDHC/uSDHC controller support
139 bus, found on platforms like mx35/51. 139 found on i.MX25, i.MX35 i.MX5x and i.MX6x.
140 140
141 If you have a controller with this interface, say Y or M here. 141 If you have a controller with this interface, say Y or M here.
142 142
@@ -326,11 +326,11 @@ config MMC_MSM
326 support for SDIO devices. 326 support for SDIO devices.
327 327
328config MMC_MXC 328config MMC_MXC
329 tristate "Freescale i.MX2/3 Multimedia Card Interface support" 329 tristate "Freescale i.MX21/27/31 Multimedia Card Interface support"
330 depends on MACH_MX21 || MACH_MX27 || ARCH_MX31 330 depends on ARCH_MXC
331 help 331 help
332 This selects the Freescale i.MX2/3 Multimedia card Interface. 332 This selects the Freescale i.MX21, i.MX27 and i.MX31 Multimedia card
333 If you have a i.MX platform with a Multimedia Card slot, 333 Interface. If you have a i.MX platform with a Multimedia Card slot,
334 say Y or M here. 334 say Y or M here.
335 335
336 If unsure, say N. 336 If unsure, say N.
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index a4aa3af86fed..a8b4d2aa18e5 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -869,7 +869,11 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
869static irqreturn_t at91_mmc_det_irq(int irq, void *_host) 869static irqreturn_t at91_mmc_det_irq(int irq, void *_host)
870{ 870{
871 struct at91mci_host *host = _host; 871 struct at91mci_host *host = _host;
872 int present = !gpio_get_value(irq_to_gpio(irq)); 872 int present;
873
874 /* entering this ISR means that we have configured det_pin:
875 * we can use its value in board structure */
876 present = !gpio_get_value(host->board->det_pin);
873 877
874 /* 878 /*
875 * we expect this irq on both insert and remove, 879 * we expect this irq on both insert and remove,
diff --git a/drivers/mmc/host/atmel-mci-regs.h b/drivers/mmc/host/atmel-mci-regs.h
index fc8a0fe7c5c5..000b3ad0f5ca 100644
--- a/drivers/mmc/host/atmel-mci-regs.h
+++ b/drivers/mmc/host/atmel-mci-regs.h
@@ -17,112 +17,126 @@
17#define __DRIVERS_MMC_ATMEL_MCI_H__ 17#define __DRIVERS_MMC_ATMEL_MCI_H__
18 18
19/* MCI Register Definitions */ 19/* MCI Register Definitions */
20#define MCI_CR 0x0000 /* Control */ 20#define ATMCI_CR 0x0000 /* Control */
21# define MCI_CR_MCIEN ( 1 << 0) /* MCI Enable */ 21# define ATMCI_CR_MCIEN ( 1 << 0) /* MCI Enable */
22# define MCI_CR_MCIDIS ( 1 << 1) /* MCI Disable */ 22# define ATMCI_CR_MCIDIS ( 1 << 1) /* MCI Disable */
23# define MCI_CR_PWSEN ( 1 << 2) /* Power Save Enable */ 23# define ATMCI_CR_PWSEN ( 1 << 2) /* Power Save Enable */
24# define MCI_CR_PWSDIS ( 1 << 3) /* Power Save Disable */ 24# define ATMCI_CR_PWSDIS ( 1 << 3) /* Power Save Disable */
25# define MCI_CR_SWRST ( 1 << 7) /* Software Reset */ 25# define ATMCI_CR_SWRST ( 1 << 7) /* Software Reset */
26#define MCI_MR 0x0004 /* Mode */ 26#define ATMCI_MR 0x0004 /* Mode */
27# define MCI_MR_CLKDIV(x) ((x) << 0) /* Clock Divider */ 27# define ATMCI_MR_CLKDIV(x) ((x) << 0) /* Clock Divider */
28# define MCI_MR_PWSDIV(x) ((x) << 8) /* Power Saving Divider */ 28# define ATMCI_MR_PWSDIV(x) ((x) << 8) /* Power Saving Divider */
29# define MCI_MR_RDPROOF ( 1 << 11) /* Read Proof */ 29# define ATMCI_MR_RDPROOF ( 1 << 11) /* Read Proof */
30# define MCI_MR_WRPROOF ( 1 << 12) /* Write Proof */ 30# define ATMCI_MR_WRPROOF ( 1 << 12) /* Write Proof */
31# define MCI_MR_PDCFBYTE ( 1 << 13) /* Force Byte Transfer */ 31# define ATMCI_MR_PDCFBYTE ( 1 << 13) /* Force Byte Transfer */
32# define MCI_MR_PDCPADV ( 1 << 14) /* Padding Value */ 32# define ATMCI_MR_PDCPADV ( 1 << 14) /* Padding Value */
33# define MCI_MR_PDCMODE ( 1 << 15) /* PDC-oriented Mode */ 33# define ATMCI_MR_PDCMODE ( 1 << 15) /* PDC-oriented Mode */
34#define MCI_DTOR 0x0008 /* Data Timeout */ 34#define ATMCI_DTOR 0x0008 /* Data Timeout */
35# define MCI_DTOCYC(x) ((x) << 0) /* Data Timeout Cycles */ 35# define ATMCI_DTOCYC(x) ((x) << 0) /* Data Timeout Cycles */
36# define MCI_DTOMUL(x) ((x) << 4) /* Data Timeout Multiplier */ 36# define ATMCI_DTOMUL(x) ((x) << 4) /* Data Timeout Multiplier */
37#define MCI_SDCR 0x000c /* SD Card / SDIO */ 37#define ATMCI_SDCR 0x000c /* SD Card / SDIO */
38# define MCI_SDCSEL_SLOT_A ( 0 << 0) /* Select SD slot A */ 38# define ATMCI_SDCSEL_SLOT_A ( 0 << 0) /* Select SD slot A */
39# define MCI_SDCSEL_SLOT_B ( 1 << 0) /* Select SD slot A */ 39# define ATMCI_SDCSEL_SLOT_B ( 1 << 0) /* Select SD slot A */
40# define MCI_SDCSEL_MASK ( 3 << 0) 40# define ATMCI_SDCSEL_MASK ( 3 << 0)
41# define MCI_SDCBUS_1BIT ( 0 << 6) /* 1-bit data bus */ 41# define ATMCI_SDCBUS_1BIT ( 0 << 6) /* 1-bit data bus */
42# define MCI_SDCBUS_4BIT ( 2 << 6) /* 4-bit data bus */ 42# define ATMCI_SDCBUS_4BIT ( 2 << 6) /* 4-bit data bus */
43# define MCI_SDCBUS_8BIT ( 3 << 6) /* 8-bit data bus[2] */ 43# define ATMCI_SDCBUS_8BIT ( 3 << 6) /* 8-bit data bus[2] */
44# define MCI_SDCBUS_MASK ( 3 << 6) 44# define ATMCI_SDCBUS_MASK ( 3 << 6)
45#define MCI_ARGR 0x0010 /* Command Argument */ 45#define ATMCI_ARGR 0x0010 /* Command Argument */
46#define MCI_CMDR 0x0014 /* Command */ 46#define ATMCI_CMDR 0x0014 /* Command */
47# define MCI_CMDR_CMDNB(x) ((x) << 0) /* Command Opcode */ 47# define ATMCI_CMDR_CMDNB(x) ((x) << 0) /* Command Opcode */
48# define MCI_CMDR_RSPTYP_NONE ( 0 << 6) /* No response */ 48# define ATMCI_CMDR_RSPTYP_NONE ( 0 << 6) /* No response */
49# define MCI_CMDR_RSPTYP_48BIT ( 1 << 6) /* 48-bit response */ 49# define ATMCI_CMDR_RSPTYP_48BIT ( 1 << 6) /* 48-bit response */
50# define MCI_CMDR_RSPTYP_136BIT ( 2 << 6) /* 136-bit response */ 50# define ATMCI_CMDR_RSPTYP_136BIT ( 2 << 6) /* 136-bit response */
51# define MCI_CMDR_SPCMD_INIT ( 1 << 8) /* Initialization command */ 51# define ATMCI_CMDR_SPCMD_INIT ( 1 << 8) /* Initialization command */
52# define MCI_CMDR_SPCMD_SYNC ( 2 << 8) /* Synchronized command */ 52# define ATMCI_CMDR_SPCMD_SYNC ( 2 << 8) /* Synchronized command */
53# define MCI_CMDR_SPCMD_INT ( 4 << 8) /* Interrupt command */ 53# define ATMCI_CMDR_SPCMD_INT ( 4 << 8) /* Interrupt command */
54# define MCI_CMDR_SPCMD_INTRESP ( 5 << 8) /* Interrupt response */ 54# define ATMCI_CMDR_SPCMD_INTRESP ( 5 << 8) /* Interrupt response */
55# define MCI_CMDR_OPDCMD ( 1 << 11) /* Open Drain */ 55# define ATMCI_CMDR_OPDCMD ( 1 << 11) /* Open Drain */
56# define MCI_CMDR_MAXLAT_5CYC ( 0 << 12) /* Max latency 5 cycles */ 56# define ATMCI_CMDR_MAXLAT_5CYC ( 0 << 12) /* Max latency 5 cycles */
57# define MCI_CMDR_MAXLAT_64CYC ( 1 << 12) /* Max latency 64 cycles */ 57# define ATMCI_CMDR_MAXLAT_64CYC ( 1 << 12) /* Max latency 64 cycles */
58# define MCI_CMDR_START_XFER ( 1 << 16) /* Start data transfer */ 58# define ATMCI_CMDR_START_XFER ( 1 << 16) /* Start data transfer */
59# define MCI_CMDR_STOP_XFER ( 2 << 16) /* Stop data transfer */ 59# define ATMCI_CMDR_STOP_XFER ( 2 << 16) /* Stop data transfer */
60# define MCI_CMDR_TRDIR_WRITE ( 0 << 18) /* Write data */ 60# define ATMCI_CMDR_TRDIR_WRITE ( 0 << 18) /* Write data */
61# define MCI_CMDR_TRDIR_READ ( 1 << 18) /* Read data */ 61# define ATMCI_CMDR_TRDIR_READ ( 1 << 18) /* Read data */
62# define MCI_CMDR_BLOCK ( 0 << 19) /* Single-block transfer */ 62# define ATMCI_CMDR_BLOCK ( 0 << 19) /* Single-block transfer */
63# define MCI_CMDR_MULTI_BLOCK ( 1 << 19) /* Multi-block transfer */ 63# define ATMCI_CMDR_MULTI_BLOCK ( 1 << 19) /* Multi-block transfer */
64# define MCI_CMDR_STREAM ( 2 << 19) /* MMC Stream transfer */ 64# define ATMCI_CMDR_STREAM ( 2 << 19) /* MMC Stream transfer */
65# define MCI_CMDR_SDIO_BYTE ( 4 << 19) /* SDIO Byte transfer */ 65# define ATMCI_CMDR_SDIO_BYTE ( 4 << 19) /* SDIO Byte transfer */
66# define MCI_CMDR_SDIO_BLOCK ( 5 << 19) /* SDIO Block transfer */ 66# define ATMCI_CMDR_SDIO_BLOCK ( 5 << 19) /* SDIO Block transfer */
67# define MCI_CMDR_SDIO_SUSPEND ( 1 << 24) /* SDIO Suspend Command */ 67# define ATMCI_CMDR_SDIO_SUSPEND ( 1 << 24) /* SDIO Suspend Command */
68# define MCI_CMDR_SDIO_RESUME ( 2 << 24) /* SDIO Resume Command */ 68# define ATMCI_CMDR_SDIO_RESUME ( 2 << 24) /* SDIO Resume Command */
69#define MCI_BLKR 0x0018 /* Block */ 69#define ATMCI_BLKR 0x0018 /* Block */
70# define MCI_BCNT(x) ((x) << 0) /* Data Block Count */ 70# define ATMCI_BCNT(x) ((x) << 0) /* Data Block Count */
71# define MCI_BLKLEN(x) ((x) << 16) /* Data Block Length */ 71# define ATMCI_BLKLEN(x) ((x) << 16) /* Data Block Length */
72#define MCI_CSTOR 0x001c /* Completion Signal Timeout[2] */ 72#define ATMCI_CSTOR 0x001c /* Completion Signal Timeout[2] */
73# define MCI_CSTOCYC(x) ((x) << 0) /* CST cycles */ 73# define ATMCI_CSTOCYC(x) ((x) << 0) /* CST cycles */
74# define MCI_CSTOMUL(x) ((x) << 4) /* CST multiplier */ 74# define ATMCI_CSTOMUL(x) ((x) << 4) /* CST multiplier */
75#define MCI_RSPR 0x0020 /* Response 0 */ 75#define ATMCI_RSPR 0x0020 /* Response 0 */
76#define MCI_RSPR1 0x0024 /* Response 1 */ 76#define ATMCI_RSPR1 0x0024 /* Response 1 */
77#define MCI_RSPR2 0x0028 /* Response 2 */ 77#define ATMCI_RSPR2 0x0028 /* Response 2 */
78#define MCI_RSPR3 0x002c /* Response 3 */ 78#define ATMCI_RSPR3 0x002c /* Response 3 */
79#define MCI_RDR 0x0030 /* Receive Data */ 79#define ATMCI_RDR 0x0030 /* Receive Data */
80#define MCI_TDR 0x0034 /* Transmit Data */ 80#define ATMCI_TDR 0x0034 /* Transmit Data */
81#define MCI_SR 0x0040 /* Status */ 81#define ATMCI_SR 0x0040 /* Status */
82#define MCI_IER 0x0044 /* Interrupt Enable */ 82#define ATMCI_IER 0x0044 /* Interrupt Enable */
83#define MCI_IDR 0x0048 /* Interrupt Disable */ 83#define ATMCI_IDR 0x0048 /* Interrupt Disable */
84#define MCI_IMR 0x004c /* Interrupt Mask */ 84#define ATMCI_IMR 0x004c /* Interrupt Mask */
85# define MCI_CMDRDY ( 1 << 0) /* Command Ready */ 85# define ATMCI_CMDRDY ( 1 << 0) /* Command Ready */
86# define MCI_RXRDY ( 1 << 1) /* Receiver Ready */ 86# define ATMCI_RXRDY ( 1 << 1) /* Receiver Ready */
87# define MCI_TXRDY ( 1 << 2) /* Transmitter Ready */ 87# define ATMCI_TXRDY ( 1 << 2) /* Transmitter Ready */
88# define MCI_BLKE ( 1 << 3) /* Data Block Ended */ 88# define ATMCI_BLKE ( 1 << 3) /* Data Block Ended */
89# define MCI_DTIP ( 1 << 4) /* Data Transfer In Progress */ 89# define ATMCI_DTIP ( 1 << 4) /* Data Transfer In Progress */
90# define MCI_NOTBUSY ( 1 << 5) /* Data Not Busy */ 90# define ATMCI_NOTBUSY ( 1 << 5) /* Data Not Busy */
91# define MCI_SDIOIRQA ( 1 << 8) /* SDIO IRQ in slot A */ 91# define ATMCI_ENDRX ( 1 << 6) /* End of RX Buffer */
92# define MCI_SDIOIRQB ( 1 << 9) /* SDIO IRQ in slot B */ 92# define ATMCI_ENDTX ( 1 << 7) /* End of TX Buffer */
93# define MCI_RINDE ( 1 << 16) /* Response Index Error */ 93# define ATMCI_SDIOIRQA ( 1 << 8) /* SDIO IRQ in slot A */
94# define MCI_RDIRE ( 1 << 17) /* Response Direction Error */ 94# define ATMCI_SDIOIRQB ( 1 << 9) /* SDIO IRQ in slot B */
95# define MCI_RCRCE ( 1 << 18) /* Response CRC Error */ 95# define ATMCI_SDIOWAIT ( 1 << 12) /* SDIO Read Wait Operation Status */
96# define MCI_RENDE ( 1 << 19) /* Response End Bit Error */ 96# define ATMCI_CSRCV ( 1 << 13) /* CE-ATA Completion Signal Received */
97# define MCI_RTOE ( 1 << 20) /* Response Time-Out Error */ 97# define ATMCI_RXBUFF ( 1 << 14) /* RX Buffer Full */
98# define MCI_DCRCE ( 1 << 21) /* Data CRC Error */ 98# define ATMCI_TXBUFE ( 1 << 15) /* TX Buffer Empty */
99# define MCI_DTOE ( 1 << 22) /* Data Time-Out Error */ 99# define ATMCI_RINDE ( 1 << 16) /* Response Index Error */
100# define MCI_OVRE ( 1 << 30) /* RX Overrun Error */ 100# define ATMCI_RDIRE ( 1 << 17) /* Response Direction Error */
101# define MCI_UNRE ( 1 << 31) /* TX Underrun Error */ 101# define ATMCI_RCRCE ( 1 << 18) /* Response CRC Error */
102#define MCI_DMA 0x0050 /* DMA Configuration[2] */ 102# define ATMCI_RENDE ( 1 << 19) /* Response End Bit Error */
103# define MCI_DMA_OFFSET(x) ((x) << 0) /* DMA Write Buffer Offset */ 103# define ATMCI_RTOE ( 1 << 20) /* Response Time-Out Error */
104# define MCI_DMA_CHKSIZE(x) ((x) << 4) /* DMA Channel Read and Write Chunk Size */ 104# define ATMCI_DCRCE ( 1 << 21) /* Data CRC Error */
105# define MCI_DMAEN ( 1 << 8) /* DMA Hardware Handshaking Enable */ 105# define ATMCI_DTOE ( 1 << 22) /* Data Time-Out Error */
106#define MCI_CFG 0x0054 /* Configuration[2] */ 106# define ATMCI_CSTOE ( 1 << 23) /* Completion Signal Time-out Error */
107# define MCI_CFG_FIFOMODE_1DATA ( 1 << 0) /* MCI Internal FIFO control mode */ 107# define ATMCI_BLKOVRE ( 1 << 24) /* DMA Block Overrun Error */
108# define MCI_CFG_FERRCTRL_COR ( 1 << 4) /* Flow Error flag reset control mode */ 108# define ATMCI_DMADONE ( 1 << 25) /* DMA Transfer Done */
109# define MCI_CFG_HSMODE ( 1 << 8) /* High Speed Mode */ 109# define ATMCI_FIFOEMPTY ( 1 << 26) /* FIFO Empty Flag */
110# define MCI_CFG_LSYNC ( 1 << 12) /* Synchronize on the last block */ 110# define ATMCI_XFRDONE ( 1 << 27) /* Transfer Done Flag */
111#define MCI_WPMR 0x00e4 /* Write Protection Mode[2] */ 111# define ATMCI_ACKRCV ( 1 << 28) /* Boot Operation Acknowledge Received */
112# define MCI_WP_EN ( 1 << 0) /* WP Enable */ 112# define ATMCI_ACKRCVE ( 1 << 29) /* Boot Operation Acknowledge Error */
113# define MCI_WP_KEY (0x4d4349 << 8) /* WP Key */ 113# define ATMCI_OVRE ( 1 << 30) /* RX Overrun Error */
114#define MCI_WPSR 0x00e8 /* Write Protection Status[2] */ 114# define ATMCI_UNRE ( 1 << 31) /* TX Underrun Error */
115# define MCI_GET_WP_VS(x) ((x) & 0x0f) 115#define ATMCI_DMA 0x0050 /* DMA Configuration[2] */
116# define MCI_GET_WP_VSRC(x) (((x) >> 8) & 0xffff) 116# define ATMCI_DMA_OFFSET(x) ((x) << 0) /* DMA Write Buffer Offset */
117#define MCI_FIFO_APERTURE 0x0200 /* FIFO Aperture[2] */ 117# define ATMCI_DMA_CHKSIZE(x) ((x) << 4) /* DMA Channel Read and Write Chunk Size */
118# define ATMCI_DMAEN ( 1 << 8) /* DMA Hardware Handshaking Enable */
119#define ATMCI_CFG 0x0054 /* Configuration[2] */
120# define ATMCI_CFG_FIFOMODE_1DATA ( 1 << 0) /* MCI Internal FIFO control mode */
121# define ATMCI_CFG_FERRCTRL_COR ( 1 << 4) /* Flow Error flag reset control mode */
122# define ATMCI_CFG_HSMODE ( 1 << 8) /* High Speed Mode */
123# define ATMCI_CFG_LSYNC ( 1 << 12) /* Synchronize on the last block */
124#define ATMCI_WPMR 0x00e4 /* Write Protection Mode[2] */
125# define ATMCI_WP_EN ( 1 << 0) /* WP Enable */
126# define ATMCI_WP_KEY (0x4d4349 << 8) /* WP Key */
127#define ATMCI_WPSR 0x00e8 /* Write Protection Status[2] */
128# define ATMCI_GET_WP_VS(x) ((x) & 0x0f)
129# define ATMCI_GET_WP_VSRC(x) (((x) >> 8) & 0xffff)
130#define ATMCI_VERSION 0x00FC /* Version */
131#define ATMCI_FIFO_APERTURE 0x0200 /* FIFO Aperture[2] */
118 132
119/* This is not including the FIFO Aperture on MCI2 */ 133/* This is not including the FIFO Aperture on MCI2 */
120#define MCI_REGS_SIZE 0x100 134#define ATMCI_REGS_SIZE 0x100
121 135
122/* Register access macros */ 136/* Register access macros */
123#define mci_readl(port,reg) \ 137#define atmci_readl(port,reg) \
124 __raw_readl((port)->regs + MCI_##reg) 138 __raw_readl((port)->regs + reg)
125#define mci_writel(port,reg,value) \ 139#define atmci_writel(port,reg,value) \
126 __raw_writel((value), (port)->regs + MCI_##reg) 140 __raw_writel((value), (port)->regs + reg)
127 141
128#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */ 142#endif /* __DRIVERS_MMC_ATMEL_MCI_H__ */
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index fa8cae1d7005..a7ee50271465 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -30,6 +30,7 @@
30 30
31#include <mach/atmel-mci.h> 31#include <mach/atmel-mci.h>
32#include <linux/atmel-mci.h> 32#include <linux/atmel-mci.h>
33#include <linux/atmel_pdc.h>
33 34
34#include <asm/io.h> 35#include <asm/io.h>
35#include <asm/unaligned.h> 36#include <asm/unaligned.h>
@@ -39,7 +40,7 @@
39 40
40#include "atmel-mci-regs.h" 41#include "atmel-mci-regs.h"
41 42
42#define ATMCI_DATA_ERROR_FLAGS (MCI_DCRCE | MCI_DTOE | MCI_OVRE | MCI_UNRE) 43#define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE)
43#define ATMCI_DMA_THRESHOLD 16 44#define ATMCI_DMA_THRESHOLD 16
44 45
45enum { 46enum {
@@ -58,18 +59,35 @@ enum atmel_mci_state {
58 STATE_DATA_ERROR, 59 STATE_DATA_ERROR,
59}; 60};
60 61
62enum atmci_xfer_dir {
63 XFER_RECEIVE = 0,
64 XFER_TRANSMIT,
65};
66
67enum atmci_pdc_buf {
68 PDC_FIRST_BUF = 0,
69 PDC_SECOND_BUF,
70};
71
72struct atmel_mci_caps {
73 bool has_dma;
74 bool has_pdc;
75 bool has_cfg_reg;
76 bool has_cstor_reg;
77 bool has_highspeed;
78 bool has_rwproof;
79};
80
61struct atmel_mci_dma { 81struct atmel_mci_dma {
62#ifdef CONFIG_MMC_ATMELMCI_DMA
63 struct dma_chan *chan; 82 struct dma_chan *chan;
64 struct dma_async_tx_descriptor *data_desc; 83 struct dma_async_tx_descriptor *data_desc;
65#endif
66}; 84};
67 85
68/** 86/**
69 * struct atmel_mci - MMC controller state shared between all slots 87 * struct atmel_mci - MMC controller state shared between all slots
70 * @lock: Spinlock protecting the queue and associated data. 88 * @lock: Spinlock protecting the queue and associated data.
71 * @regs: Pointer to MMIO registers. 89 * @regs: Pointer to MMIO registers.
72 * @sg: Scatterlist entry currently being processed by PIO code, if any. 90 * @sg: Scatterlist entry currently being processed by PIO or PDC code.
73 * @pio_offset: Offset into the current scatterlist entry. 91 * @pio_offset: Offset into the current scatterlist entry.
74 * @cur_slot: The slot which is currently using the controller. 92 * @cur_slot: The slot which is currently using the controller.
75 * @mrq: The request currently being processed on @cur_slot, 93 * @mrq: The request currently being processed on @cur_slot,
@@ -77,6 +95,7 @@ struct atmel_mci_dma {
77 * @cmd: The command currently being sent to the card, or NULL. 95 * @cmd: The command currently being sent to the card, or NULL.
78 * @data: The data currently being transferred, or NULL if no data 96 * @data: The data currently being transferred, or NULL if no data
79 * transfer is in progress. 97 * transfer is in progress.
98 * @data_size: just data->blocks * data->blksz.
80 * @dma: DMA client state. 99 * @dma: DMA client state.
81 * @data_chan: DMA channel being used for the current data transfer. 100 * @data_chan: DMA channel being used for the current data transfer.
82 * @cmd_status: Snapshot of SR taken upon completion of the current 101 * @cmd_status: Snapshot of SR taken upon completion of the current
@@ -103,6 +122,13 @@ struct atmel_mci_dma {
103 * @mck: The peripheral bus clock hooked up to the MMC controller. 122 * @mck: The peripheral bus clock hooked up to the MMC controller.
104 * @pdev: Platform device associated with the MMC controller. 123 * @pdev: Platform device associated with the MMC controller.
105 * @slot: Slots sharing this MMC controller. 124 * @slot: Slots sharing this MMC controller.
125 * @caps: MCI capabilities depending on MCI version.
126 * @prepare_data: function to setup MCI before data transfer which
127 * depends on MCI capabilities.
128 * @submit_data: function to start data transfer which depends on MCI
129 * capabilities.
130 * @stop_transfer: function to stop data transfer which depends on MCI
131 * capabilities.
106 * 132 *
107 * Locking 133 * Locking
108 * ======= 134 * =======
@@ -143,6 +169,7 @@ struct atmel_mci {
143 struct mmc_request *mrq; 169 struct mmc_request *mrq;
144 struct mmc_command *cmd; 170 struct mmc_command *cmd;
145 struct mmc_data *data; 171 struct mmc_data *data;
172 unsigned int data_size;
146 173
147 struct atmel_mci_dma dma; 174 struct atmel_mci_dma dma;
148 struct dma_chan *data_chan; 175 struct dma_chan *data_chan;
@@ -166,7 +193,13 @@ struct atmel_mci {
166 struct clk *mck; 193 struct clk *mck;
167 struct platform_device *pdev; 194 struct platform_device *pdev;
168 195
169 struct atmel_mci_slot *slot[ATMEL_MCI_MAX_NR_SLOTS]; 196 struct atmel_mci_slot *slot[ATMCI_MAX_NR_SLOTS];
197
198 struct atmel_mci_caps caps;
199
200 u32 (*prepare_data)(struct atmel_mci *host, struct mmc_data *data);
201 void (*submit_data)(struct atmel_mci *host, struct mmc_data *data);
202 void (*stop_transfer)(struct atmel_mci *host);
170}; 203};
171 204
172/** 205/**
@@ -220,31 +253,6 @@ struct atmel_mci_slot {
220 set_bit(event, &host->pending_events) 253 set_bit(event, &host->pending_events)
221 254
222/* 255/*
223 * Enable or disable features/registers based on
224 * whether the processor supports them
225 */
226static bool mci_has_rwproof(void)
227{
228 if (cpu_is_at91sam9261() || cpu_is_at91rm9200())
229 return false;
230 else
231 return true;
232}
233
234/*
235 * The new MCI2 module isn't 100% compatible with the old MCI module,
236 * and it has a few nice features which we want to use...
237 */
238static inline bool atmci_is_mci2(void)
239{
240 if (cpu_is_at91sam9g45())
241 return true;
242
243 return false;
244}
245
246
247/*
248 * The debugfs stuff below is mostly optimized away when 256 * The debugfs stuff below is mostly optimized away when
249 * CONFIG_DEBUG_FS is not set. 257 * CONFIG_DEBUG_FS is not set.
250 */ 258 */
@@ -352,7 +360,7 @@ static int atmci_regs_show(struct seq_file *s, void *v)
352 struct atmel_mci *host = s->private; 360 struct atmel_mci *host = s->private;
353 u32 *buf; 361 u32 *buf;
354 362
355 buf = kmalloc(MCI_REGS_SIZE, GFP_KERNEL); 363 buf = kmalloc(ATMCI_REGS_SIZE, GFP_KERNEL);
356 if (!buf) 364 if (!buf)
357 return -ENOMEM; 365 return -ENOMEM;
358 366
@@ -363,47 +371,50 @@ static int atmci_regs_show(struct seq_file *s, void *v)
363 */ 371 */
364 spin_lock_bh(&host->lock); 372 spin_lock_bh(&host->lock);
365 clk_enable(host->mck); 373 clk_enable(host->mck);
366 memcpy_fromio(buf, host->regs, MCI_REGS_SIZE); 374 memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
367 clk_disable(host->mck); 375 clk_disable(host->mck);
368 spin_unlock_bh(&host->lock); 376 spin_unlock_bh(&host->lock);
369 377
370 seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u\n", 378 seq_printf(s, "MR:\t0x%08x%s%s CLKDIV=%u\n",
371 buf[MCI_MR / 4], 379 buf[ATMCI_MR / 4],
372 buf[MCI_MR / 4] & MCI_MR_RDPROOF ? " RDPROOF" : "", 380 buf[ATMCI_MR / 4] & ATMCI_MR_RDPROOF ? " RDPROOF" : "",
373 buf[MCI_MR / 4] & MCI_MR_WRPROOF ? " WRPROOF" : "", 381 buf[ATMCI_MR / 4] & ATMCI_MR_WRPROOF ? " WRPROOF" : "",
374 buf[MCI_MR / 4] & 0xff); 382 buf[ATMCI_MR / 4] & 0xff);
375 seq_printf(s, "DTOR:\t0x%08x\n", buf[MCI_DTOR / 4]); 383 seq_printf(s, "DTOR:\t0x%08x\n", buf[ATMCI_DTOR / 4]);
376 seq_printf(s, "SDCR:\t0x%08x\n", buf[MCI_SDCR / 4]); 384 seq_printf(s, "SDCR:\t0x%08x\n", buf[ATMCI_SDCR / 4]);
377 seq_printf(s, "ARGR:\t0x%08x\n", buf[MCI_ARGR / 4]); 385 seq_printf(s, "ARGR:\t0x%08x\n", buf[ATMCI_ARGR / 4]);
378 seq_printf(s, "BLKR:\t0x%08x BCNT=%u BLKLEN=%u\n", 386 seq_printf(s, "BLKR:\t0x%08x BCNT=%u BLKLEN=%u\n",
379 buf[MCI_BLKR / 4], 387 buf[ATMCI_BLKR / 4],
380 buf[MCI_BLKR / 4] & 0xffff, 388 buf[ATMCI_BLKR / 4] & 0xffff,
381 (buf[MCI_BLKR / 4] >> 16) & 0xffff); 389 (buf[ATMCI_BLKR / 4] >> 16) & 0xffff);
382 if (atmci_is_mci2()) 390 if (host->caps.has_cstor_reg)
383 seq_printf(s, "CSTOR:\t0x%08x\n", buf[MCI_CSTOR / 4]); 391 seq_printf(s, "CSTOR:\t0x%08x\n", buf[ATMCI_CSTOR / 4]);
384 392
385 /* Don't read RSPR and RDR; it will consume the data there */ 393 /* Don't read RSPR and RDR; it will consume the data there */
386 394
387 atmci_show_status_reg(s, "SR", buf[MCI_SR / 4]); 395 atmci_show_status_reg(s, "SR", buf[ATMCI_SR / 4]);
388 atmci_show_status_reg(s, "IMR", buf[MCI_IMR / 4]); 396 atmci_show_status_reg(s, "IMR", buf[ATMCI_IMR / 4]);
389 397
390 if (atmci_is_mci2()) { 398 if (host->caps.has_dma) {
391 u32 val; 399 u32 val;
392 400
393 val = buf[MCI_DMA / 4]; 401 val = buf[ATMCI_DMA / 4];
394 seq_printf(s, "DMA:\t0x%08x OFFSET=%u CHKSIZE=%u%s\n", 402 seq_printf(s, "DMA:\t0x%08x OFFSET=%u CHKSIZE=%u%s\n",
395 val, val & 3, 403 val, val & 3,
396 ((val >> 4) & 3) ? 404 ((val >> 4) & 3) ?
397 1 << (((val >> 4) & 3) + 1) : 1, 405 1 << (((val >> 4) & 3) + 1) : 1,
398 val & MCI_DMAEN ? " DMAEN" : ""); 406 val & ATMCI_DMAEN ? " DMAEN" : "");
407 }
408 if (host->caps.has_cfg_reg) {
409 u32 val;
399 410
400 val = buf[MCI_CFG / 4]; 411 val = buf[ATMCI_CFG / 4];
401 seq_printf(s, "CFG:\t0x%08x%s%s%s%s\n", 412 seq_printf(s, "CFG:\t0x%08x%s%s%s%s\n",
402 val, 413 val,
403 val & MCI_CFG_FIFOMODE_1DATA ? " FIFOMODE_ONE_DATA" : "", 414 val & ATMCI_CFG_FIFOMODE_1DATA ? " FIFOMODE_ONE_DATA" : "",
404 val & MCI_CFG_FERRCTRL_COR ? " FERRCTRL_CLEAR_ON_READ" : "", 415 val & ATMCI_CFG_FERRCTRL_COR ? " FERRCTRL_CLEAR_ON_READ" : "",
405 val & MCI_CFG_HSMODE ? " HSMODE" : "", 416 val & ATMCI_CFG_HSMODE ? " HSMODE" : "",
406 val & MCI_CFG_LSYNC ? " LSYNC" : ""); 417 val & ATMCI_CFG_LSYNC ? " LSYNC" : "");
407 } 418 }
408 419
409 kfree(buf); 420 kfree(buf);
@@ -466,7 +477,7 @@ err:
466 dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n"); 477 dev_err(&mmc->class_dev, "failed to initialize debugfs for slot\n");
467} 478}
468 479
469static inline unsigned int ns_to_clocks(struct atmel_mci *host, 480static inline unsigned int atmci_ns_to_clocks(struct atmel_mci *host,
470 unsigned int ns) 481 unsigned int ns)
471{ 482{
472 return (ns * (host->bus_hz / 1000000) + 999) / 1000; 483 return (ns * (host->bus_hz / 1000000) + 999) / 1000;
@@ -482,7 +493,8 @@ static void atmci_set_timeout(struct atmel_mci *host,
482 unsigned dtocyc; 493 unsigned dtocyc;
483 unsigned dtomul; 494 unsigned dtomul;
484 495
485 timeout = ns_to_clocks(host, data->timeout_ns) + data->timeout_clks; 496 timeout = atmci_ns_to_clocks(host, data->timeout_ns)
497 + data->timeout_clks;
486 498
487 for (dtomul = 0; dtomul < 8; dtomul++) { 499 for (dtomul = 0; dtomul < 8; dtomul++) {
488 unsigned shift = dtomul_to_shift[dtomul]; 500 unsigned shift = dtomul_to_shift[dtomul];
@@ -498,7 +510,7 @@ static void atmci_set_timeout(struct atmel_mci *host,
498 510
499 dev_vdbg(&slot->mmc->class_dev, "setting timeout to %u cycles\n", 511 dev_vdbg(&slot->mmc->class_dev, "setting timeout to %u cycles\n",
500 dtocyc << dtomul_to_shift[dtomul]); 512 dtocyc << dtomul_to_shift[dtomul]);
501 mci_writel(host, DTOR, (MCI_DTOMUL(dtomul) | MCI_DTOCYC(dtocyc))); 513 atmci_writel(host, ATMCI_DTOR, (ATMCI_DTOMUL(dtomul) | ATMCI_DTOCYC(dtocyc)));
502} 514}
503 515
504/* 516/*
@@ -512,13 +524,13 @@ static u32 atmci_prepare_command(struct mmc_host *mmc,
512 524
513 cmd->error = -EINPROGRESS; 525 cmd->error = -EINPROGRESS;
514 526
515 cmdr = MCI_CMDR_CMDNB(cmd->opcode); 527 cmdr = ATMCI_CMDR_CMDNB(cmd->opcode);
516 528
517 if (cmd->flags & MMC_RSP_PRESENT) { 529 if (cmd->flags & MMC_RSP_PRESENT) {
518 if (cmd->flags & MMC_RSP_136) 530 if (cmd->flags & MMC_RSP_136)
519 cmdr |= MCI_CMDR_RSPTYP_136BIT; 531 cmdr |= ATMCI_CMDR_RSPTYP_136BIT;
520 else 532 else
521 cmdr |= MCI_CMDR_RSPTYP_48BIT; 533 cmdr |= ATMCI_CMDR_RSPTYP_48BIT;
522 } 534 }
523 535
524 /* 536 /*
@@ -526,34 +538,34 @@ static u32 atmci_prepare_command(struct mmc_host *mmc,
526 * it's too difficult to determine whether this is an ACMD or 538 * it's too difficult to determine whether this is an ACMD or
527 * not. Better make it 64. 539 * not. Better make it 64.
528 */ 540 */
529 cmdr |= MCI_CMDR_MAXLAT_64CYC; 541 cmdr |= ATMCI_CMDR_MAXLAT_64CYC;
530 542
531 if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN) 543 if (mmc->ios.bus_mode == MMC_BUSMODE_OPENDRAIN)
532 cmdr |= MCI_CMDR_OPDCMD; 544 cmdr |= ATMCI_CMDR_OPDCMD;
533 545
534 data = cmd->data; 546 data = cmd->data;
535 if (data) { 547 if (data) {
536 cmdr |= MCI_CMDR_START_XFER; 548 cmdr |= ATMCI_CMDR_START_XFER;
537 549
538 if (cmd->opcode == SD_IO_RW_EXTENDED) { 550 if (cmd->opcode == SD_IO_RW_EXTENDED) {
539 cmdr |= MCI_CMDR_SDIO_BLOCK; 551 cmdr |= ATMCI_CMDR_SDIO_BLOCK;
540 } else { 552 } else {
541 if (data->flags & MMC_DATA_STREAM) 553 if (data->flags & MMC_DATA_STREAM)
542 cmdr |= MCI_CMDR_STREAM; 554 cmdr |= ATMCI_CMDR_STREAM;
543 else if (data->blocks > 1) 555 else if (data->blocks > 1)
544 cmdr |= MCI_CMDR_MULTI_BLOCK; 556 cmdr |= ATMCI_CMDR_MULTI_BLOCK;
545 else 557 else
546 cmdr |= MCI_CMDR_BLOCK; 558 cmdr |= ATMCI_CMDR_BLOCK;
547 } 559 }
548 560
549 if (data->flags & MMC_DATA_READ) 561 if (data->flags & MMC_DATA_READ)
550 cmdr |= MCI_CMDR_TRDIR_READ; 562 cmdr |= ATMCI_CMDR_TRDIR_READ;
551 } 563 }
552 564
553 return cmdr; 565 return cmdr;
554} 566}
555 567
556static void atmci_start_command(struct atmel_mci *host, 568static void atmci_send_command(struct atmel_mci *host,
557 struct mmc_command *cmd, u32 cmd_flags) 569 struct mmc_command *cmd, u32 cmd_flags)
558{ 570{
559 WARN_ON(host->cmd); 571 WARN_ON(host->cmd);
@@ -563,43 +575,119 @@ static void atmci_start_command(struct atmel_mci *host,
563 "start command: ARGR=0x%08x CMDR=0x%08x\n", 575 "start command: ARGR=0x%08x CMDR=0x%08x\n",
564 cmd->arg, cmd_flags); 576 cmd->arg, cmd_flags);
565 577
566 mci_writel(host, ARGR, cmd->arg); 578 atmci_writel(host, ATMCI_ARGR, cmd->arg);
567 mci_writel(host, CMDR, cmd_flags); 579 atmci_writel(host, ATMCI_CMDR, cmd_flags);
568} 580}
569 581
570static void send_stop_cmd(struct atmel_mci *host, struct mmc_data *data) 582static void atmci_send_stop_cmd(struct atmel_mci *host, struct mmc_data *data)
571{ 583{
572 atmci_start_command(host, data->stop, host->stop_cmdr); 584 atmci_send_command(host, data->stop, host->stop_cmdr);
573 mci_writel(host, IER, MCI_CMDRDY); 585 atmci_writel(host, ATMCI_IER, ATMCI_CMDRDY);
574} 586}
575 587
576#ifdef CONFIG_MMC_ATMELMCI_DMA 588/*
577static void atmci_dma_cleanup(struct atmel_mci *host) 589 * Configure given PDC buffer taking care of alignement issues.
590 * Update host->data_size and host->sg.
591 */
592static void atmci_pdc_set_single_buf(struct atmel_mci *host,
593 enum atmci_xfer_dir dir, enum atmci_pdc_buf buf_nb)
594{
595 u32 pointer_reg, counter_reg;
596
597 if (dir == XFER_RECEIVE) {
598 pointer_reg = ATMEL_PDC_RPR;
599 counter_reg = ATMEL_PDC_RCR;
600 } else {
601 pointer_reg = ATMEL_PDC_TPR;
602 counter_reg = ATMEL_PDC_TCR;
603 }
604
605 if (buf_nb == PDC_SECOND_BUF) {
606 pointer_reg += ATMEL_PDC_SCND_BUF_OFF;
607 counter_reg += ATMEL_PDC_SCND_BUF_OFF;
608 }
609
610 atmci_writel(host, pointer_reg, sg_dma_address(host->sg));
611 if (host->data_size <= sg_dma_len(host->sg)) {
612 if (host->data_size & 0x3) {
613 /* If size is different from modulo 4, transfer bytes */
614 atmci_writel(host, counter_reg, host->data_size);
615 atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCFBYTE);
616 } else {
617 /* Else transfer 32-bits words */
618 atmci_writel(host, counter_reg, host->data_size / 4);
619 }
620 host->data_size = 0;
621 } else {
622 /* We assume the size of a page is 32-bits aligned */
623 atmci_writel(host, counter_reg, sg_dma_len(host->sg) / 4);
624 host->data_size -= sg_dma_len(host->sg);
625 if (host->data_size)
626 host->sg = sg_next(host->sg);
627 }
628}
629
630/*
631 * Configure PDC buffer according to the data size ie configuring one or two
632 * buffers. Don't use this function if you want to configure only the second
633 * buffer. In this case, use atmci_pdc_set_single_buf.
634 */
635static void atmci_pdc_set_both_buf(struct atmel_mci *host, int dir)
578{ 636{
579 struct mmc_data *data = host->data; 637 atmci_pdc_set_single_buf(host, dir, PDC_FIRST_BUF);
638 if (host->data_size)
639 atmci_pdc_set_single_buf(host, dir, PDC_SECOND_BUF);
640}
641
642/*
643 * Unmap sg lists, called when transfer is finished.
644 */
645static void atmci_pdc_cleanup(struct atmel_mci *host)
646{
647 struct mmc_data *data = host->data;
580 648
581 if (data) 649 if (data)
582 dma_unmap_sg(host->dma.chan->device->dev, 650 dma_unmap_sg(&host->pdev->dev,
583 data->sg, data->sg_len, 651 data->sg, data->sg_len,
584 ((data->flags & MMC_DATA_WRITE) 652 ((data->flags & MMC_DATA_WRITE)
585 ? DMA_TO_DEVICE : DMA_FROM_DEVICE)); 653 ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
586} 654}
587 655
588static void atmci_stop_dma(struct atmel_mci *host) 656/*
657 * Disable PDC transfers. Update pending flags to EVENT_XFER_COMPLETE after
658 * having received ATMCI_TXBUFE or ATMCI_RXBUFF interrupt. Enable ATMCI_NOTBUSY
659 * interrupt needed for both transfer directions.
660 */
661static void atmci_pdc_complete(struct atmel_mci *host)
589{ 662{
590 struct dma_chan *chan = host->data_chan; 663 atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTDIS | ATMEL_PDC_TXTDIS);
664 atmci_pdc_cleanup(host);
591 665
592 if (chan) { 666 /*
593 dmaengine_terminate_all(chan); 667 * If the card was removed, data will be NULL. No point trying
594 atmci_dma_cleanup(host); 668 * to send the stop command or waiting for NBUSY in this case.
595 } else { 669 */
596 /* Data transfer was stopped by the interrupt handler */ 670 if (host->data) {
597 atmci_set_pending(host, EVENT_XFER_COMPLETE); 671 atmci_set_pending(host, EVENT_XFER_COMPLETE);
598 mci_writel(host, IER, MCI_NOTBUSY); 672 tasklet_schedule(&host->tasklet);
673 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
599 } 674 }
600} 675}
601 676
602/* This function is called by the DMA driver from tasklet context. */ 677static void atmci_dma_cleanup(struct atmel_mci *host)
678{
679 struct mmc_data *data = host->data;
680
681 if (data)
682 dma_unmap_sg(host->dma.chan->device->dev,
683 data->sg, data->sg_len,
684 ((data->flags & MMC_DATA_WRITE)
685 ? DMA_TO_DEVICE : DMA_FROM_DEVICE));
686}
687
688/*
689 * This function is called by the DMA driver from tasklet context.
690 */
603static void atmci_dma_complete(void *arg) 691static void atmci_dma_complete(void *arg)
604{ 692{
605 struct atmel_mci *host = arg; 693 struct atmel_mci *host = arg;
@@ -607,9 +695,9 @@ static void atmci_dma_complete(void *arg)
607 695
608 dev_vdbg(&host->pdev->dev, "DMA complete\n"); 696 dev_vdbg(&host->pdev->dev, "DMA complete\n");
609 697
610 if (atmci_is_mci2()) 698 if (host->caps.has_dma)
611 /* Disable DMA hardware handshaking on MCI */ 699 /* Disable DMA hardware handshaking on MCI */
612 mci_writel(host, DMA, mci_readl(host, DMA) & ~MCI_DMAEN); 700 atmci_writel(host, ATMCI_DMA, atmci_readl(host, ATMCI_DMA) & ~ATMCI_DMAEN);
613 701
614 atmci_dma_cleanup(host); 702 atmci_dma_cleanup(host);
615 703
@@ -641,11 +729,93 @@ static void atmci_dma_complete(void *arg)
641 * completion callback" rule of the dma engine 729 * completion callback" rule of the dma engine
642 * framework. 730 * framework.
643 */ 731 */
644 mci_writel(host, IER, MCI_NOTBUSY); 732 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
645 } 733 }
646} 734}
647 735
648static int 736/*
737 * Returns a mask of interrupt flags to be enabled after the whole
738 * request has been prepared.
739 */
740static u32 atmci_prepare_data(struct atmel_mci *host, struct mmc_data *data)
741{
742 u32 iflags;
743
744 data->error = -EINPROGRESS;
745
746 host->sg = data->sg;
747 host->data = data;
748 host->data_chan = NULL;
749
750 iflags = ATMCI_DATA_ERROR_FLAGS;
751
752 /*
753 * Errata: MMC data write operation with less than 12
754 * bytes is impossible.
755 *
756 * Errata: MCI Transmit Data Register (TDR) FIFO
757 * corruption when length is not multiple of 4.
758 */
759 if (data->blocks * data->blksz < 12
760 || (data->blocks * data->blksz) & 3)
761 host->need_reset = true;
762
763 host->pio_offset = 0;
764 if (data->flags & MMC_DATA_READ)
765 iflags |= ATMCI_RXRDY;
766 else
767 iflags |= ATMCI_TXRDY;
768
769 return iflags;
770}
771
772/*
773 * Set interrupt flags and set block length into the MCI mode register even
774 * if this value is also accessible in the MCI block register. It seems to be
775 * necessary before the High Speed MCI version. It also map sg and configure
776 * PDC registers.
777 */
778static u32
779atmci_prepare_data_pdc(struct atmel_mci *host, struct mmc_data *data)
780{
781 u32 iflags, tmp;
782 unsigned int sg_len;
783 enum dma_data_direction dir;
784
785 data->error = -EINPROGRESS;
786
787 host->data = data;
788 host->sg = data->sg;
789 iflags = ATMCI_DATA_ERROR_FLAGS;
790
791 /* Enable pdc mode */
792 atmci_writel(host, ATMCI_MR, host->mode_reg | ATMCI_MR_PDCMODE);
793
794 if (data->flags & MMC_DATA_READ) {
795 dir = DMA_FROM_DEVICE;
796 iflags |= ATMCI_ENDRX | ATMCI_RXBUFF;
797 } else {
798 dir = DMA_TO_DEVICE;
799 iflags |= ATMCI_ENDTX | ATMCI_TXBUFE;
800 }
801
802 /* Set BLKLEN */
803 tmp = atmci_readl(host, ATMCI_MR);
804 tmp &= 0x0000ffff;
805 tmp |= ATMCI_BLKLEN(data->blksz);
806 atmci_writel(host, ATMCI_MR, tmp);
807
808 /* Configure PDC */
809 host->data_size = data->blocks * data->blksz;
810 sg_len = dma_map_sg(&host->pdev->dev, data->sg, data->sg_len, dir);
811 if (host->data_size)
812 atmci_pdc_set_both_buf(host,
813 ((dir == DMA_FROM_DEVICE) ? XFER_RECEIVE : XFER_TRANSMIT));
814
815 return iflags;
816}
817
818static u32
649atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data) 819atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
650{ 820{
651 struct dma_chan *chan; 821 struct dma_chan *chan;
@@ -654,6 +824,15 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
654 unsigned int i; 824 unsigned int i;
655 enum dma_data_direction direction; 825 enum dma_data_direction direction;
656 unsigned int sglen; 826 unsigned int sglen;
827 u32 iflags;
828
829 data->error = -EINPROGRESS;
830
831 WARN_ON(host->data);
832 host->sg = NULL;
833 host->data = data;
834
835 iflags = ATMCI_DATA_ERROR_FLAGS;
657 836
658 /* 837 /*
659 * We don't do DMA on "complex" transfers, i.e. with 838 * We don't do DMA on "complex" transfers, i.e. with
@@ -661,13 +840,13 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
661 * with all the DMA setup overhead for short transfers. 840 * with all the DMA setup overhead for short transfers.
662 */ 841 */
663 if (data->blocks * data->blksz < ATMCI_DMA_THRESHOLD) 842 if (data->blocks * data->blksz < ATMCI_DMA_THRESHOLD)
664 return -EINVAL; 843 return atmci_prepare_data(host, data);
665 if (data->blksz & 3) 844 if (data->blksz & 3)
666 return -EINVAL; 845 return atmci_prepare_data(host, data);
667 846
668 for_each_sg(data->sg, sg, data->sg_len, i) { 847 for_each_sg(data->sg, sg, data->sg_len, i) {
669 if (sg->offset & 3 || sg->length & 3) 848 if (sg->offset & 3 || sg->length & 3)
670 return -EINVAL; 849 return atmci_prepare_data(host, data);
671 } 850 }
672 851
673 /* If we don't have a channel, we can't do DMA */ 852 /* If we don't have a channel, we can't do DMA */
@@ -678,8 +857,8 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
678 if (!chan) 857 if (!chan)
679 return -ENODEV; 858 return -ENODEV;
680 859
681 if (atmci_is_mci2()) 860 if (host->caps.has_dma)
682 mci_writel(host, DMA, MCI_DMA_CHKSIZE(3) | MCI_DMAEN); 861 atmci_writel(host, ATMCI_DMA, ATMCI_DMA_CHKSIZE(3) | ATMCI_DMAEN);
683 862
684 if (data->flags & MMC_DATA_READ) 863 if (data->flags & MMC_DATA_READ)
685 direction = DMA_FROM_DEVICE; 864 direction = DMA_FROM_DEVICE;
@@ -687,7 +866,7 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
687 direction = DMA_TO_DEVICE; 866 direction = DMA_TO_DEVICE;
688 867
689 sglen = dma_map_sg(chan->device->dev, data->sg, 868 sglen = dma_map_sg(chan->device->dev, data->sg,
690 data->sg_len, direction); 869 data->sg_len, direction);
691 870
692 desc = chan->device->device_prep_slave_sg(chan, 871 desc = chan->device->device_prep_slave_sg(chan,
693 data->sg, sglen, direction, 872 data->sg, sglen, direction,
@@ -699,13 +878,32 @@ atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
699 desc->callback = atmci_dma_complete; 878 desc->callback = atmci_dma_complete;
700 desc->callback_param = host; 879 desc->callback_param = host;
701 880
702 return 0; 881 return iflags;
703unmap_exit: 882unmap_exit:
704 dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, direction); 883 dma_unmap_sg(chan->device->dev, data->sg, data->sg_len, direction);
705 return -ENOMEM; 884 return -ENOMEM;
706} 885}
707 886
708static void atmci_submit_data(struct atmel_mci *host) 887static void
888atmci_submit_data(struct atmel_mci *host, struct mmc_data *data)
889{
890 return;
891}
892
893/*
894 * Start PDC according to transfer direction.
895 */
896static void
897atmci_submit_data_pdc(struct atmel_mci *host, struct mmc_data *data)
898{
899 if (data->flags & MMC_DATA_READ)
900 atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_RXTEN);
901 else
902 atmci_writel(host, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN);
903}
904
905static void
906atmci_submit_data_dma(struct atmel_mci *host, struct mmc_data *data)
709{ 907{
710 struct dma_chan *chan = host->data_chan; 908 struct dma_chan *chan = host->data_chan;
711 struct dma_async_tx_descriptor *desc = host->dma.data_desc; 909 struct dma_async_tx_descriptor *desc = host->dma.data_desc;
@@ -716,64 +914,39 @@ static void atmci_submit_data(struct atmel_mci *host)
716 } 914 }
717} 915}
718 916
719#else /* CONFIG_MMC_ATMELMCI_DMA */ 917static void atmci_stop_transfer(struct atmel_mci *host)
720
721static int atmci_prepare_data_dma(struct atmel_mci *host, struct mmc_data *data)
722{
723 return -ENOSYS;
724}
725
726static void atmci_submit_data(struct atmel_mci *host) {}
727
728static void atmci_stop_dma(struct atmel_mci *host)
729{ 918{
730 /* Data transfer was stopped by the interrupt handler */
731 atmci_set_pending(host, EVENT_XFER_COMPLETE); 919 atmci_set_pending(host, EVENT_XFER_COMPLETE);
732 mci_writel(host, IER, MCI_NOTBUSY); 920 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
733} 921}
734 922
735#endif /* CONFIG_MMC_ATMELMCI_DMA */
736
737/* 923/*
738 * Returns a mask of interrupt flags to be enabled after the whole 924 * Stop data transfer because error(s) occured.
739 * request has been prepared.
740 */ 925 */
741static u32 atmci_prepare_data(struct atmel_mci *host, struct mmc_data *data) 926static void atmci_stop_transfer_pdc(struct atmel_mci *host)
742{ 927{
743 u32 iflags; 928 atmci_set_pending(host, EVENT_XFER_COMPLETE);
744 929 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
745 data->error = -EINPROGRESS; 930}
746
747 WARN_ON(host->data);
748 host->sg = NULL;
749 host->data = data;
750
751 iflags = ATMCI_DATA_ERROR_FLAGS;
752 if (atmci_prepare_data_dma(host, data)) {
753 host->data_chan = NULL;
754 931
755 /* 932static void atmci_stop_transfer_dma(struct atmel_mci *host)
756 * Errata: MMC data write operation with less than 12 933{
757 * bytes is impossible. 934 struct dma_chan *chan = host->data_chan;
758 *
759 * Errata: MCI Transmit Data Register (TDR) FIFO
760 * corruption when length is not multiple of 4.
761 */
762 if (data->blocks * data->blksz < 12
763 || (data->blocks * data->blksz) & 3)
764 host->need_reset = true;
765 935
766 host->sg = data->sg; 936 if (chan) {
767 host->pio_offset = 0; 937 dmaengine_terminate_all(chan);
768 if (data->flags & MMC_DATA_READ) 938 atmci_dma_cleanup(host);
769 iflags |= MCI_RXRDY; 939 } else {
770 else 940 /* Data transfer was stopped by the interrupt handler */
771 iflags |= MCI_TXRDY; 941 atmci_set_pending(host, EVENT_XFER_COMPLETE);
942 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
772 } 943 }
773
774 return iflags;
775} 944}
776 945
946/*
947 * Start a request: prepare data if needed, prepare the command and activate
948 * interrupts.
949 */
777static void atmci_start_request(struct atmel_mci *host, 950static void atmci_start_request(struct atmel_mci *host,
778 struct atmel_mci_slot *slot) 951 struct atmel_mci_slot *slot)
779{ 952{
@@ -792,24 +965,24 @@ static void atmci_start_request(struct atmel_mci *host,
792 host->data_status = 0; 965 host->data_status = 0;
793 966
794 if (host->need_reset) { 967 if (host->need_reset) {
795 mci_writel(host, CR, MCI_CR_SWRST); 968 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
796 mci_writel(host, CR, MCI_CR_MCIEN); 969 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
797 mci_writel(host, MR, host->mode_reg); 970 atmci_writel(host, ATMCI_MR, host->mode_reg);
798 if (atmci_is_mci2()) 971 if (host->caps.has_cfg_reg)
799 mci_writel(host, CFG, host->cfg_reg); 972 atmci_writel(host, ATMCI_CFG, host->cfg_reg);
800 host->need_reset = false; 973 host->need_reset = false;
801 } 974 }
802 mci_writel(host, SDCR, slot->sdc_reg); 975 atmci_writel(host, ATMCI_SDCR, slot->sdc_reg);
803 976
804 iflags = mci_readl(host, IMR); 977 iflags = atmci_readl(host, ATMCI_IMR);
805 if (iflags & ~(MCI_SDIOIRQA | MCI_SDIOIRQB)) 978 if (iflags & ~(ATMCI_SDIOIRQA | ATMCI_SDIOIRQB))
806 dev_warn(&slot->mmc->class_dev, "WARNING: IMR=0x%08x\n", 979 dev_warn(&slot->mmc->class_dev, "WARNING: IMR=0x%08x\n",
807 iflags); 980 iflags);
808 981
809 if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT, &slot->flags))) { 982 if (unlikely(test_and_clear_bit(ATMCI_CARD_NEED_INIT, &slot->flags))) {
810 /* Send init sequence (74 clock cycles) */ 983 /* Send init sequence (74 clock cycles) */
811 mci_writel(host, CMDR, MCI_CMDR_SPCMD_INIT); 984 atmci_writel(host, ATMCI_CMDR, ATMCI_CMDR_SPCMD_INIT);
812 while (!(mci_readl(host, SR) & MCI_CMDRDY)) 985 while (!(atmci_readl(host, ATMCI_SR) & ATMCI_CMDRDY))
813 cpu_relax(); 986 cpu_relax();
814 } 987 }
815 iflags = 0; 988 iflags = 0;
@@ -818,31 +991,31 @@ static void atmci_start_request(struct atmel_mci *host,
818 atmci_set_timeout(host, slot, data); 991 atmci_set_timeout(host, slot, data);
819 992
820 /* Must set block count/size before sending command */ 993 /* Must set block count/size before sending command */
821 mci_writel(host, BLKR, MCI_BCNT(data->blocks) 994 atmci_writel(host, ATMCI_BLKR, ATMCI_BCNT(data->blocks)
822 | MCI_BLKLEN(data->blksz)); 995 | ATMCI_BLKLEN(data->blksz));
823 dev_vdbg(&slot->mmc->class_dev, "BLKR=0x%08x\n", 996 dev_vdbg(&slot->mmc->class_dev, "BLKR=0x%08x\n",
824 MCI_BCNT(data->blocks) | MCI_BLKLEN(data->blksz)); 997 ATMCI_BCNT(data->blocks) | ATMCI_BLKLEN(data->blksz));
825 998
826 iflags |= atmci_prepare_data(host, data); 999 iflags |= host->prepare_data(host, data);
827 } 1000 }
828 1001
829 iflags |= MCI_CMDRDY; 1002 iflags |= ATMCI_CMDRDY;
830 cmd = mrq->cmd; 1003 cmd = mrq->cmd;
831 cmdflags = atmci_prepare_command(slot->mmc, cmd); 1004 cmdflags = atmci_prepare_command(slot->mmc, cmd);
832 atmci_start_command(host, cmd, cmdflags); 1005 atmci_send_command(host, cmd, cmdflags);
833 1006
834 if (data) 1007 if (data)
835 atmci_submit_data(host); 1008 host->submit_data(host, data);
836 1009
837 if (mrq->stop) { 1010 if (mrq->stop) {
838 host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop); 1011 host->stop_cmdr = atmci_prepare_command(slot->mmc, mrq->stop);
839 host->stop_cmdr |= MCI_CMDR_STOP_XFER; 1012 host->stop_cmdr |= ATMCI_CMDR_STOP_XFER;
840 if (!(data->flags & MMC_DATA_WRITE)) 1013 if (!(data->flags & MMC_DATA_WRITE))
841 host->stop_cmdr |= MCI_CMDR_TRDIR_READ; 1014 host->stop_cmdr |= ATMCI_CMDR_TRDIR_READ;
842 if (data->flags & MMC_DATA_STREAM) 1015 if (data->flags & MMC_DATA_STREAM)
843 host->stop_cmdr |= MCI_CMDR_STREAM; 1016 host->stop_cmdr |= ATMCI_CMDR_STREAM;
844 else 1017 else
845 host->stop_cmdr |= MCI_CMDR_MULTI_BLOCK; 1018 host->stop_cmdr |= ATMCI_CMDR_MULTI_BLOCK;
846 } 1019 }
847 1020
848 /* 1021 /*
@@ -851,7 +1024,7 @@ static void atmci_start_request(struct atmel_mci *host,
851 * conditions (e.g. command and data complete, but stop not 1024 * conditions (e.g. command and data complete, but stop not
852 * prepared yet.) 1025 * prepared yet.)
853 */ 1026 */
854 mci_writel(host, IER, iflags); 1027 atmci_writel(host, ATMCI_IER, iflags);
855} 1028}
856 1029
857static void atmci_queue_request(struct atmel_mci *host, 1030static void atmci_queue_request(struct atmel_mci *host,
@@ -909,13 +1082,13 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
909 struct atmel_mci *host = slot->host; 1082 struct atmel_mci *host = slot->host;
910 unsigned int i; 1083 unsigned int i;
911 1084
912 slot->sdc_reg &= ~MCI_SDCBUS_MASK; 1085 slot->sdc_reg &= ~ATMCI_SDCBUS_MASK;
913 switch (ios->bus_width) { 1086 switch (ios->bus_width) {
914 case MMC_BUS_WIDTH_1: 1087 case MMC_BUS_WIDTH_1:
915 slot->sdc_reg |= MCI_SDCBUS_1BIT; 1088 slot->sdc_reg |= ATMCI_SDCBUS_1BIT;
916 break; 1089 break;
917 case MMC_BUS_WIDTH_4: 1090 case MMC_BUS_WIDTH_4:
918 slot->sdc_reg |= MCI_SDCBUS_4BIT; 1091 slot->sdc_reg |= ATMCI_SDCBUS_4BIT;
919 break; 1092 break;
920 } 1093 }
921 1094
@@ -926,10 +1099,10 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
926 spin_lock_bh(&host->lock); 1099 spin_lock_bh(&host->lock);
927 if (!host->mode_reg) { 1100 if (!host->mode_reg) {
928 clk_enable(host->mck); 1101 clk_enable(host->mck);
929 mci_writel(host, CR, MCI_CR_SWRST); 1102 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
930 mci_writel(host, CR, MCI_CR_MCIEN); 1103 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
931 if (atmci_is_mci2()) 1104 if (host->caps.has_cfg_reg)
932 mci_writel(host, CFG, host->cfg_reg); 1105 atmci_writel(host, ATMCI_CFG, host->cfg_reg);
933 } 1106 }
934 1107
935 /* 1108 /*
@@ -937,7 +1110,7 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
937 * core ios update when finding the minimum. 1110 * core ios update when finding the minimum.
938 */ 1111 */
939 slot->clock = ios->clock; 1112 slot->clock = ios->clock;
940 for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) { 1113 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
941 if (host->slot[i] && host->slot[i]->clock 1114 if (host->slot[i] && host->slot[i]->clock
942 && host->slot[i]->clock < clock_min) 1115 && host->slot[i]->clock < clock_min)
943 clock_min = host->slot[i]->clock; 1116 clock_min = host->slot[i]->clock;
@@ -952,28 +1125,28 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
952 clkdiv = 255; 1125 clkdiv = 255;
953 } 1126 }
954 1127
955 host->mode_reg = MCI_MR_CLKDIV(clkdiv); 1128 host->mode_reg = ATMCI_MR_CLKDIV(clkdiv);
956 1129
957 /* 1130 /*
958 * WRPROOF and RDPROOF prevent overruns/underruns by 1131 * WRPROOF and RDPROOF prevent overruns/underruns by
959 * stopping the clock when the FIFO is full/empty. 1132 * stopping the clock when the FIFO is full/empty.
960 * This state is not expected to last for long. 1133 * This state is not expected to last for long.
961 */ 1134 */
962 if (mci_has_rwproof()) 1135 if (host->caps.has_rwproof)
963 host->mode_reg |= (MCI_MR_WRPROOF | MCI_MR_RDPROOF); 1136 host->mode_reg |= (ATMCI_MR_WRPROOF | ATMCI_MR_RDPROOF);
964 1137
965 if (atmci_is_mci2()) { 1138 if (host->caps.has_cfg_reg) {
966 /* setup High Speed mode in relation with card capacity */ 1139 /* setup High Speed mode in relation with card capacity */
967 if (ios->timing == MMC_TIMING_SD_HS) 1140 if (ios->timing == MMC_TIMING_SD_HS)
968 host->cfg_reg |= MCI_CFG_HSMODE; 1141 host->cfg_reg |= ATMCI_CFG_HSMODE;
969 else 1142 else
970 host->cfg_reg &= ~MCI_CFG_HSMODE; 1143 host->cfg_reg &= ~ATMCI_CFG_HSMODE;
971 } 1144 }
972 1145
973 if (list_empty(&host->queue)) { 1146 if (list_empty(&host->queue)) {
974 mci_writel(host, MR, host->mode_reg); 1147 atmci_writel(host, ATMCI_MR, host->mode_reg);
975 if (atmci_is_mci2()) 1148 if (host->caps.has_cfg_reg)
976 mci_writel(host, CFG, host->cfg_reg); 1149 atmci_writel(host, ATMCI_CFG, host->cfg_reg);
977 } else { 1150 } else {
978 host->need_clock_update = true; 1151 host->need_clock_update = true;
979 } 1152 }
@@ -984,16 +1157,16 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
984 1157
985 spin_lock_bh(&host->lock); 1158 spin_lock_bh(&host->lock);
986 slot->clock = 0; 1159 slot->clock = 0;
987 for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) { 1160 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
988 if (host->slot[i] && host->slot[i]->clock) { 1161 if (host->slot[i] && host->slot[i]->clock) {
989 any_slot_active = true; 1162 any_slot_active = true;
990 break; 1163 break;
991 } 1164 }
992 } 1165 }
993 if (!any_slot_active) { 1166 if (!any_slot_active) {
994 mci_writel(host, CR, MCI_CR_MCIDIS); 1167 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
995 if (host->mode_reg) { 1168 if (host->mode_reg) {
996 mci_readl(host, MR); 1169 atmci_readl(host, ATMCI_MR);
997 clk_disable(host->mck); 1170 clk_disable(host->mck);
998 } 1171 }
999 host->mode_reg = 0; 1172 host->mode_reg = 0;
@@ -1057,9 +1230,9 @@ static void atmci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1057 struct atmel_mci *host = slot->host; 1230 struct atmel_mci *host = slot->host;
1058 1231
1059 if (enable) 1232 if (enable)
1060 mci_writel(host, IER, slot->sdio_irq); 1233 atmci_writel(host, ATMCI_IER, slot->sdio_irq);
1061 else 1234 else
1062 mci_writel(host, IDR, slot->sdio_irq); 1235 atmci_writel(host, ATMCI_IDR, slot->sdio_irq);
1063} 1236}
1064 1237
1065static const struct mmc_host_ops atmci_ops = { 1238static const struct mmc_host_ops atmci_ops = {
@@ -1086,9 +1259,9 @@ static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq)
1086 * busy transferring data. 1259 * busy transferring data.
1087 */ 1260 */
1088 if (host->need_clock_update) { 1261 if (host->need_clock_update) {
1089 mci_writel(host, MR, host->mode_reg); 1262 atmci_writel(host, ATMCI_MR, host->mode_reg);
1090 if (atmci_is_mci2()) 1263 if (host->caps.has_cfg_reg)
1091 mci_writel(host, CFG, host->cfg_reg); 1264 atmci_writel(host, ATMCI_CFG, host->cfg_reg);
1092 } 1265 }
1093 1266
1094 host->cur_slot->mrq = NULL; 1267 host->cur_slot->mrq = NULL;
@@ -1117,16 +1290,16 @@ static void atmci_command_complete(struct atmel_mci *host,
1117 u32 status = host->cmd_status; 1290 u32 status = host->cmd_status;
1118 1291
1119 /* Read the response from the card (up to 16 bytes) */ 1292 /* Read the response from the card (up to 16 bytes) */
1120 cmd->resp[0] = mci_readl(host, RSPR); 1293 cmd->resp[0] = atmci_readl(host, ATMCI_RSPR);
1121 cmd->resp[1] = mci_readl(host, RSPR); 1294 cmd->resp[1] = atmci_readl(host, ATMCI_RSPR);
1122 cmd->resp[2] = mci_readl(host, RSPR); 1295 cmd->resp[2] = atmci_readl(host, ATMCI_RSPR);
1123 cmd->resp[3] = mci_readl(host, RSPR); 1296 cmd->resp[3] = atmci_readl(host, ATMCI_RSPR);
1124 1297
1125 if (status & MCI_RTOE) 1298 if (status & ATMCI_RTOE)
1126 cmd->error = -ETIMEDOUT; 1299 cmd->error = -ETIMEDOUT;
1127 else if ((cmd->flags & MMC_RSP_CRC) && (status & MCI_RCRCE)) 1300 else if ((cmd->flags & MMC_RSP_CRC) && (status & ATMCI_RCRCE))
1128 cmd->error = -EILSEQ; 1301 cmd->error = -EILSEQ;
1129 else if (status & (MCI_RINDE | MCI_RDIRE | MCI_RENDE)) 1302 else if (status & (ATMCI_RINDE | ATMCI_RDIRE | ATMCI_RENDE))
1130 cmd->error = -EIO; 1303 cmd->error = -EIO;
1131 else 1304 else
1132 cmd->error = 0; 1305 cmd->error = 0;
@@ -1136,10 +1309,10 @@ static void atmci_command_complete(struct atmel_mci *host,
1136 "command error: status=0x%08x\n", status); 1309 "command error: status=0x%08x\n", status);
1137 1310
1138 if (cmd->data) { 1311 if (cmd->data) {
1139 atmci_stop_dma(host); 1312 host->stop_transfer(host);
1140 host->data = NULL; 1313 host->data = NULL;
1141 mci_writel(host, IDR, MCI_NOTBUSY 1314 atmci_writel(host, ATMCI_IDR, ATMCI_NOTBUSY
1142 | MCI_TXRDY | MCI_RXRDY 1315 | ATMCI_TXRDY | ATMCI_RXRDY
1143 | ATMCI_DATA_ERROR_FLAGS); 1316 | ATMCI_DATA_ERROR_FLAGS);
1144 } 1317 }
1145 } 1318 }
@@ -1191,11 +1364,11 @@ static void atmci_detect_change(unsigned long data)
1191 * Reset controller to terminate any ongoing 1364 * Reset controller to terminate any ongoing
1192 * commands or data transfers. 1365 * commands or data transfers.
1193 */ 1366 */
1194 mci_writel(host, CR, MCI_CR_SWRST); 1367 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
1195 mci_writel(host, CR, MCI_CR_MCIEN); 1368 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
1196 mci_writel(host, MR, host->mode_reg); 1369 atmci_writel(host, ATMCI_MR, host->mode_reg);
1197 if (atmci_is_mci2()) 1370 if (host->caps.has_cfg_reg)
1198 mci_writel(host, CFG, host->cfg_reg); 1371 atmci_writel(host, ATMCI_CFG, host->cfg_reg);
1199 1372
1200 host->data = NULL; 1373 host->data = NULL;
1201 host->cmd = NULL; 1374 host->cmd = NULL;
@@ -1210,7 +1383,7 @@ static void atmci_detect_change(unsigned long data)
1210 /* fall through */ 1383 /* fall through */
1211 case STATE_SENDING_DATA: 1384 case STATE_SENDING_DATA:
1212 mrq->data->error = -ENOMEDIUM; 1385 mrq->data->error = -ENOMEDIUM;
1213 atmci_stop_dma(host); 1386 host->stop_transfer(host);
1214 break; 1387 break;
1215 case STATE_DATA_BUSY: 1388 case STATE_DATA_BUSY:
1216 case STATE_DATA_ERROR: 1389 case STATE_DATA_ERROR:
@@ -1261,7 +1434,7 @@ static void atmci_tasklet_func(unsigned long priv)
1261 dev_vdbg(&host->pdev->dev, 1434 dev_vdbg(&host->pdev->dev,
1262 "tasklet: state %u pending/completed/mask %lx/%lx/%x\n", 1435 "tasklet: state %u pending/completed/mask %lx/%lx/%x\n",
1263 state, host->pending_events, host->completed_events, 1436 state, host->pending_events, host->completed_events,
1264 mci_readl(host, IMR)); 1437 atmci_readl(host, ATMCI_IMR));
1265 1438
1266 do { 1439 do {
1267 prev_state = state; 1440 prev_state = state;
@@ -1289,9 +1462,9 @@ static void atmci_tasklet_func(unsigned long priv)
1289 case STATE_SENDING_DATA: 1462 case STATE_SENDING_DATA:
1290 if (atmci_test_and_clear_pending(host, 1463 if (atmci_test_and_clear_pending(host,
1291 EVENT_DATA_ERROR)) { 1464 EVENT_DATA_ERROR)) {
1292 atmci_stop_dma(host); 1465 host->stop_transfer(host);
1293 if (data->stop) 1466 if (data->stop)
1294 send_stop_cmd(host, data); 1467 atmci_send_stop_cmd(host, data);
1295 state = STATE_DATA_ERROR; 1468 state = STATE_DATA_ERROR;
1296 break; 1469 break;
1297 } 1470 }
@@ -1313,11 +1486,11 @@ static void atmci_tasklet_func(unsigned long priv)
1313 atmci_set_completed(host, EVENT_DATA_COMPLETE); 1486 atmci_set_completed(host, EVENT_DATA_COMPLETE);
1314 status = host->data_status; 1487 status = host->data_status;
1315 if (unlikely(status & ATMCI_DATA_ERROR_FLAGS)) { 1488 if (unlikely(status & ATMCI_DATA_ERROR_FLAGS)) {
1316 if (status & MCI_DTOE) { 1489 if (status & ATMCI_DTOE) {
1317 dev_dbg(&host->pdev->dev, 1490 dev_dbg(&host->pdev->dev,
1318 "data timeout error\n"); 1491 "data timeout error\n");
1319 data->error = -ETIMEDOUT; 1492 data->error = -ETIMEDOUT;
1320 } else if (status & MCI_DCRCE) { 1493 } else if (status & ATMCI_DCRCE) {
1321 dev_dbg(&host->pdev->dev, 1494 dev_dbg(&host->pdev->dev,
1322 "data CRC error\n"); 1495 "data CRC error\n");
1323 data->error = -EILSEQ; 1496 data->error = -EILSEQ;
@@ -1330,7 +1503,7 @@ static void atmci_tasklet_func(unsigned long priv)
1330 } else { 1503 } else {
1331 data->bytes_xfered = data->blocks * data->blksz; 1504 data->bytes_xfered = data->blocks * data->blksz;
1332 data->error = 0; 1505 data->error = 0;
1333 mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS); 1506 atmci_writel(host, ATMCI_IDR, ATMCI_DATA_ERROR_FLAGS);
1334 } 1507 }
1335 1508
1336 if (!data->stop) { 1509 if (!data->stop) {
@@ -1340,7 +1513,7 @@ static void atmci_tasklet_func(unsigned long priv)
1340 1513
1341 prev_state = state = STATE_SENDING_STOP; 1514 prev_state = state = STATE_SENDING_STOP;
1342 if (!data->error) 1515 if (!data->error)
1343 send_stop_cmd(host, data); 1516 atmci_send_stop_cmd(host, data);
1344 /* fall through */ 1517 /* fall through */
1345 1518
1346 case STATE_SENDING_STOP: 1519 case STATE_SENDING_STOP:
@@ -1380,7 +1553,7 @@ static void atmci_read_data_pio(struct atmel_mci *host)
1380 unsigned int nbytes = 0; 1553 unsigned int nbytes = 0;
1381 1554
1382 do { 1555 do {
1383 value = mci_readl(host, RDR); 1556 value = atmci_readl(host, ATMCI_RDR);
1384 if (likely(offset + 4 <= sg->length)) { 1557 if (likely(offset + 4 <= sg->length)) {
1385 put_unaligned(value, (u32 *)(buf + offset)); 1558 put_unaligned(value, (u32 *)(buf + offset));
1386 1559
@@ -1412,9 +1585,9 @@ static void atmci_read_data_pio(struct atmel_mci *host)
1412 nbytes += offset; 1585 nbytes += offset;
1413 } 1586 }
1414 1587
1415 status = mci_readl(host, SR); 1588 status = atmci_readl(host, ATMCI_SR);
1416 if (status & ATMCI_DATA_ERROR_FLAGS) { 1589 if (status & ATMCI_DATA_ERROR_FLAGS) {
1417 mci_writel(host, IDR, (MCI_NOTBUSY | MCI_RXRDY 1590 atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_RXRDY
1418 | ATMCI_DATA_ERROR_FLAGS)); 1591 | ATMCI_DATA_ERROR_FLAGS));
1419 host->data_status = status; 1592 host->data_status = status;
1420 data->bytes_xfered += nbytes; 1593 data->bytes_xfered += nbytes;
@@ -1423,7 +1596,7 @@ static void atmci_read_data_pio(struct atmel_mci *host)
1423 tasklet_schedule(&host->tasklet); 1596 tasklet_schedule(&host->tasklet);
1424 return; 1597 return;
1425 } 1598 }
1426 } while (status & MCI_RXRDY); 1599 } while (status & ATMCI_RXRDY);
1427 1600
1428 host->pio_offset = offset; 1601 host->pio_offset = offset;
1429 data->bytes_xfered += nbytes; 1602 data->bytes_xfered += nbytes;
@@ -1431,8 +1604,8 @@ static void atmci_read_data_pio(struct atmel_mci *host)
1431 return; 1604 return;
1432 1605
1433done: 1606done:
1434 mci_writel(host, IDR, MCI_RXRDY); 1607 atmci_writel(host, ATMCI_IDR, ATMCI_RXRDY);
1435 mci_writel(host, IER, MCI_NOTBUSY); 1608 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
1436 data->bytes_xfered += nbytes; 1609 data->bytes_xfered += nbytes;
1437 smp_wmb(); 1610 smp_wmb();
1438 atmci_set_pending(host, EVENT_XFER_COMPLETE); 1611 atmci_set_pending(host, EVENT_XFER_COMPLETE);
@@ -1451,7 +1624,7 @@ static void atmci_write_data_pio(struct atmel_mci *host)
1451 do { 1624 do {
1452 if (likely(offset + 4 <= sg->length)) { 1625 if (likely(offset + 4 <= sg->length)) {
1453 value = get_unaligned((u32 *)(buf + offset)); 1626 value = get_unaligned((u32 *)(buf + offset));
1454 mci_writel(host, TDR, value); 1627 atmci_writel(host, ATMCI_TDR, value);
1455 1628
1456 offset += 4; 1629 offset += 4;
1457 nbytes += 4; 1630 nbytes += 4;
@@ -1472,20 +1645,20 @@ static void atmci_write_data_pio(struct atmel_mci *host)
1472 1645
1473 host->sg = sg = sg_next(sg); 1646 host->sg = sg = sg_next(sg);
1474 if (!sg) { 1647 if (!sg) {
1475 mci_writel(host, TDR, value); 1648 atmci_writel(host, ATMCI_TDR, value);
1476 goto done; 1649 goto done;
1477 } 1650 }
1478 1651
1479 offset = 4 - remaining; 1652 offset = 4 - remaining;
1480 buf = sg_virt(sg); 1653 buf = sg_virt(sg);
1481 memcpy((u8 *)&value + remaining, buf, offset); 1654 memcpy((u8 *)&value + remaining, buf, offset);
1482 mci_writel(host, TDR, value); 1655 atmci_writel(host, ATMCI_TDR, value);
1483 nbytes += offset; 1656 nbytes += offset;
1484 } 1657 }
1485 1658
1486 status = mci_readl(host, SR); 1659 status = atmci_readl(host, ATMCI_SR);
1487 if (status & ATMCI_DATA_ERROR_FLAGS) { 1660 if (status & ATMCI_DATA_ERROR_FLAGS) {
1488 mci_writel(host, IDR, (MCI_NOTBUSY | MCI_TXRDY 1661 atmci_writel(host, ATMCI_IDR, (ATMCI_NOTBUSY | ATMCI_TXRDY
1489 | ATMCI_DATA_ERROR_FLAGS)); 1662 | ATMCI_DATA_ERROR_FLAGS));
1490 host->data_status = status; 1663 host->data_status = status;
1491 data->bytes_xfered += nbytes; 1664 data->bytes_xfered += nbytes;
@@ -1494,7 +1667,7 @@ static void atmci_write_data_pio(struct atmel_mci *host)
1494 tasklet_schedule(&host->tasklet); 1667 tasklet_schedule(&host->tasklet);
1495 return; 1668 return;
1496 } 1669 }
1497 } while (status & MCI_TXRDY); 1670 } while (status & ATMCI_TXRDY);
1498 1671
1499 host->pio_offset = offset; 1672 host->pio_offset = offset;
1500 data->bytes_xfered += nbytes; 1673 data->bytes_xfered += nbytes;
@@ -1502,8 +1675,8 @@ static void atmci_write_data_pio(struct atmel_mci *host)
1502 return; 1675 return;
1503 1676
1504done: 1677done:
1505 mci_writel(host, IDR, MCI_TXRDY); 1678 atmci_writel(host, ATMCI_IDR, ATMCI_TXRDY);
1506 mci_writel(host, IER, MCI_NOTBUSY); 1679 atmci_writel(host, ATMCI_IER, ATMCI_NOTBUSY);
1507 data->bytes_xfered += nbytes; 1680 data->bytes_xfered += nbytes;
1508 smp_wmb(); 1681 smp_wmb();
1509 atmci_set_pending(host, EVENT_XFER_COMPLETE); 1682 atmci_set_pending(host, EVENT_XFER_COMPLETE);
@@ -1511,7 +1684,7 @@ done:
1511 1684
1512static void atmci_cmd_interrupt(struct atmel_mci *host, u32 status) 1685static void atmci_cmd_interrupt(struct atmel_mci *host, u32 status)
1513{ 1686{
1514 mci_writel(host, IDR, MCI_CMDRDY); 1687 atmci_writel(host, ATMCI_IDR, ATMCI_CMDRDY);
1515 1688
1516 host->cmd_status = status; 1689 host->cmd_status = status;
1517 smp_wmb(); 1690 smp_wmb();
@@ -1523,7 +1696,7 @@ static void atmci_sdio_interrupt(struct atmel_mci *host, u32 status)
1523{ 1696{
1524 int i; 1697 int i;
1525 1698
1526 for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) { 1699 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
1527 struct atmel_mci_slot *slot = host->slot[i]; 1700 struct atmel_mci_slot *slot = host->slot[i];
1528 if (slot && (status & slot->sdio_irq)) { 1701 if (slot && (status & slot->sdio_irq)) {
1529 mmc_signal_sdio_irq(slot->mmc); 1702 mmc_signal_sdio_irq(slot->mmc);
@@ -1539,40 +1712,92 @@ static irqreturn_t atmci_interrupt(int irq, void *dev_id)
1539 unsigned int pass_count = 0; 1712 unsigned int pass_count = 0;
1540 1713
1541 do { 1714 do {
1542 status = mci_readl(host, SR); 1715 status = atmci_readl(host, ATMCI_SR);
1543 mask = mci_readl(host, IMR); 1716 mask = atmci_readl(host, ATMCI_IMR);
1544 pending = status & mask; 1717 pending = status & mask;
1545 if (!pending) 1718 if (!pending)
1546 break; 1719 break;
1547 1720
1548 if (pending & ATMCI_DATA_ERROR_FLAGS) { 1721 if (pending & ATMCI_DATA_ERROR_FLAGS) {
1549 mci_writel(host, IDR, ATMCI_DATA_ERROR_FLAGS 1722 atmci_writel(host, ATMCI_IDR, ATMCI_DATA_ERROR_FLAGS
1550 | MCI_RXRDY | MCI_TXRDY); 1723 | ATMCI_RXRDY | ATMCI_TXRDY);
1551 pending &= mci_readl(host, IMR); 1724 pending &= atmci_readl(host, ATMCI_IMR);
1552 1725
1553 host->data_status = status; 1726 host->data_status = status;
1554 smp_wmb(); 1727 smp_wmb();
1555 atmci_set_pending(host, EVENT_DATA_ERROR); 1728 atmci_set_pending(host, EVENT_DATA_ERROR);
1556 tasklet_schedule(&host->tasklet); 1729 tasklet_schedule(&host->tasklet);
1557 } 1730 }
1558 if (pending & MCI_NOTBUSY) { 1731
1559 mci_writel(host, IDR, 1732 if (pending & ATMCI_TXBUFE) {
1560 ATMCI_DATA_ERROR_FLAGS | MCI_NOTBUSY); 1733 atmci_writel(host, ATMCI_IDR, ATMCI_TXBUFE);
1734 atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX);
1735 /*
1736 * We can receive this interruption before having configured
1737 * the second pdc buffer, so we need to reconfigure first and
1738 * second buffers again
1739 */
1740 if (host->data_size) {
1741 atmci_pdc_set_both_buf(host, XFER_TRANSMIT);
1742 atmci_writel(host, ATMCI_IER, ATMCI_ENDTX);
1743 atmci_writel(host, ATMCI_IER, ATMCI_TXBUFE);
1744 } else {
1745 atmci_pdc_complete(host);
1746 }
1747 } else if (pending & ATMCI_ENDTX) {
1748 atmci_writel(host, ATMCI_IDR, ATMCI_ENDTX);
1749
1750 if (host->data_size) {
1751 atmci_pdc_set_single_buf(host,
1752 XFER_TRANSMIT, PDC_SECOND_BUF);
1753 atmci_writel(host, ATMCI_IER, ATMCI_ENDTX);
1754 }
1755 }
1756
1757 if (pending & ATMCI_RXBUFF) {
1758 atmci_writel(host, ATMCI_IDR, ATMCI_RXBUFF);
1759 atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX);
1760 /*
1761 * We can receive this interruption before having configured
1762 * the second pdc buffer, so we need to reconfigure first and
1763 * second buffers again
1764 */
1765 if (host->data_size) {
1766 atmci_pdc_set_both_buf(host, XFER_RECEIVE);
1767 atmci_writel(host, ATMCI_IER, ATMCI_ENDRX);
1768 atmci_writel(host, ATMCI_IER, ATMCI_RXBUFF);
1769 } else {
1770 atmci_pdc_complete(host);
1771 }
1772 } else if (pending & ATMCI_ENDRX) {
1773 atmci_writel(host, ATMCI_IDR, ATMCI_ENDRX);
1774
1775 if (host->data_size) {
1776 atmci_pdc_set_single_buf(host,
1777 XFER_RECEIVE, PDC_SECOND_BUF);
1778 atmci_writel(host, ATMCI_IER, ATMCI_ENDRX);
1779 }
1780 }
1781
1782
1783 if (pending & ATMCI_NOTBUSY) {
1784 atmci_writel(host, ATMCI_IDR,
1785 ATMCI_DATA_ERROR_FLAGS | ATMCI_NOTBUSY);
1561 if (!host->data_status) 1786 if (!host->data_status)
1562 host->data_status = status; 1787 host->data_status = status;
1563 smp_wmb(); 1788 smp_wmb();
1564 atmci_set_pending(host, EVENT_DATA_COMPLETE); 1789 atmci_set_pending(host, EVENT_DATA_COMPLETE);
1565 tasklet_schedule(&host->tasklet); 1790 tasklet_schedule(&host->tasklet);
1566 } 1791 }
1567 if (pending & MCI_RXRDY) 1792 if (pending & ATMCI_RXRDY)
1568 atmci_read_data_pio(host); 1793 atmci_read_data_pio(host);
1569 if (pending & MCI_TXRDY) 1794 if (pending & ATMCI_TXRDY)
1570 atmci_write_data_pio(host); 1795 atmci_write_data_pio(host);
1571 1796
1572 if (pending & MCI_CMDRDY) 1797 if (pending & ATMCI_CMDRDY)
1573 atmci_cmd_interrupt(host, status); 1798 atmci_cmd_interrupt(host, status);
1574 1799
1575 if (pending & (MCI_SDIOIRQA | MCI_SDIOIRQB)) 1800 if (pending & (ATMCI_SDIOIRQA | ATMCI_SDIOIRQB))
1576 atmci_sdio_interrupt(host, status); 1801 atmci_sdio_interrupt(host, status);
1577 1802
1578 } while (pass_count++ < 5); 1803 } while (pass_count++ < 5);
@@ -1621,7 +1846,7 @@ static int __init atmci_init_slot(struct atmel_mci *host,
1621 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 1846 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1622 if (sdio_irq) 1847 if (sdio_irq)
1623 mmc->caps |= MMC_CAP_SDIO_IRQ; 1848 mmc->caps |= MMC_CAP_SDIO_IRQ;
1624 if (atmci_is_mci2()) 1849 if (host->caps.has_highspeed)
1625 mmc->caps |= MMC_CAP_SD_HIGHSPEED; 1850 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
1626 if (slot_data->bus_width >= 4) 1851 if (slot_data->bus_width >= 4)
1627 mmc->caps |= MMC_CAP_4_BIT_DATA; 1852 mmc->caps |= MMC_CAP_4_BIT_DATA;
@@ -1704,8 +1929,7 @@ static void __exit atmci_cleanup_slot(struct atmel_mci_slot *slot,
1704 mmc_free_host(slot->mmc); 1929 mmc_free_host(slot->mmc);
1705} 1930}
1706 1931
1707#ifdef CONFIG_MMC_ATMELMCI_DMA 1932static bool atmci_filter(struct dma_chan *chan, void *slave)
1708static bool filter(struct dma_chan *chan, void *slave)
1709{ 1933{
1710 struct mci_dma_data *sl = slave; 1934 struct mci_dma_data *sl = slave;
1711 1935
@@ -1730,14 +1954,14 @@ static void atmci_configure_dma(struct atmel_mci *host)
1730 dma_cap_mask_t mask; 1954 dma_cap_mask_t mask;
1731 1955
1732 setup_dma_addr(pdata->dma_slave, 1956 setup_dma_addr(pdata->dma_slave,
1733 host->mapbase + MCI_TDR, 1957 host->mapbase + ATMCI_TDR,
1734 host->mapbase + MCI_RDR); 1958 host->mapbase + ATMCI_RDR);
1735 1959
1736 /* Try to grab a DMA channel */ 1960 /* Try to grab a DMA channel */
1737 dma_cap_zero(mask); 1961 dma_cap_zero(mask);
1738 dma_cap_set(DMA_SLAVE, mask); 1962 dma_cap_set(DMA_SLAVE, mask);
1739 host->dma.chan = 1963 host->dma.chan =
1740 dma_request_channel(mask, filter, pdata->dma_slave); 1964 dma_request_channel(mask, atmci_filter, pdata->dma_slave);
1741 } 1965 }
1742 if (!host->dma.chan) 1966 if (!host->dma.chan)
1743 dev_notice(&host->pdev->dev, "DMA not available, using PIO\n"); 1967 dev_notice(&host->pdev->dev, "DMA not available, using PIO\n");
@@ -1746,9 +1970,60 @@ static void atmci_configure_dma(struct atmel_mci *host)
1746 "Using %s for DMA transfers\n", 1970 "Using %s for DMA transfers\n",
1747 dma_chan_name(host->dma.chan)); 1971 dma_chan_name(host->dma.chan));
1748} 1972}
1973
1974static inline unsigned int atmci_get_version(struct atmel_mci *host)
1975{
1976 return atmci_readl(host, ATMCI_VERSION) & 0x00000fff;
1977}
1978
1979/*
1980 * HSMCI (High Speed MCI) module is not fully compatible with MCI module.
1981 * HSMCI provides DMA support and a new config register but no more supports
1982 * PDC.
1983 */
1984static void __init atmci_get_cap(struct atmel_mci *host)
1985{
1986 unsigned int version;
1987
1988 version = atmci_get_version(host);
1989 dev_info(&host->pdev->dev,
1990 "version: 0x%x\n", version);
1991
1992 host->caps.has_dma = 0;
1993 host->caps.has_pdc = 0;
1994 host->caps.has_cfg_reg = 0;
1995 host->caps.has_cstor_reg = 0;
1996 host->caps.has_highspeed = 0;
1997 host->caps.has_rwproof = 0;
1998
1999 /* keep only major version number */
2000 switch (version & 0xf00) {
2001 case 0x100:
2002 case 0x200:
2003 host->caps.has_pdc = 1;
2004 host->caps.has_rwproof = 1;
2005 break;
2006 case 0x300:
2007 case 0x400:
2008 case 0x500:
2009#ifdef CONFIG_AT_HDMAC
2010 host->caps.has_dma = 1;
1749#else 2011#else
1750static void atmci_configure_dma(struct atmel_mci *host) {} 2012 host->caps.has_dma = 0;
2013 dev_info(&host->pdev->dev,
2014 "has dma capability but dma engine is not selected, then use pio\n");
1751#endif 2015#endif
2016 host->caps.has_cfg_reg = 1;
2017 host->caps.has_cstor_reg = 1;
2018 host->caps.has_highspeed = 1;
2019 host->caps.has_rwproof = 1;
2020 break;
2021 default:
2022 dev_warn(&host->pdev->dev,
2023 "Unmanaged mci version, set minimum capabilities\n");
2024 break;
2025 }
2026}
1752 2027
1753static int __init atmci_probe(struct platform_device *pdev) 2028static int __init atmci_probe(struct platform_device *pdev)
1754{ 2029{
@@ -1789,7 +2064,7 @@ static int __init atmci_probe(struct platform_device *pdev)
1789 goto err_ioremap; 2064 goto err_ioremap;
1790 2065
1791 clk_enable(host->mck); 2066 clk_enable(host->mck);
1792 mci_writel(host, CR, MCI_CR_SWRST); 2067 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
1793 host->bus_hz = clk_get_rate(host->mck); 2068 host->bus_hz = clk_get_rate(host->mck);
1794 clk_disable(host->mck); 2069 clk_disable(host->mck);
1795 2070
@@ -1801,7 +2076,27 @@ static int __init atmci_probe(struct platform_device *pdev)
1801 if (ret) 2076 if (ret)
1802 goto err_request_irq; 2077 goto err_request_irq;
1803 2078
1804 atmci_configure_dma(host); 2079 /* Get MCI capabilities and set operations according to it */
2080 atmci_get_cap(host);
2081 if (host->caps.has_dma) {
2082 dev_info(&pdev->dev, "using DMA\n");
2083 host->prepare_data = &atmci_prepare_data_dma;
2084 host->submit_data = &atmci_submit_data_dma;
2085 host->stop_transfer = &atmci_stop_transfer_dma;
2086 } else if (host->caps.has_pdc) {
2087 dev_info(&pdev->dev, "using PDC\n");
2088 host->prepare_data = &atmci_prepare_data_pdc;
2089 host->submit_data = &atmci_submit_data_pdc;
2090 host->stop_transfer = &atmci_stop_transfer_pdc;
2091 } else {
2092 dev_info(&pdev->dev, "no DMA, no PDC\n");
2093 host->prepare_data = &atmci_prepare_data;
2094 host->submit_data = &atmci_submit_data;
2095 host->stop_transfer = &atmci_stop_transfer;
2096 }
2097
2098 if (host->caps.has_dma)
2099 atmci_configure_dma(host);
1805 2100
1806 platform_set_drvdata(pdev, host); 2101 platform_set_drvdata(pdev, host);
1807 2102
@@ -1810,13 +2105,13 @@ static int __init atmci_probe(struct platform_device *pdev)
1810 ret = -ENODEV; 2105 ret = -ENODEV;
1811 if (pdata->slot[0].bus_width) { 2106 if (pdata->slot[0].bus_width) {
1812 ret = atmci_init_slot(host, &pdata->slot[0], 2107 ret = atmci_init_slot(host, &pdata->slot[0],
1813 0, MCI_SDCSEL_SLOT_A, MCI_SDIOIRQA); 2108 0, ATMCI_SDCSEL_SLOT_A, ATMCI_SDIOIRQA);
1814 if (!ret) 2109 if (!ret)
1815 nr_slots++; 2110 nr_slots++;
1816 } 2111 }
1817 if (pdata->slot[1].bus_width) { 2112 if (pdata->slot[1].bus_width) {
1818 ret = atmci_init_slot(host, &pdata->slot[1], 2113 ret = atmci_init_slot(host, &pdata->slot[1],
1819 1, MCI_SDCSEL_SLOT_B, MCI_SDIOIRQB); 2114 1, ATMCI_SDCSEL_SLOT_B, ATMCI_SDIOIRQB);
1820 if (!ret) 2115 if (!ret)
1821 nr_slots++; 2116 nr_slots++;
1822 } 2117 }
@@ -1833,10 +2128,8 @@ static int __init atmci_probe(struct platform_device *pdev)
1833 return 0; 2128 return 0;
1834 2129
1835err_init_slot: 2130err_init_slot:
1836#ifdef CONFIG_MMC_ATMELMCI_DMA
1837 if (host->dma.chan) 2131 if (host->dma.chan)
1838 dma_release_channel(host->dma.chan); 2132 dma_release_channel(host->dma.chan);
1839#endif
1840 free_irq(irq, host); 2133 free_irq(irq, host);
1841err_request_irq: 2134err_request_irq:
1842 iounmap(host->regs); 2135 iounmap(host->regs);
@@ -1854,15 +2147,15 @@ static int __exit atmci_remove(struct platform_device *pdev)
1854 2147
1855 platform_set_drvdata(pdev, NULL); 2148 platform_set_drvdata(pdev, NULL);
1856 2149
1857 for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) { 2150 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
1858 if (host->slot[i]) 2151 if (host->slot[i])
1859 atmci_cleanup_slot(host->slot[i], i); 2152 atmci_cleanup_slot(host->slot[i], i);
1860 } 2153 }
1861 2154
1862 clk_enable(host->mck); 2155 clk_enable(host->mck);
1863 mci_writel(host, IDR, ~0UL); 2156 atmci_writel(host, ATMCI_IDR, ~0UL);
1864 mci_writel(host, CR, MCI_CR_MCIDIS); 2157 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
1865 mci_readl(host, SR); 2158 atmci_readl(host, ATMCI_SR);
1866 clk_disable(host->mck); 2159 clk_disable(host->mck);
1867 2160
1868#ifdef CONFIG_MMC_ATMELMCI_DMA 2161#ifdef CONFIG_MMC_ATMELMCI_DMA
@@ -1885,7 +2178,7 @@ static int atmci_suspend(struct device *dev)
1885 struct atmel_mci *host = dev_get_drvdata(dev); 2178 struct atmel_mci *host = dev_get_drvdata(dev);
1886 int i; 2179 int i;
1887 2180
1888 for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) { 2181 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
1889 struct atmel_mci_slot *slot = host->slot[i]; 2182 struct atmel_mci_slot *slot = host->slot[i];
1890 int ret; 2183 int ret;
1891 2184
@@ -1916,7 +2209,7 @@ static int atmci_resume(struct device *dev)
1916 int i; 2209 int i;
1917 int ret = 0; 2210 int ret = 0;
1918 2211
1919 for (i = 0; i < ATMEL_MCI_MAX_NR_SLOTS; i++) { 2212 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
1920 struct atmel_mci_slot *slot = host->slot[i]; 2213 struct atmel_mci_slot *slot = host->slot[i];
1921 int err; 2214 int err;
1922 2215
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index ef72e874ca36..707bc7dddd22 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -55,7 +55,7 @@
55 55
56#ifdef DEBUG 56#ifdef DEBUG
57#define DBG(fmt, idx, args...) \ 57#define DBG(fmt, idx, args...) \
58 printk(KERN_DEBUG "au1xmmc(%d): DEBUG: " fmt, idx, ##args) 58 pr_debug("au1xmmc(%d): DEBUG: " fmt, idx, ##args)
59#else 59#else
60#define DBG(fmt, idx, args...) do {} while (0) 60#define DBG(fmt, idx, args...) do {} while (0)
61#endif 61#endif
@@ -268,7 +268,7 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
268 mmccmd |= SD_CMD_RT_3; 268 mmccmd |= SD_CMD_RT_3;
269 break; 269 break;
270 default: 270 default:
271 printk(KERN_INFO "au1xmmc: unhandled response type %02x\n", 271 pr_info("au1xmmc: unhandled response type %02x\n",
272 mmc_resp_type(cmd)); 272 mmc_resp_type(cmd));
273 return -EINVAL; 273 return -EINVAL;
274 } 274 }
@@ -1031,7 +1031,7 @@ static int __devinit au1xmmc_probe(struct platform_device *pdev)
1031#ifdef CONFIG_SOC_AU1200 1031#ifdef CONFIG_SOC_AU1200
1032 ret = au1xmmc_dbdma_init(host); 1032 ret = au1xmmc_dbdma_init(host);
1033 if (ret) 1033 if (ret)
1034 printk(KERN_INFO DRIVER_NAME ": DBDMA init failed; using PIO\n"); 1034 pr_info(DRIVER_NAME ": DBDMA init failed; using PIO\n");
1035#endif 1035#endif
1036 1036
1037#ifdef CONFIG_LEDS_CLASS 1037#ifdef CONFIG_LEDS_CLASS
@@ -1056,7 +1056,7 @@ static int __devinit au1xmmc_probe(struct platform_device *pdev)
1056 1056
1057 platform_set_drvdata(pdev, host); 1057 platform_set_drvdata(pdev, host);
1058 1058
1059 printk(KERN_INFO DRIVER_NAME ": MMC Controller %d set up at %8.8X" 1059 pr_info(DRIVER_NAME ": MMC Controller %d set up at %8.8X"
1060 " (mode=%s)\n", pdev->id, host->iobase, 1060 " (mode=%s)\n", pdev->id, host->iobase,
1061 host->flags & HOST_F_DMA ? "dma" : "pio"); 1061 host->flags & HOST_F_DMA ? "dma" : "pio");
1062 1062
@@ -1188,7 +1188,7 @@ static int __init au1xmmc_init(void)
1188 */ 1188 */
1189 memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev); 1189 memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
1190 if (!memid) 1190 if (!memid)
1191 printk(KERN_ERR "au1xmmc: cannot add memory dbdma dev\n"); 1191 pr_err("au1xmmc: cannot add memory dbdma dev\n");
1192#endif 1192#endif
1193 return platform_driver_register(&au1xmmc_driver); 1193 return platform_driver_register(&au1xmmc_driver);
1194} 1194}
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index ff0f714b012c..3aaeb0841914 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -764,11 +764,29 @@ static int dw_mci_get_cd(struct mmc_host *mmc)
764 return present; 764 return present;
765} 765}
766 766
767static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
768{
769 struct dw_mci_slot *slot = mmc_priv(mmc);
770 struct dw_mci *host = slot->host;
771 u32 int_mask;
772
773 /* Enable/disable Slot Specific SDIO interrupt */
774 int_mask = mci_readl(host, INTMASK);
775 if (enb) {
776 mci_writel(host, INTMASK,
777 (int_mask | (1 << SDMMC_INT_SDIO(slot->id))));
778 } else {
779 mci_writel(host, INTMASK,
780 (int_mask & ~(1 << SDMMC_INT_SDIO(slot->id))));
781 }
782}
783
767static const struct mmc_host_ops dw_mci_ops = { 784static const struct mmc_host_ops dw_mci_ops = {
768 .request = dw_mci_request, 785 .request = dw_mci_request,
769 .set_ios = dw_mci_set_ios, 786 .set_ios = dw_mci_set_ios,
770 .get_ro = dw_mci_get_ro, 787 .get_ro = dw_mci_get_ro,
771 .get_cd = dw_mci_get_cd, 788 .get_cd = dw_mci_get_cd,
789 .enable_sdio_irq = dw_mci_enable_sdio_irq,
772}; 790};
773 791
774static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) 792static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
@@ -1025,7 +1043,8 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1025 buf += len; 1043 buf += len;
1026 cnt -= len; 1044 cnt -= len;
1027 if (!sg_next(host->sg) || host->part_buf_count == 2) { 1045 if (!sg_next(host->sg) || host->part_buf_count == 2) {
1028 mci_writew(host, DATA, host->part_buf16); 1046 mci_writew(host, DATA(host->data_offset),
1047 host->part_buf16);
1029 host->part_buf_count = 0; 1048 host->part_buf_count = 0;
1030 } 1049 }
1031 } 1050 }
@@ -1042,21 +1061,23 @@ static void dw_mci_push_data16(struct dw_mci *host, void *buf, int cnt)
1042 cnt -= len; 1061 cnt -= len;
1043 /* push data from aligned buffer into fifo */ 1062 /* push data from aligned buffer into fifo */
1044 for (i = 0; i < items; ++i) 1063 for (i = 0; i < items; ++i)
1045 mci_writew(host, DATA, aligned_buf[i]); 1064 mci_writew(host, DATA(host->data_offset),
1065 aligned_buf[i]);
1046 } 1066 }
1047 } else 1067 } else
1048#endif 1068#endif
1049 { 1069 {
1050 u16 *pdata = buf; 1070 u16 *pdata = buf;
1051 for (; cnt >= 2; cnt -= 2) 1071 for (; cnt >= 2; cnt -= 2)
1052 mci_writew(host, DATA, *pdata++); 1072 mci_writew(host, DATA(host->data_offset), *pdata++);
1053 buf = pdata; 1073 buf = pdata;
1054 } 1074 }
1055 /* put anything remaining in the part_buf */ 1075 /* put anything remaining in the part_buf */
1056 if (cnt) { 1076 if (cnt) {
1057 dw_mci_set_part_bytes(host, buf, cnt); 1077 dw_mci_set_part_bytes(host, buf, cnt);
1058 if (!sg_next(host->sg)) 1078 if (!sg_next(host->sg))
1059 mci_writew(host, DATA, host->part_buf16); 1079 mci_writew(host, DATA(host->data_offset),
1080 host->part_buf16);
1060 } 1081 }
1061} 1082}
1062 1083
@@ -1071,7 +1092,8 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
1071 int items = len >> 1; 1092 int items = len >> 1;
1072 int i; 1093 int i;
1073 for (i = 0; i < items; ++i) 1094 for (i = 0; i < items; ++i)
1074 aligned_buf[i] = mci_readw(host, DATA); 1095 aligned_buf[i] = mci_readw(host,
1096 DATA(host->data_offset));
1075 /* memcpy from aligned buffer into output buffer */ 1097 /* memcpy from aligned buffer into output buffer */
1076 memcpy(buf, aligned_buf, len); 1098 memcpy(buf, aligned_buf, len);
1077 buf += len; 1099 buf += len;
@@ -1082,11 +1104,11 @@ static void dw_mci_pull_data16(struct dw_mci *host, void *buf, int cnt)
1082 { 1104 {
1083 u16 *pdata = buf; 1105 u16 *pdata = buf;
1084 for (; cnt >= 2; cnt -= 2) 1106 for (; cnt >= 2; cnt -= 2)
1085 *pdata++ = mci_readw(host, DATA); 1107 *pdata++ = mci_readw(host, DATA(host->data_offset));
1086 buf = pdata; 1108 buf = pdata;
1087 } 1109 }
1088 if (cnt) { 1110 if (cnt) {
1089 host->part_buf16 = mci_readw(host, DATA); 1111 host->part_buf16 = mci_readw(host, DATA(host->data_offset));
1090 dw_mci_pull_final_bytes(host, buf, cnt); 1112 dw_mci_pull_final_bytes(host, buf, cnt);
1091 } 1113 }
1092} 1114}
@@ -1099,7 +1121,8 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1099 buf += len; 1121 buf += len;
1100 cnt -= len; 1122 cnt -= len;
1101 if (!sg_next(host->sg) || host->part_buf_count == 4) { 1123 if (!sg_next(host->sg) || host->part_buf_count == 4) {
1102 mci_writel(host, DATA, host->part_buf32); 1124 mci_writel(host, DATA(host->data_offset),
1125 host->part_buf32);
1103 host->part_buf_count = 0; 1126 host->part_buf_count = 0;
1104 } 1127 }
1105 } 1128 }
@@ -1116,21 +1139,23 @@ static void dw_mci_push_data32(struct dw_mci *host, void *buf, int cnt)
1116 cnt -= len; 1139 cnt -= len;
1117 /* push data from aligned buffer into fifo */ 1140 /* push data from aligned buffer into fifo */
1118 for (i = 0; i < items; ++i) 1141 for (i = 0; i < items; ++i)
1119 mci_writel(host, DATA, aligned_buf[i]); 1142 mci_writel(host, DATA(host->data_offset),
1143 aligned_buf[i]);
1120 } 1144 }
1121 } else 1145 } else
1122#endif 1146#endif
1123 { 1147 {
1124 u32 *pdata = buf; 1148 u32 *pdata = buf;
1125 for (; cnt >= 4; cnt -= 4) 1149 for (; cnt >= 4; cnt -= 4)
1126 mci_writel(host, DATA, *pdata++); 1150 mci_writel(host, DATA(host->data_offset), *pdata++);
1127 buf = pdata; 1151 buf = pdata;
1128 } 1152 }
1129 /* put anything remaining in the part_buf */ 1153 /* put anything remaining in the part_buf */
1130 if (cnt) { 1154 if (cnt) {
1131 dw_mci_set_part_bytes(host, buf, cnt); 1155 dw_mci_set_part_bytes(host, buf, cnt);
1132 if (!sg_next(host->sg)) 1156 if (!sg_next(host->sg))
1133 mci_writel(host, DATA, host->part_buf32); 1157 mci_writel(host, DATA(host->data_offset),
1158 host->part_buf32);
1134 } 1159 }
1135} 1160}
1136 1161
@@ -1145,7 +1170,8 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
1145 int items = len >> 2; 1170 int items = len >> 2;
1146 int i; 1171 int i;
1147 for (i = 0; i < items; ++i) 1172 for (i = 0; i < items; ++i)
1148 aligned_buf[i] = mci_readl(host, DATA); 1173 aligned_buf[i] = mci_readl(host,
1174 DATA(host->data_offset));
1149 /* memcpy from aligned buffer into output buffer */ 1175 /* memcpy from aligned buffer into output buffer */
1150 memcpy(buf, aligned_buf, len); 1176 memcpy(buf, aligned_buf, len);
1151 buf += len; 1177 buf += len;
@@ -1156,11 +1182,11 @@ static void dw_mci_pull_data32(struct dw_mci *host, void *buf, int cnt)
1156 { 1182 {
1157 u32 *pdata = buf; 1183 u32 *pdata = buf;
1158 for (; cnt >= 4; cnt -= 4) 1184 for (; cnt >= 4; cnt -= 4)
1159 *pdata++ = mci_readl(host, DATA); 1185 *pdata++ = mci_readl(host, DATA(host->data_offset));
1160 buf = pdata; 1186 buf = pdata;
1161 } 1187 }
1162 if (cnt) { 1188 if (cnt) {
1163 host->part_buf32 = mci_readl(host, DATA); 1189 host->part_buf32 = mci_readl(host, DATA(host->data_offset));
1164 dw_mci_pull_final_bytes(host, buf, cnt); 1190 dw_mci_pull_final_bytes(host, buf, cnt);
1165 } 1191 }
1166} 1192}
@@ -1173,7 +1199,8 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1173 buf += len; 1199 buf += len;
1174 cnt -= len; 1200 cnt -= len;
1175 if (!sg_next(host->sg) || host->part_buf_count == 8) { 1201 if (!sg_next(host->sg) || host->part_buf_count == 8) {
1176 mci_writew(host, DATA, host->part_buf); 1202 mci_writew(host, DATA(host->data_offset),
1203 host->part_buf);
1177 host->part_buf_count = 0; 1204 host->part_buf_count = 0;
1178 } 1205 }
1179 } 1206 }
@@ -1190,21 +1217,23 @@ static void dw_mci_push_data64(struct dw_mci *host, void *buf, int cnt)
1190 cnt -= len; 1217 cnt -= len;
1191 /* push data from aligned buffer into fifo */ 1218 /* push data from aligned buffer into fifo */
1192 for (i = 0; i < items; ++i) 1219 for (i = 0; i < items; ++i)
1193 mci_writeq(host, DATA, aligned_buf[i]); 1220 mci_writeq(host, DATA(host->data_offset),
1221 aligned_buf[i]);
1194 } 1222 }
1195 } else 1223 } else
1196#endif 1224#endif
1197 { 1225 {
1198 u64 *pdata = buf; 1226 u64 *pdata = buf;
1199 for (; cnt >= 8; cnt -= 8) 1227 for (; cnt >= 8; cnt -= 8)
1200 mci_writeq(host, DATA, *pdata++); 1228 mci_writeq(host, DATA(host->data_offset), *pdata++);
1201 buf = pdata; 1229 buf = pdata;
1202 } 1230 }
1203 /* put anything remaining in the part_buf */ 1231 /* put anything remaining in the part_buf */
1204 if (cnt) { 1232 if (cnt) {
1205 dw_mci_set_part_bytes(host, buf, cnt); 1233 dw_mci_set_part_bytes(host, buf, cnt);
1206 if (!sg_next(host->sg)) 1234 if (!sg_next(host->sg))
1207 mci_writeq(host, DATA, host->part_buf); 1235 mci_writeq(host, DATA(host->data_offset),
1236 host->part_buf);
1208 } 1237 }
1209} 1238}
1210 1239
@@ -1219,7 +1248,8 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1219 int items = len >> 3; 1248 int items = len >> 3;
1220 int i; 1249 int i;
1221 for (i = 0; i < items; ++i) 1250 for (i = 0; i < items; ++i)
1222 aligned_buf[i] = mci_readq(host, DATA); 1251 aligned_buf[i] = mci_readq(host,
1252 DATA(host->data_offset));
1223 /* memcpy from aligned buffer into output buffer */ 1253 /* memcpy from aligned buffer into output buffer */
1224 memcpy(buf, aligned_buf, len); 1254 memcpy(buf, aligned_buf, len);
1225 buf += len; 1255 buf += len;
@@ -1230,11 +1260,11 @@ static void dw_mci_pull_data64(struct dw_mci *host, void *buf, int cnt)
1230 { 1260 {
1231 u64 *pdata = buf; 1261 u64 *pdata = buf;
1232 for (; cnt >= 8; cnt -= 8) 1262 for (; cnt >= 8; cnt -= 8)
1233 *pdata++ = mci_readq(host, DATA); 1263 *pdata++ = mci_readq(host, DATA(host->data_offset));
1234 buf = pdata; 1264 buf = pdata;
1235 } 1265 }
1236 if (cnt) { 1266 if (cnt) {
1237 host->part_buf = mci_readq(host, DATA); 1267 host->part_buf = mci_readq(host, DATA(host->data_offset));
1238 dw_mci_pull_final_bytes(host, buf, cnt); 1268 dw_mci_pull_final_bytes(host, buf, cnt);
1239 } 1269 }
1240} 1270}
@@ -1406,6 +1436,7 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
1406 struct dw_mci *host = dev_id; 1436 struct dw_mci *host = dev_id;
1407 u32 status, pending; 1437 u32 status, pending;
1408 unsigned int pass_count = 0; 1438 unsigned int pass_count = 0;
1439 int i;
1409 1440
1410 do { 1441 do {
1411 status = mci_readl(host, RINTSTS); 1442 status = mci_readl(host, RINTSTS);
@@ -1477,6 +1508,15 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
1477 queue_work(dw_mci_card_workqueue, &host->card_work); 1508 queue_work(dw_mci_card_workqueue, &host->card_work);
1478 } 1509 }
1479 1510
1511 /* Handle SDIO Interrupts */
1512 for (i = 0; i < host->num_slots; i++) {
1513 struct dw_mci_slot *slot = host->slot[i];
1514 if (pending & SDMMC_INT_SDIO(i)) {
1515 mci_writel(host, RINTSTS, SDMMC_INT_SDIO(i));
1516 mmc_signal_sdio_irq(slot->mmc);
1517 }
1518 }
1519
1480 } while (pass_count++ < 5); 1520 } while (pass_count++ < 5);
1481 1521
1482#ifdef CONFIG_MMC_DW_IDMAC 1522#ifdef CONFIG_MMC_DW_IDMAC
@@ -1673,7 +1713,7 @@ static int __init dw_mci_init_slot(struct dw_mci *host, unsigned int id)
1673 1713
1674 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); 1714 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
1675 if (IS_ERR(host->vmmc)) { 1715 if (IS_ERR(host->vmmc)) {
1676 printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc)); 1716 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
1677 host->vmmc = NULL; 1717 host->vmmc = NULL;
1678 } else 1718 } else
1679 regulator_enable(host->vmmc); 1719 regulator_enable(host->vmmc);
@@ -1924,6 +1964,18 @@ static int dw_mci_probe(struct platform_device *pdev)
1924 } 1964 }
1925 1965
1926 /* 1966 /*
1967 * In 2.40a spec, Data offset is changed.
1968 * Need to check the version-id and set data-offset for DATA register.
1969 */
1970 host->verid = SDMMC_GET_VERID(mci_readl(host, VERID));
1971 dev_info(&pdev->dev, "Version ID is %04x\n", host->verid);
1972
1973 if (host->verid < DW_MMC_240A)
1974 host->data_offset = DATA_OFFSET;
1975 else
1976 host->data_offset = DATA_240A_OFFSET;
1977
1978 /*
1927 * Enable interrupts for command done, data over, data empty, card det, 1979 * Enable interrupts for command done, data over, data empty, card det,
1928 * receive ready and error such as transmit, receive timeout, crc error 1980 * receive ready and error such as transmit, receive timeout, crc error
1929 */ 1981 */
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 027d37735394..72c071f6e001 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -14,6 +14,8 @@
14#ifndef _DW_MMC_H_ 14#ifndef _DW_MMC_H_
15#define _DW_MMC_H_ 15#define _DW_MMC_H_
16 16
17#define DW_MMC_240A 0x240a
18
17#define SDMMC_CTRL 0x000 19#define SDMMC_CTRL 0x000
18#define SDMMC_PWREN 0x004 20#define SDMMC_PWREN 0x004
19#define SDMMC_CLKDIV 0x008 21#define SDMMC_CLKDIV 0x008
@@ -51,7 +53,14 @@
51#define SDMMC_IDINTEN 0x090 53#define SDMMC_IDINTEN 0x090
52#define SDMMC_DSCADDR 0x094 54#define SDMMC_DSCADDR 0x094
53#define SDMMC_BUFADDR 0x098 55#define SDMMC_BUFADDR 0x098
54#define SDMMC_DATA 0x100 56#define SDMMC_DATA(x) (x)
57
58/*
59 * Data offset is difference according to Version
60 * Lower than 2.40a : data register offest is 0x100
61 */
62#define DATA_OFFSET 0x100
63#define DATA_240A_OFFSET 0x200
55 64
56/* shift bit field */ 65/* shift bit field */
57#define _SBF(f, v) ((v) << (f)) 66#define _SBF(f, v) ((v) << (f))
@@ -82,7 +91,7 @@
82#define SDMMC_CTYPE_4BIT BIT(0) 91#define SDMMC_CTYPE_4BIT BIT(0)
83#define SDMMC_CTYPE_1BIT 0 92#define SDMMC_CTYPE_1BIT 0
84/* Interrupt status & mask register defines */ 93/* Interrupt status & mask register defines */
85#define SDMMC_INT_SDIO BIT(16) 94#define SDMMC_INT_SDIO(n) BIT(16 + (n))
86#define SDMMC_INT_EBE BIT(15) 95#define SDMMC_INT_EBE BIT(15)
87#define SDMMC_INT_ACD BIT(14) 96#define SDMMC_INT_ACD BIT(14)
88#define SDMMC_INT_SBE BIT(13) 97#define SDMMC_INT_SBE BIT(13)
@@ -130,6 +139,8 @@
130#define SDMMC_IDMAC_ENABLE BIT(7) 139#define SDMMC_IDMAC_ENABLE BIT(7)
131#define SDMMC_IDMAC_FB BIT(1) 140#define SDMMC_IDMAC_FB BIT(1)
132#define SDMMC_IDMAC_SWRESET BIT(0) 141#define SDMMC_IDMAC_SWRESET BIT(0)
142/* Version ID register define */
143#define SDMMC_GET_VERID(x) ((x) & 0xFFFF)
133 144
134/* Register access macros */ 145/* Register access macros */
135#define mci_readl(dev, reg) \ 146#define mci_readl(dev, reg) \
diff --git a/drivers/mmc/host/imxmmc.c b/drivers/mmc/host/imxmmc.c
index 881f7ba545ae..ea0f3cedef21 100644
--- a/drivers/mmc/host/imxmmc.c
+++ b/drivers/mmc/host/imxmmc.c
@@ -942,7 +942,7 @@ static int __init imxmci_probe(struct platform_device *pdev)
942 int ret = 0, irq; 942 int ret = 0, irq;
943 u16 rev_no; 943 u16 rev_no;
944 944
945 printk(KERN_INFO "i.MX mmc driver\n"); 945 pr_info("i.MX mmc driver\n");
946 946
947 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 947 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
948 irq = platform_get_irq(pdev, 0); 948 irq = platform_get_irq(pdev, 0);
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 7c1e16aaf17f..92946b84e9fa 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -27,6 +27,7 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/module.h>
30#include <linux/bio.h> 31#include <linux/bio.h>
31#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
32#include <linux/crc7.h> 33#include <linux/crc7.h>
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 7be8db0f9f7d..50b5f9926f64 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -466,7 +466,7 @@ static void mmci_get_next_data(struct mmci_host *host, struct mmc_data *data)
466 struct mmci_host_next *next = &host->next_data; 466 struct mmci_host_next *next = &host->next_data;
467 467
468 if (data->host_cookie && data->host_cookie != next->cookie) { 468 if (data->host_cookie && data->host_cookie != next->cookie) {
469 printk(KERN_WARNING "[%s] invalid cookie: data->host_cookie %d" 469 pr_warning("[%s] invalid cookie: data->host_cookie %d"
470 " host->next_data.cookie %d\n", 470 " host->next_data.cookie %d\n",
471 __func__, data->host_cookie, host->next_data.cookie); 471 __func__, data->host_cookie, host->next_data.cookie);
472 data->host_cookie = 0; 472 data->host_cookie = 0;
@@ -531,7 +531,7 @@ static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
531 if (chan) { 531 if (chan) {
532 if (err) 532 if (err)
533 dmaengine_terminate_all(chan); 533 dmaengine_terminate_all(chan);
534 if (err || data->host_cookie) 534 if (data->host_cookie)
535 dma_unmap_sg(mmc_dev(host->mmc), data->sg, 535 dma_unmap_sg(mmc_dev(host->mmc), data->sg,
536 data->sg_len, dir); 536 data->sg_len, dir);
537 mrq->data->host_cookie = 0; 537 mrq->data->host_cookie = 0;
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index a4c865a5286b..80d8eb143b48 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -213,7 +213,8 @@ msmsdcc_dma_exec_func(struct msm_dmov_cmd *cmd)
213 msmsdcc_writel(host, host->cmd_timeout, MMCIDATATIMER); 213 msmsdcc_writel(host, host->cmd_timeout, MMCIDATATIMER);
214 msmsdcc_writel(host, (unsigned int)host->curr.xfer_size, 214 msmsdcc_writel(host, (unsigned int)host->curr.xfer_size,
215 MMCIDATALENGTH); 215 MMCIDATALENGTH);
216 msmsdcc_writel(host, host->cmd_pio_irqmask, MMCIMASK1); 216 msmsdcc_writel(host, (msmsdcc_readl(host, MMCIMASK0) &
217 (~MCI_IRQ_PIO)) | host->cmd_pio_irqmask, MMCIMASK0);
217 msmsdcc_writel(host, host->cmd_datactrl, MMCIDATACTRL); 218 msmsdcc_writel(host, host->cmd_datactrl, MMCIDATACTRL);
218 219
219 if (host->cmd_cmd) { 220 if (host->cmd_cmd) {
@@ -388,7 +389,7 @@ static int msmsdcc_config_dma(struct msmsdcc_host *host, struct mmc_data *data)
388 n = dma_map_sg(mmc_dev(host->mmc), host->dma.sg, 389 n = dma_map_sg(mmc_dev(host->mmc), host->dma.sg,
389 host->dma.num_ents, host->dma.dir); 390 host->dma.num_ents, host->dma.dir);
390 if (n == 0) { 391 if (n == 0) {
391 printk(KERN_ERR "%s: Unable to map in all sg elements\n", 392 pr_err("%s: Unable to map in all sg elements\n",
392 mmc_hostname(host->mmc)); 393 mmc_hostname(host->mmc));
393 host->dma.sg = NULL; 394 host->dma.sg = NULL;
394 host->dma.num_ents = 0; 395 host->dma.num_ents = 0;
@@ -474,7 +475,7 @@ msmsdcc_start_command_deferred(struct msmsdcc_host *host,
474 *c |= MCI_CSPM_MCIABORT; 475 *c |= MCI_CSPM_MCIABORT;
475 476
476 if (host->curr.cmd != NULL) { 477 if (host->curr.cmd != NULL) {
477 printk(KERN_ERR "%s: Overlapping command requests\n", 478 pr_err("%s: Overlapping command requests\n",
478 mmc_hostname(host->mmc)); 479 mmc_hostname(host->mmc));
479 } 480 }
480 host->curr.cmd = cmd; 481 host->curr.cmd = cmd;
@@ -543,7 +544,9 @@ msmsdcc_start_data(struct msmsdcc_host *host, struct mmc_data *data,
543 544
544 msmsdcc_writel(host, host->curr.xfer_size, MMCIDATALENGTH); 545 msmsdcc_writel(host, host->curr.xfer_size, MMCIDATALENGTH);
545 546
546 msmsdcc_writel(host, pio_irqmask, MMCIMASK1); 547 msmsdcc_writel(host, (msmsdcc_readl(host, MMCIMASK0) &
548 (~MCI_IRQ_PIO)) | pio_irqmask, MMCIMASK0);
549
547 msmsdcc_writel(host, datactrl, MMCIDATACTRL); 550 msmsdcc_writel(host, datactrl, MMCIDATACTRL);
548 551
549 if (cmd) { 552 if (cmd) {
@@ -659,8 +662,13 @@ msmsdcc_pio_irq(int irq, void *dev_id)
659{ 662{
660 struct msmsdcc_host *host = dev_id; 663 struct msmsdcc_host *host = dev_id;
661 uint32_t status; 664 uint32_t status;
665 u32 mci_mask0;
662 666
663 status = msmsdcc_readl(host, MMCISTATUS); 667 status = msmsdcc_readl(host, MMCISTATUS);
668 mci_mask0 = msmsdcc_readl(host, MMCIMASK0);
669
670 if (((mci_mask0 & status) & MCI_IRQ_PIO) == 0)
671 return IRQ_NONE;
664 672
665 do { 673 do {
666 unsigned long flags; 674 unsigned long flags;
@@ -719,10 +727,12 @@ msmsdcc_pio_irq(int irq, void *dev_id)
719 } while (1); 727 } while (1);
720 728
721 if (status & MCI_RXACTIVE && host->curr.xfer_remain < MCI_FIFOSIZE) 729 if (status & MCI_RXACTIVE && host->curr.xfer_remain < MCI_FIFOSIZE)
722 msmsdcc_writel(host, MCI_RXDATAAVLBLMASK, MMCIMASK1); 730 msmsdcc_writel(host, (mci_mask0 & (~MCI_IRQ_PIO)) |
731 MCI_RXDATAAVLBLMASK, MMCIMASK0);
723 732
724 if (!host->curr.xfer_remain) 733 if (!host->curr.xfer_remain)
725 msmsdcc_writel(host, 0, MMCIMASK1); 734 msmsdcc_writel(host, (mci_mask0 & (~MCI_IRQ_PIO)) | 0,
735 MMCIMASK0);
726 736
727 return IRQ_HANDLED; 737 return IRQ_HANDLED;
728} 738}
@@ -854,6 +864,8 @@ msmsdcc_irq(int irq, void *dev_id)
854 do { 864 do {
855 status = msmsdcc_readl(host, MMCISTATUS); 865 status = msmsdcc_readl(host, MMCISTATUS);
856 status &= msmsdcc_readl(host, MMCIMASK0); 866 status &= msmsdcc_readl(host, MMCIMASK0);
867 if ((status & (~MCI_IRQ_PIO)) == 0)
868 break;
857 msmsdcc_writel(host, status, MMCICLEAR); 869 msmsdcc_writel(host, status, MMCICLEAR);
858 870
859 if (status & MCI_SDIOINTR) 871 if (status & MCI_SDIOINTR)
@@ -939,7 +951,7 @@ static void msmsdcc_setup_gpio(struct msmsdcc_host *host, bool enable)
939 struct msm_mmc_gpio_data *curr; 951 struct msm_mmc_gpio_data *curr;
940 int i, rc = 0; 952 int i, rc = 0;
941 953
942 if (!host->plat->gpio_data && host->gpio_config_status == enable) 954 if (!host->plat->gpio_data || host->gpio_config_status == enable)
943 return; 955 return;
944 956
945 curr = host->plat->gpio_data; 957 curr = host->plat->gpio_data;
@@ -1052,10 +1064,19 @@ static void msmsdcc_enable_sdio_irq(struct mmc_host *mmc, int enable)
1052 spin_unlock_irqrestore(&host->lock, flags); 1064 spin_unlock_irqrestore(&host->lock, flags);
1053} 1065}
1054 1066
1067static void msmsdcc_init_card(struct mmc_host *mmc, struct mmc_card *card)
1068{
1069 struct msmsdcc_host *host = mmc_priv(mmc);
1070
1071 if (host->plat->init_card)
1072 host->plat->init_card(card);
1073}
1074
1055static const struct mmc_host_ops msmsdcc_ops = { 1075static const struct mmc_host_ops msmsdcc_ops = {
1056 .request = msmsdcc_request, 1076 .request = msmsdcc_request,
1057 .set_ios = msmsdcc_set_ios, 1077 .set_ios = msmsdcc_set_ios,
1058 .enable_sdio_irq = msmsdcc_enable_sdio_irq, 1078 .enable_sdio_irq = msmsdcc_enable_sdio_irq,
1079 .init_card = msmsdcc_init_card,
1059}; 1080};
1060 1081
1061static void 1082static void
@@ -1092,7 +1113,7 @@ msmsdcc_platform_status_irq(int irq, void *dev_id)
1092{ 1113{
1093 struct msmsdcc_host *host = dev_id; 1114 struct msmsdcc_host *host = dev_id;
1094 1115
1095 printk(KERN_DEBUG "%s: %d\n", __func__, irq); 1116 pr_debug("%s: %d\n", __func__, irq);
1096 msmsdcc_check_status((unsigned long) host); 1117 msmsdcc_check_status((unsigned long) host);
1097 return IRQ_HANDLED; 1118 return IRQ_HANDLED;
1098} 1119}
@@ -1102,7 +1123,7 @@ msmsdcc_status_notify_cb(int card_present, void *dev_id)
1102{ 1123{
1103 struct msmsdcc_host *host = dev_id; 1124 struct msmsdcc_host *host = dev_id;
1104 1125
1105 printk(KERN_DEBUG "%s: card_present %d\n", mmc_hostname(host->mmc), 1126 pr_debug("%s: card_present %d\n", mmc_hostname(host->mmc),
1106 card_present); 1127 card_present);
1107 msmsdcc_check_status((unsigned long) host); 1128 msmsdcc_check_status((unsigned long) host);
1108} 1129}
@@ -1150,7 +1171,6 @@ msmsdcc_probe(struct platform_device *pdev)
1150 struct msmsdcc_host *host; 1171 struct msmsdcc_host *host;
1151 struct mmc_host *mmc; 1172 struct mmc_host *mmc;
1152 struct resource *cmd_irqres = NULL; 1173 struct resource *cmd_irqres = NULL;
1153 struct resource *pio_irqres = NULL;
1154 struct resource *stat_irqres = NULL; 1174 struct resource *stat_irqres = NULL;
1155 struct resource *memres = NULL; 1175 struct resource *memres = NULL;
1156 struct resource *dmares = NULL; 1176 struct resource *dmares = NULL;
@@ -1175,12 +1195,10 @@ msmsdcc_probe(struct platform_device *pdev)
1175 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1195 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1176 cmd_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, 1196 cmd_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1177 "cmd_irq"); 1197 "cmd_irq");
1178 pio_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1179 "pio_irq");
1180 stat_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, 1198 stat_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
1181 "status_irq"); 1199 "status_irq");
1182 1200
1183 if (!cmd_irqres || !pio_irqres || !memres) { 1201 if (!cmd_irqres || !memres) {
1184 pr_err("%s: Invalid resource\n", __func__); 1202 pr_err("%s: Invalid resource\n", __func__);
1185 return -ENXIO; 1203 return -ENXIO;
1186 } 1204 }
@@ -1200,17 +1218,20 @@ msmsdcc_probe(struct platform_device *pdev)
1200 host->plat = plat; 1218 host->plat = plat;
1201 host->mmc = mmc; 1219 host->mmc = mmc;
1202 host->curr.cmd = NULL; 1220 host->curr.cmd = NULL;
1221 init_timer(&host->busclk_timer);
1222 host->busclk_timer.data = (unsigned long) host;
1223 host->busclk_timer.function = msmsdcc_busclk_expired;
1224
1203 1225
1204 host->cmdpoll = 1; 1226 host->cmdpoll = 1;
1205 1227
1206 host->base = ioremap(memres->start, PAGE_SIZE); 1228 host->base = ioremap(memres->start, PAGE_SIZE);
1207 if (!host->base) { 1229 if (!host->base) {
1208 ret = -ENOMEM; 1230 ret = -ENOMEM;
1209 goto out; 1231 goto host_free;
1210 } 1232 }
1211 1233
1212 host->cmd_irqres = cmd_irqres; 1234 host->cmd_irqres = cmd_irqres;
1213 host->pio_irqres = pio_irqres;
1214 host->memres = memres; 1235 host->memres = memres;
1215 host->dmares = dmares; 1236 host->dmares = dmares;
1216 spin_lock_init(&host->lock); 1237 spin_lock_init(&host->lock);
@@ -1221,13 +1242,19 @@ msmsdcc_probe(struct platform_device *pdev)
1221 /* 1242 /*
1222 * Setup DMA 1243 * Setup DMA
1223 */ 1244 */
1224 msmsdcc_init_dma(host); 1245 if (host->dmares) {
1246 ret = msmsdcc_init_dma(host);
1247 if (ret)
1248 goto ioremap_free;
1249 } else {
1250 host->dma.channel = -1;
1251 }
1225 1252
1226 /* Get our clocks */ 1253 /* Get our clocks */
1227 host->pclk = clk_get(&pdev->dev, "sdc_pclk"); 1254 host->pclk = clk_get(&pdev->dev, "sdc_pclk");
1228 if (IS_ERR(host->pclk)) { 1255 if (IS_ERR(host->pclk)) {
1229 ret = PTR_ERR(host->pclk); 1256 ret = PTR_ERR(host->pclk);
1230 goto host_free; 1257 goto dma_free;
1231 } 1258 }
1232 1259
1233 host->clk = clk_get(&pdev->dev, "sdc_clk"); 1260 host->clk = clk_get(&pdev->dev, "sdc_clk");
@@ -1236,17 +1263,17 @@ msmsdcc_probe(struct platform_device *pdev)
1236 goto pclk_put; 1263 goto pclk_put;
1237 } 1264 }
1238 1265
1239 /* Enable clocks */
1240 ret = msmsdcc_enable_clocks(host);
1241 if (ret)
1242 goto clk_put;
1243
1244 ret = clk_set_rate(host->clk, msmsdcc_fmin); 1266 ret = clk_set_rate(host->clk, msmsdcc_fmin);
1245 if (ret) { 1267 if (ret) {
1246 pr_err("%s: Clock rate set failed (%d)\n", __func__, ret); 1268 pr_err("%s: Clock rate set failed (%d)\n", __func__, ret);
1247 goto clk_disable; 1269 goto clk_put;
1248 } 1270 }
1249 1271
1272 /* Enable clocks */
1273 ret = msmsdcc_enable_clocks(host);
1274 if (ret)
1275 goto clk_put;
1276
1250 host->pclk_rate = clk_get_rate(host->pclk); 1277 host->pclk_rate = clk_get_rate(host->pclk);
1251 host->clk_rate = clk_get_rate(host->clk); 1278 host->clk_rate = clk_get_rate(host->clk);
1252 1279
@@ -1316,16 +1343,12 @@ msmsdcc_probe(struct platform_device *pdev)
1316 host->eject = !host->oldstat; 1343 host->eject = !host->oldstat;
1317 } 1344 }
1318 1345
1319 init_timer(&host->busclk_timer);
1320 host->busclk_timer.data = (unsigned long) host;
1321 host->busclk_timer.function = msmsdcc_busclk_expired;
1322
1323 ret = request_irq(cmd_irqres->start, msmsdcc_irq, IRQF_SHARED, 1346 ret = request_irq(cmd_irqres->start, msmsdcc_irq, IRQF_SHARED,
1324 DRIVER_NAME " (cmd)", host); 1347 DRIVER_NAME " (cmd)", host);
1325 if (ret) 1348 if (ret)
1326 goto stat_irq_free; 1349 goto stat_irq_free;
1327 1350
1328 ret = request_irq(pio_irqres->start, msmsdcc_pio_irq, IRQF_SHARED, 1351 ret = request_irq(cmd_irqres->start, msmsdcc_pio_irq, IRQF_SHARED,
1329 DRIVER_NAME " (pio)", host); 1352 DRIVER_NAME " (pio)", host);
1330 if (ret) 1353 if (ret)
1331 goto cmd_irq_free; 1354 goto cmd_irq_free;
@@ -1368,6 +1391,13 @@ msmsdcc_probe(struct platform_device *pdev)
1368 clk_put(host->clk); 1391 clk_put(host->clk);
1369 pclk_put: 1392 pclk_put:
1370 clk_put(host->pclk); 1393 clk_put(host->pclk);
1394dma_free:
1395 if (host->dmares)
1396 dma_free_coherent(NULL, sizeof(struct msmsdcc_nc_dmadata),
1397 host->dma.nc, host->dma.nc_busaddr);
1398ioremap_free:
1399 tasklet_kill(&host->dma_tlet);
1400 iounmap(host->base);
1371 host_free: 1401 host_free:
1372 mmc_free_host(mmc); 1402 mmc_free_host(mmc);
1373 out: 1403 out:
diff --git a/drivers/mmc/host/msm_sdcc.h b/drivers/mmc/host/msm_sdcc.h
index 42d7bbc977c5..402028d16b86 100644
--- a/drivers/mmc/host/msm_sdcc.h
+++ b/drivers/mmc/host/msm_sdcc.h
@@ -140,6 +140,11 @@
140 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \ 140 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
141 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK|MCI_PROGDONEMASK) 141 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATAENDMASK|MCI_PROGDONEMASK)
142 142
143#define MCI_IRQ_PIO \
144 (MCI_RXDATAAVLBLMASK | MCI_TXDATAAVLBLMASK | MCI_RXFIFOEMPTYMASK | \
145 MCI_TXFIFOEMPTYMASK | MCI_RXFIFOFULLMASK | MCI_TXFIFOFULLMASK | \
146 MCI_RXFIFOHALFFULLMASK | MCI_TXFIFOHALFEMPTYMASK | \
147 MCI_RXACTIVEMASK | MCI_TXACTIVEMASK)
143/* 148/*
144 * The size of the FIFO in bytes. 149 * The size of the FIFO in bytes.
145 */ 150 */
@@ -202,7 +207,6 @@ struct msmsdcc_stats {
202 207
203struct msmsdcc_host { 208struct msmsdcc_host {
204 struct resource *cmd_irqres; 209 struct resource *cmd_irqres;
205 struct resource *pio_irqres;
206 struct resource *memres; 210 struct resource *memres;
207 struct resource *dmares; 211 struct resource *dmares;
208 void __iomem *base; 212 void __iomem *base;
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index a5bf60e01af4..211a4959c293 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -117,7 +117,7 @@ static int mvsd_setup_data(struct mvsd_host *host, struct mmc_data *data)
117 host->pio_size = data->blocks * data->blksz; 117 host->pio_size = data->blocks * data->blksz;
118 host->pio_ptr = sg_virt(data->sg); 118 host->pio_ptr = sg_virt(data->sg);
119 if (!nodma) 119 if (!nodma)
120 printk(KERN_DEBUG "%s: fallback to PIO for data " 120 pr_debug("%s: fallback to PIO for data "
121 "at 0x%p size %d\n", 121 "at 0x%p size %d\n",
122 mmc_hostname(host->mmc), 122 mmc_hostname(host->mmc),
123 host->pio_ptr, host->pio_size); 123 host->pio_ptr, host->pio_size);
@@ -471,7 +471,7 @@ static irqreturn_t mvsd_irq(int irq, void *dev)
471 if (mrq->data) 471 if (mrq->data)
472 err_status = mvsd_finish_data(host, mrq->data, err_status); 472 err_status = mvsd_finish_data(host, mrq->data, err_status);
473 if (err_status) { 473 if (err_status) {
474 printk(KERN_ERR "%s: unhandled error status %#04x\n", 474 pr_err("%s: unhandled error status %#04x\n",
475 mmc_hostname(host->mmc), err_status); 475 mmc_hostname(host->mmc), err_status);
476 cmd->error = -ENOMSG; 476 cmd->error = -ENOMSG;
477 } 477 }
@@ -489,7 +489,7 @@ static irqreturn_t mvsd_irq(int irq, void *dev)
489 if (irq_handled) 489 if (irq_handled)
490 return IRQ_HANDLED; 490 return IRQ_HANDLED;
491 491
492 printk(KERN_ERR "%s: unhandled interrupt status=0x%04x en=0x%04x " 492 pr_err("%s: unhandled interrupt status=0x%04x en=0x%04x "
493 "pio=%d\n", mmc_hostname(host->mmc), intr_status, 493 "pio=%d\n", mmc_hostname(host->mmc), intr_status,
494 host->intr_en, host->pio_size); 494 host->intr_en, host->pio_size);
495 return IRQ_NONE; 495 return IRQ_NONE;
@@ -505,9 +505,9 @@ static void mvsd_timeout_timer(unsigned long data)
505 spin_lock_irqsave(&host->lock, flags); 505 spin_lock_irqsave(&host->lock, flags);
506 mrq = host->mrq; 506 mrq = host->mrq;
507 if (mrq) { 507 if (mrq) {
508 printk(KERN_ERR "%s: Timeout waiting for hardware interrupt.\n", 508 pr_err("%s: Timeout waiting for hardware interrupt.\n",
509 mmc_hostname(host->mmc)); 509 mmc_hostname(host->mmc));
510 printk(KERN_ERR "%s: hw_state=0x%04x, intr_status=0x%04x " 510 pr_err("%s: hw_state=0x%04x, intr_status=0x%04x "
511 "intr_en=0x%04x\n", mmc_hostname(host->mmc), 511 "intr_en=0x%04x\n", mmc_hostname(host->mmc),
512 mvsd_read(MVSD_HW_STATE), 512 mvsd_read(MVSD_HW_STATE),
513 mvsd_read(MVSD_NOR_INTR_STATUS), 513 mvsd_read(MVSD_NOR_INTR_STATUS),
@@ -762,7 +762,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
762 762
763 ret = request_irq(irq, mvsd_irq, 0, DRIVER_NAME, host); 763 ret = request_irq(irq, mvsd_irq, 0, DRIVER_NAME, host);
764 if (ret) { 764 if (ret) {
765 printk(KERN_ERR "%s: cannot assign irq %d\n", DRIVER_NAME, irq); 765 pr_err("%s: cannot assign irq %d\n", DRIVER_NAME, irq);
766 goto out; 766 goto out;
767 } else 767 } else
768 host->irq = irq; 768 host->irq = irq;
@@ -802,7 +802,7 @@ static int __init mvsd_probe(struct platform_device *pdev)
802 if (ret) 802 if (ret)
803 goto out; 803 goto out;
804 804
805 printk(KERN_NOTICE "%s: %s driver initialized, ", 805 pr_notice("%s: %s driver initialized, ",
806 mmc_hostname(mmc), DRIVER_NAME); 806 mmc_hostname(mmc), DRIVER_NAME);
807 if (host->gpio_card_detect) 807 if (host->gpio_card_detect)
808 printk("using GPIO %d for card detection\n", 808 printk("using GPIO %d for card detection\n",
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index 14aa213b00da..f48743de4673 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -842,7 +842,7 @@ static int mxcmci_probe(struct platform_device *pdev)
842 int ret = 0, irq; 842 int ret = 0, irq;
843 dma_cap_mask_t mask; 843 dma_cap_mask_t mask;
844 844
845 printk(KERN_INFO "i.MX SDHC driver\n"); 845 pr_info("i.MX SDHC driver\n");
846 846
847 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 847 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
848 irq = platform_get_irq(pdev, 0); 848 irq = platform_get_irq(pdev, 0);
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index d513d47364d0..99b449d26a4d 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -37,6 +37,7 @@
37#include <linux/mmc/sdio.h> 37#include <linux/mmc/sdio.h>
38#include <linux/gpio.h> 38#include <linux/gpio.h>
39#include <linux/regulator/consumer.h> 39#include <linux/regulator/consumer.h>
40#include <linux/module.h>
40 41
41#include <mach/mxs.h> 42#include <mach/mxs.h>
42#include <mach/common.h> 43#include <mach/common.h>
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 21e4a799df48..e8ff12396680 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -450,15 +450,14 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
450 * framework is fixed, we need a workaround like this 450 * framework is fixed, we need a workaround like this
451 * (which is safe for MMC, but not in general). 451 * (which is safe for MMC, but not in general).
452 */ 452 */
453 if (regulator_is_enabled(host->vcc) > 0) { 453 if (regulator_is_enabled(host->vcc) > 0 ||
454 regulator_enable(host->vcc); 454 (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) {
455 regulator_disable(host->vcc); 455 int vdd = ffs(mmc_slot(host).ocr_mask) - 1;
456 } 456
457 if (host->vcc_aux) { 457 mmc_slot(host).set_power(host->dev, host->slot_id,
458 if (regulator_is_enabled(reg) > 0) { 458 1, vdd);
459 regulator_enable(reg); 459 mmc_slot(host).set_power(host->dev, host->slot_id,
460 regulator_disable(reg); 460 0, 0);
461 }
462 } 461 }
463 } 462 }
464 463
@@ -1264,14 +1263,14 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1264 host->reqs_blocked = 0; 1263 host->reqs_blocked = 0;
1265 if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) { 1264 if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) {
1266 if (host->protect_card) { 1265 if (host->protect_card) {
1267 printk(KERN_INFO "%s: cover is closed, " 1266 pr_info("%s: cover is closed, "
1268 "card is now accessible\n", 1267 "card is now accessible\n",
1269 mmc_hostname(host->mmc)); 1268 mmc_hostname(host->mmc));
1270 host->protect_card = 0; 1269 host->protect_card = 0;
1271 } 1270 }
1272 } else { 1271 } else {
1273 if (!host->protect_card) { 1272 if (!host->protect_card) {
1274 printk(KERN_INFO "%s: cover is open, " 1273 pr_info"%s: cover is open, "
1275 "card is now inaccessible\n", 1274 "card is now inaccessible\n",
1276 mmc_hostname(host->mmc)); 1275 mmc_hostname(host->mmc));
1277 host->protect_card = 1; 1276 host->protect_card = 1;
@@ -1422,7 +1421,7 @@ static int omap_hsmmc_pre_dma_transfer(struct omap_hsmmc_host *host,
1422 1421
1423 if (!next && data->host_cookie && 1422 if (!next && data->host_cookie &&
1424 data->host_cookie != host->next_data.cookie) { 1423 data->host_cookie != host->next_data.cookie) {
1425 printk(KERN_WARNING "[%s] invalid cookie: data->host_cookie %d" 1424 pr_warning("[%s] invalid cookie: data->host_cookie %d"
1426 " host->next_data.cookie %d\n", 1425 " host->next_data.cookie %d\n",
1427 __func__, data->host_cookie, host->next_data.cookie); 1426 __func__, data->host_cookie, host->next_data.cookie);
1428 data->host_cookie = 0; 1427 data->host_cookie = 0;
@@ -1943,6 +1942,10 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
1943 omap_hsmmc_context_save(host); 1942 omap_hsmmc_context_save(host);
1944 1943
1945 mmc->caps |= MMC_CAP_DISABLE; 1944 mmc->caps |= MMC_CAP_DISABLE;
1945 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
1946 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
1947 mmc->caps2 |= MMC_CAP2_NO_MULTI_READ;
1948 }
1946 1949
1947 pm_runtime_enable(host->dev); 1950 pm_runtime_enable(host->dev);
1948 pm_runtime_get_sync(host->dev); 1951 pm_runtime_get_sync(host->dev);
@@ -2015,7 +2018,7 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
2015 } 2018 }
2016 2019
2017 /* Request IRQ for MMC operations */ 2020 /* Request IRQ for MMC operations */
2018 ret = request_irq(host->irq, omap_hsmmc_irq, IRQF_DISABLED, 2021 ret = request_irq(host->irq, omap_hsmmc_irq, 0,
2019 mmc_hostname(mmc), host); 2022 mmc_hostname(mmc), host);
2020 if (ret) { 2023 if (ret) {
2021 dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n"); 2024 dev_dbg(mmc_dev(host->mmc), "Unable to grab HSMMC IRQ\n");
@@ -2043,8 +2046,7 @@ static int __init omap_hsmmc_probe(struct platform_device *pdev)
2043 if ((mmc_slot(host).card_detect_irq)) { 2046 if ((mmc_slot(host).card_detect_irq)) {
2044 ret = request_irq(mmc_slot(host).card_detect_irq, 2047 ret = request_irq(mmc_slot(host).card_detect_irq,
2045 omap_hsmmc_cd_handler, 2048 omap_hsmmc_cd_handler,
2046 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING 2049 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
2047 | IRQF_DISABLED,
2048 mmc_hostname(mmc), host); 2050 mmc_hostname(mmc), host);
2049 if (ret) { 2051 if (ret) {
2050 dev_dbg(mmc_dev(host->mmc), 2052 dev_dbg(mmc_dev(host->mmc),
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index 7257738fd7da..fc4356e00d46 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -558,7 +558,7 @@ static void pxamci_dma_irq(int dma, void *devid)
558 if (dcsr & DCSR_ENDINTR) { 558 if (dcsr & DCSR_ENDINTR) {
559 writel(BUF_PART_FULL, host->base + MMC_PRTBUF); 559 writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
560 } else { 560 } else {
561 printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n", 561 pr_err("%s: DMA error on channel %d (DCSR=%#x)\n",
562 mmc_hostname(host->mmc), dma, dcsr); 562 mmc_hostname(host->mmc), dma, dcsr);
563 host->data->error = -EIO; 563 host->data->error = -EIO;
564 pxamci_data_done(host, 0); 564 pxamci_data_done(host, 0);
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index a04f87d7ee3d..d2856b6b2a62 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -247,7 +247,7 @@ static void s3cmci_check_sdio_irq(struct s3cmci_host *host)
247{ 247{
248 if (host->sdio_irqen) { 248 if (host->sdio_irqen) {
249 if (gpio_get_value(S3C2410_GPE(8)) == 0) { 249 if (gpio_get_value(S3C2410_GPE(8)) == 0) {
250 printk(KERN_DEBUG "%s: signalling irq\n", __func__); 250 pr_debug("%s: signalling irq\n", __func__);
251 mmc_signal_sdio_irq(host->mmc); 251 mmc_signal_sdio_irq(host->mmc);
252 } 252 }
253 } 253 }
@@ -344,7 +344,7 @@ static void s3cmci_disable_irq(struct s3cmci_host *host, bool transfer)
344 344
345 local_irq_save(flags); 345 local_irq_save(flags);
346 346
347 //printk(KERN_DEBUG "%s: transfer %d\n", __func__, transfer); 347 /* pr_debug("%s: transfer %d\n", __func__, transfer); */
348 348
349 host->irq_disabled = transfer; 349 host->irq_disabled = transfer;
350 350
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 4dc0028086a3..ae57769ba50d 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -32,6 +32,15 @@
32/* VENDOR SPEC register */ 32/* VENDOR SPEC register */
33#define SDHCI_VENDOR_SPEC 0xC0 33#define SDHCI_VENDOR_SPEC 0xC0
34#define SDHCI_VENDOR_SPEC_SDIO_QUIRK 0x00000002 34#define SDHCI_VENDOR_SPEC_SDIO_QUIRK 0x00000002
35#define SDHCI_MIX_CTRL 0x48
36
37/*
38 * There is an INT DMA ERR mis-match between eSDHC and STD SDHC SPEC:
39 * Bit25 is used in STD SPEC, and is reserved in fsl eSDHC design,
40 * but bit28 is used as the INT DMA ERR in fsl eSDHC design.
41 * Define this macro DMA error INT for fsl eSDHC
42 */
43#define SDHCI_INT_VENDOR_SPEC_DMA_ERR 0x10000000
35 44
36/* 45/*
37 * The CMDTYPE of the CMD register (offset 0xE) should be set to 46 * The CMDTYPE of the CMD register (offset 0xE) should be set to
@@ -51,6 +60,7 @@ enum imx_esdhc_type {
51 IMX35_ESDHC, 60 IMX35_ESDHC,
52 IMX51_ESDHC, 61 IMX51_ESDHC,
53 IMX53_ESDHC, 62 IMX53_ESDHC,
63 IMX6Q_USDHC,
54}; 64};
55 65
56struct pltfm_imx_data { 66struct pltfm_imx_data {
@@ -74,6 +84,9 @@ static struct platform_device_id imx_esdhc_devtype[] = {
74 .name = "sdhci-esdhc-imx53", 84 .name = "sdhci-esdhc-imx53",
75 .driver_data = IMX53_ESDHC, 85 .driver_data = IMX53_ESDHC,
76 }, { 86 }, {
87 .name = "sdhci-usdhc-imx6q",
88 .driver_data = IMX6Q_USDHC,
89 }, {
77 /* sentinel */ 90 /* sentinel */
78 } 91 }
79}; 92};
@@ -84,6 +97,7 @@ static const struct of_device_id imx_esdhc_dt_ids[] = {
84 { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], }, 97 { .compatible = "fsl,imx35-esdhc", .data = &imx_esdhc_devtype[IMX35_ESDHC], },
85 { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], }, 98 { .compatible = "fsl,imx51-esdhc", .data = &imx_esdhc_devtype[IMX51_ESDHC], },
86 { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], }, 99 { .compatible = "fsl,imx53-esdhc", .data = &imx_esdhc_devtype[IMX53_ESDHC], },
100 { .compatible = "fsl,imx6q-usdhc", .data = &imx_esdhc_devtype[IMX6Q_USDHC], },
87 { /* sentinel */ } 101 { /* sentinel */ }
88}; 102};
89MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids); 103MODULE_DEVICE_TABLE(of, imx_esdhc_dt_ids);
@@ -108,6 +122,11 @@ static inline int is_imx53_esdhc(struct pltfm_imx_data *data)
108 return data->devtype == IMX53_ESDHC; 122 return data->devtype == IMX53_ESDHC;
109} 123}
110 124
125static inline int is_imx6q_usdhc(struct pltfm_imx_data *data)
126{
127 return data->devtype == IMX6Q_USDHC;
128}
129
111static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg) 130static inline void esdhc_clrset_le(struct sdhci_host *host, u32 mask, u32 val, int reg)
112{ 131{
113 void __iomem *base = host->ioaddr + (reg & ~0x3); 132 void __iomem *base = host->ioaddr + (reg & ~0x3);
@@ -135,6 +154,27 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
135 val |= SDHCI_CARD_PRESENT; 154 val |= SDHCI_CARD_PRESENT;
136 } 155 }
137 156
157 if (unlikely(reg == SDHCI_CAPABILITIES)) {
158 /* In FSL esdhc IC module, only bit20 is used to indicate the
159 * ADMA2 capability of esdhc, but this bit is messed up on
160 * some SOCs (e.g. on MX25, MX35 this bit is set, but they
161 * don't actually support ADMA2). So set the BROKEN_ADMA
162 * uirk on MX25/35 platforms.
163 */
164
165 if (val & SDHCI_CAN_DO_ADMA1) {
166 val &= ~SDHCI_CAN_DO_ADMA1;
167 val |= SDHCI_CAN_DO_ADMA2;
168 }
169 }
170
171 if (unlikely(reg == SDHCI_INT_STATUS)) {
172 if (val & SDHCI_INT_VENDOR_SPEC_DMA_ERR) {
173 val &= ~SDHCI_INT_VENDOR_SPEC_DMA_ERR;
174 val |= SDHCI_INT_ADMA_ERROR;
175 }
176 }
177
138 return val; 178 return val;
139} 179}
140 180
@@ -179,13 +219,28 @@ static void esdhc_writel_le(struct sdhci_host *host, u32 val, int reg)
179 writel(v, host->ioaddr + SDHCI_VENDOR_SPEC); 219 writel(v, host->ioaddr + SDHCI_VENDOR_SPEC);
180 } 220 }
181 221
222 if (unlikely(reg == SDHCI_INT_ENABLE || reg == SDHCI_SIGNAL_ENABLE)) {
223 if (val & SDHCI_INT_ADMA_ERROR) {
224 val &= ~SDHCI_INT_ADMA_ERROR;
225 val |= SDHCI_INT_VENDOR_SPEC_DMA_ERR;
226 }
227 }
228
182 writel(val, host->ioaddr + reg); 229 writel(val, host->ioaddr + reg);
183} 230}
184 231
185static u16 esdhc_readw_le(struct sdhci_host *host, int reg) 232static u16 esdhc_readw_le(struct sdhci_host *host, int reg)
186{ 233{
187 if (unlikely(reg == SDHCI_HOST_VERSION)) 234 if (unlikely(reg == SDHCI_HOST_VERSION)) {
188 reg ^= 2; 235 u16 val = readw(host->ioaddr + (reg ^ 2));
236 /*
237 * uSDHC supports SDHCI v3.0, but it's encoded as value
238 * 0x3 in host controller version register, which violates
239 * SDHCI_SPEC_300 definition. Work it around here.
240 */
241 if ((val & SDHCI_SPEC_VER_MASK) == 3)
242 return --val;
243 }
189 244
190 return readw(host->ioaddr + reg); 245 return readw(host->ioaddr + reg);
191} 246}
@@ -216,8 +271,17 @@ static void esdhc_writew_le(struct sdhci_host *host, u16 val, int reg)
216 if ((host->cmd->opcode == MMC_STOP_TRANSMISSION) 271 if ((host->cmd->opcode == MMC_STOP_TRANSMISSION)
217 && (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT)) 272 && (imx_data->flags & ESDHC_FLAG_MULTIBLK_NO_INT))
218 val |= SDHCI_CMD_ABORTCMD; 273 val |= SDHCI_CMD_ABORTCMD;
219 writel(val << 16 | imx_data->scratchpad, 274
220 host->ioaddr + SDHCI_TRANSFER_MODE); 275 if (is_imx6q_usdhc(imx_data)) {
276 u32 m = readl(host->ioaddr + SDHCI_MIX_CTRL);
277 m = imx_data->scratchpad | (m & 0xffff0000);
278 writel(m, host->ioaddr + SDHCI_MIX_CTRL);
279 writel(val << 16,
280 host->ioaddr + SDHCI_TRANSFER_MODE);
281 } else {
282 writel(val << 16 | imx_data->scratchpad,
283 host->ioaddr + SDHCI_TRANSFER_MODE);
284 }
221 return; 285 return;
222 case SDHCI_BLOCK_SIZE: 286 case SDHCI_BLOCK_SIZE:
223 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0); 287 val &= ~SDHCI_MAKE_BLKSZ(0x7, 0);
@@ -311,9 +375,10 @@ static struct sdhci_ops sdhci_esdhc_ops = {
311}; 375};
312 376
313static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = { 377static struct sdhci_pltfm_data sdhci_esdhc_imx_pdata = {
314 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_ADMA 378 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_NO_HISPD_BIT
379 | SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC
380 | SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC
315 | SDHCI_QUIRK_BROKEN_CARD_DETECTION, 381 | SDHCI_QUIRK_BROKEN_CARD_DETECTION,
316 /* ADMA has issues. Might be fixable */
317 .ops = &sdhci_esdhc_ops, 382 .ops = &sdhci_esdhc_ops,
318}; 383};
319 384
@@ -405,7 +470,8 @@ static int __devinit sdhci_esdhc_imx_probe(struct platform_device *pdev)
405 470
406 if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data)) 471 if (is_imx25_esdhc(imx_data) || is_imx35_esdhc(imx_data))
407 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */ 472 /* Fix errata ENGcm07207 present on i.MX25 and i.MX35 */
408 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK; 473 host->quirks |= SDHCI_QUIRK_NO_MULTIBLOCK
474 | SDHCI_QUIRK_BROKEN_ADMA;
409 475
410 if (is_imx53_esdhc(imx_data)) 476 if (is_imx53_esdhc(imx_data))
411 imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT; 477 imx_data->flags |= ESDHC_FLAG_MULTIBLK_NO_INT;
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index fe604df65011..59e9d003e589 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Freescale eSDHC controller driver. 2 * Freescale eSDHC controller driver.
3 * 3 *
4 * Copyright (c) 2007 Freescale Semiconductor, Inc. 4 * Copyright (c) 2007, 2010 Freescale Semiconductor, Inc.
5 * Copyright (c) 2009 MontaVista Software, Inc. 5 * Copyright (c) 2009 MontaVista Software, Inc.
6 * 6 *
7 * Authors: Xiaobo Xie <X.Xie@freescale.com> 7 * Authors: Xiaobo Xie <X.Xie@freescale.com>
@@ -15,6 +15,7 @@
15 15
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/module.h>
18#include <linux/mmc/host.h> 19#include <linux/mmc/host.h>
19#include "sdhci-pltfm.h" 20#include "sdhci-pltfm.h"
20#include "sdhci-esdhc.h" 21#include "sdhci-esdhc.h"
@@ -22,11 +23,21 @@
22static u16 esdhc_readw(struct sdhci_host *host, int reg) 23static u16 esdhc_readw(struct sdhci_host *host, int reg)
23{ 24{
24 u16 ret; 25 u16 ret;
26 int base = reg & ~0x3;
27 int shift = (reg & 0x2) * 8;
25 28
26 if (unlikely(reg == SDHCI_HOST_VERSION)) 29 if (unlikely(reg == SDHCI_HOST_VERSION))
27 ret = in_be16(host->ioaddr + reg); 30 ret = in_be32(host->ioaddr + base) & 0xffff;
28 else 31 else
29 ret = sdhci_be32bs_readw(host, reg); 32 ret = (in_be32(host->ioaddr + base) >> shift) & 0xffff;
33 return ret;
34}
35
36static u8 esdhc_readb(struct sdhci_host *host, int reg)
37{
38 int base = reg & ~0x3;
39 int shift = (reg & 0x3) * 8;
40 u8 ret = (in_be32(host->ioaddr + base) >> shift) & 0xff;
30 return ret; 41 return ret;
31} 42}
32 43
@@ -74,7 +85,7 @@ static unsigned int esdhc_of_get_min_clock(struct sdhci_host *host)
74static struct sdhci_ops sdhci_esdhc_ops = { 85static struct sdhci_ops sdhci_esdhc_ops = {
75 .read_l = sdhci_be32bs_readl, 86 .read_l = sdhci_be32bs_readl,
76 .read_w = esdhc_readw, 87 .read_w = esdhc_readw,
77 .read_b = sdhci_be32bs_readb, 88 .read_b = esdhc_readb,
78 .write_l = sdhci_be32bs_writel, 89 .write_l = sdhci_be32bs_writel,
79 .write_w = esdhc_writew, 90 .write_w = esdhc_writew,
80 .write_b = esdhc_writeb, 91 .write_b = esdhc_writeb,
diff --git a/drivers/mmc/host/sdhci-of-hlwd.c b/drivers/mmc/host/sdhci-of-hlwd.c
index 735be131dca9..9b0d794a4f69 100644
--- a/drivers/mmc/host/sdhci-of-hlwd.c
+++ b/drivers/mmc/host/sdhci-of-hlwd.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/module.h>
23#include <linux/mmc/host.h> 24#include <linux/mmc/host.h>
24#include "sdhci-pltfm.h" 25#include "sdhci-pltfm.h"
25 26
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 26c528648f3c..d833d9c2f7e3 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/highmem.h> 16#include <linux/highmem.h>
17#include <linux/module.h>
17#include <linux/pci.h> 18#include <linux/pci.h>
18#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
@@ -21,6 +22,9 @@
21#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
22#include <linux/scatterlist.h> 23#include <linux/scatterlist.h>
23#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/gpio.h>
26#include <linux/sfi.h>
27#include <linux/pm_runtime.h>
24 28
25#include "sdhci.h" 29#include "sdhci.h"
26 30
@@ -43,6 +47,7 @@ struct sdhci_pci_slot;
43 47
44struct sdhci_pci_fixes { 48struct sdhci_pci_fixes {
45 unsigned int quirks; 49 unsigned int quirks;
50 bool allow_runtime_pm;
46 51
47 int (*probe) (struct sdhci_pci_chip *); 52 int (*probe) (struct sdhci_pci_chip *);
48 53
@@ -59,12 +64,16 @@ struct sdhci_pci_slot {
59 struct sdhci_host *host; 64 struct sdhci_host *host;
60 65
61 int pci_bar; 66 int pci_bar;
67 int rst_n_gpio;
68 int cd_gpio;
69 int cd_irq;
62}; 70};
63 71
64struct sdhci_pci_chip { 72struct sdhci_pci_chip {
65 struct pci_dev *pdev; 73 struct pci_dev *pdev;
66 74
67 unsigned int quirks; 75 unsigned int quirks;
76 bool allow_runtime_pm;
68 const struct sdhci_pci_fixes *fixes; 77 const struct sdhci_pci_fixes *fixes;
69 78
70 int num_slots; /* Slots on controller */ 79 int num_slots; /* Slots on controller */
@@ -163,12 +172,129 @@ static int mrst_hc_probe(struct sdhci_pci_chip *chip)
163 return 0; 172 return 0;
164} 173}
165 174
175/* Medfield eMMC hardware reset GPIOs */
176static int mfd_emmc0_rst_gpio = -EINVAL;
177static int mfd_emmc1_rst_gpio = -EINVAL;
178
179static int mfd_emmc_gpio_parse(struct sfi_table_header *table)
180{
181 struct sfi_table_simple *sb = (struct sfi_table_simple *)table;
182 struct sfi_gpio_table_entry *entry;
183 int i, num;
184
185 num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
186 entry = (struct sfi_gpio_table_entry *)sb->pentry;
187
188 for (i = 0; i < num; i++, entry++) {
189 if (!strncmp(entry->pin_name, "emmc0_rst", SFI_NAME_LEN))
190 mfd_emmc0_rst_gpio = entry->pin_no;
191 else if (!strncmp(entry->pin_name, "emmc1_rst", SFI_NAME_LEN))
192 mfd_emmc1_rst_gpio = entry->pin_no;
193 }
194
195 return 0;
196}
197
198#ifdef CONFIG_PM_RUNTIME
199
200static irqreturn_t mfd_sd_cd(int irq, void *dev_id)
201{
202 struct sdhci_pci_slot *slot = dev_id;
203 struct sdhci_host *host = slot->host;
204
205 mmc_detect_change(host->mmc, msecs_to_jiffies(200));
206 return IRQ_HANDLED;
207}
208
209#define MFLD_SD_CD_PIN 69
210
211static int mfd_sd_probe_slot(struct sdhci_pci_slot *slot)
212{
213 int err, irq, gpio = MFLD_SD_CD_PIN;
214
215 slot->cd_gpio = -EINVAL;
216 slot->cd_irq = -EINVAL;
217
218 err = gpio_request(gpio, "sd_cd");
219 if (err < 0)
220 goto out;
221
222 err = gpio_direction_input(gpio);
223 if (err < 0)
224 goto out_free;
225
226 irq = gpio_to_irq(gpio);
227 if (irq < 0)
228 goto out_free;
229
230 err = request_irq(irq, mfd_sd_cd, IRQF_TRIGGER_RISING |
231 IRQF_TRIGGER_FALLING, "sd_cd", slot);
232 if (err)
233 goto out_free;
234
235 slot->cd_gpio = gpio;
236 slot->cd_irq = irq;
237 slot->host->quirks2 |= SDHCI_QUIRK2_OWN_CARD_DETECTION;
238
239 return 0;
240
241out_free:
242 gpio_free(gpio);
243out:
244 dev_warn(&slot->chip->pdev->dev, "failed to setup card detect wake up\n");
245 return 0;
246}
247
248static void mfd_sd_remove_slot(struct sdhci_pci_slot *slot, int dead)
249{
250 if (slot->cd_irq >= 0)
251 free_irq(slot->cd_irq, slot);
252 gpio_free(slot->cd_gpio);
253}
254
255#else
256
257#define mfd_sd_probe_slot NULL
258#define mfd_sd_remove_slot NULL
259
260#endif
261
166static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot) 262static int mfd_emmc_probe_slot(struct sdhci_pci_slot *slot)
167{ 263{
168 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA; 264 const char *name = NULL;
265 int gpio = -EINVAL;
266
267 sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, mfd_emmc_gpio_parse);
268
269 switch (slot->chip->pdev->device) {
270 case PCI_DEVICE_ID_INTEL_MFD_EMMC0:
271 gpio = mfd_emmc0_rst_gpio;
272 name = "eMMC0_reset";
273 break;
274 case PCI_DEVICE_ID_INTEL_MFD_EMMC1:
275 gpio = mfd_emmc1_rst_gpio;
276 name = "eMMC1_reset";
277 break;
278 }
279
280 if (!gpio_request(gpio, name)) {
281 gpio_direction_output(gpio, 1);
282 slot->rst_n_gpio = gpio;
283 slot->host->mmc->caps |= MMC_CAP_HW_RESET;
284 }
285
286 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE;
287
288 slot->host->mmc->caps2 = MMC_CAP2_BOOTPART_NOACC;
289
169 return 0; 290 return 0;
170} 291}
171 292
293static void mfd_emmc_remove_slot(struct sdhci_pci_slot *slot, int dead)
294{
295 gpio_free(slot->rst_n_gpio);
296}
297
172static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = { 298static const struct sdhci_pci_fixes sdhci_intel_mrst_hc0 = {
173 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT, 299 .quirks = SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_NO_HISPD_BIT,
174 .probe_slot = mrst_hc_probe_slot, 300 .probe_slot = mrst_hc_probe_slot,
@@ -181,15 +307,21 @@ static const struct sdhci_pci_fixes sdhci_intel_mrst_hc1_hc2 = {
181 307
182static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = { 308static const struct sdhci_pci_fixes sdhci_intel_mfd_sd = {
183 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 309 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
310 .allow_runtime_pm = true,
311 .probe_slot = mfd_sd_probe_slot,
312 .remove_slot = mfd_sd_remove_slot,
184}; 313};
185 314
186static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = { 315static const struct sdhci_pci_fixes sdhci_intel_mfd_sdio = {
187 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 316 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
317 .allow_runtime_pm = true,
188}; 318};
189 319
190static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = { 320static const struct sdhci_pci_fixes sdhci_intel_mfd_emmc = {
191 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, 321 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
322 .allow_runtime_pm = true,
192 .probe_slot = mfd_emmc_probe_slot, 323 .probe_slot = mfd_emmc_probe_slot,
324 .remove_slot = mfd_emmc_remove_slot,
193}; 325};
194 326
195/* O2Micro extra registers */ 327/* O2Micro extra registers */
@@ -832,9 +964,25 @@ static int sdhci_pci_8bit_width(struct sdhci_host *host, int width)
832 return 0; 964 return 0;
833} 965}
834 966
967static void sdhci_pci_hw_reset(struct sdhci_host *host)
968{
969 struct sdhci_pci_slot *slot = sdhci_priv(host);
970 int rst_n_gpio = slot->rst_n_gpio;
971
972 if (!gpio_is_valid(rst_n_gpio))
973 return;
974 gpio_set_value_cansleep(rst_n_gpio, 0);
975 /* For eMMC, minimum is 1us but give it 10us for good measure */
976 udelay(10);
977 gpio_set_value_cansleep(rst_n_gpio, 1);
978 /* For eMMC, minimum is 200us but give it 300us for good measure */
979 usleep_range(300, 1000);
980}
981
835static struct sdhci_ops sdhci_pci_ops = { 982static struct sdhci_ops sdhci_pci_ops = {
836 .enable_dma = sdhci_pci_enable_dma, 983 .enable_dma = sdhci_pci_enable_dma,
837 .platform_8bit_width = sdhci_pci_8bit_width, 984 .platform_8bit_width = sdhci_pci_8bit_width,
985 .hw_reset = sdhci_pci_hw_reset,
838}; 986};
839 987
840/*****************************************************************************\ 988/*****************************************************************************\
@@ -944,6 +1092,95 @@ static int sdhci_pci_resume(struct pci_dev *pdev)
944 1092
945#endif /* CONFIG_PM */ 1093#endif /* CONFIG_PM */
946 1094
1095#ifdef CONFIG_PM_RUNTIME
1096
1097static int sdhci_pci_runtime_suspend(struct device *dev)
1098{
1099 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1100 struct sdhci_pci_chip *chip;
1101 struct sdhci_pci_slot *slot;
1102 pm_message_t state = { .event = PM_EVENT_SUSPEND };
1103 int i, ret;
1104
1105 chip = pci_get_drvdata(pdev);
1106 if (!chip)
1107 return 0;
1108
1109 for (i = 0; i < chip->num_slots; i++) {
1110 slot = chip->slots[i];
1111 if (!slot)
1112 continue;
1113
1114 ret = sdhci_runtime_suspend_host(slot->host);
1115
1116 if (ret) {
1117 for (i--; i >= 0; i--)
1118 sdhci_runtime_resume_host(chip->slots[i]->host);
1119 return ret;
1120 }
1121 }
1122
1123 if (chip->fixes && chip->fixes->suspend) {
1124 ret = chip->fixes->suspend(chip, state);
1125 if (ret) {
1126 for (i = chip->num_slots - 1; i >= 0; i--)
1127 sdhci_runtime_resume_host(chip->slots[i]->host);
1128 return ret;
1129 }
1130 }
1131
1132 return 0;
1133}
1134
1135static int sdhci_pci_runtime_resume(struct device *dev)
1136{
1137 struct pci_dev *pdev = container_of(dev, struct pci_dev, dev);
1138 struct sdhci_pci_chip *chip;
1139 struct sdhci_pci_slot *slot;
1140 int i, ret;
1141
1142 chip = pci_get_drvdata(pdev);
1143 if (!chip)
1144 return 0;
1145
1146 if (chip->fixes && chip->fixes->resume) {
1147 ret = chip->fixes->resume(chip);
1148 if (ret)
1149 return ret;
1150 }
1151
1152 for (i = 0; i < chip->num_slots; i++) {
1153 slot = chip->slots[i];
1154 if (!slot)
1155 continue;
1156
1157 ret = sdhci_runtime_resume_host(slot->host);
1158 if (ret)
1159 return ret;
1160 }
1161
1162 return 0;
1163}
1164
1165static int sdhci_pci_runtime_idle(struct device *dev)
1166{
1167 return 0;
1168}
1169
1170#else
1171
1172#define sdhci_pci_runtime_suspend NULL
1173#define sdhci_pci_runtime_resume NULL
1174#define sdhci_pci_runtime_idle NULL
1175
1176#endif
1177
1178static const struct dev_pm_ops sdhci_pci_pm_ops = {
1179 .runtime_suspend = sdhci_pci_runtime_suspend,
1180 .runtime_resume = sdhci_pci_runtime_resume,
1181 .runtime_idle = sdhci_pci_runtime_idle,
1182};
1183
947/*****************************************************************************\ 1184/*****************************************************************************\
948 * * 1185 * *
949 * Device probing/removal * 1186 * Device probing/removal *
@@ -988,6 +1225,7 @@ static struct sdhci_pci_slot * __devinit sdhci_pci_probe_slot(
988 slot->chip = chip; 1225 slot->chip = chip;
989 slot->host = host; 1226 slot->host = host;
990 slot->pci_bar = bar; 1227 slot->pci_bar = bar;
1228 slot->rst_n_gpio = -EINVAL;
991 1229
992 host->hw_name = "PCI"; 1230 host->hw_name = "PCI";
993 host->ops = &sdhci_pci_ops; 1231 host->ops = &sdhci_pci_ops;
@@ -1058,6 +1296,21 @@ static void sdhci_pci_remove_slot(struct sdhci_pci_slot *slot)
1058 sdhci_free_host(slot->host); 1296 sdhci_free_host(slot->host);
1059} 1297}
1060 1298
1299static void __devinit sdhci_pci_runtime_pm_allow(struct device *dev)
1300{
1301 pm_runtime_put_noidle(dev);
1302 pm_runtime_allow(dev);
1303 pm_runtime_set_autosuspend_delay(dev, 50);
1304 pm_runtime_use_autosuspend(dev);
1305 pm_suspend_ignore_children(dev, 1);
1306}
1307
1308static void __devexit sdhci_pci_runtime_pm_forbid(struct device *dev)
1309{
1310 pm_runtime_forbid(dev);
1311 pm_runtime_get_noresume(dev);
1312}
1313
1061static int __devinit sdhci_pci_probe(struct pci_dev *pdev, 1314static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1062 const struct pci_device_id *ent) 1315 const struct pci_device_id *ent)
1063{ 1316{
@@ -1107,8 +1360,10 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1107 1360
1108 chip->pdev = pdev; 1361 chip->pdev = pdev;
1109 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data; 1362 chip->fixes = (const struct sdhci_pci_fixes *)ent->driver_data;
1110 if (chip->fixes) 1363 if (chip->fixes) {
1111 chip->quirks = chip->fixes->quirks; 1364 chip->quirks = chip->fixes->quirks;
1365 chip->allow_runtime_pm = chip->fixes->allow_runtime_pm;
1366 }
1112 chip->num_slots = slots; 1367 chip->num_slots = slots;
1113 1368
1114 pci_set_drvdata(pdev, chip); 1369 pci_set_drvdata(pdev, chip);
@@ -1133,6 +1388,9 @@ static int __devinit sdhci_pci_probe(struct pci_dev *pdev,
1133 chip->slots[i] = slot; 1388 chip->slots[i] = slot;
1134 } 1389 }
1135 1390
1391 if (chip->allow_runtime_pm)
1392 sdhci_pci_runtime_pm_allow(&pdev->dev);
1393
1136 return 0; 1394 return 0;
1137 1395
1138free: 1396free:
@@ -1152,6 +1410,9 @@ static void __devexit sdhci_pci_remove(struct pci_dev *pdev)
1152 chip = pci_get_drvdata(pdev); 1410 chip = pci_get_drvdata(pdev);
1153 1411
1154 if (chip) { 1412 if (chip) {
1413 if (chip->allow_runtime_pm)
1414 sdhci_pci_runtime_pm_forbid(&pdev->dev);
1415
1155 for (i = 0; i < chip->num_slots; i++) 1416 for (i = 0; i < chip->num_slots; i++)
1156 sdhci_pci_remove_slot(chip->slots[i]); 1417 sdhci_pci_remove_slot(chip->slots[i]);
1157 1418
@@ -1169,6 +1430,9 @@ static struct pci_driver sdhci_driver = {
1169 .remove = __devexit_p(sdhci_pci_remove), 1430 .remove = __devexit_p(sdhci_pci_remove),
1170 .suspend = sdhci_pci_suspend, 1431 .suspend = sdhci_pci_suspend,
1171 .resume = sdhci_pci_resume, 1432 .resume = sdhci_pci_resume,
1433 .driver = {
1434 .pm = &sdhci_pci_pm_ops
1435 },
1172}; 1436};
1173 1437
1174/*****************************************************************************\ 1438/*****************************************************************************\
diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c
index 6414efeddca0..a9e12ea05583 100644
--- a/drivers/mmc/host/sdhci-pltfm.c
+++ b/drivers/mmc/host/sdhci-pltfm.c
@@ -29,6 +29,7 @@
29 */ 29 */
30 30
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/module.h>
32#include <linux/of.h> 33#include <linux/of.h>
33#ifdef CONFIG_PPC 34#ifdef CONFIG_PPC
34#include <asm/machdep.h> 35#include <asm/machdep.h>
diff --git a/drivers/mmc/host/sdhci-pxav2.c b/drivers/mmc/host/sdhci-pxav2.c
index 38f58994f79a..d4bf6d30c7ba 100644
--- a/drivers/mmc/host/sdhci-pxav2.c
+++ b/drivers/mmc/host/sdhci-pxav2.c
@@ -21,6 +21,7 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/clk.h> 23#include <linux/clk.h>
24#include <linux/module.h>
24#include <linux/io.h> 25#include <linux/io.h>
25#include <linux/gpio.h> 26#include <linux/gpio.h>
26#include <linux/mmc/card.h> 27#include <linux/mmc/card.h>
@@ -59,7 +60,7 @@ static void pxav2_set_private_registers(struct sdhci_host *host, u8 mask)
59 * tune timing of read data/command when crc error happen 60 * tune timing of read data/command when crc error happen
60 * no performance impact 61 * no performance impact
61 */ 62 */
62 if (pdata->clk_delay_sel == 1) { 63 if (pdata && pdata->clk_delay_sel == 1) {
63 tmp = readw(host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP); 64 tmp = readw(host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
64 65
65 tmp &= ~(SDCLK_DELAY_MASK << SDCLK_DELAY_SHIFT); 66 tmp &= ~(SDCLK_DELAY_MASK << SDCLK_DELAY_SHIFT);
@@ -71,7 +72,7 @@ static void pxav2_set_private_registers(struct sdhci_host *host, u8 mask)
71 writew(tmp, host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP); 72 writew(tmp, host->ioaddr + SD_CLOCK_BURST_SIZE_SETUP);
72 } 73 }
73 74
74 if (pdata->flags & PXA_FLAG_ENABLE_CLOCK_GATING) { 75 if (pdata && (pdata->flags & PXA_FLAG_ENABLE_CLOCK_GATING)) {
75 tmp = readw(host->ioaddr + SD_FIFO_PARAM); 76 tmp = readw(host->ioaddr + SD_FIFO_PARAM);
76 tmp &= ~CLK_GATE_SETTING_BITS; 77 tmp &= ~CLK_GATE_SETTING_BITS;
77 writew(tmp, host->ioaddr + SD_FIFO_PARAM); 78 writew(tmp, host->ioaddr + SD_FIFO_PARAM);
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index fc7e4a515629..cff4ad3e7a59 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -27,6 +27,7 @@
27#include <linux/platform_data/pxa_sdhci.h> 27#include <linux/platform_data/pxa_sdhci.h>
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 "sdhci.h" 31#include "sdhci.h"
31#include "sdhci-pltfm.h" 32#include "sdhci-pltfm.h"
32 33
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index fe886d6c474a..3d00e722efc9 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -203,17 +203,23 @@ static void sdhci_s3c_set_clock(struct sdhci_host *host, unsigned int clock)
203 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2); 203 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
204 } 204 }
205 205
206 /* reconfigure the hardware for new clock rate */ 206 /* reprogram default hardware configuration */
207 207 writel(S3C64XX_SDHCI_CONTROL4_DRIVE_9mA,
208 { 208 host->ioaddr + S3C64XX_SDHCI_CONTROL4);
209 struct mmc_ios ios; 209
210 210 ctrl = readl(host->ioaddr + S3C_SDHCI_CONTROL2);
211 ios.clock = clock; 211 ctrl |= (S3C64XX_SDHCI_CTRL2_ENSTAASYNCCLR |
212 212 S3C64XX_SDHCI_CTRL2_ENCMDCNFMSK |
213 if (ourhost->pdata->cfg_card) 213 S3C_SDHCI_CTRL2_ENFBCLKRX |
214 (ourhost->pdata->cfg_card)(ourhost->pdev, host->ioaddr, 214 S3C_SDHCI_CTRL2_DFCNT_NONE |
215 &ios, NULL); 215 S3C_SDHCI_CTRL2_ENCLKOUTHOLD);
216 } 216 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL2);
217
218 /* reconfigure the controller for new clock rate */
219 ctrl = (S3C_SDHCI_CTRL3_FCSEL1 | S3C_SDHCI_CTRL3_FCSEL0);
220 if (clock < 25 * 1000000)
221 ctrl |= (S3C_SDHCI_CTRL3_FCSEL3 | S3C_SDHCI_CTRL3_FCSEL2);
222 writel(ctrl, host->ioaddr + S3C_SDHCI_CONTROL3);
217} 223}
218 224
219/** 225/**
@@ -561,8 +567,10 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
561 567
562 err_req_regs: 568 err_req_regs:
563 for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) { 569 for (ptr = 0; ptr < MAX_BUS_CLK; ptr++) {
564 clk_disable(sc->clk_bus[ptr]); 570 if (sc->clk_bus[ptr]) {
565 clk_put(sc->clk_bus[ptr]); 571 clk_disable(sc->clk_bus[ptr]);
572 clk_put(sc->clk_bus[ptr]);
573 }
566 } 574 }
567 575
568 err_no_busclks: 576 err_no_busclks:
diff --git a/drivers/mmc/host/sdhci-spear.c b/drivers/mmc/host/sdhci-spear.c
index 60a4c97d3d18..63cc8b6a1c9e 100644
--- a/drivers/mmc/host/sdhci-spear.c
+++ b/drivers/mmc/host/sdhci-spear.c
@@ -17,6 +17,7 @@
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/gpio.h> 18#include <linux/gpio.h>
19#include <linux/highmem.h> 19#include <linux/highmem.h>
20#include <linux/module.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
21#include <linux/irq.h> 22#include <linux/irq.h>
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
@@ -177,8 +178,6 @@ static int __devinit sdhci_probe(struct platform_device *pdev)
177 sdhci->data->card_power_gpio); 178 sdhci->data->card_power_gpio);
178 goto err_pgpio_direction; 179 goto err_pgpio_direction;
179 } 180 }
180
181 gpio_set_value(sdhci->data->card_power_gpio, 1);
182 } 181 }
183 182
184 if (sdhci->data->card_int_gpio >= 0) { 183 if (sdhci->data->card_int_gpio >= 0) {
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index 21b00cefae63..067a4cded9cf 100644
--- a/drivers/mmc/host/sdhci-tegra.c
+++ b/drivers/mmc/host/sdhci-tegra.c
@@ -17,9 +17,12 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/clk.h> 18#include <linux/clk.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/of.h>
21#include <linux/of_gpio.h>
20#include <linux/gpio.h> 22#include <linux/gpio.h>
21#include <linux/mmc/card.h> 23#include <linux/mmc/card.h>
22#include <linux/mmc/host.h> 24#include <linux/mmc/host.h>
25#include <linux/module.h>
23 26
24#include <asm/gpio.h> 27#include <asm/gpio.h>
25 28
@@ -75,10 +78,8 @@ static void tegra_sdhci_writel(struct sdhci_host *host, u32 val, int reg)
75 78
76static unsigned int tegra_sdhci_get_ro(struct sdhci_host *sdhci) 79static unsigned int tegra_sdhci_get_ro(struct sdhci_host *sdhci)
77{ 80{
78 struct platform_device *pdev = to_platform_device(mmc_dev(sdhci->mmc)); 81 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(sdhci);
79 struct tegra_sdhci_platform_data *plat; 82 struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
80
81 plat = pdev->dev.platform_data;
82 83
83 if (!gpio_is_valid(plat->wp_gpio)) 84 if (!gpio_is_valid(plat->wp_gpio))
84 return -1; 85 return -1;
@@ -96,12 +97,10 @@ static irqreturn_t carddetect_irq(int irq, void *data)
96 97
97static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width) 98static int tegra_sdhci_8bit(struct sdhci_host *host, int bus_width)
98{ 99{
99 struct platform_device *pdev = to_platform_device(mmc_dev(host->mmc)); 100 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
100 struct tegra_sdhci_platform_data *plat; 101 struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
101 u32 ctrl; 102 u32 ctrl;
102 103
103 plat = pdev->dev.platform_data;
104
105 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 104 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
106 if (plat->is_8bit && bus_width == MMC_BUS_WIDTH_8) { 105 if (plat->is_8bit && bus_width == MMC_BUS_WIDTH_8) {
107 ctrl &= ~SDHCI_CTRL_4BITBUS; 106 ctrl &= ~SDHCI_CTRL_4BITBUS;
@@ -133,6 +132,36 @@ static struct sdhci_pltfm_data sdhci_tegra_pdata = {
133 .ops = &tegra_sdhci_ops, 132 .ops = &tegra_sdhci_ops,
134}; 133};
135 134
135static const struct of_device_id sdhci_tegra_dt_match[] __devinitdata = {
136 { .compatible = "nvidia,tegra20-sdhci", },
137 {}
138};
139MODULE_DEVICE_TABLE(of, sdhci_dt_ids);
140
141static struct tegra_sdhci_platform_data * __devinit sdhci_tegra_dt_parse_pdata(
142 struct platform_device *pdev)
143{
144 struct tegra_sdhci_platform_data *plat;
145 struct device_node *np = pdev->dev.of_node;
146
147 if (!np)
148 return NULL;
149
150 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
151 if (!plat) {
152 dev_err(&pdev->dev, "Can't allocate platform data\n");
153 return NULL;
154 }
155
156 plat->cd_gpio = of_get_named_gpio(np, "cd-gpios", 0);
157 plat->wp_gpio = of_get_named_gpio(np, "wp-gpios", 0);
158 plat->power_gpio = of_get_named_gpio(np, "power-gpios", 0);
159 if (of_find_property(np, "support-8bit", NULL))
160 plat->is_8bit = 1;
161
162 return plat;
163}
164
136static int __devinit sdhci_tegra_probe(struct platform_device *pdev) 165static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
137{ 166{
138 struct sdhci_pltfm_host *pltfm_host; 167 struct sdhci_pltfm_host *pltfm_host;
@@ -149,12 +178,17 @@ static int __devinit sdhci_tegra_probe(struct platform_device *pdev)
149 178
150 plat = pdev->dev.platform_data; 179 plat = pdev->dev.platform_data;
151 180
181 if (plat == NULL)
182 plat = sdhci_tegra_dt_parse_pdata(pdev);
183
152 if (plat == NULL) { 184 if (plat == NULL) {
153 dev_err(mmc_dev(host->mmc), "missing platform data\n"); 185 dev_err(mmc_dev(host->mmc), "missing platform data\n");
154 rc = -ENXIO; 186 rc = -ENXIO;
155 goto err_no_plat; 187 goto err_no_plat;
156 } 188 }
157 189
190 pltfm_host->priv = plat;
191
158 if (gpio_is_valid(plat->power_gpio)) { 192 if (gpio_is_valid(plat->power_gpio)) {
159 rc = gpio_request(plat->power_gpio, "sdhci_power"); 193 rc = gpio_request(plat->power_gpio, "sdhci_power");
160 if (rc) { 194 if (rc) {
@@ -249,13 +283,11 @@ static int __devexit sdhci_tegra_remove(struct platform_device *pdev)
249{ 283{
250 struct sdhci_host *host = platform_get_drvdata(pdev); 284 struct sdhci_host *host = platform_get_drvdata(pdev);
251 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 285 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
252 struct tegra_sdhci_platform_data *plat; 286 struct tegra_sdhci_platform_data *plat = pltfm_host->priv;
253 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); 287 int dead = (readl(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff);
254 288
255 sdhci_remove_host(host, dead); 289 sdhci_remove_host(host, dead);
256 290
257 plat = pdev->dev.platform_data;
258
259 if (gpio_is_valid(plat->wp_gpio)) { 291 if (gpio_is_valid(plat->wp_gpio)) {
260 tegra_gpio_disable(plat->wp_gpio); 292 tegra_gpio_disable(plat->wp_gpio);
261 gpio_free(plat->wp_gpio); 293 gpio_free(plat->wp_gpio);
@@ -284,6 +316,7 @@ static struct platform_driver sdhci_tegra_driver = {
284 .driver = { 316 .driver = {
285 .name = "sdhci-tegra", 317 .name = "sdhci-tegra",
286 .owner = THIS_MODULE, 318 .owner = THIS_MODULE,
319 .of_match_table = sdhci_tegra_dt_match,
287 }, 320 },
288 .probe = sdhci_tegra_probe, 321 .probe = sdhci_tegra_probe,
289 .remove = __devexit_p(sdhci_tegra_remove), 322 .remove = __devexit_p(sdhci_tegra_remove),
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 0e02cc1df12e..6d8eea323541 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -16,10 +16,12 @@
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/module.h>
19#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
22#include <linux/regulator/consumer.h> 23#include <linux/regulator/consumer.h>
24#include <linux/pm_runtime.h>
23 25
24#include <linux/leds.h> 26#include <linux/leds.h>
25 27
@@ -41,6 +43,7 @@
41#define MAX_TUNING_LOOP 40 43#define MAX_TUNING_LOOP 40
42 44
43static unsigned int debug_quirks = 0; 45static unsigned int debug_quirks = 0;
46static unsigned int debug_quirks2;
44 47
45static void sdhci_finish_data(struct sdhci_host *); 48static void sdhci_finish_data(struct sdhci_host *);
46 49
@@ -49,53 +52,67 @@ static void sdhci_finish_command(struct sdhci_host *);
49static int sdhci_execute_tuning(struct mmc_host *mmc); 52static int sdhci_execute_tuning(struct mmc_host *mmc);
50static void sdhci_tuning_timer(unsigned long data); 53static void sdhci_tuning_timer(unsigned long data);
51 54
55#ifdef CONFIG_PM_RUNTIME
56static int sdhci_runtime_pm_get(struct sdhci_host *host);
57static int sdhci_runtime_pm_put(struct sdhci_host *host);
58#else
59static inline int sdhci_runtime_pm_get(struct sdhci_host *host)
60{
61 return 0;
62}
63static inline int sdhci_runtime_pm_put(struct sdhci_host *host)
64{
65 return 0;
66}
67#endif
68
52static void sdhci_dumpregs(struct sdhci_host *host) 69static void sdhci_dumpregs(struct sdhci_host *host)
53{ 70{
54 printk(KERN_DEBUG DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n", 71 pr_debug(DRIVER_NAME ": =========== REGISTER DUMP (%s)===========\n",
55 mmc_hostname(host->mmc)); 72 mmc_hostname(host->mmc));
56 73
57 printk(KERN_DEBUG DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n", 74 pr_debug(DRIVER_NAME ": Sys addr: 0x%08x | Version: 0x%08x\n",
58 sdhci_readl(host, SDHCI_DMA_ADDRESS), 75 sdhci_readl(host, SDHCI_DMA_ADDRESS),
59 sdhci_readw(host, SDHCI_HOST_VERSION)); 76 sdhci_readw(host, SDHCI_HOST_VERSION));
60 printk(KERN_DEBUG DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n", 77 pr_debug(DRIVER_NAME ": Blk size: 0x%08x | Blk cnt: 0x%08x\n",
61 sdhci_readw(host, SDHCI_BLOCK_SIZE), 78 sdhci_readw(host, SDHCI_BLOCK_SIZE),
62 sdhci_readw(host, SDHCI_BLOCK_COUNT)); 79 sdhci_readw(host, SDHCI_BLOCK_COUNT));
63 printk(KERN_DEBUG DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n", 80 pr_debug(DRIVER_NAME ": Argument: 0x%08x | Trn mode: 0x%08x\n",
64 sdhci_readl(host, SDHCI_ARGUMENT), 81 sdhci_readl(host, SDHCI_ARGUMENT),
65 sdhci_readw(host, SDHCI_TRANSFER_MODE)); 82 sdhci_readw(host, SDHCI_TRANSFER_MODE));
66 printk(KERN_DEBUG DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n", 83 pr_debug(DRIVER_NAME ": Present: 0x%08x | Host ctl: 0x%08x\n",
67 sdhci_readl(host, SDHCI_PRESENT_STATE), 84 sdhci_readl(host, SDHCI_PRESENT_STATE),
68 sdhci_readb(host, SDHCI_HOST_CONTROL)); 85 sdhci_readb(host, SDHCI_HOST_CONTROL));
69 printk(KERN_DEBUG DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n", 86 pr_debug(DRIVER_NAME ": Power: 0x%08x | Blk gap: 0x%08x\n",
70 sdhci_readb(host, SDHCI_POWER_CONTROL), 87 sdhci_readb(host, SDHCI_POWER_CONTROL),
71 sdhci_readb(host, SDHCI_BLOCK_GAP_CONTROL)); 88 sdhci_readb(host, SDHCI_BLOCK_GAP_CONTROL));
72 printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n", 89 pr_debug(DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
73 sdhci_readb(host, SDHCI_WAKE_UP_CONTROL), 90 sdhci_readb(host, SDHCI_WAKE_UP_CONTROL),
74 sdhci_readw(host, SDHCI_CLOCK_CONTROL)); 91 sdhci_readw(host, SDHCI_CLOCK_CONTROL));
75 printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n", 92 pr_debug(DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
76 sdhci_readb(host, SDHCI_TIMEOUT_CONTROL), 93 sdhci_readb(host, SDHCI_TIMEOUT_CONTROL),
77 sdhci_readl(host, SDHCI_INT_STATUS)); 94 sdhci_readl(host, SDHCI_INT_STATUS));
78 printk(KERN_DEBUG DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n", 95 pr_debug(DRIVER_NAME ": Int enab: 0x%08x | Sig enab: 0x%08x\n",
79 sdhci_readl(host, SDHCI_INT_ENABLE), 96 sdhci_readl(host, SDHCI_INT_ENABLE),
80 sdhci_readl(host, SDHCI_SIGNAL_ENABLE)); 97 sdhci_readl(host, SDHCI_SIGNAL_ENABLE));
81 printk(KERN_DEBUG DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n", 98 pr_debug(DRIVER_NAME ": AC12 err: 0x%08x | Slot int: 0x%08x\n",
82 sdhci_readw(host, SDHCI_ACMD12_ERR), 99 sdhci_readw(host, SDHCI_ACMD12_ERR),
83 sdhci_readw(host, SDHCI_SLOT_INT_STATUS)); 100 sdhci_readw(host, SDHCI_SLOT_INT_STATUS));
84 printk(KERN_DEBUG DRIVER_NAME ": Caps: 0x%08x | Caps_1: 0x%08x\n", 101 pr_debug(DRIVER_NAME ": Caps: 0x%08x | Caps_1: 0x%08x\n",
85 sdhci_readl(host, SDHCI_CAPABILITIES), 102 sdhci_readl(host, SDHCI_CAPABILITIES),
86 sdhci_readl(host, SDHCI_CAPABILITIES_1)); 103 sdhci_readl(host, SDHCI_CAPABILITIES_1));
87 printk(KERN_DEBUG DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n", 104 pr_debug(DRIVER_NAME ": Cmd: 0x%08x | Max curr: 0x%08x\n",
88 sdhci_readw(host, SDHCI_COMMAND), 105 sdhci_readw(host, SDHCI_COMMAND),
89 sdhci_readl(host, SDHCI_MAX_CURRENT)); 106 sdhci_readl(host, SDHCI_MAX_CURRENT));
90 printk(KERN_DEBUG DRIVER_NAME ": Host ctl2: 0x%08x\n", 107 pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n",
91 sdhci_readw(host, SDHCI_HOST_CONTROL2)); 108 sdhci_readw(host, SDHCI_HOST_CONTROL2));
92 109
93 if (host->flags & SDHCI_USE_ADMA) 110 if (host->flags & SDHCI_USE_ADMA)
94 printk(KERN_DEBUG DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n", 111 pr_debug(DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n",
95 readl(host->ioaddr + SDHCI_ADMA_ERROR), 112 readl(host->ioaddr + SDHCI_ADMA_ERROR),
96 readl(host->ioaddr + SDHCI_ADMA_ADDRESS)); 113 readl(host->ioaddr + SDHCI_ADMA_ADDRESS));
97 114
98 printk(KERN_DEBUG DRIVER_NAME ": ===========================================\n"); 115 pr_debug(DRIVER_NAME ": ===========================================\n");
99} 116}
100 117
101/*****************************************************************************\ 118/*****************************************************************************\
@@ -132,6 +149,9 @@ static void sdhci_set_card_detection(struct sdhci_host *host, bool enable)
132 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) 149 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
133 return; 150 return;
134 151
152 if (host->quirks2 & SDHCI_QUIRK2_OWN_CARD_DETECTION)
153 return;
154
135 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & 155 present = sdhci_readl(host, SDHCI_PRESENT_STATE) &
136 SDHCI_CARD_PRESENT; 156 SDHCI_CARD_PRESENT;
137 irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT; 157 irqs = present ? SDHCI_INT_CARD_REMOVE : SDHCI_INT_CARD_INSERT;
@@ -180,7 +200,7 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)
180 /* hw clears the bit when it's done */ 200 /* hw clears the bit when it's done */
181 while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) { 201 while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
182 if (timeout == 0) { 202 if (timeout == 0) {
183 printk(KERN_ERR "%s: Reset 0x%x never completed.\n", 203 pr_err("%s: Reset 0x%x never completed.\n",
184 mmc_hostname(host->mmc), (int)mask); 204 mmc_hostname(host->mmc), (int)mask);
185 sdhci_dumpregs(host); 205 sdhci_dumpregs(host);
186 return; 206 return;
@@ -251,11 +271,14 @@ static void sdhci_led_control(struct led_classdev *led,
251 271
252 spin_lock_irqsave(&host->lock, flags); 272 spin_lock_irqsave(&host->lock, flags);
253 273
274 if (host->runtime_suspended)
275 goto out;
276
254 if (brightness == LED_OFF) 277 if (brightness == LED_OFF)
255 sdhci_deactivate_led(host); 278 sdhci_deactivate_led(host);
256 else 279 else
257 sdhci_activate_led(host); 280 sdhci_activate_led(host);
258 281out:
259 spin_unlock_irqrestore(&host->lock, flags); 282 spin_unlock_irqrestore(&host->lock, flags);
260} 283}
261#endif 284#endif
@@ -654,7 +677,7 @@ static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd)
654 } 677 }
655 678
656 if (count >= 0xF) { 679 if (count >= 0xF) {
657 printk(KERN_WARNING "%s: Too large timeout requested for CMD%d!\n", 680 pr_warning("%s: Too large timeout requested for CMD%d!\n",
658 mmc_hostname(host->mmc), cmd->opcode); 681 mmc_hostname(host->mmc), cmd->opcode);
659 count = 0xE; 682 count = 0xE;
660 } 683 }
@@ -949,7 +972,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
949 972
950 while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { 973 while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
951 if (timeout == 0) { 974 if (timeout == 0) {
952 printk(KERN_ERR "%s: Controller never released " 975 pr_err("%s: Controller never released "
953 "inhibit bit(s).\n", mmc_hostname(host->mmc)); 976 "inhibit bit(s).\n", mmc_hostname(host->mmc));
954 sdhci_dumpregs(host); 977 sdhci_dumpregs(host);
955 cmd->error = -EIO; 978 cmd->error = -EIO;
@@ -971,7 +994,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
971 sdhci_set_transfer_mode(host, cmd); 994 sdhci_set_transfer_mode(host, cmd);
972 995
973 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) { 996 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
974 printk(KERN_ERR "%s: Unsupported response type!\n", 997 pr_err("%s: Unsupported response type!\n",
975 mmc_hostname(host->mmc)); 998 mmc_hostname(host->mmc));
976 cmd->error = -EINVAL; 999 cmd->error = -EINVAL;
977 tasklet_schedule(&host->finish_tasklet); 1000 tasklet_schedule(&host->finish_tasklet);
@@ -1121,7 +1144,7 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
1121 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) 1144 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
1122 & SDHCI_CLOCK_INT_STABLE)) { 1145 & SDHCI_CLOCK_INT_STABLE)) {
1123 if (timeout == 0) { 1146 if (timeout == 0) {
1124 printk(KERN_ERR "%s: Internal clock never " 1147 pr_err("%s: Internal clock never "
1125 "stabilised.\n", mmc_hostname(host->mmc)); 1148 "stabilised.\n", mmc_hostname(host->mmc));
1126 sdhci_dumpregs(host); 1149 sdhci_dumpregs(host);
1127 return; 1150 return;
@@ -1209,6 +1232,8 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1209 1232
1210 host = mmc_priv(mmc); 1233 host = mmc_priv(mmc);
1211 1234
1235 sdhci_runtime_pm_get(host);
1236
1212 spin_lock_irqsave(&host->lock, flags); 1237 spin_lock_irqsave(&host->lock, flags);
1213 1238
1214 WARN_ON(host->mrq != NULL); 1239 WARN_ON(host->mrq != NULL);
@@ -1269,14 +1294,11 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1269 spin_unlock_irqrestore(&host->lock, flags); 1294 spin_unlock_irqrestore(&host->lock, flags);
1270} 1295}
1271 1296
1272static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) 1297static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1273{ 1298{
1274 struct sdhci_host *host;
1275 unsigned long flags; 1299 unsigned long flags;
1276 u8 ctrl; 1300 u8 ctrl;
1277 1301
1278 host = mmc_priv(mmc);
1279
1280 spin_lock_irqsave(&host->lock, flags); 1302 spin_lock_irqsave(&host->lock, flags);
1281 1303
1282 if (host->flags & SDHCI_DEVICE_DEAD) 1304 if (host->flags & SDHCI_DEVICE_DEAD)
@@ -1426,7 +1448,16 @@ out:
1426 spin_unlock_irqrestore(&host->lock, flags); 1448 spin_unlock_irqrestore(&host->lock, flags);
1427} 1449}
1428 1450
1429static int check_ro(struct sdhci_host *host) 1451static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1452{
1453 struct sdhci_host *host = mmc_priv(mmc);
1454
1455 sdhci_runtime_pm_get(host);
1456 sdhci_do_set_ios(host, ios);
1457 sdhci_runtime_pm_put(host);
1458}
1459
1460static int sdhci_check_ro(struct sdhci_host *host)
1430{ 1461{
1431 unsigned long flags; 1462 unsigned long flags;
1432 int is_readonly; 1463 int is_readonly;
@@ -1450,19 +1481,16 @@ static int check_ro(struct sdhci_host *host)
1450 1481
1451#define SAMPLE_COUNT 5 1482#define SAMPLE_COUNT 5
1452 1483
1453static int sdhci_get_ro(struct mmc_host *mmc) 1484static int sdhci_do_get_ro(struct sdhci_host *host)
1454{ 1485{
1455 struct sdhci_host *host;
1456 int i, ro_count; 1486 int i, ro_count;
1457 1487
1458 host = mmc_priv(mmc);
1459
1460 if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT)) 1488 if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT))
1461 return check_ro(host); 1489 return sdhci_check_ro(host);
1462 1490
1463 ro_count = 0; 1491 ro_count = 0;
1464 for (i = 0; i < SAMPLE_COUNT; i++) { 1492 for (i = 0; i < SAMPLE_COUNT; i++) {
1465 if (check_ro(host)) { 1493 if (sdhci_check_ro(host)) {
1466 if (++ro_count > SAMPLE_COUNT / 2) 1494 if (++ro_count > SAMPLE_COUNT / 2)
1467 return 1; 1495 return 1;
1468 } 1496 }
@@ -1471,38 +1499,64 @@ static int sdhci_get_ro(struct mmc_host *mmc)
1471 return 0; 1499 return 0;
1472} 1500}
1473 1501
1474static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) 1502static void sdhci_hw_reset(struct mmc_host *mmc)
1475{ 1503{
1476 struct sdhci_host *host; 1504 struct sdhci_host *host = mmc_priv(mmc);
1477 unsigned long flags;
1478 1505
1479 host = mmc_priv(mmc); 1506 if (host->ops && host->ops->hw_reset)
1507 host->ops->hw_reset(host);
1508}
1480 1509
1481 spin_lock_irqsave(&host->lock, flags); 1510static int sdhci_get_ro(struct mmc_host *mmc)
1511{
1512 struct sdhci_host *host = mmc_priv(mmc);
1513 int ret;
1482 1514
1515 sdhci_runtime_pm_get(host);
1516 ret = sdhci_do_get_ro(host);
1517 sdhci_runtime_pm_put(host);
1518 return ret;
1519}
1520
1521static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable)
1522{
1483 if (host->flags & SDHCI_DEVICE_DEAD) 1523 if (host->flags & SDHCI_DEVICE_DEAD)
1484 goto out; 1524 goto out;
1485 1525
1486 if (enable) 1526 if (enable)
1527 host->flags |= SDHCI_SDIO_IRQ_ENABLED;
1528 else
1529 host->flags &= ~SDHCI_SDIO_IRQ_ENABLED;
1530
1531 /* SDIO IRQ will be enabled as appropriate in runtime resume */
1532 if (host->runtime_suspended)
1533 goto out;
1534
1535 if (enable)
1487 sdhci_unmask_irqs(host, SDHCI_INT_CARD_INT); 1536 sdhci_unmask_irqs(host, SDHCI_INT_CARD_INT);
1488 else 1537 else
1489 sdhci_mask_irqs(host, SDHCI_INT_CARD_INT); 1538 sdhci_mask_irqs(host, SDHCI_INT_CARD_INT);
1490out: 1539out:
1491 mmiowb(); 1540 mmiowb();
1541}
1542
1543static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
1544{
1545 struct sdhci_host *host = mmc_priv(mmc);
1546 unsigned long flags;
1492 1547
1548 spin_lock_irqsave(&host->lock, flags);
1549 sdhci_enable_sdio_irq_nolock(host, enable);
1493 spin_unlock_irqrestore(&host->lock, flags); 1550 spin_unlock_irqrestore(&host->lock, flags);
1494} 1551}
1495 1552
1496static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, 1553static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
1497 struct mmc_ios *ios) 1554 struct mmc_ios *ios)
1498{ 1555{
1499 struct sdhci_host *host;
1500 u8 pwr; 1556 u8 pwr;
1501 u16 clk, ctrl; 1557 u16 clk, ctrl;
1502 u32 present_state; 1558 u32 present_state;
1503 1559
1504 host = mmc_priv(mmc);
1505
1506 /* 1560 /*
1507 * Signal Voltage Switching is only applicable for Host Controllers 1561 * Signal Voltage Switching is only applicable for Host Controllers
1508 * v3.00 and above. 1562 * v3.00 and above.
@@ -1528,7 +1582,7 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1528 if (!(ctrl & SDHCI_CTRL_VDD_180)) 1582 if (!(ctrl & SDHCI_CTRL_VDD_180))
1529 return 0; 1583 return 0;
1530 else { 1584 else {
1531 printk(KERN_INFO DRIVER_NAME ": Switching to 3.3V " 1585 pr_info(DRIVER_NAME ": Switching to 3.3V "
1532 "signalling voltage failed\n"); 1586 "signalling voltage failed\n");
1533 return -EIO; 1587 return -EIO;
1534 } 1588 }
@@ -1587,7 +1641,7 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1587 pwr |= SDHCI_POWER_ON; 1641 pwr |= SDHCI_POWER_ON;
1588 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); 1642 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
1589 1643
1590 printk(KERN_INFO DRIVER_NAME ": Switching to 1.8V signalling " 1644 pr_info(DRIVER_NAME ": Switching to 1.8V signalling "
1591 "voltage failed, retrying with S18R set to 0\n"); 1645 "voltage failed, retrying with S18R set to 0\n");
1592 return -EAGAIN; 1646 return -EAGAIN;
1593 } else 1647 } else
@@ -1595,6 +1649,20 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1595 return 0; 1649 return 0;
1596} 1650}
1597 1651
1652static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
1653 struct mmc_ios *ios)
1654{
1655 struct sdhci_host *host = mmc_priv(mmc);
1656 int err;
1657
1658 if (host->version < SDHCI_SPEC_300)
1659 return 0;
1660 sdhci_runtime_pm_get(host);
1661 err = sdhci_do_start_signal_voltage_switch(host, ios);
1662 sdhci_runtime_pm_put(host);
1663 return err;
1664}
1665
1598static int sdhci_execute_tuning(struct mmc_host *mmc) 1666static int sdhci_execute_tuning(struct mmc_host *mmc)
1599{ 1667{
1600 struct sdhci_host *host; 1668 struct sdhci_host *host;
@@ -1606,6 +1674,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1606 1674
1607 host = mmc_priv(mmc); 1675 host = mmc_priv(mmc);
1608 1676
1677 sdhci_runtime_pm_get(host);
1609 disable_irq(host->irq); 1678 disable_irq(host->irq);
1610 spin_lock(&host->lock); 1679 spin_lock(&host->lock);
1611 1680
@@ -1623,6 +1692,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1623 else { 1692 else {
1624 spin_unlock(&host->lock); 1693 spin_unlock(&host->lock);
1625 enable_irq(host->irq); 1694 enable_irq(host->irq);
1695 sdhci_runtime_pm_put(host);
1626 return 0; 1696 return 0;
1627 } 1697 }
1628 1698
@@ -1648,7 +1718,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1648 timeout = 150; 1718 timeout = 150;
1649 do { 1719 do {
1650 struct mmc_command cmd = {0}; 1720 struct mmc_command cmd = {0};
1651 struct mmc_request mrq = {0}; 1721 struct mmc_request mrq = {NULL};
1652 1722
1653 if (!tuning_loop_counter && !timeout) 1723 if (!tuning_loop_counter && !timeout)
1654 break; 1724 break;
@@ -1694,7 +1764,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1694 spin_lock(&host->lock); 1764 spin_lock(&host->lock);
1695 1765
1696 if (!host->tuning_done) { 1766 if (!host->tuning_done) {
1697 printk(KERN_INFO DRIVER_NAME ": Timeout waiting for " 1767 pr_info(DRIVER_NAME ": Timeout waiting for "
1698 "Buffer Read Ready interrupt during tuning " 1768 "Buffer Read Ready interrupt during tuning "
1699 "procedure, falling back to fixed sampling " 1769 "procedure, falling back to fixed sampling "
1700 "clock\n"); 1770 "clock\n");
@@ -1724,7 +1794,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc)
1724 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1794 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1725 } else { 1795 } else {
1726 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) { 1796 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
1727 printk(KERN_INFO DRIVER_NAME ": Tuning procedure" 1797 pr_info(DRIVER_NAME ": Tuning procedure"
1728 " failed, falling back to fixed sampling" 1798 " failed, falling back to fixed sampling"
1729 " clock\n"); 1799 " clock\n");
1730 err = -EIO; 1800 err = -EIO;
@@ -1766,18 +1836,16 @@ out:
1766 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier); 1836 sdhci_clear_set_irqs(host, SDHCI_INT_DATA_AVAIL, ier);
1767 spin_unlock(&host->lock); 1837 spin_unlock(&host->lock);
1768 enable_irq(host->irq); 1838 enable_irq(host->irq);
1839 sdhci_runtime_pm_put(host);
1769 1840
1770 return err; 1841 return err;
1771} 1842}
1772 1843
1773static void sdhci_enable_preset_value(struct mmc_host *mmc, bool enable) 1844static void sdhci_do_enable_preset_value(struct sdhci_host *host, bool enable)
1774{ 1845{
1775 struct sdhci_host *host;
1776 u16 ctrl; 1846 u16 ctrl;
1777 unsigned long flags; 1847 unsigned long flags;
1778 1848
1779 host = mmc_priv(mmc);
1780
1781 /* Host Controller v3.00 defines preset value registers */ 1849 /* Host Controller v3.00 defines preset value registers */
1782 if (host->version < SDHCI_SPEC_300) 1850 if (host->version < SDHCI_SPEC_300)
1783 return; 1851 return;
@@ -1793,18 +1861,30 @@ static void sdhci_enable_preset_value(struct mmc_host *mmc, bool enable)
1793 if (enable && !(ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) { 1861 if (enable && !(ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) {
1794 ctrl |= SDHCI_CTRL_PRESET_VAL_ENABLE; 1862 ctrl |= SDHCI_CTRL_PRESET_VAL_ENABLE;
1795 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1863 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1864 host->flags |= SDHCI_PV_ENABLED;
1796 } else if (!enable && (ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) { 1865 } else if (!enable && (ctrl & SDHCI_CTRL_PRESET_VAL_ENABLE)) {
1797 ctrl &= ~SDHCI_CTRL_PRESET_VAL_ENABLE; 1866 ctrl &= ~SDHCI_CTRL_PRESET_VAL_ENABLE;
1798 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); 1867 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1868 host->flags &= ~SDHCI_PV_ENABLED;
1799 } 1869 }
1800 1870
1801 spin_unlock_irqrestore(&host->lock, flags); 1871 spin_unlock_irqrestore(&host->lock, flags);
1802} 1872}
1803 1873
1874static void sdhci_enable_preset_value(struct mmc_host *mmc, bool enable)
1875{
1876 struct sdhci_host *host = mmc_priv(mmc);
1877
1878 sdhci_runtime_pm_get(host);
1879 sdhci_do_enable_preset_value(host, enable);
1880 sdhci_runtime_pm_put(host);
1881}
1882
1804static const struct mmc_host_ops sdhci_ops = { 1883static const struct mmc_host_ops sdhci_ops = {
1805 .request = sdhci_request, 1884 .request = sdhci_request,
1806 .set_ios = sdhci_set_ios, 1885 .set_ios = sdhci_set_ios,
1807 .get_ro = sdhci_get_ro, 1886 .get_ro = sdhci_get_ro,
1887 .hw_reset = sdhci_hw_reset,
1808 .enable_sdio_irq = sdhci_enable_sdio_irq, 1888 .enable_sdio_irq = sdhci_enable_sdio_irq,
1809 .start_signal_voltage_switch = sdhci_start_signal_voltage_switch, 1889 .start_signal_voltage_switch = sdhci_start_signal_voltage_switch,
1810 .execute_tuning = sdhci_execute_tuning, 1890 .execute_tuning = sdhci_execute_tuning,
@@ -1826,19 +1906,19 @@ static void sdhci_tasklet_card(unsigned long param)
1826 1906
1827 spin_lock_irqsave(&host->lock, flags); 1907 spin_lock_irqsave(&host->lock, flags);
1828 1908
1829 if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) { 1909 /* Check host->mrq first in case we are runtime suspended */
1830 if (host->mrq) { 1910 if (host->mrq &&
1831 printk(KERN_ERR "%s: Card removed during transfer!\n", 1911 !(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
1832 mmc_hostname(host->mmc)); 1912 pr_err("%s: Card removed during transfer!\n",
1833 printk(KERN_ERR "%s: Resetting controller.\n", 1913 mmc_hostname(host->mmc));
1834 mmc_hostname(host->mmc)); 1914 pr_err("%s: Resetting controller.\n",
1915 mmc_hostname(host->mmc));
1835 1916
1836 sdhci_reset(host, SDHCI_RESET_CMD); 1917 sdhci_reset(host, SDHCI_RESET_CMD);
1837 sdhci_reset(host, SDHCI_RESET_DATA); 1918 sdhci_reset(host, SDHCI_RESET_DATA);
1838 1919
1839 host->mrq->cmd->error = -ENOMEDIUM; 1920 host->mrq->cmd->error = -ENOMEDIUM;
1840 tasklet_schedule(&host->finish_tasklet); 1921 tasklet_schedule(&host->finish_tasklet);
1841 }
1842 } 1922 }
1843 1923
1844 spin_unlock_irqrestore(&host->lock, flags); 1924 spin_unlock_irqrestore(&host->lock, flags);
@@ -1854,14 +1934,16 @@ static void sdhci_tasklet_finish(unsigned long param)
1854 1934
1855 host = (struct sdhci_host*)param; 1935 host = (struct sdhci_host*)param;
1856 1936
1937 spin_lock_irqsave(&host->lock, flags);
1938
1857 /* 1939 /*
1858 * If this tasklet gets rescheduled while running, it will 1940 * If this tasklet gets rescheduled while running, it will
1859 * be run again afterwards but without any active request. 1941 * be run again afterwards but without any active request.
1860 */ 1942 */
1861 if (!host->mrq) 1943 if (!host->mrq) {
1944 spin_unlock_irqrestore(&host->lock, flags);
1862 return; 1945 return;
1863 1946 }
1864 spin_lock_irqsave(&host->lock, flags);
1865 1947
1866 del_timer(&host->timer); 1948 del_timer(&host->timer);
1867 1949
@@ -1905,6 +1987,7 @@ static void sdhci_tasklet_finish(unsigned long param)
1905 spin_unlock_irqrestore(&host->lock, flags); 1987 spin_unlock_irqrestore(&host->lock, flags);
1906 1988
1907 mmc_request_done(host->mmc, mrq); 1989 mmc_request_done(host->mmc, mrq);
1990 sdhci_runtime_pm_put(host);
1908} 1991}
1909 1992
1910static void sdhci_timeout_timer(unsigned long data) 1993static void sdhci_timeout_timer(unsigned long data)
@@ -1917,7 +2000,7 @@ static void sdhci_timeout_timer(unsigned long data)
1917 spin_lock_irqsave(&host->lock, flags); 2000 spin_lock_irqsave(&host->lock, flags);
1918 2001
1919 if (host->mrq) { 2002 if (host->mrq) {
1920 printk(KERN_ERR "%s: Timeout waiting for hardware " 2003 pr_err("%s: Timeout waiting for hardware "
1921 "interrupt.\n", mmc_hostname(host->mmc)); 2004 "interrupt.\n", mmc_hostname(host->mmc));
1922 sdhci_dumpregs(host); 2005 sdhci_dumpregs(host);
1923 2006
@@ -1963,7 +2046,7 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
1963 BUG_ON(intmask == 0); 2046 BUG_ON(intmask == 0);
1964 2047
1965 if (!host->cmd) { 2048 if (!host->cmd) {
1966 printk(KERN_ERR "%s: Got command interrupt 0x%08x even " 2049 pr_err("%s: Got command interrupt 0x%08x even "
1967 "though no command operation was in progress.\n", 2050 "though no command operation was in progress.\n",
1968 mmc_hostname(host->mmc), (unsigned)intmask); 2051 mmc_hostname(host->mmc), (unsigned)intmask);
1969 sdhci_dumpregs(host); 2052 sdhci_dumpregs(host);
@@ -2063,7 +2146,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
2063 } 2146 }
2064 } 2147 }
2065 2148
2066 printk(KERN_ERR "%s: Got data interrupt 0x%08x even " 2149 pr_err("%s: Got data interrupt 0x%08x even "
2067 "though no data operation was in progress.\n", 2150 "though no data operation was in progress.\n",
2068 mmc_hostname(host->mmc), (unsigned)intmask); 2151 mmc_hostname(host->mmc), (unsigned)intmask);
2069 sdhci_dumpregs(host); 2152 sdhci_dumpregs(host);
@@ -2080,7 +2163,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
2080 != MMC_BUS_TEST_R) 2163 != MMC_BUS_TEST_R)
2081 host->data->error = -EILSEQ; 2164 host->data->error = -EILSEQ;
2082 else if (intmask & SDHCI_INT_ADMA_ERROR) { 2165 else if (intmask & SDHCI_INT_ADMA_ERROR) {
2083 printk(KERN_ERR "%s: ADMA error\n", mmc_hostname(host->mmc)); 2166 pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
2084 sdhci_show_adma_error(host); 2167 sdhci_show_adma_error(host);
2085 host->data->error = -EIO; 2168 host->data->error = -EIO;
2086 } 2169 }
@@ -2136,12 +2219,19 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
2136static irqreturn_t sdhci_irq(int irq, void *dev_id) 2219static irqreturn_t sdhci_irq(int irq, void *dev_id)
2137{ 2220{
2138 irqreturn_t result; 2221 irqreturn_t result;
2139 struct sdhci_host* host = dev_id; 2222 struct sdhci_host *host = dev_id;
2140 u32 intmask; 2223 u32 intmask;
2141 int cardint = 0; 2224 int cardint = 0;
2142 2225
2143 spin_lock(&host->lock); 2226 spin_lock(&host->lock);
2144 2227
2228 if (host->runtime_suspended) {
2229 spin_unlock(&host->lock);
2230 pr_warning("%s: got irq while runtime suspended\n",
2231 mmc_hostname(host->mmc));
2232 return IRQ_HANDLED;
2233 }
2234
2145 intmask = sdhci_readl(host, SDHCI_INT_STATUS); 2235 intmask = sdhci_readl(host, SDHCI_INT_STATUS);
2146 2236
2147 if (!intmask || intmask == 0xffffffff) { 2237 if (!intmask || intmask == 0xffffffff) {
@@ -2194,7 +2284,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
2194 intmask &= ~SDHCI_INT_ERROR; 2284 intmask &= ~SDHCI_INT_ERROR;
2195 2285
2196 if (intmask & SDHCI_INT_BUS_POWER) { 2286 if (intmask & SDHCI_INT_BUS_POWER) {
2197 printk(KERN_ERR "%s: Card is consuming too much power!\n", 2287 pr_err("%s: Card is consuming too much power!\n",
2198 mmc_hostname(host->mmc)); 2288 mmc_hostname(host->mmc));
2199 sdhci_writel(host, SDHCI_INT_BUS_POWER, SDHCI_INT_STATUS); 2289 sdhci_writel(host, SDHCI_INT_BUS_POWER, SDHCI_INT_STATUS);
2200 } 2290 }
@@ -2207,7 +2297,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
2207 intmask &= ~SDHCI_INT_CARD_INT; 2297 intmask &= ~SDHCI_INT_CARD_INT;
2208 2298
2209 if (intmask) { 2299 if (intmask) {
2210 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n", 2300 pr_err("%s: Unexpected interrupt 0x%08x.\n",
2211 mmc_hostname(host->mmc), intmask); 2301 mmc_hostname(host->mmc), intmask);
2212 sdhci_dumpregs(host); 2302 sdhci_dumpregs(host);
2213 2303
@@ -2275,7 +2365,6 @@ int sdhci_resume_host(struct sdhci_host *host)
2275 return ret; 2365 return ret;
2276 } 2366 }
2277 2367
2278
2279 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 2368 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
2280 if (host->ops->enable_dma) 2369 if (host->ops->enable_dma)
2281 host->ops->enable_dma(host); 2370 host->ops->enable_dma(host);
@@ -2314,6 +2403,90 @@ EXPORT_SYMBOL_GPL(sdhci_enable_irq_wakeups);
2314 2403
2315#endif /* CONFIG_PM */ 2404#endif /* CONFIG_PM */
2316 2405
2406#ifdef CONFIG_PM_RUNTIME
2407
2408static int sdhci_runtime_pm_get(struct sdhci_host *host)
2409{
2410 return pm_runtime_get_sync(host->mmc->parent);
2411}
2412
2413static int sdhci_runtime_pm_put(struct sdhci_host *host)
2414{
2415 pm_runtime_mark_last_busy(host->mmc->parent);
2416 return pm_runtime_put_autosuspend(host->mmc->parent);
2417}
2418
2419int sdhci_runtime_suspend_host(struct sdhci_host *host)
2420{
2421 unsigned long flags;
2422 int ret = 0;
2423
2424 /* Disable tuning since we are suspending */
2425 if (host->version >= SDHCI_SPEC_300 &&
2426 host->tuning_mode == SDHCI_TUNING_MODE_1) {
2427 del_timer_sync(&host->tuning_timer);
2428 host->flags &= ~SDHCI_NEEDS_RETUNING;
2429 }
2430
2431 spin_lock_irqsave(&host->lock, flags);
2432 sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
2433 spin_unlock_irqrestore(&host->lock, flags);
2434
2435 synchronize_irq(host->irq);
2436
2437 spin_lock_irqsave(&host->lock, flags);
2438 host->runtime_suspended = true;
2439 spin_unlock_irqrestore(&host->lock, flags);
2440
2441 return ret;
2442}
2443EXPORT_SYMBOL_GPL(sdhci_runtime_suspend_host);
2444
2445int sdhci_runtime_resume_host(struct sdhci_host *host)
2446{
2447 unsigned long flags;
2448 int ret = 0, host_flags = host->flags;
2449
2450 if (host_flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
2451 if (host->ops->enable_dma)
2452 host->ops->enable_dma(host);
2453 }
2454
2455 sdhci_init(host, 0);
2456
2457 /* Force clock and power re-program */
2458 host->pwr = 0;
2459 host->clock = 0;
2460 sdhci_do_set_ios(host, &host->mmc->ios);
2461
2462 sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
2463 if (host_flags & SDHCI_PV_ENABLED)
2464 sdhci_do_enable_preset_value(host, true);
2465
2466 /* Set the re-tuning expiration flag */
2467 if ((host->version >= SDHCI_SPEC_300) && host->tuning_count &&
2468 (host->tuning_mode == SDHCI_TUNING_MODE_1))
2469 host->flags |= SDHCI_NEEDS_RETUNING;
2470
2471 spin_lock_irqsave(&host->lock, flags);
2472
2473 host->runtime_suspended = false;
2474
2475 /* Enable SDIO IRQ */
2476 if ((host->flags & SDHCI_SDIO_IRQ_ENABLED))
2477 sdhci_enable_sdio_irq_nolock(host, true);
2478
2479 /* Enable Card Detection */
2480 sdhci_enable_card_detection(host);
2481
2482 spin_unlock_irqrestore(&host->lock, flags);
2483
2484 return ret;
2485}
2486EXPORT_SYMBOL_GPL(sdhci_runtime_resume_host);
2487
2488#endif
2489
2317/*****************************************************************************\ 2490/*****************************************************************************\
2318 * * 2491 * *
2319 * Device allocation/registration * 2492 * Device allocation/registration *
@@ -2356,6 +2529,8 @@ int sdhci_add_host(struct sdhci_host *host)
2356 2529
2357 if (debug_quirks) 2530 if (debug_quirks)
2358 host->quirks = debug_quirks; 2531 host->quirks = debug_quirks;
2532 if (debug_quirks2)
2533 host->quirks2 = debug_quirks2;
2359 2534
2360 sdhci_reset(host, SDHCI_RESET_ALL); 2535 sdhci_reset(host, SDHCI_RESET_ALL);
2361 2536
@@ -2363,7 +2538,7 @@ int sdhci_add_host(struct sdhci_host *host)
2363 host->version = (host->version & SDHCI_SPEC_VER_MASK) 2538 host->version = (host->version & SDHCI_SPEC_VER_MASK)
2364 >> SDHCI_SPEC_VER_SHIFT; 2539 >> SDHCI_SPEC_VER_SHIFT;
2365 if (host->version > SDHCI_SPEC_300) { 2540 if (host->version > SDHCI_SPEC_300) {
2366 printk(KERN_ERR "%s: Unknown controller version (%d). " 2541 pr_err("%s: Unknown controller version (%d). "
2367 "You may experience problems.\n", mmc_hostname(mmc), 2542 "You may experience problems.\n", mmc_hostname(mmc),
2368 host->version); 2543 host->version);
2369 } 2544 }
@@ -2400,7 +2575,7 @@ int sdhci_add_host(struct sdhci_host *host)
2400 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 2575 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
2401 if (host->ops->enable_dma) { 2576 if (host->ops->enable_dma) {
2402 if (host->ops->enable_dma(host)) { 2577 if (host->ops->enable_dma(host)) {
2403 printk(KERN_WARNING "%s: No suitable DMA " 2578 pr_warning("%s: No suitable DMA "
2404 "available. Falling back to PIO.\n", 2579 "available. Falling back to PIO.\n",
2405 mmc_hostname(mmc)); 2580 mmc_hostname(mmc));
2406 host->flags &= 2581 host->flags &=
@@ -2420,7 +2595,7 @@ int sdhci_add_host(struct sdhci_host *host)
2420 if (!host->adma_desc || !host->align_buffer) { 2595 if (!host->adma_desc || !host->align_buffer) {
2421 kfree(host->adma_desc); 2596 kfree(host->adma_desc);
2422 kfree(host->align_buffer); 2597 kfree(host->align_buffer);
2423 printk(KERN_WARNING "%s: Unable to allocate ADMA " 2598 pr_warning("%s: Unable to allocate ADMA "
2424 "buffers. Falling back to standard DMA.\n", 2599 "buffers. Falling back to standard DMA.\n",
2425 mmc_hostname(mmc)); 2600 mmc_hostname(mmc));
2426 host->flags &= ~SDHCI_USE_ADMA; 2601 host->flags &= ~SDHCI_USE_ADMA;
@@ -2448,8 +2623,7 @@ int sdhci_add_host(struct sdhci_host *host)
2448 if (host->max_clk == 0 || host->quirks & 2623 if (host->max_clk == 0 || host->quirks &
2449 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN) { 2624 SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN) {
2450 if (!host->ops->get_max_clock) { 2625 if (!host->ops->get_max_clock) {
2451 printk(KERN_ERR 2626 pr_err("%s: Hardware doesn't specify base clock "
2452 "%s: Hardware doesn't specify base clock "
2453 "frequency.\n", mmc_hostname(mmc)); 2627 "frequency.\n", mmc_hostname(mmc));
2454 return -ENODEV; 2628 return -ENODEV;
2455 } 2629 }
@@ -2495,8 +2669,7 @@ int sdhci_add_host(struct sdhci_host *host)
2495 host->timeout_clk = host->ops->get_timeout_clock(host); 2669 host->timeout_clk = host->ops->get_timeout_clock(host);
2496 } else if (!(host->quirks & 2670 } else if (!(host->quirks &
2497 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { 2671 SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) {
2498 printk(KERN_ERR 2672 pr_err("%s: Hardware doesn't specify timeout clock "
2499 "%s: Hardware doesn't specify timeout clock "
2500 "frequency.\n", mmc_hostname(mmc)); 2673 "frequency.\n", mmc_hostname(mmc));
2501 return -ENODEV; 2674 return -ENODEV;
2502 } 2675 }
@@ -2566,6 +2739,15 @@ int sdhci_add_host(struct sdhci_host *host)
2566 if (caps[1] & SDHCI_DRIVER_TYPE_D) 2739 if (caps[1] & SDHCI_DRIVER_TYPE_D)
2567 mmc->caps |= MMC_CAP_DRIVER_TYPE_D; 2740 mmc->caps |= MMC_CAP_DRIVER_TYPE_D;
2568 2741
2742 /*
2743 * If Power Off Notify capability is enabled by the host,
2744 * set notify to short power off notify timeout value.
2745 */
2746 if (mmc->caps2 & MMC_CAP2_POWEROFF_NOTIFY)
2747 mmc->power_notify_type = MMC_HOST_PW_NOTIFY_SHORT;
2748 else
2749 mmc->power_notify_type = MMC_HOST_PW_NOTIFY_NONE;
2750
2569 /* Initial value for re-tuning timer count */ 2751 /* Initial value for re-tuning timer count */
2570 host->tuning_count = (caps[1] & SDHCI_RETUNING_TIMER_COUNT_MASK) >> 2752 host->tuning_count = (caps[1] & SDHCI_RETUNING_TIMER_COUNT_MASK) >>
2571 SDHCI_RETUNING_TIMER_COUNT_SHIFT; 2753 SDHCI_RETUNING_TIMER_COUNT_SHIFT;
@@ -2655,7 +2837,7 @@ int sdhci_add_host(struct sdhci_host *host)
2655 mmc->ocr_avail_mmc &= host->ocr_avail_mmc; 2837 mmc->ocr_avail_mmc &= host->ocr_avail_mmc;
2656 2838
2657 if (mmc->ocr_avail == 0) { 2839 if (mmc->ocr_avail == 0) {
2658 printk(KERN_ERR "%s: Hardware doesn't report any " 2840 pr_err("%s: Hardware doesn't report any "
2659 "support voltages.\n", mmc_hostname(mmc)); 2841 "support voltages.\n", mmc_hostname(mmc));
2660 return -ENODEV; 2842 return -ENODEV;
2661 } 2843 }
@@ -2703,7 +2885,7 @@ int sdhci_add_host(struct sdhci_host *host)
2703 mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >> 2885 mmc->max_blk_size = (caps[0] & SDHCI_MAX_BLOCK_MASK) >>
2704 SDHCI_MAX_BLOCK_SHIFT; 2886 SDHCI_MAX_BLOCK_SHIFT;
2705 if (mmc->max_blk_size >= 3) { 2887 if (mmc->max_blk_size >= 3) {
2706 printk(KERN_WARNING "%s: Invalid maximum block size, " 2888 pr_warning("%s: Invalid maximum block size, "
2707 "assuming 512 bytes\n", mmc_hostname(mmc)); 2889 "assuming 512 bytes\n", mmc_hostname(mmc));
2708 mmc->max_blk_size = 0; 2890 mmc->max_blk_size = 0;
2709 } 2891 }
@@ -2742,7 +2924,7 @@ int sdhci_add_host(struct sdhci_host *host)
2742 2924
2743 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc"); 2925 host->vmmc = regulator_get(mmc_dev(mmc), "vmmc");
2744 if (IS_ERR(host->vmmc)) { 2926 if (IS_ERR(host->vmmc)) {
2745 printk(KERN_INFO "%s: no vmmc regulator found\n", mmc_hostname(mmc)); 2927 pr_info("%s: no vmmc regulator found\n", mmc_hostname(mmc));
2746 host->vmmc = NULL; 2928 host->vmmc = NULL;
2747 } else { 2929 } else {
2748 regulator_enable(host->vmmc); 2930 regulator_enable(host->vmmc);
@@ -2771,7 +2953,7 @@ int sdhci_add_host(struct sdhci_host *host)
2771 2953
2772 mmc_add_host(mmc); 2954 mmc_add_host(mmc);
2773 2955
2774 printk(KERN_INFO "%s: SDHCI controller on %s [%s] using %s\n", 2956 pr_info("%s: SDHCI controller on %s [%s] using %s\n",
2775 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), 2957 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
2776 (host->flags & SDHCI_USE_ADMA) ? "ADMA" : 2958 (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
2777 (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"); 2959 (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
@@ -2804,7 +2986,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
2804 host->flags |= SDHCI_DEVICE_DEAD; 2986 host->flags |= SDHCI_DEVICE_DEAD;
2805 2987
2806 if (host->mrq) { 2988 if (host->mrq) {
2807 printk(KERN_ERR "%s: Controller removed during " 2989 pr_err("%s: Controller removed during "
2808 " transfer!\n", mmc_hostname(host->mmc)); 2990 " transfer!\n", mmc_hostname(host->mmc));
2809 2991
2810 host->mrq->cmd->error = -ENOMEDIUM; 2992 host->mrq->cmd->error = -ENOMEDIUM;
@@ -2863,9 +3045,9 @@ EXPORT_SYMBOL_GPL(sdhci_free_host);
2863 3045
2864static int __init sdhci_drv_init(void) 3046static int __init sdhci_drv_init(void)
2865{ 3047{
2866 printk(KERN_INFO DRIVER_NAME 3048 pr_info(DRIVER_NAME
2867 ": Secure Digital Host Controller Interface driver\n"); 3049 ": Secure Digital Host Controller Interface driver\n");
2868 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); 3050 pr_info(DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
2869 3051
2870 return 0; 3052 return 0;
2871} 3053}
@@ -2878,9 +3060,11 @@ module_init(sdhci_drv_init);
2878module_exit(sdhci_drv_exit); 3060module_exit(sdhci_drv_exit);
2879 3061
2880module_param(debug_quirks, uint, 0444); 3062module_param(debug_quirks, uint, 0444);
3063module_param(debug_quirks2, uint, 0444);
2881 3064
2882MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>"); 3065MODULE_AUTHOR("Pierre Ossman <pierre@ossman.eu>");
2883MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver"); 3066MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");
2884MODULE_LICENSE("GPL"); 3067MODULE_LICENSE("GPL");
2885 3068
2886MODULE_PARM_DESC(debug_quirks, "Force certain quirks."); 3069MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");
3070MODULE_PARM_DESC(debug_quirks2, "Force certain other quirks.");
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 745c42fa41ed..0a5b65460d8a 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -273,7 +273,7 @@ struct sdhci_ops {
273 void (*platform_reset_enter)(struct sdhci_host *host, u8 mask); 273 void (*platform_reset_enter)(struct sdhci_host *host, u8 mask);
274 void (*platform_reset_exit)(struct sdhci_host *host, u8 mask); 274 void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
275 int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs); 275 int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
276 276 void (*hw_reset)(struct sdhci_host *host);
277}; 277};
278 278
279#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS 279#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
@@ -379,4 +379,9 @@ extern int sdhci_resume_host(struct sdhci_host *host);
379extern void sdhci_enable_irq_wakeups(struct sdhci_host *host); 379extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
380#endif 380#endif
381 381
382#ifdef CONFIG_PM_RUNTIME
383extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
384extern int sdhci_runtime_resume_host(struct sdhci_host *host);
385#endif
386
382#endif /* __SDHCI_HW_H */ 387#endif /* __SDHCI_HW_H */
diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c
index 496b7efbc6b0..7009f17ad6cd 100644
--- a/drivers/mmc/host/sdricoh_cs.c
+++ b/drivers/mmc/host/sdricoh_cs.c
@@ -26,6 +26,7 @@
26*/ 26*/
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/highmem.h> 28#include <linux/highmem.h>
29#include <linux/module.h>
29#include <linux/pci.h> 30#include <linux/pci.h>
30#include <linux/ioport.h> 31#include <linux/ioport.h>
31#include <linux/scatterlist.h> 32#include <linux/scatterlist.h>
diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 557886bee9ce..369366c8e205 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -31,6 +31,7 @@
31#include <linux/platform_device.h> 31#include <linux/platform_device.h>
32#include <linux/pm_runtime.h> 32#include <linux/pm_runtime.h>
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/module.h>
34 35
35#define DRIVER_NAME "sh_mmcif" 36#define DRIVER_NAME "sh_mmcif"
36#define DRIVER_VERSION "2010-04-28" 37#define DRIVER_VERSION "2010-04-28"
@@ -165,6 +166,8 @@ struct sh_mmcif_host {
165 struct mmc_host *mmc; 166 struct mmc_host *mmc;
166 struct mmc_data *data; 167 struct mmc_data *data;
167 struct platform_device *pd; 168 struct platform_device *pd;
169 struct sh_dmae_slave dma_slave_tx;
170 struct sh_dmae_slave dma_slave_rx;
168 struct clk *hclk; 171 struct clk *hclk;
169 unsigned int clk; 172 unsigned int clk;
170 int bus_width; 173 int bus_width;
@@ -323,25 +326,35 @@ static bool sh_mmcif_filter(struct dma_chan *chan, void *arg)
323static void sh_mmcif_request_dma(struct sh_mmcif_host *host, 326static void sh_mmcif_request_dma(struct sh_mmcif_host *host,
324 struct sh_mmcif_plat_data *pdata) 327 struct sh_mmcif_plat_data *pdata)
325{ 328{
329 struct sh_dmae_slave *tx, *rx;
326 host->dma_active = false; 330 host->dma_active = false;
327 331
328 /* We can only either use DMA for both Tx and Rx or not use it at all */ 332 /* We can only either use DMA for both Tx and Rx or not use it at all */
329 if (pdata->dma) { 333 if (pdata->dma) {
334 dev_warn(&host->pd->dev,
335 "Update your platform to use embedded DMA slave IDs\n");
336 tx = &pdata->dma->chan_priv_tx;
337 rx = &pdata->dma->chan_priv_rx;
338 } else {
339 tx = &host->dma_slave_tx;
340 tx->slave_id = pdata->slave_id_tx;
341 rx = &host->dma_slave_rx;
342 rx->slave_id = pdata->slave_id_rx;
343 }
344 if (tx->slave_id > 0 && rx->slave_id > 0) {
330 dma_cap_mask_t mask; 345 dma_cap_mask_t mask;
331 346
332 dma_cap_zero(mask); 347 dma_cap_zero(mask);
333 dma_cap_set(DMA_SLAVE, mask); 348 dma_cap_set(DMA_SLAVE, mask);
334 349
335 host->chan_tx = dma_request_channel(mask, sh_mmcif_filter, 350 host->chan_tx = dma_request_channel(mask, sh_mmcif_filter, tx);
336 &pdata->dma->chan_priv_tx);
337 dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__, 351 dev_dbg(&host->pd->dev, "%s: TX: got channel %p\n", __func__,
338 host->chan_tx); 352 host->chan_tx);
339 353
340 if (!host->chan_tx) 354 if (!host->chan_tx)
341 return; 355 return;
342 356
343 host->chan_rx = dma_request_channel(mask, sh_mmcif_filter, 357 host->chan_rx = dma_request_channel(mask, sh_mmcif_filter, rx);
344 &pdata->dma->chan_priv_rx);
345 dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__, 358 dev_dbg(&host->pd->dev, "%s: RX: got channel %p\n", __func__,
346 host->chan_rx); 359 host->chan_rx);
347 360
diff --git a/drivers/mmc/host/sh_mobile_sdhi.c b/drivers/mmc/host/sh_mobile_sdhi.c
index 0c4a672f5db6..41ae6466bd83 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/module.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
25#include <linux/mmc/host.h> 26#include <linux/mmc/host.h>
26#include <linux/mmc/sh_mobile_sdhi.h> 27#include <linux/mmc/sh_mobile_sdhi.h>
@@ -96,7 +97,8 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
96 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 97 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
97 struct tmio_mmc_host *host; 98 struct tmio_mmc_host *host;
98 char clk_name[8]; 99 char clk_name[8];
99 int i, irq, ret; 100 int irq, ret, i = 0;
101 bool multiplexed_isr = true;
100 102
101 priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL); 103 priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
102 if (priv == NULL) { 104 if (priv == NULL) {
@@ -153,27 +155,60 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
153 if (ret < 0) 155 if (ret < 0)
154 goto eprobe; 156 goto eprobe;
155 157
156 for (i = 0; i < 3; i++) { 158 /*
157 irq = platform_get_irq(pdev, i); 159 * Allow one or more specific (named) ISRs or
158 if (irq < 0) { 160 * one or more multiplexed (un-named) ISRs.
159 if (i) { 161 */
160 continue; 162
161 } else { 163 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT);
162 ret = irq; 164 if (irq >= 0) {
163 goto eirq; 165 multiplexed_isr = false;
164 } 166 ret = request_irq(irq, tmio_mmc_card_detect_irq, 0,
165 } 167 dev_name(&pdev->dev), host);
166 ret = request_irq(irq, tmio_mmc_irq, 0, 168 if (ret)
169 goto eirq_card_detect;
170 }
171
172 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO);
173 if (irq >= 0) {
174 multiplexed_isr = false;
175 ret = request_irq(irq, tmio_mmc_sdio_irq, 0,
176 dev_name(&pdev->dev), host);
177 if (ret)
178 goto eirq_sdio;
179 }
180
181 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDCARD);
182 if (irq >= 0) {
183 multiplexed_isr = false;
184 ret = request_irq(irq, tmio_mmc_sdcard_irq, 0,
167 dev_name(&pdev->dev), host); 185 dev_name(&pdev->dev), host);
168 if (ret) { 186 if (ret)
169 while (i--) { 187 goto eirq_sdcard;
170 irq = platform_get_irq(pdev, i); 188 } else if (!multiplexed_isr) {
171 if (irq >= 0) 189 dev_err(&pdev->dev,
172 free_irq(irq, host); 190 "Principal SD-card IRQ is missing among named interrupts\n");
173 } 191 ret = irq;
174 goto eirq; 192 goto eirq_sdcard;
193 }
194
195 if (multiplexed_isr) {
196 while (1) {
197 irq = platform_get_irq(pdev, i);
198 if (irq < 0)
199 break;
200 i++;
201 ret = request_irq(irq, tmio_mmc_irq, 0,
202 dev_name(&pdev->dev), host);
203 if (ret)
204 goto eirq_multiplexed;
175 } 205 }
206
207 /* There must be at least one IRQ source */
208 if (!i)
209 goto eirq_multiplexed;
176 } 210 }
211
177 dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n", 212 dev_info(&pdev->dev, "%s base at 0x%08lx clock rate %u MHz\n",
178 mmc_hostname(host->mmc), (unsigned long) 213 mmc_hostname(host->mmc), (unsigned long)
179 (platform_get_resource(pdev,IORESOURCE_MEM, 0)->start), 214 (platform_get_resource(pdev,IORESOURCE_MEM, 0)->start),
@@ -181,7 +216,20 @@ static int __devinit sh_mobile_sdhi_probe(struct platform_device *pdev)
181 216
182 return ret; 217 return ret;
183 218
184eirq: 219eirq_multiplexed:
220 while (i--) {
221 irq = platform_get_irq(pdev, i);
222 free_irq(irq, host);
223 }
224eirq_sdcard:
225 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_SDIO);
226 if (irq >= 0)
227 free_irq(irq, host);
228eirq_sdio:
229 irq = platform_get_irq_byname(pdev, SH_MOBILE_SDHI_IRQ_CARD_DETECT);
230 if (irq >= 0)
231 free_irq(irq, host);
232eirq_card_detect:
185 tmio_mmc_host_remove(host); 233 tmio_mmc_host_remove(host);
186eprobe: 234eprobe:
187 clk_disable(priv->clk); 235 clk_disable(priv->clk);
@@ -197,16 +245,17 @@ static int sh_mobile_sdhi_remove(struct platform_device *pdev)
197 struct tmio_mmc_host *host = mmc_priv(mmc); 245 struct tmio_mmc_host *host = mmc_priv(mmc);
198 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data); 246 struct sh_mobile_sdhi *priv = container_of(host->pdata, struct sh_mobile_sdhi, mmc_data);
199 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data; 247 struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
200 int i, irq; 248 int i = 0, irq;
201 249
202 p->pdata = NULL; 250 p->pdata = NULL;
203 251
204 tmio_mmc_host_remove(host); 252 tmio_mmc_host_remove(host);
205 253
206 for (i = 0; i < 3; i++) { 254 while (1) {
207 irq = platform_get_irq(pdev, i); 255 irq = platform_get_irq(pdev, i++);
208 if (irq >= 0) 256 if (irq < 0)
209 free_irq(irq, host); 257 break;
258 free_irq(irq, host);
210 } 259 }
211 260
212 clk_disable(priv->clk); 261 clk_disable(priv->clk);
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index 457c26ea09de..f70d04664cac 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -16,6 +16,7 @@
16#include <linux/mmc/host.h> 16#include <linux/mmc/host.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
19#include <linux/module.h>
19#include <asm/io.h> 20#include <asm/io.h>
20 21
21#define DRIVER_NAME "tifm_sd" 22#define DRIVER_NAME "tifm_sd"
@@ -631,7 +632,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
631 } 632 }
632 633
633 if (host->req) { 634 if (host->req) {
634 printk(KERN_ERR "%s : unfinished request detected\n", 635 pr_err("%s : unfinished request detected\n",
635 dev_name(&sock->dev)); 636 dev_name(&sock->dev));
636 mrq->cmd->error = -ETIMEDOUT; 637 mrq->cmd->error = -ETIMEDOUT;
637 goto err_out; 638 goto err_out;
@@ -671,7 +672,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
671 r_data->flags & MMC_DATA_WRITE 672 r_data->flags & MMC_DATA_WRITE
672 ? PCI_DMA_TODEVICE 673 ? PCI_DMA_TODEVICE
673 : PCI_DMA_FROMDEVICE)) { 674 : PCI_DMA_FROMDEVICE)) {
674 printk(KERN_ERR "%s : scatterlist map failed\n", 675 pr_err("%s : scatterlist map failed\n",
675 dev_name(&sock->dev)); 676 dev_name(&sock->dev));
676 mrq->cmd->error = -ENOMEM; 677 mrq->cmd->error = -ENOMEM;
677 goto err_out; 678 goto err_out;
@@ -683,7 +684,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
683 ? PCI_DMA_TODEVICE 684 ? PCI_DMA_TODEVICE
684 : PCI_DMA_FROMDEVICE); 685 : PCI_DMA_FROMDEVICE);
685 if (host->sg_len < 1) { 686 if (host->sg_len < 1) {
686 printk(KERN_ERR "%s : scatterlist map failed\n", 687 pr_err("%s : scatterlist map failed\n",
687 dev_name(&sock->dev)); 688 dev_name(&sock->dev));
688 tifm_unmap_sg(sock, &host->bounce_buf, 1, 689 tifm_unmap_sg(sock, &host->bounce_buf, 1,
689 r_data->flags & MMC_DATA_WRITE 690 r_data->flags & MMC_DATA_WRITE
@@ -747,7 +748,7 @@ static void tifm_sd_end_cmd(unsigned long data)
747 host->req = NULL; 748 host->req = NULL;
748 749
749 if (!mrq) { 750 if (!mrq) {
750 printk(KERN_ERR " %s : no request to complete?\n", 751 pr_err(" %s : no request to complete?\n",
751 dev_name(&sock->dev)); 752 dev_name(&sock->dev));
752 spin_unlock_irqrestore(&sock->lock, flags); 753 spin_unlock_irqrestore(&sock->lock, flags);
753 return; 754 return;
@@ -786,8 +787,7 @@ static void tifm_sd_abort(unsigned long data)
786{ 787{
787 struct tifm_sd *host = (struct tifm_sd*)data; 788 struct tifm_sd *host = (struct tifm_sd*)data;
788 789
789 printk(KERN_ERR 790 pr_err("%s : card failed to respond for a long period of time "
790 "%s : card failed to respond for a long period of time "
791 "(%x, %x)\n", 791 "(%x, %x)\n",
792 dev_name(&host->dev->dev), host->req->cmd->opcode, host->cmd_flags); 792 dev_name(&host->dev->dev), host->req->cmd->opcode, host->cmd_flags);
793 793
@@ -905,7 +905,7 @@ static int tifm_sd_initialize_host(struct tifm_sd *host)
905 } 905 }
906 906
907 if (rc) { 907 if (rc) {
908 printk(KERN_ERR "%s : controller failed to reset\n", 908 pr_err("%s : controller failed to reset\n",
909 dev_name(&sock->dev)); 909 dev_name(&sock->dev));
910 return -ENODEV; 910 return -ENODEV;
911 } 911 }
@@ -931,8 +931,7 @@ static int tifm_sd_initialize_host(struct tifm_sd *host)
931 } 931 }
932 932
933 if (rc) { 933 if (rc) {
934 printk(KERN_ERR 934 pr_err("%s : card not ready - probe failed on initialization\n",
935 "%s : card not ready - probe failed on initialization\n",
936 dev_name(&sock->dev)); 935 dev_name(&sock->dev));
937 return -ENODEV; 936 return -ENODEV;
938 } 937 }
@@ -953,7 +952,7 @@ static int tifm_sd_probe(struct tifm_dev *sock)
953 952
954 if (!(TIFM_SOCK_STATE_OCCUPIED 953 if (!(TIFM_SOCK_STATE_OCCUPIED
955 & readl(sock->addr + SOCK_PRESENT_STATE))) { 954 & readl(sock->addr + SOCK_PRESENT_STATE))) {
956 printk(KERN_WARNING "%s : card gone, unexpectedly\n", 955 pr_warning("%s : card gone, unexpectedly\n",
957 dev_name(&sock->dev)); 956 dev_name(&sock->dev));
958 return rc; 957 return rc;
959 } 958 }
diff --git a/drivers/mmc/host/tmio_mmc.c b/drivers/mmc/host/tmio_mmc.c
index 44a9668c4b7a..a4ea10242787 100644
--- a/drivers/mmc/host/tmio_mmc.c
+++ b/drivers/mmc/host/tmio_mmc.c
@@ -88,8 +88,8 @@ static int __devinit tmio_mmc_probe(struct platform_device *pdev)
88 if (ret) 88 if (ret)
89 goto cell_disable; 89 goto cell_disable;
90 90
91 ret = request_irq(irq, tmio_mmc_irq, IRQF_DISABLED | 91 ret = request_irq(irq, tmio_mmc_irq, IRQF_TRIGGER_FALLING,
92 IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), host); 92 dev_name(&pdev->dev), host);
93 if (ret) 93 if (ret)
94 goto host_remove; 94 goto host_remove;
95 95
diff --git a/drivers/mmc/host/tmio_mmc.h b/drivers/mmc/host/tmio_mmc.h
index eeaf64391fbe..3020f98218f0 100644
--- a/drivers/mmc/host/tmio_mmc.h
+++ b/drivers/mmc/host/tmio_mmc.h
@@ -79,6 +79,10 @@ struct tmio_mmc_host {
79 struct delayed_work delayed_reset_work; 79 struct delayed_work delayed_reset_work;
80 struct work_struct done; 80 struct work_struct done;
81 81
82 /* Cache IRQ mask */
83 u32 sdcard_irq_mask;
84 u32 sdio_irq_mask;
85
82 spinlock_t lock; /* protect host private data */ 86 spinlock_t lock; /* protect host private data */
83 unsigned long last_req_ts; 87 unsigned long last_req_ts;
84 struct mutex ios_lock; /* protect set_ios() context */ 88 struct mutex ios_lock; /* protect set_ios() context */
@@ -93,6 +97,9 @@ void tmio_mmc_do_data_irq(struct tmio_mmc_host *host);
93void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i); 97void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
94void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i); 98void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i);
95irqreturn_t tmio_mmc_irq(int irq, void *devid); 99irqreturn_t tmio_mmc_irq(int irq, void *devid);
100irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid);
101irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid);
102irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid);
96 103
97static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg, 104static inline char *tmio_mmc_kmap_atomic(struct scatterlist *sg,
98 unsigned long *flags) 105 unsigned long *flags)
diff --git a/drivers/mmc/host/tmio_mmc_pio.c b/drivers/mmc/host/tmio_mmc_pio.c
index 1f16357e7301..d85a60cda167 100644
--- a/drivers/mmc/host/tmio_mmc_pio.c
+++ b/drivers/mmc/host/tmio_mmc_pio.c
@@ -48,14 +48,14 @@
48 48
49void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i) 49void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
50{ 50{
51 u32 mask = sd_ctrl_read32(host, CTL_IRQ_MASK) & ~(i & TMIO_MASK_IRQ); 51 host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ);
52 sd_ctrl_write32(host, CTL_IRQ_MASK, mask); 52 sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
53} 53}
54 54
55void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i) 55void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
56{ 56{
57 u32 mask = sd_ctrl_read32(host, CTL_IRQ_MASK) | (i & TMIO_MASK_IRQ); 57 host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ);
58 sd_ctrl_write32(host, CTL_IRQ_MASK, mask); 58 sd_ctrl_write32(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
59} 59}
60 60
61static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i) 61static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i)
@@ -92,7 +92,7 @@ static int tmio_mmc_next_sg(struct tmio_mmc_host *host)
92static void pr_debug_status(u32 status) 92static void pr_debug_status(u32 status)
93{ 93{
94 int i = 0; 94 int i = 0;
95 printk(KERN_DEBUG "status: %08x = ", status); 95 pr_debug("status: %08x = ", status);
96 STATUS_TO_TEXT(CARD_REMOVE, status, i); 96 STATUS_TO_TEXT(CARD_REMOVE, status, i);
97 STATUS_TO_TEXT(CARD_INSERT, status, i); 97 STATUS_TO_TEXT(CARD_INSERT, status, i);
98 STATUS_TO_TEXT(SIGSTATE, status, i); 98 STATUS_TO_TEXT(SIGSTATE, status, i);
@@ -127,11 +127,13 @@ static void tmio_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
127 127
128 if (enable) { 128 if (enable) {
129 host->sdio_irq_enabled = 1; 129 host->sdio_irq_enabled = 1;
130 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL &
131 ~TMIO_SDIO_STAT_IOIRQ;
130 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001); 132 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001);
131 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, 133 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
132 (TMIO_SDIO_MASK_ALL & ~TMIO_SDIO_STAT_IOIRQ));
133 } else { 134 } else {
134 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, TMIO_SDIO_MASK_ALL); 135 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
136 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
135 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000); 137 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000);
136 host->sdio_irq_enabled = 0; 138 host->sdio_irq_enabled = 0;
137 } 139 }
@@ -543,45 +545,20 @@ out:
543 spin_unlock(&host->lock); 545 spin_unlock(&host->lock);
544} 546}
545 547
546irqreturn_t tmio_mmc_irq(int irq, void *devid) 548static void tmio_mmc_card_irq_status(struct tmio_mmc_host *host,
549 int *ireg, int *status)
547{ 550{
548 struct tmio_mmc_host *host = devid; 551 *status = sd_ctrl_read32(host, CTL_STATUS);
549 struct mmc_host *mmc = host->mmc; 552 *ireg = *status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask;
550 struct tmio_mmc_data *pdata = host->pdata;
551 unsigned int ireg, irq_mask, status;
552 unsigned int sdio_ireg, sdio_irq_mask, sdio_status;
553
554 pr_debug("MMC IRQ begin\n");
555
556 status = sd_ctrl_read32(host, CTL_STATUS);
557 irq_mask = sd_ctrl_read32(host, CTL_IRQ_MASK);
558 ireg = status & TMIO_MASK_IRQ & ~irq_mask;
559
560 sdio_ireg = 0;
561 if (!ireg && pdata->flags & TMIO_MMC_SDIO_IRQ) {
562 sdio_status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
563 sdio_irq_mask = sd_ctrl_read16(host, CTL_SDIO_IRQ_MASK);
564 sdio_ireg = sdio_status & TMIO_SDIO_MASK_ALL & ~sdio_irq_mask;
565 553
566 sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status & ~TMIO_SDIO_MASK_ALL); 554 pr_debug_status(*status);
567 555 pr_debug_status(*ireg);
568 if (sdio_ireg && !host->sdio_irq_enabled) { 556}
569 pr_warning("tmio_mmc: Spurious SDIO IRQ, disabling! 0x%04x 0x%04x 0x%04x\n",
570 sdio_status, sdio_irq_mask, sdio_ireg);
571 tmio_mmc_enable_sdio_irq(mmc, 0);
572 goto out;
573 }
574
575 if (mmc->caps & MMC_CAP_SDIO_IRQ &&
576 sdio_ireg & TMIO_SDIO_STAT_IOIRQ)
577 mmc_signal_sdio_irq(mmc);
578
579 if (sdio_ireg)
580 goto out;
581 }
582 557
583 pr_debug_status(status); 558static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host,
584 pr_debug_status(ireg); 559 int ireg, int status)
560{
561 struct mmc_host *mmc = host->mmc;
585 562
586 /* Card insert / remove attempts */ 563 /* Card insert / remove attempts */
587 if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)) { 564 if (ireg & (TMIO_STAT_CARD_INSERT | TMIO_STAT_CARD_REMOVE)) {
@@ -591,43 +568,102 @@ irqreturn_t tmio_mmc_irq(int irq, void *devid)
591 ((ireg & TMIO_STAT_CARD_INSERT) && !mmc->card)) && 568 ((ireg & TMIO_STAT_CARD_INSERT) && !mmc->card)) &&
592 !work_pending(&mmc->detect.work)) 569 !work_pending(&mmc->detect.work))
593 mmc_detect_change(host->mmc, msecs_to_jiffies(100)); 570 mmc_detect_change(host->mmc, msecs_to_jiffies(100));
594 goto out; 571 return true;
595 } 572 }
596 573
597 /* CRC and other errors */ 574 return false;
598/* if (ireg & TMIO_STAT_ERR_IRQ) 575}
599 * handled |= tmio_error_irq(host, irq, stat); 576
600 */ 577irqreturn_t tmio_mmc_card_detect_irq(int irq, void *devid)
578{
579 unsigned int ireg, status;
580 struct tmio_mmc_host *host = devid;
581
582 tmio_mmc_card_irq_status(host, &ireg, &status);
583 __tmio_mmc_card_detect_irq(host, ireg, status);
601 584
585 return IRQ_HANDLED;
586}
587EXPORT_SYMBOL(tmio_mmc_card_detect_irq);
588
589static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host,
590 int ireg, int status)
591{
602 /* Command completion */ 592 /* Command completion */
603 if (ireg & (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT)) { 593 if (ireg & (TMIO_STAT_CMDRESPEND | TMIO_STAT_CMDTIMEOUT)) {
604 tmio_mmc_ack_mmc_irqs(host, 594 tmio_mmc_ack_mmc_irqs(host,
605 TMIO_STAT_CMDRESPEND | 595 TMIO_STAT_CMDRESPEND |
606 TMIO_STAT_CMDTIMEOUT); 596 TMIO_STAT_CMDTIMEOUT);
607 tmio_mmc_cmd_irq(host, status); 597 tmio_mmc_cmd_irq(host, status);
608 goto out; 598 return true;
609 } 599 }
610 600
611 /* Data transfer */ 601 /* Data transfer */
612 if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) { 602 if (ireg & (TMIO_STAT_RXRDY | TMIO_STAT_TXRQ)) {
613 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ); 603 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
614 tmio_mmc_pio_irq(host); 604 tmio_mmc_pio_irq(host);
615 goto out; 605 return true;
616 } 606 }
617 607
618 /* Data transfer completion */ 608 /* Data transfer completion */
619 if (ireg & TMIO_STAT_DATAEND) { 609 if (ireg & TMIO_STAT_DATAEND) {
620 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND); 610 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND);
621 tmio_mmc_data_irq(host); 611 tmio_mmc_data_irq(host);
622 goto out; 612 return true;
623 } 613 }
624 614
625 pr_warning("tmio_mmc: Spurious irq, disabling! " 615 return false;
626 "0x%08x 0x%08x 0x%08x\n", status, irq_mask, ireg); 616}
627 pr_debug_status(status); 617
628 tmio_mmc_disable_mmc_irqs(host, status & ~irq_mask); 618irqreturn_t tmio_mmc_sdcard_irq(int irq, void *devid)
619{
620 unsigned int ireg, status;
621 struct tmio_mmc_host *host = devid;
622
623 tmio_mmc_card_irq_status(host, &ireg, &status);
624 __tmio_mmc_sdcard_irq(host, ireg, status);
625
626 return IRQ_HANDLED;
627}
628EXPORT_SYMBOL(tmio_mmc_sdcard_irq);
629
630irqreturn_t tmio_mmc_sdio_irq(int irq, void *devid)
631{
632 struct tmio_mmc_host *host = devid;
633 struct mmc_host *mmc = host->mmc;
634 struct tmio_mmc_data *pdata = host->pdata;
635 unsigned int ireg, status;
636
637 if (!(pdata->flags & TMIO_MMC_SDIO_IRQ))
638 return IRQ_HANDLED;
639
640 status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
641 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdcard_irq_mask;
642
643 sd_ctrl_write16(host, CTL_SDIO_STATUS, status & ~TMIO_SDIO_MASK_ALL);
644
645 if (mmc->caps & MMC_CAP_SDIO_IRQ && ireg & TMIO_SDIO_STAT_IOIRQ)
646 mmc_signal_sdio_irq(mmc);
647
648 return IRQ_HANDLED;
649}
650EXPORT_SYMBOL(tmio_mmc_sdio_irq);
651
652irqreturn_t tmio_mmc_irq(int irq, void *devid)
653{
654 struct tmio_mmc_host *host = devid;
655 unsigned int ireg, status;
656
657 pr_debug("MMC IRQ begin\n");
658
659 tmio_mmc_card_irq_status(host, &ireg, &status);
660 if (__tmio_mmc_card_detect_irq(host, ireg, status))
661 return IRQ_HANDLED;
662 if (__tmio_mmc_sdcard_irq(host, ireg, status))
663 return IRQ_HANDLED;
664
665 tmio_mmc_sdio_irq(irq, devid);
629 666
630out:
631 return IRQ_HANDLED; 667 return IRQ_HANDLED;
632} 668}
633EXPORT_SYMBOL(tmio_mmc_irq); 669EXPORT_SYMBOL(tmio_mmc_irq);
@@ -882,6 +918,7 @@ int __devinit tmio_mmc_host_probe(struct tmio_mmc_host **host,
882 tmio_mmc_clk_stop(_host); 918 tmio_mmc_clk_stop(_host);
883 tmio_mmc_reset(_host); 919 tmio_mmc_reset(_host);
884 920
921 _host->sdcard_irq_mask = sd_ctrl_read32(_host, CTL_IRQ_MASK);
885 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL); 922 tmio_mmc_disable_mmc_irqs(_host, TMIO_MASK_ALL);
886 if (pdata->flags & TMIO_MMC_SDIO_IRQ) 923 if (pdata->flags & TMIO_MMC_SDIO_IRQ)
887 tmio_mmc_enable_sdio_irq(mmc, 0); 924 tmio_mmc_enable_sdio_irq(mmc, 0);
diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
index 4dfe2c02ea91..4b83c43f950d 100644
--- a/drivers/mmc/host/via-sdmmc.c
+++ b/drivers/mmc/host/via-sdmmc.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/module.h>
12#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
13#include <linux/highmem.h> 14#include <linux/highmem.h>
14#include <linux/delay.h> 15#include <linux/delay.h>
@@ -1191,7 +1192,7 @@ static void __devexit via_sd_remove(struct pci_dev *pcidev)
1191 mmiowb(); 1192 mmiowb();
1192 1193
1193 if (sdhost->mrq) { 1194 if (sdhost->mrq) {
1194 printk(KERN_ERR "%s: Controller removed during " 1195 pr_err("%s: Controller removed during "
1195 "transfer\n", mmc_hostname(sdhost->mmc)); 1196 "transfer\n", mmc_hostname(sdhost->mmc));
1196 1197
1197 /* make sure all DMA is stopped */ 1198 /* make sure all DMA is stopped */
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index 62e5a4d171e1..64acd9ce141c 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -194,7 +194,7 @@ static void wbsd_reset(struct wbsd_host *host)
194{ 194{
195 u8 setup; 195 u8 setup;
196 196
197 printk(KERN_ERR "%s: Resetting chip\n", mmc_hostname(host->mmc)); 197 pr_err("%s: Resetting chip\n", mmc_hostname(host->mmc));
198 198
199 /* 199 /*
200 * Soft reset of chip (SD/MMC part). 200 * Soft reset of chip (SD/MMC part).
@@ -721,7 +721,7 @@ static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
721 * Any leftover data? 721 * Any leftover data?
722 */ 722 */
723 if (count) { 723 if (count) {
724 printk(KERN_ERR "%s: Incomplete DMA transfer. " 724 pr_err("%s: Incomplete DMA transfer. "
725 "%d bytes left.\n", 725 "%d bytes left.\n",
726 mmc_hostname(host->mmc), count); 726 mmc_hostname(host->mmc), count);
727 727
@@ -803,7 +803,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
803 803
804 default: 804 default:
805#ifdef CONFIG_MMC_DEBUG 805#ifdef CONFIG_MMC_DEBUG
806 printk(KERN_WARNING "%s: Data command %d is not " 806 pr_warning("%s: Data command %d is not "
807 "supported by this controller.\n", 807 "supported by this controller.\n",
808 mmc_hostname(host->mmc), cmd->opcode); 808 mmc_hostname(host->mmc), cmd->opcode);
809#endif 809#endif
@@ -1029,7 +1029,7 @@ static void wbsd_tasklet_card(unsigned long param)
1029 host->flags &= ~WBSD_FCARD_PRESENT; 1029 host->flags &= ~WBSD_FCARD_PRESENT;
1030 1030
1031 if (host->mrq) { 1031 if (host->mrq) {
1032 printk(KERN_ERR "%s: Card removed during transfer!\n", 1032 pr_err("%s: Card removed during transfer!\n",
1033 mmc_hostname(host->mmc)); 1033 mmc_hostname(host->mmc));
1034 wbsd_reset(host); 1034 wbsd_reset(host);
1035 1035
@@ -1429,7 +1429,7 @@ free:
1429 free_dma(dma); 1429 free_dma(dma);
1430 1430
1431err: 1431err:
1432 printk(KERN_WARNING DRIVER_NAME ": Unable to allocate DMA %d. " 1432 pr_warning(DRIVER_NAME ": Unable to allocate DMA %d. "
1433 "Falling back on FIFO.\n", dma); 1433 "Falling back on FIFO.\n", dma);
1434} 1434}
1435 1435
@@ -1664,7 +1664,7 @@ static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma,
1664 ret = wbsd_scan(host); 1664 ret = wbsd_scan(host);
1665 if (ret) { 1665 if (ret) {
1666 if (pnp && (ret == -ENODEV)) { 1666 if (pnp && (ret == -ENODEV)) {
1667 printk(KERN_WARNING DRIVER_NAME 1667 pr_warning(DRIVER_NAME
1668 ": Unable to confirm device presence. You may " 1668 ": Unable to confirm device presence. You may "
1669 "experience lock-ups.\n"); 1669 "experience lock-ups.\n");
1670 } else { 1670 } else {
@@ -1688,7 +1688,7 @@ static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma,
1688 */ 1688 */
1689 if (pnp) { 1689 if (pnp) {
1690 if ((host->config != 0) && !wbsd_chip_validate(host)) { 1690 if ((host->config != 0) && !wbsd_chip_validate(host)) {
1691 printk(KERN_WARNING DRIVER_NAME 1691 pr_warning(DRIVER_NAME
1692 ": PnP active but chip not configured! " 1692 ": PnP active but chip not configured! "
1693 "You probably have a buggy BIOS. " 1693 "You probably have a buggy BIOS. "
1694 "Configuring chip manually.\n"); 1694 "Configuring chip manually.\n");
@@ -1720,7 +1720,7 @@ static int __devinit wbsd_init(struct device *dev, int base, int irq, int dma,
1720 1720
1721 mmc_add_host(mmc); 1721 mmc_add_host(mmc);
1722 1722
1723 printk(KERN_INFO "%s: W83L51xD", mmc_hostname(mmc)); 1723 pr_info("%s: W83L51xD", mmc_hostname(mmc));
1724 if (host->chip_id != 0) 1724 if (host->chip_id != 0)
1725 printk(" id %x", (int)host->chip_id); 1725 printk(" id %x", (int)host->chip_id);
1726 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq); 1726 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq);
@@ -1909,7 +1909,7 @@ static int wbsd_pnp_resume(struct pnp_dev *pnp_dev)
1909 */ 1909 */
1910 if (host->config != 0) { 1910 if (host->config != 0) {
1911 if (!wbsd_chip_validate(host)) { 1911 if (!wbsd_chip_validate(host)) {
1912 printk(KERN_WARNING DRIVER_NAME 1912 pr_warning(DRIVER_NAME
1913 ": PnP active but chip not configured! " 1913 ": PnP active but chip not configured! "
1914 "You probably have a buggy BIOS. " 1914 "You probably have a buggy BIOS. "
1915 "Configuring chip manually.\n"); 1915 "Configuring chip manually.\n");
@@ -1973,9 +1973,9 @@ static int __init wbsd_drv_init(void)
1973{ 1973{
1974 int result; 1974 int result;
1975 1975
1976 printk(KERN_INFO DRIVER_NAME 1976 pr_info(DRIVER_NAME
1977 ": Winbond W83L51xD SD/MMC card interface driver\n"); 1977 ": Winbond W83L51xD SD/MMC card interface driver\n");
1978 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); 1978 pr_info(DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1979 1979
1980#ifdef CONFIG_PNP 1980#ifdef CONFIG_PNP
1981 1981
diff --git a/include/linux/atmel-mci.h b/include/linux/atmel-mci.h
index 3e09b345f4d6..4c7a4b2104bf 100644
--- a/include/linux/atmel-mci.h
+++ b/include/linux/atmel-mci.h
@@ -1,7 +1,7 @@
1#ifndef __LINUX_ATMEL_MCI_H 1#ifndef __LINUX_ATMEL_MCI_H
2#define __LINUX_ATMEL_MCI_H 2#define __LINUX_ATMEL_MCI_H
3 3
4#define ATMEL_MCI_MAX_NR_SLOTS 2 4#define ATMCI_MAX_NR_SLOTS 2
5 5
6/** 6/**
7 * struct mci_slot_pdata - board-specific per-slot configuration 7 * struct mci_slot_pdata - board-specific per-slot configuration
@@ -33,7 +33,7 @@ struct mci_slot_pdata {
33 */ 33 */
34struct mci_platform_data { 34struct mci_platform_data {
35 struct mci_dma_data *dma_slave; 35 struct mci_dma_data *dma_slave;
36 struct mci_slot_pdata slot[ATMEL_MCI_MAX_NR_SLOTS]; 36 struct mci_slot_pdata slot[ATMCI_MAX_NR_SLOTS];
37}; 37};
38 38
39#endif /* __LINUX_ATMEL_MCI_H */ 39#endif /* __LINUX_ATMEL_MCI_H */
diff --git a/include/linux/atmel_pdc.h b/include/linux/atmel_pdc.h
index 5058a31d2ce8..63499ce806ea 100644
--- a/include/linux/atmel_pdc.h
+++ b/include/linux/atmel_pdc.h
@@ -33,4 +33,6 @@
33 33
34#define ATMEL_PDC_PTSR 0x124 /* Transfer Status Register */ 34#define ATMEL_PDC_PTSR 0x124 /* Transfer Status Register */
35 35
36#define ATMEL_PDC_SCND_BUF_OFF 0x10 /* Offset between first and second buffer registers */
37
36#endif 38#endif
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index b460fc2af8a1..415f2db414e1 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -50,8 +50,12 @@ struct mmc_ext_csd {
50 u8 rel_sectors; 50 u8 rel_sectors;
51 u8 rel_param; 51 u8 rel_param;
52 u8 part_config; 52 u8 part_config;
53 u8 cache_ctrl;
54 u8 rst_n_function;
53 unsigned int part_time; /* Units: ms */ 55 unsigned int part_time; /* Units: ms */
54 unsigned int sa_timeout; /* Units: 100ns */ 56 unsigned int sa_timeout; /* Units: 100ns */
57 unsigned int generic_cmd6_time; /* Units: 10ms */
58 unsigned int power_off_longtime; /* Units: ms */
55 unsigned int hs_max_dtr; 59 unsigned int hs_max_dtr;
56 unsigned int sectors; 60 unsigned int sectors;
57 unsigned int card_type; 61 unsigned int card_type;
@@ -63,11 +67,15 @@ struct mmc_ext_csd {
63 bool enhanced_area_en; /* enable bit */ 67 bool enhanced_area_en; /* enable bit */
64 unsigned long long enhanced_area_offset; /* Units: Byte */ 68 unsigned long long enhanced_area_offset; /* Units: Byte */
65 unsigned int enhanced_area_size; /* Units: KB */ 69 unsigned int enhanced_area_size; /* Units: KB */
66 unsigned int boot_size; /* in bytes */ 70 unsigned int cache_size; /* Units: KB */
71 bool hpi_en; /* HPI enablebit */
72 bool hpi; /* HPI support bit */
73 unsigned int hpi_cmd; /* cmd used as HPI */
67 u8 raw_partition_support; /* 160 */ 74 u8 raw_partition_support; /* 160 */
68 u8 raw_erased_mem_count; /* 181 */ 75 u8 raw_erased_mem_count; /* 181 */
69 u8 raw_ext_csd_structure; /* 194 */ 76 u8 raw_ext_csd_structure; /* 194 */
70 u8 raw_card_type; /* 196 */ 77 u8 raw_card_type; /* 196 */
78 u8 out_of_int_time; /* 198 */
71 u8 raw_s_a_timeout; /* 217 */ 79 u8 raw_s_a_timeout; /* 217 */
72 u8 raw_hc_erase_gap_size; /* 221 */ 80 u8 raw_hc_erase_gap_size; /* 221 */
73 u8 raw_erase_timeout_mult; /* 223 */ 81 u8 raw_erase_timeout_mult; /* 223 */
@@ -77,6 +85,9 @@ struct mmc_ext_csd {
77 u8 raw_sec_feature_support;/* 231 */ 85 u8 raw_sec_feature_support;/* 231 */
78 u8 raw_trim_mult; /* 232 */ 86 u8 raw_trim_mult; /* 232 */
79 u8 raw_sectors[4]; /* 212 - 4 bytes */ 87 u8 raw_sectors[4]; /* 212 - 4 bytes */
88
89 unsigned int feature_support;
90#define MMC_DISCARD_FEATURE BIT(0) /* CMD38 feature */
80}; 91};
81 92
82struct sd_scr { 93struct sd_scr {
@@ -157,6 +168,24 @@ struct sdio_func_tuple;
157 168
158#define SDIO_MAX_FUNCS 7 169#define SDIO_MAX_FUNCS 7
159 170
171/* The number of MMC physical partitions. These consist of:
172 * boot partitions (2), general purpose partitions (4) in MMC v4.4.
173 */
174#define MMC_NUM_BOOT_PARTITION 2
175#define MMC_NUM_GP_PARTITION 4
176#define MMC_NUM_PHY_PARTITION 6
177#define MAX_MMC_PART_NAME_LEN 20
178
179/*
180 * MMC Physical partitions
181 */
182struct mmc_part {
183 unsigned int size; /* partition size (in bytes) */
184 unsigned int part_cfg; /* partition type */
185 char name[MAX_MMC_PART_NAME_LEN];
186 bool force_ro; /* to make boot parts RO by default */
187};
188
160/* 189/*
161 * MMC device 190 * MMC device
162 */ 191 */
@@ -188,6 +217,13 @@ struct mmc_card {
188#define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */ 217#define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */
189#define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */ 218#define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */
190#define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */ 219#define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */
220#define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8) /* Avoid sending 512 bytes in */
221 /* byte mode */
222 unsigned int poweroff_notify_state; /* eMMC4.5 notify feature */
223#define MMC_NO_POWER_NOTIFICATION 0
224#define MMC_POWERED_ON 1
225#define MMC_POWEROFF_SHORT 2
226#define MMC_POWEROFF_LONG 3
191 227
192 unsigned int erase_size; /* erase size in sectors */ 228 unsigned int erase_size; /* erase size in sectors */
193 unsigned int erase_shift; /* if erase unit is power 2 */ 229 unsigned int erase_shift; /* if erase unit is power 2 */
@@ -216,9 +252,24 @@ struct mmc_card {
216 unsigned int sd_bus_speed; /* Bus Speed Mode set for the card */ 252 unsigned int sd_bus_speed; /* Bus Speed Mode set for the card */
217 253
218 struct dentry *debugfs_root; 254 struct dentry *debugfs_root;
255 struct mmc_part part[MMC_NUM_PHY_PARTITION]; /* physical partitions */
256 unsigned int nr_parts;
219}; 257};
220 258
221/* 259/*
260 * This function fill contents in mmc_part.
261 */
262static inline void mmc_part_add(struct mmc_card *card, unsigned int size,
263 unsigned int part_cfg, char *name, int idx, bool ro)
264{
265 card->part[card->nr_parts].size = size;
266 card->part[card->nr_parts].part_cfg = part_cfg;
267 sprintf(card->part[card->nr_parts].name, name, idx);
268 card->part[card->nr_parts].force_ro = ro;
269 card->nr_parts++;
270}
271
272/*
222 * The world is not perfect and supplies us with broken mmc/sdio devices. 273 * The world is not perfect and supplies us with broken mmc/sdio devices.
223 * For at least some of these bugs we need a work-around. 274 * For at least some of these bugs we need a work-around.
224 */ 275 */
@@ -377,6 +428,11 @@ static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c)
377 return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF; 428 return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF;
378} 429}
379 430
431static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c)
432{
433 return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512;
434}
435
380#define mmc_card_name(c) ((c)->cid.prod_name) 436#define mmc_card_name(c) ((c)->cid.prod_name)
381#define mmc_card_id(c) (dev_name(&(c)->dev)) 437#define mmc_card_id(c) (dev_name(&(c)->dev))
382 438
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index b8b1b7a311f1..174a844a5dda 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -136,6 +136,7 @@ struct mmc_async_req;
136 136
137extern struct mmc_async_req *mmc_start_req(struct mmc_host *, 137extern struct mmc_async_req *mmc_start_req(struct mmc_host *,
138 struct mmc_async_req *, int *); 138 struct mmc_async_req *, int *);
139extern int mmc_interrupt_hpi(struct mmc_card *);
139extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *); 140extern void mmc_wait_for_req(struct mmc_host *, struct mmc_request *);
140extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int); 141extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
141extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *); 142extern int mmc_app_cmd(struct mmc_host *, struct mmc_card *);
@@ -146,6 +147,7 @@ extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
146#define MMC_ERASE_ARG 0x00000000 147#define MMC_ERASE_ARG 0x00000000
147#define MMC_SECURE_ERASE_ARG 0x80000000 148#define MMC_SECURE_ERASE_ARG 0x80000000
148#define MMC_TRIM_ARG 0x00000001 149#define MMC_TRIM_ARG 0x00000001
150#define MMC_DISCARD_ARG 0x00000003
149#define MMC_SECURE_TRIM1_ARG 0x80000001 151#define MMC_SECURE_TRIM1_ARG 0x80000001
150#define MMC_SECURE_TRIM2_ARG 0x80008000 152#define MMC_SECURE_TRIM2_ARG 0x80008000
151 153
@@ -156,12 +158,17 @@ extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
156 unsigned int arg); 158 unsigned int arg);
157extern int mmc_can_erase(struct mmc_card *card); 159extern int mmc_can_erase(struct mmc_card *card);
158extern int mmc_can_trim(struct mmc_card *card); 160extern int mmc_can_trim(struct mmc_card *card);
161extern int mmc_can_discard(struct mmc_card *card);
162extern int mmc_can_sanitize(struct mmc_card *card);
159extern int mmc_can_secure_erase_trim(struct mmc_card *card); 163extern int mmc_can_secure_erase_trim(struct mmc_card *card);
160extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, 164extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
161 unsigned int nr); 165 unsigned int nr);
162extern unsigned int mmc_calc_max_discard(struct mmc_card *card); 166extern unsigned int mmc_calc_max_discard(struct mmc_card *card);
163 167
164extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen); 168extern int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen);
169extern int mmc_hw_reset(struct mmc_host *host);
170extern int mmc_hw_reset_check(struct mmc_host *host);
171extern int mmc_can_reset(struct mmc_card *card);
165 172
166extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *); 173extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
167extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int); 174extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
@@ -171,6 +178,8 @@ extern void mmc_release_host(struct mmc_host *host);
171extern void mmc_do_release_host(struct mmc_host *host); 178extern void mmc_do_release_host(struct mmc_host *host);
172extern int mmc_try_claim_host(struct mmc_host *host); 179extern int mmc_try_claim_host(struct mmc_host *host);
173 180
181extern int mmc_flush_cache(struct mmc_card *);
182
174/** 183/**
175 * mmc_claim_host - exclusively claim a host 184 * mmc_claim_host - exclusively claim a host
176 * @host: mmc host to claim 185 * @host: mmc host to claim
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index 6b46819705d1..6dc9b80568a0 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -72,6 +72,8 @@ struct mmc_data;
72 * rate and timeout calculations. 72 * rate and timeout calculations.
73 * @current_speed: Configured rate of the controller. 73 * @current_speed: Configured rate of the controller.
74 * @num_slots: Number of slots available. 74 * @num_slots: Number of slots available.
75 * @verid: Denote Version ID.
76 * @data_offset: Set the offset of DATA register according to VERID.
75 * @pdev: Platform device associated with the MMC controller. 77 * @pdev: Platform device associated with the MMC controller.
76 * @pdata: Platform data associated with the MMC controller. 78 * @pdata: Platform data associated with the MMC controller.
77 * @slot: Slots sharing this MMC controller. 79 * @slot: Slots sharing this MMC controller.
@@ -147,6 +149,8 @@ struct dw_mci {
147 u32 current_speed; 149 u32 current_speed;
148 u32 num_slots; 150 u32 num_slots;
149 u32 fifoth_val; 151 u32 fifoth_val;
152 u16 verid;
153 u16 data_offset;
150 struct platform_device *pdev; 154 struct platform_device *pdev;
151 struct dw_mci_board *pdata; 155 struct dw_mci_board *pdata;
152 struct dw_mci_slot *slot[MAX_MCI_SLOTS]; 156 struct dw_mci_slot *slot[MAX_MCI_SLOTS];
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 1d09562ccf73..a3ac9c48e5de 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -12,6 +12,7 @@
12 12
13#include <linux/leds.h> 13#include <linux/leds.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/fault-inject.h>
15 16
16#include <linux/mmc/core.h> 17#include <linux/mmc/core.h>
17#include <linux/mmc/pm.h> 18#include <linux/mmc/pm.h>
@@ -108,6 +109,9 @@ struct mmc_host_ops {
108 * It is optional for the host to implement pre_req and post_req in 109 * It is optional for the host to implement pre_req and post_req in
109 * order to support double buffering of requests (prepare one 110 * order to support double buffering of requests (prepare one
110 * request while another request is active). 111 * request while another request is active).
112 * pre_req() must always be followed by a post_req().
113 * To undo a call made to pre_req(), call post_req() with
114 * a nonzero err condition.
111 */ 115 */
112 void (*post_req)(struct mmc_host *host, struct mmc_request *req, 116 void (*post_req)(struct mmc_host *host, struct mmc_request *req,
113 int err); 117 int err);
@@ -147,6 +151,7 @@ struct mmc_host_ops {
147 int (*execute_tuning)(struct mmc_host *host); 151 int (*execute_tuning)(struct mmc_host *host);
148 void (*enable_preset_value)(struct mmc_host *host, bool enable); 152 void (*enable_preset_value)(struct mmc_host *host, bool enable);
149 int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv); 153 int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);
154 void (*hw_reset)(struct mmc_host *host);
150}; 155};
151 156
152struct mmc_card; 157struct mmc_card;
@@ -229,8 +234,20 @@ struct mmc_host {
229#define MMC_CAP_MAX_CURRENT_600 (1 << 28) /* Host max current limit is 600mA */ 234#define MMC_CAP_MAX_CURRENT_600 (1 << 28) /* Host max current limit is 600mA */
230#define MMC_CAP_MAX_CURRENT_800 (1 << 29) /* Host max current limit is 800mA */ 235#define MMC_CAP_MAX_CURRENT_800 (1 << 29) /* Host max current limit is 800mA */
231#define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */ 236#define MMC_CAP_CMD23 (1 << 30) /* CMD23 supported. */
237#define MMC_CAP_HW_RESET (1 << 31) /* Hardware reset */
238
239 unsigned int caps2; /* More host capabilities */
240
241#define MMC_CAP2_BOOTPART_NOACC (1 << 0) /* Boot partition no access */
242#define MMC_CAP2_CACHE_CTRL (1 << 1) /* Allow cache control */
243#define MMC_CAP2_POWEROFF_NOTIFY (1 << 2) /* Notify poweroff supported */
244#define MMC_CAP2_NO_MULTI_READ (1 << 3) /* Multiblock reads don't work */
232 245
233 mmc_pm_flag_t pm_caps; /* supported pm features */ 246 mmc_pm_flag_t pm_caps; /* supported pm features */
247 unsigned int power_notify_type;
248#define MMC_HOST_PW_NOTIFY_NONE 0
249#define MMC_HOST_PW_NOTIFY_SHORT 1
250#define MMC_HOST_PW_NOTIFY_LONG 2
234 251
235#ifdef CONFIG_MMC_CLKGATE 252#ifdef CONFIG_MMC_CLKGATE
236 int clk_requests; /* internal reference counter */ 253 int clk_requests; /* internal reference counter */
@@ -302,6 +319,10 @@ struct mmc_host {
302 319
303 struct mmc_async_req *areq; /* active async req */ 320 struct mmc_async_req *areq; /* active async req */
304 321
322#ifdef CONFIG_FAIL_MMC_REQUEST
323 struct fault_attr fail_mmc_request;
324#endif
325
305 unsigned long private[0] ____cacheline_aligned; 326 unsigned long private[0] ____cacheline_aligned;
306}; 327};
307 328
@@ -330,6 +351,8 @@ extern int mmc_power_restore_host(struct mmc_host *host);
330extern void mmc_detect_change(struct mmc_host *, unsigned long delay); 351extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
331extern void mmc_request_done(struct mmc_host *, struct mmc_request *); 352extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
332 353
354extern int mmc_cache_ctrl(struct mmc_host *, u8);
355
333static inline void mmc_signal_sdio_irq(struct mmc_host *host) 356static inline void mmc_signal_sdio_irq(struct mmc_host *host)
334{ 357{
335 host->ops->enable_sdio_irq(host, 0); 358 host->ops->enable_sdio_irq(host, 0);
@@ -394,4 +417,10 @@ static inline int mmc_host_cmd23(struct mmc_host *host)
394{ 417{
395 return host->caps & MMC_CAP_CMD23; 418 return host->caps & MMC_CAP_CMD23;
396} 419}
420
421static inline int mmc_boot_partition_access(struct mmc_host *host)
422{
423 return !(host->caps2 & MMC_CAP2_BOOTPART_NOACC);
424}
425
397#endif /* LINUX_MMC_HOST_H */ 426#endif /* LINUX_MMC_HOST_H */
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 5a794cb503ea..0e7135697d11 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -270,18 +270,31 @@ struct _mmc_csd {
270 * EXT_CSD fields 270 * EXT_CSD fields
271 */ 271 */
272 272
273#define EXT_CSD_FLUSH_CACHE 32 /* W */
274#define EXT_CSD_CACHE_CTRL 33 /* R/W */
275#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */
276#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */
273#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ 277#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */
274#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ 278#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */
279#define EXT_CSD_HPI_MGMT 161 /* R/W */
280#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */
281#define EXT_CSD_SANITIZE_START 165 /* W */
275#define EXT_CSD_WR_REL_PARAM 166 /* RO */ 282#define EXT_CSD_WR_REL_PARAM 166 /* RO */
276#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ 283#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
277#define EXT_CSD_PART_CONFIG 179 /* R/W */ 284#define EXT_CSD_PART_CONFIG 179 /* R/W */
278#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ 285#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */
279#define EXT_CSD_BUS_WIDTH 183 /* R/W */ 286#define EXT_CSD_BUS_WIDTH 183 /* R/W */
280#define EXT_CSD_HS_TIMING 185 /* R/W */ 287#define EXT_CSD_HS_TIMING 185 /* R/W */
288#define EXT_CSD_POWER_CLASS 187 /* R/W */
281#define EXT_CSD_REV 192 /* RO */ 289#define EXT_CSD_REV 192 /* RO */
282#define EXT_CSD_STRUCTURE 194 /* RO */ 290#define EXT_CSD_STRUCTURE 194 /* RO */
283#define EXT_CSD_CARD_TYPE 196 /* RO */ 291#define EXT_CSD_CARD_TYPE 196 /* RO */
292#define EXT_CSD_OUT_OF_INTERRUPT_TIME 198 /* RO */
284#define EXT_CSD_PART_SWITCH_TIME 199 /* RO */ 293#define EXT_CSD_PART_SWITCH_TIME 199 /* RO */
294#define EXT_CSD_PWR_CL_52_195 200 /* RO */
295#define EXT_CSD_PWR_CL_26_195 201 /* RO */
296#define EXT_CSD_PWR_CL_52_360 202 /* RO */
297#define EXT_CSD_PWR_CL_26_360 203 /* RO */
285#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ 298#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
286#define EXT_CSD_S_A_TIMEOUT 217 /* RO */ 299#define EXT_CSD_S_A_TIMEOUT 217 /* RO */
287#define EXT_CSD_REL_WR_SEC_C 222 /* RO */ 300#define EXT_CSD_REL_WR_SEC_C 222 /* RO */
@@ -293,6 +306,14 @@ struct _mmc_csd {
293#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */ 306#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */
294#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */ 307#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */
295#define EXT_CSD_TRIM_MULT 232 /* RO */ 308#define EXT_CSD_TRIM_MULT 232 /* RO */
309#define EXT_CSD_PWR_CL_200_195 236 /* RO */
310#define EXT_CSD_PWR_CL_200_360 237 /* RO */
311#define EXT_CSD_PWR_CL_DDR_52_195 238 /* RO */
312#define EXT_CSD_PWR_CL_DDR_52_360 239 /* RO */
313#define EXT_CSD_POWER_OFF_LONG_TIME 247 /* RO */
314#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */
315#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */
316#define EXT_CSD_HPI_FEATURES 503 /* RO */
296 317
297/* 318/*
298 * EXT_CSD field definitions 319 * EXT_CSD field definitions
@@ -302,7 +323,9 @@ struct _mmc_csd {
302 323
303#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) 324#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7)
304#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) 325#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1)
305#define EXT_CSD_PART_CONFIG_ACC_BOOT1 (0x2) 326#define EXT_CSD_PART_CONFIG_ACC_GP0 (0x4)
327
328#define EXT_CSD_PART_SUPPORT_PART_EN (0x1)
306 329
307#define EXT_CSD_CMD_SET_NORMAL (1<<0) 330#define EXT_CSD_CMD_SET_NORMAL (1<<0)
308#define EXT_CSD_CMD_SET_SECURE (1<<1) 331#define EXT_CSD_CMD_SET_SECURE (1<<1)
@@ -327,7 +350,20 @@ struct _mmc_csd {
327#define EXT_CSD_SEC_ER_EN BIT(0) 350#define EXT_CSD_SEC_ER_EN BIT(0)
328#define EXT_CSD_SEC_BD_BLK_EN BIT(2) 351#define EXT_CSD_SEC_BD_BLK_EN BIT(2)
329#define EXT_CSD_SEC_GB_CL_EN BIT(4) 352#define EXT_CSD_SEC_GB_CL_EN BIT(4)
353#define EXT_CSD_SEC_SANITIZE BIT(6) /* v4.5 only */
354
355#define EXT_CSD_RST_N_EN_MASK 0x3
356#define EXT_CSD_RST_N_ENABLED 1 /* RST_n is enabled on card */
357
358#define EXT_CSD_NO_POWER_NOTIFICATION 0
359#define EXT_CSD_POWER_ON 1
360#define EXT_CSD_POWER_OFF_SHORT 2
361#define EXT_CSD_POWER_OFF_LONG 3
330 362
363#define EXT_CSD_PWR_CL_8BIT_MASK 0xF0 /* 8 bit PWR CLS */
364#define EXT_CSD_PWR_CL_4BIT_MASK 0x0F /* 8 bit PWR CLS */
365#define EXT_CSD_PWR_CL_8BIT_SHIFT 4
366#define EXT_CSD_PWR_CL_4BIT_SHIFT 0
331/* 367/*
332 * MMC_SWITCH access modes 368 * MMC_SWITCH access modes
333 */ 369 */
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index 5666f3abfab7..e4b69353678d 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -88,6 +88,10 @@ struct sdhci_host {
88/* The read-only detection via SDHCI_PRESENT_STATE register is unstable */ 88/* The read-only detection via SDHCI_PRESENT_STATE register is unstable */
89#define SDHCI_QUIRK_UNSTABLE_RO_DETECT (1<<31) 89#define SDHCI_QUIRK_UNSTABLE_RO_DETECT (1<<31)
90 90
91 unsigned int quirks2; /* More deviations from spec. */
92
93#define SDHCI_QUIRK2_OWN_CARD_DETECTION (1<<0)
94
91 int irq; /* Device IRQ */ 95 int irq; /* Device IRQ */
92 void __iomem *ioaddr; /* Mapped address */ 96 void __iomem *ioaddr; /* Mapped address */
93 97
@@ -115,6 +119,8 @@ struct sdhci_host {
115#define SDHCI_NEEDS_RETUNING (1<<5) /* Host needs retuning */ 119#define SDHCI_NEEDS_RETUNING (1<<5) /* Host needs retuning */
116#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */ 120#define SDHCI_AUTO_CMD12 (1<<6) /* Auto CMD12 support */
117#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */ 121#define SDHCI_AUTO_CMD23 (1<<7) /* Auto CMD23 support */
122#define SDHCI_PV_ENABLED (1<<8) /* Preset value enabled */
123#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
118 124
119 unsigned int version; /* SDHCI spec. version */ 125 unsigned int version; /* SDHCI spec. version */
120 126
@@ -125,6 +131,8 @@ struct sdhci_host {
125 unsigned int clock; /* Current clock (MHz) */ 131 unsigned int clock; /* Current clock (MHz) */
126 u8 pwr; /* Current voltage */ 132 u8 pwr; /* Current voltage */
127 133
134 bool runtime_suspended; /* Host is runtime suspended */
135
128 struct mmc_request *mrq; /* Current request */ 136 struct mmc_request *mrq; /* Current request */
129 struct mmc_command *cmd; /* Current command */ 137 struct mmc_command *cmd; /* Current command */
130 struct mmc_data *data; /* Current data request */ 138 struct mmc_data *data; /* Current data request */
diff --git a/include/linux/mmc/sdio.h b/include/linux/mmc/sdio.h
index 2a2e9905a247..e0b1123497b9 100644
--- a/include/linux/mmc/sdio.h
+++ b/include/linux/mmc/sdio.h
@@ -72,11 +72,13 @@
72#define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */ 72#define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */
73#define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */ 73#define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */
74#define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */ 74#define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */
75#define SDIO_CCCR_REV_3_00 3 /* CCCR/FBR Version 3.00 */
75 76
76#define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */ 77#define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */
77#define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */ 78#define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */
78#define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */ 79#define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */
79#define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */ 80#define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */
81#define SDIO_SDIO_REV_3_00 4 /* SDIO Spec Version 3.00 */
80 82
81#define SDIO_CCCR_SD 0x01 83#define SDIO_CCCR_SD 0x01
82 84
diff --git a/include/linux/mmc/sh_mmcif.h b/include/linux/mmc/sh_mmcif.h
index 0222cd8ebe76..04ff452bf5c3 100644
--- a/include/linux/mmc/sh_mmcif.h
+++ b/include/linux/mmc/sh_mmcif.h
@@ -41,7 +41,9 @@ struct sh_mmcif_plat_data {
41 void (*set_pwr)(struct platform_device *pdev, int state); 41 void (*set_pwr)(struct platform_device *pdev, int state);
42 void (*down_pwr)(struct platform_device *pdev); 42 void (*down_pwr)(struct platform_device *pdev);
43 int (*get_cd)(struct platform_device *pdef); 43 int (*get_cd)(struct platform_device *pdef);
44 struct sh_mmcif_dma *dma; 44 struct sh_mmcif_dma *dma; /* Deprecated. Instead */
45 unsigned int slave_id_tx; /* use embedded slave_id_[tr]x */
46 unsigned int slave_id_rx;
45 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */ 47 u8 sup_pclk; /* 1 :SH7757, 0: SH7724/SH7372 */
46 unsigned long caps; 48 unsigned long caps;
47 u32 ocr; 49 u32 ocr;
diff --git a/include/linux/mmc/sh_mobile_sdhi.h b/include/linux/mmc/sh_mobile_sdhi.h
index bd50b365167f..71b805451bd8 100644
--- a/include/linux/mmc/sh_mobile_sdhi.h
+++ b/include/linux/mmc/sh_mobile_sdhi.h
@@ -6,6 +6,10 @@
6struct platform_device; 6struct platform_device;
7struct tmio_mmc_data; 7struct tmio_mmc_data;
8 8
9#define SH_MOBILE_SDHI_IRQ_CARD_DETECT "card_detect"
10#define SH_MOBILE_SDHI_IRQ_SDCARD "sdcard"
11#define SH_MOBILE_SDHI_IRQ_SDIO "sdio"
12
9struct sh_mobile_sdhi_info { 13struct sh_mobile_sdhi_info {
10 int dma_slave_tx; 14 int dma_slave_tx;
11 int dma_slave_rx; 15 int dma_slave_rx;
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 75330bd87565..c583a57cddfe 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1070,6 +1070,17 @@ config FAIL_IO_TIMEOUT
1070 Only works with drivers that use the generic timeout handling, 1070 Only works with drivers that use the generic timeout handling,
1071 for others it wont do anything. 1071 for others it wont do anything.
1072 1072
1073config FAIL_MMC_REQUEST
1074 bool "Fault-injection capability for MMC IO"
1075 select DEBUG_FS
1076 depends on FAULT_INJECTION && MMC
1077 help
1078 Provide fault-injection capability for MMC IO.
1079 This will make the mmc core return data errors. This is
1080 useful to test the error handling in the mmc block device
1081 and to test how the mmc host driver handles retries from
1082 the block device.
1083
1073config FAULT_INJECTION_DEBUG_FS 1084config FAULT_INJECTION_DEBUG_FS
1074 bool "Debugfs entries for fault-injection capabilities" 1085 bool "Debugfs entries for fault-injection capabilities"
1075 depends on FAULT_INJECTION && SYSFS && DEBUG_FS 1086 depends on FAULT_INJECTION && SYSFS && DEBUG_FS
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
index f193b7796449..4f7554025e30 100644
--- a/lib/fault-inject.c
+++ b/lib/fault-inject.c
@@ -14,7 +14,7 @@
14 * setup_fault_attr() is a helper function for various __setup handlers, so it 14 * setup_fault_attr() is a helper function for various __setup handlers, so it
15 * returns 0 on error, because that is what __setup handlers do. 15 * returns 0 on error, because that is what __setup handlers do.
16 */ 16 */
17int __init setup_fault_attr(struct fault_attr *attr, char *str) 17int setup_fault_attr(struct fault_attr *attr, char *str)
18{ 18{
19 unsigned long probability; 19 unsigned long probability;
20 unsigned long interval; 20 unsigned long interval;
@@ -36,6 +36,7 @@ int __init setup_fault_attr(struct fault_attr *attr, char *str)
36 36
37 return 1; 37 return 1;
38} 38}
39EXPORT_SYMBOL_GPL(setup_fault_attr);
39 40
40static void fail_dump(struct fault_attr *attr) 41static void fail_dump(struct fault_attr *attr)
41{ 42{
@@ -130,6 +131,7 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
130 131
131 return true; 132 return true;
132} 133}
134EXPORT_SYMBOL_GPL(should_fail);
133 135
134#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS 136#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
135 137
@@ -243,5 +245,6 @@ fail:
243 245
244 return ERR_PTR(-ENOMEM); 246 return ERR_PTR(-ENOMEM);
245} 247}
248EXPORT_SYMBOL_GPL(fault_create_debugfs_attr);
246 249
247#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */ 250#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */